mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 12:16:44 +00:00
core/state: reduce allocations in journal
reduces overall block building allocations by 1%
This commit is contained in:
parent
95b0563898
commit
35082b286f
1 changed files with 33 additions and 32 deletions
|
|
@ -39,7 +39,8 @@ type journalEntry interface {
|
||||||
revert(*StateDB)
|
revert(*StateDB)
|
||||||
|
|
||||||
// dirtied returns the Ethereum address modified by this journal entry.
|
// dirtied returns the Ethereum address modified by this journal entry.
|
||||||
dirtied() *common.Address
|
// indicates false if no address was changed.
|
||||||
|
dirtied() (common.Address, bool)
|
||||||
|
|
||||||
// copy returns a deep-copied journal entry.
|
// copy returns a deep-copied journal entry.
|
||||||
copy() journalEntry
|
copy() journalEntry
|
||||||
|
|
@ -100,8 +101,8 @@ func (j *journal) revertToSnapshot(revid int, s *StateDB) {
|
||||||
// append inserts a new modification entry to the end of the change journal.
|
// append inserts a new modification entry to the end of the change journal.
|
||||||
func (j *journal) append(entry journalEntry) {
|
func (j *journal) append(entry journalEntry) {
|
||||||
j.entries = append(j.entries, entry)
|
j.entries = append(j.entries, entry)
|
||||||
if addr := entry.dirtied(); addr != nil {
|
if addr, dirty := entry.dirtied(); dirty {
|
||||||
j.dirties[*addr]++
|
j.dirties[addr]++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,9 +114,9 @@ func (j *journal) revert(statedb *StateDB, snapshot int) {
|
||||||
j.entries[i].revert(statedb)
|
j.entries[i].revert(statedb)
|
||||||
|
|
||||||
// Drop any dirty tracking induced by the change
|
// Drop any dirty tracking induced by the change
|
||||||
if addr := j.entries[i].dirtied(); addr != nil {
|
if addr, dirty := j.entries[i].dirtied(); dirty {
|
||||||
if j.dirties[*addr]--; j.dirties[*addr] == 0 {
|
if j.dirties[addr]--; j.dirties[addr] == 0 {
|
||||||
delete(j.dirties, *addr)
|
delete(j.dirties, addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -294,8 +295,8 @@ func (ch createObjectChange) revert(s *StateDB) {
|
||||||
delete(s.stateObjects, ch.account)
|
delete(s.stateObjects, ch.account)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch createObjectChange) dirtied() *common.Address {
|
func (ch createObjectChange) dirtied() (common.Address, bool) {
|
||||||
return &ch.account
|
return ch.account, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch createObjectChange) copy() journalEntry {
|
func (ch createObjectChange) copy() journalEntry {
|
||||||
|
|
@ -308,8 +309,8 @@ func (ch createContractChange) revert(s *StateDB) {
|
||||||
s.getStateObject(ch.account).newContract = false
|
s.getStateObject(ch.account).newContract = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch createContractChange) dirtied() *common.Address {
|
func (ch createContractChange) dirtied() (common.Address, bool) {
|
||||||
return nil
|
return common.Address{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch createContractChange) copy() journalEntry {
|
func (ch createContractChange) copy() journalEntry {
|
||||||
|
|
@ -325,8 +326,8 @@ func (ch selfDestructChange) revert(s *StateDB) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch selfDestructChange) dirtied() *common.Address {
|
func (ch selfDestructChange) dirtied() (common.Address, bool) {
|
||||||
return &ch.account
|
return ch.account, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch selfDestructChange) copy() journalEntry {
|
func (ch selfDestructChange) copy() journalEntry {
|
||||||
|
|
@ -340,8 +341,8 @@ var ripemd = common.HexToAddress("0000000000000000000000000000000000000003")
|
||||||
func (ch touchChange) revert(s *StateDB) {
|
func (ch touchChange) revert(s *StateDB) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch touchChange) dirtied() *common.Address {
|
func (ch touchChange) dirtied() (common.Address, bool) {
|
||||||
return &ch.account
|
return ch.account, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch touchChange) copy() journalEntry {
|
func (ch touchChange) copy() journalEntry {
|
||||||
|
|
@ -354,8 +355,8 @@ 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, bool) {
|
||||||
return &ch.account
|
return ch.account, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch balanceChange) copy() journalEntry {
|
func (ch balanceChange) copy() journalEntry {
|
||||||
|
|
@ -369,8 +370,8 @@ 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, bool) {
|
||||||
return &ch.account
|
return ch.account, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch nonceChange) copy() journalEntry {
|
func (ch nonceChange) copy() journalEntry {
|
||||||
|
|
@ -384,8 +385,8 @@ func (ch codeChange) revert(s *StateDB) {
|
||||||
s.getStateObject(ch.account).setCode(crypto.Keccak256Hash(ch.prevCode), 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, bool) {
|
||||||
return &ch.account
|
return ch.account, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch codeChange) copy() journalEntry {
|
func (ch codeChange) copy() journalEntry {
|
||||||
|
|
@ -399,8 +400,8 @@ func (ch storageChange) revert(s *StateDB) {
|
||||||
s.getStateObject(ch.account).setState(ch.key, ch.prevvalue, ch.origvalue)
|
s.getStateObject(ch.account).setState(ch.key, ch.prevvalue, ch.origvalue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch storageChange) dirtied() *common.Address {
|
func (ch storageChange) dirtied() (common.Address, bool) {
|
||||||
return &ch.account
|
return ch.account, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch storageChange) copy() journalEntry {
|
func (ch storageChange) copy() journalEntry {
|
||||||
|
|
@ -416,8 +417,8 @@ 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, bool) {
|
||||||
return nil
|
return common.Address{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch transientStorageChange) copy() journalEntry {
|
func (ch transientStorageChange) copy() journalEntry {
|
||||||
|
|
@ -432,8 +433,8 @@ func (ch refundChange) revert(s *StateDB) {
|
||||||
s.refund = ch.prev
|
s.refund = ch.prev
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch refundChange) dirtied() *common.Address {
|
func (ch refundChange) dirtied() (common.Address, bool) {
|
||||||
return nil
|
return common.Address{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch refundChange) copy() journalEntry {
|
func (ch refundChange) copy() journalEntry {
|
||||||
|
|
@ -452,8 +453,8 @@ func (ch addLogChange) revert(s *StateDB) {
|
||||||
s.logSize--
|
s.logSize--
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch addLogChange) dirtied() *common.Address {
|
func (ch addLogChange) dirtied() (common.Address, bool) {
|
||||||
return nil
|
return common.Address{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch addLogChange) copy() journalEntry {
|
func (ch addLogChange) copy() journalEntry {
|
||||||
|
|
@ -475,8 +476,8 @@ func (ch accessListAddAccountChange) revert(s *StateDB) {
|
||||||
s.accessList.DeleteAddress(ch.address)
|
s.accessList.DeleteAddress(ch.address)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch accessListAddAccountChange) dirtied() *common.Address {
|
func (ch accessListAddAccountChange) dirtied() (common.Address, bool) {
|
||||||
return nil
|
return common.Address{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch accessListAddAccountChange) copy() journalEntry {
|
func (ch accessListAddAccountChange) copy() journalEntry {
|
||||||
|
|
@ -489,8 +490,8 @@ 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, bool) {
|
||||||
return nil
|
return common.Address{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch accessListAddSlotChange) copy() journalEntry {
|
func (ch accessListAddSlotChange) copy() journalEntry {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue