Refactored authority selection
@@ -794,6 +794,20 @@ impl<T: Config> Pallet<T> {
Ok(current_round_messages)
}
+ pub fn select_authority(escrow_account: T::AccountId) -> Result<AuthorityId, &'static str> {
+ let local_keys = AuthorityId::all();
+
+ let auth = AuthorityId::from_slice(escrow_account.encode().as_slice());
+
+ let submitter = local_keys
+ .binary_search(&auth)
+ .ok()
+ .map(|location| local_keys[location].clone())
+ .ok_or("Can't match")?;
+
+ Ok(submitter)
+ }
+
pub fn process_step(
step: StepEntry<T::AccountId, T::BlockNumber, T::Hash>,
escrow_account: T::AccountId,
@@ -811,11 +825,10 @@ impl<T: Config> Pallet<T> {
.map_err(|_e| "Can't cast value in dry_run_single_contract")?,
);
- let local_keys = AuthorityId::all();
-
- // ToDo: Select validators to submit by his public key, like:
- // let submitter = local_keys.binary_search(&escrow_account.into()).ok().map(|location| local_keys[location].clone()).ok_or("Can't match")?;
- let submitter = local_keys[0].clone();
+ let submitter = match Self::select_authority(escrow_account.clone()) {
+ Ok(submitter) => submitter,
+ Err(e) => return Err(e),
+ };
let gateway_xdns_record = pallet_xdns::Pallet::<T>::xdns_registry(step.gateway_entry_id)
.ok_or(Error::<T>::ProcessStepGatewayNotRecognised)?;
