erigon-pulse/trie/trie_witness.go
Alex Sharov d2286bff1c
Naive implementation of MGR P2P SubProtocol (#403)
* use NoValues cursor where possible

* add ctx

* fix broken logs

* rebase master

* rebase master

* simplify generators

* hack to measure space distribution

* naive epoch and chunking implementation

* make stateless loop cancelable

* make stateless loop cancelable

* remove one rlp layer

* eth64 protocol support - add forkId to status message
2020-03-25 15:40:30 +00:00

31 lines
1.2 KiB
Go

package trie
import "errors"
func (t *Trie) ExtractWitness(blockNr uint64, trace bool, rs *ResolveSet) (*Witness, error) {
return extractWitnessFromRootNode(t.root, blockNr, trace, rs)
}
func (t *Trie) ExtractWitnessForPrefix(prefix []byte, blockNr uint64, trace bool, rs *ResolveSet) (*Witness, error) {
node, _, found := t.getNode(prefix, false)
if !found {
return nil, errors.New("no data found for given prefix")
}
return extractWitnessFromRootNode(node, blockNr, trace, rs)
}
// extractWitnessFromRootNode extracts a witness for a subtrie starting from the specified root
// if hashOnly param is nil it will make a witness for the full subtrie,
// if hashOnly param is set to a ResolveSet instance, it will make a witness for only the accounts/storages that were actually touched; other paths will be hashed.
func extractWitnessFromRootNode(root node, blockNr uint64, trace bool, hashOnly HashOnly) (*Witness, error) {
builder := NewWitnessBuilder(root, blockNr, trace)
var limiter *MerklePathLimiter
if hashOnly != nil {
hr := newHasher(false)
defer returnHasherToPool(hr)
limiter = &MerklePathLimiter{hashOnly, hr.hash}
}
return builder.Build(limiter)
}