Skip to content
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

init commit optimistic relay #1

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e57024c
init commit optimistic relay
michaelneuder Dec 29, 2022
95e937a
optimistic relay updates
michaelneuder Dec 31, 2022
e666a4b
db updates
michaelneuder Dec 31, 2022
26ad103
flow (c) update database with new table to persist refunds
michaelneuder Dec 31, 2022
3dddf4b
adding collateral check and DB field
michaelneuder Jan 2, 2023
e7aa032
remove db update
michaelneuder Jan 2, 2023
234ff04
add block builder demotion in the case of a simulation error after a …
michaelneuder Jan 2, 2023
c36ef85
comments from Justin
michaelneuder Jan 2, 2023
8379b4e
adding signedValidatorRegistration to the refund table
michaelneuder Jan 2, 2023
442a7bf
normalize usage of BuilderStatus and builder_status instead of Builde…
michaelneuder Jan 2, 2023
c04edc8
rename refund to demotion
michaelneuder Jan 4, 2023
66b14f7
s/TableBuidlerDemotions/TableBuilderDemotions/g
michaelneuder Jan 4, 2023
6bb8bf3
normalizing use of builder instead of block builder except in the cas…
michaelneuder Jan 4, 2023
3a37075
collateral id and demotions
michaelneuder Jan 4, 2023
cae6c95
replacing $3 with $2 in SetBlockBuilderStatus
michaelneuder Jan 4, 2023
d9845af
unit test initial pass
michaelneuder Jan 5, 2023
fe81a12
remove bad test
michaelneuder Jan 5, 2023
8267845
Justin's comments round 2
michaelneuder Jan 5, 2023
ac4aaa2
Unit testing block simulation path
michaelneuder Jan 7, 2023
def09c6
unit test get payload optimistic
michaelneuder Jan 8, 2023
6692741
save full request from builder to justify demotion
michaelneuder Jan 8, 2023
a2c9662
temporarily set optimistic builders as high-prio if the winning block…
michaelneuder Jan 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 41 additions & 19 deletions services/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ func (api *RelayAPI) startOptimisticBlockProcessor() {
for opts := range api.optimisticBlockC {
err := api.simulateBlock(opts)
if err != nil {
api.log.WithError(err).Error("block simualtion failed")
// Validation failed, mark the status of the builder as lowPrio (pessemistic).
newStatus := datastore.MakeBlockBuilderStatus(common.LowPrio)
builderPubKey := opts.req.Message.BuilderPubkey.String()
Expand Down Expand Up @@ -888,26 +889,47 @@ func (api *RelayAPI) handleGetPayload(w http.ResponseWriter, req *http.Request)
log.WithError(err).Error("failed to increment builder-stats after getPayload")
}

simErr := api.simulateBlock(blockSimOptions{
ctx: req.Context(),
log: log,
highPrio: true, // manually set to true for these blocks.
req: &BuilderBlockValidationRequest{
BuilderSubmitBlockRequest: types.BuilderSubmitBlockRequest{
Signature: payload.Signature,
Message: &bidTrace.BidTrace,
ExecutionPayload: getPayloadResp.Data,
builderStatus, err := api.redis.GetBlockBuilderStatus(bidTrace.BuilderPubkey.String())
if err != nil {
log.WithError(err).Error("failed to get block builder status")
}

// Check if the block was valid in the optimistic case.
if builderStatus == common.Optimistic {
simErr := api.simulateBlock(blockSimOptions{
ctx: req.Context(),
log: log,
highPrio: true, // manually set to true for these blocks.
req: &BuilderBlockValidationRequest{
BuilderSubmitBlockRequest: types.BuilderSubmitBlockRequest{
Signature: payload.Signature,
Message: &bidTrace.BidTrace,
ExecutionPayload: getPayloadResp.Data,
},
},
},
})
if simErr != nil {
log.WithError(err).Error("failed to simulate signed block")
err = api.db.SaveValidatorRefund(bidTrace, payload)
if err != nil {
log.WithError(err).WithFields(logrus.Fields{
"bidTrace": bidTrace,
"signedBlindedBeaconBlock": payload,
}).Error("failed to save validator refund to database")
})
if simErr != nil {
log.WithError(err).Error("failed to simulate signed block")
err = api.db.SaveValidatorRefund(bidTrace, payload)
if err != nil {
log.WithError(err).WithFields(logrus.Fields{
"bidTrace": bidTrace,
"signedBlindedBeaconBlock": payload,
}).Error("failed to save validator refund to database")
}

// Validation failed, mark the status of the builder as lowPrio (pessemistic).
newStatus := datastore.MakeBlockBuilderStatus(common.LowPrio)
builderPubKey := bidTrace.BuilderPubkey.String()
err := api.redis.SetBlockBuilderStatus(builderPubKey, newStatus)
if err != nil {
api.log.WithError(err).Error("could not set block builder status in redis")
}

err = api.db.SetBlockBuilderStatus(builderPubKey, common.LowPrio)
if err != nil {
api.log.WithError(err).Error("could not set block builder status in database")
}
}
}
}()
Expand Down