mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Push proposer settings every slot (#14155)
* test push settings every slot * updating comments * changing design a little bit based on feedback * adding corrected deadline
This commit is contained in:
@@ -63,11 +63,7 @@ func run(ctx context.Context, v iface.Validator) {
|
||||
}
|
||||
deadline := time.Now().Add(5 * time.Minute)
|
||||
if err := v.PushProposerSettings(ctx, km, headSlot, deadline); err != nil {
|
||||
if errors.Is(err, ErrBuilderValidatorRegistration) {
|
||||
log.WithError(err).Warn("Push proposer settings error")
|
||||
} else {
|
||||
log.WithError(err).Fatal("Failed to update proposer settings") // allow fatal. skipcq
|
||||
}
|
||||
log.WithError(err).Fatal("Failed to update proposer settings") // allow fatal. skipcq
|
||||
}
|
||||
for {
|
||||
ctx, span := trace.StartSpan(ctx, "validator.processSlot")
|
||||
@@ -98,16 +94,11 @@ func run(ctx context.Context, v iface.Validator) {
|
||||
continue
|
||||
}
|
||||
|
||||
// call push proposer setting at the start of each epoch to account for the following edge case:
|
||||
// call push proposer settings often to account for the following edge cases:
|
||||
// proposer is activated at the start of epoch and tries to propose immediately
|
||||
if slots.IsEpochStart(slot) {
|
||||
go func() {
|
||||
// deadline set for 1 epoch from call to not overlap.
|
||||
epochDeadline := v.SlotDeadline(slot + params.BeaconConfig().SlotsPerEpoch - 1)
|
||||
if err := v.PushProposerSettings(ctx, km, slot, epochDeadline); err != nil {
|
||||
log.WithError(err).Warn("Failed to update proposer settings")
|
||||
}
|
||||
}()
|
||||
// account has changed in the middle of an epoch
|
||||
if err := v.PushProposerSettings(ctx, km, slot, deadline); err != nil {
|
||||
log.WithError(err).Warn("Failed to update proposer settings")
|
||||
}
|
||||
|
||||
// Start fetching domain data for the next epoch.
|
||||
|
||||
@@ -370,37 +370,3 @@ func TestUpdateProposerSettingsAt_EpochEndOk(t *testing.T) {
|
||||
// can't test "Failed to update proposer settings" because of log.fatal
|
||||
assert.LogsContain(t, hook, "Mock updated proposer settings")
|
||||
}
|
||||
|
||||
func TestUpdateProposerSettings_ContinuesAfterValidatorRegistrationFails(t *testing.T) {
|
||||
errSomeOtherError := errors.New("some internal error")
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
node := healthTesting.NewMockHealthClient(ctrl)
|
||||
tracker := beacon.NewNodeHealthTracker(node)
|
||||
node.EXPECT().IsHealthy(gomock.Any()).Return(true).AnyTimes()
|
||||
v := &testutil.FakeValidator{
|
||||
ProposerSettingsErr: errors.Wrap(ErrBuilderValidatorRegistration, errSomeOtherError.Error()),
|
||||
Km: &mockKeymanager{accountsChangedFeed: &event.Feed{}},
|
||||
Tracker: tracker,
|
||||
}
|
||||
err := v.SetProposerSettings(context.Background(), &proposer.Settings{
|
||||
DefaultConfig: &proposer.Option{
|
||||
FeeRecipientConfig: &proposer.FeeRecipientConfig{
|
||||
FeeRecipient: common.HexToAddress("0x046Fb65722E7b2455012BFEBf6177F1D2e9738D9"),
|
||||
},
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
hook := logTest.NewGlobal()
|
||||
slot := params.BeaconConfig().SlotsPerEpoch
|
||||
ticker := make(chan primitives.Slot)
|
||||
v.NextSlotRet = ticker
|
||||
go func() {
|
||||
ticker <- slot
|
||||
|
||||
cancel()
|
||||
}()
|
||||
run(ctx, v)
|
||||
assert.LogsContain(t, hook, ErrBuilderValidatorRegistration.Error())
|
||||
}
|
||||
|
||||
@@ -1125,6 +1125,7 @@ func (v *validator) PushProposerSettings(ctx context.Context, km keymanager.IKey
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
proposerReqs, err := v.buildPrepProposerReqs(filteredKeys)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1139,16 +1140,21 @@ func (v *validator) PushProposerSettings(ctx context.Context, km keymanager.IKey
|
||||
"proposerSettingsRequestCount": len(proposerReqs),
|
||||
}).Debugln("Request count did not match included validator count. Only keys that have been activated will be included in the request.")
|
||||
}
|
||||
|
||||
if _, err := v.validatorClient.PrepareBeaconProposer(ctx, ðpb.PrepareBeaconProposerRequest{
|
||||
Recipients: proposerReqs,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
signedRegReqs := v.buildSignedRegReqs(ctx, filteredKeys, km.Sign)
|
||||
if err := SubmitValidatorRegistrations(ctx, v.validatorClient, signedRegReqs, v.validatorsRegBatchSize); err != nil {
|
||||
return errors.Wrap(ErrBuilderValidatorRegistration, err.Error())
|
||||
if len(signedRegReqs) > 0 {
|
||||
go func() {
|
||||
if err := SubmitValidatorRegistrations(ctx, v.validatorClient, signedRegReqs, v.validatorsRegBatchSize); err != nil {
|
||||
log.WithError(errors.Wrap(ErrBuilderValidatorRegistration, err.Error())).Warn("failed to register validator on builder")
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1477,6 +1477,7 @@ func TestValidator_PushSettings(t *testing.T) {
|
||||
feeRecipientMap map[primitives.ValidatorIndex]string
|
||||
mockExpectedRequests []ExpectedValidatorRegistration
|
||||
err string
|
||||
logDelay time.Duration
|
||||
logMessages []string
|
||||
doesntContainLogs bool
|
||||
}{
|
||||
@@ -1993,7 +1994,8 @@ func TestValidator_PushSettings(t *testing.T) {
|
||||
).Return(&empty.Empty{}, errors.New("request failed"))
|
||||
return &v
|
||||
},
|
||||
err: "could not submit signed registrations to beacon node",
|
||||
logMessages: []string{"request failed"},
|
||||
logDelay: 1 * time.Second,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@@ -2030,6 +2032,9 @@ func TestValidator_PushSettings(t *testing.T) {
|
||||
assert.ErrorContains(t, tt.err, err)
|
||||
}
|
||||
if len(tt.logMessages) > 0 {
|
||||
if tt.logDelay > 0 {
|
||||
time.Sleep(tt.logDelay)
|
||||
}
|
||||
for _, message := range tt.logMessages {
|
||||
if tt.doesntContainLogs {
|
||||
assert.LogsDoNotContain(t, hook, message)
|
||||
|
||||
Reference in New Issue
Block a user