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

feat(ckb|example): Dynamic fetching cell deps deployed by TypeID #191

Merged
merged 8 commits into from
Jun 2, 2024

Conversation

duanyytop
Copy link
Collaborator

@duanyytop duanyytop commented May 24, 2024

Problem

Although Lumos provides a function refreshTypeIdCellDeps to refresh the cell deps of a upgraded TypeID script, it requires the dApp developers themselves to handle it manually.

But usually a dApp developer doesn't know when a TypeID script is updated.

This PR introduces a mechanism to automatically get the TypeID scripts' latest cell deps, trying to make things easier.

Design Goal and Main Changes

Those that need to be optimized

Fetching the GitHub JSON file is not stable or slow for some users, we should do something to optimize it.

The GitHub JSON file path is https://github.com/ckb-cell/rgbpp-sdk/pull/191/files#diff-3039d7f71cfd89a5a23296b2cccdb966bc9132c2bf938a39a08bf0aeceed5d58R21

The tests that need to be run

I have tested the examples of xudt-on-ckb and using the integration tests of #169 to test more examples is needed. cc @Dawn-githup

@Flouse
Copy link
Contributor

Flouse commented May 28, 2024

Those that need to be optimized

Fetching the GitHub JSON file is not stable or slow for some users, we should do something to optimize it.

The GitHub JSON file path is https://github.com/ckb-cell/rgbpp-sdk/pull/191/files#diff-3039d7f71cfd89a5a23296b2cccdb966bc9132c2bf938a39a08bf0aeceed5d58R21

May need a CDN for the static JSON content and test the speed comparing to fetching TypeID script cell deps through ckb-indexer directly.

@ahonn
Copy link
Collaborator

ahonn commented May 28, 2024

Setup CDN for https://raw.githubusercontent.com/ckb-cell/typeid-contract-cell-deps/main/deployment/cell-deps.json

We can try using https://www.jsdelivr.com/?docs=gh, they provide a free, fast CDN.
For example: https://cdn.jsdelivr.net/gh/ckb-cell/typeid-contract-cell-deps@main/deployment/cell-deps.json

@duanyytop
Copy link
Collaborator Author

duanyytop commented May 28, 2024

Those that need to be optimized

Fetching the GitHub JSON file is not stable or slow for some users, we should do something to optimize it.
The GitHub JSON file path is https://github.com/ckb-cell/rgbpp-sdk/pull/191/files#diff-3039d7f71cfd89a5a23296b2cccdb966bc9132c2bf938a39a08bf0aeceed5d58R21

May need a CDN for the static JSON content and test the speed comparing to fetching TypeID script cell deps through ckb-indexer directly.

# RGB++ Lock deployment type script
➜  rgbpp echo '{
    "id": 2,
    "jsonrpc": "2.0",
    "method": "get_cells",
    "params": [
        {
            "script": {
                "code_hash": "0x00000000000000000000000000000000000000000000000000545950455f4944",
                "hash_type": "type",
                "args": "0xa3bc8441df149def76cfe15fec7b1e51d949548bc27fb7a75e9d4b3ef1c12c7f"
            },
            "script_type": "type"
        },
        "asc",
        "0x64"
    ]
}' \
| curl -o /dev/null -s -w 'Total: %{time_total}s\n' -H 'content-type: application/json' -d @- \
https://testnet.ckb.dev/indexer
Total: 0.710650s

# CDN
➜  rgbpp curl -o /dev/null -s -w 'Total: %{time_total}s\n' https://cdn.jsdelivr.net/gh/ckb-cell/typeid-contract-cell-deps@main/deployment/cell-deps.json

Total: 0.197599s

# raw github url
➜  rgbpp curl -o /dev/null -s -w 'Total: %{time_total}s\n' https://raw.githubusercontent.com/ckb-cell/typeid-contract-cell-deps/main/deployment/cell-deps.json
Total: 0.559571s
➜  rgbpp curl -o /dev/null -s -w 'Total: %{time_total}s\n' https://raw.githubusercontent.com/ckb-cell/typeid-contract-cell-deps/main/deployment/cell-deps.json
Total: 0.279097s

@duanyytop
Copy link
Collaborator Author

duanyytop commented May 28, 2024

const request = (url: string) => axios.get(url, { timeout: 2000 });

const fetchCellDepsJson = async () => {
  try {
    const response = await Promise.any([request(GITHUB_CELL_DEPS_JSON_URL), request(CDN_GITHUB_CELL_DEPS_JSON_URL)]);
    return response.data as CellDepsObject;
  } catch (error) {
    // console.error('Error fetching cell deps:', error);
  }
};

The CDN and timeout have been added to make the cell deps fetching faster and more stable in 1310d40

@duanyytop
Copy link
Collaborator Author

Update https://github.com/ckb-cell/typeid-contract-cell-deps automatically through a GitHub action workflow (maybe every 5 mins)

I think the update of the cell-ceps.json of typeid-contract-cell-deps should not block this PR. And I will implement the feature in the typeid-contract-cell-deps repository later.

@duanyytop duanyytop requested a review from ahonn May 28, 2024 10:39
@duanyytop
Copy link
Collaborator Author

Update https://github.com/ckb-cell/typeid-contract-cell-deps automatically through a GitHub action workflow (maybe every 5 mins)

I think the update of the cell-ceps.json of typeid-contract-cell-deps should not block this PR. And I will implement the feature in the typeid-contract-cell-deps repository later.

The task of updating latest cell deps has been triggering and the update time is not strictly 5 minutes.
https://github.com/ckb-cell/typeid-contract-cell-deps/actions/workflows/update.yml

@Flouse Flouse added this pull request to the merge queue Jun 2, 2024
Merged via the queue into develop with commit 207ca98 Jun 2, 2024
2 checks passed
@duanyytop duanyytop deleted the feat/dynamic-fetch-cell-dep branch July 17, 2024 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants