Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions core/state/database_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,7 @@ func (r *historicStateReader) Account(addr common.Address) (*types.StateAccount,
if account == nil {
return nil, nil
}
acct := &types.StateAccount{
Nonce: account.Nonce,
Balance: account.Balance,
CodeHash: account.CodeHash,
Root: common.BytesToHash(account.Root),
}
if len(acct.CodeHash) == 0 {
acct.CodeHash = types.EmptyCodeHash.Bytes()
}
if acct.Root == (common.Hash{}) {
acct.Root = types.EmptyRootHash
}
return acct, nil
return slimAccountToStateAccount(account)
}

// Storage implements StateReader, retrieving the storage slot specified by the
Expand Down
43 changes: 43 additions & 0 deletions core/state/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
qkccommon "github.com/ethereum/go-ethereum/qkc/common"
"github.com/holiman/uint256"
)

Expand Down Expand Up @@ -229,6 +230,14 @@ func (j *journal) accessListAddSlot(addr common.Address, slot common.Hash) {
})
}

func (j *journal) mntBalanceChange(addr common.Address, prev *qkccommon.TokenBalances) {
var snap *qkccommon.TokenBalances
if prev != nil {
snap = prev.Copy()
}
j.append(mntBalanceChange{addr: addr, prev: snap})
}

type (
// Changes to the account trie.
createObjectChange struct {
Expand Down Expand Up @@ -289,6 +298,12 @@ type (
account common.Address
key, prevalue common.Hash
}

// mntBalanceChange records a snapshot of MNT balances for revert support.
mntBalanceChange struct {
addr common.Address
prev *qkccommon.TokenBalances
}
)

func (ch createObjectChange) revert(s *StateDB) {
Expand Down Expand Up @@ -352,6 +367,8 @@ func (ch touchChange) copy() journalEntry {
}

func (ch balanceChange) revert(s *StateDB) {
// pyquarkchain restores the previous value by writing it back into the
// balance map. Even when the previous value is zero, the token entry remains.
s.getStateObject(ch.account).setBalance(ch.prev)
}

Expand Down Expand Up @@ -500,3 +517,29 @@ func (ch accessListAddSlotChange) copy() journalEntry {
slot: ch.slot,
}
}

func (ch mntBalanceChange) revert(s *StateDB) {
obj := s.getStateObject(ch.addr)
if obj != nil {
if ch.prev == nil {
obj.data.MntBalances = nil
} else {
obj.data.MntBalances = ch.prev.Copy()
}
}
}

func (ch mntBalanceChange) dirtied() (common.Address, bool) {
return ch.addr, true
}

func (ch mntBalanceChange) copy() journalEntry {
var prev *qkccommon.TokenBalances
if ch.prev != nil {
prev = ch.prev.Copy()
}
return mntBalanceChange{
addr: ch.addr,
prev: prev,
}
}
Loading