Skip to content

Commit 8c486c8

Browse files
committed
main: add OnUtreexoTx
We add support for handling utreexotx messages that we receive from peers.
1 parent de77b1e commit 8c486c8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

server.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,33 @@ func (sp *serverPeer) OnTx(_ *peer.Peer, msg *wire.MsgTx) {
601601
<-sp.txProcessed
602602
}
603603

604+
// OnUtreexoTx is invoked when a peer receives a utreexo tx bitcoin message.
605+
// It blocks until the bitcoin transaction has been fully processed. Unlock the block
606+
// handler this does not serialize all transactions through a single thread
607+
// transactions don't rely on the previous one in a linear fashion like blocks.
608+
func (sp *serverPeer) OnUtreexoTx(_ *peer.Peer, msg *wire.MsgUtreexoTx) {
609+
if cfg.BlocksOnly {
610+
peerLog.Tracef("Ignoring utreexo tx %v from %v - blocksonly enabled",
611+
msg.TxHash(), sp)
612+
return
613+
}
614+
615+
// Add the transaction to the known inventory for the peer.
616+
// Convert the raw MsgUtreexoTx to a btcutil.UtreexoTx which provides some convenience
617+
// methods and things such as hash caching.
618+
tx := btcutil.NewUtreexoTx(msg)
619+
iv := wire.NewInvVect(wire.InvTypeTx, tx.Hash())
620+
sp.AddKnownInventory(iv)
621+
622+
// Queue the transaction up to be handled by the sync manager and
623+
// intentionally block further receives until the transaction is fully
624+
// processed and known good or bad. This helps prevent a malicious peer
625+
// from queuing up a bunch of bad transactions before disconnecting (or
626+
// being disconnected) and wasting memory.
627+
sp.server.syncManager.QueueUtreexoTx(tx, sp.Peer, sp.txProcessed)
628+
<-sp.txProcessed
629+
}
630+
604631
// OnBlock is invoked when a peer receives a block bitcoin message. It
605632
// blocks until the bitcoin block has been fully processed.
606633
func (sp *serverPeer) OnBlock(_ *peer.Peer, msg *wire.MsgBlock, buf []byte) {
@@ -2408,6 +2435,7 @@ func newPeerConfig(sp *serverPeer) *peer.Config {
24082435
OnVerAck: sp.OnVerAck,
24092436
OnMemPool: sp.OnMemPool,
24102437
OnTx: sp.OnTx,
2438+
OnUtreexoTx: sp.OnUtreexoTx,
24112439
OnBlock: sp.OnBlock,
24122440
OnInv: sp.OnInv,
24132441
OnHeaders: sp.OnHeaders,

0 commit comments

Comments
 (0)