A multi-role review of e733bad and 8e45d5f found five real defects, three of them
reproduced independently by more than one reviewer. All five were introduced by
those commits.
Reweighting stopped short of its fixed point
weighted_median_reference ran a hard-coded four passes. Raising the reference
only ever raises weights, so the chosen index climbs one position per pass and
a set spread over many decades never arrives: a ten-pool counterexample settled
on 411_155 against a true fixed point of 501_964, and random search found
spreads off by 81x. A wrong reference mis-sites the whole F=5 band. The loop now
runs until it converges, bounded by the pool count, which is sufficient because
the pick never revisits a position.
A stale materialised bucket shadowed newer legs
fetch_last_close_before consulted ohlcv_1h first and returned on any hit. That
table is structurally at least three hours behind the tip and is empty for the
whole of a post-version-bump rebuild, so the seed was routinely far older than
the real last print -- reproduced returning 10.0 where the last print was 50.0.
Fixing "unbounded lookback" in e733bad had removed the upper bound along with
the lower one. The lookup is now anchored to the hour containing the token's
most recent activity.
...and could return a price from after the instant asked about
The same query took any bucket with bucket_ts < timestamp_end, so a
non-hour-aligned cutoff could land on a bucket straddling it and return a close
set later than the requested time. The predecessor was hour-aligned precisely to
prevent this.
Skipping unpriceable buckets discarded their volume
Dropping the row avoided the f64 sentinels but took volume_sats, volume_tokens
and tx_count with it, so the materialised path reported zero volume for hours
the raw path reported in full. The guard makes those hours ordinary rather than
exotic -- one manipulation burst can fill a whole bucket, and muting every leg
in it then erased the hour. Such buckets are now written flat at the carried
close. This also stops get_max_bucket_ts regressing, which had let the
background sweep re-seed already-scanned ranges under a different snapshot.
The rebuild seeded from unconfirmed reserves
rebuild_range folds only legs with tx.blockhash IS NOT NULL, but the snapshot
had no such filter and effective_timestamp is populated for mempool rows. A
broadcast-but-unmined trade could therefore set the reference for a whole batch,
making materialised output a function of mempool contents at rebuild time and
freezing it via INSERT OR IGNORE. fetch_reserve_snapshot now takes
confirmed_only, set by the rebuild and clear on the live query paths.
Tests. Six mutation tests confirm each new regression test fails against the
specific defect it names. The review also found four of e733bad's tests vacuous
under mutation -- passing with the dust floor deleted, with min-depth weighting
disabled, and under the exact integer-division rounding they were named for. Those
are rewritten to be falsifiable, and the tier-2 self-qualification gap now has a
test documenting it.
Corrections to earlier commit messages in this branch. e733bad claimed every fix
carried a test "confirmed to fail against the old code"; only two of them were
drop-in regression tests, the rest exercise APIs that did not exist before it.
e733bad's "~1125 resets per token" should read once per batch in which the token
traded, and contradicts d961a5f's "~700" for the same span. 8e45d5f overstated its
reach: excluding pools withdrawn before the snapshot instant does not address the
OLA case, where the withdrawal lands mid-window -- that still needs the unbuilt
withdrawal-event synthesis.
Known gap, unchanged and now under test: tier 2 compares a pool's credit against a
share of the largest credit, so the deepest pool clears a share of itself and any
single-pool token is unguarded. This predates these commits and awaits a decision
on the rule.
OHLCV_VERSION 4 -> 5, and the version-4 changelog entry corrected: it named two of
the six behaviour changes that version actually carried.
Tests: 244 passing
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
RiftenLabs indexer is for indexing DeFi contracts by Riften Labs. It allows
for querying historical on-chain data on Bitcoin Cash.
Contributing
All contributors are required to sign a Contributor License Agreement (CLA)
before their contributions can be merged into the project.
Contributions are generally welcome. If you intend to make larger changes please
discuss them in an issue before MRing them to avoid duplicate work and
architectural mismatches.
Installing Rust
Rust can be installed using your package manager of choice or
rustup.rs. The former way is considered more secure since
it typically doesn't involve trust in the CA system. But you should be aware
that the version of Rust shipped by your distribution might be out of date.