Magickbase / neuron-public-issues

Neuron Issues
6 stars 3 forks source link

Supporting Spore #252

Closed Keith-CY closed 12 months ago

Keith-CY commented 1 year ago

This protocol is not open-sourced yet, so the document is shared by magickbase google workspace at https://drive.google.com/file/d/1uQ4TMRxiF8TsEhkP_6oQoQzzsC4Q5Tbs/view?usp=sharing

SDK:


It's intended to be public on mainnet on YYYY/mm/dd, and the team hopes Neuron to support displaying its name and description(optional) in the customized assets window, similar to what m-NFT did.

The mechanism is simple as follows:

  1. detect if an unknown asset is a spore cell, if yes;
  2. parse type id of spore cluster cell(if there is) and load it;
  3. parse name and description from the spore cluster cell and display it along with the spore cell
  4. if a spore cell is not bound to a cluster, display a fallback name.
Danie0918 commented 1 year ago

PRD : https://10x1hg.axshare.com @Keith-CY Please review.

yanguoyu commented 1 year ago

if cluster was set, then the referenced Spore Cluster Cell should appear in CellDep , and should follow rules below:

  1. A Spore Cluster Cell with same Type Script args set in Spore Cell 's cluster field must exist in both Inputs and Outputs

If the Spore cell has a cluster field in the data, we can find the cluster in the transaction input or output, then we can load the cluster cell data and get name and description. Otherwise, we will show the fallback name. Do I understand correctly?

Keith-CY commented 1 year ago

if cluster was set, then the referenced Spore Cluster Cell should appear in CellDep , and should follow rules below:

  1. A Spore Cluster Cell with same Type Script args set in Spore Cell 's cluster field must exist in both Inputs and Outputs

If the Spore cell has a cluster field in the data, we can find the cluster in the transaction input or output, then we can load the cluster cell data and get name and description. Otherwise, we will show the fallback name. Do I understand correctly?

The reference to the cluster cell could be found in the cell deps field

if cluster was set, then the referenced Spore Cluster Cell should appear in CellDep , and should follow rules below

homura commented 1 year ago

According to the PRD and SDK, we may need a model to adapt light client and full node.

One difficulty here is that it's a bit hard to find the cluster of a spore in light client, we may need to use fetch_tranasction to continuously resolve the OutPoint until we find the minting/issuance transition

interface SporeNftManager {
  list(): Promise<Paginate<SporeNft>>;
  getClusterBySpore(outPoint: OutPoint): Promise<Cluster>;
  transfer(options: { recipient: Address; outPoint: OutPoint }): Promise<Hash>;
}

interface LightClientSporeManager extends SporeNftManager {
  // `fetch_transaction` to find previous transaction inputs 
  // until resolvedTx.inputs.find(input => equals(input.type.scriptHash(), targetClusterTypeHash))
  getClusterBySpore(outPoint: OutPoint): Promise<Cluster>;
}

interface FullNodeSporeManager extends SporeNftManager {}
homura commented 1 year ago

@Keith-CY @yanguoyu

I've created a pull request for this issue, but it has some limitations when working with the light client. Perhaps we can discuss whether the limitations are acceptable.

Limitation with The Light Client

  • expected: [ID][Cluster Name] Spore
  • actual: [ID][Cluster ID] Spore

When working with the light client in this PR, the [Cluster Name] part is displayed as a Cluster ID. This is because it is difficult to resolve the cluster cell from a spore cell, which is not owned by the wallet. To search the cluster cell that derives the spore cell, we need to:

  1. Decode the cluster_id from a spore cell's data if the spore is born from a cluster
  2. Build the type script filter of code_hash: cluster_code_hash, data: data1, args: cluster_id and search in the CKB indexer
  3. Repeat step 2 with another version of cluster scripts if the cluster cell is not found.

This limitation appears because Neuron only subscribes to lock scripts owned by a wallet, while the cluster cell may not belong to it.

Although we can subscribe to the cluster cells not owned by the wallet, it will make the light client heavier. If we subscribe to more scripts to make the features the same as the full node, the light client will lose its lightness. Therefore, I believe that the trade-off here may be acceptable.

Keith-CY commented 1 year ago

@Keith-CY @yanguoyu

I've created a pull request for this issue, but it has some limitations when working with the light client. Perhaps we can discuss whether the limitations are acceptable.

Limitation with The Light Client

  • expected: [ID][Cluster Name] Spore
  • actual: [ID][Cluster ID] Spore

When working with the light client in this PR, the [Cluster Name] part is displayed as a Cluster ID. This is because it is difficult to resolve the cluster cell from a spore cell, which is not owned by the wallet. To search the cluster cell that derives the spore cell, we need to:

  1. Decode the cluster_id from a spore cell's data if the spore is born from a cluster
  2. Build the type script filter of code_hash: cluster_code_hash, data: data1, args: cluster_id and search in the CKB indexer
  3. Repeat step 2 with another version of cluster scripts if the cluster cell is not found.

This limitation appears because Neuron only subscribes to lock scripts owned by a wallet, while the cluster cell may not belong to it. Although we can subscribe to the cluster cells not owned by the wallet, it will make the light client heavier. If we subscribe to more scripts to make the features the same as the full node, the light client will lose its lightness. Therefore, I believe that the trade-off here may be acceptable.

I have a question, a trade-off solution and a suggestion 🙈

question: why is step 2 repeated when the cluster cell is not found

trade-off solution: a link to the spore cell can be appended next to an unknown spore nft

suggestion: we may connect to light client developers for some advices.

homura commented 1 year ago

question: why is step 2 repeated when the cluster cell is not found

Since there are multiple versions of cluster scripts available, we need to try them until we find a match.

suggestion: we may connect to light client developers for some advices.

good point

yanguoyu commented 1 year ago

We'd better set the start block number(maybe the spore contract block number) for the cluster script when adding a cluster script to the filter. The light client will wait for the minimum synced height when we add a new script into the script filter. After all filter scripts reach the same height, they will sync together again.

The sync speed will slow if the wallet owner has many different spore clusters. Or can we get the cluster transaction hash? If so we can get the cluster detail by fetch_transaction but not wait to sync the script.

homura commented 1 year ago

Or can we get the cluster transaction hash?

When fetching the transaction of a cluster cell, one must trace back from the spore cell to find the mint transaction. However, the fetch_transaction process is async and requires a placeholder during the search.

I'm not sure it's worth increasing the workload of the light client for this process, as fetching the spore data, typically an image, is not small.

yanguoyu commented 1 year ago

Or can we get the cluster transaction hash?

When fetching the transaction of a cluster cell, one must trace back from the spore cell to find the mint transaction. However, the fetch_transaction process is async and requires a placeholder during the search.

I'm not sure it's worth increasing the workload of the light client for this process, as fetching the spore data, typically an image, is not small.

I guess finding the cluster cell from transaction lists is quicker than adding the script to filter because it needs to scan the block from the start block number to the cluster cell, we don't know the cluster cell's block number. And it may block other scripts' sync process.

typically an image, is not small. It's really a point that we should consider. How much is the spore cell max image size?

yanguoyu commented 1 year ago

https://github.com/nervosnetwork/neuron/pull/2810

homura commented 1 year ago

It is better for Neuron to support the transferring feature because the Spore Demo is only supporting Omnilock for now, otherwise, the Spores in Neuron would lose its activity