Skip to content

feat: add CellsCommitments softfork #4090

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

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ckb-app-config = { path = "../util/app-config", version = "= 0.112.0-pre" }
ckb-rust-unstable-port = { path = "../util/rust-unstable-port", version = "= 0.112.0-pre" }
ckb-channel = { path = "../util/channel", version = "= 0.112.0-pre" }
faux = { version = "^0.1", optional = true }
ckb-merkle-mountain-range = "0.5.2"
ckb-merkle-mountain-range = { git = "https://github.com/quake/merkle-mountain-range", branch = "quake/updatable" }

[dev-dependencies]
ckb-test-chain-utils = { path = "../util/test-chain-utils", version = "= 0.112.0-pre" }
Expand Down
1 change: 1 addition & 0 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ impl ChainService {
switch,
Arc::clone(&txs_verify_cache),
&mmr,
&txn,
);
contextual_block_verifier.verify(&resolved, b)
};
Expand Down
11 changes: 10 additions & 1 deletion db-schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// Column families alias type
pub type Col = &'static str;
/// Total column number
pub const COLUMNS: u32 = 19;
pub const COLUMNS: u32 = 20;
/// Column store chain index
pub const COLUMN_INDEX: Col = "0";
/// Column store block's header
Expand Down Expand Up @@ -44,6 +44,8 @@ pub const COLUMN_CHAIN_ROOT_MMR: Col = "16";
pub const COLUMN_BLOCK_FILTER: Col = "17";
/// Column store filter data hash for client-side filtering
pub const COLUMN_BLOCK_FILTER_HASH: Col = "18";
/// Column store cells root MMR data
pub const COLUMN_CELLS_ROOT_MMR: Col = "19";

/// META_TIP_HEADER_KEY tracks the latest known best block header
pub const META_TIP_HEADER_KEY: &[u8] = b"TIP_HEADER";
Expand All @@ -52,6 +54,13 @@ pub const META_CURRENT_EPOCH_KEY: &[u8] = b"CURRENT_EPOCH";
/// META_FILTER_DATA_KEY tracks the latest built filter data block hash
pub const META_LATEST_BUILT_FILTER_DATA_KEY: &[u8] = b"LATEST_BUILT_FILTER_DATA";

/// A key prefix records the cells root mmr size by block number
pub const CELLS_ROOT_MMR_SIZE_KEY_PREFIX: &[u8] = &[0];
/// A key prefix records the status of out_point in cells root mmr
pub const CELLS_ROOT_MMR_STATUS_KEY_PREFIX: &[u8] = &[1];
/// A key prefix records the cells root mmr element by position
pub const CELLS_ROOT_MMR_ELEMENT_KEY_PREFIX: &[u8] = &[2];

/// CHAIN_SPEC_HASH_KEY tracks the hash of chain spec which created current database
pub const CHAIN_SPEC_HASH_KEY: &[u8] = b"chain-spec-hash";
/// MIGRATION_VERSION_KEY tracks the current database version.
Expand Down
1 change: 1 addition & 0 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ckb-tx-pool = { path = "../tx-pool", version = "= 0.112.0-pre" }
ckb-memory-tracker = { path = "../util/memory-tracker", version = "= 0.112.0-pre" }
ckb-pow = { path = "../pow", version = "= 0.112.0-pre" }
ckb-indexer = { path = "../util/indexer", version = "= 0.112.0-pre" }
ckb-merkle-mountain-range = { git = "https://github.com/quake/merkle-mountain-range", branch = "quake/updatable" }
itertools.workspace = true
tokio = "1"

Expand Down
181 changes: 180 additions & 1 deletion rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ The crate `ckb-rpc`'s minimum supported rustc version is 1.67.1.
* [Method `verify_transaction_proof`](#method-verify_transaction_proof)
* [Method `get_transaction_and_witness_proof`](#method-get_transaction_and_witness_proof)
* [Method `verify_transaction_and_witness_proof`](#method-verify_transaction_and_witness_proof)
* [Method `get_cells_status_proof`](#method-get_cells_status_proof)
* [Method `verify_cells_status_proof`](#method-verify_cells_status_proof)
* [Method `get_fork_block`](#method-get_fork_block)
* [Method `get_consensus`](#method-get_consensus)
* [Method `get_block_median_time`](#method-get_block_median_time)
Expand Down Expand Up @@ -120,8 +122,10 @@ The crate `ckb-rpc`'s minimum supported rustc version is 1.67.1.
* [Type `CellInfo`](#type-cellinfo)
* [Type `CellInput`](#type-cellinput)
* [Type `CellOutput`](#type-celloutput)
* [Type `CellStatus`](#type-cellstatus)
* [Type `CellWithStatus`](#type-cellwithstatus)
* [Type `CellbaseTemplate`](#type-cellbasetemplate)
* [Type `CellsStatusProof`](#type-cellsstatusproof)
* [Type `ChainInfo`](#type-chaininfo)
* [Type `Consensus`](#type-consensus)
* [Type `Cycle`](#type-cycle)
Expand Down Expand Up @@ -1502,6 +1506,146 @@ Response
```


#### Method `get_cells_status_proof`
* `get_cells_status_proof(out_points, block_hash)`
* `out_points`: `Array<` [`OutPoint`](#type-outpoint) `>`
* `block_hash`: [`H256`](#type-h256) `|` `null`
* result: [`CellsStatusProof`](#type-cellsstatusproof)

Returns a proof of the cells status in the specified block.

###### Params

* `out_points` - Cells’ out points to prove

* `block_hash` - An optional parameter, if specified, generate proof for the block with this hash, otherwise use the tip block

###### Examples

Request


```
{
"id": 42,
"jsonrpc": "2.0",
"method": "get_cells_status_proof",
"params": [
[
{
"tx_hash": "0xa4037a893eb48e18ed4ef61034ce26eba9c585f15c9cee102ae58505565eccc3",
"index": "0x0"
}
]
]
}
```


Response


```
{
"id": 42,
"jsonrpc": "2.0",
"result": {
"block_hash": "0xa5f5c85987a15de25661e5a214f2c1449cd803f071acc7999820f25246471f40",
"cells_count": "0x3f6",
"cells_status": [
{
"mmr_position": "0x0",
"out_point": {
"tx_hash": "0xa4037a893eb48e18ed4ef61034ce26eba9c585f15c9cee102ae58505565eccc3",
"index": "0x0"
},
"created_by": "0x0",
"consumed_by": null
}
],
"merkle_proof": [
"0xdeb75ce5f1a45df88aca9370c01224fcbba5e996b190a8a6ca4b7b3df18b5d42",
"0x29deb32dfc73c95d62be24915c5edafc2c0c8e61eda94e6abed78e18f6e1af1b",
"0xa936c971f5c59b1a200a6b3f2cc8d11ef099fa7a7b18e5faa5792d8aab3ef6a8",
"0x3b98c55e5a8d274c0c5558de7f1c9c2427fddd291ff961b95e3f5e0deffbd717",
"0x384b248b63348edc3466016c73cb8657feeccc181c5d73f318dd16b2d59e0305",
"0xa173912a34b254a2ebc921f7559c0a777fa556362a6761522a2204bd7b524c7e",
"0xaa6a62aa7388c1df92c16d605233e13ed861234bb803cd37ee1112cfe244b94a",
"0x9819e43079dad6302e80cc6f0db90cd55aff16dd5380fc461aa02cab19af2d4c",
"0x944db3a79017c60da31dddb33f796d196dd5c0209ddb738398f489ac3c2b7159",
"0xe4e6bb25e72c3ce034aa02231e42b2c05030495c37e29530ed7c8fc429f902f9"
]
}
}
```


#### Method `verify_cells_status_proof`
* `verify_cells_status_proof(proof)`
* `proof`: [`CellsStatusProof`](#type-cellsstatusproof)
* result: `boolean`

Verifies that a cells status proof is valid or not.

###### Params

* `out_points` - Cells’ out points to prove

* `block_hash` - An optional parameter, if specified, generate proof for the block with this hash, otherwise use the tip block

###### Examples

Request


```
{
"id": 42,
"jsonrpc": "2.0",
"method": "verify_cells_status_proof",
"params": [{
"block_hash": "0xa5f5c85987a15de25661e5a214f2c1449cd803f071acc7999820f25246471f40",
"cells_count": "0x3f6",
"cells_status": [
{
"mmr_position": "0x0",
"out_point": {
"tx_hash": "0xa4037a893eb48e18ed4ef61034ce26eba9c585f15c9cee102ae58505565eccc3",
"index": "0x0"
},
"created_by": "0x0",
"consumed_by": null
}
],
"merkle_proof": [
"0xdeb75ce5f1a45df88aca9370c01224fcbba5e996b190a8a6ca4b7b3df18b5d42",
"0x29deb32dfc73c95d62be24915c5edafc2c0c8e61eda94e6abed78e18f6e1af1b",
"0xa936c971f5c59b1a200a6b3f2cc8d11ef099fa7a7b18e5faa5792d8aab3ef6a8",
"0x3b98c55e5a8d274c0c5558de7f1c9c2427fddd291ff961b95e3f5e0deffbd717",
"0x384b248b63348edc3466016c73cb8657feeccc181c5d73f318dd16b2d59e0305",
"0xa173912a34b254a2ebc921f7559c0a777fa556362a6761522a2204bd7b524c7e",
"0xaa6a62aa7388c1df92c16d605233e13ed861234bb803cd37ee1112cfe244b94a",
"0x9819e43079dad6302e80cc6f0db90cd55aff16dd5380fc461aa02cab19af2d4c",
"0x944db3a79017c60da31dddb33f796d196dd5c0209ddb738398f489ac3c2b7159",
"0xe4e6bb25e72c3ce034aa02231e42b2c05030495c37e29530ed7c8fc429f902f9"
]
}]
}
```


Response


```
{
"id": 42,
"jsonrpc": "2.0",
"result": true
}
```


#### Method `get_fork_block`
* `get_fork_block(block_hash, verbosity)`
* `block_hash`: [`H256`](#type-h256)
Expand Down Expand Up @@ -5525,6 +5669,23 @@ The fields of an output cell except the cell data.
The JSON field name is “type”.


### Type `CellStatus`

Cell status.

#### Fields

`CellStatus` is a JSON object with the following fields.

* `mmr_position`: [`Uint64`](#type-uint64) - The position of the leaf node in the MMR.

* `out_point`: [`OutPoint`](#type-outpoint) - The cell’s out point.

* `created_by`: [`BlockNumber`](#type-blocknumber) - The block number when the cell was created.

* `consumed_by`: [`BlockNumber`](#type-blocknumber) `|` `null` - The block number when the cell was consumed, optional, none if the cell is live.


### Type `CellWithStatus`

The JSON view of a cell with its status information.
Expand Down Expand Up @@ -5599,6 +5760,23 @@ The cellbase transaction template of the new block for miners.
* `data`: [`Transaction`](#type-transaction) - The cellbase transaction.


### Type `CellsStatusProof`

Proof of cells status.

#### Fields

`CellsStatusProof` is a JSON object with the following fields.

* `block_hash`: [`H256`](#type-h256) - The block hash of the specified block.

* `cells_count`: [`Uint64`](#type-uint64) - The total number of generated cells from genesis block to the specified block, including consumed cells.

* `cells_status`: `Array<` [`CellStatus`](#type-cellstatus) `>` - An array of cell status.

* `merkle_proof`: `Array<` [`H256`](#type-h256) `>` - The merkle proof of the MMR, it is an array of hash digests.


### Type `ChainInfo`

Chain information.
Expand Down Expand Up @@ -5762,10 +5940,11 @@ An object containing various state info regarding deployments of consensus chang

Deployment name

`DeploymentPos` is equivalent to `"testdummy" | "light_client"`.
`DeploymentPos` is equivalent to `"testdummy" | "light_client" | "cells_commitments"`.

* Dummy
* light client protocol
* Tranaction output commitments


### Type `DeploymentState`
Expand Down
Loading