From 6ebcb6238d1f72127bc13b3982c87a1c240c14ae Mon Sep 17 00:00:00 2001 From: noot Date: Fri, 28 Jan 2022 14:26:46 -0500 Subject: [PATCH 1/2] remove max size from block request --- dot/sync/chain_sync.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/dot/sync/chain_sync.go b/dot/sync/chain_sync.go index 70cf52b0da..288acafebe 100644 --- a/dot/sync/chain_sync.go +++ b/dot/sync/chain_sync.go @@ -972,16 +972,8 @@ func workerToRequests(w *worker) ([]*network.BlockRequestMessage, error) { reqs := make([]*network.BlockRequestMessage, numRequests) for i := 0; i < numRequests; i++ { - // check if we want to specify a size - var max uint32 = maxResponseSize - if i == numRequests-1 { - size := numBlocks % maxResponseSize - if size == 0 { - size = maxResponseSize - } - max = uint32(size) - } - + max := uint32(maxResponseSize) + var start *variadic.Uint64OrHash if w.startHash.IsEmpty() { // worker startHash is unspecified if we are in bootstrap mode From 175e507781af163dafdadca688a4387f14403b91 Mon Sep 17 00:00:00 2001 From: noot Date: Fri, 28 Jan 2022 15:00:42 -0500 Subject: [PATCH 2/2] fix tests --- dot/sync/chain_sync.go | 11 ++++++++++- dot/sync/chain_sync_test.go | 11 +++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/dot/sync/chain_sync.go b/dot/sync/chain_sync.go index 288acafebe..fabaaec4cb 100644 --- a/dot/sync/chain_sync.go +++ b/dot/sync/chain_sync.go @@ -972,8 +972,17 @@ func workerToRequests(w *worker) ([]*network.BlockRequestMessage, error) { reqs := make([]*network.BlockRequestMessage, numRequests) for i := 0; i < numRequests; i++ { + // check if we want to specify a size max := uint32(maxResponseSize) - + + if w.direction == network.Descending && i == numRequests-1 { + size := numBlocks % maxResponseSize + if size == 0 { + size = maxResponseSize + } + max = uint32(size) + } + var start *variadic.Uint64OrHash if w.startHash.IsEmpty() { // worker startHash is unspecified if we are in bootstrap mode diff --git a/dot/sync/chain_sync_test.go b/dot/sync/chain_sync_test.go index 8b78ddf352..25ace5fbae 100644 --- a/dot/sync/chain_sync_test.go +++ b/dot/sync/chain_sync_test.go @@ -275,7 +275,6 @@ func TestWorkerToRequests(t *testing.T) { max128 = uint32(128) max9 = uint32(9) max64 = uint32(64) - max1 = uint32(1) ) testCases := []testCase{ @@ -333,7 +332,7 @@ func TestWorkerToRequests(t *testing.T) { StartingBlock: *variadic.MustNewUint64OrHash(1), EndBlockHash: nil, Direction: network.Ascending, - Max: &max9, + Max: &max128, }, }, }, @@ -374,7 +373,7 @@ func TestWorkerToRequests(t *testing.T) { StartingBlock: *variadic.MustNewUint64OrHash(1 + maxResponseSize), EndBlockHash: nil, Direction: network.Ascending, - Max: &max64, + Max: &max128, }, }, }, @@ -392,7 +391,7 @@ func TestWorkerToRequests(t *testing.T) { StartingBlock: *variadic.MustNewUint64OrHash(1), EndBlockHash: &(common.Hash{0xa}), Direction: network.Ascending, - Max: &max9, + Max: &max128, }, }, }, @@ -411,7 +410,7 @@ func TestWorkerToRequests(t *testing.T) { StartingBlock: *variadic.MustNewUint64OrHash(common.Hash{0xb}), EndBlockHash: &(common.Hash{0xc}), Direction: network.Ascending, - Max: &max9, + Max: &max128, }, }, }, @@ -427,7 +426,7 @@ func TestWorkerToRequests(t *testing.T) { RequestedData: bootstrapRequestData, StartingBlock: *variadic.MustNewUint64OrHash(10), Direction: network.Ascending, - Max: &max1, + Max: &max128, }, }, },