diff --git a/go/consensus/tendermint/apps/staking/fees.go b/go/consensus/tendermint/apps/staking/fees.go index 0d09ab33a7d..7bd93399821 100644 --- a/go/consensus/tendermint/apps/staking/fees.go +++ b/go/consensus/tendermint/apps/staking/fees.go @@ -63,7 +63,7 @@ func (app *stakingApplication) disburseFeesP( // Pay the proposer. feeProposerAmt := totalFees.Clone() - if proposerEntity != nil { + if proposerEntity != nil && !feeProposerAmt.IsZero() { acct, err := stakeState.Account(ctx, *proposerEntity) if err != nil { return fmt.Errorf("failed to fetch proposer account: %w", err) diff --git a/go/consensus/tendermint/apps/staking/state/gas.go b/go/consensus/tendermint/apps/staking/state/gas.go index bba9f8e61d8..d6d3983da5c 100644 --- a/go/consensus/tendermint/apps/staking/state/gas.go +++ b/go/consensus/tendermint/apps/staking/state/gas.go @@ -98,13 +98,15 @@ func AuthenticateAndPayFees( return fmt.Errorf("failed to set account: %w", err) } - // Emit transfer event. - ev := cbor.Marshal(&staking.TransferEvent{ - From: id, - To: staking.FeeAccumulatorAccountID, - Tokens: fee.Amount, - }) - ctx.EmitEvent(abciAPI.NewEventBuilder(AppName).Attribute(KeyTransfer, ev)) + // Emit transfer event if fee is non-zero. + if !fee.Amount.IsZero() { + ev := cbor.Marshal(&staking.TransferEvent{ + From: id, + To: staking.FeeAccumulatorAccountID, + Tokens: fee.Amount, + }) + ctx.EmitEvent(abciAPI.NewEventBuilder(AppName).Attribute(KeyTransfer, ev)) + } // Configure gas accountant on the context. ctx.SetGasAccountant(abciAPI.NewCompositeGasAccountant( diff --git a/go/staking/tests/tester.go b/go/staking/tests/tester.go index 62fe286e5c0..55063ee1dde 100644 --- a/go/staking/tests/tester.go +++ b/go/staking/tests/tester.go @@ -181,8 +181,6 @@ func testTransfer(t *testing.T, state *stakingTestsState, backend api.Backend, c err = consensusAPI.SignAndSubmitTx(context.Background(), consensus, srcSigner, tx) require.NoError(err, "Transfer") - var gotCommon bool - var gotFeeAcc bool var gotTransfer bool TransferWaitLoop: @@ -190,11 +188,11 @@ TransferWaitLoop: select { case ev := <-ch: if ev.From.Equal(api.CommonPoolAccountID) || ev.To.Equal(api.CommonPoolAccountID) { - gotCommon = true + require.False(ev.Tokens.IsZero(), "CommonPool xfer: amount should be non-zero") continue } if ev.From.Equal(api.FeeAccumulatorAccountID) || ev.To.Equal(api.FeeAccumulatorAccountID) { - gotFeeAcc = true + require.False(ev.Tokens.IsZero(), "FeeAccumulator xfer: amount should be non-zero") continue } @@ -218,7 +216,7 @@ TransferWaitLoop: require.True(gotTransfer, "GetEvents should return transfer event") } - if (gotCommon || gotFeeAcc) && gotTransfer { + if gotTransfer { break TransferWaitLoop } case <-time.After(recvTimeout): @@ -226,8 +224,6 @@ TransferWaitLoop: } } - require.True(gotCommon || gotFeeAcc, "WatchTransfers should also return transfers related to the common pool and/or the fee accumulator") - _ = srcAcc.General.Balance.Sub(&xfer.Tokens) newSrcAcc, err := backend.AccountInfo(context.Background(), &api.OwnerQuery{Owner: SrcID, Height: consensusAPI.HeightLatest}) require.NoError(err, "src: AccountInfo - after") @@ -267,8 +263,6 @@ func testTransferWatchEvents(t *testing.T, state *stakingTestsState, backend api err = consensusAPI.SignAndSubmitTx(context.Background(), consensus, srcSigner, tx) require.NoError(err, "SignAndSubmitTx") - var gotCommon bool - var gotFeeAcc bool var gotTransfer bool TransferWaitLoop: @@ -282,14 +276,15 @@ TransferWaitLoop: from := ev.TransferEvent.From to := ev.TransferEvent.To + tokens := ev.TransferEvent.Tokens // We should also get some traffic to/from the common pool and fee accumulator. if from.Equal(api.CommonPoolAccountID) || to.Equal(api.CommonPoolAccountID) { - gotCommon = true + require.False(tokens.IsZero(), "CommonPool xfer: amount should be non-zero") continue } if from.Equal(api.FeeAccumulatorAccountID) || to.Equal(api.FeeAccumulatorAccountID) { - gotFeeAcc = true + require.False(tokens.IsZero(), "FeeAccumulator xfer: amount should be non-zero") continue } @@ -307,15 +302,13 @@ TransferWaitLoop: gotTransfer = true } - if (gotCommon || gotFeeAcc) && gotTransfer { + if gotTransfer { break TransferWaitLoop } case <-time.After(recvTimeout): t.Fatalf("failed to receive transfer event") } } - - require.True(gotCommon || gotFeeAcc, "WatchEvents should also return transfer events related to the common pool and/or the fee accumulator") } func testSelfTransfer(t *testing.T, state *stakingTestsState, backend api.Backend, consensus consensusAPI.Backend) { @@ -336,8 +329,6 @@ func testSelfTransfer(t *testing.T, state *stakingTestsState, backend api.Backen err = consensusAPI.SignAndSubmitTx(context.Background(), consensus, srcSigner, tx) require.NoError(err, "Transfer") - var gotCommon bool - var gotFeeAcc bool var gotTransfer bool TransferWaitLoop: @@ -345,11 +336,11 @@ TransferWaitLoop: select { case ev := <-ch: if ev.From.Equal(api.CommonPoolAccountID) || ev.To.Equal(api.CommonPoolAccountID) { - gotCommon = true + require.False(ev.Tokens.IsZero(), "CommonPool xfer: amount should be non-zero") continue } if ev.From.Equal(api.FeeAccumulatorAccountID) || ev.To.Equal(api.FeeAccumulatorAccountID) { - gotFeeAcc = true + require.False(ev.Tokens.IsZero(), "FeeAccumulator xfer: amount should be non-zero") continue } @@ -360,7 +351,7 @@ TransferWaitLoop: gotTransfer = true } - if (gotCommon || gotFeeAcc) && gotTransfer { + if gotTransfer { break TransferWaitLoop } case <-time.After(recvTimeout): @@ -368,8 +359,6 @@ TransferWaitLoop: } } - require.True(gotCommon || gotFeeAcc, "WatchTransfers should also return transfers related to the common pool and/or the fee accumulator") - newSrcAcc, err := backend.AccountInfo(context.Background(), &api.OwnerQuery{Owner: SrcID, Height: consensusAPI.HeightLatest}) require.NoError(err, "src: AccountInfo - after") require.Equal(srcAcc.General.Balance, newSrcAcc.General.Balance, "src: general balance - after")