Skip to content

Commit

Permalink
Collecting two extra timestamps in the block lifecycle (flashbots#301)
Browse files Browse the repository at this point in the history
collecting two extra timestamps in the block lifecycle
  • Loading branch information
michaelneuder committed Mar 17, 2023
1 parent f3970ef commit f23b636
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ func (s *DatabaseService) prepareNamedQueries() (err error) {

// Insert block builder submission
query = `INSERT INTO ` + vars.TableBuilderBlockSubmission + `
(received_at, eligible_at, execution_payload_id, sim_success, sim_error, signature, slot, parent_hash, block_hash, builder_pubkey, proposer_pubkey, proposer_fee_recipient, gas_used, gas_limit, num_tx, value, epoch, block_number, decode_duration, prechecks_duration, simulation_duration, redis_update_duration, total_duration, optimistic_submission) VALUES
(:received_at, :eligible_at, :execution_payload_id, :sim_success, :sim_error, :signature, :slot, :parent_hash, :block_hash, :builder_pubkey, :proposer_pubkey, :proposer_fee_recipient, :gas_used, :gas_limit, :num_tx, :value, :epoch, :block_number, :decode_duration, :prechecks_duration, :simulation_duration, :redis_update_duration, :total_duration, :optimistic_submission)
(received_at, eligible_at, execution_payload_id, sim_success, sim_error, signature, slot, parent_hash, block_hash, builder_pubkey, proposer_pubkey, proposer_fee_recipient, gas_used, gas_limit, num_tx, value, epoch, block_number) VALUES
(:received_at, :eligible_at, :execution_payload_id, :sim_success, :sim_error, :signature, :slot, :parent_hash, :block_hash, :builder_pubkey, :proposer_pubkey, :proposer_fee_recipient, :gas_used, :gas_limit, :num_tx, :value, :epoch, :block_number)
RETURNING id`
s.nstmtInsertBlockBuilderSubmission, err = s.DB.PrepareNamed(query)
return err
Expand Down
18 changes: 18 additions & 0 deletions database/migrations/003_bid_add_eligibleat_payload_add_signedat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package migrations

import (
"github.com/flashbots/mev-boost-relay/database/vars"
migrate "github.com/rubenv/sql-migrate"
)

var Migration003AddEligibleAtSignedAt = &migrate.Migration{
Id: "003-add-eligibleat-add-signedat",
Up: []string{`
ALTER TABLE ` + vars.TableBuilderBlockSubmission + ` ADD eligible_at timestamp;
ALTER TABLE ` + vars.TableDeliveredPayload + ` ADD signed_at timestamp;
`},
Down: []string{},

DisableTransactionUp: true,
DisableTransactionDown: true,
}
2 changes: 1 addition & 1 deletion database/migrations/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ var Migrations = migrate.MemoryMigrationSource{
Migrations: []*migrate.Migration{
Migration001InitDatabase,
Migration002RemoveIsBestAddReceivedAt,
Migration003Optimistic,
Migration003AddEligibleAtSignedAt,
},
}
3 changes: 3 additions & 0 deletions services/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,9 @@ func (api *RelayAPI) handleGetPayload(w http.ResponseWriter, req *http.Request)
}
}

// Once the signature is verified, we know the proposer is committed to this bid.
signedAt := time.Now().UTC()

// Get the response - from memory, Redis or DB
// note that mev-boost might send getPayload for bids of other relays, thus this code wouldn't find anything
getPayloadResp, err := api.datastore.GetGetPayloadResponse(payload.Slot(), proposerPubkey.String(), payload.BlockHash())
Expand Down

0 comments on commit f23b636

Please sign in to comment.