Skip to content

Commit

Permalink
Merge pull request #95 from kcalvinalvin/2023-12-21-utreexo-index-par…
Browse files Browse the repository at this point in the history
…tial-proof-support

indexers: add methods for partial proof tx propagation
  • Loading branch information
kcalvinalvin authored Dec 21, 2023
2 parents acb4603 + 2116123 commit 09a0c64
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
37 changes: 37 additions & 0 deletions blockchain/indexers/flatutreexoproofindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,43 @@ func (idx *FlatUtreexoProofIndex) FetchUtreexoProof(height int32, excludeAccProo
return ud, nil
}

// GetLeafHashPositions returns the positions of the passed in hashes.
func (idx *FlatUtreexoProofIndex) GetLeafHashPositions(delHashes []utreexo.Hash) []uint64 {
idx.mtx.RLock()
defer idx.mtx.RUnlock()

return idx.utreexoState.state.GetLeafPositions(delHashes)
}

// GenerateUDataPartial generates a utreexo data based on the current state of the accumulator.
// It leaves out the full proof hashes and only fetches the requested positions.
func (idx *FlatUtreexoProofIndex) GenerateUDataPartial(dels []wire.LeafData, positions []uint64) (*wire.UData, error) {
idx.mtx.RLock()
defer idx.mtx.RUnlock()

ud := new(wire.UData)
ud.LeafDatas = dels

// Get the positions of the targets of delHashes.
delHashes, err := wire.HashesFromLeafDatas(ud.LeafDatas)
if err != nil {
return nil, err
}

hashes := make([]utreexo.Hash, len(positions))
for i, pos := range positions {
hashes[i] = idx.utreexoState.state.GetHash(pos)
}

targets := idx.utreexoState.state.GetLeafPositions(delHashes)
ud.AccProof = utreexo.Proof{
Targets: targets,
Proof: hashes,
}

return ud, nil
}

// FetchMultiUtreexoProof fetches the utreexo data, multi-block proof, and the hashes for
// the given height. Attempting to fetch multi-block proof at a height where there weren't
// any mulit-block proof generated will result in an error.
Expand Down
37 changes: 37 additions & 0 deletions blockchain/indexers/utreexoproofindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,43 @@ func (idx *UtreexoProofIndex) FetchUtreexoProof(hash *chainhash.Hash) (*wire.UDa
return ud, err
}

// GetLeafHashPositions returns the positions of the passed in hashes.
func (idx *UtreexoProofIndex) GetLeafHashPositions(delHashes []utreexo.Hash) []uint64 {
idx.mtx.RLock()
defer idx.mtx.RUnlock()

return idx.utreexoState.state.GetLeafPositions(delHashes)
}

// GenerateUDataPartial generates a utreexo data based on the current state of the accumulator.
// It leaves out the full proof hashes and only fetches the requested positions.
func (idx *UtreexoProofIndex) GenerateUDataPartial(dels []wire.LeafData, positions []uint64) (*wire.UData, error) {
idx.mtx.RLock()
defer idx.mtx.RUnlock()

ud := new(wire.UData)
ud.LeafDatas = dels

// Get the positions of the targets of delHashes.
delHashes, err := wire.HashesFromLeafDatas(ud.LeafDatas)
if err != nil {
return nil, err
}

hashes := make([]utreexo.Hash, len(positions))
for i, pos := range positions {
hashes[i] = idx.utreexoState.state.GetHash(pos)
}

targets := idx.utreexoState.state.GetLeafPositions(delHashes)
ud.AccProof = utreexo.Proof{
Targets: targets,
Proof: hashes,
}

return ud, nil
}

// GenerateUData generates utreexo data for the dels passed in. Height passed in
// should either be of block height of where the deletions are happening or just
// the lastest block height for mempool tx proof generation.
Expand Down

0 comments on commit 09a0c64

Please sign in to comment.