mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
only include code hash for contracts
This commit is contained in:
parent
40968d8b13
commit
651229775e
2 changed files with 22 additions and 9 deletions
|
|
@ -17,7 +17,7 @@ func (a account) MarshalJSON() ([]byte, error) {
|
||||||
type account struct {
|
type account struct {
|
||||||
Balance *hexutil.Big `json:"balance,omitempty"`
|
Balance *hexutil.Big `json:"balance,omitempty"`
|
||||||
Code hexutil.Bytes `json:"code,omitempty"`
|
Code hexutil.Bytes `json:"code,omitempty"`
|
||||||
CodeHash common.Hash `json:"codeHash,omitempty"`
|
CodeHash *common.Hash `json:"codeHash,omitempty"`
|
||||||
Nonce uint64 `json:"nonce,omitempty"`
|
Nonce uint64 `json:"nonce,omitempty"`
|
||||||
Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
|
Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
@ -50,7 +50,7 @@ func (a *account) UnmarshalJSON(input []byte) error {
|
||||||
a.Code = *dec.Code
|
a.Code = *dec.Code
|
||||||
}
|
}
|
||||||
if dec.CodeHash != nil {
|
if dec.CodeHash != nil {
|
||||||
a.CodeHash = *dec.CodeHash
|
a.CodeHash = dec.CodeHash
|
||||||
}
|
}
|
||||||
if dec.Nonce != nil {
|
if dec.Nonce != nil {
|
||||||
a.Nonce = *dec.Nonce
|
a.Nonce = *dec.Nonce
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ type stateMap = map[common.Address]*account
|
||||||
type account struct {
|
type account struct {
|
||||||
Balance *big.Int `json:"balance,omitempty"`
|
Balance *big.Int `json:"balance,omitempty"`
|
||||||
Code []byte `json:"code,omitempty"`
|
Code []byte `json:"code,omitempty"`
|
||||||
CodeHash common.Hash `json:"codeHash,omitempty"`
|
CodeHash *common.Hash `json:"codeHash,omitempty"`
|
||||||
Nonce uint64 `json:"nonce,omitempty"`
|
Nonce uint64 `json:"nonce,omitempty"`
|
||||||
Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
|
Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
|
||||||
empty bool
|
empty bool
|
||||||
|
|
@ -258,9 +258,18 @@ func (t *prestateTracer) processDiffState() {
|
||||||
modified = true
|
modified = true
|
||||||
postAccount.Nonce = newNonce
|
postAccount.Nonce = newNonce
|
||||||
}
|
}
|
||||||
if newCodeHash != t.pre[addr].CodeHash {
|
prevCodeHash := common.Hash{}
|
||||||
|
if t.pre[addr].CodeHash != nil {
|
||||||
|
prevCodeHash = *t.pre[addr].CodeHash
|
||||||
|
}
|
||||||
|
// Empty code hashes are excluded from the prestate. Normalize
|
||||||
|
// the empty code hash to a zero hash to make it comparable.
|
||||||
|
if newCodeHash == types.EmptyCodeHash {
|
||||||
|
newCodeHash = common.Hash{}
|
||||||
|
}
|
||||||
|
if newCodeHash != prevCodeHash {
|
||||||
modified = true
|
modified = true
|
||||||
postAccount.CodeHash = newCodeHash
|
postAccount.CodeHash = &newCodeHash
|
||||||
}
|
}
|
||||||
if !t.config.DisableCode {
|
if !t.config.DisableCode {
|
||||||
newCode := t.env.StateDB.GetCode(addr)
|
newCode := t.env.StateDB.GetCode(addr)
|
||||||
|
|
@ -307,10 +316,14 @@ func (t *prestateTracer) lookupAccount(addr common.Address) {
|
||||||
}
|
}
|
||||||
|
|
||||||
acc := &account{
|
acc := &account{
|
||||||
Balance: t.env.StateDB.GetBalance(addr).ToBig(),
|
Balance: t.env.StateDB.GetBalance(addr).ToBig(),
|
||||||
Nonce: t.env.StateDB.GetNonce(addr),
|
Nonce: t.env.StateDB.GetNonce(addr),
|
||||||
Code: t.env.StateDB.GetCode(addr),
|
Code: t.env.StateDB.GetCode(addr),
|
||||||
CodeHash: t.env.StateDB.GetCodeHash(addr),
|
}
|
||||||
|
codeHash := t.env.StateDB.GetCodeHash(addr)
|
||||||
|
// If the code is empty, we don't need to store it in the prestate.
|
||||||
|
if codeHash != (common.Hash{}) && codeHash != types.EmptyCodeHash {
|
||||||
|
acc.CodeHash = &codeHash
|
||||||
}
|
}
|
||||||
if !acc.exists() {
|
if !acc.exists() {
|
||||||
acc.empty = true
|
acc.empty = true
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue