mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 02:40:45 +00:00
a few fixes after hoodi testing
This commit is contained in:
parent
d82e83d2d9
commit
68621ae05a
4 changed files with 37 additions and 43 deletions
|
|
@ -71,18 +71,20 @@ func ArchivedNodeResolver(offset, size uint64) ([]*Record, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var records []*Record
|
var records []*Record
|
||||||
|
stream := rlp.NewStream(bytes.NewReader(data), uint64(len(data)))
|
||||||
for len(data) > 0 {
|
for len(data) > 0 {
|
||||||
stream := rlp.NewStream(bytes.NewReader(data), uint64(len(data)))
|
|
||||||
_, size, err := stream.Kind()
|
_, size, err := stream.Kind()
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error getting rlp kind from archive data: %w", err)
|
return nil, fmt.Errorf("error getting rlp kind from archive data: %w", err)
|
||||||
}
|
}
|
||||||
var record Record
|
var record Record
|
||||||
err = rlp.DecodeBytes(data[:size], &record)
|
err = stream.Decode(&record)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error decoding rlp record from archive data: %w", err)
|
return nil, fmt.Errorf("error decoding rlp record from archive data: %w", err)
|
||||||
}
|
}
|
||||||
data = data[size:]
|
|
||||||
records = append(records, &record)
|
records = append(records, &record)
|
||||||
}
|
}
|
||||||
return records, nil
|
return records, nil
|
||||||
|
|
|
||||||
|
|
@ -83,18 +83,11 @@ func NewArchiver(db ethdb.Database, triedb database.NodeDatabase,
|
||||||
func (a *Archiver) ProcessState(root common.Hash) error {
|
func (a *Archiver) ProcessState(root common.Hash) error {
|
||||||
a.stateRoot = root
|
a.stateRoot = root
|
||||||
|
|
||||||
// Process account trie (owner = zero hash)
|
|
||||||
log.Info("Processing account trie", "root", root)
|
|
||||||
accountTrie, err := New(StateTrieID(root), a.triedb)
|
accountTrie, err := New(StateTrieID(root), a.triedb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open account trie: %w", err)
|
return fmt.Errorf("failed to open account trie: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := a.processTrie(common.Hash{}, accountTrie); err != nil {
|
|
||||||
return fmt.Errorf("failed to process account trie: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process storage tries for accounts with storage
|
|
||||||
log.Info("Processing storage tries")
|
log.Info("Processing storage tries")
|
||||||
iter, err := accountTrie.NodeIterator(nil)
|
iter, err := accountTrie.NodeIterator(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -131,6 +124,11 @@ func (a *Archiver) ProcessState(root common.Hash) error {
|
||||||
return fmt.Errorf("account iteration error: %w", kvIter.Err)
|
return fmt.Errorf("account iteration error: %w", kvIter.Err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Info("Processing account trie", "root", root)
|
||||||
|
if err := a.processTrie(common.Hash{}, accountTrie); err != nil {
|
||||||
|
return fmt.Errorf("failed to process account trie: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
58
trie/trie.go
58
trie/trie.go
|
|
@ -230,30 +230,33 @@ func (t *Trie) get(origNode node, key []byte, pos int) (value []byte, newnode no
|
||||||
value, newnode, _, err := t.get(child, key, pos)
|
value, newnode, _, err := t.get(child, key, pos)
|
||||||
return value, newnode, true, err
|
return value, newnode, true, err
|
||||||
case *expiredNode:
|
case *expiredNode:
|
||||||
if t.archiveResolver == nil {
|
records, err := archive.ArchivedNodeResolver(n.offset, n.size)
|
||||||
return nil, n, false, archive.ErrNoResolver
|
|
||||||
}
|
|
||||||
records, err := t.archiveResolver(n.offset, n.size)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, n, false, fmt.Errorf("failed to resolve expired node: %w", err)
|
return nil, n, false, fmt.Errorf("failed to resolve expired node: %w", err)
|
||||||
}
|
}
|
||||||
newnode, err := archiveRecordsToNode(records)
|
newnode, err := archiveRecordsToNode(records)
|
||||||
for _, record := range records {
|
// alternative: don't rebuild, just find the value
|
||||||
// make sure that the path up to the node matches
|
// for _, record := range records {
|
||||||
if bytes.HasPrefix(key[pos:], record.Path) {
|
// // make sure that the path up to the node matches
|
||||||
resolved, err := decodeNodeUnsafe(nil, record.Value)
|
// if bytes.HasPrefix(key[pos:], record.Path) {
|
||||||
if err != nil {
|
// resolved, err := decodeNodeUnsafe(nil, record.Value)
|
||||||
return nil, n, false, fmt.Errorf("failed to deserialize RLP node: %w", err)
|
// if err != nil {
|
||||||
}
|
// fmt.Printf("%v %x\n", record.Path, record.Value)
|
||||||
if leaf, ok := resolved.(*shortNode); ok {
|
// return nil, n, false, fmt.Errorf("failed to deserialize RLP node: %w", err)
|
||||||
// make sure that the key to the leaf also matches
|
// }
|
||||||
if bytes.Equal(key[pos+len(record.Path):], leaf.Key) {
|
// if leaf, ok := resolved.(*shortNode); ok {
|
||||||
return leaf.Val.(valueNode), newnode, true, nil
|
// // make sure that the key to the leaf also matches
|
||||||
}
|
// if bytes.Equal(key[pos+len(record.Path):], leaf.Key) {
|
||||||
}
|
// return leaf.Val.(valueNode), newnode, true, nil
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
if err != nil {
|
||||||
|
return nil, n, false, err
|
||||||
}
|
}
|
||||||
return value, newnode, false, err
|
value, _, _, err = t.get(newnode, key, pos+1)
|
||||||
|
return value, newnode, true, err
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("%T: invalid node: %v", origNode, origNode))
|
panic(fmt.Sprintf("%T: invalid node: %v", origNode, origNode))
|
||||||
}
|
}
|
||||||
|
|
@ -389,10 +392,7 @@ func (t *Trie) getNode(origNode node, path []byte, pos int) (item []byte, newnod
|
||||||
return item, newnode, resolved + 1, err
|
return item, newnode, resolved + 1, err
|
||||||
|
|
||||||
case *expiredNode:
|
case *expiredNode:
|
||||||
if t.archiveResolver == nil {
|
records, err := archive.ArchivedNodeResolver(n.offset, n.size)
|
||||||
return nil, n, 0, archive.ErrNoResolver
|
|
||||||
}
|
|
||||||
records, err := t.archiveResolver(n.offset, n.size)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, n, 0, fmt.Errorf("failed to resolve expired node: %w", err)
|
return nil, n, 0, fmt.Errorf("failed to resolve expired node: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -524,10 +524,7 @@ func (t *Trie) insert(n node, prefix, key []byte, value node) (bool, node, error
|
||||||
return true, nn, nil
|
return true, nn, nil
|
||||||
|
|
||||||
case *expiredNode:
|
case *expiredNode:
|
||||||
if t.archiveResolver == nil {
|
records, err := archive.ArchivedNodeResolver(n.offset, n.size)
|
||||||
return false, nil, archive.ErrNoResolver
|
|
||||||
}
|
|
||||||
records, err := t.archiveResolver(n.offset, n.size)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil, fmt.Errorf("failed to resolve expired node: %w", err)
|
return false, nil, fmt.Errorf("failed to resolve expired node: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -700,10 +697,7 @@ func (t *Trie) delete(n node, prefix, key []byte) (bool, node, error) {
|
||||||
return true, nn, nil
|
return true, nn, nil
|
||||||
|
|
||||||
case *expiredNode:
|
case *expiredNode:
|
||||||
if t.archiveResolver == nil {
|
records, err := archive.ArchivedNodeResolver(n.offset, n.size)
|
||||||
return false, nil, archive.ErrNoResolver
|
|
||||||
}
|
|
||||||
records, err := t.archiveResolver(n.offset, n.size)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil, fmt.Errorf("failed to resolve expired node: %w", err)
|
return false, nil, fmt.Errorf("failed to resolve expired node: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -748,7 +742,7 @@ func copyNode(n node) node {
|
||||||
return &expiredNode{
|
return &expiredNode{
|
||||||
offset: n.offset,
|
offset: n.offset,
|
||||||
size: n.size,
|
size: n.size,
|
||||||
archiveResolver: n.archiveResolver,
|
archiveResolver: archive.ArchivedNodeResolver,
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("%T: unknown node type", n))
|
panic(fmt.Sprintf("%T: unknown node type", n))
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ func (r *reader) Node(owner common.Hash, path []byte, hash common.Hash) ([]byte,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Error out if the local one is inconsistent with the target.
|
// Error out if the local one is inconsistent with the target.
|
||||||
if !r.noHashCheck && got != hash {
|
if !r.noHashCheck && (len(blob) > 0 && blob[0] != 0) && got != hash {
|
||||||
// Location is always available even if the node
|
// Location is always available even if the node
|
||||||
// is not found.
|
// is not found.
|
||||||
switch loc.loc {
|
switch loc.loc {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue