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

Optimize the search process for BTC_TIME_LOCK ckb transactions #45

Closed
ahonn opened this issue Apr 2, 2024 · 2 comments · Fixed by #212
Closed

Optimize the search process for BTC_TIME_LOCK ckb transactions #45

ahonn opened this issue Apr 2, 2024 · 2 comments · Fixed by #212
Labels
enhancement New feature or request P-Medium

Comments

@ahonn
Copy link
Collaborator

ahonn commented Apr 2, 2024

For now, we use CKB RPC getTransactions to get all transactions that include BTC_TIME_LOCK cells, then get btc_txid from lock args.
Use btc_txid to determine whether the corresponding transaction is the corresponding CKB isomorphic transaction.

const btcTimeLockScript = getBtcTimeLockScript(isMainnet);
const txs = await fastify.ckbIndexer.getTransactions({
  script: {
    ...btcTimeLockScript,
    args: '0x',
  },
  scriptType: 'lock',
});

if (txs.objects.length > 0) {
  for (const { txHash } of txs.objects) {
    const tx = await fastify.ckbRPC.getTransaction(txHash);
    const isBtcTimeLockTx = tx.transaction.outputs.some((output) => {
      if (
        output.lock.codeHash !== btcTimeLockScript.codeHash ||
        output.lock.hashType !== btcTimeLockScript.hashType
      ) {
        return false;
      }
      const btcTxid = btcTxIdFromBtcTimeLockArgs(output.lock.args);
      return remove0x(btcTxid) === btc_txid;
    });
    if (isBtcTimeLockTx) {
      reply.header(CUSTOM_HEADERS.ResponseCacheable, 'true');
      return { txhash: txHash };
    }
  }
}

For CKB RPC getTransactions, we can optimize it through scriptSearchMode: 'partial' in the future to reduce the number of Cells that need to be checked and optimize the query speed.

But this depends on rich indexer, we need to wait for the node to support rich indexer.

References

@ahonn
Copy link
Collaborator Author

ahonn commented Apr 2, 2024

@ahonn ahonn self-assigned this Apr 2, 2024
@ahonn ahonn changed the title Optimize the search process for BTC Time Lock CKB isomorphic transactions Optimize the search process for BTC_TIME_LOCK ckb transactions Apr 2, 2024
@Flouse Flouse added enhancement New feature or request P-Low labels Apr 2, 2024
@ahonn
Copy link
Collaborator Author

ahonn commented Apr 29, 2024

Rich indexer has been released: https://github.com/nervosnetwork/ckb/releases/tag/v0.115.0
We will be optimize cell collection after lumos supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P-Medium
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants