Skip to content

Commit

Permalink
ETCM-8754: fix register command (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpinter-iohk authored Dec 11, 2024
1 parent e28ac5a commit 2a10d8f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
46 changes: 24 additions & 22 deletions toolkit/offchain/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,16 @@ pub async fn run_register<
&all_registration_utxos,
);

if own_registrations
.iter()
.any(|(_, existing_registration)| candidate_registration == existing_registration)
{
if own_registrations.iter().any(|(_, existing_registration)| {
candidate_registration.matches_keys(existing_registration)
}) {
log::info!("✅ Candidate already registered with same keys.");
return Ok(None);
}
let own_registration_utxos = own_registrations.iter().map(|r| r.0.clone()).collect::<Vec<_>>();

let zero_ex_units = ExUnits::new(&0u64.into(), &0u64.into());
let tx = register_tx(
let mut tx = register_tx(
&validator,
candidate_registration,
registration_utxo,
Expand All @@ -101,23 +100,26 @@ pub async fn run_register<
zero_ex_units,
)?;

let evaluate_response =
ogmios_client.evaluate_transaction(&tx.to_bytes()).await.map_err(|e| {
anyhow!(
"Evaluate candidate registration transaction request failed: {}, bytes: {}",
e,
hex::encode(tx.to_bytes())
)
})?;
let validator_redeemer_ex_units = get_first_validator_budget(evaluate_response)?;
let tx = register_tx(
&validator,
candidate_registration,
registration_utxo,
&own_registration_utxos,
&ctx,
validator_redeemer_ex_units,
)?;
if !own_registration_utxos.is_empty() {
let evaluate_response =
ogmios_client.evaluate_transaction(&tx.to_bytes()).await.map_err(|e| {
anyhow!(
"Evaluate candidate registration transaction request failed: {}, bytes: {}",
e,
hex::encode(tx.to_bytes())
)
})?;
let validator_redeemer_ex_units = get_first_validator_budget(evaluate_response)?;
tx = register_tx(
&validator,
candidate_registration,
registration_utxo,
&own_registration_utxos,
&ctx,
validator_redeemer_ex_units,
)?;
}

let signed_tx = ctx.sign(&tx).to_bytes();
let result = ogmios_client.submit_transaction(&signed_tx).await.map_err(|e| {
anyhow!(
Expand Down
1 change: 0 additions & 1 deletion toolkit/offchain/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ async fn upsert_d_param() {
assert!(run_upsert_d_param(genesis_utxo, 1, 1, &client).await.is_some())
}

#[ignore = "Internal error: cannot use evaluateTransaction response"]
#[tokio::test]
async fn register() {
let _ = env_logger::builder().is_test(true).try_init();
Expand Down
10 changes: 10 additions & 0 deletions toolkit/primitives/domain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,16 @@ pub struct CandidateRegistration {
pub grandpa_pub_key: GrandpaPublicKey,
}

impl CandidateRegistration {
pub fn matches_keys(&self, other: &Self) -> bool {
self.stake_ownership == other.stake_ownership
&& self.partnerchain_pub_key == other.partnerchain_pub_key
&& self.partnerchain_signature == other.partnerchain_signature
&& 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 2a10d8f

Please sign in to comment.