Implement journal
This commit is contained in:
parent
f06071decd
commit
6a741fc501
12
state/dump.go
Normal file
12
state/dump.go
Normal file
@ -0,0 +1,12 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
ethstate "github.com/ethereum/go-ethereum/core/state"
|
||||
)
|
||||
|
||||
// RawDump returns a raw state drump.
|
||||
//
|
||||
// TODO: Implement if we need it, especially for the RPC API.
|
||||
func (csdb *CommitStateDB) RawDump() ethstate.Dump {
|
||||
return ethstate.Dump{}
|
||||
}
|
107
state/journal.go
107
state/journal.go
@ -3,9 +3,11 @@ package state
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
ethcmn "github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
var ripemd = ethcmn.HexToAddress("0000000000000000000000000000000000000003")
|
||||
|
||||
// journalEntry is a modification entry in the state change journal that can be
|
||||
// reverted on demand.
|
||||
type journalEntry interface {
|
||||
@ -13,7 +15,7 @@ type journalEntry interface {
|
||||
revert(*CommitStateDB)
|
||||
|
||||
// dirtied returns the Ethereum address modified by this journal entry.
|
||||
dirtied() *common.Address
|
||||
dirtied() *ethcmn.Address
|
||||
}
|
||||
|
||||
// journal contains the list of state modifications applied since the last state
|
||||
@ -21,13 +23,13 @@ type journalEntry interface {
|
||||
// exception or revertal request.
|
||||
type journal struct {
|
||||
entries []journalEntry // Current changes tracked by the journal
|
||||
dirties map[common.Address]int // Dirty accounts and the number of changes
|
||||
dirties map[ethcmn.Address]int // Dirty accounts and the number of changes
|
||||
}
|
||||
|
||||
// newJournal create a new initialized journal.
|
||||
func newJournal() *journal {
|
||||
return &journal{
|
||||
dirties: make(map[common.Address]int),
|
||||
dirties: make(map[ethcmn.Address]int),
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,7 +61,7 @@ func (j *journal) revert(statedb *CommitStateDB, snapshot int) {
|
||||
// dirty explicitly sets an address to dirty, even if the change entries would
|
||||
// otherwise suggest it as clean. This method is an ugly hack to handle the RIPEMD
|
||||
// precompile consensus exception.
|
||||
func (j *journal) dirty(addr common.Address) {
|
||||
func (j *journal) dirty(addr ethcmn.Address) {
|
||||
j.dirties[addr]++
|
||||
}
|
||||
|
||||
@ -71,7 +73,7 @@ func (j *journal) length() int {
|
||||
type (
|
||||
// Changes to the account trie.
|
||||
createObjectChange struct {
|
||||
account *common.Address
|
||||
account *ethcmn.Address
|
||||
}
|
||||
|
||||
resetObjectChange struct {
|
||||
@ -79,30 +81,30 @@ type (
|
||||
}
|
||||
|
||||
suicideChange struct {
|
||||
account *common.Address
|
||||
account *ethcmn.Address
|
||||
prev bool // whether account had already suicided
|
||||
prevbalance sdk.Int
|
||||
prevBalance sdk.Int
|
||||
}
|
||||
|
||||
// Changes to individual accounts.
|
||||
balanceChange struct {
|
||||
account *common.Address
|
||||
account *ethcmn.Address
|
||||
prev sdk.Int
|
||||
}
|
||||
|
||||
nonceChange struct {
|
||||
account *common.Address
|
||||
account *ethcmn.Address
|
||||
prev int64
|
||||
}
|
||||
|
||||
storageChange struct {
|
||||
account *common.Address
|
||||
key, prevalue common.Hash
|
||||
account *ethcmn.Address
|
||||
key, prevValue ethcmn.Hash
|
||||
}
|
||||
|
||||
codeChange struct {
|
||||
account *common.Address
|
||||
prevcode, prevhash []byte
|
||||
account *ethcmn.Address
|
||||
prevCode, prevHash []byte
|
||||
}
|
||||
|
||||
// Changes to other state values.
|
||||
@ -111,15 +113,15 @@ type (
|
||||
}
|
||||
|
||||
addLogChange struct {
|
||||
txhash common.Hash
|
||||
txhash ethcmn.Hash
|
||||
}
|
||||
|
||||
addPreimageChange struct {
|
||||
hash common.Hash
|
||||
hash ethcmn.Hash
|
||||
}
|
||||
|
||||
touchChange struct {
|
||||
account *common.Address
|
||||
account *ethcmn.Address
|
||||
prev bool
|
||||
prevDirty bool
|
||||
}
|
||||
@ -130,107 +132,96 @@ func (ch createObjectChange) revert(s *CommitStateDB) {
|
||||
delete(s.stateObjectsDirty, *ch.account)
|
||||
}
|
||||
|
||||
func (ch createObjectChange) dirtied() *common.Address {
|
||||
func (ch createObjectChange) dirtied() *ethcmn.Address {
|
||||
return ch.account
|
||||
}
|
||||
|
||||
func (ch resetObjectChange) revert(s *CommitStateDB) {
|
||||
// TODO: ...
|
||||
// s.setStateObject(ch.prev)
|
||||
s.setStateObject(ch.prev)
|
||||
}
|
||||
|
||||
func (ch resetObjectChange) dirtied() *common.Address {
|
||||
func (ch resetObjectChange) dirtied() *ethcmn.Address {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ch suicideChange) revert(s *CommitStateDB) {
|
||||
// TODO: ...
|
||||
// obj := s.getStateObject(*ch.account)
|
||||
// if obj != nil {
|
||||
// obj.suicided = ch.prev
|
||||
// obj.setBalance(ch.prevbalance)
|
||||
// }
|
||||
so := s.getStateObject(*ch.account)
|
||||
if so != nil {
|
||||
so.suicided = ch.prev
|
||||
so.setBalance(ch.prevBalance)
|
||||
}
|
||||
}
|
||||
|
||||
func (ch suicideChange) dirtied() *common.Address {
|
||||
func (ch suicideChange) dirtied() *ethcmn.Address {
|
||||
return ch.account
|
||||
}
|
||||
|
||||
var ripemd = common.HexToAddress("0000000000000000000000000000000000000003")
|
||||
|
||||
func (ch touchChange) revert(s *CommitStateDB) {
|
||||
}
|
||||
|
||||
func (ch touchChange) dirtied() *common.Address {
|
||||
func (ch touchChange) dirtied() *ethcmn.Address {
|
||||
return ch.account
|
||||
}
|
||||
|
||||
func (ch balanceChange) revert(s *CommitStateDB) {
|
||||
// TODO: ...
|
||||
// s.getStateObject(*ch.account).setBalance(ch.prev)
|
||||
s.getStateObject(*ch.account).setBalance(ch.prev)
|
||||
}
|
||||
|
||||
func (ch balanceChange) dirtied() *common.Address {
|
||||
func (ch balanceChange) dirtied() *ethcmn.Address {
|
||||
return ch.account
|
||||
}
|
||||
|
||||
func (ch nonceChange) revert(s *CommitStateDB) {
|
||||
// TODO: ...
|
||||
// s.getStateObject(*ch.account).setNonce(ch.prev)
|
||||
s.getStateObject(*ch.account).setNonce(ch.prev)
|
||||
}
|
||||
|
||||
func (ch nonceChange) dirtied() *common.Address {
|
||||
func (ch nonceChange) dirtied() *ethcmn.Address {
|
||||
return ch.account
|
||||
}
|
||||
|
||||
func (ch codeChange) revert(s *CommitStateDB) {
|
||||
// TODO: ...
|
||||
// s.getStateObject(*ch.account).setCode(common.BytesToHash(ch.prevhash), ch.prevcode)
|
||||
s.getStateObject(*ch.account).setCode(ethcmn.BytesToHash(ch.prevHash), ch.prevCode)
|
||||
}
|
||||
|
||||
func (ch codeChange) dirtied() *common.Address {
|
||||
func (ch codeChange) dirtied() *ethcmn.Address {
|
||||
return ch.account
|
||||
}
|
||||
|
||||
func (ch storageChange) revert(s *CommitStateDB) {
|
||||
// TODO: ...
|
||||
// s.getStateObject(*ch.account).setState(ch.key, ch.prevalue)
|
||||
s.getStateObject(*ch.account).setState(ch.key, ch.prevValue)
|
||||
}
|
||||
|
||||
func (ch storageChange) dirtied() *common.Address {
|
||||
func (ch storageChange) dirtied() *ethcmn.Address {
|
||||
return ch.account
|
||||
}
|
||||
|
||||
func (ch refundChange) revert(s *CommitStateDB) {
|
||||
// TODO: ...
|
||||
// s.refund = ch.prev
|
||||
s.refund = ch.prev
|
||||
}
|
||||
|
||||
func (ch refundChange) dirtied() *common.Address {
|
||||
func (ch refundChange) dirtied() *ethcmn.Address {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ch addLogChange) revert(s *CommitStateDB) {
|
||||
// TODO: ...
|
||||
// logs := s.logs[ch.txhash]
|
||||
// if len(logs) == 1 {
|
||||
// delete(s.logs, ch.txhash)
|
||||
// } else {
|
||||
// s.logs[ch.txhash] = logs[:len(logs)-1]
|
||||
// }
|
||||
logs := s.logs[ch.txhash]
|
||||
if len(logs) == 1 {
|
||||
delete(s.logs, ch.txhash)
|
||||
} else {
|
||||
s.logs[ch.txhash] = logs[:len(logs)-1]
|
||||
}
|
||||
|
||||
// s.logSize--
|
||||
s.logSize--
|
||||
}
|
||||
|
||||
func (ch addLogChange) dirtied() *common.Address {
|
||||
func (ch addLogChange) dirtied() *ethcmn.Address {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ch addPreimageChange) revert(s *CommitStateDB) {
|
||||
// TODO: ...
|
||||
// delete(s.preimages, ch.hash)
|
||||
delete(s.preimages, ch.hash)
|
||||
}
|
||||
|
||||
func (ch addPreimageChange) dirtied() *common.Address {
|
||||
func (ch addPreimageChange) dirtied() *ethcmn.Address {
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user