Backend indexer for Riften Labs BCH DeFi contracts (Cauldron, Moria). Mirror of gitlab.com/riftenlabs/riftenlabs-indexer (AGPL-3.0). Author: Riften Labs.
Find a file
jakobsn 0eef3ecd7c Fix five defects found reviewing the previous two commits
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>
2026-07-29 20:39:14 +02:00
.vscode Convert hash columns from TEXT to BLOB storage 2026-01-22 08:30:17 +01:00
contrib Delphi v2 support 2026-05-04 15:03:40 +02:00
internal Expose authchain head + optional local IPFS gateway for BCMR downloads 2026-06-24 11:07:31 +00:00
linters Fix potential API hangs from write lock contention 2026-02-02 21:01:50 +01:00
src Fix five defects found reviewing the previous two commits 2026-07-29 20:39:14 +02:00
.gitignore Add Chipnet support 2026-01-09 13:46:58 +01:00
.gitlab-ci.yml ci: Use lockfile as cache key 2026-02-02 11:52:09 +01:00
build.rs missing build file 2024-10-25 15:28:40 +02:00
Cargo.lock ido: replace num-bigint with malachite 2026-06-22 10:41:39 +00:00
Cargo.toml ido: replace num-bigint with malachite 2026-06-22 10:41:39 +00:00
LICENSE use AGPL 2024-02-05 16:32:27 +01:00
README.md README: contributors license 2024-03-14 10:54:44 +01:00

Riftenlabs Indexer

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.

Building

The library can be built and tested using cargo:

git clone https://gitlab.com/riftenlabs/riftenlabs-indexer.git
cd riftenlabs-indexer
cargo build

You can run tests with:

cargo test