nervosnetwork / ckb-light-client

CKB light client reference implementation
MIT License
14 stars 16 forks source link

getTransactions result not consistent with ckb-index #91

Closed gpBlockchain closed 1 year ago

gpBlockchain commented 1 year ago

commit:9af874793feca252e37b9f3d25fb9973ad9c74b6

step

set _script :

 {
                code_hash: "0xc5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4",
                hash_type: "type",
                args: "0x9032560e30de0fe07fe8489d022dde6d3d5920cf8b3a4d8fd64717a778741c30"
  }
script_type:type
block_number:1755000

wait script update 1759625,

send `getTransactions` to ckb-light-client,but not find tx:  0xc7751cb8a11d67d6e464100ba20c1e3148a55bce3f434048c00fabac16e3a6c2
send `getTransactions` to ckb-index to be found

js-code

it('getTransactions not eq', async () => {

        const testScriptMsg: ScriptMsg = {
            script: {
                code_hash: "0xc5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4",
                hash_type: "type",
                args: "0x9032560e30de0fe07fe8489d022dde6d3d5920cf8b3a4d8fd64717a778741c30"
            },
            script_type: "type",
            block_number: BI.from("1755000").toHexString(),
        }

        await CkbClientNode.clean()
        await CkbClientNode.start()
        await setScripts([testScriptMsg])
        await waitScriptsUpdate(BI.from("1759625"))
        const lightTxs = await getTransactionList(testScriptMsg.script, testScriptMsg.script_type, undefined, CKB_LIGHT_RPC_URL, [BI.from("1755000").toHexString(), BI.from("1759626").toHexString()])
        const indexTxs = await getTransactionList(testScriptMsg.script, testScriptMsg.script_type, undefined, CKB_RPC_INDEX_URL, [BI.from("1755000").toHexString(), BI.from("1759626").toHexString()])
        console.log('---light txs----')
        lightTxs.forEach(x => console.log(x))
        console.log('---index txs ---')
        indexTxs.forEach(x => console.log(x))

    })

log


  issue
sh: pkill ckb-light-client
response: 
sh: rm -rf tmp/startBlockchain/ckbLightClient/ckb-light-client/target/release/data
response: 
sh: cd tmp/startBlockchain/ckbLightClient/ckb-light-client/target/release && RUST_LOG=info,ckb_light_client=trace ./ckb-light-client run --config-file ./config.toml > node.log 2>&1 &
response: 
curl --location --request POST 'http://localhost:9000' \
--header 'Content-Type: application/json' \
--data-raw '{
        "jsonrpc":"2.0",
        "method":"set_scripts",
        "params":[[{"script":{"code_hash":"0xc5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4","hash_type":"type","args":"0x9032560e30de0fe07fe8489d022dde6d3d5920cf8b3a4d8fd64717a778741c30"},"script_type":"type","block_number":"0x1ac778"}]],
        "id":64
}'
null
curl --location --request POST 'http://localhost:9000' \
--header 'Content-Type: application/json' \
--data-raw '{
        "jsonrpc":"2.0",
        "method":"get_scripts",
        "params":[],
        "id":64
}'
[
  {
    block_number: '0x1ac778',
    script: {
      args: '0x9032560e30de0fe07fe8489d022dde6d3d5920cf8b3a4d8fd64717a778741c30',
      code_hash: '0xc5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4',
      hash_type: 'type'
    },
    script_type: 'type'
  }
]
[waitScriptsUpdate] current get script Height: 1755000 ,wait sync height: 1759625
curl --location --request POST 'http://localhost:9000' \
--header 'Content-Type: application/json' \
--data-raw '{
        "jsonrpc":"2.0",
        "method":"get_scripts",
        "params":[],
        "id":64
}'
[
  {
    block_number: '0x1adb00',
    script: {
      args: '0x9032560e30de0fe07fe8489d022dde6d3d5920cf8b3a4d8fd64717a778741c30',
      code_hash: '0xc5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4',
      hash_type: 'type'
    },
    script_type: 'type'
  }
]
[waitScriptsUpdate] current get script Height: 1760000 ,wait sync height: 1759625
curl --location --request POST 'http://localhost:9000' \
--header 'Content-Type: application/json' \
--data-raw '{
        "jsonrpc":"2.0",
        "method":"get_transactions",
        "params":[{"script":{"code_hash":"0xc5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4","hash_type":"type","args":"0x9032560e30de0fe07fe8489d022dde6d3d5920cf8b3a4d8fd64717a778741c30"},"script_type":"type","group_by_transaction":true,"filter":{"block_range":["0x1ac778","0x1ad98a"]}},"asc","0xbb8",null],
        "id":64
}'
{
  last_cursor: '0x80c5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4019032560e30de0fe07fe8489d022dde6d3d5920cf8b3a4d8fd64717a778741c3000000000001ada67000000030000000001',
  objects: []
}
curl --location --request POST 'http://localhost:8116' \
--header 'Content-Type: application/json' \
--data-raw '{
        "jsonrpc":"2.0",
        "method":"get_transactions",
        "params":[{"script":{"code_hash":"0xc5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4","hash_type":"type","args":"0x9032560e30de0fe07fe8489d022dde6d3d5920cf8b3a4d8fd64717a778741c30"},"script_type":"type","group_by_transaction":true,"filter":{"block_range":["0x1ac778","0x1ad98a"]}},"asc","0xbb8",null],
        "id":64
}'
{
  last_cursor: '0xa0c5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4019032560e30de0fe07fe8489d022dde6d3d5920cf8b3a4d8fd64717a778741c300000000000309207000000010000000001',
  objects: [
    {
      block_number: '0x1ad989',
      cells: [Array],
      tx_hash: '0xc7751cb8a11d67d6e464100ba20c1e3148a55bce3f434048c00fabac16e3a6c2',
      tx_index: '0x1'
    }
  ]
}
current totalSize: 1 cursor: 0xa0c5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4019032560e30de0fe07fe8489d022dde6d3d5920cf8b3a4d8fd64717a778741c300000000000309207000000010000000001
curl --location --request POST 'http://localhost:8116' \
--header 'Content-Type: application/json' \
--data-raw '{
        "jsonrpc":"2.0",
        "method":"get_transactions",
        "params":[{"script":{"code_hash":"0xc5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4","hash_type":"type","args":"0x9032560e30de0fe07fe8489d022dde6d3d5920cf8b3a4d8fd64717a778741c30"},"script_type":"type","group_by_transaction":true,"filter":{"block_range":["0x1ac778","0x1ad98a"]}},"asc","0xbb8","0xa0c5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4019032560e30de0fe07fe8489d022dde6d3d5920cf8b3a4d8fd64717a778741c300000000000309207000000010000000001"],
        "id":64
}'
{ last_cursor: '0x', objects: [] }
---light txs----
---index txs ---
0xc7751cb8a11d67d6e464100ba20c1e3148a55bce3f434048c00fabac16e3a6c2

Reproductions

git clone https://github.com/gpBlockchain/ckb-light-test.git
git checkout issue1
npm install
sh prepare.sh
npm run test-issue

git-pod:https://gpblockchai-ckblighttes-j2lpnzh63f0.ws-us71.gitpod.io

TheWaWaR commented 1 year ago

I think I find the problem here.

In the case we call set_scripts rpc to let light client node to index from block#1755000. But in the transaction 0xc7751cb8a11d67d6e464100ba20c1e3148a55bce3f434048c00fabac16e3a6c2, we can see the type script is only exists in input 0x7c51c304d11c16befd2b4e512b137f69cd0571519088a0b1a9d00a4566b37e9c#0 is from block#1683618 (which is less than 1755000), so we not index the input transaction, and therefor we can not get this transaction(0xc775...) from light client by get_transactions or get_cells

In practice, we should set the block number in set_scripts not greater than the first block number the script included block number. In the test case the first block number of the type script is 1680344, we should use a block number in set_scripts not greater than 1680344.