streamingfast / substreams-rs

9 stars 3 forks source link

Weird behaviour with StoreMinBigDecimal #5

Closed ppoliani closed 1 year ago

ppoliani commented 1 year ago

I'm using the StoreMinBigDecimal to keep the min value in a store like so:

let price = BigDecimal::from_str(&listing.price).unwrap();
log::info!("{:?}", price);

output.min(
  listing.log_ordinal,
  key,
  price.clone(),
);

The above log prints BigDecimal(1000000)

However, when I lated read the value from the store I get a different value.

let price = prices.get_last(key).unwrap(); // prices is prices: StoreGetBigDecimal,
log::info!("{:?}", price);

The logs now show a very long value

BigDecimal(1000000.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)

Is this the expected behaviour?

Eduard-Voiculescu commented 1 year ago

Hey @ppoliani, this is normal behaviour, we just added more precision to your value. However, it is a good point that you bring up, maybe we should add more precision and only return the value set by the user.

ppoliani commented 1 year ago

Would it be possible to choose the precision we want? To be honest these figures are. quite big and we store those values in a database so there is quite a bit of extra space needed.

Eduard-Voiculescu commented 1 year ago

I am actually just gonna remove the with_prec(100) when returning back the data from the store. The precision will be set by you when you create the BigDecimal.

ppoliani commented 1 year ago

This seems to be fixed here https://github.com/streamingfast/substreams-rs/commit/1c237f8f99fd59169cc16ab107619cbd81a5638a. I have manually tested is as well. Thanks @Eduard-Voiculescu