-
Notifications
You must be signed in to change notification settings - Fork 1.3k
rpc: add SubmitSignedProposerPreferences gRPC endpoint #16538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
beacon-chain/rpc/prysm/v1alpha1/validator/proposer_preferences.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package validator | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/OffchainLabs/prysm/v7/config/params" | ||
| "github.com/OffchainLabs/prysm/v7/monitoring/tracing/trace" | ||
| ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1" | ||
| "github.com/OffchainLabs/prysm/v7/time/slots" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/sirupsen/logrus" | ||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/status" | ||
| "google.golang.org/protobuf/types/known/emptypb" | ||
| ) | ||
|
|
||
| // SubmitSignedProposerPreferences broadcasts signed proposer preferences and | ||
| // caches them locally for subsequent bid validation. | ||
| // Local submissions intentionally bypass full gossip verification (proposer | ||
| // lookahead, signature) because the validator client is trusted. | ||
| func (vs *Server) SubmitSignedProposerPreferences( | ||
| ctx context.Context, | ||
| msg *ethpb.SignedProposerPreferences, | ||
| ) (*emptypb.Empty, error) { | ||
| ctx, span := trace.StartSpan(ctx, "ValidatorServer.SubmitSignedProposerPreferences") | ||
| defer span.End() | ||
|
|
||
| if msg == nil || msg.Message == nil { | ||
| return nil, status.Errorf(codes.InvalidArgument, "signed proposer preferences message is nil") | ||
| } | ||
|
|
||
| if vs.SyncChecker.Syncing() { | ||
| return nil, status.Errorf(codes.Unavailable, "Syncing to latest head, not ready to respond") | ||
| } | ||
|
|
||
| proposalSlot := msg.Message.ProposalSlot | ||
| if slots.ToEpoch(proposalSlot) < params.BeaconConfig().GloasForkEpoch { | ||
| return nil, status.Errorf( | ||
| codes.InvalidArgument, | ||
| "signed proposer preferences are not supported before Gloas fork (slot %d)", | ||
| proposalSlot, | ||
| ) | ||
| } | ||
|
|
||
| currentEpoch := slots.ToEpoch(vs.TimeFetcher.CurrentSlot()) | ||
| if slots.ToEpoch(proposalSlot) != currentEpoch+1 { | ||
| return nil, status.Errorf( | ||
| codes.InvalidArgument, | ||
| "signed proposer preferences proposal slot must be in the next epoch: slot %d currentEpoch %d", | ||
| proposalSlot, | ||
| currentEpoch, | ||
| ) | ||
| } | ||
|
|
||
| if vs.ProposerPreferencesCache.Has(proposalSlot) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we already proposed it aka in the cache, should we just be returning empty? what about a debut log here saying some kind of duplicate submission? |
||
| log.WithFields(logrus.Fields{ | ||
| "slot": proposalSlot, | ||
| "validatorIndex": msg.Message.ValidatorIndex, | ||
| }).Debug("Ignoring duplicate signed proposer preferences submission") | ||
| return &emptypb.Empty{}, nil | ||
| } | ||
|
|
||
| if err := vs.P2P.Broadcast(ctx, msg); err != nil { | ||
| return nil, status.Errorf(codes.Internal, "Could not broadcast signed proposer preferences: %v", err) | ||
| } | ||
|
|
||
| vs.ProposerPreferencesCache.Add(proposalSlot, msg.Message.FeeRecipient, msg.Message.GasLimit) | ||
|
|
||
| log.WithFields(logrus.Fields{ | ||
| "slot": proposalSlot, | ||
| "validatorIndex": msg.Message.ValidatorIndex, | ||
| "feeRecipient": common.BytesToAddress(msg.Message.FeeRecipient).Hex(), | ||
| "gasLimit": msg.Message.GasLimit, | ||
| }).Debug("Submitted signed proposer preferences") | ||
| return &emptypb.Empty{}, nil | ||
| } | ||
152 changes: 152 additions & 0 deletions
152
beacon-chain/rpc/prysm/v1alpha1/validator/proposer_preferences_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| package validator | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| chainMock "github.com/OffchainLabs/prysm/v7/beacon-chain/blockchain/testing" | ||
| "github.com/OffchainLabs/prysm/v7/beacon-chain/cache" | ||
| p2pmock "github.com/OffchainLabs/prysm/v7/beacon-chain/p2p/testing" | ||
| mockSync "github.com/OffchainLabs/prysm/v7/beacon-chain/sync/initial-sync/testing" | ||
| "github.com/OffchainLabs/prysm/v7/config/params" | ||
| "github.com/OffchainLabs/prysm/v7/consensus-types/primitives" | ||
| ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1" | ||
| "github.com/OffchainLabs/prysm/v7/testing/assert" | ||
| "github.com/OffchainLabs/prysm/v7/testing/require" | ||
| "google.golang.org/protobuf/types/known/emptypb" | ||
| ) | ||
|
|
||
| func TestSubmitSignedProposerPreferences_OK(t *testing.T) { | ||
| params.SetupTestConfigCleanup(t) | ||
| cfg := params.BeaconConfig().Copy() | ||
| cfg.GloasForkEpoch = 1 | ||
| params.OverrideBeaconConfig(cfg) | ||
|
|
||
| currentSlot := primitives.Slot(31) | ||
| proposalSlot := currentSlot + 1 | ||
| chain := &chainMock.ChainService{Slot: ¤tSlot} | ||
| p2p := &p2pmock.MockBroadcaster{} | ||
| cache := cache.NewProposerPreferencesCache() | ||
| vs := &Server{ | ||
| SyncChecker: &mockSync.Sync{IsSyncing: false}, | ||
| TimeFetcher: chain, | ||
| P2P: p2p, | ||
| ProposerPreferencesCache: cache, | ||
| } | ||
|
|
||
| msg := ðpb.SignedProposerPreferences{ | ||
| Message: ðpb.ProposerPreferences{ | ||
| ProposalSlot: proposalSlot, | ||
| ValidatorIndex: 2, | ||
| FeeRecipient: make([]byte, 20), | ||
| GasLimit: 30_000_000, | ||
| }, | ||
| Signature: make([]byte, 96), | ||
| } | ||
|
|
||
| resp, err := vs.SubmitSignedProposerPreferences(t.Context(), msg) | ||
| require.NoError(t, err) | ||
| require.DeepEqual(t, &emptypb.Empty{}, resp) | ||
| assert.Equal(t, true, p2p.BroadcastCalled.Load()) | ||
| pref, ok := cache.Get(proposalSlot) | ||
| require.Equal(t, true, ok) | ||
| require.DeepEqual(t, msg.Message.FeeRecipient, pref.FeeRecipient) | ||
| require.Equal(t, msg.Message.GasLimit, pref.GasLimit) | ||
| } | ||
|
|
||
| func TestSubmitSignedProposerPreferences_DuplicateSlot(t *testing.T) { | ||
| params.SetupTestConfigCleanup(t) | ||
| cfg := params.BeaconConfig().Copy() | ||
| cfg.GloasForkEpoch = 1 | ||
| params.OverrideBeaconConfig(cfg) | ||
|
|
||
| currentSlot := primitives.Slot(31) | ||
| proposalSlot := currentSlot + 1 | ||
| chain := &chainMock.ChainService{Slot: ¤tSlot} | ||
| p2p := &p2pmock.MockBroadcaster{} | ||
| c := cache.NewProposerPreferencesCache() | ||
| c.Add(proposalSlot, make([]byte, 20), 30_000_000) | ||
| vs := &Server{ | ||
| SyncChecker: &mockSync.Sync{IsSyncing: false}, | ||
| TimeFetcher: chain, | ||
| P2P: p2p, | ||
| ProposerPreferencesCache: c, | ||
| } | ||
|
|
||
| msg := ðpb.SignedProposerPreferences{ | ||
| Message: ðpb.ProposerPreferences{ | ||
| ProposalSlot: proposalSlot, | ||
| ValidatorIndex: 2, | ||
| FeeRecipient: make([]byte, 20), | ||
| GasLimit: 30_000_000, | ||
| }, | ||
| Signature: make([]byte, 96), | ||
| } | ||
|
|
||
| resp, err := vs.SubmitSignedProposerPreferences(t.Context(), msg) | ||
| require.NoError(t, err) | ||
| require.DeepEqual(t, &emptypb.Empty{}, resp) | ||
| assert.Equal(t, false, p2p.BroadcastCalled.Load()) | ||
| } | ||
|
|
||
| func TestSubmitSignedProposerPreferences_InvalidEpoch(t *testing.T) { | ||
| params.SetupTestConfigCleanup(t) | ||
| cfg := params.BeaconConfig().Copy() | ||
| cfg.GloasForkEpoch = 1 | ||
| params.OverrideBeaconConfig(cfg) | ||
|
|
||
| currentSlot := primitives.Slot(31) | ||
| chain := &chainMock.ChainService{Slot: ¤tSlot} | ||
| vs := &Server{ | ||
| SyncChecker: &mockSync.Sync{IsSyncing: false}, | ||
| TimeFetcher: chain, | ||
| P2P: &p2pmock.MockBroadcaster{}, | ||
| ProposerPreferencesCache: cache.NewProposerPreferencesCache(), | ||
| } | ||
|
|
||
| // Same epoch (current), not next epoch. | ||
| msg := ðpb.SignedProposerPreferences{ | ||
| Message: ðpb.ProposerPreferences{ | ||
| ProposalSlot: currentSlot, | ||
| ValidatorIndex: 2, | ||
| FeeRecipient: make([]byte, 20), | ||
| GasLimit: 30_000_000, | ||
| }, | ||
| Signature: make([]byte, 96), | ||
| } | ||
| _, err := vs.SubmitSignedProposerPreferences(t.Context(), msg) | ||
| require.ErrorContains(t, "next epoch", err) | ||
|
|
||
| // Two epochs ahead. | ||
| msg.Message.ProposalSlot = currentSlot + primitives.Slot(2*params.BeaconConfig().SlotsPerEpoch) | ||
| _, err = vs.SubmitSignedProposerPreferences(t.Context(), msg) | ||
| require.ErrorContains(t, "next epoch", err) | ||
| } | ||
|
|
||
| func TestSubmitSignedProposerPreferences_Syncing(t *testing.T) { | ||
| params.SetupTestConfigCleanup(t) | ||
| cfg := params.BeaconConfig().Copy() | ||
| cfg.GloasForkEpoch = 1 | ||
| params.OverrideBeaconConfig(cfg) | ||
|
|
||
| currentSlot := primitives.Slot(31) | ||
| chain := &chainMock.ChainService{Slot: ¤tSlot} | ||
| vs := &Server{ | ||
| SyncChecker: &mockSync.Sync{IsSyncing: true}, | ||
| TimeFetcher: chain, | ||
| P2P: &p2pmock.MockBroadcaster{}, | ||
| ProposerPreferencesCache: cache.NewProposerPreferencesCache(), | ||
| } | ||
|
|
||
| msg := ðpb.SignedProposerPreferences{ | ||
| Message: ðpb.ProposerPreferences{ | ||
| ProposalSlot: currentSlot + 1, | ||
| ValidatorIndex: 2, | ||
| FeeRecipient: make([]byte, 20), | ||
| GasLimit: 30_000_000, | ||
| }, | ||
| Signature: make([]byte, 96), | ||
| } | ||
|
|
||
| _, err := vs.SubmitSignedProposerPreferences(t.Context(), msg) | ||
| require.ErrorContains(t, "not ready to respond", err) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ### Added | ||
|
|
||
| - Add gRPC endpoint `SubmitSignedProposerPreferences` for validators to broadcast proposer preferences |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the intended use only for the next epoch? if you restart your validator client and it needs to propose in the epoch it restarted on this would fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2P will ignore it anyway so it's better to know that with an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will bring up this concern again ethereum/consensus-specs#4777 (comment)