Skip to content

docs: emit header timestamp and nBits in BlockSubmitted (reminder) - #94

Draft
lsheva wants to merge 1 commit into
devfrom
chore/emit-header-fields-in-blocksubmitted
Draft

docs: emit header timestamp and nBits in BlockSubmitted (reminder)#94
lsheva wants to merge 1 commit into
devfrom
chore/emit-header-fields-in-blocksubmitted

Conversation

@lsheva

@lsheva lsheva commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Draft, left open as a reminder. Not scheduled — this should ride along with the next HashpriceBTC redeploy rather than justify one.

Why

The actual-hashrate estimate added in #93 needs the Bitcoin header timestamp and nBits per block. BlockSubmitted carries neither, so the mapping reads them back out of the 32-slot ring buffer with getBlockFromTip — one eth_call for the tip height plus one per non-tip block, ~288/day. Cheap, but it ties the mapping to an archive node and caps the submission depth the indexer can follow at 32 blocks.

Adding the two fields costs ~512 gas (both are already in memory at the emit site, so it is log data only — 64 bytes at 8 gas each, against a ~121k gas average submitBlock).

Why it is blocked

HashpriceBTC is immutable and HashpriceUSD.hashpriceOracle is immutable too, so this is a redeploy of both, plus a new checkpoint, consumer migration, oracle-abi bump, full subgraph resync, and a fresh 144-block fee SMA warmup. Not worth paying to remove two eth_calls.

The doc also records two things deliberately left off-chain: median time past (~23k gas/block for 11 ring-buffer reads, free in the mapping) and cumulative work (pure function of nBits).

Full reasoning and a checklist for when a redeploy does happen: .ai-docs/blocksubmitted-header-fields.md.

The indexer's actual-hashrate estimate reads the Bitcoin header timestamp and
nBits back out of the ring buffer with getBlockFromTip, because the event does
not carry them. Emitting them costs ~512 gas since both are already in memory
at the emit site, but the contract is immutable so it means a redeploy of both
HashpriceBTC and HashpriceUSD. Recording the reasoning so it can ride along
with the next redeploy rather than justifying one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants