diff --git a/app/protocol/flows/ibd/handle_request_headers.go b/app/protocol/flows/ibd/handle_request_headers.go index 4ac94450e..d8b6d29e3 100644 --- a/app/protocol/flows/ibd/handle_request_headers.go +++ b/app/protocol/flows/ibd/handle_request_headers.go @@ -10,6 +10,7 @@ import ( ) const ibdBatchSize = router.DefaultMaxMessages +const maxHeaders = appmessage.MaxInvPerMsg // RequestIBDBlocksContext is the interface for the context needed for the HandleRequestHeaders flow. type RequestIBDBlocksContext interface { @@ -97,7 +98,7 @@ func (flow *handleRequestBlocksFlow) buildMsgBlockHeaders(lowHash *externalapi.D if err != nil { return nil, err } - const maxHeaders = appmessage.MaxInvPerMsg + if len(blockHashes) > maxHeaders { blockHashes = blockHashes[:maxHeaders] } diff --git a/app/protocol/flows/ibd/handle_request_headers_test.go b/app/protocol/flows/ibd/handle_request_headers_test.go new file mode 100644 index 000000000..63573cdc3 --- /dev/null +++ b/app/protocol/flows/ibd/handle_request_headers_test.go @@ -0,0 +1,15 @@ +package ibd + +import ( + "github.com/kaspanet/kaspad/domain/consensus/utils/testutils" + "github.com/kaspanet/kaspad/domain/dagconfig" + "testing" +) + +func TestMaxHeaders(t *testing.T) { + testutils.ForAllNets(t, false, func(t *testing.T, params *dagconfig.Params) { + if params.FinalityDepth() > maxHeaders { + t.Errorf("FinalityDepth() in %s should be lower or equal to appmessage.MaxInvPerMsg", params.Name) + } + }) +}