-
Notifications
You must be signed in to change notification settings - Fork 59
feat!: implement fibre #942
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
Open
mcrakhman
wants to merge
31
commits into
main
Choose a base branch
from
mcrakhman/fibre
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
5ba1d2a
feat: update protos from fibre
mcrakhman ad4bddc
feat: implement fibre
mcrakhman f3b7984
feat: wasm support
mcrakhman 5cca018
feat: replace grpc contents
mcrakhman 753e5f2
fix: use correct urls
mcrakhman 8f07565
fix: remove double hashing
mcrakhman 4b631db
fix: correct timestamp marshaling
mcrakhman 580a083
fix: correctly randomize vals
mcrakhman a113c38
fix: validator proto signing
mcrakhman be3ace0
fix: map to correct inidices
mcrakhman 9d84e33
refactor: different stuff
mcrakhman d2babaa
Merge branch 'main' into mcrakhman/fibre
mcrakhman 26a13fd
feat: encode in place
mcrakhman 27ee926
refactor: remove encode to rows
mcrakhman 50993a0
feat: refactor fibre to use grpc client
mcrakhman 2a5bab0
feat: remove some allocs on download
mcrakhman 8de6275
refactor: split into folders
mcrakhman beeac72
refactor: download and upload logic
mcrakhman d10c036
feat: update payment promise signing
mcrakhman 2230b06
Merge branch 'main' into mcrakhman/fibre
mcrakhman 8e66964
feat: remove signing key
mcrakhman a346430
feat: proof in separate routine
mcrakhman f6fecbd
feat: use task
mcrakhman e904111
fix: comments
mcrakhman 69275de
fix: fmt
mcrakhman 196e1ab
fix: ci
mcrakhman f180611
fix: ci and docs
mcrakhman 91e858f
fix: review
mcrakhman d3f619c
fix: fmt
mcrakhman c223f85
fix: review
mcrakhman 378da09
fix: continue uploading stuff
mcrakhman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,92 @@ | ||
| //! Fibre API for off-chain data availability. | ||
| //! | ||
| //! The [`FibreApi`] wraps a [`celestia_fibre::FibreClient`] to provide | ||
| //! `put()` and `download()` operations through the celestia-client. | ||
|
|
||
| use std::sync::Arc; | ||
|
|
||
| use celestia_fibre::{Blob, BlobID, FibreClient, FibreError, PreparedPut}; | ||
| use celestia_grpc::{SubmittedTx, TxConfig}; | ||
| use k256::ecdsa::SigningKey; | ||
|
|
||
| use crate::Error; | ||
| use crate::client::ClientInner; | ||
|
|
||
| /// Fibre API for off-chain data availability. | ||
| /// | ||
| /// Provides access to the Fibre DA protocol for uploading and downloading | ||
| /// blobs directly to/from validators, bypassing on-chain blob submission. | ||
| pub struct FibreApi { | ||
| inner: Arc<ClientInner>, | ||
| fibre_client: Arc<FibreClient>, | ||
| } | ||
|
|
||
| impl FibreApi { | ||
| pub(crate) fn new(inner: Arc<ClientInner>, fibre_client: FibreClient) -> Self { | ||
| Self { | ||
| inner, | ||
| fibre_client: Arc::new(fibre_client), | ||
| } | ||
| } | ||
|
|
||
| /// Upload data and broadcast `MsgPayForFibre` on-chain. | ||
| /// | ||
| /// Encodes the data into a blob, distributes it to validators via the | ||
| /// Fibre protocol, collects signatures, and broadcasts a `MsgPayForFibre` | ||
| /// transaction. Returns the prepared put data and a [`SubmittedTx`] handle | ||
| /// that can be used to confirm the transaction. | ||
| /// | ||
| /// Requires the client to have a gRPC endpoint and signer configured. | ||
| pub async fn put( | ||
| &self, | ||
| signing_key: &SigningKey, | ||
| namespace: &[u8], | ||
| data: &[u8], | ||
| ) -> Result<(PreparedPut, SubmittedTx), Error> { | ||
| let grpc = self.inner.grpc()?; | ||
| let signer_address = grpc | ||
| .get_account_address() | ||
| .ok_or(Error::NoAssociatedAddress)?; | ||
|
|
||
| let prepared = self | ||
| .fibre_client | ||
| .put(signing_key, namespace, data, &signer_address.to_string()) | ||
| .await | ||
| .map_err(fibre_err)?; | ||
|
|
||
| let submitted = grpc | ||
| .broadcast_message(prepared.msg.clone(), TxConfig::default()) | ||
| .await?; | ||
|
|
||
| Ok((prepared, submitted)) | ||
| } | ||
|
|
||
| /// Download and reconstruct a blob by its [`BlobID`]. | ||
| /// | ||
| /// Fetches row proofs from validators and reconstructs the original data | ||
| /// using erasure coding. | ||
| pub async fn download(&self, id: &BlobID) -> Result<Blob, FibreError> { | ||
| self.fibre_client.download(id).await | ||
| } | ||
|
|
||
| /// Returns `true` if the underlying fibre client has been closed. | ||
| pub fn is_closed(&self) -> bool { | ||
| self.fibre_client.is_closed() | ||
| } | ||
|
|
||
| /// Close the underlying fibre client. | ||
| pub fn close(&self) { | ||
| self.fibre_client.close(); | ||
| } | ||
| } | ||
|
|
||
| /// Convert a [`FibreError`] into the client [`Error`] type. | ||
| fn fibre_err(e: FibreError) -> Error { | ||
| match e { | ||
| FibreError::Grpc(status) => Error::Grpc(celestia_grpc::Error::from(*status)), | ||
| FibreError::GrpcClient(grpc_err) => Error::Grpc(grpc_err), | ||
| #[cfg(not(target_arch = "wasm32"))] | ||
| FibreError::Transport(t) => Error::Grpc(celestia_grpc::Error::from(t)), | ||
| other => Error::Fibre(other), | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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,47 @@ | ||
| [package] | ||
| name = "celestia-fibre" | ||
| version.workspace = true | ||
| edition.workspace = true | ||
| license = "Apache-2.0" | ||
| description = "Client library for the Celestia Fibre data availability protocol" | ||
| authors = ["Celestia <contact@celestia.org>"] | ||
| homepage = "https://www.celestia.org" | ||
| repository = "https://github.com/celestiaorg/lumina" | ||
| rust-version = "1.88" | ||
|
|
||
| [dependencies] | ||
| celestia-grpc.workspace = true | ||
| celestia-proto = { workspace = true, features = ["tonic"] } | ||
| celestia-types.workspace = true | ||
| rsema1d.workspace = true | ||
|
|
||
| # Crypto | ||
| k256 = { workspace = true, features = ["ecdsa"] } | ||
| ed25519-dalek = { version = "2.1", features = ["digest"] } | ||
| sha2 = "0.10.8" | ||
| rand.workspace = true | ||
| chacha8rand = "0.1.2" | ||
|
|
||
| # Async runtime | ||
| tokio = { workspace = true, features = ["sync", "macros"] } | ||
| tokio-util.workspace = true | ||
| futures.workspace = true | ||
| lumina-utils = { workspace = true, features = ["executor"] } | ||
|
|
||
| # gRPC | ||
| tonic = { workspace = true, features = ["codegen"] } | ||
| prost.workspace = true | ||
| tendermint-proto.workspace = true | ||
|
|
||
| # Error handling and utilities | ||
| thiserror.workspace = true | ||
| tracing.workspace = true | ||
| hex.workspace = true | ||
| async-trait.workspace = true | ||
| bech32 = "0.11" | ||
|
|
||
| [target.'cfg(not(target_arch = "wasm32"))'.dependencies] | ||
| tonic = { workspace = true, features = ["transport"] } | ||
|
|
||
| [dev-dependencies] | ||
| tokio = { workspace = true, features = ["rt-multi-thread", "macros", "test-util"] } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.