mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[NOD-245] Increase MaxInvPerMsg and MaxBlocksPerMsg to 65536 (#343)
* [NOD-245] Increase MaxInvPerMsg and MaxBlocksPerMsg to 65536 * [NOD-245] Fix MaxInvPerMsg to 1 << 16
This commit is contained in:
parent
8ccc63752c
commit
4c6b8969d3
@ -697,7 +697,7 @@ func (sp *Peer) OnGetBlocks(_ *peer.Peer, msg *wire.MsgGetBlocks) {
|
||||
// This mirrors the behavior in the reference implementation.
|
||||
dag := sp.server.DAG
|
||||
hashList := dag.LocateBlocks(msg.BlockLocatorHashes, msg.HashStop,
|
||||
wire.MaxBlocksPerMsg)
|
||||
wire.MaxInvPerMsg)
|
||||
|
||||
// Generate inventory message.
|
||||
invMsg := wire.NewMsgInv()
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
const (
|
||||
// MaxInvPerMsg is the maximum number of inventory vectors that can be in a
|
||||
// single bitcoin inv message.
|
||||
MaxInvPerMsg = 50000
|
||||
MaxInvPerMsg = 1 << 16
|
||||
|
||||
// Maximum payload size for an inventory vector.
|
||||
maxInvVectPayload = 4 + daghash.HashSize
|
||||
|
@ -21,9 +21,6 @@ import (
|
||||
// backing array multiple times.
|
||||
const defaultTransactionAlloc = 2048
|
||||
|
||||
// MaxBlocksPerMsg is the maximum number of blocks allowed per message.
|
||||
const MaxBlocksPerMsg = 500
|
||||
|
||||
// MaxBlockPayload is the maximum bytes a block message can be in bytes.
|
||||
const MaxBlockPayload = 1000000
|
||||
|
||||
|
@ -28,7 +28,7 @@ func TestGetData(t *testing.T) {
|
||||
|
||||
// Ensure max payload is expected value for latest protocol version.
|
||||
// Num inventory vectors (varInt) + max allowed inventory vectors.
|
||||
wantPayload := uint32(1800009)
|
||||
wantPayload := uint32(2359305)
|
||||
maxPayload := msg.MaxPayloadLength(pver)
|
||||
if maxPayload != wantPayload {
|
||||
t.Errorf("MaxPayloadLength: wrong max payload length for "+
|
||||
@ -176,7 +176,7 @@ func TestGetDataWireErrors(t *testing.T) {
|
||||
hashStr := "3264bc2ac36a60840790ba1d475d01367e7c723da941069e9dc"
|
||||
blockHash, err := daghash.NewHashFromStr(hashStr)
|
||||
if err != nil {
|
||||
t.Errorf("NewHashFromStr: %v", err)
|
||||
t.Fatalf("NewHashFromStr: %v", err)
|
||||
}
|
||||
|
||||
iv := NewInvVect(InvTypeBlock, blockHash)
|
||||
@ -200,9 +200,13 @@ func TestGetDataWireErrors(t *testing.T) {
|
||||
maxGetData.AddInvVect(iv)
|
||||
}
|
||||
maxGetData.InvList = append(maxGetData.InvList, iv)
|
||||
maxGetDataEncoded := []byte{
|
||||
0xfd, 0x51, 0xc3, // Varint for number of inv vectors (50001)
|
||||
|
||||
w := &bytes.Buffer{}
|
||||
err = WriteVarInt(w, MaxInvPerMsg+1)
|
||||
if err != nil {
|
||||
t.Fatalf("WriteVarInt: %s", err)
|
||||
}
|
||||
maxGetDataEncoded := w.Bytes()
|
||||
|
||||
tests := []struct {
|
||||
in *MsgGetData // Value to encode
|
||||
@ -218,7 +222,7 @@ func TestGetDataWireErrors(t *testing.T) {
|
||||
// Force error in inventory list.
|
||||
{baseGetData, baseGetDataEncoded, pver, 1, io.ErrShortWrite, io.EOF},
|
||||
// Force error with greater than max inventory vectors.
|
||||
{maxGetData, maxGetDataEncoded, pver, 3, wireErr, wireErr},
|
||||
{maxGetData, maxGetDataEncoded, pver, 5, wireErr, wireErr},
|
||||
}
|
||||
|
||||
t.Logf("Running %d tests", len(tests))
|
||||
|
@ -28,7 +28,7 @@ func TestInv(t *testing.T) {
|
||||
|
||||
// Ensure max payload is expected value for latest protocol version.
|
||||
// Num inventory vectors (varInt) + max allowed inventory vectors.
|
||||
wantPayload := uint32(1800009)
|
||||
wantPayload := uint32(2359305)
|
||||
maxPayload := msg.MaxPayloadLength(pver)
|
||||
if maxPayload != wantPayload {
|
||||
t.Errorf("MaxPayloadLength: wrong max payload length for "+
|
||||
@ -200,9 +200,13 @@ func TestInvWireErrors(t *testing.T) {
|
||||
maxInv.AddInvVect(iv)
|
||||
}
|
||||
maxInv.InvList = append(maxInv.InvList, iv)
|
||||
maxInvEncoded := []byte{
|
||||
0xfd, 0x51, 0xc3, // Varint for number of inv vectors (50001)
|
||||
|
||||
w := &bytes.Buffer{}
|
||||
err = WriteVarInt(w, MaxInvPerMsg+1)
|
||||
if err != nil {
|
||||
t.Fatalf("WriteVarInt: %s", err)
|
||||
}
|
||||
maxInvEncoded := w.Bytes()
|
||||
|
||||
tests := []struct {
|
||||
in *MsgInv // Value to encode
|
||||
@ -218,7 +222,7 @@ func TestInvWireErrors(t *testing.T) {
|
||||
// Force error in inventory list.
|
||||
{baseInv, baseInvEncoded, pver, 1, io.ErrShortWrite, io.EOF},
|
||||
// Force error with greater than max inventory vectors.
|
||||
{maxInv, maxInvEncoded, pver, 3, wireErr, wireErr},
|
||||
{maxInv, maxInvEncoded, pver, 5, wireErr, wireErr},
|
||||
}
|
||||
|
||||
t.Logf("Running %d tests", len(tests))
|
||||
|
@ -28,7 +28,7 @@ func TestNotFound(t *testing.T) {
|
||||
|
||||
// Ensure max payload is expected value for latest protocol version.
|
||||
// Num inventory vectors (varInt) + max allowed inventory vectors.
|
||||
wantPayload := uint32(1800009)
|
||||
wantPayload := uint32(2359305)
|
||||
maxPayload := msg.MaxPayloadLength(pver)
|
||||
if maxPayload != wantPayload {
|
||||
t.Errorf("MaxPayloadLength: wrong max payload length for "+
|
||||
@ -191,9 +191,13 @@ func TestNotFoundWireErrors(t *testing.T) {
|
||||
maxNotFound.AddInvVect(iv)
|
||||
}
|
||||
maxNotFound.InvList = append(maxNotFound.InvList, iv)
|
||||
maxNotFoundEncoded := []byte{
|
||||
0xfd, 0x51, 0xc3, // Varint for number of inv vectors (50001)
|
||||
|
||||
w := &bytes.Buffer{}
|
||||
err = WriteVarInt(w, MaxInvPerMsg+1)
|
||||
if err != nil {
|
||||
t.Fatalf("WriteVarInt: %s", err)
|
||||
}
|
||||
maxNotFoundEncoded := w.Bytes()
|
||||
|
||||
tests := []struct {
|
||||
in *MsgNotFound // Value to encode
|
||||
@ -208,7 +212,7 @@ func TestNotFoundWireErrors(t *testing.T) {
|
||||
// Force error in inventory list.
|
||||
{baseNotFound, baseNotFoundEncoded, pver, 1, io.ErrShortWrite, io.EOF},
|
||||
// Force error with greater than max inventory vectors.
|
||||
{maxNotFound, maxNotFoundEncoded, pver, 3, wireErr, wireErr},
|
||||
{maxNotFound, maxNotFoundEncoded, pver, 5, wireErr, wireErr},
|
||||
}
|
||||
|
||||
t.Logf("Running %d tests", len(tests))
|
||||
|
Loading…
x
Reference in New Issue
Block a user