diff --git a/Cargo.lock b/Cargo.lock index ce22aaa7..f4e41094 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -821,7 +821,6 @@ dependencies = [ "multiaddr", "multihash", "nmt-rs", - "proptest", "rand", "ruint", "serde", diff --git a/ci/Dockerfile.bridge b/ci/Dockerfile.bridge index 463e0ab8..0e20633b 100644 --- a/ci/Dockerfile.bridge +++ b/ci/Dockerfile.bridge @@ -1,15 +1,15 @@ # A dockerfile for the celestia bridge node in DA layer # Based on: # https://github.com/celestiaorg/celestia-node/blob/main/Dockerfile -FROM docker.io/alpine:3.18.3 +FROM docker.io/alpine:3.19.1 ENV CELESTIA_HOME=/root RUN apk update && apk add --no-cache bash jq # Copy in the binary -COPY --from=ghcr.io/celestiaorg/celestia-node:v0.12.0 /bin/celestia /bin/celestia -COPY --from=ghcr.io/celestiaorg/celestia-node:v0.12.0 /bin/cel-key /bin/cel-key +COPY --from=ghcr.io/celestiaorg/celestia-node:v0.13.1 /bin/celestia /bin/celestia +COPY --from=ghcr.io/celestiaorg/celestia-node:v0.13.1 /bin/cel-key /bin/cel-key COPY ./run-bridge.sh /opt/entrypoint.sh diff --git a/ci/Dockerfile.validator b/ci/Dockerfile.validator index 7ef44edd..0b9e29cb 100644 --- a/ci/Dockerfile.validator +++ b/ci/Dockerfile.validator @@ -1,14 +1,14 @@ # A dockerfile for the celestia validator in consensus layer # Based on: # https://github.com/celestiaorg/celestia-app/blob/main/Dockerfile -FROM docker.io/alpine:3.18.3 +FROM docker.io/alpine:3.19.1 ENV CELESTIA_HOME=/root RUN apk update && apk add --no-cache bash jq # Copy in the binary -COPY --from=ghcr.io/celestiaorg/celestia-app:v1.3.0 /bin/celestia-appd /bin/celestia-appd +COPY --from=ghcr.io/celestiaorg/celestia-app:v1.7.0 /bin/celestia-appd /bin/celestia-appd COPY ./run-validator.sh /opt/entrypoint.sh diff --git a/ci/run-bridge.sh b/ci/run-bridge.sh index 3953edb2..0b6b4f70 100755 --- a/ci/run-bridge.sh +++ b/ci/run-bridge.sh @@ -67,6 +67,7 @@ main() { # Start the bridge node echo "Configuration finished. Running a bridge node..." celestia bridge start \ + --rpc.addr 0.0.0.0 \ --core.ip validator \ --keyring.accname "$NODE_NAME" \ --p2p.network "$P2P_NETWORK" diff --git a/rpc/README.md b/rpc/README.md index 66c3332e..a8742a0b 100644 --- a/rpc/README.md +++ b/rpc/README.md @@ -7,7 +7,7 @@ This crate builds on top of the [`jsonrpsee`](https://docs.rs/jsonrpsee) clients ```rust,no_run use celestia_rpc::{BlobClient, Client}; use celestia_types::{Blob, nmt::Namespace}; -use celestia_types::blob::SubmitOptions; +use celestia_types::blob::GasPrice; async fn submit_blob() { // create a client to the celestia node @@ -22,7 +22,7 @@ async fn submit_blob() { .expect("Failed to create a blob"); // submit it - client.blob_submit(&[blob], SubmitOptions::default()) + client.blob_submit(&[blob], GasPrice::default()) .await .expect("Failed submitting the blob"); } diff --git a/rpc/src/blob.rs b/rpc/src/blob.rs index 63d1b64c..2df49d24 100644 --- a/rpc/src/blob.rs +++ b/rpc/src/blob.rs @@ -1,5 +1,5 @@ use celestia_types::nmt::{Namespace, NamespaceProof}; -use celestia_types::{blob::SubmitOptions, Blob, Commitment}; +use celestia_types::{blob::GasPrice, Blob, Commitment}; use jsonrpsee::proc_macros::rpc; #[rpc(client)] @@ -39,5 +39,5 @@ pub trait Blob { /// Submit sends Blobs and reports the height in which they were included. Allows sending multiple Blobs atomically synchronously. Uses default wallet registered on the Node. #[method(name = "blob.Submit")] - async fn blob_submit(&self, blobs: &[Blob], opts: SubmitOptions) -> Result; + async fn blob_submit(&self, blobs: &[Blob], gas_price: GasPrice) -> Result; } diff --git a/rpc/tests/utils/client.rs b/rpc/tests/utils/client.rs index fcacac63..1a56efbc 100644 --- a/rpc/tests/utils/client.rs +++ b/rpc/tests/utils/client.rs @@ -4,7 +4,7 @@ use std::sync::OnceLock; use anyhow::Result; use celestia_rpc::prelude::*; use celestia_rpc::Client; -use celestia_types::{blob::SubmitOptions, Blob}; +use celestia_types::{blob::GasPrice, Blob}; use jsonrpsee::core::client::ClientT; use jsonrpsee::core::Error; use tokio::sync::{Mutex, MutexGuard}; @@ -55,5 +55,5 @@ where C: ClientT + Sync, { let _guard = write_lock().await; - client.blob_submit(blobs, SubmitOptions::default()).await + client.blob_submit(blobs, GasPrice::default()).await } diff --git a/types/Cargo.toml b/types/Cargo.toml index 2cf82db9..fa33eda7 100644 --- a/types/Cargo.toml +++ b/types/Cargo.toml @@ -40,7 +40,6 @@ thiserror = "1.0.40" [dev-dependencies] ed25519-consensus = "2.1.0" -proptest = { version = "1.2.0", default-features = false, features = ["std"] } rand = "0.8.5" serde_json = "1.0.97" diff --git a/types/src/blob.rs b/types/src/blob.rs index fde67e65..f79fefb1 100644 --- a/types/src/blob.rs +++ b/types/src/blob.rs @@ -9,24 +9,30 @@ mod commitment; pub use self::commitment::Commitment; use crate::consts::appconsts; use crate::nmt::Namespace; -use crate::serializers::none_as_negative_one; use crate::{bail_validation, Error, Result, Share}; -/// Options for configuring the blob submission to the network. +/// GasPrice represents the amount to be paid per gas unit. /// -/// If no options are provided, then the default ones will be used. +/// Fee is set by multiplying GasPrice by GasLimit, which is determined by the blob sizes. +/// If no value is provided, then this will be serialized to `-1.0` which means the node that +/// receives the request will calculate the GasPrice for given blob. /// Read more about the mechanisms of fees and gas usage in [`submitting data blobs`]. /// /// [`submitting data blobs`]: https://docs.celestia.org/developers/submit-data#fees-and-gas-limits -#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] -#[serde(rename_all = "PascalCase")] -pub struct SubmitOptions { - /// A fee for the validator. Transactions will be prioritized based on their fees. - #[serde(with = "none_as_negative_one")] - pub fee: Option, - /// A maximum gas amount that can be used by a validator when trying to include the - /// transaction. - pub gas_limit: Option, +#[derive(Debug, Default, Copy, Clone, PartialEq, Serialize, Deserialize)] +#[serde(transparent)] +pub struct GasPrice(#[serde(with = "gas_prize_serde")] Option); + +impl From for GasPrice { + fn from(value: f64) -> Self { + Self(Some(value)) + } +} + +impl From> for GasPrice { + fn from(value: Option) -> Self { + Self(value) + } } /// Arbitrary data that can be stored in the network within certain [`Namespace`]. @@ -179,6 +185,27 @@ impl From for RawBlob { } } +mod gas_prize_serde { + use serde::{Deserialize, Deserializer, Serializer}; + + /// Serialize [`Option`] with `None` represented as `-1` + pub fn serialize(value: &Option, serializer: S) -> Result + where + S: Serializer, + { + let x = value.unwrap_or(-1.0); + serializer.serialize_f64(x) + } + + /// Deserialize [`Option`] with an error when the value is not present. + pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> + where + D: Deserializer<'de>, + { + f64::deserialize(deserializer).map(Some) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/types/src/lib.rs b/types/src/lib.rs index 66115717..f75f70d3 100644 --- a/types/src/lib.rs +++ b/types/src/lib.rs @@ -18,7 +18,6 @@ pub mod p2p; pub mod row; mod rsmt2d; pub mod sample; -pub(crate) mod serializers; mod share; pub mod state; mod sync; diff --git a/types/src/serializers.rs b/types/src/serializers.rs deleted file mode 100644 index 21b14c51..00000000 --- a/types/src/serializers.rs +++ /dev/null @@ -1,67 +0,0 @@ -pub(crate) mod none_as_negative_one { - use serde::{Deserialize, Deserializer, Serializer}; - - /// Deserialize [`Option`] with negative numbers represented as `None` - pub(crate) fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> - where - D: Deserializer<'de>, - { - let value = Option::::deserialize(deserializer)?; - let value = match value { - Some(..=-1) => None, - Some(x) => Some(u64::try_from(x).map_err(serde::de::Error::custom)?), - None => None, - }; - Ok(value) - } - - /// Serialize [`Option`] with `None` represented as `-1` - pub(crate) fn serialize(value: &Option, serializer: S) -> Result - where - S: Serializer, - { - let x = value.map(|x| x as i128).unwrap_or(-1); - serializer.serialize_i128(x) - } - - #[cfg(test)] - mod tests { - #[cfg(not(target_arch = "wasm32"))] - use proptest::prelude::*; - use serde::{Deserialize, Serialize}; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::wasm_bindgen_test as test; - - #[derive(Serialize, Deserialize, PartialEq, Eq)] - #[serde(transparent)] - struct OptionU64(#[serde(with = "super")] Option); - - #[test] - fn serialize_none_as_negative_one() { - let x = OptionU64(None); - let serialized = serde_json::to_string(&x).unwrap(); - - assert_eq!(&serialized, "-1"); - } - - #[cfg(not(target_arch = "wasm32"))] - proptest! { - #[test] - fn deserialize_negative(x in i64::MIN..0) { - let x = format!("{x}"); - let opt_u64: OptionU64 = serde_json::from_str(&x).unwrap(); - - assert_eq!(opt_u64.0, None); - } - - #[test] - fn serialize_deserialize(x: Option) { - let serialized = serde_json::to_string(&OptionU64(x)).unwrap(); - let deserialized: OptionU64 = serde_json::from_str(&serialized).unwrap(); - - assert_eq!(x, deserialized.0); - } - } - } -}