From 617ed8e43d249c9b543018eb23d09e769df5535e Mon Sep 17 00:00:00 2001 From: nisdas Date: Fri, 2 Feb 2024 17:57:44 +0800 Subject: [PATCH 1/6] fix it --- .../sync/validate_attester_slashing.go | 8 ++++ .../sync/validate_attester_slashing_test.go | 44 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/beacon-chain/sync/validate_attester_slashing.go b/beacon-chain/sync/validate_attester_slashing.go index fb56960f81b4..51b0484b8eb1 100644 --- a/beacon-chain/sync/validate_attester_slashing.go +++ b/beacon-chain/sync/validate_attester_slashing.go @@ -61,17 +61,25 @@ func (s *Service) validateAttesterSlashing(ctx context.Context, pid peer.ID, msg return pubsub.ValidationReject, err } isSlashable := false + previouslySlashed := false for _, v := range slashedVals { val, err := headState.ValidatorAtIndexReadOnly(primitives.ValidatorIndex(v)) if err != nil { return pubsub.ValidationIgnore, err } + if val.Slashed() { + previouslySlashed = true + continue + } if helpers.IsSlashableValidator(val.ActivationEpoch(), val.WithdrawableEpoch(), val.Slashed(), slots.ToEpoch(headState.Slot())) { isSlashable = true break } } if !isSlashable { + if previouslySlashed { + return pubsub.ValidationIgnore, errors.Errorf("validators were previously slashed: %v", slashedVals) + } return pubsub.ValidationReject, errors.Errorf("none of the validators are slashable: %v", slashedVals) } s.cfg.chain.ReceiveAttesterSlashing(ctx, slashing) diff --git a/beacon-chain/sync/validate_attester_slashing_test.go b/beacon-chain/sync/validate_attester_slashing_test.go index 3fd1ebc1d817..3520282ba59f 100644 --- a/beacon-chain/sync/validate_attester_slashing_test.go +++ b/beacon-chain/sync/validate_attester_slashing_test.go @@ -116,6 +116,50 @@ func TestValidateAttesterSlashing_ValidSlashing(t *testing.T) { assert.NotNil(t, msg.ValidatorData, "Decoded message was not set on the message validator data") } +func TestValidateAttesterSlashing_ValidOldSlashing(t *testing.T) { + p := p2ptest.NewTestP2P(t) + ctx := context.Background() + + slashing, s := setupValidAttesterSlashing(t) + vals := s.Validators() + for _, v := range vals { + v.Slashed = true + } + require.NoError(t, s.SetValidators(vals)) + chain := &mock.ChainService{State: s, Genesis: time.Now()} + r := &Service{ + cfg: &config{ + p2p: p, + chain: chain, + clock: startup.NewClock(chain.Genesis, chain.ValidatorsRoot), + initialSync: &mockSync.Sync{IsSyncing: false}, + operationNotifier: chain.OperationNotifier(), + }, + seenAttesterSlashingCache: make(map[uint64]bool), + subHandler: newSubTopicHandler(), + } + + buf := new(bytes.Buffer) + _, err := p.Encoding().EncodeGossip(buf, slashing) + require.NoError(t, err) + + topic := p2p.GossipTypeMapping[reflect.TypeOf(slashing)] + d, err := r.currentForkDigest() + assert.NoError(t, err) + topic = r.addDigestToTopic(topic, d) + msg := &pubsub.Message{ + Message: &pubsubpb.Message{ + Data: buf.Bytes(), + Topic: &topic, + }, + } + res, err := r.validateAttesterSlashing(ctx, "foobar", msg) + assert.ErrorContains(t, "validators were previously slashed", err) + valid := res == pubsub.ValidationIgnore + + assert.Equal(t, true, valid, "Incorrect Validation") +} + func TestValidateAttesterSlashing_InvalidSlashing_WithdrawableEpoch(t *testing.T) { p := p2ptest.NewTestP2P(t) ctx := context.Background() From 4f518d408dcd0512548eb741c6f12d753f91724e Mon Sep 17 00:00:00 2001 From: nisdas Date: Tue, 6 Feb 2024 12:18:30 +0800 Subject: [PATCH 2/6] check range avail --- .../sync/rpc_beacon_blocks_by_range.go | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/beacon-chain/sync/rpc_beacon_blocks_by_range.go b/beacon-chain/sync/rpc_beacon_blocks_by_range.go index 3e7f7038271c..b52b85ec818c 100644 --- a/beacon-chain/sync/rpc_beacon_blocks_by_range.go +++ b/beacon-chain/sync/rpc_beacon_blocks_by_range.go @@ -6,6 +6,7 @@ import ( libp2pcore "github.com/libp2p/go-libp2p/core" "github.com/pkg/errors" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/db" p2ptypes "github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/v4/cmd/beacon-chain/flags" "github.com/prysmaticlabs/prysm/v4/config/params" @@ -126,6 +127,40 @@ func validateRangeRequest(r *pb.BeaconBlocksByRangeRequest, current primitives.S return rp, nil } +func (s *Service) validateRangeAvailibility(ctx context.Context, rp rangeParams) (bool, error) { + startBlock := rp.start + hs := s.cfg.chain.HeadSlot() + // This is beyond our current head slot. + if startBlock > hs { + return false, nil + } + bs, err := s.cfg.beaconDB.BackfillStatus(ctx) + if err != nil { + // If this is a genesis or legacy node, we retrieve the checkpoint + // sync block. + if !errors.Is(err, db.ErrNotFound) { + return false, err + } + cpr, err := s.cfg.beaconDB.OriginCheckpointBlockRoot(ctx) + if errors.Is(err, db.ErrNotFoundOriginBlockRoot) { + // This would be a genesis synced node and + // would be able to serve all the required blocks. + return true, nil + } + if err != nil { + return false, err + } + cBlk, err := s.cfg.beaconDB.Block(ctx, cpr) + if err != nil { + return false, err + } + // Mark range as unavailable if our checkpoint block has + // as slot less than or equal to the start of the request. + return cBlk.Block().Slot() <= startBlock, nil + } + return primitives.Slot(bs.LowSlot) <= startBlock, nil +} + func (s *Service) writeBlockBatchToStream(ctx context.Context, batch blockBatch, stream libp2pcore.Stream) error { ctx, span := trace.StartSpan(ctx, "sync.WriteBlockRangeToStream") defer span.End() From 431f6b4923bc3a09b43b2ea465bcc8bde544ec68 Mon Sep 17 00:00:00 2001 From: nisdas Date: Tue, 6 Feb 2024 15:45:05 +0800 Subject: [PATCH 3/6] add test cases --- beacon-chain/db/iface/interface.go | 1 + beacon-chain/sync/BUILD.bazel | 1 + .../sync/rpc_beacon_blocks_by_range.go | 5 - .../sync/rpc_beacon_blocks_by_range_test.go | 209 ++++++++++++++++++ 4 files changed, 211 insertions(+), 5 deletions(-) diff --git a/beacon-chain/db/iface/interface.go b/beacon-chain/db/iface/interface.go index aac8dea40999..36cd83b4bb91 100644 --- a/beacon-chain/db/iface/interface.go +++ b/beacon-chain/db/iface/interface.go @@ -111,6 +111,7 @@ type HeadAccessDatabase interface { // Support for checkpoint sync and backfill. SaveOrigin(ctx context.Context, serState, serBlock []byte) error + SaveOriginCheckpointBlockRoot(ctx context.Context, blockRoot [32]byte) error SaveBackfillStatus(context.Context, *dbval.BackfillStatus) error BackfillFinalizedIndex(ctx context.Context, blocks []blocks.ROBlock, finalizedChildRoot [32]byte) error } diff --git a/beacon-chain/sync/BUILD.bazel b/beacon-chain/sync/BUILD.bazel index bfe8a44ed0cc..8d19707a3c87 100644 --- a/beacon-chain/sync/BUILD.bazel +++ b/beacon-chain/sync/BUILD.bazel @@ -233,6 +233,7 @@ go_test( "//encoding/bytesutil:go_default_library", "//encoding/ssz/equality:go_default_library", "//network/forks:go_default_library", + "//proto/dbval:go_default_library", "//proto/engine/v1:go_default_library", "//proto/eth/v2:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/beacon-chain/sync/rpc_beacon_blocks_by_range.go b/beacon-chain/sync/rpc_beacon_blocks_by_range.go index b52b85ec818c..249773b49e05 100644 --- a/beacon-chain/sync/rpc_beacon_blocks_by_range.go +++ b/beacon-chain/sync/rpc_beacon_blocks_by_range.go @@ -129,11 +129,6 @@ func validateRangeRequest(r *pb.BeaconBlocksByRangeRequest, current primitives.S func (s *Service) validateRangeAvailibility(ctx context.Context, rp rangeParams) (bool, error) { startBlock := rp.start - hs := s.cfg.chain.HeadSlot() - // This is beyond our current head slot. - if startBlock > hs { - return false, nil - } bs, err := s.cfg.beaconDB.BackfillStatus(ctx) if err != nil { // If this is a genesis or legacy node, we retrieve the checkpoint diff --git a/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go b/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go index 0d44edc4c06c..094f0b86deee 100644 --- a/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go +++ b/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go @@ -21,6 +21,7 @@ import ( p2ptest "github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p/testing" p2ptypes "github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/v4/beacon-chain/startup" + state_native "github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v4/cmd/beacon-chain/flags" fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams" "github.com/prysmaticlabs/prysm/v4/config/params" @@ -28,6 +29,7 @@ import ( "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" leakybucket "github.com/prysmaticlabs/prysm/v4/container/leaky-bucket" "github.com/prysmaticlabs/prysm/v4/encoding/bytesutil" + "github.com/prysmaticlabs/prysm/v4/proto/dbval" enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/testing/assert" @@ -1105,3 +1107,210 @@ func TestRPCBeaconBlocksByRange_FilterBlocks_PreviousRoot(t *testing.T) { // pointer should reference a new root. require.NotEqual(t, cf.prevRoot, [32]byte{}) } + +func TestRPCBeaconBlocksByRange_ValidateRangeAvailibility(t *testing.T) { + tests := []struct { + name string + rp rangeParams + expectedError error + available bool + svcCreator func(t *testing.T) *Service + }{ + { + name: "Single Block from genesis", + rp: rangeParams{ + start: 1, + end: 1, + size: 1, + }, + svcCreator: func(t *testing.T) *Service { + d := db.SetupDB(t) + clock := startup.NewClock(time.Now(), [32]byte{}) + st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ + Slot: 3, + }) + require.NoError(t, err) + return &Service{cfg: &config{beaconDB: d, clock: clock, chain: &chainMock.ChainService{State: st}}} + }, + expectedError: nil, + available: true, + }, + { + name: "Normal Range from genesis", + rp: rangeParams{ + start: 100, + end: 130, + size: 31, + }, + svcCreator: func(t *testing.T) *Service { + d := db.SetupDB(t) + clock := startup.NewClock(time.Now(), [32]byte{}) + st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ + Slot: 150, + }) + require.NoError(t, err) + return &Service{cfg: &config{beaconDB: d, clock: clock, chain: &chainMock.ChainService{State: st}}} + }, + expectedError: nil, + available: true, + }, + { + name: "Beyond head from genesis", + rp: rangeParams{ + start: 100, + end: 130, + size: 31, + }, + svcCreator: func(t *testing.T) *Service { + d := db.SetupDB(t) + clock := startup.NewClock(time.Now(), [32]byte{}) + st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ + Slot: 100, + }) + require.NoError(t, err) + return &Service{cfg: &config{beaconDB: d, clock: clock, chain: &chainMock.ChainService{State: st}}} + }, + expectedError: nil, + available: true, + }, + { + name: "Before our checkpoint block", + rp: rangeParams{ + start: 100, + end: 130, + size: 31, + }, + svcCreator: func(t *testing.T) *Service { + d := db.SetupDB(t) + clock := startup.NewClock(time.Now(), [32]byte{}) + st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ + Slot: 200, + }) + require.NoError(t, err) + nBlock := util.NewBeaconBlock() + nBlock.Block.Slot = 150 + root, err := nBlock.Block.HashTreeRoot() + require.NoError(t, err) + roBlock, err := blocks.NewSignedBeaconBlock(nBlock) + require.NoError(t, err) + require.NoError(t, d.SaveOriginCheckpointBlockRoot(context.Background(), root)) + require.NoError(t, d.SaveBlock(context.Background(), roBlock)) + + return &Service{cfg: &config{beaconDB: d, clock: clock, chain: &chainMock.ChainService{State: st}}} + }, + expectedError: nil, + available: false, + }, + { + name: "After our checkpoint block", + rp: rangeParams{ + start: 190, + end: 200, + size: 11, + }, + svcCreator: func(t *testing.T) *Service { + d := db.SetupDB(t) + clock := startup.NewClock(time.Now(), [32]byte{}) + st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ + Slot: 200, + }) + require.NoError(t, err) + nBlock := util.NewBeaconBlock() + nBlock.Block.Slot = 150 + root, err := nBlock.Block.HashTreeRoot() + require.NoError(t, err) + roBlock, err := blocks.NewSignedBeaconBlock(nBlock) + require.NoError(t, err) + require.NoError(t, d.SaveOriginCheckpointBlockRoot(context.Background(), root)) + require.NoError(t, d.SaveBlock(context.Background(), roBlock)) + + return &Service{cfg: &config{beaconDB: d, clock: clock, chain: &chainMock.ChainService{State: st}}} + }, + expectedError: nil, + available: true, + }, + { + name: "Before lowest in backfill status", + rp: rangeParams{ + start: 90, + end: 130, + size: 41, + }, + svcCreator: func(t *testing.T) *Service { + d := db.SetupDB(t) + clock := startup.NewClock(time.Now(), [32]byte{}) + st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ + Slot: 200, + }) + require.NoError(t, err) + nBlock := util.NewBeaconBlock() + nBlock.Block.Slot = 150 + root, err := nBlock.Block.HashTreeRoot() + require.NoError(t, err) + roBlock, err := blocks.NewSignedBeaconBlock(nBlock) + require.NoError(t, err) + require.NoError(t, d.SaveOriginCheckpointBlockRoot(context.Background(), root)) + require.NoError(t, d.SaveBlock(context.Background(), roBlock)) + require.NoError(t, d.SaveBackfillStatus(context.Background(), &dbval.BackfillStatus{ + LowSlot: 100, + LowRoot: make([]byte, 32), + LowParentRoot: make([]byte, 32), + OriginSlot: 150, + OriginRoot: root[:], + })) + + return &Service{cfg: &config{beaconDB: d, clock: clock, chain: &chainMock.ChainService{State: st}}} + }, + expectedError: nil, + available: false, + }, + { + name: "After lowest in backfill status", + rp: rangeParams{ + start: 110, + end: 130, + size: 21, + }, + svcCreator: func(t *testing.T) *Service { + d := db.SetupDB(t) + clock := startup.NewClock(time.Now(), [32]byte{}) + st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ + Slot: 200, + }) + require.NoError(t, err) + nBlock := util.NewBeaconBlock() + nBlock.Block.Slot = 150 + root, err := nBlock.Block.HashTreeRoot() + require.NoError(t, err) + roBlock, err := blocks.NewSignedBeaconBlock(nBlock) + require.NoError(t, err) + require.NoError(t, d.SaveOriginCheckpointBlockRoot(context.Background(), root)) + require.NoError(t, d.SaveBlock(context.Background(), roBlock)) + require.NoError(t, d.SaveBackfillStatus(context.Background(), &dbval.BackfillStatus{ + LowSlot: 100, + LowRoot: make([]byte, 32), + LowParentRoot: make([]byte, 32), + OriginSlot: 150, + OriginRoot: root[:], + })) + + return &Service{cfg: &config{beaconDB: d, clock: clock, chain: &chainMock.ChainService{State: st}}} + }, + expectedError: nil, + available: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + s := tt.svcCreator(t) + avail, err := s.validateRangeAvailibility(context.Background(), tt.rp) + if tt.expectedError != nil { + assert.ErrorContains(t, tt.expectedError.Error(), err, "got incorrect error") + } else { + assert.NoError(t, err, "wanted no error") + } + assert.Equal(t, tt.available, avail) + }) + } +} From dde35ac4313ed274d683390f4ac392d428db623e Mon Sep 17 00:00:00 2001 From: nisdas Date: Tue, 6 Feb 2024 16:02:55 +0800 Subject: [PATCH 4/6] add checks --- beacon-chain/p2p/types/rpc_errors.go | 1 + beacon-chain/sync/rpc_beacon_blocks_by_range.go | 15 ++++++++++++++- .../sync/rpc_beacon_blocks_by_range_test.go | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/beacon-chain/p2p/types/rpc_errors.go b/beacon-chain/p2p/types/rpc_errors.go index 9fb7d6e6b4de..6bed696b169f 100644 --- a/beacon-chain/p2p/types/rpc_errors.go +++ b/beacon-chain/p2p/types/rpc_errors.go @@ -14,4 +14,5 @@ var ( ErrInvalidRequest = errors.New("invalid range, step or count") ErrBlobLTMinRequest = errors.New("blob slot < minimum_request_epoch") ErrMaxBlobReqExceeded = errors.New("requested more than MAX_REQUEST_BLOB_SIDECARS") + ErrResourceUnavailable = errors.New("resource requested unavailable") ) diff --git a/beacon-chain/sync/rpc_beacon_blocks_by_range.go b/beacon-chain/sync/rpc_beacon_blocks_by_range.go index 249773b49e05..614459dedd22 100644 --- a/beacon-chain/sync/rpc_beacon_blocks_by_range.go +++ b/beacon-chain/sync/rpc_beacon_blocks_by_range.go @@ -39,6 +39,19 @@ func (s *Service) beaconBlocksByRangeRPCHandler(ctx context.Context, msg interfa tracing.AnnotateError(span, err) return err } + available, err := s.validateRangeAvailability(ctx, rp) + if err != nil { + log.WithError(err).Debug("error in validating range availability") + s.writeErrorResponseToStream(responseCodeServerError, p2ptypes.ErrGeneric.Error(), stream) + tracing.AnnotateError(span, err) + return err + } + if !available { + log.Debug("error in validating range availability") + s.writeErrorResponseToStream(responseCodeResourceUnavailable, p2ptypes.ErrResourceUnavailable.Error(), stream) + tracing.AnnotateError(span, err) + return nil + } blockLimiter, err := s.rateLimiter.topicCollector(string(stream.Protocol())) if err != nil { @@ -127,7 +140,7 @@ func validateRangeRequest(r *pb.BeaconBlocksByRangeRequest, current primitives.S return rp, nil } -func (s *Service) validateRangeAvailibility(ctx context.Context, rp rangeParams) (bool, error) { +func (s *Service) validateRangeAvailability(ctx context.Context, rp rangeParams) (bool, error) { startBlock := rp.start bs, err := s.cfg.beaconDB.BackfillStatus(ctx) if err != nil { diff --git a/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go b/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go index 094f0b86deee..af07d7a446be 100644 --- a/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go +++ b/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go @@ -1304,7 +1304,7 @@ func TestRPCBeaconBlocksByRange_ValidateRangeAvailibility(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { s := tt.svcCreator(t) - avail, err := s.validateRangeAvailibility(context.Background(), tt.rp) + avail, err := s.validateRangeAvailability(context.Background(), tt.rp) if tt.expectedError != nil { assert.ErrorContains(t, tt.expectedError.Error(), err, "got incorrect error") } else { From 1f799aeb4dd85649ad1379bdacab2ef9c12e926a Mon Sep 17 00:00:00 2001 From: nisdas Date: Thu, 8 Feb 2024 16:57:44 +0800 Subject: [PATCH 5/6] kasey's review --- beacon-chain/db/iface/interface.go | 1 - beacon-chain/node/node.go | 5 +- beacon-chain/sync/BUILD.bazel | 2 + beacon-chain/sync/options.go | 10 + .../sync/rpc_beacon_blocks_by_range.go | 37 +-- .../sync/rpc_beacon_blocks_by_range_test.go | 240 ++---------------- beacon-chain/sync/service.go | 2 + 7 files changed, 40 insertions(+), 257 deletions(-) diff --git a/beacon-chain/db/iface/interface.go b/beacon-chain/db/iface/interface.go index 36cd83b4bb91..aac8dea40999 100644 --- a/beacon-chain/db/iface/interface.go +++ b/beacon-chain/db/iface/interface.go @@ -111,7 +111,6 @@ type HeadAccessDatabase interface { // Support for checkpoint sync and backfill. SaveOrigin(ctx context.Context, serState, serBlock []byte) error - SaveOriginCheckpointBlockRoot(ctx context.Context, blockRoot [32]byte) error SaveBackfillStatus(context.Context, *dbval.BackfillStatus) error BackfillFinalizedIndex(ctx context.Context, blocks []blocks.ROBlock, finalizedChildRoot [32]byte) error } diff --git a/beacon-chain/node/node.go b/beacon-chain/node/node.go index 8c59aed2ceab..31426aaaaadb 100644 --- a/beacon-chain/node/node.go +++ b/beacon-chain/node/node.go @@ -277,7 +277,7 @@ func New(cliCtx *cli.Context, cancel context.CancelFunc, opts ...Option) (*Beaco } log.Debugln("Registering Sync Service") - if err := beacon.registerSyncService(beacon.initialSyncComplete); err != nil { + if err := beacon.registerSyncService(beacon.initialSyncComplete, bfs); err != nil { return nil, err } @@ -719,7 +719,7 @@ func (b *BeaconNode) registerPOWChainService() error { return b.services.RegisterService(web3Service) } -func (b *BeaconNode) registerSyncService(initialSyncComplete chan struct{}) error { +func (b *BeaconNode) registerSyncService(initialSyncComplete chan struct{}, bFillStore *backfill.Store) error { var web3Service *execution.Service if err := b.services.FetchService(&web3Service); err != nil { return err @@ -758,6 +758,7 @@ func (b *BeaconNode) registerSyncService(initialSyncComplete chan struct{}) erro regularsync.WithStateNotifier(b), regularsync.WithBlobStorage(b.BlobStorage), regularsync.WithVerifierWaiter(b.verifyInitWaiter), + regularsync.WithAvailableBlocker(bFillStore), ) return b.services.RegisterService(rs) } diff --git a/beacon-chain/sync/BUILD.bazel b/beacon-chain/sync/BUILD.bazel index 8d19707a3c87..b13b9db94713 100644 --- a/beacon-chain/sync/BUILD.bazel +++ b/beacon-chain/sync/BUILD.bazel @@ -90,6 +90,7 @@ go_library( "//beacon-chain/startup:go_default_library", "//beacon-chain/state:go_default_library", "//beacon-chain/state/stategen:go_default_library", + "//beacon-chain/sync/backfill/coverage:go_default_library", "//beacon-chain/sync/verify:go_default_library", "//beacon-chain/verification:go_default_library", "//cache/lru:go_default_library", @@ -216,6 +217,7 @@ go_test( "//beacon-chain/state:go_default_library", "//beacon-chain/state/state-native:go_default_library", "//beacon-chain/state/stategen:go_default_library", + "//beacon-chain/sync/backfill:go_default_library", "//beacon-chain/sync/initial-sync/testing:go_default_library", "//beacon-chain/verification:go_default_library", "//cache/lru:go_default_library", diff --git a/beacon-chain/sync/options.go b/beacon-chain/sync/options.go index cba850c8a3f4..e605fd2c848b 100644 --- a/beacon-chain/sync/options.go +++ b/beacon-chain/sync/options.go @@ -16,6 +16,7 @@ import ( "github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/v4/beacon-chain/startup" "github.com/prysmaticlabs/prysm/v4/beacon-chain/state/stategen" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/sync/backfill/coverage" "github.com/prysmaticlabs/prysm/v4/beacon-chain/verification" ) @@ -170,3 +171,12 @@ func WithVerifierWaiter(v *verification.InitializerWaiter) Option { return nil } } + +// WithAvailableBlocker allows the sync package to access the current +// status of backfill. +func WithAvailableBlocker(avb coverage.AvailableBlocker) Option { + return func(s *Service) error { + s.availableBlocker = avb + return nil + } +} diff --git a/beacon-chain/sync/rpc_beacon_blocks_by_range.go b/beacon-chain/sync/rpc_beacon_blocks_by_range.go index 614459dedd22..30cfddfbdfc4 100644 --- a/beacon-chain/sync/rpc_beacon_blocks_by_range.go +++ b/beacon-chain/sync/rpc_beacon_blocks_by_range.go @@ -6,7 +6,6 @@ import ( libp2pcore "github.com/libp2p/go-libp2p/core" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/db" p2ptypes "github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/v4/cmd/beacon-chain/flags" "github.com/prysmaticlabs/prysm/v4/config/params" @@ -39,13 +38,7 @@ func (s *Service) beaconBlocksByRangeRPCHandler(ctx context.Context, msg interfa tracing.AnnotateError(span, err) return err } - available, err := s.validateRangeAvailability(ctx, rp) - if err != nil { - log.WithError(err).Debug("error in validating range availability") - s.writeErrorResponseToStream(responseCodeServerError, p2ptypes.ErrGeneric.Error(), stream) - tracing.AnnotateError(span, err) - return err - } + available := s.validateRangeAvailability(rp) if !available { log.Debug("error in validating range availability") s.writeErrorResponseToStream(responseCodeResourceUnavailable, p2ptypes.ErrResourceUnavailable.Error(), stream) @@ -140,33 +133,9 @@ func validateRangeRequest(r *pb.BeaconBlocksByRangeRequest, current primitives.S return rp, nil } -func (s *Service) validateRangeAvailability(ctx context.Context, rp rangeParams) (bool, error) { +func (s *Service) validateRangeAvailability(rp rangeParams) bool { startBlock := rp.start - bs, err := s.cfg.beaconDB.BackfillStatus(ctx) - if err != nil { - // If this is a genesis or legacy node, we retrieve the checkpoint - // sync block. - if !errors.Is(err, db.ErrNotFound) { - return false, err - } - cpr, err := s.cfg.beaconDB.OriginCheckpointBlockRoot(ctx) - if errors.Is(err, db.ErrNotFoundOriginBlockRoot) { - // This would be a genesis synced node and - // would be able to serve all the required blocks. - return true, nil - } - if err != nil { - return false, err - } - cBlk, err := s.cfg.beaconDB.Block(ctx, cpr) - if err != nil { - return false, err - } - // Mark range as unavailable if our checkpoint block has - // as slot less than or equal to the start of the request. - return cBlk.Block().Slot() <= startBlock, nil - } - return primitives.Slot(bs.LowSlot) <= startBlock, nil + return s.availableBlocker.AvailableBlock(startBlock) } func (s *Service) writeBlockBatchToStream(ctx context.Context, batch blockBatch, stream libp2pcore.Stream) error { diff --git a/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go b/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go index af07d7a446be..a71950baa400 100644 --- a/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go +++ b/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go @@ -21,7 +21,6 @@ import ( p2ptest "github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p/testing" p2ptypes "github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/v4/beacon-chain/startup" - state_native "github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v4/cmd/beacon-chain/flags" fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams" "github.com/prysmaticlabs/prysm/v4/config/params" @@ -29,7 +28,6 @@ import ( "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" leakybucket "github.com/prysmaticlabs/prysm/v4/container/leaky-bucket" "github.com/prysmaticlabs/prysm/v4/encoding/bytesutil" - "github.com/prysmaticlabs/prysm/v4/proto/dbval" enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/testing/assert" @@ -66,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) @@ -129,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) @@ -246,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) @@ -316,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) @@ -382,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) @@ -474,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) @@ -501,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) @@ -532,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) @@ -724,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, @@ -893,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, @@ -925,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, @@ -960,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, @@ -996,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, @@ -1037,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, @@ -1108,209 +1107,10 @@ func TestRPCBeaconBlocksByRange_FilterBlocks_PreviousRoot(t *testing.T) { require.NotEqual(t, cf.prevRoot, [32]byte{}) } -func TestRPCBeaconBlocksByRange_ValidateRangeAvailibility(t *testing.T) { - tests := []struct { - name string - rp rangeParams - expectedError error - available bool - svcCreator func(t *testing.T) *Service - }{ - { - name: "Single Block from genesis", - rp: rangeParams{ - start: 1, - end: 1, - size: 1, - }, - svcCreator: func(t *testing.T) *Service { - d := db.SetupDB(t) - clock := startup.NewClock(time.Now(), [32]byte{}) - st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ - Slot: 3, - }) - require.NoError(t, err) - return &Service{cfg: &config{beaconDB: d, clock: clock, chain: &chainMock.ChainService{State: st}}} - }, - expectedError: nil, - available: true, - }, - { - name: "Normal Range from genesis", - rp: rangeParams{ - start: 100, - end: 130, - size: 31, - }, - svcCreator: func(t *testing.T) *Service { - d := db.SetupDB(t) - clock := startup.NewClock(time.Now(), [32]byte{}) - st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ - Slot: 150, - }) - require.NoError(t, err) - return &Service{cfg: &config{beaconDB: d, clock: clock, chain: &chainMock.ChainService{State: st}}} - }, - expectedError: nil, - available: true, - }, - { - name: "Beyond head from genesis", - rp: rangeParams{ - start: 100, - end: 130, - size: 31, - }, - svcCreator: func(t *testing.T) *Service { - d := db.SetupDB(t) - clock := startup.NewClock(time.Now(), [32]byte{}) - st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ - Slot: 100, - }) - require.NoError(t, err) - return &Service{cfg: &config{beaconDB: d, clock: clock, chain: &chainMock.ChainService{State: st}}} - }, - expectedError: nil, - available: true, - }, - { - name: "Before our checkpoint block", - rp: rangeParams{ - start: 100, - end: 130, - size: 31, - }, - svcCreator: func(t *testing.T) *Service { - d := db.SetupDB(t) - clock := startup.NewClock(time.Now(), [32]byte{}) - st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ - Slot: 200, - }) - require.NoError(t, err) - nBlock := util.NewBeaconBlock() - nBlock.Block.Slot = 150 - root, err := nBlock.Block.HashTreeRoot() - require.NoError(t, err) - roBlock, err := blocks.NewSignedBeaconBlock(nBlock) - require.NoError(t, err) - require.NoError(t, d.SaveOriginCheckpointBlockRoot(context.Background(), root)) - require.NoError(t, d.SaveBlock(context.Background(), roBlock)) - - return &Service{cfg: &config{beaconDB: d, clock: clock, chain: &chainMock.ChainService{State: st}}} - }, - expectedError: nil, - available: false, - }, - { - name: "After our checkpoint block", - rp: rangeParams{ - start: 190, - end: 200, - size: 11, - }, - svcCreator: func(t *testing.T) *Service { - d := db.SetupDB(t) - clock := startup.NewClock(time.Now(), [32]byte{}) - st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ - Slot: 200, - }) - require.NoError(t, err) - nBlock := util.NewBeaconBlock() - nBlock.Block.Slot = 150 - root, err := nBlock.Block.HashTreeRoot() - require.NoError(t, err) - roBlock, err := blocks.NewSignedBeaconBlock(nBlock) - require.NoError(t, err) - require.NoError(t, d.SaveOriginCheckpointBlockRoot(context.Background(), root)) - require.NoError(t, d.SaveBlock(context.Background(), roBlock)) - - return &Service{cfg: &config{beaconDB: d, clock: clock, chain: &chainMock.ChainService{State: st}}} - }, - expectedError: nil, - available: true, - }, - { - name: "Before lowest in backfill status", - rp: rangeParams{ - start: 90, - end: 130, - size: 41, - }, - svcCreator: func(t *testing.T) *Service { - d := db.SetupDB(t) - clock := startup.NewClock(time.Now(), [32]byte{}) - st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ - Slot: 200, - }) - require.NoError(t, err) - nBlock := util.NewBeaconBlock() - nBlock.Block.Slot = 150 - root, err := nBlock.Block.HashTreeRoot() - require.NoError(t, err) - roBlock, err := blocks.NewSignedBeaconBlock(nBlock) - require.NoError(t, err) - require.NoError(t, d.SaveOriginCheckpointBlockRoot(context.Background(), root)) - require.NoError(t, d.SaveBlock(context.Background(), roBlock)) - require.NoError(t, d.SaveBackfillStatus(context.Background(), &dbval.BackfillStatus{ - LowSlot: 100, - LowRoot: make([]byte, 32), - LowParentRoot: make([]byte, 32), - OriginSlot: 150, - OriginRoot: root[:], - })) - - return &Service{cfg: &config{beaconDB: d, clock: clock, chain: &chainMock.ChainService{State: st}}} - }, - expectedError: nil, - available: false, - }, - { - name: "After lowest in backfill status", - rp: rangeParams{ - start: 110, - end: 130, - size: 21, - }, - svcCreator: func(t *testing.T) *Service { - d := db.SetupDB(t) - clock := startup.NewClock(time.Now(), [32]byte{}) - st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ - Slot: 200, - }) - require.NoError(t, err) - nBlock := util.NewBeaconBlock() - nBlock.Block.Slot = 150 - root, err := nBlock.Block.HashTreeRoot() - require.NoError(t, err) - roBlock, err := blocks.NewSignedBeaconBlock(nBlock) - require.NoError(t, err) - require.NoError(t, d.SaveOriginCheckpointBlockRoot(context.Background(), root)) - require.NoError(t, d.SaveBlock(context.Background(), roBlock)) - require.NoError(t, d.SaveBackfillStatus(context.Background(), &dbval.BackfillStatus{ - LowSlot: 100, - LowRoot: make([]byte, 32), - LowParentRoot: make([]byte, 32), - OriginSlot: 150, - OriginRoot: root[:], - })) - - return &Service{cfg: &config{beaconDB: d, clock: clock, chain: &chainMock.ChainService{State: st}}} - }, - expectedError: nil, - available: true, - }, - } +type mockBlocker struct { + avail bool +} - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - s := tt.svcCreator(t) - avail, err := s.validateRangeAvailability(context.Background(), tt.rp) - if tt.expectedError != nil { - assert.ErrorContains(t, tt.expectedError.Error(), err, "got incorrect error") - } else { - assert.NoError(t, err, "wanted no error") - } - assert.Equal(t, tt.available, avail) - }) - } +func (m mockBlocker) AvailableBlock(_ primitives.Slot) bool { + return m.avail } diff --git a/beacon-chain/sync/service.go b/beacon-chain/sync/service.go index bc664489814e..2cb280a92fac 100644 --- a/beacon-chain/sync/service.go +++ b/beacon-chain/sync/service.go @@ -33,6 +33,7 @@ import ( "github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/v4/beacon-chain/startup" "github.com/prysmaticlabs/prysm/v4/beacon-chain/state/stategen" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/sync/backfill/coverage" "github.com/prysmaticlabs/prysm/v4/beacon-chain/verification" lruwrpr "github.com/prysmaticlabs/prysm/v4/cache/lru" "github.com/prysmaticlabs/prysm/v4/config/params" @@ -155,6 +156,7 @@ type Service struct { initialSyncComplete chan struct{} verifierWaiter *verification.InitializerWaiter newBlobVerifier verification.NewBlobVerifier + availableBlocker coverage.AvailableBlocker } // NewService initializes new regular sync service. From 360e2f9e5f2af61b3369301e37cde2553b5839f6 Mon Sep 17 00:00:00 2001 From: nisdas Date: Thu, 8 Feb 2024 17:00:42 +0800 Subject: [PATCH 6/6] gaz --- beacon-chain/sync/BUILD.bazel | 2 -- 1 file changed, 2 deletions(-) diff --git a/beacon-chain/sync/BUILD.bazel b/beacon-chain/sync/BUILD.bazel index b13b9db94713..3e981185e739 100644 --- a/beacon-chain/sync/BUILD.bazel +++ b/beacon-chain/sync/BUILD.bazel @@ -217,7 +217,6 @@ go_test( "//beacon-chain/state:go_default_library", "//beacon-chain/state/state-native:go_default_library", "//beacon-chain/state/stategen:go_default_library", - "//beacon-chain/sync/backfill:go_default_library", "//beacon-chain/sync/initial-sync/testing:go_default_library", "//beacon-chain/verification:go_default_library", "//cache/lru:go_default_library", @@ -235,7 +234,6 @@ go_test( "//encoding/bytesutil:go_default_library", "//encoding/ssz/equality:go_default_library", "//network/forks:go_default_library", - "//proto/dbval:go_default_library", "//proto/engine/v1:go_default_library", "//proto/eth/v2:go_default_library", "//proto/prysm/v1alpha1:go_default_library",