|
|
|
|
@@ -64,7 +64,7 @@ func TestRPCBeaconBlocksByRange_RPCHandlerReturnsBlocks(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
clock := startup.NewClock(time.Unix(0, 0), [32]byte{})
|
|
|
|
|
// Start service with 160 as allowed blocks capacity (and almost zero capacity recovery).
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, clock: clock, chain: &chainMock.ChainService{}}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, clock: clock, chain: &chainMock.ChainService{}}, availableBlocker: mockBlocker{avail: true}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
pcl := protocol.ID(p2p.RPCBlocksByRangeTopicV1)
|
|
|
|
|
topic := string(pcl)
|
|
|
|
|
r.rateLimiter.limiterMap[topic] = leakybucket.NewCollector(0.000001, int64(req.Count*10), time.Second, false)
|
|
|
|
|
@@ -127,7 +127,7 @@ func TestRPCBeaconBlocksByRange_ReturnCorrectNumberBack(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
clock := startup.NewClock(time.Unix(0, 0), [32]byte{})
|
|
|
|
|
// Start service with 160 as allowed blocks capacity (and almost zero capacity recovery).
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, chain: &chainMock.ChainService{}, clock: clock}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, chain: &chainMock.ChainService{}, clock: clock}, availableBlocker: mockBlocker{avail: true}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
pcl := protocol.ID(p2p.RPCBlocksByRangeTopicV1)
|
|
|
|
|
topic := string(pcl)
|
|
|
|
|
r.rateLimiter.limiterMap[topic] = leakybucket.NewCollector(0.000001, int64(req.Count*10), time.Second, false)
|
|
|
|
|
@@ -244,7 +244,8 @@ func TestRPCBeaconBlocksByRange_ReconstructsPayloads(t *testing.T) {
|
|
|
|
|
clock: clock,
|
|
|
|
|
executionPayloadReconstructor: mockEngine,
|
|
|
|
|
},
|
|
|
|
|
rateLimiter: newRateLimiter(p1),
|
|
|
|
|
rateLimiter: newRateLimiter(p1),
|
|
|
|
|
availableBlocker: mockBlocker{avail: true},
|
|
|
|
|
}
|
|
|
|
|
pcl := protocol.ID(p2p.RPCBlocksByRangeTopicV1)
|
|
|
|
|
topic := string(pcl)
|
|
|
|
|
@@ -314,7 +315,7 @@ func TestRPCBeaconBlocksByRange_RPCHandlerReturnsSortedBlocks(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
clock := startup.NewClock(time.Unix(0, 0), [32]byte{})
|
|
|
|
|
// Start service with 160 as allowed blocks capacity (and almost zero capacity recovery).
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, clock: clock, chain: &chainMock.ChainService{}}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, clock: clock, chain: &chainMock.ChainService{}}, availableBlocker: mockBlocker{avail: true}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
pcl := protocol.ID(p2p.RPCBlocksByRangeTopicV1)
|
|
|
|
|
topic := string(pcl)
|
|
|
|
|
r.rateLimiter.limiterMap[topic] = leakybucket.NewCollector(0.000001, int64(req.Count*10), time.Second, false)
|
|
|
|
|
@@ -380,7 +381,7 @@ func TestRPCBeaconBlocksByRange_ReturnsGenesisBlock(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clock := startup.NewClock(time.Unix(0, 0), [32]byte{})
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, clock: clock, chain: &chainMock.ChainService{}}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, clock: clock, chain: &chainMock.ChainService{}}, availableBlocker: mockBlocker{avail: true}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
pcl := protocol.ID(p2p.RPCBlocksByRangeTopicV1)
|
|
|
|
|
topic := string(pcl)
|
|
|
|
|
r.rateLimiter.limiterMap[topic] = leakybucket.NewCollector(10000, 10000, time.Second, false)
|
|
|
|
|
@@ -472,7 +473,7 @@ func TestRPCBeaconBlocksByRange_RPCHandlerRateLimitOverflow(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
capacity := int64(flags.Get().BlockBatchLimit * 3)
|
|
|
|
|
clock := startup.NewClock(time.Unix(0, 0), [32]byte{})
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, chain: &chainMock.ChainService{}, clock: clock}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, chain: &chainMock.ChainService{}, clock: clock}, availableBlocker: mockBlocker{avail: true}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
|
|
|
|
|
pcl := protocol.ID(p2p.RPCBlocksByRangeTopicV1)
|
|
|
|
|
topic := string(pcl)
|
|
|
|
|
@@ -499,7 +500,7 @@ func TestRPCBeaconBlocksByRange_RPCHandlerRateLimitOverflow(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
capacity := int64(flags.Get().BlockBatchLimit * 3)
|
|
|
|
|
clock := startup.NewClock(time.Unix(0, 0), [32]byte{})
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, clock: clock, chain: &chainMock.ChainService{}}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, clock: clock, chain: &chainMock.ChainService{}}, availableBlocker: mockBlocker{avail: true}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
|
|
|
|
|
pcl := protocol.ID(p2p.RPCBlocksByRangeTopicV1)
|
|
|
|
|
topic := string(pcl)
|
|
|
|
|
@@ -530,7 +531,7 @@ func TestRPCBeaconBlocksByRange_RPCHandlerRateLimitOverflow(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
capacity := int64(flags.Get().BlockBatchLimit * flags.Get().BlockBatchLimitBurstFactor)
|
|
|
|
|
clock := startup.NewClock(time.Unix(0, 0), [32]byte{})
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, clock: clock, chain: &chainMock.ChainService{}}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, clock: clock, chain: &chainMock.ChainService{}}, availableBlocker: mockBlocker{avail: true}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
pcl := protocol.ID(p2p.RPCBlocksByRangeTopicV1)
|
|
|
|
|
topic := string(pcl)
|
|
|
|
|
r.rateLimiter.limiterMap[topic] = leakybucket.NewCollector(0.000001, capacity, time.Second, false)
|
|
|
|
|
@@ -722,7 +723,7 @@ func TestRPCBeaconBlocksByRange_EnforceResponseInvariants(t *testing.T) {
|
|
|
|
|
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
|
|
|
|
|
|
|
|
|
clock := startup.NewClock(time.Unix(0, 0), [32]byte{})
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, chain: &chainMock.ChainService{}, clock: clock}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, chain: &chainMock.ChainService{}, clock: clock}, availableBlocker: mockBlocker{avail: true}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
r.rateLimiter.limiterMap[string(pcl)] = leakybucket.NewCollector(0.000001, 640, time.Second, false)
|
|
|
|
|
req := ðpb.BeaconBlocksByRangeRequest{
|
|
|
|
|
StartSlot: 448,
|
|
|
|
|
@@ -891,7 +892,7 @@ func TestRPCBeaconBlocksByRange_FilterBlocks(t *testing.T) {
|
|
|
|
|
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
|
|
|
|
|
|
|
|
|
clock := startup.NewClock(time.Unix(0, 0), [32]byte{})
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, clock: clock, chain: &chainMock.ChainService{}}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, clock: clock, chain: &chainMock.ChainService{}}, availableBlocker: mockBlocker{avail: true}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
r.rateLimiter.limiterMap[string(pcl)] = leakybucket.NewCollector(0.000001, 640, time.Second, false)
|
|
|
|
|
req := ðpb.BeaconBlocksByRangeRequest{
|
|
|
|
|
StartSlot: 1,
|
|
|
|
|
@@ -923,7 +924,7 @@ func TestRPCBeaconBlocksByRange_FilterBlocks(t *testing.T) {
|
|
|
|
|
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
|
|
|
|
|
|
|
|
|
clock := startup.NewClock(time.Unix(0, 0), [32]byte{})
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, clock: clock, chain: &chainMock.ChainService{}}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, clock: clock, chain: &chainMock.ChainService{}}, availableBlocker: mockBlocker{avail: true}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
r.rateLimiter.limiterMap[string(pcl)] = leakybucket.NewCollector(0.000001, 640, time.Second, false)
|
|
|
|
|
req := ðpb.BeaconBlocksByRangeRequest{
|
|
|
|
|
StartSlot: 1,
|
|
|
|
|
@@ -958,7 +959,7 @@ func TestRPCBeaconBlocksByRange_FilterBlocks(t *testing.T) {
|
|
|
|
|
p1.Connect(p2)
|
|
|
|
|
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
|
|
|
|
clock := startup.NewClock(time.Unix(0, 0), [32]byte{})
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, chain: &chainMock.ChainService{}, clock: clock}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, chain: &chainMock.ChainService{}, clock: clock}, availableBlocker: mockBlocker{avail: true}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
r.rateLimiter.limiterMap[string(pcl)] = leakybucket.NewCollector(0.000001, 640, time.Second, false)
|
|
|
|
|
req := ðpb.BeaconBlocksByRangeRequest{
|
|
|
|
|
StartSlot: 1,
|
|
|
|
|
@@ -994,7 +995,7 @@ func TestRPCBeaconBlocksByRange_FilterBlocks(t *testing.T) {
|
|
|
|
|
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
|
|
|
|
|
|
|
|
|
clock := startup.NewClock(time.Unix(0, 0), [32]byte{})
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, chain: &chainMock.ChainService{}, clock: clock}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, chain: &chainMock.ChainService{}, clock: clock}, availableBlocker: mockBlocker{avail: true}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
r.rateLimiter.limiterMap[string(pcl)] = leakybucket.NewCollector(0.000001, 640, time.Second, false)
|
|
|
|
|
req := ðpb.BeaconBlocksByRangeRequest{
|
|
|
|
|
StartSlot: 1,
|
|
|
|
|
@@ -1035,7 +1036,7 @@ func TestRPCBeaconBlocksByRange_FilterBlocks(t *testing.T) {
|
|
|
|
|
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
|
|
|
|
|
|
|
|
|
clock := startup.NewClock(time.Unix(0, 0), [32]byte{})
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, chain: &chainMock.ChainService{}, clock: clock}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
r := &Service{cfg: &config{p2p: p1, beaconDB: d, chain: &chainMock.ChainService{}, clock: clock}, availableBlocker: mockBlocker{avail: true}, rateLimiter: newRateLimiter(p1)}
|
|
|
|
|
r.rateLimiter.limiterMap[string(pcl)] = leakybucket.NewCollector(0.000001, 640, time.Second, false)
|
|
|
|
|
req := ðpb.BeaconBlocksByRangeRequest{
|
|
|
|
|
StartSlot: 1,
|
|
|
|
|
@@ -1105,3 +1106,11 @@ func TestRPCBeaconBlocksByRange_FilterBlocks_PreviousRoot(t *testing.T) {
|
|
|
|
|
// pointer should reference a new root.
|
|
|
|
|
require.NotEqual(t, cf.prevRoot, [32]byte{})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type mockBlocker struct {
|
|
|
|
|
avail bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m mockBlocker) AvailableBlock(_ primitives.Slot) bool {
|
|
|
|
|
return m.avail
|
|
|
|
|
}
|
|
|
|
|
|