Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
3ecdafb0
Commit
3ecdafb0
authored
Sep 22, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
statedb is very close
parent
0a3e2d0c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
27 deletions
+62
-27
statedb.go
minigeth/core/state/statedb.go
+62
-27
No files found.
minigeth/core/state/statedb.go
View file @
3ecdafb0
// Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Package state provides a caching layer atop the Ethereum state trie.
package
state
import
(
...
...
@@ -15,16 +32,35 @@ import (
"github.com/ethereum/go-ethereum/rlp"
)
// for includes we don't have
//
type
revision
struct
{
id
int
journalIndex
int
}
var
(
// emptyRoot is the known root hash of an empty trie.
emptyRoot
=
common
.
HexToHash
(
"56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
)
)
type
revision
struct
{
id
int
journalIndex
int
type
proofList
[][]
byte
func
(
n
*
proofList
)
Put
(
key
[]
byte
,
value
[]
byte
)
error
{
*
n
=
append
(
*
n
,
value
)
return
nil
}
func
(
n
*
proofList
)
Delete
(
key
[]
byte
)
error
{
panic
(
"not supported"
)
}
// StateDB structs within the ethereum protocol are used to store anything
// within the merkle trie. StateDBs take care of caching and storing
// nested states. It's the general query interface to retrieve:
// * Contracts
// * Accounts
type
StateDB
struct
{
db
Database
prefetcher
*
triePrefetcher
...
...
@@ -32,36 +68,17 @@ type StateDB struct {
trie
Trie
hasher
crypto
.
KeccakState
blockNumber
*
big
.
Int
stateRoot
common
.
Hash
// This map holds 'live' objects, which will get modified while processing a state transition.
stateObjects
map
[
common
.
Address
]
*
stateObject
stateObjectsPending
map
[
common
.
Address
]
struct
{}
// State objects finalized but not yet written to the trie
stateObjectsDirty
map
[
common
.
Address
]
struct
{}
// State objects modified in the current execution
// Per-transaction access list
accessList
*
accessList
preimages
map
[
common
.
Hash
][]
byte
snaps
*
snapshot
.
Tree
snap
snapshot
.
Snapshot
snapDestructs
map
[
common
.
Hash
]
struct
{}
snapAccounts
map
[
common
.
Hash
][]
byte
snapStorage
map
[
common
.
Hash
]
map
[
common
.
Hash
][]
byte
// Journal of state modifications. This is the backbone of
// Snapshot and RevertToSnapshot.
journal
*
journal
validRevisions
[]
revision
nextRevisionId
int
logs
map
[
common
.
Hash
][]
*
types
.
Log
logSize
uint
// This map holds 'live' objects, which will get modified while processing a state transition.
stateObjects
map
[
common
.
Address
]
*
stateObject
stateObjectsPending
map
[
common
.
Address
]
struct
{}
// State objects finalized but not yet written to the trie
stateObjectsDirty
map
[
common
.
Address
]
struct
{}
// State objects modified in the current execution
thash
common
.
Hash
txIndex
int
// DB error.
// State objects are used by the consensus core and VM which are
// unable to deal with database-level errors. Any error that occurs
...
...
@@ -72,6 +89,22 @@ type StateDB struct {
// The refund counter, also used by state transitioning.
refund
uint64
thash
common
.
Hash
txIndex
int
logs
map
[
common
.
Hash
][]
*
types
.
Log
logSize
uint
preimages
map
[
common
.
Hash
][]
byte
// Per-transaction access list
accessList
*
accessList
// Journal of state modifications. This is the backbone of
// Snapshot and RevertToSnapshot.
journal
*
journal
validRevisions
[]
revision
nextRevisionId
int
// Measurements gathered during execution for debugging purposes
AccountReads
time
.
Duration
AccountHashes
time
.
Duration
...
...
@@ -84,6 +117,8 @@ type StateDB struct {
SnapshotAccountReads
time
.
Duration
SnapshotStorageReads
time
.
Duration
SnapshotCommits
time
.
Duration
blockNumber
*
big
.
Int
}
func
NewStateDB
(
header
types
.
Header
)
*
StateDB
{
...
...
@@ -92,7 +127,7 @@ func NewStateDB(header types.Header) *StateDB {
stateObjects
:
make
(
map
[
common
.
Address
]
*
stateObject
),
stateObjectsPending
:
make
(
map
[
common
.
Address
]
struct
{}),
stateObjectsDirty
:
make
(
map
[
common
.
Address
]
struct
{}),
stateRoot
:
header
.
Root
,
originalRoot
:
header
.
Root
,
db
:
Database
{
BlockNumber
:
header
.
Number
,
StateRoot
:
header
.
Root
},
trie
:
SimpleTrie
{
BlockNumber
:
header
.
Number
,
Root
:
header
.
Root
,
Storage
:
false
},
journal
:
newJournal
(),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment