Skip to content

Commit

Permalink
compatibility with geth - of stateDiff encoding (#11362)
Browse files Browse the repository at this point in the history
cherry pick of #10531

Co-authored-by: boyuan-chen <46272347+boyuan-chen@users.noreply.github.com>
  • Loading branch information
AskAlexSharov and boyuan-chen authored Jul 27, 2024
1 parent ea49def commit 4d45aa9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 5 additions & 5 deletions turbo/adapter/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ func (args *CallArgs) ToMessage(globalGasCap uint64, baseFee *uint256.Int) (type
// if statDiff is set, all diff will be applied first and then execute the call
// message.
type Account struct {
Nonce *hexutil.Uint64 `json:"nonce"`
Code *hexutility.Bytes `json:"code"`
Balance **hexutil.Big `json:"balance"`
State *map[libcommon.Hash]uint256.Int `json:"state"`
StateDiff *map[libcommon.Hash]uint256.Int `json:"stateDiff"`
Nonce *hexutil.Uint64 `json:"nonce"`
Code *hexutility.Bytes `json:"code"`
Balance **hexutil.Big `json:"balance"`
State *map[libcommon.Hash]libcommon.Hash `json:"state"`
StateDiff *map[libcommon.Hash]libcommon.Hash `json:"stateDiff"`
}

func NewRevertError(result *core.ExecutionResult) *RevertError {
Expand Down
10 changes: 8 additions & 2 deletions turbo/adapter/ethapi/state_overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ func (overrides *StateOverrides) Override(state *state.IntraBlockState) error {
}
// Replace entire state if caller requires.
if account.State != nil {
state.SetStorage(addr, *account.State)
intState := map[libcommon.Hash]uint256.Int{}
for key, value := range *account.State {
intValue := new(uint256.Int).SetBytes32(value.Bytes())
intState[key] = *intValue
}
state.SetStorage(addr, intState)
}
// Apply state diff into specified accounts.
if account.StateDiff != nil {
for key, value := range *account.StateDiff {
key := key
state.SetState(addr, &key, value)
intValue := new(uint256.Int).SetBytes32(value.Bytes())
state.SetState(addr, &key, *intValue)
}
}
}
Expand Down

0 comments on commit 4d45aa9

Please sign in to comment.