Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zone117x committed Oct 21, 2024
1 parent 3b21538 commit 8f52303
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/event-stream/core-node-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ export interface CoreNodeBlockMessage {
/** String quoted micro-STX amount. */
tx_fees_streamed_produced: string;
}[];
anchored_cost: CoreNodeExecutionCostMessage;
confirmed_microblocks_cost: CoreNodeExecutionCostMessage;
anchored_cost?: CoreNodeExecutionCostMessage;
confirmed_microblocks_cost?: CoreNodeExecutionCostMessage;
pox_v1_unlock_height?: number;
pox_v2_unlock_height?: number;
pox_v3_unlock_height?: number;
Expand Down
30 changes: 25 additions & 5 deletions src/event-stream/event-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,26 @@ export function parseNewBlockMessage(
const signerSignatures =
msg.signer_signature?.map(s => (s.startsWith('0x') ? s : '0x' + s)) ?? null;

// `anchored_cost` is not available in very old versions of stacks-core
const execCost =
msg.anchored_cost ??
parsedTxs.reduce(
(acc, { core_tx: { execution_cost } }) => ({
read_count: acc.read_count + execution_cost.read_count,
read_length: acc.read_length + execution_cost.read_length,
runtime: acc.runtime + execution_cost.runtime,
write_count: acc.write_count + execution_cost.write_count,
write_length: acc.write_length + execution_cost.write_length,
}),
{
read_count: 0,
read_length: 0,
runtime: 0,
write_count: 0,
write_length: 0,
}
);

const dbBlock: DbBlock = {
canonical: true,
block_hash: msg.block_hash,
Expand All @@ -1013,11 +1033,11 @@ export function parseNewBlockMessage(
burn_block_hash: msg.burn_block_hash,
burn_block_height: msg.burn_block_height,
miner_txid: msg.miner_txid,
execution_cost_read_count: msg.anchored_cost.read_count,
execution_cost_read_length: msg.anchored_cost.read_length,
execution_cost_runtime: msg.anchored_cost.runtime,
execution_cost_write_count: msg.anchored_cost.write_count,
execution_cost_write_length: msg.anchored_cost.write_length,
execution_cost_read_count: execCost.read_count,
execution_cost_read_length: execCost.read_length,
execution_cost_runtime: execCost.runtime,
execution_cost_write_count: execCost.write_count,
execution_cost_write_length: execCost.write_length,
tx_count: msg.transactions.length,
block_time: blockData.block_time,
signer_bitvec: signerBitvec,
Expand Down

0 comments on commit 8f52303

Please sign in to comment.