Skip to content

Commit

Permalink
optimize code to avoid reinit cdc (#895)
Browse files Browse the repository at this point in the history
  • Loading branch information
KamiD authored Jun 2, 2021
1 parent 822e664 commit 544d652
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions app/rpc/namespaces/eth/simulation/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,27 @@ type InternalDba struct {
ocProxy QueryOnChainProxy
}

func newCdc() *codec.Codec {
var gSimulateCdc *codec.Codec = nil
var gSimulateChainConfig []byte = nil

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

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

func NewInternalDba(qoc QueryOnChainProxy) InternalDba {
Expand All @@ -186,10 +202,9 @@ func (i InternalDba) NewStore(parent store.KVStore, Prefix []byte) evmtypes.Stor
return nil
}

cdc := newCdc()
switch Prefix[0] {
case evmtypes.KeyPrefixChainConfig[0]:
return ConfigStore{defaultConfig: cdc.MustMarshalBinaryBare(evmtypes.DefaultChainConfig())}
return ConfigStore{defaultConfig: instanceOfChainConfig()}
case evmtypes.KeyPrefixBloom[0]:
return BloomStore{}
case evmtypes.KeyPrefixStorage[0]:
Expand Down

0 comments on commit 544d652

Please sign in to comment.