Skip to content

Commit

Permalink
Merge PR:concurrent safe cdc&config singleton (#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilovers authored Jun 3, 2021
1 parent 544d652 commit 0442dd6
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions app/rpc/namespaces/eth/simulation/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package simulation

import (
"encoding/binary"
"github.com/okex/exchain/x/evm"
"sync"

"github.com/cosmos/cosmos-sdk/codec"
store "github.com/cosmos/cosmos-sdk/store/types"
Expand All @@ -19,7 +21,6 @@ import (
"github.com/okex/exchain/x/backend"
"github.com/okex/exchain/x/dex"
distr "github.com/okex/exchain/x/distribution"
"github.com/okex/exchain/x/evm"
evmtypes "github.com/okex/exchain/x/evm/types"
"github.com/okex/exchain/x/evm/watcher"
"github.com/okex/exchain/x/farm"
Expand Down Expand Up @@ -169,26 +170,28 @@ type InternalDba struct {
ocProxy QueryOnChainProxy
}

var gSimulateCdc *codec.Codec = nil
var gSimulateChainConfig []byte = nil
var (
gSimulateCdc *codec.Codec
cdcOnce sync.Once
gSimulateChainConfig []byte
configOnce sync.Once
)

func instanceOfCdc() *codec.Codec {
if gSimulateCdc != nil {
return gSimulateCdc
}
module := evm.AppModuleBasic{}
cdc := codec.New()
module.RegisterCodec(cdc)
gSimulateCdc = cdc
cdcOnce.Do(func() {
module := evm.AppModuleBasic{}
cdc := codec.New()
module.RegisterCodec(cdc)
gSimulateCdc = cdc
})
return gSimulateCdc
}

func instanceOfChainConfig() []byte {
if gSimulateChainConfig != nil {
return gSimulateChainConfig
}
cdc := instanceOfCdc()
gSimulateChainConfig = cdc.MustMarshalBinaryBare(evmtypes.DefaultChainConfig())
configOnce.Do(func() {
cdc := instanceOfCdc()
gSimulateChainConfig = cdc.MustMarshalBinaryBare(evmtypes.DefaultChainConfig())
})
return gSimulateChainConfig
}

Expand Down

0 comments on commit 0442dd6

Please sign in to comment.