Skip to content

Commit

Permalink
[evm] proper handle refundSnapshot and upgrade go-ethereum release (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinxie committed Dec 19, 2022
1 parent 5d3910b commit 4149d95
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
34 changes: 21 additions & 13 deletions action/protocol/execution/evm/evmstatedbadapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,27 @@ func (stateDB *StateDBAdapter) RevertToSnapshot(snapshot int) {
// restore gas refund
if !stateDB.manualCorrectGasRefund {
stateDB.refund = stateDB.refundSnapshot[snapshot]
delete(stateDB.refundSnapshot, snapshot)
for i := snapshot + 1; ; i++ {
if _, ok := stateDB.refundSnapshot[i]; ok {
delete(stateDB.refundSnapshot, i)
} else {
break
}
}
}
// restore access list
stateDB.accessList = nil
stateDB.accessList = stateDB.accessListSnapshot[snapshot]
{
delete(stateDB.accessListSnapshot, snapshot)
for i := snapshot + 1; ; i++ {
if _, ok := stateDB.accessListSnapshot[i]; ok {
delete(stateDB.accessListSnapshot, i)
} else {
break
}
}
}
// restore logs and txLogs
if stateDB.revertLog {
Expand Down Expand Up @@ -624,19 +645,6 @@ func (stateDB *StateDBAdapter) RevertToSnapshot(snapshot int) {
}
}
}
// restore access list
stateDB.accessList = nil
stateDB.accessList = stateDB.accessListSnapshot[snapshot]
{
delete(stateDB.accessListSnapshot, snapshot)
for i := snapshot + 1; ; i++ {
if _, ok := stateDB.accessListSnapshot[i]; ok {
delete(stateDB.accessListSnapshot, i)
} else {
break
}
}
}
}

func (stateDB *StateDBAdapter) cachedContractAddrs() []hash.Hash160 {
Expand Down
6 changes: 6 additions & 0 deletions action/protocol/execution/evm/evmstatedbadapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,16 @@ func TestSnapshotRevertAndCommit(t *testing.T) {
require.Equal(1, len(stateDB.contractSnapshot))
require.Equal(1, len(stateDB.suicideSnapshot))
require.Equal(1, len(stateDB.preimageSnapshot))
require.Equal(1, len(stateDB.accessListSnapshot))
require.Equal(1, len(stateDB.refundSnapshot))
} else {
require.Equal(3, len(stateDB.contractSnapshot))
require.Equal(3, len(stateDB.suicideSnapshot))
require.Equal(3, len(stateDB.preimageSnapshot))
// refund fix and accessList are introduced after fixSnapshot
// so their snapshot are always properly cleared
require.Zero(len(stateDB.accessListSnapshot))
require.Zero(len(stateDB.refundSnapshot))
}
// commit snapshot 0's state
require.NoError(stateDB.CommitContracts())
Expand Down
2 changes: 1 addition & 1 deletion api/web3server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"go.uber.org/zap"

"github.com/iotexproject/iotex-core/action"
stakingabi "github.com/iotexproject/iotex-core/action/protocol/staking/ethabi"
rewardingabi "github.com/iotexproject/iotex-core/action/protocol/rewarding/ethabi"
stakingabi "github.com/iotexproject/iotex-core/action/protocol/staking/ethabi"
apitypes "github.com/iotexproject/iotex-core/api/types"
"github.com/iotexproject/iotex-core/pkg/log"
"github.com/iotexproject/iotex-core/pkg/tracer"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,6 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/ethereum/go-ethereum => github.com/iotexproject/go-ethereum v1.7.4-0.20221123031803-9e576f7b3e4b
replace github.com/ethereum/go-ethereum => github.com/iotexproject/go-ethereum v0.4.2

replace golang.org/x/xerrors => golang.org/x/xerrors v0.0.0-20190212162355-a5947ffaace3
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ github.com/influxdata/promql/v2 v2.12.0/go.mod h1:fxOPu+DY0bqCTCECchSRtWfc+0X19y
github.com/influxdata/roaring v0.4.13-0.20180809181101-fc520f41fab6/go.mod h1:bSgUQ7q5ZLSO+bKBGqJiCBGAl+9DxyW63zLTujjUlOE=
github.com/influxdata/tdigest v0.0.0-20181121200506-bf2b5ad3c0a9/go.mod h1:Js0mqiSBE6Ffsg94weZZ2c+v/ciT8QRHFOap7EKDrR0=
github.com/influxdata/usage-client v0.0.0-20160829180054-6d3895376368/go.mod h1:Wbbw6tYNvwa5dlB6304Sd+82Z3f7PmVZHVKU637d4po=
github.com/iotexproject/go-ethereum v1.7.4-0.20221123031803-9e576f7b3e4b h1:ImtTdFM8yaH8mYL4sd4idxHiV5J0r12B1SYiyBezdCs=
github.com/iotexproject/go-ethereum v1.7.4-0.20221123031803-9e576f7b3e4b/go.mod h1:Lt5WzjM07XlXc95YzrhosmR4J9Ahd6X2wyEV2SvGhk0=
github.com/iotexproject/go-ethereum v0.4.2 h1:aXfCHX4tL6/Gnh24p4KZGwiKmu63bjMrAAshPRBp6Pk=
github.com/iotexproject/go-ethereum v0.4.2/go.mod h1:Lt5WzjM07XlXc95YzrhosmR4J9Ahd6X2wyEV2SvGhk0=
github.com/iotexproject/go-fsm v1.0.0 h1:Zrg9JnNDUZg4Anpj6oa0Tk4+sXbHTpJzI0v5/Cj5N6A=
github.com/iotexproject/go-fsm v1.0.0/go.mod h1:t3aYXtCCcQxyS7oduQZyuUpPnVI4ddFTwbAagHN7fT0=
github.com/iotexproject/go-p2p v0.3.5 h1:F71XxYQtR25youD+dCXnMgtfiCKGUFh8KDIqU7u5xOk=
Expand Down

0 comments on commit 4149d95

Please sign in to comment.