Skip to content

Commit

Permalink
fix: use total block costs from /new_block message instead of calcu…
Browse files Browse the repository at this point in the history
…lating manually
  • Loading branch information
zone117x committed Oct 21, 2024
1 parent 68e1f15 commit 955b5c5
Show file tree
Hide file tree
Showing 3 changed files with 998 additions and 22 deletions.
2 changes: 2 additions & 0 deletions src/event-stream/core-node-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ export interface CoreNodeBlockMessage {
/** String quoted micro-STX amount. */
tx_fees_streamed_produced: string;
}[];
anchored_cost: CoreNodeExecutionCostMessage;
confirmed_microblocks_cost: CoreNodeExecutionCostMessage;
pox_v1_unlock_height?: number;
pox_v2_unlock_height?: number;
pox_v3_unlock_height?: number;
Expand Down
27 changes: 5 additions & 22 deletions src/event-stream/event-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -992,23 +992,6 @@ export function parseNewBlockMessage(
counts.events[event.type] += 1;
}

const executionCost = 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 signerBitvec = msg.signer_bitvec
? BitVec.consensusDeserializeToString(msg.signer_bitvec)
: null;
Expand All @@ -1030,11 +1013,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: executionCost.read_count,
execution_cost_read_length: executionCost.read_length,
execution_cost_runtime: executionCost.runtime,
execution_cost_write_count: executionCost.write_count,
execution_cost_write_length: executionCost.write_length,
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,
tx_count: msg.transactions.length,
block_time: blockData.block_time,
signer_bitvec: signerBitvec,
Expand Down
Loading

0 comments on commit 955b5c5

Please sign in to comment.