mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 02:40:45 +00:00
parent
07e2609c25
commit
8f0ad36af6
3 changed files with 48 additions and 48 deletions
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/common"
|
"github.com/XinFinOrg/XDPoSChain/common"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
// journalEntry is a modification entry in the state change journal that can be
|
// journalEntry is a modification entry in the state change journal that can be
|
||||||
|
|
@ -87,35 +88,35 @@ func (j *journal) length() int {
|
||||||
type (
|
type (
|
||||||
// Changes to the account trie.
|
// Changes to the account trie.
|
||||||
createObjectChange struct {
|
createObjectChange struct {
|
||||||
account *common.Address
|
account common.Address
|
||||||
}
|
}
|
||||||
resetObjectChange struct {
|
resetObjectChange struct {
|
||||||
account *common.Address
|
account common.Address
|
||||||
prev *stateObject
|
prev *stateObject
|
||||||
prevdestruct bool
|
prevdestruct bool
|
||||||
}
|
}
|
||||||
selfDestructChange struct {
|
selfDestructChange struct {
|
||||||
account *common.Address
|
account common.Address
|
||||||
prev bool // whether account had already self-destructed
|
prev bool // whether account had already self-destructed
|
||||||
prevbalance *big.Int
|
prevbalance *big.Int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changes to individual accounts.
|
// Changes to individual accounts.
|
||||||
balanceChange struct {
|
balanceChange struct {
|
||||||
account *common.Address
|
account common.Address
|
||||||
prev *big.Int
|
prev *big.Int
|
||||||
}
|
}
|
||||||
nonceChange struct {
|
nonceChange struct {
|
||||||
account *common.Address
|
account common.Address
|
||||||
prev uint64
|
prev uint64
|
||||||
}
|
}
|
||||||
storageChange struct {
|
storageChange struct {
|
||||||
account *common.Address
|
account common.Address
|
||||||
key, prevalue common.Hash
|
key, prevalue common.Hash
|
||||||
}
|
}
|
||||||
codeChange struct {
|
codeChange struct {
|
||||||
account *common.Address
|
account common.Address
|
||||||
prevcode, prevhash []byte
|
prevCode []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changes to other state values.
|
// Changes to other state values.
|
||||||
|
|
@ -129,30 +130,30 @@ type (
|
||||||
hash common.Hash
|
hash common.Hash
|
||||||
}
|
}
|
||||||
touchChange struct {
|
touchChange struct {
|
||||||
account *common.Address
|
account common.Address
|
||||||
}
|
}
|
||||||
// Changes to the access list
|
// Changes to the access list
|
||||||
accessListAddAccountChange struct {
|
accessListAddAccountChange struct {
|
||||||
address *common.Address
|
address common.Address
|
||||||
}
|
}
|
||||||
accessListAddSlotChange struct {
|
accessListAddSlotChange struct {
|
||||||
address *common.Address
|
address common.Address
|
||||||
slot *common.Hash
|
slot common.Hash
|
||||||
}
|
}
|
||||||
|
|
||||||
transientStorageChange struct {
|
transientStorageChange struct {
|
||||||
account *common.Address
|
account common.Address
|
||||||
key, prevalue common.Hash
|
key, prevalue common.Hash
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (ch createObjectChange) revert(s *StateDB) {
|
func (ch createObjectChange) revert(s *StateDB) {
|
||||||
delete(s.stateObjects, *ch.account)
|
delete(s.stateObjects, ch.account)
|
||||||
delete(s.stateObjectsDirty, *ch.account)
|
delete(s.stateObjectsDirty, ch.account)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch createObjectChange) dirtied() *common.Address {
|
func (ch createObjectChange) dirtied() *common.Address {
|
||||||
return ch.account
|
return &ch.account
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch resetObjectChange) revert(s *StateDB) {
|
func (ch resetObjectChange) revert(s *StateDB) {
|
||||||
|
|
@ -163,11 +164,11 @@ func (ch resetObjectChange) revert(s *StateDB) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch resetObjectChange) dirtied() *common.Address {
|
func (ch resetObjectChange) dirtied() *common.Address {
|
||||||
return ch.account
|
return &ch.account
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch selfDestructChange) revert(s *StateDB) {
|
func (ch selfDestructChange) revert(s *StateDB) {
|
||||||
obj := s.getStateObject(*ch.account)
|
obj := s.getStateObject(ch.account)
|
||||||
if obj != nil {
|
if obj != nil {
|
||||||
obj.selfDestructed = ch.prev
|
obj.selfDestructed = ch.prev
|
||||||
obj.setBalance(ch.prevbalance)
|
obj.setBalance(ch.prevbalance)
|
||||||
|
|
@ -175,7 +176,7 @@ func (ch selfDestructChange) revert(s *StateDB) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch selfDestructChange) dirtied() *common.Address {
|
func (ch selfDestructChange) dirtied() *common.Address {
|
||||||
return ch.account
|
return &ch.account
|
||||||
}
|
}
|
||||||
|
|
||||||
var ripemd = common.HexToAddress("0000000000000000000000000000000000000003")
|
var ripemd = common.HexToAddress("0000000000000000000000000000000000000003")
|
||||||
|
|
@ -184,43 +185,43 @@ func (ch touchChange) revert(s *StateDB) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch touchChange) dirtied() *common.Address {
|
func (ch touchChange) dirtied() *common.Address {
|
||||||
return ch.account
|
return &ch.account
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch balanceChange) revert(s *StateDB) {
|
func (ch balanceChange) revert(s *StateDB) {
|
||||||
s.getStateObject(*ch.account).setBalance(ch.prev)
|
s.getStateObject(ch.account).setBalance(ch.prev)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch balanceChange) dirtied() *common.Address {
|
func (ch balanceChange) dirtied() *common.Address {
|
||||||
return ch.account
|
return &ch.account
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch nonceChange) revert(s *StateDB) {
|
func (ch nonceChange) revert(s *StateDB) {
|
||||||
s.getStateObject(*ch.account).setNonce(ch.prev)
|
s.getStateObject(ch.account).setNonce(ch.prev)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch nonceChange) dirtied() *common.Address {
|
func (ch nonceChange) dirtied() *common.Address {
|
||||||
return ch.account
|
return &ch.account
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch codeChange) revert(s *StateDB) {
|
func (ch codeChange) revert(s *StateDB) {
|
||||||
s.getStateObject(*ch.account).setCode(common.BytesToHash(ch.prevhash), ch.prevcode)
|
s.getStateObject(ch.account).setCode(crypto.Keccak256Hash(ch.prevCode), ch.prevCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch codeChange) dirtied() *common.Address {
|
func (ch codeChange) dirtied() *common.Address {
|
||||||
return ch.account
|
return &ch.account
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch storageChange) revert(s *StateDB) {
|
func (ch storageChange) revert(s *StateDB) {
|
||||||
s.getStateObject(*ch.account).setState(ch.key, ch.prevalue)
|
s.getStateObject(ch.account).setState(ch.key, ch.prevalue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch storageChange) dirtied() *common.Address {
|
func (ch storageChange) dirtied() *common.Address {
|
||||||
return ch.account
|
return &ch.account
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch transientStorageChange) revert(s *StateDB) {
|
func (ch transientStorageChange) revert(s *StateDB) {
|
||||||
s.setTransientState(*ch.account, ch.key, ch.prevalue)
|
s.setTransientState(ch.account, ch.key, ch.prevalue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch transientStorageChange) dirtied() *common.Address {
|
func (ch transientStorageChange) dirtied() *common.Address {
|
||||||
|
|
@ -267,7 +268,7 @@ func (ch accessListAddAccountChange) revert(s *StateDB) {
|
||||||
(addr) at this point, since no storage adds can remain when come upon
|
(addr) at this point, since no storage adds can remain when come upon
|
||||||
a single (addr) change.
|
a single (addr) change.
|
||||||
*/
|
*/
|
||||||
s.accessList.DeleteAddress(*ch.address)
|
s.accessList.DeleteAddress(ch.address)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch accessListAddAccountChange) dirtied() *common.Address {
|
func (ch accessListAddAccountChange) dirtied() *common.Address {
|
||||||
|
|
@ -275,7 +276,7 @@ func (ch accessListAddAccountChange) dirtied() *common.Address {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch accessListAddSlotChange) revert(s *StateDB) {
|
func (ch accessListAddSlotChange) revert(s *StateDB) {
|
||||||
s.accessList.DeleteSlot(*ch.address, *ch.slot)
|
s.accessList.DeleteSlot(ch.address, ch.slot)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch accessListAddSlotChange) dirtied() *common.Address {
|
func (ch accessListAddSlotChange) dirtied() *common.Address {
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ func (s *stateObject) markSelfdestructed() {
|
||||||
|
|
||||||
func (s *stateObject) touch() {
|
func (s *stateObject) touch() {
|
||||||
s.db.journal.append(touchChange{
|
s.db.journal.append(touchChange{
|
||||||
account: &s.address,
|
account: s.address,
|
||||||
})
|
})
|
||||||
if s.address == ripemd {
|
if s.address == ripemd {
|
||||||
// Explicitly put it in the dirty-cache, which is otherwise generated from
|
// Explicitly put it in the dirty-cache, which is otherwise generated from
|
||||||
|
|
@ -226,7 +226,7 @@ func (s *stateObject) SetState(db Database, key, value common.Hash) {
|
||||||
}
|
}
|
||||||
// New value is different, update and journal the change
|
// New value is different, update and journal the change
|
||||||
s.db.journal.append(storageChange{
|
s.db.journal.append(storageChange{
|
||||||
account: &s.address,
|
account: s.address,
|
||||||
key: key,
|
key: key,
|
||||||
prevalue: prev,
|
prevalue: prev,
|
||||||
})
|
})
|
||||||
|
|
@ -363,7 +363,7 @@ func (s *stateObject) SubBalance(amount *big.Int, reason tracing.BalanceChangeRe
|
||||||
|
|
||||||
func (s *stateObject) SetBalance(amount *big.Int, reason tracing.BalanceChangeReason) {
|
func (s *stateObject) SetBalance(amount *big.Int, reason tracing.BalanceChangeReason) {
|
||||||
s.db.journal.append(balanceChange{
|
s.db.journal.append(balanceChange{
|
||||||
account: &s.address,
|
account: s.address,
|
||||||
prev: new(big.Int).Set(s.data.Balance),
|
prev: new(big.Int).Set(s.data.Balance),
|
||||||
})
|
})
|
||||||
if s.db.logger != nil && s.db.logger.OnBalanceChange != nil {
|
if s.db.logger != nil && s.db.logger.OnBalanceChange != nil {
|
||||||
|
|
@ -434,14 +434,13 @@ func (s *stateObject) CodeSize(db Database) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stateObject) SetCode(codeHash common.Hash, code []byte) {
|
func (s *stateObject) SetCode(codeHash common.Hash, code []byte) {
|
||||||
prevcode := s.Code(s.db.db)
|
prevCode := s.Code(s.db.db)
|
||||||
s.db.journal.append(codeChange{
|
s.db.journal.append(codeChange{
|
||||||
account: &s.address,
|
account: s.address,
|
||||||
prevhash: s.CodeHash(),
|
prevCode: prevCode,
|
||||||
prevcode: prevcode,
|
|
||||||
})
|
})
|
||||||
if s.db.logger != nil && s.db.logger.OnCodeChange != nil {
|
if s.db.logger != nil && s.db.logger.OnCodeChange != nil {
|
||||||
s.db.logger.OnCodeChange(s.address, common.BytesToHash(s.CodeHash()), prevcode, codeHash, code)
|
s.db.logger.OnCodeChange(s.address, common.BytesToHash(s.CodeHash()), prevCode, codeHash, code)
|
||||||
}
|
}
|
||||||
s.setCode(codeHash, code)
|
s.setCode(codeHash, code)
|
||||||
}
|
}
|
||||||
|
|
@ -454,7 +453,7 @@ func (s *stateObject) setCode(codeHash common.Hash, code []byte) {
|
||||||
|
|
||||||
func (s *stateObject) SetNonce(nonce uint64) {
|
func (s *stateObject) SetNonce(nonce uint64) {
|
||||||
s.db.journal.append(nonceChange{
|
s.db.journal.append(nonceChange{
|
||||||
account: &s.address,
|
account: s.address,
|
||||||
prev: s.data.Nonce,
|
prev: s.data.Nonce,
|
||||||
})
|
})
|
||||||
if s.db.logger != nil && s.db.logger.OnNonceChange != nil {
|
if s.db.logger != nil && s.db.logger.OnNonceChange != nil {
|
||||||
|
|
|
||||||
|
|
@ -463,7 +463,7 @@ func (s *StateDB) SelfDestruct(addr common.Address) {
|
||||||
n = new(big.Int)
|
n = new(big.Int)
|
||||||
)
|
)
|
||||||
s.journal.append(selfDestructChange{
|
s.journal.append(selfDestructChange{
|
||||||
account: &addr,
|
account: addr,
|
||||||
prev: stateObject.selfDestructed,
|
prev: stateObject.selfDestructed,
|
||||||
prevbalance: prev,
|
prevbalance: prev,
|
||||||
})
|
})
|
||||||
|
|
@ -494,7 +494,7 @@ func (s *StateDB) SetTransientState(addr common.Address, key, value common.Hash)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.journal.append(transientStorageChange{
|
s.journal.append(transientStorageChange{
|
||||||
account: &addr,
|
account: addr,
|
||||||
key: key,
|
key: key,
|
||||||
prevalue: prev,
|
prevalue: prev,
|
||||||
})
|
})
|
||||||
|
|
@ -604,13 +604,13 @@ func (s *StateDB) createObject(addr common.Address) (newobj, prev *stateObject)
|
||||||
prev = s.getDeletedStateObject(addr) // Note, prev might have been deleted, we need that!
|
prev = s.getDeletedStateObject(addr) // Note, prev might have been deleted, we need that!
|
||||||
newobj = newObject(s, addr, types.StateAccount{})
|
newobj = newObject(s, addr, types.StateAccount{})
|
||||||
if prev == nil {
|
if prev == nil {
|
||||||
s.journal.append(createObjectChange{account: &addr})
|
s.journal.append(createObjectChange{account: addr})
|
||||||
} else {
|
} else {
|
||||||
_, prevdestruct := s.stateObjectsDestruct[prev.address]
|
_, prevdestruct := s.stateObjectsDestruct[prev.address]
|
||||||
if !prevdestruct {
|
if !prevdestruct {
|
||||||
s.stateObjectsDestruct[prev.address] = struct{}{}
|
s.stateObjectsDestruct[prev.address] = struct{}{}
|
||||||
}
|
}
|
||||||
s.journal.append(resetObjectChange{account: &addr, prev: prev, prevdestruct: prevdestruct})
|
s.journal.append(resetObjectChange{account: addr, prev: prev, prevdestruct: prevdestruct})
|
||||||
}
|
}
|
||||||
|
|
||||||
newobj.created = true
|
newobj.created = true
|
||||||
|
|
@ -999,7 +999,7 @@ func (s *StateDB) Prepare(rules params.Rules, sender, coinbase common.Address, d
|
||||||
// AddAddressToAccessList adds the given address to the access list
|
// AddAddressToAccessList adds the given address to the access list
|
||||||
func (s *StateDB) AddAddressToAccessList(addr common.Address) {
|
func (s *StateDB) AddAddressToAccessList(addr common.Address) {
|
||||||
if s.accessList.AddAddress(addr) {
|
if s.accessList.AddAddress(addr) {
|
||||||
s.journal.append(accessListAddAccountChange{&addr})
|
s.journal.append(accessListAddAccountChange{addr})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1011,12 +1011,12 @@ func (s *StateDB) AddSlotToAccessList(addr common.Address, slot common.Hash) {
|
||||||
// scope of 'address' without having the 'address' become already added
|
// scope of 'address' without having the 'address' become already added
|
||||||
// to the access list (via call-variant, create, etc).
|
// to the access list (via call-variant, create, etc).
|
||||||
// Better safe than sorry, though
|
// Better safe than sorry, though
|
||||||
s.journal.append(accessListAddAccountChange{&addr})
|
s.journal.append(accessListAddAccountChange{addr})
|
||||||
}
|
}
|
||||||
if slotMod {
|
if slotMod {
|
||||||
s.journal.append(accessListAddSlotChange{
|
s.journal.append(accessListAddSlotChange{
|
||||||
address: &addr,
|
address: addr,
|
||||||
slot: &slot,
|
slot: slot,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue