ckb-cell / rgbpp-sdk

Utilities for Bitcoin and RGB++ asset integration
ISC License
52 stars 16 forks source link

feat(btc|service): support internal query data caching in TxBuilder.payFee() #184

Closed ShookLyngs closed 2 months ago

ShookLyngs commented 2 months ago

Changes

Query data cache

Previously, when collecting inputs for paying fees, the BtcAssetsApi.getBtcUtxos() API and the BtcAssetsApi.getRgbppAssetsByBtcUtxo() API were queried multiple times. In this PR, a DataCache is added to prevent querying the same API with the same params too often.

Reference: https://github.com/ckb-cell/rgbpp-sdk/issues/173#issuecomment-2112523137

Test

ShookLyngs commented 2 months ago

Here are some suggestions from @ahonn:

Dawn-githup commented 2 months ago

https://pudge.explorer.nervos.org/xudt/0xdc50aa08391b9f7831e08a70884e1094dae8984412e52a8c8371ca3bbccc44f5

Verify that there are 36 cells:

duanyytop commented 2 months ago

https://pudge.explorer.nervos.org/xudt/0xdc50aa08391b9f7831e08a70884e1094dae8984412e52a8c8371ca3bbccc44f5

Verify that there are 36 cells:

  • develop branch build transaction time::
image
  • This branch builds transaction time:
image

Is there still room for improvement in the time cost reduction by the cache? Or is this test case not typical enough?

ShookLyngs commented 2 months ago

Just renamed the cache-related options to make them look clearer:

ShookLyngs commented 2 months ago

Is there still room for improvement in the time cost reduction by the cache? Or is this test case not typical enough?

The problem can be broken down into two parts:

  1. The test case is using the sendRgbppUtxos() API for testing, which is indeed not typical enough because this PR aims to improve the construction time for transactions that collect a large amount of inputs during the fee-paying process.
  2. The sendRgbppUtxos() API can be optimized individually, as it contains time-costly syntax like for (...) { await fetch() }, which can be refactored using the await Promise.all() API.