Skip to content

Commit

Permalink
fix: minor (#106)
Browse files Browse the repository at this point in the history
* use atomic uint64

* remove redundant set
  • Loading branch information
beer-1 authored Nov 11, 2024
1 parent 381e983 commit 23ccbfb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 5 additions & 3 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"sync/atomic"

"cosmossdk.io/collections"
"cosmossdk.io/core/address"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -109,7 +110,8 @@ func NewKeeper(
panic(err)
}

execIndex := uint64(0)
execIndex := &atomic.Uint64{}
execIndex.Store(0)
k := &Keeper{
ac: ac,
cdc: cdc,
Expand All @@ -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)),
Expand Down
8 changes: 2 additions & 6 deletions x/evm/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,18 @@ 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 {
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
Expand Down

0 comments on commit 23ccbfb

Please sign in to comment.