From fab444ce9325ca0acef5192810adc324a76ba26b Mon Sep 17 00:00:00 2001 From: beer-1 Date: Sun, 10 Nov 2024 01:22:01 +0900 Subject: [PATCH 1/2] use atomic uint64 --- x/evm/keeper/keeper.go | 8 +++++--- x/evm/state/statedb.go | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index 58cb461..5d69733 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "sync/atomic" "cosmossdk.io/collections" "cosmossdk.io/core/address" @@ -49,7 +50,7 @@ type Keeper struct { // execIndex is unique index for each execution, which is used // unique key for transient stores. - execIndex *uint64 + execIndex *atomic.Uint64 // transient store TSchema collections.Schema @@ -109,7 +110,8 @@ func NewKeeper( panic(err) } - execIndex := uint64(0) + execIndex := &atomic.Uint64{} + execIndex.Store(0) k := &Keeper{ ac: ac, cdc: cdc, @@ -130,7 +132,7 @@ func NewKeeper( Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), VMStore: collections.NewMap(sb, types.VMStorePrefix, "vm_store", collections.BytesKey, collections.BytesValue), - execIndex: &execIndex, + execIndex: execIndex, TransientVMStore: collections.NewMap(tsb, types.TransientVMStorePrefix, "transient_vm_store", collections.PairKeyCodec(collections.Uint64Key, collections.BytesKey), collections.BytesValue), TransientCreated: collections.NewKeySet(tsb, types.TransientCreatedPrefix, "transient_created", collections.PairKeyCodec(collections.Uint64Key, collections.BytesKey)), diff --git a/x/evm/state/statedb.go b/x/evm/state/statedb.go index 682f4b6..73f0791 100644 --- a/x/evm/state/statedb.go +++ b/x/evm/state/statedb.go @@ -73,13 +73,13 @@ func NewStateDB( transientLogSize collections.Map[uint64, uint64], transientAccessList collections.KeySet[collections.Pair[uint64, []byte]], transientRefund collections.Map[uint64, uint64], - execIndex *uint64, + execIndex *atomic.Uint64, // erc20 params evm callableEVM, erc20ABI *abi.ABI, feeContractAddr common.Address, ) (*StateDB, error) { - eidx := atomic.AddUint64(execIndex, 1) + eidx := execIndex.Add(1) err := transientLogSize.Set(ctx, eidx, 0) if err != nil { From b13dc86caf90f8012b1d81d2e31334571c7a311c Mon Sep 17 00:00:00 2001 From: beer-1 Date: Sun, 10 Nov 2024 01:27:52 +0900 Subject: [PATCH 2/2] remove redundant set --- x/evm/state/statedb.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/x/evm/state/statedb.go b/x/evm/state/statedb.go index 73f0791..bf92b6c 100644 --- a/x/evm/state/statedb.go +++ b/x/evm/state/statedb.go @@ -85,10 +85,6 @@ func NewStateDB( if err != nil { return nil, err } - err = transientLogSize.Set(ctx, eidx, 0) - if err != nil { - return nil, err - } err = transientRefund.Set(ctx, eidx, 0) if err != nil { return nil, err