feat(rpc/validator): stream and use deneb block (#12510)

This commit is contained in:
terencechain
2023-06-09 10:15:51 -07:00
committed by Preston Van Loon
parent 5b1634b335
commit 2be87f623b
3 changed files with 46 additions and 0 deletions

View File

@@ -349,6 +349,8 @@ func (v *validator) ReceiveBlocks(ctx context.Context, connectionErrorChannel ch
blk, err = blocks.NewSignedBeaconBlock(b.BellatrixBlock)
case *ethpb.StreamBlocksResponse_CapellaBlock:
blk, err = blocks.NewSignedBeaconBlock(b.CapellaBlock)
case *ethpb.StreamBlocksResponse_DenebBlock:
blk, err = blocks.NewSignedBeaconBlock(b.DenebBlock)
}
if err != nil {
log.WithError(err).Error("Failed to wrap signed block")

View File

@@ -949,6 +949,37 @@ func TestService_ReceiveBlocks_SetHighest(t *testing.T) {
require.Equal(t, slot, v.highestValidSlot)
}
func TestService_ReceiveBlocks_SetHighestDeneb(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
client := validatormock.NewMockValidatorClient(ctrl)
v := validator{
validatorClient: client,
blockFeed: new(event.Feed),
}
stream := mock2.NewMockBeaconNodeValidatorAltair_StreamBlocksClient(ctrl)
ctx, cancel := context.WithCancel(context.Background())
client.EXPECT().StreamBlocksAltair(
gomock.Any(),
&ethpb.StreamBlocksRequest{VerifiedOnly: true},
).Return(stream, nil)
stream.EXPECT().Context().Return(ctx).AnyTimes()
slot := primitives.Slot(100)
stream.EXPECT().Recv().Return(
&ethpb.StreamBlocksResponse{
Block: &ethpb.StreamBlocksResponse_DenebBlock{
DenebBlock: &ethpb.SignedBeaconBlockDeneb{Block: &ethpb.BeaconBlockDeneb{Slot: slot, Body: &ethpb.BeaconBlockBodyDeneb{}}}},
},
nil,
).Do(func() {
cancel()
})
connectionErrorChannel := make(chan error)
v.ReceiveBlocks(ctx, connectionErrorChannel)
require.Equal(t, slot, v.highestValidSlot)
}
type doppelGangerRequestMatcher struct {
req *ethpb.DoppelGangerRequest
}