Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kpinter-iohk committed Dec 6, 2024
1 parent ee68a13 commit 7ea63af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
18 changes: 10 additions & 8 deletions toolkit/offchain/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub trait Register {
block_producer_registration: &BlockProducerRegistration,
registration_utxo: UtxoId,
payment_signing_key: MainchainPrivateKey,
) -> Result<OgmiosTx, OffchainError>;
) -> Result<Option<OgmiosTx>, OffchainError>;
}

impl<T> Register for T
Expand All @@ -50,7 +50,7 @@ where
block_producer_registration: &BlockProducerRegistration,
registration_utxo: UtxoId,
payment_signing_key: MainchainPrivateKey,
) -> Result<OgmiosTx, OffchainError> {
) -> Result<Option<OgmiosTx>, OffchainError> {
run_register(
genesis_utxo,
block_producer_registration,
Expand All @@ -74,7 +74,7 @@ pub async fn run_register<
payment_signing_key: MainchainPrivateKey,
ogmios_client: &C,
await_tx: A,
) -> anyhow::Result<OgmiosTx> {
) -> anyhow::Result<Option<OgmiosTx>> {
let ctx = TransactionContext::for_payment_key(payment_signing_key.0, ogmios_client).await?;
let own_pkh = ed25519_key_hash_to_mainchain_address_hash(ctx.payment_key_hash());
let validator = crate::scripts_data::registered_candidates_scripts(genesis_utxo)?;
Expand All @@ -92,10 +92,12 @@ pub async fn run_register<
)?;
let own_registration_utxos = own_registrations.iter().map(|r| r.0.clone()).collect::<Vec<_>>();

if own_registrations.iter().any(|(_, existing_registration)| {
block_producer_registration.matches_keys(existing_registration)
}) {
return Err(anyhow!("BlockProducer with given set of keys is already registered"));
if own_registrations
.iter()
.any(|(_, existing_registration)| block_producer_registration == existing_registration)
{
log::info!("✅ Block producer already registered with same keys.");
return Ok(None);
}

let zero_ex_units = ExUnits::new(&0u64.into(), &0u64.into());
Expand Down Expand Up @@ -141,7 +143,7 @@ pub async fn run_register<
.await_tx_output(ogmios_client, UtxoId { tx_hash: McTxHash(tx_id), index: UtxoIndex(0) })
.await?;

Ok(result.transaction)
Ok(Some(result.transaction))
}

fn ed25519_key_hash_to_mainchain_address_hash(value: Ed25519KeyHash) -> MainchainAddressHash {
Expand Down
9 changes: 0 additions & 9 deletions toolkit/primitives/domain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,15 +660,6 @@ pub struct BlockProducerRegistration {
pub grandpa_pub_key: GrandpaPublicKey,
}

impl BlockProducerRegistration {
pub fn matches_keys(&self, other: &Self) -> bool {
self.stake_ownership == other.stake_ownership
&& self.sidechain_pub_key == other.sidechain_pub_key
&& self.aura_pub_key == other.aura_pub_key
&& self.grandpa_pub_key == other.grandpa_pub_key
}
}

/// AdaBasedStaking is a variant of Plutus type StakeOwnership.
/// The other variant, TokenBasedStaking, is not supported
#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down

0 comments on commit 7ea63af

Please sign in to comment.