@@ -63,12 +63,12 @@ export class PgStore extends BasePgStore {
63
63
// they differ from the existing values. Return true if the row was updated, false otherwise.
64
64
// Should only update the row if the values are null (i.e. the first time the values are set).
65
65
const updateResult = await this . sql `
66
- UPDATE chain_tip
67
- SET
66
+ UPDATE chain_tip
67
+ SET
68
68
first_burnchain_block_height = ${ poxInfo . first_burnchain_block_height } ,
69
69
reward_cycle_length = ${ poxInfo . reward_cycle_length }
70
70
WHERE
71
- first_burnchain_block_height IS DISTINCT FROM ${ poxInfo . first_burnchain_block_height }
71
+ first_burnchain_block_height IS DISTINCT FROM ${ poxInfo . first_burnchain_block_height }
72
72
OR reward_cycle_length IS DISTINCT FROM ${ poxInfo . reward_cycle_length }
73
73
` ;
74
74
return { rowUpdated : updateResult . count > 0 } ;
@@ -149,8 +149,13 @@ export class PgStore extends BasePgStore {
149
149
} [ ]
150
150
> `
151
151
WITH latest_blocks AS (
152
- SELECT * FROM blocks
153
- ORDER BY block_height DESC
152
+ SELECT
153
+ b.*,
154
+ ct.block_height AS chain_tip_block_height,
155
+ (b.burn_block_height - ct.first_burnchain_block_height) / ct.reward_cycle_length AS cycle_number
156
+ FROM blocks b
157
+ CROSS JOIN chain_tip ct
158
+ ORDER BY b.block_height DESC
154
159
LIMIT ${ limit }
155
160
OFFSET ${ offset }
156
161
),
@@ -172,7 +177,7 @@ export class PgStore extends BasePgStore {
172
177
lb.block_hash,
173
178
lb.index_block_hash,
174
179
lb.burn_block_height,
175
- bp .cycle_number,
180
+ lb .cycle_number,
176
181
bp.received_at AS block_proposal_time_ms,
177
182
rs.signer_key,
178
183
COALESCE(rs.signer_weight, 0) AS signer_weight,
@@ -186,7 +191,7 @@ export class PgStore extends BasePgStore {
186
191
EXTRACT(MILLISECOND FROM (fbr.received_at - bp.received_at)) AS response_time_ms
187
192
FROM latest_blocks lb
188
193
LEFT JOIN filtered_block_proposals bp ON lb.block_hash = bp.block_hash
189
- LEFT JOIN reward_set_signers rs ON bp .cycle_number = rs.cycle_number
194
+ LEFT JOIN reward_set_signers rs ON lb .cycle_number = rs.cycle_number
190
195
LEFT JOIN block_signer_signatures bss ON lb.block_height = bss.block_height AND rs.signer_key = bss.signer_key
191
196
LEFT JOIN filtered_block_responses fbr ON fbr.signer_key = rs.signer_key AND fbr.signer_sighash = lb.block_hash
192
197
),
@@ -219,7 +224,8 @@ export class PgStore extends BasePgStore {
219
224
lb.burn_block_height,
220
225
lb.tenure_height,
221
226
EXTRACT(EPOCH FROM lb.block_time)::integer AS block_time,
222
- bsa.cycle_number,
227
+ lb.cycle_number,
228
+ lb.chain_tip_block_height,
223
229
(EXTRACT(EPOCH FROM bsa.block_proposal_time_ms) * 1000)::bigint AS block_proposal_time_ms,
224
230
bsa.total_signer_count::integer,
225
231
bsa.signer_accepted_mined_count::integer,
@@ -234,11 +240,9 @@ export class PgStore extends BasePgStore {
234
240
bsa.accepted_mined_weight::integer,
235
241
bsa.accepted_excluded_weight::integer,
236
242
bsa.rejected_weight::integer,
237
- bsa.missing_weight::integer,
238
- ct.block_height AS chain_tip_block_height
243
+ bsa.missing_weight::integer
239
244
FROM latest_blocks lb
240
245
JOIN signer_state_aggregation bsa ON lb.id = bsa.block_id
241
- CROSS JOIN chain_tip ct
242
246
ORDER BY lb.block_height DESC
243
247
` ;
244
248
return result ;
0 commit comments