Skip to content

Commit

Permalink
blockchain: add GenerateUDataPartial
Browse files Browse the repository at this point in the history
GenerateUDataPartial allows for the generation of partial udata to serve
to other utreexo nodes.
  • Loading branch information
kcalvinalvin committed Dec 21, 2023
1 parent 70a9fea commit 32f3e68
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions blockchain/utreexoviewpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,39 @@ func (b *BlockChain) VerifyUData(ud *wire.UData, txIns []*wire.TxIn, remember bo
return nil
}

// GenerateUDataPartial generates a utreexo data based on the current state of the utreexo viewpoint.
// It leaves out the full proof hashes and only fetches the requested positions.
//
// This function is safe for concurrent access.
func (b *BlockChain) GenerateUDataPartial(dels []wire.LeafData, positions []uint64) (*wire.UData, error) {
b.chainLock.RLock()
defer b.chainLock.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
}
targets := b.getLeafHashPositions(delHashes)

// Fetch the requested hashes.
hashes := make([]utreexo.Hash, len(positions))
for i, pos := range positions {
hashes[i] = b.utreexoView.accumulator.GetHash(pos)
}

// Put the proof together and return.
ud.AccProof = utreexo.Proof{
Targets: targets,
Proof: hashes,
}

return ud, nil
}

// GenerateUData generates a utreexo data based on the current state of the utreexo viewpoint.
//
// This function is safe for concurrent access.
Expand Down

0 comments on commit 32f3e68

Please sign in to comment.