mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 19:40:37 +00:00
Add optimistic status to chainhead (#10842)
* Add optimistic status to chainhead * Fix tests Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
parent
fce9e6883d
commit
7fcadbe3ef
@ -393,6 +393,10 @@ func (bs *Server) chainHeadRetrieval(ctx context.Context) (*ethpb.ChainHead, err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Error(codes.Internal, "Could not get head block")
|
return nil, status.Error(codes.Internal, "Could not get head block")
|
||||||
}
|
}
|
||||||
|
optimisticStatus, err := bs.OptimisticModeFetcher.IsOptimistic(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, status.Error(codes.Internal, "Could not get optimistic status")
|
||||||
|
}
|
||||||
if err := wrapper.BeaconBlockIsNil(headBlock); err != nil {
|
if err := wrapper.BeaconBlockIsNil(headBlock); err != nil {
|
||||||
return nil, status.Errorf(codes.NotFound, "Head block of chain was nil: %v", err)
|
return nil, status.Errorf(codes.NotFound, "Head block of chain was nil: %v", err)
|
||||||
}
|
}
|
||||||
@ -474,5 +478,6 @@ func (bs *Server) chainHeadRetrieval(ctx context.Context) (*ethpb.ChainHead, err
|
|||||||
PreviousJustifiedSlot: pjSlot,
|
PreviousJustifiedSlot: pjSlot,
|
||||||
PreviousJustifiedEpoch: prevJustifiedCheckpoint.Epoch,
|
PreviousJustifiedEpoch: prevJustifiedCheckpoint.Epoch,
|
||||||
PreviousJustifiedBlockRoot: prevJustifiedCheckpoint.Root,
|
PreviousJustifiedBlockRoot: prevJustifiedCheckpoint.Root,
|
||||||
|
OptimisticStatus: optimisticStatus,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -426,6 +426,7 @@ func TestServer_GetChainHead_NoGenesis(t *testing.T) {
|
|||||||
FinalizedCheckPoint: s.FinalizedCheckpoint(),
|
FinalizedCheckPoint: s.FinalizedCheckpoint(),
|
||||||
CurrentJustifiedCheckPoint: s.CurrentJustifiedCheckpoint(),
|
CurrentJustifiedCheckPoint: s.CurrentJustifiedCheckpoint(),
|
||||||
PreviousJustifiedCheckPoint: s.PreviousJustifiedCheckpoint()},
|
PreviousJustifiedCheckPoint: s.PreviousJustifiedCheckpoint()},
|
||||||
|
OptimisticModeFetcher: &chainMock.ChainService{},
|
||||||
}
|
}
|
||||||
_, err = bs.GetChainHead(context.Background(), nil)
|
_, err = bs.GetChainHead(context.Background(), nil)
|
||||||
require.ErrorContains(t, "Could not get genesis block", err)
|
require.ErrorContains(t, "Could not get genesis block", err)
|
||||||
@ -461,6 +462,7 @@ func TestServer_GetChainHead_NoFinalizedBlock(t *testing.T) {
|
|||||||
FinalizedCheckPoint: s.FinalizedCheckpoint(),
|
FinalizedCheckPoint: s.FinalizedCheckpoint(),
|
||||||
CurrentJustifiedCheckPoint: s.CurrentJustifiedCheckpoint(),
|
CurrentJustifiedCheckPoint: s.CurrentJustifiedCheckpoint(),
|
||||||
PreviousJustifiedCheckPoint: s.PreviousJustifiedCheckpoint()},
|
PreviousJustifiedCheckPoint: s.PreviousJustifiedCheckpoint()},
|
||||||
|
OptimisticModeFetcher: &chainMock.ChainService{},
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = bs.GetChainHead(context.Background(), nil)
|
_, err = bs.GetChainHead(context.Background(), nil)
|
||||||
@ -469,7 +471,8 @@ func TestServer_GetChainHead_NoFinalizedBlock(t *testing.T) {
|
|||||||
|
|
||||||
func TestServer_GetChainHead_NoHeadBlock(t *testing.T) {
|
func TestServer_GetChainHead_NoHeadBlock(t *testing.T) {
|
||||||
bs := &Server{
|
bs := &Server{
|
||||||
HeadFetcher: &chainMock.ChainService{Block: nil},
|
HeadFetcher: &chainMock.ChainService{Block: nil},
|
||||||
|
OptimisticModeFetcher: &chainMock.ChainService{},
|
||||||
}
|
}
|
||||||
_, err := bs.GetChainHead(context.Background(), nil)
|
_, err := bs.GetChainHead(context.Background(), nil)
|
||||||
assert.ErrorContains(t, "Head block of chain was nil", err)
|
assert.ErrorContains(t, "Head block of chain was nil", err)
|
||||||
@ -531,8 +534,9 @@ func TestServer_GetChainHead(t *testing.T) {
|
|||||||
wsb, err = wrapper.WrappedSignedBeaconBlock(b)
|
wsb, err = wrapper.WrappedSignedBeaconBlock(b)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
bs := &Server{
|
bs := &Server{
|
||||||
BeaconDB: db,
|
BeaconDB: db,
|
||||||
HeadFetcher: &chainMock.ChainService{Block: wsb, State: s},
|
HeadFetcher: &chainMock.ChainService{Block: wsb, State: s},
|
||||||
|
OptimisticModeFetcher: &chainMock.ChainService{},
|
||||||
FinalizationFetcher: &chainMock.ChainService{
|
FinalizationFetcher: &chainMock.ChainService{
|
||||||
FinalizedCheckPoint: s.FinalizedCheckpoint(),
|
FinalizedCheckPoint: s.FinalizedCheckpoint(),
|
||||||
CurrentJustifiedCheckPoint: s.CurrentJustifiedCheckpoint(),
|
CurrentJustifiedCheckPoint: s.CurrentJustifiedCheckpoint(),
|
||||||
@ -550,6 +554,7 @@ func TestServer_GetChainHead(t *testing.T) {
|
|||||||
assert.DeepEqual(t, pjRoot[:], head.PreviousJustifiedBlockRoot, "Unexpected PreviousJustifiedBlockRoot")
|
assert.DeepEqual(t, pjRoot[:], head.PreviousJustifiedBlockRoot, "Unexpected PreviousJustifiedBlockRoot")
|
||||||
assert.DeepEqual(t, jRoot[:], head.JustifiedBlockRoot, "Unexpected JustifiedBlockRoot")
|
assert.DeepEqual(t, jRoot[:], head.JustifiedBlockRoot, "Unexpected JustifiedBlockRoot")
|
||||||
assert.DeepEqual(t, fRoot[:], head.FinalizedBlockRoot, "Unexpected FinalizedBlockRoot")
|
assert.DeepEqual(t, fRoot[:], head.FinalizedBlockRoot, "Unexpected FinalizedBlockRoot")
|
||||||
|
assert.Equal(t, false, head.OptimisticStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_StreamChainHead_ContextCanceled(t *testing.T) {
|
func TestServer_StreamChainHead_ContextCanceled(t *testing.T) {
|
||||||
@ -645,6 +650,7 @@ func TestServer_StreamChainHead_OnHeadUpdated(t *testing.T) {
|
|||||||
FinalizedCheckPoint: s.FinalizedCheckpoint(),
|
FinalizedCheckPoint: s.FinalizedCheckpoint(),
|
||||||
CurrentJustifiedCheckPoint: s.CurrentJustifiedCheckpoint(),
|
CurrentJustifiedCheckPoint: s.CurrentJustifiedCheckpoint(),
|
||||||
PreviousJustifiedCheckPoint: s.PreviousJustifiedCheckpoint()},
|
PreviousJustifiedCheckPoint: s.PreviousJustifiedCheckpoint()},
|
||||||
|
OptimisticModeFetcher: &chainMock.ChainService{},
|
||||||
}
|
}
|
||||||
exitRoutine := make(chan bool)
|
exitRoutine := make(chan bool)
|
||||||
ctrl := gomock.NewController(t)
|
ctrl := gomock.NewController(t)
|
||||||
|
@ -47,4 +47,5 @@ type Server struct {
|
|||||||
SyncChecker sync.Checker
|
SyncChecker sync.Checker
|
||||||
ReplayerBuilder stategen.ReplayerBuilder
|
ReplayerBuilder stategen.ReplayerBuilder
|
||||||
HeadUpdater blockchain.HeadUpdater
|
HeadUpdater blockchain.HeadUpdater
|
||||||
|
OptimisticModeFetcher blockchain.OptimisticModeFetcher
|
||||||
}
|
}
|
||||||
|
@ -268,6 +268,7 @@ func (s *Service) Start() {
|
|||||||
AttestationsPool: s.cfg.AttestationsPool,
|
AttestationsPool: s.cfg.AttestationsPool,
|
||||||
SlashingsPool: s.cfg.SlashingsPool,
|
SlashingsPool: s.cfg.SlashingsPool,
|
||||||
HeadUpdater: s.cfg.HeadUpdater,
|
HeadUpdater: s.cfg.HeadUpdater,
|
||||||
|
OptimisticModeFetcher: s.cfg.OptimisticModeFetcher,
|
||||||
HeadFetcher: s.cfg.HeadFetcher,
|
HeadFetcher: s.cfg.HeadFetcher,
|
||||||
FinalizationFetcher: s.cfg.FinalizationFetcher,
|
FinalizationFetcher: s.cfg.FinalizationFetcher,
|
||||||
CanonicalFetcher: s.cfg.CanonicalFetcher,
|
CanonicalFetcher: s.cfg.CanonicalFetcher,
|
||||||
|
1559
proto/prysm/v1alpha1/beacon_chain.pb.go
generated
1559
proto/prysm/v1alpha1/beacon_chain.pb.go
generated
File diff suppressed because it is too large
Load Diff
@ -474,6 +474,9 @@ message ChainHead {
|
|||||||
|
|
||||||
// Previous 32 byte justified block root.
|
// Previous 32 byte justified block root.
|
||||||
bytes previous_justified_block_root = 12 [(ethereum.eth.ext.ssz_size) = "32"];
|
bytes previous_justified_block_root = 12 [(ethereum.eth.ext.ssz_size) = "32"];
|
||||||
|
|
||||||
|
// Optimistic status of the current head
|
||||||
|
bool optimistic_status = 13;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ListCommitteesRequest {
|
message ListCommitteesRequest {
|
||||||
|
Loading…
Reference in New Issue
Block a user