Skip to content

metrics: incorrect write_time counter for insert_decided_block in store.rs #142

@ikwuoz

Description

@ikwuoz

fn insert_decided_block(
&self,
decided_block: DecidedBlock,
proposer: Address,
) -> Result<(), StoreError> {
let start = Instant::now();
let mut write_bytes = 0;
let height = decided_block.height();
let tx = self.db.begin_write()?;
{
let mut blocks = tx.open_table(DECIDED_BLOCKS_TABLE)?;
let block_bytes = encode_execution_payload(&decided_block.execution_payload);
#[allow(clippy::arithmetic_side_effects)]
{
write_bytes += block_bytes.len();
}
blocks.insert(height, block_bytes)?;
}
self.insert_certificate(
&tx,
decided_block.certificate,
CommitCertificateType::Minimal,
Some(proposer),
)?;
tx.commit()?;
self.update_write_metrics(write_bytes, start.elapsed());
Ok(())
}

In insert_decided_block above, start.elapsed() spans the entire function body including insert_certificate(), which itself calls update_write_metrics with its own internal timer, then:

  1. The write time in insert_decided_block is for block bytes, but it ends up including the write time for certificate bytes,
  2. However insert_certificate also reports its own write time internally.

Therefore, the certificate insertion time is double counted in the aggregated write_time metric because both calls accumulate into the same counter.

Impact: The write latency metric overstates actual DB write time by roughly one cert encoding + insert cycle per insert_decided_block call, causing metric inaccuracy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions