From b32a0c6277e43fefb9a123e7562440d92fb7225d Mon Sep 17 00:00:00 2001 From: shawn <36943337+lxex@users.noreply.github.com> Date: Thu, 5 Aug 2021 09:56:28 +0800 Subject: [PATCH 1/3] =?UTF-8?q?There=20is=20no=20need=20to=20call=20?= =?UTF-8?q?=E2=80=99IsLondon=E2=80=98=20twice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no need to call ’IsLondon‘ twice, which may affect TPS --- core/state_transition.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/state_transition.go b/core/state_transition.go index b5b0ae990a41..eb0e7e9b9cbc 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -311,7 +311,9 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { st.state.SetNonce(msg.From(), st.state.GetNonce(sender.Address())+1) ret, st.gas, vmerr = st.evm.Call(sender, st.to(), st.data, st.gas, st.value) } - if !st.evm.ChainConfig().IsLondon(st.evm.Context.BlockNumber) { + + isLondon := st.evm.ChainConfig().IsLondon(st.evm.Context.BlockNumber) + if !isLondon { // Before EIP-3529: refunds were capped to gasUsed / 2 st.refundGas(params.RefundQuotient) } else { @@ -319,7 +321,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { st.refundGas(params.RefundQuotientEIP3529) } effectiveTip := st.gasPrice - if st.evm.ChainConfig().IsLondon(st.evm.Context.BlockNumber) { + if isLondon { effectiveTip = cmath.BigMin(st.gasTipCap, new(big.Int).Sub(st.gasFeeCap, st.evm.Context.BaseFee)) } st.state.AddBalance(st.evm.Context.Coinbase, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), effectiveTip)) From 94f6474c9b18d4c9ca8a49f459be37257be02c61 Mon Sep 17 00:00:00 2001 From: lxex Date: Mon, 9 Aug 2021 18:31:43 +0800 Subject: [PATCH 2/3] To keep the naming style consistent, use 'london' instead of 'isLondon' --- core/state_transition.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/state_transition.go b/core/state_transition.go index eb0e7e9b9cbc..f739cfbac5c2 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -311,9 +311,9 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { st.state.SetNonce(msg.From(), st.state.GetNonce(sender.Address())+1) ret, st.gas, vmerr = st.evm.Call(sender, st.to(), st.data, st.gas, st.value) } - - isLondon := st.evm.ChainConfig().IsLondon(st.evm.Context.BlockNumber) - if !isLondon { + + london := st.evm.ChainConfig().IsLondon(st.evm.Context.BlockNumber) + if !london { // Before EIP-3529: refunds were capped to gasUsed / 2 st.refundGas(params.RefundQuotient) } else { @@ -321,7 +321,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { st.refundGas(params.RefundQuotientEIP3529) } effectiveTip := st.gasPrice - if isLondon { + if london { effectiveTip = cmath.BigMin(st.gasTipCap, new(big.Int).Sub(st.gasFeeCap, st.evm.Context.BaseFee)) } st.state.AddBalance(st.evm.Context.Coinbase, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), effectiveTip)) From 2d093f39f10e4cb15bd2e3db501e948bf73a82bb Mon Sep 17 00:00:00 2001 From: lxex Date: Mon, 9 Aug 2021 18:44:38 +0800 Subject: [PATCH 3/3] Move 'london' to the right place --- core/state_transition.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/state_transition.go b/core/state_transition.go index f739cfbac5c2..3782cce51cf3 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -279,6 +279,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { sender := vm.AccountRef(msg.From()) homestead := st.evm.ChainConfig().IsHomestead(st.evm.Context.BlockNumber) istanbul := st.evm.ChainConfig().IsIstanbul(st.evm.Context.BlockNumber) + london := st.evm.ChainConfig().IsLondon(st.evm.Context.BlockNumber) contractCreation := msg.To() == nil // Check clauses 4-5, subtract intrinsic gas if everything is correct @@ -312,7 +313,6 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { ret, st.gas, vmerr = st.evm.Call(sender, st.to(), st.data, st.gas, st.value) } - london := st.evm.ChainConfig().IsLondon(st.evm.Context.BlockNumber) if !london { // Before EIP-3529: refunds were capped to gasUsed / 2 st.refundGas(params.RefundQuotient)