Skip to content

Commit

Permalink
blockchain, main: allow csns to serve utreexo data
Browse files Browse the repository at this point in the history
The server code that only allowed for bridge nodes to serve blocks/tx to
utreexo nodes is now changed so that a csn that has all the neccessary
data is able to send data to another csn.
  • Loading branch information
kcalvinalvin committed Oct 18, 2023
1 parent 87f43be commit 196e8d2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
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

0 comments on commit 196e8d2

Please sign in to comment.