Skip to content

Commit

Permalink
add effective height back to query
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaytonNorthey92 committed Dec 23, 2024
1 parent fba541c commit f715482
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions database/bfgd/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (
)

const effectiveHeightSql = `
SELECT COALESCE((SELECT height
COALESCE((SELECT height
FROM
(
Expand Down Expand Up @@ -547,17 +547,6 @@ func (p *pgdb) PopBasisByL2KeystoneAbrevHash(ctx context.Context, aHash [32]byte
return pbs, nil
}

func (p *pgdb) attachEffectiveHeight(ctx context.Context, finalities []bfgd.L2BTCFinality) error {
for i := range finalities {
row := p.db.QueryRowContext(ctx, effectiveHeightSql, finalities[i].L2Keystone.L2BlockNumber)
if err := row.Scan(&finalities[i].EffectiveHeight); err != nil {
return err
}
}

return nil
}

// L2BTCFinalityMostRecent gets the most recent L2BtcFinalities sorted
// descending by l2_block_number
func (p *pgdb) L2BTCFinalityMostRecent(ctx context.Context, limit uint32) ([]bfgd.L2BTCFinality, error) {
Expand Down Expand Up @@ -633,6 +622,7 @@ func (p *pgdb) L2BTCFinalityByL2KeystoneAbrevHash(ctx context.Context, l2Keyston
l2_keystones.state_root,
l2_keystones.ep_hash,
l2_keystones.version,
%s,
COALESCE((SELECT height FROM btc_blocks_can ORDER BY height DESC LIMIT 1),0)
FROM l2_keystones
Expand All @@ -652,7 +642,7 @@ func (p *pgdb) L2BTCFinalityByL2KeystoneAbrevHash(ctx context.Context, l2Keyston
OFFSET $2
LIMIT $3
`)
`, effectiveHeightSql)

l2KeystoneAbrevHashesStr := [][]byte{}
for _, l := range l2KeystoneAbrevHashes {
Expand Down Expand Up @@ -681,6 +671,7 @@ func (p *pgdb) L2BTCFinalityByL2KeystoneAbrevHash(ctx context.Context, l2Keyston
&l2BtcFinality.L2Keystone.StateRoot,
&l2BtcFinality.L2Keystone.EPHash,
&l2BtcFinality.L2Keystone.Version,
&l2BtcFinality.EffectiveHeight,
&l2BtcFinality.BTCTipHeight,
)
if err != nil {
Expand All @@ -697,12 +688,6 @@ func (p *pgdb) L2BTCFinalityByL2KeystoneAbrevHash(ctx context.Context, l2Keyston
return nil, rows.Err()
}

rows.Close() // can be called more than once

if err := p.attachEffectiveHeight(ctx, finalities); err != nil {
return nil, err
}

return finalities, nil
}

Expand Down

0 comments on commit f715482

Please sign in to comment.