Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blockchain, wire, main: allow csns to serve utreexo data #82

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions blockchain/utreexoviewpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,21 @@ func (b *BlockChain) VerifyUData(ud *wire.UData, txIns []*wire.TxIn) error {
return nil
}

// GenerateUData generates a utreexo data based on the current state of the utreexo viewpoint.
//
// This function is safe for concurrent access.
func (b *BlockChain) GenerateUData(dels []wire.LeafData) (*wire.UData, error) {
b.chainLock.RLock()
defer b.chainLock.RUnlock()

ud, err := wire.GenerateUData(dels, &b.utreexoView.accumulator)
if err != nil {
return nil, err
}

return ud, nil
}

// ChainTipProof represents all the information that is needed to prove that a
// utxo exists in the chain tip with utreexo accumulator proof.
type ChainTipProof struct {
Expand Down
10 changes: 6 additions & 4 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ func (s *server) pushTxMsg(sp *serverPeer, hash *chainhash.Hash, doneChan chan<-
if encoding&wire.UtreexoEncoding == wire.UtreexoEncoding {
// If utreexo proof index is not present, we can't send the tx
// as we can't grab the proof for the tx.
if s.utreexoProofIndex == nil && s.flatUtreexoProofIndex == nil {
if s.utreexoProofIndex == nil && s.flatUtreexoProofIndex == nil && !cfg.Utreexo {
err := fmt.Errorf("UtreexoProofIndex and FlatUtreexoProofIndex is nil. " +
"Cannot fetch utreexo accumulator proofs.")
srvrLog.Debugf(err.Error())
Expand All @@ -1544,8 +1544,10 @@ func (s *server) pushTxMsg(sp *serverPeer, hash *chainhash.Hash, doneChan chan<-
// generate the UData.
if s.utreexoProofIndex != nil {
ud, err = s.utreexoProofIndex.GenerateUData(leafDatas)
} else {
} else if s.flatUtreexoProofIndex != nil {
ud, err = s.flatUtreexoProofIndex.GenerateUData(leafDatas)
} else {
ud, err = s.chain.GenerateUData(leafDatas)
}
if err != nil {
chanLog.Errorf(err.Error())
Expand Down Expand Up @@ -1575,7 +1577,7 @@ func (s *server) pushBlockMsg(sp *serverPeer, hash *chainhash.Hash, doneChan cha

// Early check to see if Utreexo proof index is there if UtreexoEncoding is given.
doUtreexo := encoding&wire.UtreexoEncoding == wire.UtreexoEncoding
if doUtreexo && s.utreexoProofIndex == nil && s.flatUtreexoProofIndex == nil {
if doUtreexo && s.utreexoProofIndex == nil && s.flatUtreexoProofIndex == nil && !cfg.Utreexo {
err := fmt.Errorf("UtreexoProofIndex is nil. Cannot fetch utreexo accumulator proofs.")
peerLog.Tracef(err.Error())
if doneChan != nil {
Expand Down Expand Up @@ -1616,7 +1618,7 @@ func (s *server) pushBlockMsg(sp *serverPeer, hash *chainhash.Hash, doneChan cha
}

// Fetch the Utreexo accumulator proof.
if doUtreexo {
if doUtreexo && msgBlock.UData == nil {
var ud *wire.UData

// We already checked that at least one is active. Pick one and
Expand Down
2 changes: 1 addition & 1 deletion wire/udata.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ func DeserializeRemembers(r io.Reader) ([]uint32, error) {
// to get a batched inclusion proof from the accumulator. It then adds on the leaf data,
// to create a block proof which both proves inclusion and gives all utxo data
// needed for transaction verification.
func GenerateUData(txIns []LeafData, pollard *utreexo.Pollard) (
func GenerateUData(txIns []LeafData, pollard utreexo.Utreexo) (
*UData, error) {

ud := new(UData)
Expand Down
Loading