Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
张蕾
Geth-Modification
Commits
817553cc
Unverified
Commit
817553cc
authored
Jul 31, 2023
by
rjl493456442
Committed by
GitHub
Jul 31, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core, trie: track state change set with account address (#27815)
parent
43a1a48e
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
57 deletions
+60
-57
journal.go
core/state/journal.go
+2
-2
state_object.go
core/state/state_object.go
+2
-2
statedb.go
core/state/statedb.go
+40
-40
statedb_fuzz_test.go
core/state/statedb_fuzz_test.go
+13
-10
state.go
trie/triestate/state.go
+3
-3
No files found.
core/state/journal.go
View file @
817553cc
...
...
@@ -173,10 +173,10 @@ func (ch resetObjectChange) revert(s *StateDB) {
s
.
storages
[
ch
.
prev
.
addrHash
]
=
ch
.
prevStorage
}
if
ch
.
prevAccountOriginExist
{
s
.
accountsOrigin
[
ch
.
prev
.
addr
Hash
]
=
ch
.
prevAccountOrigin
s
.
accountsOrigin
[
ch
.
prev
.
addr
ess
]
=
ch
.
prevAccountOrigin
}
if
ch
.
prevStorageOrigin
!=
nil
{
s
.
storagesOrigin
[
ch
.
prev
.
addr
Hash
]
=
ch
.
prevStorageOrigin
s
.
storagesOrigin
[
ch
.
prev
.
addr
ess
]
=
ch
.
prevStorageOrigin
}
}
...
...
core/state/state_object.go
View file @
817553cc
...
...
@@ -328,9 +328,9 @@ func (s *stateObject) updateTrie() (Trie, error) {
// Cache the original value of mutated storage slots
if
origin
==
nil
{
if
origin
=
s
.
db
.
storagesOrigin
[
s
.
addr
Hash
];
origin
==
nil
{
if
origin
=
s
.
db
.
storagesOrigin
[
s
.
addr
ess
];
origin
==
nil
{
origin
=
make
(
map
[
common
.
Hash
][]
byte
)
s
.
db
.
storagesOrigin
[
s
.
addr
Hash
]
=
origin
s
.
db
.
storagesOrigin
[
s
.
addr
ess
]
=
origin
}
}
// Track the original value of slot only if it's mutated first time
...
...
core/state/statedb.go
View file @
817553cc
This diff is collapsed.
Click to expand it.
core/state/statedb_fuzz_test.go
View file @
817553cc
...
...
@@ -32,6 +32,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/trie/triestate"
...
...
@@ -171,11 +172,11 @@ func (test *stateTest) String() string {
func
(
test
*
stateTest
)
run
()
bool
{
var
(
roots
[]
common
.
Hash
accountList
[]
map
[
common
.
Hash
][]
byte
storageList
[]
map
[
common
.
Hash
]
map
[
common
.
Hash
][]
byte
accountList
[]
map
[
common
.
Address
][]
byte
storageList
[]
map
[
common
.
Address
]
map
[
common
.
Hash
][]
byte
onCommit
=
func
(
states
*
triestate
.
Set
)
{
accountList
=
append
(
accountList
,
copy
Accounts
(
states
.
Accounts
))
storageList
=
append
(
storageList
,
copy
Storages
(
states
.
Storages
))
accountList
=
append
(
accountList
,
copy
Set
(
states
.
Accounts
))
storageList
=
append
(
storageList
,
copy
2DSet
(
states
.
Storages
))
}
disk
=
rawdb
.
NewMemoryDatabase
()
tdb
=
trie
.
NewDatabaseWithConfig
(
disk
,
&
trie
.
Config
{
OnCommit
:
onCommit
})
...
...
@@ -235,8 +236,9 @@ func (test *stateTest) run() bool {
// - the account was indeed not present in trie
// - the account is present in new trie, nil->nil is regarded as invalid
// - the slots transition is correct
func
(
test
*
stateTest
)
verifyAccountCreation
(
next
common
.
Hash
,
db
*
trie
.
Database
,
otr
,
ntr
*
trie
.
Trie
,
addr
Hash
common
.
Hash
,
slots
map
[
common
.
Hash
][]
byte
)
error
{
func
(
test
*
stateTest
)
verifyAccountCreation
(
next
common
.
Hash
,
db
*
trie
.
Database
,
otr
,
ntr
*
trie
.
Trie
,
addr
common
.
Address
,
slots
map
[
common
.
Hash
][]
byte
)
error
{
// Verify account change
addrHash
:=
crypto
.
Keccak256Hash
(
addr
.
Bytes
())
oBlob
,
err
:=
otr
.
Get
(
addrHash
.
Bytes
())
if
err
!=
nil
{
return
err
...
...
@@ -285,8 +287,9 @@ func (test *stateTest) verifyAccountCreation(next common.Hash, db *trie.Database
// - the account was indeed present in trie
// - the account in old trie matches the provided value
// - the slots transition is correct
func
(
test
*
stateTest
)
verifyAccountUpdate
(
next
common
.
Hash
,
db
*
trie
.
Database
,
otr
,
ntr
*
trie
.
Trie
,
addr
Hash
common
.
Hash
,
origin
[]
byte
,
slots
map
[
common
.
Hash
][]
byte
)
error
{
func
(
test
*
stateTest
)
verifyAccountUpdate
(
next
common
.
Hash
,
db
*
trie
.
Database
,
otr
,
ntr
*
trie
.
Trie
,
addr
common
.
Address
,
origin
[]
byte
,
slots
map
[
common
.
Hash
][]
byte
)
error
{
// Verify account change
addrHash
:=
crypto
.
Keccak256Hash
(
addr
.
Bytes
())
oBlob
,
err
:=
otr
.
Get
(
addrHash
.
Bytes
())
if
err
!=
nil
{
return
err
...
...
@@ -338,7 +341,7 @@ func (test *stateTest) verifyAccountUpdate(next common.Hash, db *trie.Database,
return
nil
}
func
(
test
*
stateTest
)
verify
(
root
common
.
Hash
,
next
common
.
Hash
,
db
*
trie
.
Database
,
accountsOrigin
map
[
common
.
Hash
][]
byte
,
storagesOrigin
map
[
common
.
Hash
]
map
[
common
.
Hash
][]
byte
)
error
{
func
(
test
*
stateTest
)
verify
(
root
common
.
Hash
,
next
common
.
Hash
,
db
*
trie
.
Database
,
accountsOrigin
map
[
common
.
Address
][]
byte
,
storagesOrigin
map
[
common
.
Address
]
map
[
common
.
Hash
][]
byte
)
error
{
otr
,
err
:=
trie
.
New
(
trie
.
StateTrieID
(
root
),
db
)
if
err
!=
nil
{
return
err
...
...
@@ -347,12 +350,12 @@ func (test *stateTest) verify(root common.Hash, next common.Hash, db *trie.Datab
if
err
!=
nil
{
return
err
}
for
addr
Hash
,
account
:=
range
accountsOrigin
{
for
addr
,
account
:=
range
accountsOrigin
{
var
err
error
if
len
(
account
)
==
0
{
err
=
test
.
verifyAccountCreation
(
next
,
db
,
otr
,
ntr
,
addr
Hash
,
storagesOrigin
[
addrHash
])
err
=
test
.
verifyAccountCreation
(
next
,
db
,
otr
,
ntr
,
addr
,
storagesOrigin
[
addr
])
}
else
{
err
=
test
.
verifyAccountUpdate
(
next
,
db
,
otr
,
ntr
,
addr
Hash
,
accountsOrigin
[
addrHash
],
storagesOrigin
[
addrHash
])
err
=
test
.
verifyAccountUpdate
(
next
,
db
,
otr
,
ntr
,
addr
,
accountsOrigin
[
addr
],
storagesOrigin
[
addr
])
}
if
err
!=
nil
{
return
err
...
...
trie/triestate/state.go
View file @
817553cc
...
...
@@ -22,7 +22,7 @@ import "github.com/ethereum/go-ethereum/common"
// The value refers to the original content of state before the transition
// is made. Nil means that the state was not present previously.
type
Set
struct
{
Accounts
map
[
common
.
Hash
][]
byte
// Mutated account set, nil means the account was not present
Storages
map
[
common
.
Hash
]
map
[
common
.
Hash
][]
byte
// Mutated storage set, nil means the slot was not present
Incomplete
map
[
common
.
Hash
]
struct
{}
// Indicator whether the storage slot is incomplete due to large deletion
Accounts
map
[
common
.
Address
][]
byte
// Mutated account set, nil means the account was not present
Storages
map
[
common
.
Address
]
map
[
common
.
Hash
][]
byte
// Mutated storage set, nil means the slot was not present
Incomplete
map
[
common
.
Address
]
struct
{}
// Indicator whether the storage slot is incomplete due to large deletion
}
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