Skip to content

Commit 2116123

Browse files
committed
indexers: add methods for partial proof tx propagation
The added GetLeafHashPsositions and GenerateUDataPartial are needed to serve partial utreexo proofs to utreexo nodes.
1 parent acb4603 commit 2116123

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

blockchain/indexers/flatutreexoproofindex.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,43 @@ func (idx *FlatUtreexoProofIndex) FetchUtreexoProof(height int32, excludeAccProo
685685
return ud, nil
686686
}
687687

688+
// GetLeafHashPositions returns the positions of the passed in hashes.
689+
func (idx *FlatUtreexoProofIndex) GetLeafHashPositions(delHashes []utreexo.Hash) []uint64 {
690+
idx.mtx.RLock()
691+
defer idx.mtx.RUnlock()
692+
693+
return idx.utreexoState.state.GetLeafPositions(delHashes)
694+
}
695+
696+
// GenerateUDataPartial generates a utreexo data based on the current state of the accumulator.
697+
// It leaves out the full proof hashes and only fetches the requested positions.
698+
func (idx *FlatUtreexoProofIndex) GenerateUDataPartial(dels []wire.LeafData, positions []uint64) (*wire.UData, error) {
699+
idx.mtx.RLock()
700+
defer idx.mtx.RUnlock()
701+
702+
ud := new(wire.UData)
703+
ud.LeafDatas = dels
704+
705+
// Get the positions of the targets of delHashes.
706+
delHashes, err := wire.HashesFromLeafDatas(ud.LeafDatas)
707+
if err != nil {
708+
return nil, err
709+
}
710+
711+
hashes := make([]utreexo.Hash, len(positions))
712+
for i, pos := range positions {
713+
hashes[i] = idx.utreexoState.state.GetHash(pos)
714+
}
715+
716+
targets := idx.utreexoState.state.GetLeafPositions(delHashes)
717+
ud.AccProof = utreexo.Proof{
718+
Targets: targets,
719+
Proof: hashes,
720+
}
721+
722+
return ud, nil
723+
}
724+
688725
// FetchMultiUtreexoProof fetches the utreexo data, multi-block proof, and the hashes for
689726
// the given height. Attempting to fetch multi-block proof at a height where there weren't
690727
// any mulit-block proof generated will result in an error.

blockchain/indexers/utreexoproofindex.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,43 @@ func (idx *UtreexoProofIndex) FetchUtreexoProof(hash *chainhash.Hash) (*wire.UDa
234234
return ud, err
235235
}
236236

237+
// GetLeafHashPositions returns the positions of the passed in hashes.
238+
func (idx *UtreexoProofIndex) GetLeafHashPositions(delHashes []utreexo.Hash) []uint64 {
239+
idx.mtx.RLock()
240+
defer idx.mtx.RUnlock()
241+
242+
return idx.utreexoState.state.GetLeafPositions(delHashes)
243+
}
244+
245+
// GenerateUDataPartial generates a utreexo data based on the current state of the accumulator.
246+
// It leaves out the full proof hashes and only fetches the requested positions.
247+
func (idx *UtreexoProofIndex) GenerateUDataPartial(dels []wire.LeafData, positions []uint64) (*wire.UData, error) {
248+
idx.mtx.RLock()
249+
defer idx.mtx.RUnlock()
250+
251+
ud := new(wire.UData)
252+
ud.LeafDatas = dels
253+
254+
// Get the positions of the targets of delHashes.
255+
delHashes, err := wire.HashesFromLeafDatas(ud.LeafDatas)
256+
if err != nil {
257+
return nil, err
258+
}
259+
260+
hashes := make([]utreexo.Hash, len(positions))
261+
for i, pos := range positions {
262+
hashes[i] = idx.utreexoState.state.GetHash(pos)
263+
}
264+
265+
targets := idx.utreexoState.state.GetLeafPositions(delHashes)
266+
ud.AccProof = utreexo.Proof{
267+
Targets: targets,
268+
Proof: hashes,
269+
}
270+
271+
return ud, nil
272+
}
273+
237274
// GenerateUData generates utreexo data for the dels passed in. Height passed in
238275
// should either be of block height of where the deletions are happening or just
239276
// the lastest block height for mempool tx proof generation.

0 commit comments

Comments
 (0)