-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related #1605. VM PR FuelLabs/fuel-vm#670. This PR adds DA compression crate for Fuel blocks, performed upon block creation. The compressed blocks are stored into the offchain database and can be fetched using the GraphQL API. ## Note for reviewers To keep this reasonably compact, decompression support is not included in this PR, and will be done as a follow-up. As a result, the full data roundtrip testing is not part of this PR. There's no proof here that compression of full blocks is reversible. ## TODO #### Features - [x] Temporal registry db support - [x] Optimize temporal registry eviction implementation - [x] Implement TxId ↔ TxPointer lookups - [x] Integrate with the block committer (GraphQL interface, probably) #### Tests - [x] compressed blocks are available from non-block-producer nodes - [ ] e2e test for the full decompression cycle (moved to a follow-up) ## Follow-up issues - Sync the node from L1: #2208 - Decompression roudntrip tests #2238 - Figure out which cache eviction algorithm/behavior is wanted: #2231 - Figure out if we need to remove the compressed blocks from the db after a while - Merkle roots for fraud proofs #2232 --------- Co-authored-by: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Co-authored-by: Green Baneling <XgreenX9999@gmail.com> Co-authored-by: Rafał Chabowski <88321181+rafal-ch@users.noreply.github.com>
- Loading branch information
1 parent
301fb60
commit 1ec05a9
Showing
53 changed files
with
2,317 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use crate::client::schema::{ | ||
schema, | ||
U32, | ||
}; | ||
|
||
use super::HexString; | ||
|
||
#[derive(cynic::QueryVariables, Debug)] | ||
pub struct DaCompressedBlockByHeightArgs { | ||
pub height: U32, | ||
} | ||
|
||
#[derive(cynic::QueryFragment, Clone, Debug)] | ||
#[cynic( | ||
schema_path = "./assets/schema.sdl", | ||
graphql_type = "Query", | ||
variables = "DaCompressedBlockByHeightArgs" | ||
)] | ||
pub struct DaCompressedBlockByHeightQuery { | ||
#[arguments(height: $height)] | ||
pub da_compressed_block: Option<DaCompressedBlock>, | ||
} | ||
|
||
/// Block with transaction ids | ||
#[derive(cynic::QueryFragment, Clone, Debug)] | ||
#[cynic(schema_path = "./assets/schema.sdl")] | ||
pub struct DaCompressedBlock { | ||
pub bytes: HexString, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn block_by_height_query_gql_output() { | ||
use cynic::QueryBuilder; | ||
let operation = | ||
DaCompressedBlockByHeightQuery::build(DaCompressedBlockByHeightArgs { | ||
height: U32(0), | ||
}); | ||
insta::assert_snapshot!(operation.query) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
..._core_client__client__schema__da_compressed__tests__block_by_height_query_gql_output.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
source: crates/client/src/client/schema/da_compressed.rs | ||
expression: operation.query | ||
--- | ||
query($height: U32!) { | ||
daCompressedBlock(height: $height) { | ||
bytes | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
[package] | ||
name = "fuel-core-compression" | ||
version = { workspace = true } | ||
authors = { workspace = true } | ||
categories = ["cryptography::cryptocurrencies"] | ||
edition = { workspace = true } | ||
homepage = { workspace = true } | ||
keywords = [ | ||
"blockchain", | ||
"cryptocurrencies", | ||
"fuel-core", | ||
"fuel-client", | ||
"fuel-compression", | ||
] | ||
license = { workspace = true } | ||
repository = { workspace = true } | ||
description = "Compression and decompression of Fuel blocks for DA storage." | ||
|
||
[dependencies] | ||
anyhow = { workspace = true } | ||
fuel-core-types = { workspace = true, features = [ | ||
"alloc", | ||
"serde", | ||
"da-compression", | ||
] } | ||
paste = { workspace = true } | ||
rand = { workspace = true, optional = true } | ||
serde = { version = "1.0", features = ["derive"] } | ||
strum = { workspace = true } | ||
strum_macros = { workspace = true } | ||
|
||
[dev-dependencies] | ||
fuel-core-compression = { path = ".", features = ["test-helpers"] } | ||
postcard = { version = "1.0", features = ["use-std"] } | ||
proptest = { workspace = true } | ||
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } | ||
|
||
[features] | ||
test-helpers = [ | ||
"dep:rand", | ||
"fuel-core-types/test-helpers", | ||
"fuel-core-types/random", | ||
"fuel-core-types/std", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Compression and decompression of transactions for the DA layer | ||
|
||
## Compressed block header | ||
|
||
Each compressed block begins with a version field, so that it's possible to change the format later. | ||
|
||
## Temporal registry | ||
|
||
This crate provides offchain registries for different types such as `AssetId`, `ContractId`, scripts, and predicates. Each registry is a key-value store with three-byte key. The registries are essentially compression caches. The three byte key allows cache size of 16 million values before reregistering the older values. | ||
|
||
The registries allow replacing repeated objects with their respective keys, so if an object | ||
is used multiple times in a short interval (couple of months, maybe), then the full value | ||
exists on only a single uncompressed block. | ||
|
||
### Fraud proofs | ||
|
||
Compressed block will contain a merkle root over all compression smts, followed by newly registered values along with their keys. Using an SMT provides flexibility around the algorithm we use to define keys without knowing how exactly values were chosen to be registered. | ||
|
||
Each registry also uses an SMT. Since the keys are three bytes long, the depth of the SMT is capped at 24 levels. | ||
|
||
## Compression of `UtxoIds` | ||
|
||
Since each `UtxoId` only appears once, there's no point in registering them. Instead, they are replaced with `TxPointer` and output index, which are still unique. | ||
|
||
### Fraud proofs | ||
|
||
During fraud proofs we need to use the `prev_root` to prove that the referenced block height is part of the chain. |
Oops, something went wrong.