Skip to content

Commit

Permalink
Merge PR:fix inconsistent bytecode via call eth_getCode (#847)
Browse files Browse the repository at this point in the history
  • Loading branch information
KamiD authored Apr 26, 2021
1 parent f4bda37 commit 5edaa40
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion x/evm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ func handleMsgEthereumTx(ctx sdk.Context, k *Keeper, msg types.MsgEthereumTx) (*
k.LogSize = st.Csdb.GetLogSize()
k.Watcher.SaveTransactionReceipt(watcher.TransactionSuccess, msg, common.BytesToHash(txHash), uint64(k.TxCount-1), resultData, ctx.GasMeter().GasConsumed())
if msg.Data.Recipient == nil {
k.Watcher.SaveContractCode(resultData.ContractAddress, msg.Data.Payload)
code := st.Csdb.GetCacheCode(resultData.ContractAddress)
if code != nil {
k.Watcher.SaveContractCode(resultData.ContractAddress, code)
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions x/evm/types/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ type CommitStateDB struct {
lock sync.Mutex

params *Params

codeCache map[ethcmn.Address][]byte
}

// newCommitStateDB returns a reference to a newly initialized CommitStateDB
Expand All @@ -121,6 +123,7 @@ func newCommitStateDB(
validRevisions: []revision{},
accessList: newAccessList(),
logs: []*ethtypes.Log{},
codeCache: make(map[ethcmn.Address][]byte, 0),
}
}

Expand All @@ -144,6 +147,7 @@ func CreateEmptyCommitStateDB(csdbParams CommitStateDBParams, ctx sdk.Context) *
accessList: newAccessList(),
logSize: 0,
logs: []*ethtypes.Log{},
codeCache: make(map[ethcmn.Address][]byte, 0),
}
}

Expand All @@ -153,6 +157,14 @@ func (csdb *CommitStateDB) WithContext(ctx sdk.Context) *CommitStateDB {
return csdb
}

func (csdb *CommitStateDB) GetCacheCode(addr ethcmn.Address) []byte {
code, ok := csdb.codeCache[addr]
if ok {
return code
}
return nil
}

// ----------------------------------------------------------------------------
// Setters
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -216,6 +228,7 @@ func (csdb *CommitStateDB) SetCode(addr ethcmn.Address, code []byte) {
if so != nil {
so.SetCode(ethcrypto.Keccak256Hash(code), code)
}
csdb.codeCache[addr] = code
}

// ----------------------------------------------------------------------------
Expand Down

0 comments on commit 5edaa40

Please sign in to comment.