mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-07 14:46:44 +00:00
[NOD-262] Renamed all instances of GetBlocks to GetBlockInvs. (#359)
This commit is contained in:
parent
594a209f83
commit
e5485ac5e6
@ -293,7 +293,7 @@ func (sm *SyncManager) startSync() {
|
|||||||
"%d from peer %s", sm.dag.ChainHeight()+1,
|
"%d from peer %s", sm.dag.ChainHeight()+1,
|
||||||
sm.nextCheckpoint.ChainHeight, bestPeer.Addr()) //TODO: (Ori) This is probably wrong. Done only for compilation
|
sm.nextCheckpoint.ChainHeight, bestPeer.Addr()) //TODO: (Ori) This is probably wrong. Done only for compilation
|
||||||
} else {
|
} else {
|
||||||
bestPeer.PushGetBlocksMsg(locator, &daghash.ZeroHash)
|
bestPeer.PushGetBlockInvsMsg(locator, &daghash.ZeroHash)
|
||||||
}
|
}
|
||||||
sm.syncPeer = bestPeer
|
sm.syncPeer = bestPeer
|
||||||
} else {
|
} else {
|
||||||
@ -674,9 +674,9 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) {
|
|||||||
sm.headerList.Init()
|
sm.headerList.Init()
|
||||||
log.Infof("Reached the final checkpoint -- switching to normal mode")
|
log.Infof("Reached the final checkpoint -- switching to normal mode")
|
||||||
locator := blockdag.BlockLocator([]*daghash.Hash{blockHash})
|
locator := blockdag.BlockLocator([]*daghash.Hash{blockHash})
|
||||||
err = peer.PushGetBlocksMsg(locator, &daghash.ZeroHash)
|
err = peer.PushGetBlockInvsMsg(locator, &daghash.ZeroHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("Failed to send getblocks message to peer %s: %s",
|
log.Warnf("Failed to send getblockinvs message to peer %s: %s",
|
||||||
peer.Addr(), err)
|
peer.Addr(), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1018,7 +1018,7 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) {
|
|||||||
// final one the remote peer knows about (zero
|
// final one the remote peer knows about (zero
|
||||||
// stop hash).
|
// stop hash).
|
||||||
locator := sm.dag.BlockLocatorFromHash(iv.Hash)
|
locator := sm.dag.BlockLocatorFromHash(iv.Hash)
|
||||||
peer.PushGetBlocksMsg(locator, &daghash.ZeroHash)
|
peer.PushGetBlockInvsMsg(locator, &daghash.ZeroHash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ A quick overview of the major features peer provides are as follows:
|
|||||||
- Does not invoke the related callbacks for older protocol versions
|
- Does not invoke the related callbacks for older protocol versions
|
||||||
- Snapshottable peer statistics such as the total number of bytes read and
|
- Snapshottable peer statistics such as the total number of bytes read and
|
||||||
written, the remote address, user agent, and negotiated protocol version
|
written, the remote address, user agent, and negotiated protocol version
|
||||||
- Helper functions pushing addresses, getblocks, getheaders, and reject
|
- Helper functions pushing addresses, getblockinvs, getheaders, and reject
|
||||||
messages
|
messages
|
||||||
- These could all be sent manually via the standard message output function,
|
- These could all be sent manually via the standard message output function,
|
||||||
but the helpers provide additional nice functionality such as duplicate
|
but the helpers provide additional nice functionality such as duplicate
|
||||||
|
@ -42,7 +42,7 @@ A quick overview of the major features peer provides are as follows:
|
|||||||
- Does not invoke the related callbacks for older protocol versions
|
- Does not invoke the related callbacks for older protocol versions
|
||||||
- Snapshottable peer statistics such as the total number of bytes read and
|
- Snapshottable peer statistics such as the total number of bytes read and
|
||||||
written, the remote address, user agent, and negotiated protocol version
|
written, the remote address, user agent, and negotiated protocol version
|
||||||
- Helper functions pushing addresses, getblocks, getheaders, and reject
|
- Helper functions pushing addresses, getblockinvs, getheaders, and reject
|
||||||
messages
|
messages
|
||||||
- These could all be sent manually via the standard message output function,
|
- These could all be sent manually via the standard message output function,
|
||||||
but the helpers provide additional nice functionality such as duplicate
|
but the helpers provide additional nice functionality such as duplicate
|
||||||
@ -109,7 +109,7 @@ of a most-recently used algorithm.
|
|||||||
Message Sending Helper Functions
|
Message Sending Helper Functions
|
||||||
|
|
||||||
In addition to the bare QueueMessage function previously described, the
|
In addition to the bare QueueMessage function previously described, the
|
||||||
PushAddrMsg, PushGetBlocksMsg, PushGetHeadersMsg, and PushRejectMsg functions
|
PushAddrMsg, PushGetBlockInvsMsg, PushGetHeadersMsg, and PushRejectMsg functions
|
||||||
are provided as a convenience. While it is of course possible to create and
|
are provided as a convenience. While it is of course possible to create and
|
||||||
send these message manually via QueueMessage, these helper functions provided
|
send these message manually via QueueMessage, these helper functions provided
|
||||||
additional useful functionality that is typically desired.
|
additional useful functionality that is typically desired.
|
||||||
@ -120,7 +120,7 @@ there are too many. This allows the caller to simply provide a slice of known
|
|||||||
addresses, such as that returned by the addrmgr package, without having to worry
|
addresses, such as that returned by the addrmgr package, without having to worry
|
||||||
about the details.
|
about the details.
|
||||||
|
|
||||||
Next, the PushGetBlocksMsg and PushGetHeadersMsg functions will construct proper
|
Next, the PushGetBlockInvsMsg and PushGetHeadersMsg functions will construct proper
|
||||||
messages using a block locator and ignore back to back duplicate requests.
|
messages using a block locator and ignore back to back duplicate requests.
|
||||||
|
|
||||||
Finally, the PushRejectMsg function can be used to easily create and send an
|
Finally, the PushRejectMsg function can be used to easily create and send an
|
||||||
|
@ -178,7 +178,7 @@ func messageSummary(msg wire.Message) string {
|
|||||||
case *wire.MsgGetData:
|
case *wire.MsgGetData:
|
||||||
return invSummary(msg.InvList)
|
return invSummary(msg.InvList)
|
||||||
|
|
||||||
case *wire.MsgGetBlocks:
|
case *wire.MsgGetBlockInvs:
|
||||||
return locatorSummary(msg.BlockLocatorHashes, msg.StopHash)
|
return locatorSummary(msg.BlockLocatorHashes, msg.StopHash)
|
||||||
|
|
||||||
case *wire.MsgGetHeaders:
|
case *wire.MsgGetHeaders:
|
||||||
|
62
peer/peer.go
62
peer/peer.go
@ -147,9 +147,9 @@ type MessageListeners struct {
|
|||||||
// OnGetData is invoked when a peer receives a getdata bitcoin message.
|
// OnGetData is invoked when a peer receives a getdata bitcoin message.
|
||||||
OnGetData func(p *Peer, msg *wire.MsgGetData)
|
OnGetData func(p *Peer, msg *wire.MsgGetData)
|
||||||
|
|
||||||
// OnGetBlocks is invoked when a peer receives a getblocks bitcoin
|
// OnGetBlockInvs is invoked when a peer receives a getblockinvs bitcoin
|
||||||
// message.
|
// message.
|
||||||
OnGetBlocks func(p *Peer, msg *wire.MsgGetBlocks)
|
OnGetBlockInvs func(p *Peer, msg *wire.MsgGetBlockInvs)
|
||||||
|
|
||||||
// OnGetHeaders is invoked when a peer receives a getheaders bitcoin
|
// OnGetHeaders is invoked when a peer receives a getheaders bitcoin
|
||||||
// message.
|
// message.
|
||||||
@ -443,13 +443,13 @@ type Peer struct {
|
|||||||
sendHeadersPreferred bool // peer sent a sendheaders message
|
sendHeadersPreferred bool // peer sent a sendheaders message
|
||||||
verAckReceived bool
|
verAckReceived bool
|
||||||
|
|
||||||
knownInventory *mruInventoryMap
|
knownInventory *mruInventoryMap
|
||||||
prevGetBlocksMtx sync.Mutex
|
prevGetBlockInvsMtx sync.Mutex
|
||||||
prevGetBlocksBegin *daghash.Hash
|
prevGetBlockInvsBegin *daghash.Hash
|
||||||
prevGetBlocksStop *daghash.Hash
|
prevGetBlockInvsStop *daghash.Hash
|
||||||
prevGetHdrsMtx sync.Mutex
|
prevGetHdrsMtx sync.Mutex
|
||||||
prevGetHdrsBegin *daghash.Hash
|
prevGetHdrsBegin *daghash.Hash
|
||||||
prevGetHdrsStop *daghash.Hash
|
prevGetHdrsStop *daghash.Hash
|
||||||
|
|
||||||
// These fields keep track of statistics for the peer and are protected
|
// These fields keep track of statistics for the peer and are protected
|
||||||
// by the statsMtx mutex.
|
// by the statsMtx mutex.
|
||||||
@ -858,33 +858,33 @@ func (p *Peer) PushAddrMsg(addresses []*wire.NetAddress, subnetworkID *subnetwor
|
|||||||
return msg.AddrList, nil
|
return msg.AddrList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PushGetBlocksMsg sends a getblocks message for the provided block locator
|
// PushGetBlockInvsMsg sends a getblockinvs message for the provided block locator
|
||||||
// and stop hash. It will ignore back-to-back duplicate requests.
|
// and stop hash. It will ignore back-to-back duplicate requests.
|
||||||
//
|
//
|
||||||
// This function is safe for concurrent access.
|
// This function is safe for concurrent access.
|
||||||
func (p *Peer) PushGetBlocksMsg(locator blockdag.BlockLocator, stopHash *daghash.Hash) error {
|
func (p *Peer) PushGetBlockInvsMsg(locator blockdag.BlockLocator, stopHash *daghash.Hash) error {
|
||||||
// Extract the begin hash from the block locator, if one was specified,
|
// Extract the begin hash from the block locator, if one was specified,
|
||||||
// to use for filtering duplicate getblocks requests.
|
// to use for filtering duplicate getblockinvs requests.
|
||||||
var beginHash *daghash.Hash
|
var beginHash *daghash.Hash
|
||||||
if len(locator) > 0 {
|
if len(locator) > 0 {
|
||||||
beginHash = locator[0]
|
beginHash = locator[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter duplicate getblocks requests.
|
// Filter duplicate getblockinvs requests.
|
||||||
p.prevGetBlocksMtx.Lock()
|
p.prevGetBlockInvsMtx.Lock()
|
||||||
isDuplicate := p.prevGetBlocksStop != nil && p.prevGetBlocksBegin != nil &&
|
isDuplicate := p.prevGetBlockInvsStop != nil && p.prevGetBlockInvsBegin != nil &&
|
||||||
beginHash != nil && stopHash.IsEqual(p.prevGetBlocksStop) &&
|
beginHash != nil && stopHash.IsEqual(p.prevGetBlockInvsStop) &&
|
||||||
beginHash.IsEqual(p.prevGetBlocksBegin)
|
beginHash.IsEqual(p.prevGetBlockInvsBegin)
|
||||||
p.prevGetBlocksMtx.Unlock()
|
p.prevGetBlockInvsMtx.Unlock()
|
||||||
|
|
||||||
if isDuplicate {
|
if isDuplicate {
|
||||||
log.Tracef("Filtering duplicate [getblocks] with begin "+
|
log.Tracef("Filtering duplicate [getblockinvs] with begin "+
|
||||||
"hash %s, stop hash %s", beginHash, stopHash)
|
"hash %s, stop hash %s", beginHash, stopHash)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct the getblocks request and queue it to be sent.
|
// Construct the getblockinvs request and queue it to be sent.
|
||||||
msg := wire.NewMsgGetBlocks(stopHash)
|
msg := wire.NewMsgGetBlockInvs(stopHash)
|
||||||
for _, hash := range locator {
|
for _, hash := range locator {
|
||||||
err := msg.AddBlockLocatorHash(hash)
|
err := msg.AddBlockLocatorHash(hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -893,16 +893,16 @@ func (p *Peer) PushGetBlocksMsg(locator blockdag.BlockLocator, stopHash *daghash
|
|||||||
}
|
}
|
||||||
p.QueueMessage(msg, nil)
|
p.QueueMessage(msg, nil)
|
||||||
|
|
||||||
// Update the previous getblocks request information for filtering
|
// Update the previous getblockinvs request information for filtering
|
||||||
// duplicates.
|
// duplicates.
|
||||||
p.prevGetBlocksMtx.Lock()
|
p.prevGetBlockInvsMtx.Lock()
|
||||||
p.prevGetBlocksBegin = beginHash
|
p.prevGetBlockInvsBegin = beginHash
|
||||||
p.prevGetBlocksStop = stopHash
|
p.prevGetBlockInvsStop = stopHash
|
||||||
p.prevGetBlocksMtx.Unlock()
|
p.prevGetBlockInvsMtx.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PushGetHeadersMsg sends a getblocks message for the provided block locator
|
// PushGetHeadersMsg sends a getblockinvs message for the provided block locator
|
||||||
// and stop hash. It will ignore back-to-back duplicate requests.
|
// and stop hash. It will ignore back-to-back duplicate requests.
|
||||||
//
|
//
|
||||||
// This function is safe for concurrent access.
|
// This function is safe for concurrent access.
|
||||||
@ -1211,7 +1211,7 @@ func (p *Peer) maybeAddDeadline(pendingResponses map[string]time.Time, msgCmd st
|
|||||||
// Expects an inv message.
|
// Expects an inv message.
|
||||||
pendingResponses[wire.CmdInv] = deadline
|
pendingResponses[wire.CmdInv] = deadline
|
||||||
|
|
||||||
case wire.CmdGetBlocks:
|
case wire.CmdGetBlockInvs:
|
||||||
// Expects an inv message.
|
// Expects an inv message.
|
||||||
pendingResponses[wire.CmdInv] = deadline
|
pendingResponses[wire.CmdInv] = deadline
|
||||||
|
|
||||||
@ -1517,9 +1517,9 @@ out:
|
|||||||
p.cfg.Listeners.OnGetData(p, msg)
|
p.cfg.Listeners.OnGetData(p, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
case *wire.MsgGetBlocks:
|
case *wire.MsgGetBlockInvs:
|
||||||
if p.cfg.Listeners.OnGetBlocks != nil {
|
if p.cfg.Listeners.OnGetBlockInvs != nil {
|
||||||
p.cfg.Listeners.OnGetBlocks(p, msg)
|
p.cfg.Listeners.OnGetBlockInvs(p, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
case *wire.MsgGetHeaders:
|
case *wire.MsgGetHeaders:
|
||||||
|
@ -375,7 +375,7 @@ func TestPeerListeners(t *testing.T) {
|
|||||||
OnGetData: func(p *peer.Peer, msg *wire.MsgGetData) {
|
OnGetData: func(p *peer.Peer, msg *wire.MsgGetData) {
|
||||||
ok <- msg
|
ok <- msg
|
||||||
},
|
},
|
||||||
OnGetBlocks: func(p *peer.Peer, msg *wire.MsgGetBlocks) {
|
OnGetBlockInvs: func(p *peer.Peer, msg *wire.MsgGetBlockInvs) {
|
||||||
ok <- msg
|
ok <- msg
|
||||||
},
|
},
|
||||||
OnGetHeaders: func(p *peer.Peer, msg *wire.MsgGetHeaders) {
|
OnGetHeaders: func(p *peer.Peer, msg *wire.MsgGetHeaders) {
|
||||||
@ -513,8 +513,8 @@ func TestPeerListeners(t *testing.T) {
|
|||||||
wire.NewMsgGetData(),
|
wire.NewMsgGetData(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"OnGetBlocks",
|
"OnGetBlockInvs",
|
||||||
wire.NewMsgGetBlocks(&daghash.Hash{}),
|
wire.NewMsgGetBlockInvs(&daghash.Hash{}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"OnGetHeaders",
|
"OnGetHeaders",
|
||||||
@ -677,8 +677,8 @@ func TestOutboundPeer(t *testing.T) {
|
|||||||
t.Errorf("PushAddrMsg: unexpected err %v\n", err)
|
t.Errorf("PushAddrMsg: unexpected err %v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := p2.PushGetBlocksMsg(nil, &daghash.Hash{}); err != nil {
|
if err := p2.PushGetBlockInvsMsg(nil, &daghash.Hash{}); err != nil {
|
||||||
t.Errorf("PushGetBlocksMsg: unexpected err %v\n", err)
|
t.Errorf("PushGetBlockInvsMsg: unexpected err %v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := p2.PushGetHeadersMsg(nil, &daghash.Hash{}); err != nil {
|
if err := p2.PushGetHeadersMsg(nil, &daghash.Hash{}); err != nil {
|
||||||
|
@ -682,9 +682,9 @@ func (sp *Peer) OnGetData(_ *peer.Peer, msg *wire.MsgGetData) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnGetBlocks is invoked when a peer receives a getblocks bitcoin
|
// OnGetBlockInvs is invoked when a peer receives a getblockinvs bitcoin
|
||||||
// message.
|
// message.
|
||||||
func (sp *Peer) OnGetBlocks(_ *peer.Peer, msg *wire.MsgGetBlocks) {
|
func (sp *Peer) OnGetBlockInvs(_ *peer.Peer, msg *wire.MsgGetBlockInvs) {
|
||||||
// Find the most recent known block in the dag based on the block
|
// Find the most recent known block in the dag based on the block
|
||||||
// locator and fetch all of the block hashes after it until either
|
// locator and fetch all of the block hashes after it until either
|
||||||
// wire.MaxBlocksPerMsg have been fetched or the provided stop hash is
|
// wire.MaxBlocksPerMsg have been fetched or the provided stop hash is
|
||||||
@ -1778,7 +1778,7 @@ func newPeerConfig(sp *Peer) *peer.Config {
|
|||||||
OnInv: sp.OnInv,
|
OnInv: sp.OnInv,
|
||||||
OnHeaders: sp.OnHeaders,
|
OnHeaders: sp.OnHeaders,
|
||||||
OnGetData: sp.OnGetData,
|
OnGetData: sp.OnGetData,
|
||||||
OnGetBlocks: sp.OnGetBlocks,
|
OnGetBlockInvs: sp.OnGetBlockInvs,
|
||||||
OnGetHeaders: sp.OnGetHeaders,
|
OnGetHeaders: sp.OnGetHeaders,
|
||||||
OnGetCFilters: sp.OnGetCFilters,
|
OnGetCFilters: sp.OnGetCFilters,
|
||||||
OnGetCFHeaders: sp.OnGetCFHeaders,
|
OnGetCFHeaders: sp.OnGetCFHeaders,
|
||||||
|
@ -445,12 +445,12 @@ func BenchmarkDecodeHeaders(b *testing.B) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// BenchmarkDecodeGetBlocks performs a benchmark on how long it takes to
|
// BenchmarkDecodeGetBlockInvs performs a benchmark on how long it takes to
|
||||||
// decode a getblocks message with the maximum number of block locator hashes.
|
// decode a getblockinvs message with the maximum number of block locator hashes.
|
||||||
func BenchmarkDecodeGetBlocks(b *testing.B) {
|
func BenchmarkDecodeGetBlockInvs(b *testing.B) {
|
||||||
// Create a message with the maximum number of block locators.
|
// Create a message with the maximum number of block locators.
|
||||||
pver := ProtocolVersion
|
pver := ProtocolVersion
|
||||||
var m MsgGetBlocks
|
var m MsgGetBlockInvs
|
||||||
for i := 0; i < MaxBlockLocatorsPerMsg; i++ {
|
for i := 0; i < MaxBlockLocatorsPerMsg; i++ {
|
||||||
hash, err := daghash.NewHashFromStr(fmt.Sprintf("%x", i))
|
hash, err := daghash.NewHashFromStr(fmt.Sprintf("%x", i))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -462,12 +462,12 @@ func BenchmarkDecodeGetBlocks(b *testing.B) {
|
|||||||
// Serialize it so the bytes are available to test the decode below.
|
// Serialize it so the bytes are available to test the decode below.
|
||||||
var bb bytes.Buffer
|
var bb bytes.Buffer
|
||||||
if err := m.BtcEncode(&bb, pver); err != nil {
|
if err := m.BtcEncode(&bb, pver); err != nil {
|
||||||
b.Fatalf("MsgGetBlocks.BtcEncode: unexpected error: %v", err)
|
b.Fatalf("MsgGetBlockInvs.BtcEncode: unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
buf := bb.Bytes()
|
buf := bb.Bytes()
|
||||||
|
|
||||||
r := bytes.NewReader(buf)
|
r := bytes.NewReader(buf)
|
||||||
var msg MsgGetBlocks
|
var msg MsgGetBlockInvs
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
r.Seek(0, 0)
|
r.Seek(0, 0)
|
||||||
|
20
wire/doc.go
20
wire/doc.go
@ -45,17 +45,17 @@ things such as protocol version and supported services with each other. Once
|
|||||||
the initial handshake is complete, the following chart indicates message
|
the initial handshake is complete, the following chart indicates message
|
||||||
interactions in no particular order.
|
interactions in no particular order.
|
||||||
|
|
||||||
Peer A Sends Peer B Responds
|
Peer A Sends Peer B Responds
|
||||||
----------------------------------------------------------------------------
|
----------------------------------------------------------------------------
|
||||||
getaddr message (MsgGetAddr) addr message (MsgAddr)
|
getaddr message (MsgGetAddr) addr message (MsgAddr)
|
||||||
getblocks message (MsgGetBlocks) inv message (MsgInv)
|
getblockinvs message (MsgGetBlockInvs) inv message (MsgInv)
|
||||||
inv message (MsgInv) getdata message (MsgGetData)
|
inv message (MsgInv) getdata message (MsgGetData)
|
||||||
getdata message (MsgGetData) block message (MsgBlock) -or-
|
getdata message (MsgGetData) block message (MsgBlock) -or-
|
||||||
tx message (MsgTx) -or-
|
tx message (MsgTx) -or-
|
||||||
notfound message (MsgNotFound)
|
notfound message (MsgNotFound)
|
||||||
getheaders message (MsgGetHeaders) headers message (MsgHeaders)
|
getheaders message (MsgGetHeaders) headers message (MsgHeaders)
|
||||||
ping message (MsgPing) pong message (MsgHeaders)* -or-
|
ping message (MsgPing) pong message (MsgHeaders)* -or-
|
||||||
(none -- Ability to send message is enough)
|
(none -- Ability to send message is enough)
|
||||||
|
|
||||||
NOTES:
|
NOTES:
|
||||||
* The pong message was not added until later protocol versions as defined
|
* The pong message was not added until later protocol versions as defined
|
||||||
|
@ -32,7 +32,7 @@ const (
|
|||||||
CmdVerAck = "verack"
|
CmdVerAck = "verack"
|
||||||
CmdGetAddr = "getaddr"
|
CmdGetAddr = "getaddr"
|
||||||
CmdAddr = "addr"
|
CmdAddr = "addr"
|
||||||
CmdGetBlocks = "getblocks"
|
CmdGetBlockInvs = "getblockinvs"
|
||||||
CmdInv = "inv"
|
CmdInv = "inv"
|
||||||
CmdGetData = "getdata"
|
CmdGetData = "getdata"
|
||||||
CmdNotFound = "notfound"
|
CmdNotFound = "notfound"
|
||||||
@ -87,8 +87,8 @@ func makeEmptyMessage(command string) (Message, error) {
|
|||||||
case CmdAddr:
|
case CmdAddr:
|
||||||
msg = &MsgAddr{}
|
msg = &MsgAddr{}
|
||||||
|
|
||||||
case CmdGetBlocks:
|
case CmdGetBlockInvs:
|
||||||
msg = &MsgGetBlocks{}
|
msg = &MsgGetBlockInvs{}
|
||||||
|
|
||||||
case CmdBlock:
|
case CmdBlock:
|
||||||
msg = &MsgBlock{}
|
msg = &MsgBlock{}
|
||||||
|
@ -51,7 +51,7 @@ func TestMessage(t *testing.T) {
|
|||||||
msgVerack := NewMsgVerAck()
|
msgVerack := NewMsgVerAck()
|
||||||
msgGetAddr := NewMsgGetAddr(false, nil)
|
msgGetAddr := NewMsgGetAddr(false, nil)
|
||||||
msgAddr := NewMsgAddr(false, nil)
|
msgAddr := NewMsgAddr(false, nil)
|
||||||
msgGetBlocks := NewMsgGetBlocks(&daghash.Hash{})
|
msgGetBlockInvs := NewMsgGetBlockInvs(&daghash.Hash{})
|
||||||
msgBlock := &blockOne
|
msgBlock := &blockOne
|
||||||
msgInv := NewMsgInv()
|
msgInv := NewMsgInv()
|
||||||
msgGetData := NewMsgGetData()
|
msgGetData := NewMsgGetData()
|
||||||
@ -90,7 +90,7 @@ func TestMessage(t *testing.T) {
|
|||||||
{msgVerack, msgVerack, pver, MainNet, 24},
|
{msgVerack, msgVerack, pver, MainNet, 24},
|
||||||
{msgGetAddr, msgGetAddr, pver, MainNet, 26},
|
{msgGetAddr, msgGetAddr, pver, MainNet, 26},
|
||||||
{msgAddr, msgAddr, pver, MainNet, 27},
|
{msgAddr, msgAddr, pver, MainNet, 27},
|
||||||
{msgGetBlocks, msgGetBlocks, pver, MainNet, 61},
|
{msgGetBlockInvs, msgGetBlockInvs, pver, MainNet, 61},
|
||||||
{msgBlock, msgBlock, pver, MainNet, 372},
|
{msgBlock, msgBlock, pver, MainNet, 372},
|
||||||
{msgInv, msgInv, pver, MainNet, 25},
|
{msgInv, msgInv, pver, MainNet, 25},
|
||||||
{msgGetData, msgGetData, pver, MainNet, 25},
|
{msgGetData, msgGetData, pver, MainNet, 25},
|
||||||
|
@ -15,11 +15,11 @@ import (
|
|||||||
// per message.
|
// per message.
|
||||||
const MaxBlockLocatorsPerMsg = 500
|
const MaxBlockLocatorsPerMsg = 500
|
||||||
|
|
||||||
// MsgGetBlocks implements the Message interface and represents a bitcoin
|
// MsgGetBlockInvs implements the Message interface and represents a bitcoin
|
||||||
// getblocks message. It is used to request a list of blocks starting after the
|
// getblockinvss message. It is used to request a list of blocks starting after
|
||||||
// last known hash in the slice of block locator hashes. The list is returned
|
// the last known hash in the slice of block locator hashes. The list is
|
||||||
// via an inv message (MsgInv) and is limited by a specific hash to stop at or
|
// returned via an inv message (MsgInv) and is limited by a specific hash to
|
||||||
// the maximum number of blocks per message, which is currently 500.
|
// stop at or the maximum number of blocks per message, which is currently 500.
|
||||||
//
|
//
|
||||||
// Set the StopHash field to the hash at which to stop and use
|
// Set the StopHash field to the hash at which to stop and use
|
||||||
// AddBlockLocatorHash to build up the list of block locator hashes.
|
// AddBlockLocatorHash to build up the list of block locator hashes.
|
||||||
@ -30,18 +30,18 @@ const MaxBlockLocatorsPerMsg = 500
|
|||||||
// most recent 10 block hashes, then double the step each loop iteration to
|
// most recent 10 block hashes, then double the step each loop iteration to
|
||||||
// exponentially decrease the number of hashes the further away from head and
|
// exponentially decrease the number of hashes the further away from head and
|
||||||
// closer to the genesis block you get.
|
// closer to the genesis block you get.
|
||||||
type MsgGetBlocks struct {
|
type MsgGetBlockInvs struct {
|
||||||
ProtocolVersion uint32
|
ProtocolVersion uint32
|
||||||
BlockLocatorHashes []*daghash.Hash
|
BlockLocatorHashes []*daghash.Hash
|
||||||
StopHash *daghash.Hash
|
StopHash *daghash.Hash
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddBlockLocatorHash adds a new block locator hash to the message.
|
// AddBlockLocatorHash adds a new block locator hash to the message.
|
||||||
func (msg *MsgGetBlocks) AddBlockLocatorHash(hash *daghash.Hash) error {
|
func (msg *MsgGetBlockInvs) AddBlockLocatorHash(hash *daghash.Hash) error {
|
||||||
if len(msg.BlockLocatorHashes)+1 > MaxBlockLocatorsPerMsg {
|
if len(msg.BlockLocatorHashes)+1 > MaxBlockLocatorsPerMsg {
|
||||||
str := fmt.Sprintf("too many block locator hashes for message [max %d]",
|
str := fmt.Sprintf("too many block locator hashes for message [max %d]",
|
||||||
MaxBlockLocatorsPerMsg)
|
MaxBlockLocatorsPerMsg)
|
||||||
return messageError("MsgGetBlocks.AddBlockLocatorHash", str)
|
return messageError("MsgGetBlockInvs.AddBlockLocatorHash", str)
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.BlockLocatorHashes = append(msg.BlockLocatorHashes, hash)
|
msg.BlockLocatorHashes = append(msg.BlockLocatorHashes, hash)
|
||||||
@ -50,7 +50,7 @@ func (msg *MsgGetBlocks) AddBlockLocatorHash(hash *daghash.Hash) error {
|
|||||||
|
|
||||||
// BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
|
// BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
|
||||||
// This is part of the Message interface implementation.
|
// This is part of the Message interface implementation.
|
||||||
func (msg *MsgGetBlocks) BtcDecode(r io.Reader, pver uint32) error {
|
func (msg *MsgGetBlockInvs) BtcDecode(r io.Reader, pver uint32) error {
|
||||||
err := ReadElement(r, &msg.ProtocolVersion)
|
err := ReadElement(r, &msg.ProtocolVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -64,7 +64,7 @@ func (msg *MsgGetBlocks) BtcDecode(r io.Reader, pver uint32) error {
|
|||||||
if count > MaxBlockLocatorsPerMsg {
|
if count > MaxBlockLocatorsPerMsg {
|
||||||
str := fmt.Sprintf("too many block locator hashes for message "+
|
str := fmt.Sprintf("too many block locator hashes for message "+
|
||||||
"[count %d, max %d]", count, MaxBlockLocatorsPerMsg)
|
"[count %d, max %d]", count, MaxBlockLocatorsPerMsg)
|
||||||
return messageError("MsgGetBlocks.BtcDecode", str)
|
return messageError("MsgGetBlockInvs.BtcDecode", str)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a contiguous slice of hashes to deserialize into in order to
|
// Create a contiguous slice of hashes to deserialize into in order to
|
||||||
@ -86,12 +86,12 @@ func (msg *MsgGetBlocks) BtcDecode(r io.Reader, pver uint32) error {
|
|||||||
|
|
||||||
// BtcEncode encodes the receiver to w using the bitcoin protocol encoding.
|
// BtcEncode encodes the receiver to w using the bitcoin protocol encoding.
|
||||||
// This is part of the Message interface implementation.
|
// This is part of the Message interface implementation.
|
||||||
func (msg *MsgGetBlocks) BtcEncode(w io.Writer, pver uint32) error {
|
func (msg *MsgGetBlockInvs) BtcEncode(w io.Writer, pver uint32) error {
|
||||||
count := len(msg.BlockLocatorHashes)
|
count := len(msg.BlockLocatorHashes)
|
||||||
if count > MaxBlockLocatorsPerMsg {
|
if count > MaxBlockLocatorsPerMsg {
|
||||||
str := fmt.Sprintf("too many block locator hashes for message "+
|
str := fmt.Sprintf("too many block locator hashes for message "+
|
||||||
"[count %d, max %d]", count, MaxBlockLocatorsPerMsg)
|
"[count %d, max %d]", count, MaxBlockLocatorsPerMsg)
|
||||||
return messageError("MsgGetBlocks.BtcEncode", str)
|
return messageError("MsgGetBlockInvs.BtcEncode", str)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := WriteElement(w, msg.ProtocolVersion)
|
err := WriteElement(w, msg.ProtocolVersion)
|
||||||
@ -116,23 +116,23 @@ func (msg *MsgGetBlocks) BtcEncode(w io.Writer, pver uint32) error {
|
|||||||
|
|
||||||
// Command returns the protocol command string for the message. This is part
|
// Command returns the protocol command string for the message. This is part
|
||||||
// of the Message interface implementation.
|
// of the Message interface implementation.
|
||||||
func (msg *MsgGetBlocks) Command() string {
|
func (msg *MsgGetBlockInvs) Command() string {
|
||||||
return CmdGetBlocks
|
return CmdGetBlockInvs
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaxPayloadLength returns the maximum length the payload can be for the
|
// MaxPayloadLength returns the maximum length the payload can be for the
|
||||||
// receiver. This is part of the Message interface implementation.
|
// receiver. This is part of the Message interface implementation.
|
||||||
func (msg *MsgGetBlocks) MaxPayloadLength(pver uint32) uint32 {
|
func (msg *MsgGetBlockInvs) MaxPayloadLength(pver uint32) uint32 {
|
||||||
// Protocol version 4 bytes + num hashes (varInt) + max block locator
|
// Protocol version 4 bytes + num hashes (varInt) + max block locator
|
||||||
// hashes + hash stop.
|
// hashes + hash stop.
|
||||||
return 4 + MaxVarIntPayload + (MaxBlockLocatorsPerMsg * daghash.HashSize) + daghash.HashSize
|
return 4 + MaxVarIntPayload + (MaxBlockLocatorsPerMsg * daghash.HashSize) + daghash.HashSize
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMsgGetBlocks returns a new bitcoin getblocks message that conforms to the
|
// NewMsgGetBlockInvs returns a new bitcoin getblockinvs message that conforms
|
||||||
// Message interface using the passed parameters and defaults for the remaining
|
// to the Message interface using the passed parameters and defaults for the
|
||||||
// fields.
|
// remaining fields.
|
||||||
func NewMsgGetBlocks(stopHash *daghash.Hash) *MsgGetBlocks {
|
func NewMsgGetBlockInvs(stopHash *daghash.Hash) *MsgGetBlockInvs {
|
||||||
return &MsgGetBlocks{
|
return &MsgGetBlockInvs{
|
||||||
ProtocolVersion: ProtocolVersion,
|
ProtocolVersion: ProtocolVersion,
|
||||||
BlockLocatorHashes: make([]*daghash.Hash, 0, MaxBlockLocatorsPerMsg),
|
BlockLocatorHashes: make([]*daghash.Hash, 0, MaxBlockLocatorsPerMsg),
|
||||||
StopHash: stopHash,
|
StopHash: stopHash,
|
||||||
|
@ -14,8 +14,8 @@ import (
|
|||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestGetBlocks tests the MsgGetBlocks API.
|
// TestGetBlockInvs tests the MsgGetBlockInvs API.
|
||||||
func TestGetBlocks(t *testing.T) {
|
func TestGetBlockInvs(t *testing.T) {
|
||||||
pver := ProtocolVersion
|
pver := ProtocolVersion
|
||||||
|
|
||||||
// Block 99500 hash.
|
// Block 99500 hash.
|
||||||
@ -33,16 +33,16 @@ func TestGetBlocks(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure we get the same data back out.
|
// Ensure we get the same data back out.
|
||||||
msg := NewMsgGetBlocks(stopHash)
|
msg := NewMsgGetBlockInvs(stopHash)
|
||||||
if !msg.StopHash.IsEqual(stopHash) {
|
if !msg.StopHash.IsEqual(stopHash) {
|
||||||
t.Errorf("NewMsgGetBlocks: wrong stop hash - got %v, want %v",
|
t.Errorf("NewMsgGetBlockInvs: wrong stop hash - got %v, want %v",
|
||||||
msg.StopHash, stopHash)
|
msg.StopHash, stopHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the command is expected value.
|
// Ensure the command is expected value.
|
||||||
wantCmd := "getblocks"
|
wantCmd := "getblockinvs"
|
||||||
if cmd := msg.Command(); cmd != wantCmd {
|
if cmd := msg.Command(); cmd != wantCmd {
|
||||||
t.Errorf("NewMsgGetBlocks: wrong command - got %v want %v",
|
t.Errorf("NewMsgGetBlockInvs: wrong command - got %v want %v",
|
||||||
cmd, wantCmd)
|
cmd, wantCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,10 +80,10 @@ func TestGetBlocks(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestGetBlocksWire tests the MsgGetBlocks wire encode and decode for various
|
// TestGetBlockInvsWire tests the MsgGetBlockInvs wire encode and decode for various
|
||||||
// numbers of block locator hashes and protocol versions.
|
// numbers of block locator hashes and protocol versions.
|
||||||
func TestGetBlocksWire(t *testing.T) {
|
func TestGetBlockInvsWire(t *testing.T) {
|
||||||
// Set protocol inside getblocks message.
|
// Set protocol inside getblockinvs message.
|
||||||
pver := uint32(1)
|
pver := uint32(1)
|
||||||
|
|
||||||
// Block 99499 hash.
|
// Block 99499 hash.
|
||||||
@ -107,8 +107,8 @@ func TestGetBlocksWire(t *testing.T) {
|
|||||||
t.Errorf("NewHashFromStr: %v", err)
|
t.Errorf("NewHashFromStr: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MsgGetBlocks message with no block locators or stop hash.
|
// MsgGetBlockInvs message with no block locators or stop hash.
|
||||||
noLocators := NewMsgGetBlocks(&daghash.Hash{})
|
noLocators := NewMsgGetBlockInvs(&daghash.Hash{})
|
||||||
noLocators.ProtocolVersion = pver
|
noLocators.ProtocolVersion = pver
|
||||||
noLocatorsEncoded := []byte{
|
noLocatorsEncoded := []byte{
|
||||||
0x01, 0x00, 0x00, 0x00, // Protocol version 1
|
0x01, 0x00, 0x00, 0x00, // Protocol version 1
|
||||||
@ -119,8 +119,8 @@ func TestGetBlocksWire(t *testing.T) {
|
|||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Hash stop
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Hash stop
|
||||||
}
|
}
|
||||||
|
|
||||||
// MsgGetBlocks message with multiple block locators and a stop hash.
|
// MsgGetBlockInvs message with multiple block locators and a stop hash.
|
||||||
multiLocators := NewMsgGetBlocks(stopHash)
|
multiLocators := NewMsgGetBlockInvs(stopHash)
|
||||||
multiLocators.AddBlockLocatorHash(hashLocator2)
|
multiLocators.AddBlockLocatorHash(hashLocator2)
|
||||||
multiLocators.AddBlockLocatorHash(hashLocator)
|
multiLocators.AddBlockLocatorHash(hashLocator)
|
||||||
multiLocators.ProtocolVersion = pver
|
multiLocators.ProtocolVersion = pver
|
||||||
@ -142,10 +142,10 @@ func TestGetBlocksWire(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
in *MsgGetBlocks // Message to encode
|
in *MsgGetBlockInvs // Message to encode
|
||||||
out *MsgGetBlocks // Expected decoded message
|
out *MsgGetBlockInvs // Expected decoded message
|
||||||
buf []byte // Wire encoding
|
buf []byte // Wire encoding
|
||||||
pver uint32 // Protocol version for wire encoding
|
pver uint32 // Protocol version for wire encoding
|
||||||
}{
|
}{
|
||||||
// Latest protocol version with no block locators.
|
// Latest protocol version with no block locators.
|
||||||
{
|
{
|
||||||
@ -180,7 +180,7 @@ func TestGetBlocksWire(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Decode the message from wire format.
|
// Decode the message from wire format.
|
||||||
var msg MsgGetBlocks
|
var msg MsgGetBlockInvs
|
||||||
rbuf := bytes.NewReader(test.buf)
|
rbuf := bytes.NewReader(test.buf)
|
||||||
err = msg.BtcDecode(rbuf, test.pver)
|
err = msg.BtcDecode(rbuf, test.pver)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -195,9 +195,9 @@ func TestGetBlocksWire(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestGetBlocksWireErrors performs negative tests against wire encode and
|
// TestGetBlockInvsWireErrors performs negative tests against wire encode and
|
||||||
// decode of MsgGetBlocks to confirm error paths work correctly.
|
// decode of MsgGetBlockInvs to confirm error paths work correctly.
|
||||||
func TestGetBlocksWireErrors(t *testing.T) {
|
func TestGetBlockInvsWireErrors(t *testing.T) {
|
||||||
// Set protocol inside getheaders message. Use protocol version 1
|
// Set protocol inside getheaders message. Use protocol version 1
|
||||||
// specifically here instead of the latest because the test data is
|
// specifically here instead of the latest because the test data is
|
||||||
// using bytes encoded with that protocol version.
|
// using bytes encoded with that protocol version.
|
||||||
@ -225,12 +225,12 @@ func TestGetBlocksWireErrors(t *testing.T) {
|
|||||||
t.Errorf("NewHashFromStr: %v", err)
|
t.Errorf("NewHashFromStr: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MsgGetBlocks message with multiple block locators and a stop hash.
|
// MsgGetBlockInvs message with multiple block locators and a stop hash.
|
||||||
baseGetBlocks := NewMsgGetBlocks(stopHash)
|
baseGetBlockInvs := NewMsgGetBlockInvs(stopHash)
|
||||||
baseGetBlocks.ProtocolVersion = pver
|
baseGetBlockInvs.ProtocolVersion = pver
|
||||||
baseGetBlocks.AddBlockLocatorHash(hashLocator2)
|
baseGetBlockInvs.AddBlockLocatorHash(hashLocator2)
|
||||||
baseGetBlocks.AddBlockLocatorHash(hashLocator)
|
baseGetBlockInvs.AddBlockLocatorHash(hashLocator)
|
||||||
baseGetBlocksEncoded := []byte{
|
baseGetBlockInvsEncoded := []byte{
|
||||||
0x01, 0x00, 0x00, 0x00, // Protocol version 1
|
0x01, 0x00, 0x00, 0x00, // Protocol version 1
|
||||||
0x02, // Varint for number of block locator hashes
|
0x02, // Varint for number of block locator hashes
|
||||||
0xe0, 0xde, 0x06, 0x44, 0x68, 0x13, 0x2c, 0x63,
|
0xe0, 0xde, 0x06, 0x44, 0x68, 0x13, 0x2c, 0x63,
|
||||||
@ -249,35 +249,35 @@ func TestGetBlocksWireErrors(t *testing.T) {
|
|||||||
|
|
||||||
// Message that forces an error by having more than the max allowed
|
// Message that forces an error by having more than the max allowed
|
||||||
// block locator hashes.
|
// block locator hashes.
|
||||||
maxGetBlocks := NewMsgGetBlocks(stopHash)
|
maxGetBlockInvs := NewMsgGetBlockInvs(stopHash)
|
||||||
for i := 0; i < MaxBlockLocatorsPerMsg; i++ {
|
for i := 0; i < MaxBlockLocatorsPerMsg; i++ {
|
||||||
maxGetBlocks.AddBlockLocatorHash(mainNetGenesisHash)
|
maxGetBlockInvs.AddBlockLocatorHash(mainNetGenesisHash)
|
||||||
}
|
}
|
||||||
maxGetBlocks.BlockLocatorHashes = append(maxGetBlocks.BlockLocatorHashes,
|
maxGetBlockInvs.BlockLocatorHashes = append(maxGetBlockInvs.BlockLocatorHashes,
|
||||||
mainNetGenesisHash)
|
mainNetGenesisHash)
|
||||||
maxGetBlocksEncoded := []byte{
|
maxGetBlockInvsEncoded := []byte{
|
||||||
0x01, 0x00, 0x00, 0x00, // Protocol version 1
|
0x01, 0x00, 0x00, 0x00, // Protocol version 1
|
||||||
0xfd, 0xf5, 0x01, // Varint for number of block loc hashes (501)
|
0xfd, 0xf5, 0x01, // Varint for number of block loc hashes (501)
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
in *MsgGetBlocks // Value to encode
|
in *MsgGetBlockInvs // Value to encode
|
||||||
buf []byte // Wire encoding
|
buf []byte // Wire encoding
|
||||||
pver uint32 // Protocol version for wire encoding
|
pver uint32 // Protocol version for wire encoding
|
||||||
max int // Max size of fixed buffer to induce errors
|
max int // Max size of fixed buffer to induce errors
|
||||||
writeErr error // Expected write error
|
writeErr error // Expected write error
|
||||||
readErr error // Expected read error
|
readErr error // Expected read error
|
||||||
}{
|
}{
|
||||||
// Force error in protocol version.
|
// Force error in protocol version.
|
||||||
{baseGetBlocks, baseGetBlocksEncoded, pver, 0, io.ErrShortWrite, io.EOF},
|
{baseGetBlockInvs, baseGetBlockInvsEncoded, pver, 0, io.ErrShortWrite, io.EOF},
|
||||||
// Force error in block locator hash count.
|
// Force error in block locator hash count.
|
||||||
{baseGetBlocks, baseGetBlocksEncoded, pver, 4, io.ErrShortWrite, io.EOF},
|
{baseGetBlockInvs, baseGetBlockInvsEncoded, pver, 4, io.ErrShortWrite, io.EOF},
|
||||||
// Force error in block locator hashes.
|
// Force error in block locator hashes.
|
||||||
{baseGetBlocks, baseGetBlocksEncoded, pver, 5, io.ErrShortWrite, io.EOF},
|
{baseGetBlockInvs, baseGetBlockInvsEncoded, pver, 5, io.ErrShortWrite, io.EOF},
|
||||||
// Force error in stop hash.
|
// Force error in stop hash.
|
||||||
{baseGetBlocks, baseGetBlocksEncoded, pver, 69, io.ErrShortWrite, io.EOF},
|
{baseGetBlockInvs, baseGetBlockInvsEncoded, pver, 69, io.ErrShortWrite, io.EOF},
|
||||||
// Force error with greater than max block locator hashes.
|
// Force error with greater than max block locator hashes.
|
||||||
{maxGetBlocks, maxGetBlocksEncoded, pver, 7, wireErr, wireErr},
|
{maxGetBlockInvs, maxGetBlockInvsEncoded, pver, 7, wireErr, wireErr},
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("Running %d tests", len(tests))
|
t.Logf("Running %d tests", len(tests))
|
||||||
@ -302,7 +302,7 @@ func TestGetBlocksWireErrors(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Decode from wire format.
|
// Decode from wire format.
|
||||||
var msg MsgGetBlocks
|
var msg MsgGetBlockInvs
|
||||||
r := newFixedReader(test.max, test.buf)
|
r := newFixedReader(test.max, test.buf)
|
||||||
err = msg.BtcDecode(r, test.pver)
|
err = msg.BtcDecode(r, test.pver)
|
||||||
if reflect.TypeOf(err) != reflect.TypeOf(test.readErr) {
|
if reflect.TypeOf(err) != reflect.TypeOf(test.readErr) {
|
||||||
|
@ -21,7 +21,7 @@ const defaultInvListAlloc = 1000
|
|||||||
// MsgInv implements the Message interface and represents a bitcoin inv message.
|
// MsgInv implements the Message interface and represents a bitcoin inv message.
|
||||||
// It is used to advertise a peer's known data such as blocks and transactions
|
// It is used to advertise a peer's known data such as blocks and transactions
|
||||||
// through inventory vectors. It may be sent unsolicited to inform other peers
|
// through inventory vectors. It may be sent unsolicited to inform other peers
|
||||||
// of the data or in response to a getblocks message (MsgGetBlocks). Each
|
// of the data or in response to a getblockinvs message (MsgGetBlockInvs). Each
|
||||||
// message is limited to a maximum number of inventory vectors, which is
|
// message is limited to a maximum number of inventory vectors, which is
|
||||||
// currently 50,000.
|
// currently 50,000.
|
||||||
//
|
//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user