Skip to content

Commit 433f3cb

Browse files
Mr-Leshiystevenj
andauthored
feat(rust/immutable-ledger): Replace ULID to UUID v7 for immutable-ledger (#117)
* change ULID to UUID v7 for immutable ledger design specs * remove ulid from immutable ledger crate * fix earthfile, added missing immutable-ledger * try * bump immutable-ledger crate version * try * try * fix doc tests * try --------- Co-authored-by: Steven Johnson <stevenj@users.noreply.github.com>
1 parent 1440d0b commit 433f3cb

File tree

6 files changed

+36
-42
lines changed

6 files changed

+36
-42
lines changed

docs/src/architecture/08_concepts/immutable_ledger/cddl/block.cddl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@ block = [
88
]
99

1010
block-header = [
11-
chain-id: ULID,
11+
chain-id: UUID, ; UUID v7
1212
height: int,
1313
timestamp: #6.1(uint .ge 1722470400), ; Epoch-based date/time
1414
prev-block-id: hash-bytes, ; hash of the previous block
15-
?ledger-type: UUID,
16-
?purpose-id: ULID / UUID,
15+
?ledger-type: UUID, ; UUID v4
16+
?purpose-id: UUID, ; UUID v7
1717
?validator,
1818
~metadata,
1919
]
2020

2121
block-data = encoded-cbor
2222

2323
UUID = #6.37(bytes) ; UUID type
24-
ULID = #6.32780(bytes) ; ULID type
2524

2625
kid = hash-bytes ; hash of the x509/c509 certificate
2726

docs/src/architecture/08_concepts/immutable_ledger/cddl/genesis_to_prev_hash.cddl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
; https://datatracker.ietf.org/doc/html/draft-ietf-cbor-cde-06
33

44
genesis-to-prev-hash = [
5-
chain-id: ULID,
5+
chain-id: UUID, ; UUID v7
66
timestamp: #6.1(uint .ge 1722470400), ; Epoch-based date/time
7-
ledger-type: UUID,
8-
purpose-id: ULID / UUID,
7+
ledger-type: UUID, ; UUID v4
8+
purpose-id: UUID, ; UUID v7
99
validator,
1010
]
1111

1212
UUID = #6.37(bytes) ; UUID type
13-
ULID = #6.32780(bytes) ; ULID type
1413

1514
validator = (kid / [2* kid])
1615
kid = hash-bytes ; hash of the x509/c509 certificate

rust/Earthfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ build:
5555
--cmd="/scripts/std_build.py" \
5656
--args1="--libs=c509-certificate --libs=cardano-chain-follower --libs=hermes-ipfs" \
5757
--args2="--libs=cbork-cddl-parser --libs=cbork-abnf-parser" \
58-
--args3="--libs=catalyst-voting --libs=vote-tx-v1 --libs=vote-tx-v2" \
58+
--args3="--libs=catalyst-voting --libs=immutable-ledger --libs=vote-tx-v1 --libs=vote-tx-v2" \
5959
--args4="--bins=cbork/cbork --libs=rbac-registration --libs=signed_doc" \
6060
--args5="--cov_report=$HOME/build/coverage-report.info" \
6161
--output="release/[^\./]+" \

rust/immutable-ledger/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "immutable-ledger"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
edition.workspace = true
55
authors.workspace = true
66
homepage.workspace = true
@@ -11,8 +11,7 @@ license.workspace = true
1111
ed25519-dalek = "2.1.1"
1212
anyhow = "1.0.86"
1313
minicbor = { version = "0.24", features = ["std"] }
14-
uuid = { version = "1.10.0", features = ["v4", "serde"] }
15-
ulid = { version = "1.1.3", features = ["serde", "uuid"] }
14+
uuid = { version = "1.10.0", features = ["v4", "v7", "serde"] }
1615
hex = "0.4.3"
1716
blake2b_simd = "1.0.2"
1817
blake3 = "=0.1.3"

rust/immutable-ledger/src/serialize.rs

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
55
use anyhow::{bail, Ok};
66
use blake2b_simd::{self, Params};
7-
use ulid::Ulid;
87
use uuid::Uuid;
98

109
/// Genesis block MUST have 0 value height.
@@ -70,9 +69,6 @@ const TIMESTAMP_CBOR_TAG: u64 = 1;
7069
/// CBOR tag for UUID
7170
const UUID_CBOR_TAG: u64 = 37;
7271

73-
/// CBOR tag for UUID
74-
const ULID_CBOR_TAG: u64 = 32780;
75-
7672
/// CBOR tags for BLAKE2 and BLAKE3 hash functions
7773
/// `https://github.com/input-output-hk/catalyst-voices/blob/main/docs/src/catalyst-standards/cbor_tags/blake.md`
7874
@@ -292,7 +288,7 @@ impl Block {
292288
#[derive(Debug, Clone, PartialEq)]
293289
pub struct BlockHeader {
294290
/// Unique identifier of the chain.
295-
pub chain_id: Ulid,
291+
pub chain_id: Uuid,
296292
/// Block height.
297293
pub height: i64,
298294
/// Block epoch-based date/time.
@@ -305,7 +301,7 @@ pub struct BlockHeader {
305301
pub ledger_type: Uuid,
306302
/// unique identifier of the purpose, each Ledger instance will have a strict time
307303
/// boundaries, so each of them will run for different purposes.
308-
pub purpose_id: Ulid,
304+
pub purpose_id: Uuid,
309305
/// Identifier or identifiers of the entity who was produced and processed a block.
310306
pub validator: Vec<Kid>,
311307
/// Add arbitrary metadata to the block.
@@ -317,8 +313,8 @@ impl BlockHeader {
317313
#[must_use]
318314
#[allow(clippy::too_many_arguments)]
319315
pub fn new(
320-
chain_id: Ulid, height: i64, block_time_stamp: i64,
321-
previous_block_hash: (HashFunction, Vec<u8>), ledger_type: Uuid, purpose_id: Ulid,
316+
chain_id: Uuid, height: i64, block_time_stamp: i64,
317+
previous_block_hash: (HashFunction, Vec<u8>), ledger_type: Uuid, purpose_id: Uuid,
322318
validator: Vec<Kid>, metadata: Vec<u8>,
323319
) -> Self {
324320
Self {
@@ -347,8 +343,8 @@ impl BlockHeader {
347343
encoder.array(BLOCK_HEADER_SIZE)?;
348344

349345
// Chain id
350-
encoder.tag(minicbor::data::Tag::new(ULID_CBOR_TAG))?;
351-
encoder.bytes(&self.chain_id.to_bytes())?;
346+
encoder.tag(minicbor::data::Tag::new(UUID_CBOR_TAG))?;
347+
encoder.bytes(self.chain_id.as_bytes())?;
352348

353349
// Block height
354350
encoder.int(self.height.into())?;
@@ -372,8 +368,8 @@ impl BlockHeader {
372368
encoder.bytes(self.ledger_type.as_bytes())?;
373369

374370
// Purpose id
375-
encoder.tag(minicbor::data::Tag::new(ULID_CBOR_TAG))?;
376-
encoder.bytes(&self.purpose_id.to_bytes())?;
371+
encoder.tag(minicbor::data::Tag::new(UUID_CBOR_TAG))?;
372+
encoder.bytes(self.purpose_id.as_bytes())?;
377373

378374
// Validators
379375
encoder.array(self.validator.len().try_into()?)?;
@@ -405,7 +401,7 @@ impl BlockHeader {
405401

406402
// Raw chain_id
407403
cbor_decoder.tag()?;
408-
let chain_id = Ulid::from_bytes(
404+
let chain_id = Uuid::from_bytes(
409405
cbor_decoder
410406
.bytes()
411407
.map_err(|e| anyhow::anyhow!(format!("Invalid cbor for chain id : {e}")))?
@@ -443,7 +439,7 @@ impl BlockHeader {
443439

444440
// Raw purpose id
445441
cbor_decoder.tag()?;
446-
let purpose_id = Ulid::from_bytes(
442+
let purpose_id = Uuid::from_bytes(
447443
cbor_decoder
448444
.bytes()
449445
.map_err(|e| anyhow::anyhow!(format!("Invalid cbor for purpose id : {e}")))?
@@ -489,7 +485,7 @@ impl BlockHeader {
489485
/// Genesis block previous identifier type i.e hash of itself
490486
pub struct GenesisPreviousHash {
491487
/// Unique identifier of the chain.
492-
pub chain_id: Ulid,
488+
pub chain_id: Uuid,
493489
/// Block epoch-based date/time.
494490
pub block_time_stamp: i64,
495491
/// unique identifier of the ledger type.
@@ -498,7 +494,7 @@ pub struct GenesisPreviousHash {
498494
pub ledger_type: Uuid,
499495
/// unique identifier of the purpose, each Ledger instance will have a strict time
500496
/// boundaries, so each of them will run for different purposes.
501-
pub purpose_id: Ulid,
497+
pub purpose_id: Uuid,
502498
/// Identifier or identifiers of the entity who was produced and processed a block.
503499
pub validator: Vec<Kid>,
504500
}
@@ -507,7 +503,7 @@ impl GenesisPreviousHash {
507503
/// Create previous block id
508504
#[must_use]
509505
pub fn new(
510-
chain_id: Ulid, block_time_stamp: i64, ledger_type: Uuid, purpose_id: Ulid,
506+
chain_id: Uuid, block_time_stamp: i64, ledger_type: Uuid, purpose_id: Uuid,
511507
validator: Vec<Kid>,
512508
) -> Self {
513509
Self {
@@ -532,8 +528,8 @@ impl GenesisPreviousHash {
532528
encoder.array(GENESIS_TO_PREV_HASH_SIZE)?;
533529

534530
// Chain id
535-
encoder.tag(minicbor::data::Tag::new(ULID_CBOR_TAG))?;
536-
encoder.bytes(&self.chain_id.to_bytes())?;
531+
encoder.tag(minicbor::data::Tag::new(UUID_CBOR_TAG))?;
532+
encoder.bytes(self.chain_id.as_bytes())?;
537533

538534
// Block timestamp
539535
encoder.tag(minicbor::data::Tag::new(TIMESTAMP_CBOR_TAG))?;
@@ -549,8 +545,8 @@ impl GenesisPreviousHash {
549545
encoder.bytes(self.ledger_type.as_bytes())?;
550546

551547
// Purpose id
552-
encoder.tag(minicbor::data::Tag::new(ULID_CBOR_TAG))?;
553-
encoder.bytes(&self.purpose_id.to_bytes())?;
548+
encoder.tag(minicbor::data::Tag::new(UUID_CBOR_TAG))?;
549+
encoder.bytes(self.purpose_id.as_bytes())?;
554550

555551
// Validators
556552
encoder.array(self.validator.len().try_into()?)?;
@@ -586,7 +582,6 @@ mod tests {
586582

587583
use ed25519_dalek::{Signature, Signer, SigningKey, SECRET_KEY_LENGTH};
588584
use test_strategy::proptest;
589-
use ulid::Ulid;
590585
use uuid::Uuid;
591586

592587
use super::{BlockHeader, Kid};
@@ -609,12 +604,12 @@ mod tests {
609604
.unwrap();
610605

611606
let block_hdr = BlockHeader::new(
612-
Ulid::new(),
607+
Uuid::now_v7(),
613608
block_height,
614609
block_timestamp,
615610
(Blake2b, prev_block_hash),
616611
Uuid::new_v4(),
617-
Ulid::new(),
612+
Uuid::now_v7(),
618613
vec![Kid(kid_a), Kid(kid_b)],
619614
metadata,
620615
);
@@ -660,12 +655,12 @@ mod tests {
660655
.unwrap();
661656

662657
let block_hdr = BlockHeader::new(
663-
Ulid::new(),
658+
Uuid::now_v7(),
664659
block_height,
665660
block_timestamp,
666661
(Blake2b, prev_block_hash),
667662
Uuid::new_v4(),
668-
Ulid::new(),
663+
Uuid::now_v7(),
669664
vec![Kid(kid_a), Kid(kid_b)],
670665
metadata,
671666
);
@@ -751,9 +746,9 @@ mod tests {
751746
.try_into()
752747
.unwrap();
753748

754-
let chain_id = Ulid::new();
749+
let chain_id = Uuid::now_v7();
755750
let ledger_type = Uuid::new_v4();
756-
let purpose_id = Ulid::new();
751+
let purpose_id = Uuid::now_v7();
757752

758753
let block_hdr = BlockHeader::new(
759754
chain_id,
@@ -824,9 +819,9 @@ mod tests {
824819
073, 197, 105, 123, 050, 105, 025, 112, 059, 172, 003, 028, 174, 127, 096,
825820
];
826821

827-
let chain_id = Ulid::new();
822+
let chain_id = Uuid::now_v7();
828823
let ledger_type = Uuid::new_v4();
829-
let purpose_id = Ulid::new();
824+
let purpose_id = Uuid::now_v7();
830825
let block_time_stamp = 1_728_474_515;
831826

832827
let kid_a: [u8; 16] = hex::decode("00112233445566778899aabbccddeeff")

rust/rbac-registration/src/cardano/cip509/utils/cip134.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ impl Cip0134Uri {
5757
/// let uri = "web+cardano://addr/stake1uyehkck0lajq8gr28t9uxnuvgcqrc6070x3k9r8048z8y5gh6ffgw";
5858
/// let cip0134_uri = Cip0134Uri::parse(uri).unwrap();
5959
/// assert_eq!(cip0134_uri.uri(), uri);
60+
/// ```
6061
#[must_use]
6162
pub fn uri(&self) -> &str {
6263
&self.uri
@@ -76,6 +77,7 @@ impl Cip0134Uri {
7677
/// panic!("Unexpected address type");
7778
/// };
7879
/// assert_eq!(address.network(), Network::Mainnet);
80+
/// ```
7981
#[must_use]
8082
pub fn address(&self) -> &Address {
8183
&self.address

0 commit comments

Comments
 (0)