Skip to content

Commit

Permalink
fix: rebase bsc/pbss_active conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
asyukii committed Sep 25, 2023
1 parent f27fd99 commit 8b2cbbd
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 38 deletions.
2 changes: 1 addition & 1 deletion cmd/geth/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func inspectTrie(ctx *cli.Context) error {
log.Error("Empty root hash")
}
fmt.Printf("ReadBlockHeader, root: %v, blocknum: %v\n", blockRoot, blockNumber)
trieDB := trie.NewDatabase(db)
trieDB := trie.NewDatabase(db, nil)
theTrie, err := trie.New(trie.TrieID(blockRoot), trieDB)
if err != nil {
fmt.Printf("fail to new trie tree, err: %v, rootHash: %v\n", err, blockRoot.String())
Expand Down
65 changes: 33 additions & 32 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1227,49 +1227,50 @@ func (bc *BlockChain) Stop() {
if !bc.cacheConfig.TrieDirtyDisabled {
triedb := bc.triedb

for _, offset := range []uint64{0, 1, bc.triesInMemory - 1} {
if number := bc.CurrentBlock().Number.Uint64(); number > offset {
recent := bc.GetBlockByNumber(number - offset)

log.Info("Writing cached state to disk", "block", recent.Number(), "hash", recent.Hash(), "root", recent.Root())
if err := triedb.Commit(recent.Root(), true); err != nil {
for _, offset := range []uint64{0, 1, bc.triesInMemory - 1} {
if number := bc.CurrentBlock().Number.Uint64(); number > offset {
recent := bc.GetBlockByNumber(number - offset)

log.Info("Writing cached state to disk", "block", recent.Number(), "hash", recent.Hash(), "root", recent.Root())
if err := triedb.Commit(recent.Root(), true); err != nil {
log.Error("Failed to commit recent state trie", "err", err)
} else {
rawdb.WriteSafePointBlockNumber(bc.db, recent.NumberU64())
}
}
}
if snapBase != (common.Hash{}) {
log.Info("Writing snapshot state to disk", "root", snapBase)
if err := triedb.Commit(snapBase, true); err != nil {
log.Error("Failed to commit recent state trie", "err", err)
} else {
rawdb.WriteSafePointBlockNumber(bc.db, recent.NumberU64())
rawdb.WriteSafePointBlockNumber(bc.db, bc.CurrentBlock().Number.Uint64())
}
if err := triedb.CommitEpochMeta(snapBase); err != nil {
log.Error("Failed to commit recent epoch meta", "err", err)
}
}
}
if snapBase != (common.Hash{}) {
log.Info("Writing snapshot state to disk", "root", snapBase)
if err := triedb.Commit(snapBase, true); err != nil {
log.Error("Failed to commit recent state trie", "err", err)
} else {
rawdb.WriteSafePointBlockNumber(bc.db, bc.CurrentBlock().Number.Uint64())
for !bc.triegc.Empty() {
go triedb.Dereference(bc.triegc.PopItem())
}
if err := triedb.CommitEpochMeta(snapBase); err != nil {
log.Error("Failed to commit recent epoch meta", "err", err)
if size, _ := triedb.Size(); size != 0 {
log.Error("Dangling trie nodes after full cleanup")
}
}
for !bc.triegc.Empty() {
go triedb.Dereference(bc.triegc.PopItem())
}
if size, _ := triedb.Size(); size != 0 {
log.Error("Dangling trie nodes after full cleanup")
}
}

epochMetaSnapTree := bc.triedb.EpochMetaSnapTree()
if epochMetaSnapTree != nil {
if err := epochMetaSnapTree.Journal(); err != nil {
log.Error("Failed to journal epochMetaSnapTree", "err", err)
epochMetaSnapTree := bc.triedb.EpochMetaSnapTree()
if epochMetaSnapTree != nil {
if err := epochMetaSnapTree.Journal(); err != nil {
log.Error("Failed to journal epochMetaSnapTree", "err", err)
}
}
}

// Flush the collected preimages to disk
if err := bc.stateCache.TrieDB().Close(); err != nil {
log.Error("Failed to close trie db", "err", err)
// Flush the collected preimages to disk
if err := bc.stateCache.TrieDB().Close(); err != nil {
log.Error("Failed to close trie db", "err", err)
}
log.Info("Blockchain stopped")
}
log.Info("Blockchain stopped")
}

// StopInsert interrupts all insertion methods, causing them to return
Expand Down
2 changes: 1 addition & 1 deletion core/state/pruner/pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ func (p *Pruner) Prune(root common.Hash) error {
rets = make([]error, 3)
expiryWG sync.WaitGroup
)
trieDB := trie.NewDatabaseWithConfig(p.db, &trie.Config{
trieDB := trie.NewDatabase(p.db, &trie.Config{
EnableStateExpiry: true,
PathDB: nil, // TODO(0xbundler): support later
})
Expand Down
1 change: 1 addition & 0 deletions core/state/state_expiry.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (

// fetchExpiredStorageFromRemote request expired state from remote full state node;
func fetchExpiredStorageFromRemote(fullDB ethdb.FullStateDB, stateRoot common.Hash, addr common.Address, root common.Hash, tr Trie, prefixKey []byte, key common.Hash) (map[string][]byte, error) {
log.Debug("fetching expired storage from remoteDB", "addr", addr, "prefix", prefixKey, "key", key)
proofs, err := fullDB.GetStorageReviveProof(stateRoot, addr, root, []string{common.Bytes2Hex(prefixKey)}, []string{common.Bytes2Hex(key[:])})
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion eth/state_accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (eth *Ethereum) hashState(ctx context.Context, block *types.Block, reexec u

func (eth *Ethereum) pathState(block *types.Block) (*state.StateDB, func(), error) {
// Check if the requested state is available in the live chain.
statedb, err := eth.blockchain.StateAt(block.Root())
statedb, err := eth.blockchain.StateAt(block.Root(), block.Hash(), block.Number())
if err == nil {
return statedb, noopReleaser, nil
}
Expand Down
4 changes: 4 additions & 0 deletions internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ func newTestBackend(t *testing.T, n int, gspec *core.Genesis, generator func(i i
return backend
}

func (b *testBackend) StorageTrie(stateRoot common.Hash, addr common.Address, root common.Hash) (state.Trie, error) {
panic("not implemented")
}

// nolint:unused
func (b *testBackend) setPendingBlock(block *types.Block) {
b.pending = block
Expand Down
4 changes: 4 additions & 0 deletions internal/ethapi/transaction_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ func newBackendMock() *backendMock {
}
}

func (b *backendMock) StorageTrie(stateRoot common.Hash, addr common.Address, root common.Hash) (state.Trie, error) {
panic("not implemented")
}

func (b *backendMock) activateLondon() {
b.current.Number = big.NewInt(1100)
}
Expand Down
7 changes: 7 additions & 0 deletions trie/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ func NewDatabase(diskdb ethdb.Database, config *Config) *Database {
}
db.backend = hashdb.New(diskdb, config.HashDB, mptResolver{})
}
if config != nil && config.EnableStateExpiry {
snapTree, err := epochmeta.NewEpochMetaSnapTree(diskdb)
if err != nil {
panic(fmt.Sprintf("init SnapshotTree err: %v", err))
}
db.snapTree = snapTree
}
return db
}

Expand Down
4 changes: 2 additions & 2 deletions trie/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func makeProvers(trie *Trie) []func(key []byte) *memorydb.Database {
}

func TestOneElementPathProof(t *testing.T) {
trie := NewEmpty(NewDatabase(rawdb.NewMemoryDatabase()))
trie := NewEmpty(NewDatabase(rawdb.NewMemoryDatabase(), nil))
updateString(trie, "k", "v")

var proofList proofList
Expand Down Expand Up @@ -1108,7 +1108,7 @@ func nonRandomTrie(n int) (*Trie, map[string]*kv) {
}

func nonRandomTrieWithExpiry(n int) (*Trie, map[string]*kv) {
db := NewDatabase(rawdb.NewMemoryDatabase())
db := NewDatabase(rawdb.NewMemoryDatabase(), nil)
trie := NewEmpty(db)
trie.currentEpoch = 10
trie.rootEpoch = 10
Expand Down
2 changes: 1 addition & 1 deletion trie/trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ func TestReviveCustom(t *testing.T) {
}

func createCustomTrie(data map[string]string, epoch types.StateEpoch) *Trie {
db := NewDatabase(rawdb.NewMemoryDatabase())
db := NewDatabase(rawdb.NewMemoryDatabase(), nil)
trie := NewEmpty(db)
trie.rootEpoch = epoch
trie.currentEpoch = epoch
Expand Down

0 comments on commit 8b2cbbd

Please sign in to comment.