diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index 64fb107..7bed3df 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 @@ -110,7 +111,8 @@ func NewKeeper( panic(err) } - execIndex := uint64(0) + execIndex := &atomic.Uint64{} + execIndex.Store(0) k := &Keeper{ ac: ac, cdc: cdc, @@ -131,7 +133,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 {