Skip to content

Commit f8ae20c

Browse files
authored
fix: pindexer: don't index candles with NaN (#5251)
## Describe your changes This skips indexing candles with a price of NaN, at the source where we ingest point candles, representing a single trace input and output value. For some reason, the dex sometimes produces candles with 0 input and 0 output volume, resulting in a NaN, which then pollutes and corrupts other data. This fix addresses the source of the pollution in indexing. We should investigate why these traces are being emitted. To test, run pindexer again, observe that NaNs are out of the candles. ## Checklist before requesting a review - [x] I have added guiding text to explain how a reviewer should test these changes. - [x] If this code contains consensus-breaking changes, I have added the "consensus-breaking" label. Otherwise, I declare my belief that there are not consensus-breaking changes, for the following reason: > Indexing only.
1 parent 0562170 commit f8ae20c

File tree

1 file changed

+5
-1
lines changed
  • crates/bin/pindexer/src/dex_ex

1 file changed

+5
-1
lines changed

crates/bin/pindexer/src/dex_ex/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,10 @@ impl Events {
747747
let pair_2_1 = pair_1_2.flip();
748748
let input_amount = f64::from(input.amount);
749749
let output_amount = f64::from(output.amount);
750+
if input_amount == 0.0 && output_amount == 0.0 {
751+
tracing::warn!(?input, ?output, "ignoring trace with 0 input and output");
752+
return;
753+
}
750754
let price_1_2 = output_amount / input_amount;
751755
let candle_1_2 = Candle::point(price_1_2, input_amount);
752756
let candle_2_1 = Candle::point(1.0 / price_1_2, output_amount);
@@ -1492,7 +1496,7 @@ impl AppView for Component {
14921496
.as_bytes()
14931497
.try_into()
14941498
.expect("Impossible 000-001: expected 32 byte hash");
1495-
Version::with_major(1).with_option_hash(hash)
1499+
Version::with_major(2).with_option_hash(hash)
14961500
}
14971501

14981502
async fn reset(&self, dbtx: &mut PgTransaction) -> Result<(), anyhow::Error> {

0 commit comments

Comments
 (0)