diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index 3b73932f7..ba5c571fc 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -407,7 +407,12 @@ func (b *SimulatedBackend) PendingNonceAt(_ context.Context, account common.Addr // SuggestGasPrice implements ContractTransactor.SuggestGasPrice. Since the simulated // chain doesn't have miners, we just return a gas price of 1 for any call. func (b *SimulatedBackend) SuggestGasPrice(_ context.Context) (*big.Int, error) { - return new(big.Int).SetUint64(b.config.UnitPrice), nil + current := b.blockchain.CurrentBlock() + if b.blockchain.Config().IsMagmaForkEnabled(current.Number()) { + return new(big.Int).Mul(current.Header().BaseFee, big.NewInt(2)), nil + } else { + return new(big.Int).SetUint64(b.config.UnitPrice), nil + } } // EstimateGas executes the requested code against the latest block/state and diff --git a/blockchain/state_transition.go b/blockchain/state_transition.go index 4a6fd4377..fdb70a83e 100644 --- a/blockchain/state_transition.go +++ b/blockchain/state_transition.go @@ -487,7 +487,3 @@ func (st *StateTransition) refundGas(refundQuotient uint64) { func (st *StateTransition) gasUsed() uint64 { return st.initialGas - st.gas } - -func getBurnAmountMagma(fee *big.Int) *big.Int { - return new(big.Int).Div(fee, big.NewInt(2)) -} diff --git a/blockchain/system/rebalance.go b/blockchain/system/rebalance.go index c1902f6bf..e98b7466c 100644 --- a/blockchain/system/rebalance.go +++ b/blockchain/system/rebalance.go @@ -154,7 +154,7 @@ func newRebalanceReceipt() *rebalanceResult { } } -func (result *rebalanceResult) memo(isKip103 bool) []byte { +func (result *rebalanceResult) Memo(isKip103 bool) []byte { var ( memo []byte err error @@ -322,8 +322,5 @@ func RebalanceTreasury(state *state.StateDB, chain backends.BlockChainForCaller, remainder := new(big.Int).Sub(totalZeroedAmount, totalAllocatedAmount) result.Burnt.Add(result.Burnt, remainder) result.Success = true - - // Leave a memo for logging - logger.Info("successfully executed treasury rebalancing", "memo", string(result.memo(isKIP103))) return result, nil } diff --git a/blockchain/system/rebalance_test.go b/blockchain/system/rebalance_test.go index 62237aa85..db9aab769 100644 --- a/blockchain/system/rebalance_test.go +++ b/blockchain/system/rebalance_test.go @@ -222,7 +222,7 @@ func rebalanceTreasury(t *testing.T, sender *bind.TransactOpts, config *params.C res, err := RebalanceTreasury(state, chain, chain.CurrentHeader()) if chain.Config().Kip103CompatibleBlock != nil && tc.expectBurnt.Cmp(big.NewInt(0)) == -1 { assert.Equal(t, ErrRebalanceNotEnoughBalance, err) - t.Log(string(res.memo(true))) + t.Log(string(res.Memo(true))) continue } @@ -250,9 +250,9 @@ func rebalanceTreasury(t *testing.T, sender *bind.TransactOpts, config *params.C // assert.Equal(t, tc.expectKip103Memo, string(res.memo(isKip103))) //} - t.Log(string(res.memo(isKip103))) + t.Log(string(res.Memo(isKip103))) if !isKip103 { - assert.Equal(t, tc.expectKip160Memo, string(res.memo(isKip103))) + assert.Equal(t, tc.expectKip160Memo, string(res.Memo(isKip103))) } } } diff --git a/consensus/istanbul/backend/engine.go b/consensus/istanbul/backend/engine.go index 3515c7ad1..002f23b66 100644 --- a/consensus/istanbul/backend/engine.go +++ b/consensus/istanbul/backend/engine.go @@ -553,9 +553,13 @@ func (sb *backend) Finalize(chain consensus.ChainReader, header *types.Header, s // so the existing state db should be used to apply the rebalancing result. // Only on the KIP-103 or KIP-160 hardfork block, the following logic should be executed if chain.Config().IsKIP160ForkBlock(header.Number) || chain.Config().IsKIP103ForkBlock(header.Number) { - _, err := system.RebalanceTreasury(state, chain, header) + rebalanceResult, err := system.RebalanceTreasury(state, chain, header) if err != nil { logger.Error("failed to execute treasury rebalancing. State not changed", "err", err) + } else { + // Leave the memo in the log for later contract finalization + isKIP103 := chain.Config().IsKIP103ForkBlock(header.Number) // because memo format differs between KIP-103 and KIP-160 + logger.Info("successfully executed treasury rebalancing", "memo", string(rebalanceResult.Memo(isKIP103))) } }