nervosnetwork / fiber

25 stars 11 forks source link

[graph_channels] When iterating to the last page, the returned last_cursor is not 0x. #249

Closed gpBlockchain closed 1 month ago

gpBlockchain commented 1 month ago

When iterating to the last page, the returned last_cursor is not 0x. It will waste the user an additional query

curl --location 'http://127.0.0.1:8228' --header 'Content-Type: application/json' --data '{
    "id": 42,
    "jsonrpc": "2.0",
    "method": "graph_channels",
    "params": [
        {
        "limit":1}
    ]
}'
{"jsonrpc":"2.0","result":{"channels":[{"channel_outpoint":"0x661818e9c1d2aa4fb54b8b32e756d1984501ddf5be04b6c5839896c7f681f7ea00000000","funding_tx_block_number":"0x2a","funding_tx_index":"0x0","node1":"024989c6e8959af260f8f9bf148868eb031b6c0e717710d121c50c9e9710c8875c","node2":"03cae29c8c097a8b24a727f752799262e5ce016b507861346f4e3c1e8f43b81259","last_updated_timestamp":"0x1929f139110","created_timestamp":1729245712634,"node1_to_node2_fee_rate":"0x3e8","node2_to_node1_fee_rate":"0x3e8","capacity":"0x619a44600","chain_hash":"0x0000000000000000000000000000000000000000000000000000000000000000","udt_type_script":null}],"last_cursor":"0x60661818e9c1d2aa4fb54b8b32e756d1984501ddf5be04b6c5839896c7f681f7ea00000000"},"id":42}%                                                                          guopenglin@192 fiber % 
guopenglin@192 fiber % 
guopenglin@192 fiber % curl --location 'http://127.0.0.1:8228' --header 'Content-Type: application/json' --data '{
    "id": 42,
    "jsonrpc": "2.0",
    "method": "graph_channels",
    "params": [
        {
        "limit":1,
                "after":"0x60661818e9c1d2aa4fb54b8b32e756d1984501ddf5be04b6c5839896c7f681f7ea00000000"}

    ]
}'
{"jsonrpc":"2.0","result":{"channels":[],"last_cursor":"0x"},"id":42}%       
chenyukang commented 1 month ago

it's not an issue, the flag to check the termination condition is channels.len() == 0, not last_cursor == 0x0.

from the implementation view, it's also not trivial to fix it since we always need to select limit + 1 to make sure there are more elements, it is not worth for it.

ckb's pagination also works in current way.