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

get_transactions method not returning results in expected order #4549

Closed
Flouse opened this issue Jul 26, 2024 · 7 comments
Closed

get_transactions method not returning results in expected order #4549

Flouse opened this issue Jul 26, 2024 · 7 comments
Labels
b:rpc Break RPC interface help wanted Extra attention is needed m:indexer module: ckb-indexer stale To be closed due to a lack of activity

Comments

@Flouse
Copy link
Contributor

Flouse commented Jul 26, 2024

Current Behavior

The following request is not returning results in ascending order.

curl --location --request POST 'https://testnet.ckb.dev/' \
--header 'Content-Type: application/json' \
--header 'Host: testnet.ckb.dev' \
--data-raw '{
  "id": 2,
  "jsonrpc": "2.0",
  "method": "get_transactions",
  "params": [
    {
      "script": {
        "code_hash": "0x8e341bcfec6393dcd41e635733ff2dca00a6af546949f70c57a706c0f344df8b",
        "hash_type": "type",
        "args": "0x"
      },
      "script_type": "type"
    },
    "asc",
    "0xf"
  ]
}'

Result

Despite specifying the order as "asc" in the request parameters, the results returned are not in ascending order.

{
    "jsonrpc": "2.0",
    "result": {
        "last_cursor": "0xa08e341bcfec6393dcd41e635733ff2dca00a6af546949f70c57a706c0f344df8b01034c88b621a2853c571af93230a9569730cfeb3c0000000000ccc082000000020000000401",
        "objects": [
            {
                "block_number": "0xd2cedc",
                "io_index": "0x1",
                "io_type": "output",
                "tx_hash": "0x6ee515830f9d7f4062dbd446f66fe29b10ba4f8565d3750bfce33418b0081785",
                "tx_index": "0x2"
            },
            {
                "block_number": "0xd12bd6",
                "io_index": "0x1",
                "io_type": "output",
                "tx_hash": "0xb423e11fa44051c4a2580523c9d19720553a2492fa305f3b386cbde6c235ca7e",
                "tx_index": "0x1"
            },
            {
                "block_number": "0xc4dc4a",
                "io_index": "0x1",
                "io_type": "output",
                "tx_hash": "0xf862b851fbb67a85e6454e17013547530c73ea7fd6cead5e48f919132ad1324e",
                "tx_index": "0x4"
            },
            {
                "block_number": "0xc69f5c",
                "io_index": "0x1",
                "io_type": "output",
                "tx_hash": "0x6d5ffc7d851f71eb4dbe5dafc09206f07d5c55e27db3d0d28d70f9adf49c6935",
                "tx_index": "0x2"
            },
            {
                "block_number": "0xcb1a50",
                "io_index": "0x1",
                "io_type": "output",
                "tx_hash": "0x6563dac7aa2ac4df0704c76acfc46260887eab25773877cffc7d961d40e042cf",
                "tx_index": "0x2"
            },
            {
                "block_number": "0xd190e5",
                "io_index": "0x1",
                "io_type": "output",
                "tx_hash": "0x4e5035fa8838cc04c206b451f3e65f6d34072f697981d77ca6c2624139fd28c0",
                "tx_index": "0x4"
            },
            {
                "block_number": "0xd08639",
                "io_index": "0x1",
                "io_type": "output",
                "tx_hash": "0x827229880d19a216858965446cc9856d0f41b2c9d5a1c0f5157b127d7ce5a0b8",
                "tx_index": "0x4"
            },
            {
                "block_number": "0xc9f261",
                "io_index": "0x1",
                "io_type": "output",
                "tx_hash": "0x5173e7cca5eab271382d97bb84e1d0509abdf6def142e50c8ce2a3daeb63f7ef",
                "tx_index": "0x1"
            },
            {
                "block_number": "0xcba6b6",
                "io_index": "0x1",
                "io_type": "output",
                "tx_hash": "0xdb1088f5ffe5f4ec3e0466ed789715b8600ee0bcb68e6ad7832c8e4cf01cfac2",
                "tx_index": "0x1"
            },
            {
                "block_number": "0xca51ad",
                "io_index": "0x1",
                "io_type": "output",
                "tx_hash": "0x3930e2094e0356fad6f85912a0cda7619ecb7c70434ac4dfef573f52f1a5520c",
                "tx_index": "0x2"
            },
            {
                "block_number": "0xc5cd7a",
                "io_index": "0x1",
                "io_type": "output",
                "tx_hash": "0xc73c95c35ffc333f6f02500db0c6f19b410ed44fae7b21571d7e79a1fc77e93b",
                "tx_index": "0x1"
            },
            {
                "block_number": "0xc53188",
                "io_index": "0x1",
                "io_type": "output",
                "tx_hash": "0x316438dda4f7014e2c8c9fb5c59e902458d6b96815b99522c80da1f6991f0595",
                "tx_index": "0x1"
            },
            {
                "block_number": "0xcc3908",
                "io_index": "0x1",
                "io_type": "output",
                "tx_hash": "0xfe25e92527220c39a2cd412e106586eb9fc1829dea12524490aa0414c01893f0",
                "tx_index": "0x2"
            },
            {
                "block_number": "0xcc3f12",
                "io_index": "0x4",
                "io_type": "output",
                "tx_hash": "0x82a680d4e75420bc634b93b3cf11c5b3a64f4e07dc22f6b91d35b9f121fc8cb7",
                "tx_index": "0x1"
            },
            {
                "block_number": "0xccc082",
                "io_index": "0x4",
                "io_type": "output",
                "tx_hash": "0xbcea937c1365b7934f05ab68eff32aed93a5325a0f8cc21f5ce9c016a3315bca",
                "tx_index": "0x2"
            }
        ]
    },
    "id": 2
}

Expected Behavior:

I expected the transactions to be returned in ascending order based on the specified parameters.

Actual Behavior:

The transactions returned do not appear to be sorted in ascending order, as indicated by the block_number values. This is contrary to the expected behavior

Environment

See the node of https://testnet.ckb.dev

@Flouse Flouse added the t:bug Type: This doesn't seem right. label Jul 26, 2024
@eval-exec eval-exec added the b:rpc Break RPC interface label Jul 26, 2024
@eval-exec
Copy link
Collaborator

eval-exec commented Jul 26, 2024

It seems that when storing data in RocksDB, ascending order(ckb-rocksdb::ops::Direction::Forward) is not arranged according to BlockNumber from smallest to largest.

@eval-exec eval-exec added help wanted Extra attention is needed m:indexer module: ckb-indexer labels Jul 26, 2024
@eval-exec eval-exec self-assigned this Jul 27, 2024
@quake
Copy link
Member

quake commented Jul 30, 2024

it's expected, the result is ordered by script first then block number, since the script code hash are same, it's order by args first:

args                                        block number
0x006c079e7979fbde1c62a854fab9eef6606d5963  0xd2cedc
0x00866b5963a04aa5910b4316feb42d83b71bf606  0xd12bd6
0x0087cc10fe36646a48b8d302640e015543f89075  0xc4dc4a

@eval-exec eval-exec removed their assignment Jul 31, 2024
@eval-exec eval-exec removed the t:bug Type: This doesn't seem right. label Jul 31, 2024
@Flouse
Copy link
Contributor Author

Flouse commented Aug 2, 2024

May I ask what is the purpose of ordering the results by script first?
Does any app use this feature?

My use case

When a UDT first appears in a transaction's outputs alongside a Unique Cell, the unique cell defines the UDT's information or metadata.

So I expect that the asc order to sort by block_number & tx_index.


Well, it's ok that the caller can sort the result by himself.
I suggest that add docs for this order rules into https://github.com/nervosnetwork/ckb/blob/master/rpc/README.md#type-indexerorder

@quake
Copy link
Member

quake commented Aug 2, 2024

May I ask what is the purpose of ordering the results by script first?

the default indexer backend is rocksdb, it's difficult to design a secondary index in kv store, which will introduce a lot of complexity and storage size overhead. so we use a simple way to implement this ordering strategy.

you may try the rich-inexer ( https://github.com/nervosnetwork/ckb/blob/5233b91a586fbe628f71ea5e42de83110a25eccf/util/rich-indexer/README.md#ckb-rich-indexer ) and implement a more complex ordering strategy based on it.

@ahonn
Copy link

ahonn commented Aug 8, 2024

The results are ordered by script first and then by block number.
What is the purpose of the after pagination parameter when ordering by script? It seems odd.

Copy link

github-actions bot commented Sep 8, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the stale To be closed due to a lack of activity label Sep 8, 2024
Copy link

This issue was closed because it has been stalled for 5 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
b:rpc Break RPC interface help wanted Extra attention is needed m:indexer module: ckb-indexer stale To be closed due to a lack of activity
Projects
Status: Done
Development

When branches are created from issues, their pull requests are automatically linked.

4 participants