aboutsummaryrefslogtreecommitdiffstats
path: root/core/state/dump.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-09-23 03:04:58 +0800
committerFelix Lange <fjl@twurst.com>2016-09-26 16:09:52 +0800
commita59a93f476434f2805c8fd3e10bf1b2f579b078f (patch)
tree17d1f3abefabfd7f8cb9149994a4788d2c0f08bc /core/state/dump.go
parente859f3696783ec75d9bb39c0c66eda3a88cea8c6 (diff)
downloadgo-tangerine-a59a93f476434f2805c8fd3e10bf1b2f579b078f.tar
go-tangerine-a59a93f476434f2805c8fd3e10bf1b2f579b078f.tar.gz
go-tangerine-a59a93f476434f2805c8fd3e10bf1b2f579b078f.tar.bz2
go-tangerine-a59a93f476434f2805c8fd3e10bf1b2f579b078f.tar.lz
go-tangerine-a59a93f476434f2805c8fd3e10bf1b2f579b078f.tar.xz
go-tangerine-a59a93f476434f2805c8fd3e10bf1b2f579b078f.tar.zst
go-tangerine-a59a93f476434f2805c8fd3e10bf1b2f579b078f.zip
core/state: track all accounts in canon state
This change introduces a global, per-state cache that keeps account data in the canon state. Thanks to @karalabe for lots of fixes.
Diffstat (limited to 'core/state/dump.go')
-rw-r--r--core/state/dump.go47
1 files changed, 20 insertions, 27 deletions
diff --git a/core/state/dump.go b/core/state/dump.go
index a328b0537..58ecd852b 100644
--- a/core/state/dump.go
+++ b/core/state/dump.go
@@ -21,9 +21,10 @@ import (
"fmt"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/rlp"
)
-type Account struct {
+type DumpAccount struct {
Balance string `json:"balance"`
Nonce uint64 `json:"nonce"`
Root string `json:"root"`
@@ -32,40 +33,41 @@ type Account struct {
Storage map[string]string `json:"storage"`
}
-type World struct {
- Root string `json:"root"`
- Accounts map[string]Account `json:"accounts"`
+type Dump struct {
+ Root string `json:"root"`
+ Accounts map[string]DumpAccount `json:"accounts"`
}
-func (self *StateDB) RawDump() World {
- world := World{
+func (self *StateDB) RawDump() Dump {
+ dump := Dump{
Root: common.Bytes2Hex(self.trie.Root()),
- Accounts: make(map[string]Account),
+ Accounts: make(map[string]DumpAccount),
}
it := self.trie.Iterator()
for it.Next() {
addr := self.trie.GetKey(it.Key)
- stateObject, err := DecodeObject(common.BytesToAddress(addr), self.db, it.Value)
- if err != nil {
+ var data Account
+ if err := rlp.DecodeBytes(it.Value, &data); err != nil {
panic(err)
}
- account := Account{
- Balance: stateObject.balance.String(),
- Nonce: stateObject.nonce,
- Root: common.Bytes2Hex(stateObject.Root()),
- CodeHash: common.Bytes2Hex(stateObject.codeHash),
- Code: common.Bytes2Hex(stateObject.Code()),
+ obj := NewObject(common.BytesToAddress(addr), data, nil)
+ account := DumpAccount{
+ Balance: data.Balance.String(),
+ Nonce: data.Nonce,
+ Root: common.Bytes2Hex(data.Root[:]),
+ CodeHash: common.Bytes2Hex(data.CodeHash),
+ Code: common.Bytes2Hex(obj.Code(self.db)),
Storage: make(map[string]string),
}
- storageIt := stateObject.trie.Iterator()
+ storageIt := obj.getTrie(self.db).Iterator()
for storageIt.Next() {
account.Storage[common.Bytes2Hex(self.trie.GetKey(storageIt.Key))] = common.Bytes2Hex(storageIt.Value)
}
- world.Accounts[common.Bytes2Hex(addr)] = account
+ dump.Accounts[common.Bytes2Hex(addr)] = account
}
- return world
+ return dump
}
func (self *StateDB) Dump() []byte {
@@ -76,12 +78,3 @@ func (self *StateDB) Dump() []byte {
return json
}
-
-// Debug stuff
-func (self *StateObject) CreateOutputForDiff() {
- fmt.Printf("%x %x %x %x\n", self.Address(), self.Root(), self.balance.Bytes(), self.nonce)
- it := self.trie.Iterator()
- for it.Next() {
- fmt.Printf("%x %x\n", it.Key, it.Value)
- }
-}