Skip to content

Commit 352f9f4

Browse files
rjl493456442gzliudan
authored andcommitted
core, trie: port snap sync changes ethereum#24898
core, eth, les, trie: rework snap sync
1 parent 8bc1887 commit 352f9f4

File tree

14 files changed

+828
-471
lines changed

14 files changed

+828
-471
lines changed

XDCx/tradingstate/state_liquidationprice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (l *liquidationPriceState) updateRoot(db Database) error {
136136
if l.dbErr != nil {
137137
return l.dbErr
138138
}
139-
root, err := l.trie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash) error {
139+
root, err := l.trie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash, _ []byte) error {
140140
var orderList orderList
141141
if err := rlp.DecodeBytes(leaf, &orderList); err != nil {
142142
return nil

XDCx/tradingstate/state_orderbook.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (te *tradingExchanges) CommitAsksTrie(db Database) error {
245245
if te.dbErr != nil {
246246
return te.dbErr
247247
}
248-
root, err := te.asksTrie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash) error {
248+
root, err := te.asksTrie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash, _ []byte) error {
249249
var orderList orderList
250250
if err := rlp.DecodeBytes(leaf, &orderList); err != nil {
251251
return nil
@@ -307,7 +307,7 @@ func (te *tradingExchanges) CommitBidsTrie(db Database) error {
307307
if te.dbErr != nil {
308308
return te.dbErr
309309
}
310-
root, err := te.bidsTrie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash) error {
310+
root, err := te.bidsTrie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash, _ []byte) error {
311311
var orderList orderList
312312
if err := rlp.DecodeBytes(leaf, &orderList); err != nil {
313313
return nil
@@ -783,7 +783,7 @@ func (t *tradingExchanges) CommitLiquidationPriceTrie(db Database) error {
783783
if t.dbErr != nil {
784784
return t.dbErr
785785
}
786-
root, err := t.liquidationPriceTrie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash) error {
786+
root, err := t.liquidationPriceTrie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash, _ []byte) error {
787787
var orderList orderList
788788
if err := rlp.DecodeBytes(leaf, &orderList); err != nil {
789789
return nil

XDCx/tradingstate/statedb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ func (t *TradingStateDB) Commit() (root common.Hash, err error) {
589589
}
590590
}
591591
// Write trie changes.
592-
root, err = t.trie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash) error {
592+
root, err = t.trie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash, _ []byte) error {
593593
var exchange tradingExchangeObject
594594
if err := rlp.DecodeBytes(leaf, &exchange); err != nil {
595595
return nil

XDCxlending/lendingstate/state_lendingbook.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ func (le *lendingExchangeState) CommitInvestingTrie(db Database) error {
472472
if le.dbErr != nil {
473473
return le.dbErr
474474
}
475-
root, err := le.investingTrie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash) error {
475+
root, err := le.investingTrie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash, _ []byte) error {
476476
var orderList itemList
477477
if err := rlp.DecodeBytes(leaf, &orderList); err != nil {
478478
return nil
@@ -493,7 +493,7 @@ func (le *lendingExchangeState) CommitBorrowingTrie(db Database) error {
493493
if le.dbErr != nil {
494494
return le.dbErr
495495
}
496-
root, err := le.borrowingTrie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash) error {
496+
root, err := le.borrowingTrie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash, _ []byte) error {
497497
var orderList itemList
498498
if err := rlp.DecodeBytes(leaf, &orderList); err != nil {
499499
return nil
@@ -514,7 +514,7 @@ func (le *lendingExchangeState) CommitLiquidationTimeTrie(db Database) error {
514514
if le.dbErr != nil {
515515
return le.dbErr
516516
}
517-
root, err := le.liquidationTimeTrie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash) error {
517+
root, err := le.liquidationTimeTrie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash, _ []byte) error {
518518
var orderList itemList
519519
if err := rlp.DecodeBytes(leaf, &orderList); err != nil {
520520
return nil

XDCxlending/lendingstate/statedb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ func (ls *LendingStateDB) Commit() (root common.Hash, err error) {
578578
}
579579
}
580580
// Write trie changes.
581-
root, err = ls.trie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash) error {
581+
root, err = ls.trie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash, _ []byte) error {
582582
var exchange lendingObject
583583
if err := rlp.DecodeBytes(leaf, &exchange); err != nil {
584584
return nil

core/state/statedb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) {
835835
// Write the account trie changes, measuing the amount of wasted time
836836
start := time.Now()
837837

838-
root, accountCommitted, err := s.trie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash) error {
838+
root, accountCommitted, err := s.trie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash, _ []byte) error {
839839
var account types.StateAccount
840840
if err := rlp.DecodeBytes(leaf, &account); err != nil {
841841
return nil

core/state/sync.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,29 @@ import (
2727
)
2828

2929
// NewStateSync create a new state trie download scheduler.
30-
func NewStateSync(root common.Hash, database ethdb.KeyValueReader, onLeaf func(paths [][]byte, leaf []byte) error) *trie.Sync {
30+
func NewStateSync(root common.Hash, database ethdb.KeyValueReader, onLeaf func(keys [][]byte, leaf []byte) error) *trie.Sync {
3131
// Register the storage slot callback if the external callback is specified.
32-
var onSlot func(paths [][]byte, hexpath []byte, leaf []byte, parent common.Hash) error
32+
var onSlot func(keys [][]byte, path []byte, leaf []byte, parent common.Hash, parentPath []byte) error
3333
if onLeaf != nil {
34-
onSlot = func(paths [][]byte, hexpath []byte, leaf []byte, parent common.Hash) error {
35-
return onLeaf(paths, leaf)
34+
onSlot = func(keys [][]byte, path []byte, leaf []byte, parent common.Hash, parentPath []byte) error {
35+
return onLeaf(keys, leaf)
3636
}
3737
}
3838
// Register the account callback to connect the state trie and the storage
3939
// trie belongs to the contract.
4040
var syncer *trie.Sync
41-
onAccount := func(paths [][]byte, hexpath []byte, leaf []byte, parent common.Hash) error {
41+
onAccount := func(keys [][]byte, path []byte, leaf []byte, parent common.Hash, parentPath []byte) error {
4242
if onLeaf != nil {
43-
if err := onLeaf(paths, leaf); err != nil {
43+
if err := onLeaf(keys, leaf); err != nil {
4444
return err
4545
}
4646
}
4747
var obj types.StateAccount
4848
if err := rlp.Decode(bytes.NewReader(leaf), &obj); err != nil {
4949
return err
5050
}
51-
syncer.AddSubTrie(obj.Root, hexpath, parent, onSlot)
52-
syncer.AddCodeEntry(common.BytesToHash(obj.CodeHash), hexpath, parent)
51+
syncer.AddSubTrie(obj.Root, path, parent, parentPath, onSlot)
52+
syncer.AddCodeEntry(common.BytesToHash(obj.CodeHash), path, parent, parentPath)
5353
return nil
5454
}
5555
syncer = trie.NewSync(root, database, onAccount)

0 commit comments

Comments
 (0)