Skip to content

Commit 0dc9c03

Browse files
committed
Refactor: Update GenesisKeyhash to use consistent hash types and improve error handling in tx_unpacker
1 parent d181f1c commit 0dc9c03

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

codec/src/map_parameters.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ pub fn to_hash<const N: usize>(pallas_hash: &pallas_primitives::Hash<N>) -> Hash
3737

3838
/// Convert a Pallas Hash reference to an Acropolis Hash (owned)
3939
/// Works for any hash size N
40-
pub fn genesis_to_hash(pallas_hash: &pallas_primitives::Genesishash) -> GenesisKeyhash {
41-
GenesisKeyhash::try_from(pallas_hash.as_ref()).unwrap()
40+
pub fn genesis_to_hash(pallas_hash: &pallas_primitives::Genesishash) -> Hash<32> {
41+
Hash::try_from(pallas_hash.as_ref()).unwrap()
4242
}
4343

4444
/// Convert a Pallas Hash reference to an Acropolis Hash (owned)

common/src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ pub type ScriptHash = KeyHash;
450450
pub type AddrKeyhash = KeyHash;
451451

452452
/// Script identifier
453-
pub type GenesisKeyhash = Hash<32>;
453+
pub type GenesisKeyhash = Hash<28>;
454454

455455
declare_hash_type!(BlockHash, 32);
456456
declare_hash_type!(TxHash, 32);
@@ -982,7 +982,7 @@ pub struct SPORewards {
982982
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
983983
pub struct GenesisKeyDelegation {
984984
/// Genesis hash
985-
pub genesis_hash: GenesisKeyhash,
985+
pub genesis_hash: Hash<32>,
986986

987987
/// Genesis delegate hash
988988
pub genesis_delegate_hash: PoolId,

modules/tx_unpacker/src/tx_unpacker.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,23 @@ impl TxUnpacker {
4949
enactment_epoch: epoch,
5050
};
5151

52-
for (hash, vote) in proposals.iter() {
52+
for (hash_bytes, vote) in proposals.iter() {
53+
let hash = match GenesisKeyhash::try_from(hash_bytes.as_ref()) {
54+
Ok(h) => h,
55+
Err(e) => {
56+
error!("Invalid genesis keyhash in protocol parameter update: {e}");
57+
continue;
58+
}
59+
};
60+
5361
match map(vote) {
54-
Ok(upd) => update.proposals.push((hash.to_vec(), upd)),
55-
Err(e) => error!("Cannot convert alonzo protocol param update {vote:?}: {e}"),
62+
Ok(upd) => update.proposals.push((hash, upd)),
63+
Err(e) => error!("Cannot convert protocol param update {vote:?}: {e}"),
5664
}
5765
}
5866

5967
dest.push(update);
6068
}
61-
6269
/// Main init function
6370
pub async fn init(&self, context: Arc<Context<Message>>, config: Arc<Config>) -> Result<()> {
6471
// Get configuration

0 commit comments

Comments
 (0)