mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 05:36:46 +00:00
triedb/pathdb: fix test
This commit is contained in:
parent
0574091a8d
commit
19000cea88
2 changed files with 29 additions and 19 deletions
|
|
@ -37,19 +37,29 @@ func waitIndexing(db *Database) {
|
|||
}
|
||||
}
|
||||
|
||||
func checkHistoricalState(env *tester, root common.Hash, hr *historyReader) error {
|
||||
// Short circuit if the historical state is no longer available
|
||||
id := rawdb.ReadStateID(env.db.diskdb, root)
|
||||
if id == nil {
|
||||
func stateAvail(id uint64, env *tester) bool {
|
||||
if env.db.config.StateHistory == 0 {
|
||||
return true
|
||||
}
|
||||
dl := env.db.tree.bottom()
|
||||
if dl.stateID() <= env.db.config.StateHistory {
|
||||
return true
|
||||
}
|
||||
firstID := dl.stateID() - env.db.config.StateHistory + 1
|
||||
|
||||
return id+1 >= firstID
|
||||
}
|
||||
|
||||
func checkHistoricalState(env *tester, root common.Hash, id uint64, hr *historyReader) error {
|
||||
if !stateAvail(id, env) {
|
||||
return nil
|
||||
}
|
||||
meta, err := readStateHistoryMeta(env.db.stateFreezer, *id)
|
||||
if err != nil {
|
||||
return nil // e.g., the referred state history has been pruned
|
||||
}
|
||||
if meta.root != root {
|
||||
return fmt.Errorf("state %#x is not canonincal", root)
|
||||
|
||||
// Short circuit if the historical state is no longer available
|
||||
if rawdb.ReadStateID(env.db.diskdb, root) == nil {
|
||||
return fmt.Errorf("state not found %d %x", id, root)
|
||||
}
|
||||
|
||||
var (
|
||||
dl = env.db.tree.bottom()
|
||||
stateID = rawdb.ReadStateID(env.db.diskdb, root)
|
||||
|
|
@ -141,14 +151,14 @@ func testHistoryReader(t *testing.T, historyLimit uint64) {
|
|||
|
||||
var (
|
||||
roots = env.roots
|
||||
dRoot = env.db.tree.bottom().rootHash()
|
||||
dl = env.db.tree.bottom()
|
||||
hr = newHistoryReader(env.db.diskdb, env.db.stateFreezer)
|
||||
)
|
||||
for _, root := range roots {
|
||||
if root == dRoot {
|
||||
for i, root := range roots {
|
||||
if root == dl.rootHash() {
|
||||
break
|
||||
}
|
||||
if err := checkHistoricalState(env, root, hr); err != nil {
|
||||
if err := checkHistoricalState(env, root, uint64(i+1), hr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
@ -157,11 +167,11 @@ func testHistoryReader(t *testing.T, historyLimit uint64) {
|
|||
env.extend(4)
|
||||
waitIndexing(env.db)
|
||||
|
||||
for _, root := range roots {
|
||||
if root == dRoot {
|
||||
for i, root := range roots {
|
||||
if root == dl.rootHash() {
|
||||
break
|
||||
}
|
||||
if err := checkHistoricalState(env, root, hr); err != nil {
|
||||
if err := checkHistoricalState(env, root, uint64(i+1), hr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -224,11 +224,11 @@ func (db *Database) HistoricReader(root common.Hash) (*HistoricalStateReader, er
|
|||
}
|
||||
// Ensure the requested state is canonical, historical states on side chain
|
||||
// are not accessible.
|
||||
meta, err := readStateHistoryMeta(db.stateFreezer, *id)
|
||||
meta, err := readStateHistoryMeta(db.stateFreezer, *id+1)
|
||||
if err != nil {
|
||||
return nil, err // e.g., the referred state history has been pruned
|
||||
}
|
||||
if meta.root != root {
|
||||
if meta.parent != root {
|
||||
return nil, fmt.Errorf("state %#x is not canonincal", root)
|
||||
}
|
||||
return &HistoricalStateReader{
|
||||
|
|
|
|||
Loading…
Reference in a new issue