Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

globalbalance returns wrong onchain balance #2847

Open
rorp opened this issue Apr 7, 2024 · 2 comments
Open

globalbalance returns wrong onchain balance #2847

rorp opened this issue Apr 7, 2024 · 2 comments

Comments

@rorp
Copy link
Contributor

rorp commented Apr 7, 2024

eclair-cli globalbalance returns these values

"onChain": {
    "confirmed": x.yyyyyyy9000000001,
    "unconfirmed": 0
  }

whereas bitcoin-cli getbalace returns x.yyyyyyy9.

Eclair found 0.00000000000000001 somewhere.

@t-bast
Copy link
Member

t-bast commented Jul 29, 2024

@pm47 could that be related to something eclair does, or is that just a rounding issue from scala's double?

@pm47
Copy link
Member

pm47 commented Jul 29, 2024

My bet is a conversion error from BigDecimal to Decimal at serialization (we should probably use Formats.withBigDecimal() and not convert to Decimal):

object BtcSerializer extends MinimalSerializer({
case x: Btc => JDecimal(x.toDouble)
})

We do use Formats.withBigDecimal() to parse bitcoind responses, the rounding could potentially come from here too:

implicit val formats: Formats = DefaultFormats.withBigDecimal +

Or when summing individual amounts to build the CorrectedOnChainBalance (note that we don't call getbalance):

detailed = utxos.foldLeft(DetailedBalance()) {
case (total, utxo) if utxo.confirmations == 0 => total.modify(_.unconfirmed).using(_ + utxo.amount)
case (total, utxo) => total.modify(_.confirmed).using(_ + utxo.amount)
}

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

No branches or pull requests

3 participants