Refactor p2p requests: extract BeaconBlocksByRangeRequest and BeaconBlocksByRootRequest (#7718)

* extract SendBeaconBlocksByRangeRequest

* adds extra processing

* extract SendBeaconBlocksByRootRequest

* extract into rpc_send_request.go

* add tests

* more tests

* gazelle

* remove redundant import

* for consistency

* for consistency

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Victor Farazdagi
2020-11-04 23:09:19 +03:00
committed by GitHub
parent 3485f3b8b0
commit 7acd73e1fe
10 changed files with 543 additions and 95 deletions

View File

@@ -633,7 +633,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T)
validate: func(req *p2ppb.BeaconBlocksByRangeRequest, blocks []*eth.SignedBeaconBlock) {
assert.Equal(t, 0, len(blocks))
},
wantedErr: errInvalidFetchedData.Error(),
wantedErr: beaconsync.ErrInvalidFetchedData.Error(),
},
{
name: "not in a consecutive order",
@@ -657,7 +657,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T)
validate: func(req *p2ppb.BeaconBlocksByRangeRequest, blocks []*eth.SignedBeaconBlock) {
assert.Equal(t, 0, len(blocks))
},
wantedErr: errInvalidFetchedData.Error(),
wantedErr: beaconsync.ErrInvalidFetchedData.Error(),
},
{
name: "same slot number",
@@ -681,7 +681,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T)
validate: func(req *p2ppb.BeaconBlocksByRangeRequest, blocks []*eth.SignedBeaconBlock) {
assert.Equal(t, 0, len(blocks))
},
wantedErr: errInvalidFetchedData.Error(),
wantedErr: beaconsync.ErrInvalidFetchedData.Error(),
},
{
name: "slot is too low",
@@ -709,7 +709,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T)
}
}
},
wantedErr: errInvalidFetchedData.Error(),
wantedErr: beaconsync.ErrInvalidFetchedData.Error(),
validate: func(req *p2ppb.BeaconBlocksByRangeRequest, blocks []*eth.SignedBeaconBlock) {
assert.Equal(t, 0, len(blocks))
},
@@ -740,7 +740,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T)
}
}
},
wantedErr: errInvalidFetchedData.Error(),
wantedErr: beaconsync.ErrInvalidFetchedData.Error(),
validate: func(req *p2ppb.BeaconBlocksByRangeRequest, blocks []*eth.SignedBeaconBlock) {
assert.Equal(t, 0, len(blocks))
},
@@ -790,7 +790,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T)
validate: func(req *p2ppb.BeaconBlocksByRangeRequest, blocks []*eth.SignedBeaconBlock) {
assert.Equal(t, 0, len(blocks))
},
wantedErr: errInvalidFetchedData.Error(),
wantedErr: beaconsync.ErrInvalidFetchedData.Error(),
},
}