[trie] create compressed merkle proofs for past tries
@@ -28,19 +28,29 @@ func (s *Trie) MerkleProof(key []byte) ([][]byte, bool, []byte, []byte, error) {
// (key,value) can be 1- (nil, value), value of the included key, 2- the kv of a LeafNode
// on the path of the non-included key, 3- (nil, nil) for a non-included key
// with a DefaultLeaf on the path
-func (s *Trie) MerkleProofPast(key []byte, root []byte) ([][]byte, bool, []byte, []byte, error) {
+func (s *Trie) MerkleProofPast(key, root []byte) ([][]byte, bool, []byte, []byte, error) {
s.lock.RLock()
defer s.lock.RUnlock()
s.atomicUpdate = false // so loadChildren doesnt return a copy
return s.merkleProof(root, key, nil, s.TrieHeight, 0)
}
+// MerkleProofCompressed returns a compressed merkle proof in the given trie
+func (s *Trie) MerkleProofCompressedPast(key, root []byte) ([]byte, [][]byte, int, bool, []byte, []byte, error) {
+ return s.merkleProofCompressed(key, root)
+}
+
// MerkleProofCompressed returns a compressed merkle proof
func (s *Trie) MerkleProofCompressed(key []byte) ([]byte, [][]byte, int, bool, []byte, []byte, error) {
+ return s.merkleProofCompressed(key, s.Root)
+}
+
+func (s *Trie) merkleProofCompressed(key, root []byte) ([]byte, [][]byte, int, bool, []byte, []byte, error) {
s.lock.RLock()
defer s.lock.RUnlock()
+ s.atomicUpdate = false // so loadChildren doesnt return a copy
// create a regular merkle proof and then compress it
- mpFull, included, proofKey, proofVal, err := s.merkleProof(s.Root, key, nil, s.TrieHeight, 0)
+ mpFull, included, proofKey, proofVal, err := s.merkleProof(root, key, nil, s.TrieHeight, 0)
if err != nil {
return nil, nil, 0, true, nil, nil, err
}
