View definition


Defined in


handleGetData is invoked when a peer receives a getdata bitcoin message and is used to deliver block and transaction information.

OnGetData is referenced in 1 repository


		if err != nil {

			// When there is a failure fetching the final entry
			// and the done channel was sent in due to there
			// being no outstanding not found inventory, consume
			// it here because there is now not found inventory
			// that will use the channel momentarily.
			if i == len(msg.InvList)-1 && c != nil {
		waitChan = c
	if len(notFound.InvList) != 0 {
		p.QueueMessage(notFound, doneChan)

	// Wait for messages to be sent. We can send quite a lot of data at this
	// point and this will keep the peer busy for a decent amount of time.
	// We don't process anything else by them in this time so that we
	// have an idea of when we should hear back from them - else the idle
	// timeout could fire when we were only half done sending the blocks.
	if numAdded > 0 {

// OnGetBlocks is invoked when a peer receives a getblocks bitcoin
// message.
func (sp *serverPeer) OnGetBlocks(p *peer.Peer, msg *wire.MsgGetBlocks) {
	// Return all block hashes to the latest one (up to max per message) if
	// no stop hash was specified.
	// Attempt to find the ending index of the stop hash if specified.
	chain := sp.server.blockManager.chain
	endIdx := int32(math.MaxInt32)
	if !msg.HashStop.IsEqual(&zeroHash) {
		height, err := chain.BlockHeightByHash(&msg.HashStop)
		if err == nil {
			endIdx = height + 1

	// Find the most recent known block based on the block locator.
	// Use the block after the genesis block if no other blocks in the
	// provided locator are known.  This does mean the client will start
	// over with the genesis block if unknown block locators are provided.
	// This mirrors the behavior in the reference implementation.
	startIdx := int32(1)
	for _, hash := range msg.BlockLocatorHashes {
		height, err := chain.BlockHeightByHash(hash)
		if err == nil {
			// Start with the next hash since we know this one.
			startIdx = height + 1

	// Don't attempt to fetch more than we can put into a single message.
	autoContinue := false
	if endIdx-startIdx > wire.MaxBlocksPerMsg {
		endIdx = startIdx + wire.MaxBlocksPerMsg
		autoContinue = true

	// Fetch the inventory from the block database.
	hashList, err := chain.HeightRange(startIdx, endIdx)
	if err != nil {
		peerLog.Warnf("Block lookup failed: %v", err)