From fbd6024240f89114e0b0b99a00072284c0c82d1d Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Thu, 11 Dec 2025 10:51:03 +0800 Subject: [PATCH] eth/tracers, cmd/workload: use standard account for json unmarshal --- cmd/workload/prooftestgen.go | 2 +- eth/tracers/native/gen_account_json.go | 32 +++++++++++++------------- eth/tracers/native/prestate.go | 12 +++++----- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/cmd/workload/prooftestgen.go b/cmd/workload/prooftestgen.go index abc68af098..5d92eea114 100644 --- a/cmd/workload/prooftestgen.go +++ b/cmd/workload/prooftestgen.go @@ -223,7 +223,7 @@ func genStorageProof(cli *client, startBlock uint64, endBlock uint64, number int log.Error("Failed to marshal data", "err", err) continue } - var accounts map[common.Address]*native.PrestateAccount + var accounts map[common.Address]*types.Account if err := json.Unmarshal(blob, &accounts); err != nil { log.Error("Failed to decode trace result", "blockNumber", blockNumber, "hash", tx.Hash(), "err", err) continue diff --git a/eth/tracers/native/gen_account_json.go b/eth/tracers/native/gen_account_json.go index 185220ff59..5fec2648b7 100644 --- a/eth/tracers/native/gen_account_json.go +++ b/eth/tracers/native/gen_account_json.go @@ -13,50 +13,50 @@ import ( var _ = (*accountMarshaling)(nil) // MarshalJSON marshals as JSON. -func (p PrestateAccount) MarshalJSON() ([]byte, error) { - type PrestateAccount struct { +func (a account) MarshalJSON() ([]byte, error) { + type account struct { Balance *hexutil.Big `json:"balance,omitempty"` Code hexutil.Bytes `json:"code,omitempty"` CodeHash *common.Hash `json:"codeHash,omitempty"` Nonce uint64 `json:"nonce,omitempty"` Storage map[common.Hash]common.Hash `json:"storage,omitempty"` } - var enc PrestateAccount - enc.Balance = (*hexutil.Big)(p.Balance) - enc.Code = p.Code - enc.CodeHash = p.CodeHash - enc.Nonce = p.Nonce - enc.Storage = p.Storage + var enc account + enc.Balance = (*hexutil.Big)(a.Balance) + enc.Code = a.Code + enc.CodeHash = a.CodeHash + enc.Nonce = a.Nonce + enc.Storage = a.Storage return json.Marshal(&enc) } // UnmarshalJSON unmarshals from JSON. -func (p *PrestateAccount) UnmarshalJSON(input []byte) error { - type PrestateAccount struct { +func (a *account) UnmarshalJSON(input []byte) error { + type account struct { Balance *hexutil.Big `json:"balance,omitempty"` Code *hexutil.Bytes `json:"code,omitempty"` CodeHash *common.Hash `json:"codeHash,omitempty"` Nonce *uint64 `json:"nonce,omitempty"` Storage map[common.Hash]common.Hash `json:"storage,omitempty"` } - var dec PrestateAccount + var dec account if err := json.Unmarshal(input, &dec); err != nil { return err } if dec.Balance != nil { - p.Balance = (*big.Int)(dec.Balance) + a.Balance = (*big.Int)(dec.Balance) } if dec.Code != nil { - p.Code = *dec.Code + a.Code = *dec.Code } if dec.CodeHash != nil { - p.CodeHash = dec.CodeHash + a.CodeHash = dec.CodeHash } if dec.Nonce != nil { - p.Nonce = *dec.Nonce + a.Nonce = *dec.Nonce } if dec.Storage != nil { - p.Storage = dec.Storage + a.Storage = dec.Storage } return nil } diff --git a/eth/tracers/native/prestate.go b/eth/tracers/native/prestate.go index 87312e2b5e..159a91b310 100644 --- a/eth/tracers/native/prestate.go +++ b/eth/tracers/native/prestate.go @@ -35,15 +35,15 @@ import ( "github.com/ethereum/go-ethereum/params" ) -//go:generate go run github.com/fjl/gencodec -type PrestateAccount -field-override accountMarshaling -out gen_account_json.go +//go:generate go run github.com/fjl/gencodec -type account -field-override accountMarshaling -out gen_account_json.go func init() { tracers.DefaultDirectory.Register("prestateTracer", newPrestateTracer, false) } -type stateMap = map[common.Address]*PrestateAccount +type stateMap = map[common.Address]*account -type PrestateAccount struct { +type account struct { Balance *big.Int `json:"balance,omitempty"` Code []byte `json:"code,omitempty"` CodeHash *common.Hash `json:"codeHash,omitempty"` @@ -52,7 +52,7 @@ type PrestateAccount struct { empty bool } -func (a *PrestateAccount) exists() bool { +func (a *account) exists() bool { return a.Nonce > 0 || len(a.Code) > 0 || len(a.Storage) > 0 || (a.Balance != nil && a.Balance.Sign() != 0) } @@ -253,7 +253,7 @@ func (t *prestateTracer) processDiffState() { continue } modified := false - postAccount := &PrestateAccount{Storage: make(map[common.Hash]common.Hash)} + postAccount := &account{Storage: make(map[common.Hash]common.Hash)} newBalance := t.env.StateDB.GetBalance(addr).ToBig() newNonce := t.env.StateDB.GetNonce(addr) newCodeHash := t.env.StateDB.GetCodeHash(addr) @@ -323,7 +323,7 @@ func (t *prestateTracer) lookupAccount(addr common.Address) { return } - acc := &PrestateAccount{ + acc := &account{ Balance: t.env.StateDB.GetBalance(addr).ToBig(), Nonce: t.env.StateDB.GetNonce(addr), Code: t.env.StateDB.GetCode(addr),