Skip to content

Commit 786b620

Browse files
authored
Merge pull request #82 from kcalvinalvin/make-csns-able-to-server-2023-10-18
blockchain, wire, main: allow csns to serve utreexo data
2 parents aeddca7 + 196e8d2 commit 786b620

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

blockchain/utreexoviewpoint.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,21 @@ func (b *BlockChain) VerifyUData(ud *wire.UData, txIns []*wire.TxIn) error {
924924
return nil
925925
}
926926

927+
// GenerateUData generates a utreexo data based on the current state of the utreexo viewpoint.
928+
//
929+
// This function is safe for concurrent access.
930+
func (b *BlockChain) GenerateUData(dels []wire.LeafData) (*wire.UData, error) {
931+
b.chainLock.RLock()
932+
defer b.chainLock.RUnlock()
933+
934+
ud, err := wire.GenerateUData(dels, &b.utreexoView.accumulator)
935+
if err != nil {
936+
return nil, err
937+
}
938+
939+
return ud, nil
940+
}
941+
927942
// ChainTipProof represents all the information that is needed to prove that a
928943
// utxo exists in the chain tip with utreexo accumulator proof.
929944
type ChainTipProof struct {

server.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,7 @@ func (s *server) pushTxMsg(sp *serverPeer, hash *chainhash.Hash, doneChan chan<-
15181518
if encoding&wire.UtreexoEncoding == wire.UtreexoEncoding {
15191519
// If utreexo proof index is not present, we can't send the tx
15201520
// as we can't grab the proof for the tx.
1521-
if s.utreexoProofIndex == nil && s.flatUtreexoProofIndex == nil {
1521+
if s.utreexoProofIndex == nil && s.flatUtreexoProofIndex == nil && !cfg.Utreexo {
15221522
err := fmt.Errorf("UtreexoProofIndex and FlatUtreexoProofIndex is nil. " +
15231523
"Cannot fetch utreexo accumulator proofs.")
15241524
srvrLog.Debugf(err.Error())
@@ -1544,8 +1544,10 @@ func (s *server) pushTxMsg(sp *serverPeer, hash *chainhash.Hash, doneChan chan<-
15441544
// generate the UData.
15451545
if s.utreexoProofIndex != nil {
15461546
ud, err = s.utreexoProofIndex.GenerateUData(leafDatas)
1547-
} else {
1547+
} else if s.flatUtreexoProofIndex != nil {
15481548
ud, err = s.flatUtreexoProofIndex.GenerateUData(leafDatas)
1549+
} else {
1550+
ud, err = s.chain.GenerateUData(leafDatas)
15491551
}
15501552
if err != nil {
15511553
chanLog.Errorf(err.Error())
@@ -1575,7 +1577,7 @@ func (s *server) pushBlockMsg(sp *serverPeer, hash *chainhash.Hash, doneChan cha
15751577

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

16181620
// Fetch the Utreexo accumulator proof.
1619-
if doUtreexo {
1621+
if doUtreexo && msgBlock.UData == nil {
16201622
var ud *wire.UData
16211623

16221624
// We already checked that at least one is active. Pick one and

wire/udata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ func DeserializeRemembers(r io.Reader) ([]uint32, error) {
432432
// to get a batched inclusion proof from the accumulator. It then adds on the leaf data,
433433
// to create a block proof which both proves inclusion and gives all utxo data
434434
// needed for transaction verification.
435-
func GenerateUData(txIns []LeafData, pollard *utreexo.Pollard) (
435+
func GenerateUData(txIns []LeafData, pollard utreexo.Utreexo) (
436436
*UData, error) {
437437

438438
ud := new(UData)

0 commit comments

Comments
 (0)