Skip to content

Commit

Permalink
chore!(types,rpc): compatibility with celestia-node 0.13.1 (#239)
Browse files Browse the repository at this point in the history
* chore: update the ci setup for 0.13.0

* feat!(types,rpc): Replace SubmitOptions with GasPrice

* update images

* cleanup serializers

* revert changes to container ports

* remove unused dev dependency

* Update types/src/blob.rs

Co-authored-by: Yiannis Marangos <[email protected]>
Signed-off-by: Maciej Zwoliński <[email protected]>

---------

Signed-off-by: Maciej Zwoliński <[email protected]>
Co-authored-by: Yiannis Marangos <[email protected]>
  • Loading branch information
zvolin and oblique authored Mar 11, 2024
1 parent 0936723 commit 3f845dd
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 93 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

6 changes: 3 additions & 3 deletions ci/Dockerfile.bridge
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions ci/Dockerfile.validator
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions ci/run-bridge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");
}
Expand Down
4 changes: 2 additions & 2 deletions rpc/src/blob.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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<u64, Error>;
async fn blob_submit(&self, blobs: &[Blob], gas_price: GasPrice) -> Result<u64, Error>;
}
4 changes: 2 additions & 2 deletions rpc/tests/utils/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
}
1 change: 0 additions & 1 deletion types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
51 changes: 39 additions & 12 deletions types/src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>,
/// A maximum gas amount that can be used by a validator when trying to include the
/// transaction.
pub gas_limit: Option<u64>,
#[derive(Debug, Default, Copy, Clone, PartialEq, Serialize, Deserialize)]
#[serde(transparent)]
pub struct GasPrice(#[serde(with = "gas_prize_serde")] Option<f64>);

impl From<f64> for GasPrice {
fn from(value: f64) -> Self {
Self(Some(value))
}
}

impl From<Option<f64>> for GasPrice {
fn from(value: Option<f64>) -> Self {
Self(value)
}
}

/// Arbitrary data that can be stored in the network within certain [`Namespace`].
Expand Down Expand Up @@ -179,6 +185,27 @@ impl From<Blob> for RawBlob {
}
}

mod gas_prize_serde {
use serde::{Deserialize, Deserializer, Serializer};

/// Serialize [`Option<f64>`] with `None` represented as `-1`
pub fn serialize<S>(value: &Option<f64>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let x = value.unwrap_or(-1.0);
serializer.serialize_f64(x)
}

/// Deserialize [`Option<f64>`] with an error when the value is not present.
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<f64>, D::Error>
where
D: Deserializer<'de>,
{
f64::deserialize(deserializer).map(Some)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
1 change: 0 additions & 1 deletion types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
67 changes: 0 additions & 67 deletions types/src/serializers.rs

This file was deleted.

0 comments on commit 3f845dd

Please sign in to comment.