Skip to content

Commit

Permalink
fix sql insert block value
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonche committed Jun 25, 2024
1 parent 851d91e commit b8a03e4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
9 changes: 4 additions & 5 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ func (s *DatabaseService) prepareNamedQueries() (err error) {

// Insert block builder submission
query = `INSERT INTO ` + vars.TableBuilderBlockSubmission + `
(received_at, eligible_at, execution_payload_id, was_simulated, sim_success, sim_error, sim_req_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, :was_simulated, :sim_success, :sim_error, :sim_req_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, was_simulated, sim_success, sim_error, sim_req_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, block_value) VALUES
(:received_at, :eligible_at, :execution_payload_id, :was_simulated, :sim_success, :sim_error, :sim_req_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, :block_value)
RETURNING id`
s.nstmtInsertBlockBuilderSubmission, err = s.DB.PrepareNamed(query)
return err
Expand Down Expand Up @@ -205,7 +205,6 @@ func (s *DatabaseService) SaveBuilderBlockSubmission(payload *common.VersionedSu
if blockValue != nil {
blockValueStr = blockValue.Dec()
}

submission, err := common.GetBlockSubmissionInfo(payload)
if err != nil {
return nil, err
Expand All @@ -220,7 +219,7 @@ func (s *DatabaseService) SaveBuilderBlockSubmission(payload *common.VersionedSu
SimSuccess: wasSimulated && validationError == nil,
SimError: simErrStr,
SimReqError: requestErrStr,
BlockValue: blockValueStr,
BlockValue: NewNullString(blockValueStr),

Signature: submission.Signature.String(),

Expand Down Expand Up @@ -410,7 +409,7 @@ func (s *DatabaseService) GetBuilderSubmissions(filters GetBuilderSubmissionsFil
"builder_pubkey": filters.BuilderPubkey,
}

fields := "id, inserted_at, received_at, eligible_at, slot, epoch, builder_pubkey, proposer_pubkey, proposer_fee_recipient, parent_hash, block_hash, block_number, num_tx, value, gas_used, gas_limit, optimistic_submission"
fields := "id, inserted_at, received_at, eligible_at, slot, epoch, builder_pubkey, proposer_pubkey, proposer_fee_recipient, parent_hash, block_hash, block_number, num_tx, value, gas_used, gas_limit, optimistic_submission, block_value"
limit := "LIMIT :limit"

whereConds := []string{
Expand Down
5 changes: 4 additions & 1 deletion database/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const (
slot = uint64(42)
collateral = 1000
collateralStr = "1000"
blockValue = 1234
blockValueStr = "1234"
builderID = "builder0x69"
randao = "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"
optimisticSubmission = true
Expand Down Expand Up @@ -88,7 +90,7 @@ func insertTestBuilder(t *testing.T, db IDatabaseService) string {
Value: uint256.NewInt(collateral),
},
}, spec.DataVersionDeneb)
entry, err := db.SaveBuilderBlockSubmission(req, nil, nil, time.Now(), time.Now().Add(time.Second), true, true, profile, optimisticSubmission, nil)
entry, err := db.SaveBuilderBlockSubmission(req, nil, nil, time.Now(), time.Now().Add(time.Second), true, true, profile, optimisticSubmission, uint256.NewInt(blockValue))
require.NoError(t, err)
err = db.UpsertBlockBuilderEntryAfterSubmission(entry, false)
require.NoError(t, err)
Expand Down Expand Up @@ -450,6 +452,7 @@ func TestGetBuilderSubmissions(t *testing.T) {
require.Equal(t, pubkey, e.BuilderPubkey)
require.Equal(t, feeRecipient.String(), e.ProposerFeeRecipient)
require.Equal(t, strconv.Itoa(collateral), e.Value)
require.Equal(t, NewNullString(blockHashStr), e.BlockValue)
}

func TestUpsertTooLateGetPayload(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions database/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ type BuilderBlockSubmissionEntry struct {
ExecutionPayloadID sql.NullInt64 `db:"execution_payload_id"`

// Sim Result
WasSimulated bool `db:"was_simulated"`
SimSuccess bool `db:"sim_success"`
SimError string `db:"sim_error"`
SimReqError string `db:"sim_req_error"`
BlockValue string `db:"block_value"`
WasSimulated bool `db:"was_simulated"`
SimSuccess bool `db:"sim_success"`
SimError string `db:"sim_error"`
SimReqError string `db:"sim_req_error"`
BlockValue sql.NullString `db:"block_value"`

// BidTrace data
Signature string `db:"signature"`
Expand Down

0 comments on commit b8a03e4

Please sign in to comment.