Skip to content

Commit b60f211

Browse files
committed
fix: use Hash for shelley genesis hash type
1 parent 1796892 commit b60f211

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

common/src/genesis_values.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
use std::str::FromStr;
2+
13
use crate::{
24
calculations::{
35
epoch_to_first_slot_with_shelley_params, slot_to_epoch_with_shelley_params,
46
slot_to_timestamp_with_params,
57
},
8+
hash::Hash,
69
GenesisDelegates,
710
};
811
const MAINNET_SHELLEY_GENESIS_HASH: &str =
@@ -13,7 +16,7 @@ pub struct GenesisValues {
1316
pub byron_timestamp: u64,
1417
pub shelley_epoch: u64,
1518
pub shelley_epoch_len: u64,
16-
pub shelley_genesis_hash: [u8; 32],
19+
pub shelley_genesis_hash: Hash<32>,
1720
pub genesis_delegs: GenesisDelegates,
1821
}
1922

@@ -23,10 +26,7 @@ impl GenesisValues {
2326
byron_timestamp: 1506203091,
2427
shelley_epoch: 208,
2528
shelley_epoch_len: 432000,
26-
shelley_genesis_hash: hex::decode(MAINNET_SHELLEY_GENESIS_HASH)
27-
.unwrap()
28-
.try_into()
29-
.unwrap(),
29+
shelley_genesis_hash: Hash::<32>::from_str(MAINNET_SHELLEY_GENESIS_HASH).unwrap(),
3030
genesis_delegs: GenesisDelegates::try_from(vec![
3131
(
3232
"ad5463153dc3d24b9ff133e46136028bdc1edbb897f5a7cf1b37950c",

common/src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,8 +1765,8 @@ impl Voter {
17651765
impl Display for Voter {
17661766
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
17671767
match self.to_bech32() {
1768-
Ok(addr) => write!(f, "{}", addr),
1769-
Err(e) => write!(f, "<invalid voter: {}>", e),
1768+
Ok(addr) => write!(f, "{addr}"),
1769+
Err(e) => write!(f, "<invalid voter: {e}>"),
17701770
}
17711771
}
17721772
}

modules/genesis_bootstrapper/src/genesis_bootstrapper.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
use acropolis_common::{
55
genesis_values::GenesisValues,
6+
hash::Hash,
67
messages::{
78
CardanoMessage, GenesisCompleteMessage, GenesisUTxOsMessage, Message, PotDeltasMessage,
89
UTXODeltasMessage,
@@ -41,11 +42,11 @@ const SANCHONET_SHELLEY_START_EPOCH: u64 = 0;
4142
// Initial reserves (=maximum ever Lovelace supply)
4243
const INITIAL_RESERVES: Lovelace = 45_000_000_000_000_000;
4344

44-
fn hash_genesis_bytes(raw_bytes: &[u8]) -> [u8; 32] {
45+
fn hash_genesis_bytes(raw_bytes: &[u8]) -> Hash<32> {
4546
let mut hasher = Blake2b::<U32>::new();
4647
hasher.update(raw_bytes);
4748
let hash: [u8; 32] = hasher.finalize().into();
48-
hash
49+
Hash::<32>::new(hash)
4950
}
5051

5152
/// Genesis bootstrapper module

modules/snapshot_bootstrapper/src/snapshot_bootstrapper.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use std::sync::Arc;
1+
use std::{str::FromStr, sync::Arc};
22

33
use acropolis_common::{
44
genesis_values::GenesisValues,
5+
hash::Hash,
56
messages::{CardanoMessage, GenesisCompleteMessage, Message},
67
snapshot::{
78
streaming_snapshot::{
@@ -86,12 +87,11 @@ impl SnapshotHandler {
8687
byron_timestamp: 1506203091, // Byron mainnet genesis timestamp
8788
shelley_epoch: 208, // Shelley started at epoch 208 on mainnet
8889
shelley_epoch_len: 432000, // 5 days in seconds
89-
shelley_genesis_hash: [
90-
// Shelley mainnet genesis hash (placeholder - should be from config)
91-
0x1a, 0x3d, 0x98, 0x7a, 0x95, 0xad, 0xd2, 0x3e, 0x4f, 0x4d, 0x2d, 0x78, 0x74, 0x9f,
92-
0x96, 0x65, 0xd4, 0x1e, 0x48, 0x3e, 0xf2, 0xa2, 0x22, 0x9c, 0x4b, 0x0b, 0xf3, 0x9f,
93-
0xad, 0x7d, 0x5e, 0x27,
94-
],
90+
// Shelley mainnet genesis hash (placeholder - should be from config)
91+
shelley_genesis_hash: Hash::<32>::from_str(
92+
"1a3be38bcbb7911969283716ad7aa550250226b76a61fc51cc9a9a35d9276d81",
93+
)
94+
.unwrap(),
9595
genesis_delegs: GenesisDelegates::try_from(vec![]).unwrap(),
9696
})
9797
}

0 commit comments

Comments
 (0)