Skip to content

Commit 2cd69fa

Browse files
authored
fix: event-replay block parsing outdated and incorrect (#2133)
* fix: event-replay block parsing outdated and incorrect * fix: use total block costs from `/new_block` message instead of calculating manually * chore: remove outdated test * chore: fix tests
1 parent c389154 commit 2cd69fa

File tree

8 files changed

+1127
-381
lines changed

8 files changed

+1127
-381
lines changed

src/datastore/helpers.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,43 +1283,6 @@ export function convertTxQueryResultToDbMempoolTx(txs: TxQueryResult[]): DbMempo
12831283
return dbMempoolTxs;
12841284
}
12851285

1286-
export function setTotalBlockUpdateDataExecutionCost(data: DataStoreBlockUpdateData) {
1287-
const cost = data.txs.reduce(
1288-
(previousValue, currentValue) => {
1289-
const {
1290-
execution_cost_read_count,
1291-
execution_cost_read_length,
1292-
execution_cost_runtime,
1293-
execution_cost_write_count,
1294-
execution_cost_write_length,
1295-
} = previousValue;
1296-
return {
1297-
execution_cost_read_count:
1298-
execution_cost_read_count + currentValue.tx.execution_cost_read_count,
1299-
execution_cost_read_length:
1300-
execution_cost_read_length + currentValue.tx.execution_cost_read_length,
1301-
execution_cost_runtime: execution_cost_runtime + currentValue.tx.execution_cost_runtime,
1302-
execution_cost_write_count:
1303-
execution_cost_write_count + currentValue.tx.execution_cost_write_count,
1304-
execution_cost_write_length:
1305-
execution_cost_write_length + currentValue.tx.execution_cost_write_length,
1306-
};
1307-
},
1308-
{
1309-
execution_cost_read_count: 0,
1310-
execution_cost_read_length: 0,
1311-
execution_cost_runtime: 0,
1312-
execution_cost_write_count: 0,
1313-
execution_cost_write_length: 0,
1314-
}
1315-
);
1316-
data.block.execution_cost_read_count = cost.execution_cost_read_count;
1317-
data.block.execution_cost_read_length = cost.execution_cost_read_length;
1318-
data.block.execution_cost_runtime = cost.execution_cost_runtime;
1319-
data.block.execution_cost_write_count = cost.execution_cost_write_count;
1320-
data.block.execution_cost_write_length = cost.execution_cost_write_length;
1321-
}
1322-
13231286
export function markBlockUpdateDataAsNonCanonical(data: DataStoreBlockUpdateData): void {
13241287
data.block = { ...data.block, canonical: false };
13251288
data.microblocks = data.microblocks.map(mb => ({ ...mb, canonical: false }));

src/datastore/pg-write-store.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ import {
6666
} from './common';
6767
import {
6868
BLOCK_COLUMNS,
69-
setTotalBlockUpdateDataExecutionCost,
7069
convertTxQueryResultToDbMempoolTx,
7170
markBlockUpdateDataAsNonCanonical,
7271
MICROBLOCK_COLUMNS,
@@ -210,7 +209,6 @@ export class PgWriteStore extends PgStore {
210209
}));
211210
await this.pruneMempoolTxs(sql, prunableTxs);
212211
}
213-
setTotalBlockUpdateDataExecutionCost(data);
214212

215213
// Insert microblocks, if any. Clear already inserted microblock txs from the anchor-block
216214
// update data to avoid duplicate inserts.

src/event-replay/parquet-based/importers/new-block-importer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ const populateBatchInserters = (db: PgWriteStore) => {
160160
write: async (data: CoreNodeBlockMessage, _encoding, next) => {
161161
let dbData: DataStoreBlockUpdateData;
162162
try {
163-
dbData = parseNewBlockMessage(chainID, data);
163+
({ dbData } = parseNewBlockMessage(chainID, data, true));
164164
} catch (err) {
165165
logger.error({ component: 'event-replay' }, 'Error when parsing new_block event');
166166
console.error(err);

src/event-stream/core-node-message.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ export interface CoreNodeBlockMessage {
301301
/** String quoted micro-STX amount. */
302302
tx_fees_streamed_produced: string;
303303
}[];
304+
anchored_cost?: CoreNodeExecutionCostMessage;
305+
confirmed_microblocks_cost?: CoreNodeExecutionCostMessage;
304306
pox_v1_unlock_height?: number;
305307
pox_v2_unlock_height?: number;
306308
pox_v3_unlock_height?: number;

0 commit comments

Comments
 (0)