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 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)