Skip to content

Commit 9034f37

Browse files
pepyakinrphmeier
authored andcommitted
follow up namespace type extension
Follow up to #115 Related #12
1 parent 4ec3546 commit 9034f37

File tree

12 files changed

+2125
-1728
lines changed

12 files changed

+2125
-1728
lines changed

adapters/sovereign/src/spec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
88
pub struct DaLayerSpec;
99

1010
pub struct ChainParams {
11-
pub namespace_id: [u8; 4],
11+
pub namespace_id: [u8; sugondat_nmt::NS_ID_SIZE],
1212
}
1313

1414
impl sov_rollup_interface::da::DaSpec for DaLayerSpec {

adapters/sovereign/src/verifier.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use sov_rollup_interface::{
66
da::{BlockHeaderTrait, DaSpec, DaVerifier},
77
zk::ValidityCondition,
88
};
9-
use sugondat_nmt::Namespace;
9+
use sugondat_nmt::{Namespace, NS_ID_SIZE};
1010

1111
/// A validity condition expressing that a chain of DA layer blocks is contiguous and canonical
1212
#[derive(
@@ -44,7 +44,7 @@ pub struct SugondatVerifier {
4444
// is needed a way to create the verifier without knowing the trait DaVerifier,
4545
// so without new method
4646
impl SugondatVerifier {
47-
pub fn from_raw(raw_namespace_id: [u8; 4]) -> Self {
47+
pub fn from_raw(raw_namespace_id: [u8; NS_ID_SIZE]) -> Self {
4848
Self {
4949
namespace: Namespace::from_raw_bytes(raw_namespace_id),
5050
}

demo/rollkit/init-local.sh

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ TOKEN_AMOUNT="10000000000000000000000000stake"
1010
STAKING_AMOUNT="1000000000stake"
1111

1212
# create a random Namespace ID for your rollup to post blocks to
13-
NAMESPACE=01020304
13+
NAMESPACE=01020304050607080910111213141516
1414

1515
# query the DA Layer start height, in this case we are querying
1616
# our local devnet at port 26657, the RPC. The RPC endpoint is
@@ -22,32 +22,32 @@ DA_BLOCK_HEIGHT=1
2222
# rollkit logo
2323
cat <<'EOF'
2424
25-
:=+++=.
26-
-++- .-++:
27-
.=+=. :++-.
28-
-++- .=+=: .
29-
.=+=: -%@@@*
30-
+%- .=#@@@@@@*
31-
-++- -*%@@@@@@%+:
32-
.=*=. .=#@@@@@@@%=.
33-
-++-.-++: =*#@@@@@%+:.-++-=-
34-
.=+=. :=+=.-: @@#=. .-*@@@@%
35-
=*=: .-==+- :+#@@@@@@%-
36-
:++- -*@@@@@@@#=:
37-
=%+=. .=#@@@@@@@#%:
38-
-++: -++- *+=@@@@%+: =#*##-
39-
=*=. :=+=---@*=. .=*@@@@@%
40-
.-+=: :-: :+%@@@@@@%+.
41-
:=+- -*@@@@@@@#=.
42-
.=+=: .=#@@@@@@%*-
43-
-++- *=.@@@#+:
44-
.====+*-.
45-
46-
______ _ _ _ _ _
47-
| ___ \ | || || | (_)| |
48-
| |_/ / ___ | || || | __ _ | |_
25+
:=+++=.
26+
-++- .-++:
27+
.=+=. :++-.
28+
-++- .=+=: .
29+
.=+=: -%@@@*
30+
+%- .=#@@@@@@*
31+
-++- -*%@@@@@@%+:
32+
.=*=. .=#@@@@@@@%=.
33+
-++-.-++: =*#@@@@@%+:.-++-=-
34+
.=+=. :=+=.-: @@#=. .-*@@@@%
35+
=*=: .-==+- :+#@@@@@@%-
36+
:++- -*@@@@@@@#=:
37+
=%+=. .=#@@@@@@@#%:
38+
-++: -++- *+=@@@@%+: =#*##-
39+
=*=. :=+=---@*=. .=*@@@@@%
40+
.-+=: :-: :+%@@@@@@%+.
41+
:=+- -*@@@@@@@#=.
42+
.=+=: .=#@@@@@@%*-
43+
-++- *=.@@@#+:
44+
.====+*-.
45+
46+
______ _ _ _ _ _
47+
| ___ \ | || || | (_)| |
48+
| |_/ / ___ | || || | __ _ | |_
4949
| / / _ \ | || || |/ /| || __|
50-
| |\ \ | (_) || || || < | || |_
50+
| |\ \ | (_) || || || < | || |_
5151
\_| \_| \___/ |_||_||_|\_\|_| \__|
5252
EOF
5353

demo/rollkit/restart-local.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
DA_BLOCK_HEIGHT=1
2-
NAMESPACE=01020304
2+
NAMESPACE=01020304050607080910111213141516
33
AUTH_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJwdWJsaWMiLCJyZWFkIiwid3JpdGUiLCJhZG1pbiJdfQ.mj7taF7Z9ZcTN2hhC1-cLf5SmqQd-ZA4YVZymd3-Ato
4-
gmd start --rollkit.aggregator true --rollkit.da_layer sugondat --rollkit.da_config='{"base_url":"http://localhost:10995","namespace":"01020304"}' --rollkit.namespace_id $NAMESPACE --rollkit.da_start_height $DA_BLOCK_HEIGHT --rpc.laddr tcp://127.0.0.1:36657 --p2p.laddr "0.0.0.0:36656"
4+
gmd start --rollkit.aggregator true --rollkit.da_layer sugondat --rollkit.da_config='{"base_url":"http://localhost:10995","namespace":"01020304050607080910111213141516"}' --rollkit.namespace_id $NAMESPACE --rollkit.da_start_height $DA_BLOCK_HEIGHT --rpc.laddr tcp://127.0.0.1:36657 --p2p.laddr "0.0.0.0:36656"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/// The namespace used by the rollup to store its data. This is a raw slice of 8 bytes.
22
/// The rollup stores its data in the namespace b"sov-test" on Celestia. Which in this case is encoded using the
33
/// ascii representation of each character.
4-
pub const ROLLUP_NAMESPACE_RAW: [u8; 4] = [3, 0, 0, 0];
4+
pub const ROLLUP_NAMESPACE_RAW: [u8; 16] = 3_u128.to_be_bytes();

sugondat-nmt/src/ns.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ impl Namespace {
2828
self.0
2929
}
3030

31-
/// A convenience function to create a namespace from an unsigned 32-bit integer.
31+
/// A convenience function to create a namespace from an unsigned 128-bit integer.
3232
///
3333
/// This function will take the given integer (which is assumed to be in host byte order), and
3434
/// take its big-endian representation as the namespace ID.
3535
pub fn from_u128_be(namespace_id: u128) -> Self {
3636
Self(namespace_id.to_be_bytes())
3737
}
3838

39-
/// Reinterpret the namespace ID as a big-endian 32-bit integer and return.
39+
/// Reinterpret the namespace ID as a big-endian 128-bit integer and return.
4040
pub fn to_u128_be(&self) -> u128 {
4141
u128::from_be_bytes(self.0)
4242
}
@@ -54,7 +54,7 @@ impl Namespace {
5454

5555
impl fmt::Display for Namespace {
5656
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57-
// Print the namespace as a 4-byte hex string. We don't use `hex` crate here to avoid
57+
// Print the namespace as a 16-byte hex string. We don't use `hex` crate here to avoid
5858
// extra dependencies.
5959
write!(f, "0x")?;
6060
for byte in self.to_raw_bytes().iter() {

sugondat-shim/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ pub mod query {
166166

167167
/// The namespace to submit the blob into.
168168
///
169-
/// The namespace can be specified either as a 4-byte vector, or as an unsigned 32-bit
169+
/// The namespace can be specified either as a 16-byte vector, or as an unsigned 128-bit
170170
/// big-endian integer. To distinguish between the two, the byte vector must be prefixed
171171
/// with `0x`.
172172
#[clap(long, short, env = ENV_SUGONDAT_NAMESPACE)]

sugondat-shim/src/cmd/query/submit.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,22 @@ fn read_blob(path: &str) -> anyhow::Result<Vec<u8>> {
4040

4141
/// Reads the namespace from a given namespace specifier.
4242
///
43-
/// The original namespace format is a 4-byte vector. so we support both the original format and
44-
/// a more human-readable format, which is an unsigned 32-bit integer. To distinguish between the
43+
/// The original namespace format is a 16-byte vector. so we support both the original format and
44+
/// a more human-readable format, which is an unsigned 128-bit integer. To distinguish between the
4545
/// two, the byte vector must be prefixed with `0x`.
4646
///
4747
/// The integer is interpreted as big-endian.
4848
fn read_namespace(namespace: &str) -> anyhow::Result<sugondat_nmt::Namespace> {
4949
if let Some(hex) = namespace.strip_prefix("0x") {
5050
let namespace = hex::decode(hex)?;
51-
let namespace: [u8; 4] = namespace.try_into().map_err(|e: Vec<u8>| {
52-
anyhow::anyhow!("namespace must be 4 bytes long, but was {}", e.len())
51+
let namespace: [u8; 16] = namespace.try_into().map_err(|e: Vec<u8>| {
52+
anyhow::anyhow!("namespace must be 16 bytes long, but was {}", e.len())
5353
})?;
5454
return Ok(sugondat_nmt::Namespace::from_raw_bytes(namespace));
5555
}
5656

5757
let namespace_id = namespace
58-
.parse::<u32>()
58+
.parse::<u128>()
5959
.with_context(|| format!("cannot parse namespace id '{}'", namespace))?;
60-
Ok(sugondat_nmt::Namespace::from_u32_be(namespace_id))
60+
Ok(sugondat_nmt::Namespace::from_u128_be(namespace_id))
6161
}

sugondat-shim/src/dock/rollkit.rs

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,52 @@ impl RollkitRPCServer for RollkitDock {
6565

6666
/// Parses the namespace from a given string encoded as hex.
6767
///
68-
/// Note that rollkit uses arbitrary length namespaces, but sugondat uses 4-byte namespaces. For
69-
/// now, we would silently truncate or pad the namespace to 4 bytes.
68+
/// Note that rollkit uses arbitrary length namespaces, but sugondat uses 16-byte namespaces. For
69+
/// now, we would silently truncate or pad the namespace to 16 bytes.
7070
fn parse_namespace(namespace: &str) -> anyhow::Result<sugondat_nmt::Namespace> {
71+
use sugondat_nmt::NS_ID_SIZE;
7172
let namespace_bytes = hex::decode(namespace)?;
7273
let namespace_bytes = match namespace_bytes.len() {
7374
0 => anyhow::bail!("namespace must not be empty"),
74-
1..=4 => {
75+
1..=NS_ID_SIZE => {
7576
let mut namespace_bytes = namespace_bytes;
76-
namespace_bytes.resize(4, 0);
77+
namespace_bytes.resize(NS_ID_SIZE, 0);
7778
namespace_bytes
7879
}
79-
5.. => {
80+
_ => {
8081
let mut namespace_bytes = namespace_bytes;
81-
namespace_bytes.truncate(4);
82+
namespace_bytes.truncate(NS_ID_SIZE);
8283
namespace_bytes
8384
}
84-
_ => unreachable!(),
8585
};
8686
Ok(sugondat_nmt::Namespace::from_raw_bytes(
8787
namespace_bytes.try_into().unwrap(),
8888
))
8989
}
90+
91+
#[test]
92+
fn test_parse_namespace() {
93+
use sugondat_nmt::NS_ID_SIZE;
94+
assert!(parse_namespace("").is_err());
95+
assert!(parse_namespace("").is_err());
96+
assert_eq!(
97+
parse_namespace("00").unwrap(),
98+
sugondat_nmt::Namespace::from_raw_bytes([0; NS_ID_SIZE])
99+
);
100+
assert_eq!(
101+
parse_namespace("00").unwrap(),
102+
sugondat_nmt::Namespace::from_raw_bytes([0; NS_ID_SIZE])
103+
);
104+
assert_eq!(
105+
parse_namespace("FF").unwrap(),
106+
sugondat_nmt::Namespace::from_raw_bytes({
107+
let mut bytes = [0; NS_ID_SIZE];
108+
bytes[0] = 0xFF;
109+
bytes
110+
})
111+
);
112+
assert_eq!(
113+
parse_namespace("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00" /* 17 bytes */).unwrap(),
114+
sugondat_nmt::Namespace::from_raw_bytes([0xFF; NS_ID_SIZE])
115+
);
116+
}

sugondat-shim/src/sugondat_rpc/conn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ impl Conn {
4040
/// Tries to find the `Blob` pallet in the runtime metadata. If it's not there, then we are not
4141
/// connected to a Sugondat node.
4242
fn check_if_compatible(client: &sugondat_subxt::Client) -> anyhow::Result<()> {
43-
assert!(sugondat_subxt::sugondat::PALLETS.contains(&"Blob"));
44-
if let Some(pallet) = client.metadata().pallet_by_name("Blob") {
43+
assert!(sugondat_subxt::sugondat::PALLETS.contains(&"Blobs"));
44+
if let Some(pallet) = client.metadata().pallet_by_name("Blobs") {
4545
if pallet.call_variant_by_name("submit_blob").is_some() {
4646
return Ok(());
4747
}

sugondat-shim/src/sugondat_rpc/mod.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use anyhow::Context;
55
use subxt::{rpc_params, utils::H256};
66
use sugondat_nmt::Namespace;
77
use sugondat_subxt::{
8-
sugondat::runtime_types::bounded_collections::bounded_vec::BoundedVec, Header,
8+
sugondat::runtime_types::pallet_sugondat_blobs::namespace_param::UnvalidatedNamespace, Header,
99
};
1010
use tokio::sync::watch;
1111
use tracing::Level;
@@ -163,10 +163,9 @@ impl Client {
163163
namespace: sugondat_nmt::Namespace,
164164
key: Keypair,
165165
) -> anyhow::Result<[u8; 32]> {
166-
let namespace_id = namespace.to_u32_be();
167166
let extrinsic = sugondat_subxt::sugondat::tx()
168-
.blob()
169-
.submit_blob(namespace_id, BoundedVec(blob));
167+
.blobs()
168+
.submit_blob(UnvalidatedNamespace(namespace.to_raw_bytes()), blob);
170169

171170
let conn = self.connector.ensure_connected().await;
172171
let signed = conn
@@ -204,7 +203,7 @@ fn extract_timestamp(extrinsics: &[sugondat_subxt::ExtrinsicDetails]) -> anyhow:
204203

205204
/// Iterates over the extrinsics in a block and extracts the submit_blob extrinsics.
206205
fn extract_blobs(extrinsics: Vec<sugondat_subxt::ExtrinsicDetails>) -> Vec<Blob> {
207-
use sugondat_subxt::sugondat::blob::calls::types::SubmitBlob;
206+
use sugondat_subxt::sugondat::blobs::calls::types::SubmitBlob;
208207

209208
let mut blobs = vec![];
210209
for (extrinsic_index, e) in extrinsics.iter().enumerate() {
@@ -219,11 +218,19 @@ fn extract_blobs(extrinsics: Vec<sugondat_subxt::ExtrinsicDetails>) -> Vec<Blob>
219218
// Not a submit blob extrinsic, skip.
220219
continue;
221220
};
221+
// we are scanning the extrinsics of a block, presumably, received from an RPC from a node.
222+
// The block should be from a correct chain. The STF, atm, is defined in such a way, that
223+
// it bork the block if the namespace is invalid.
224+
//
225+
// However, there is no absolute guarantee of it, because the RPC could send anything really
226+
// or the shim could be outdated. So we don't panic here.
227+
let UnvalidatedNamespace(namespace_id) = namespace_id;
228+
let namespace = sugondat_nmt::Namespace::from_raw_bytes(namespace_id);
222229
blobs.push(Blob {
223230
extrinsic_index: extrinsic_index as u32,
224-
namespace: sugondat_nmt::Namespace::from_u32_be(namespace_id),
231+
namespace,
225232
sender,
226-
data: blob.0,
233+
data: blob,
227234
})
228235
}
229236
blobs

0 commit comments

Comments
 (0)