forked from cerc-io/laconicd-deprecated
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 (
|
import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
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
|
// journalEntry is a modification entry in the state change journal that can be
|
||||||
// reverted on demand.
|
// reverted on demand.
|
||||||
type journalEntry interface {
|
type journalEntry interface {
|
||||||
@ -13,7 +15,7 @@ type journalEntry interface {
|
|||||||
revert(*CommitStateDB)
|
revert(*CommitStateDB)
|
||||||
|
|
||||||
// dirtied returns the Ethereum address modified by this journal entry.
|
// 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
|
// journal contains the list of state modifications applied since the last state
|
||||||
@ -21,13 +23,13 @@ type journalEntry interface {
|
|||||||
// exception or revertal request.
|
// exception or revertal request.
|
||||||
type journal struct {
|
type journal struct {
|
||||||
entries []journalEntry // Current changes tracked by the journal
|
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.
|
// newJournal create a new initialized journal.
|
||||||
func newJournal() *journal {
|
func newJournal() *journal {
|
||||||
return &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
|
// 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
|
// otherwise suggest it as clean. This method is an ugly hack to handle the RIPEMD
|
||||||
// precompile consensus exception.
|
// precompile consensus exception.
|
||||||
func (j *journal) dirty(addr common.Address) {
|
func (j *journal) dirty(addr ethcmn.Address) {
|
||||||
j.dirties[addr]++
|
j.dirties[addr]++
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +73,7 @@ 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 *ethcmn.Address
|
||||||
}
|
}
|
||||||
|
|
||||||
resetObjectChange struct {
|
resetObjectChange struct {
|
||||||
@ -79,30 +81,30 @@ type (
|
|||||||
}
|
}
|
||||||
|
|
||||||
suicideChange struct {
|
suicideChange struct {
|
||||||
account *common.Address
|
account *ethcmn.Address
|
||||||
prev bool // whether account had already suicided
|
prev bool // whether account had already suicided
|
||||||
prevbalance sdk.Int
|
prevBalance sdk.Int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changes to individual accounts.
|
// Changes to individual accounts.
|
||||||
balanceChange struct {
|
balanceChange struct {
|
||||||
account *common.Address
|
account *ethcmn.Address
|
||||||
prev sdk.Int
|
prev sdk.Int
|
||||||
}
|
}
|
||||||
|
|
||||||
nonceChange struct {
|
nonceChange struct {
|
||||||
account *common.Address
|
account *ethcmn.Address
|
||||||
prev int64
|
prev int64
|
||||||
}
|
}
|
||||||
|
|
||||||
storageChange struct {
|
storageChange struct {
|
||||||
account *common.Address
|
account *ethcmn.Address
|
||||||
key, prevalue common.Hash
|
key, prevValue ethcmn.Hash
|
||||||
}
|
}
|
||||||
|
|
||||||
codeChange struct {
|
codeChange struct {
|
||||||
account *common.Address
|
account *ethcmn.Address
|
||||||
prevcode, prevhash []byte
|
prevCode, prevHash []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changes to other state values.
|
// Changes to other state values.
|
||||||
@ -111,15 +113,15 @@ type (
|
|||||||
}
|
}
|
||||||
|
|
||||||
addLogChange struct {
|
addLogChange struct {
|
||||||
txhash common.Hash
|
txhash ethcmn.Hash
|
||||||
}
|
}
|
||||||
|
|
||||||
addPreimageChange struct {
|
addPreimageChange struct {
|
||||||
hash common.Hash
|
hash ethcmn.Hash
|
||||||
}
|
}
|
||||||
|
|
||||||
touchChange struct {
|
touchChange struct {
|
||||||
account *common.Address
|
account *ethcmn.Address
|
||||||
prev bool
|
prev bool
|
||||||
prevDirty bool
|
prevDirty bool
|
||||||
}
|
}
|
||||||
@ -130,107 +132,96 @@ func (ch createObjectChange) revert(s *CommitStateDB) {
|
|||||||
delete(s.stateObjectsDirty, *ch.account)
|
delete(s.stateObjectsDirty, *ch.account)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch createObjectChange) dirtied() *common.Address {
|
func (ch createObjectChange) dirtied() *ethcmn.Address {
|
||||||
return ch.account
|
return ch.account
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch resetObjectChange) revert(s *CommitStateDB) {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch suicideChange) revert(s *CommitStateDB) {
|
func (ch suicideChange) revert(s *CommitStateDB) {
|
||||||
// TODO: ...
|
so := s.getStateObject(*ch.account)
|
||||||
// obj := s.getStateObject(*ch.account)
|
if so != nil {
|
||||||
// if obj != nil {
|
so.suicided = ch.prev
|
||||||
// obj.suicided = ch.prev
|
so.setBalance(ch.prevBalance)
|
||||||
// obj.setBalance(ch.prevbalance)
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch suicideChange) dirtied() *common.Address {
|
func (ch suicideChange) dirtied() *ethcmn.Address {
|
||||||
return ch.account
|
return ch.account
|
||||||
}
|
}
|
||||||
|
|
||||||
var ripemd = common.HexToAddress("0000000000000000000000000000000000000003")
|
|
||||||
|
|
||||||
func (ch touchChange) revert(s *CommitStateDB) {
|
func (ch touchChange) revert(s *CommitStateDB) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch touchChange) dirtied() *common.Address {
|
func (ch touchChange) dirtied() *ethcmn.Address {
|
||||||
return ch.account
|
return ch.account
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch balanceChange) revert(s *CommitStateDB) {
|
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
|
return ch.account
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch nonceChange) revert(s *CommitStateDB) {
|
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
|
return ch.account
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch codeChange) revert(s *CommitStateDB) {
|
func (ch codeChange) revert(s *CommitStateDB) {
|
||||||
// TODO: ...
|
s.getStateObject(*ch.account).setCode(ethcmn.BytesToHash(ch.prevHash), ch.prevCode)
|
||||||
// s.getStateObject(*ch.account).setCode(common.BytesToHash(ch.prevhash), ch.prevcode)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch codeChange) dirtied() *common.Address {
|
func (ch codeChange) dirtied() *ethcmn.Address {
|
||||||
return ch.account
|
return ch.account
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch storageChange) revert(s *CommitStateDB) {
|
func (ch storageChange) revert(s *CommitStateDB) {
|
||||||
// TODO: ...
|
s.getStateObject(*ch.account).setState(ch.key, ch.prevValue)
|
||||||
// s.getStateObject(*ch.account).setState(ch.key, ch.prevalue)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch storageChange) dirtied() *common.Address {
|
func (ch storageChange) dirtied() *ethcmn.Address {
|
||||||
return ch.account
|
return ch.account
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch refundChange) revert(s *CommitStateDB) {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch addLogChange) revert(s *CommitStateDB) {
|
func (ch addLogChange) revert(s *CommitStateDB) {
|
||||||
// TODO: ...
|
logs := s.logs[ch.txhash]
|
||||||
// logs := s.logs[ch.txhash]
|
if len(logs) == 1 {
|
||||||
// if len(logs) == 1 {
|
delete(s.logs, ch.txhash)
|
||||||
// delete(s.logs, ch.txhash)
|
} else {
|
||||||
// } else {
|
s.logs[ch.txhash] = logs[:len(logs)-1]
|
||||||
// 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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch addPreimageChange) revert(s *CommitStateDB) {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user