package p2p import ( "github.com/kaspanet/kaspad/peer" "github.com/kaspanet/kaspad/util" "github.com/kaspanet/kaspad/wire" ) // OnBlock is invoked when a peer receives a block kaspa message. It // blocks until the kaspa block has been fully processed. func (sp *Peer) OnBlock(_ *peer.Peer, msg *wire.MsgBlock, buf []byte) { // Convert the raw MsgBlock to a util.Block which provides some // convenience methods and things such as hash caching. block := util.NewBlockFromBlockAndBytes(msg, buf) // Add the block to the known inventory for the peer. iv := wire.NewInvVect(wire.InvTypeBlock, block.Hash()) sp.AddKnownInventory(iv) // Queue the block up to be handled by the block // manager and intentionally block further receives // until the kaspa block is fully processed and known // good or bad. This helps prevent a malicious peer // from queuing up a bunch of bad blocks before // disconnecting (or being disconnected) and wasting // memory. Additionally, this behavior is depended on // by at least the block acceptance test tool as the // reference implementation processes blocks in the same // thread and therefore blocks further messages until // the kaspa block has been fully processed. sp.server.SyncManager.QueueBlock(block, sp.Peer, false, sp.blockProcessed) <-sp.blockProcessed }