Skip to content

Commit

Permalink
Fix grandpa keys in chain-spec (#267)
Browse files Browse the repository at this point in the history
Fix #250, follow same _impl_ of `v1`
  • Loading branch information
pepoviola authored Oct 16, 2024
1 parent 3460ec1 commit cae47b2
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion crates/orchestrator/src/generators/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ impl ChainSpec {
.is_some()
{
add_aura_authorities(&pointer, &mut chain_spec_json, &validators, KeyType::Aura);
// await addParaCustom(chainSpecFullPathPlain, node);
} else {
warn!("Can't customize keys, not `session` or `aura` find in the chain-spec file");
};
Expand Down Expand Up @@ -577,6 +576,9 @@ impl ChainSpec {
&validators,
SessionKeyType::Stash,
);
} else {
add_aura_authorities(&pointer, &mut chain_spec_json, &validators, KeyType::Aura);
add_grandpa_authorities(&pointer, &mut chain_spec_json, &validators, KeyType::Aura);
}

// staking && nominators
Expand Down Expand Up @@ -1023,6 +1025,36 @@ fn add_aura_authorities(
unreachable!("pointer to runtime config should be valid!")
}
}

fn add_grandpa_authorities(
runtime_config_ptr: &str,
chain_spec_json: &mut serde_json::Value,
nodes: &[&NodeSpec],
_key_type: KeyType,
) {
if let Some(val) = chain_spec_json.pointer_mut(runtime_config_ptr) {
let keys: Vec<(String, usize)> = nodes
.iter()
.map(|node| {
(
node.accounts
.accounts
.get("ed")
.expect(&format!(
"'ed' account should be set at spec computation {THIS_IS_A_BUG}"
))
.address
.clone(),
1,
)
})
.collect();
val["grandpa"]["authorities"] = json!(keys);
} else {
unreachable!("pointer to runtime config should be valid!")
}
}

// TODO: (team)

// fn add_staking() {}
Expand Down

0 comments on commit cae47b2

Please sign in to comment.