Repository navigation
Description
Bug Report
Setup
CometBFT version (use cometbft version or git rev-parse --verify HEAD if installed from source): should be latest
Have you tried the latest version: no
ABCI app (name for built-in, URL for self-written if it's publicly available): Rebus
Environment:
- OS (e.g. from /etc/os-release): Ubuntu
- Install tools:
- Others:
node command runtime flags:
Config
What happened?
I am building a tool to subscribe to transactions and messages I need. Internally I use Query /libs/pubsub/query/query.go to filter out messages I do not need. One of my goals is to use values comparison (for example, as in this filter: delegate.amount > 10000000, to filter out MsgDelegate messages with amount less than 10m native tokens). It works okay with small values, but on chains with a different denom exponent (namely, Rebus, with exponent 18, and probably Evmos (haven't tested it with it, but it should result in a similar error)), when trying to subscribe to that filter, it would result in the following error:
7:52PM ERR Error querying for events err="failed to match against query message.action = '/cosmos.staking.v1beta1.MsgDelegate' AND delegate.amount > 10000000000000000000: got strconv.ParseInt: parsing \"10000000000000000000\": value out of range while trying to parse 10000000000000000000 as int64 (should never happen if the grammar is correct)" module=pubsub server=node
And if you do the same in app (try to create a filter from the following string and use query.Matches() on it, it would result in the error in this app.
What did you expect to happen?
Conversion is done without any errors.
How to reproduce it
- Start a Rebus node (or any other node that has denom exponent 18 or bigger)
- Subscribe via Tendermint Websockets to the updates on the following filter:
message.action = '/cosmos.staking.v1beta1.MsgDelegate' AND delegate.amount > 10000000000000000000 - Check logs and see errors if such transactions would occur, get a message like the one above per each.
Logs
See above
dump_consensus_state output
Anything else we need to know
This is a copy of tendermint/tendermint#9978 which was closed as stale but apparently never fixed.
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDone
Activity
thanethomson commentedon Apr 24, 2023
@freak12techno could you please clarify which version(s) of CometBFT you're using? This will help in deciding the version(s) of CometBFT to target with a fix.
freak12techno commentedon Apr 24, 2023
@thanethomson I haven't tested this with CometBFT but tested it with Tendermint with a Rebus node, its Tendermint version is apparently v0.34.22.
Additionally I asked CometBFT devs in Discord and they confirmed this is indeed still an issue with the latest versions.
andynog commentedon Apr 24, 2023
Just checking the file
libs/pubsub/query/query.go. Looks like this file was completely revamped last year (around Sep/2022)The
mainbranch doesn't have the logic that is causing this error. I was looking for this text(should never happen if the grammar is correct)in the code and couldn't find it in themainbranch.https://github.com/cometbft/cometbft/blob/main/libs/pubsub/query/query.go
But looking at
CometBFTv0.37release, it seems the code it's still there, and this line seems to be the one causing it.cometbft/libs/pubsub/query/query.go
Line 155 in 43c5ad8
The problem is that this amount is greater than
Int64so it will error. You can see an example here: https://go.dev/play/p/Bm7JVDAfSQDThis might even cause issues because if you look at the example above, the
strconv.ParseIntfunction returns avalue, errand if the code doesn't check forerrthevalueis assigned theint64max value which can lead to unintended consequences (but the code handleserrso it's fine here).The way the current code on
mainbranch handles it by using astrconv.ParseFloatthat will output a10000000000000000000.000000value and it will not error out.Another solution to handle these large denoms (10^18) would be to use a library that can handle Big Integers (BigInt). The
cosmos-sdkuses a library that can handle these integers with 256 bits https://pkg.go.dev/cosmossdk.io/math#pkg-overview, Maybe use something like https://pkg.go.dev/cosmossdk.io/math#NewIntFromString that returns anInt(which is a wrapped BigInt). But this is probably needed if you are doing some arithmetic with these numbers, and the library would help with that. In this case just for parsing the number to be used in a query might not make much sense using this library.freak12techno commentedon Apr 25, 2023
To add my two cents here: having values that exceed 2^64 is quite a common usecase, as we have quite a few chains with denom exponent as 18 (few examples I know: Rebus, Evmos).
As cosmos-sdk uses BigInt internally, I think the best way to solve it is to use BigInt in CometBFT as well, what do you think?
There's also an issue when CometBFT itself isn't able to determine whether the event matches the filter someone subscribed to. I also had it in my own app, where I used Query internally, but it happens also on the node itself when checking if event matches the filter, it doesn't do any conversions there to work with numbers except for determining if it's matching the filter.
jmalicevic commentedon Apr 27, 2023
@freak12techno , can you confirm which version of CometBFT you are using?
freak12techno commentedon Apr 27, 2023
@thanethomson see my answer here #726 (comment)
jmalicevic commentedon Apr 27, 2023
Oh sorry, don't know how I missed that. Yes that is in line with what we are expecting, 0.37.x and earlier versions all parse non-float numbers as
int64. Thanks for the quick feedback :)jmalicevic commentedon May 11, 2023
@freak12techno this should be fixed now with #798 for 0.34.x and #771 for v0.37.x and should be out in the next release of these versions.