From 87f43bed8cb031cedbdcae744ee08797b194693c Mon Sep 17 00:00:00 2001 From: Calvin Kim Date: Wed, 18 Oct 2023 17:34:09 +0900 Subject: [PATCH 1/2] wire: change GenerateUData to take in utreexo.Utreexo Mostly so it's more generic and isn't stuck with just utreexo.Pollard. --- wire/udata.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wire/udata.go b/wire/udata.go index 5a420a1e..ab7457ed 100644 --- a/wire/udata.go +++ b/wire/udata.go @@ -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) From 196e8d28c0388ee3c2069e5645f4db8576103a22 Mon Sep 17 00:00:00 2001 From: Calvin Kim Date: Wed, 18 Oct 2023 17:36:55 +0900 Subject: [PATCH 2/2] blockchain, main: allow csns to serve utreexo data 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. --- blockchain/utreexoviewpoint.go | 15 +++++++++++++++ server.go | 10 ++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/blockchain/utreexoviewpoint.go b/blockchain/utreexoviewpoint.go index 8190943f..15a1e726 100644 --- a/blockchain/utreexoviewpoint.go +++ b/blockchain/utreexoviewpoint.go @@ -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 { diff --git a/server.go b/server.go index 69f53d6c..02734226 100644 --- a/server.go +++ b/server.go @@ -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()) @@ -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()) @@ -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 { @@ -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