Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into test/authority-rotati…
Browse files Browse the repository at this point in the history
…on-integration

* origin/main:
  fix: is_qualified should be called for all checks (#3910)
  🍒 cherry-pick: `preinst` script updates (#3917)
  Chore: explicitly reset vault rotator state on ceremony restarts (#3907)
  feat: shorter protocol id (#3906)
  • Loading branch information
syan095 committed Aug 29, 2023
2 parents 26b04dd + 3cfdab0 commit aa553df
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 55 deletions.
31 changes: 6 additions & 25 deletions engine/package/perseverance/preinst
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ if [ "$1" != "upgrade" ]; then
exit 0
fi

# TODO: Uncomment after we re-re-release 0.8
#ENGINE_VERSION=$(chainflip-engine -V)
#
#if echo "$ENGINE_VERSION" | grep 0.8; then
# echo "chainflip-engine: Detected version 0.8, skipping migration"
# exit 0
#fi
ENGINE_VERSION=$(chainflip-engine -V)

if echo "$ENGINE_VERSION" | grep 0.9; then
echo "chainflip-engine: Detected version 0.9, skipping migration"
exit 0
fi

CF_ROOT=/etc/chainflip

Expand Down Expand Up @@ -43,24 +42,6 @@ if [ -f "/var/log/chainflip-engine.log" ]; then
rm -rf "/var/log/chainflip-engine*"
fi

# Add the BTC settings to the config file if they don't exist
if ! grep -q '\[btc\]' /etc/chainflip/config/Settings.toml; then
echo "chainflip-engine: No BTC config found ... Adding BTC RPC endpoint to config file"
cat <<EOF >>$CF_ROOT/config/Settings.toml
[btc]
http_node_endpoint = "http://a108a82b574a640359e360cf66afd45d-424380952.eu-central-1.elb.amazonaws.com"
rpc_user = "flip"
rpc_password = "flip"
EOF
fi

# Check if pdot endpoint is pdot.chainflip.io and change to pdot.chainflip.xyz
if grep -q 'pdot.chainflip.io' /etc/chainflip/config/Settings.toml; then
echo "chainflip-engine: Found pdot.chainflip.io endpoint ... Changing to pdot.chainflip.xyz"
sed -i 's/pdot.chainflip.io/pdot.chainflip.xyz/g' /etc/chainflip/config/Settings.toml
fi

systemctl daemon-reload

#DEBHELPER#
Expand Down
13 changes: 6 additions & 7 deletions state-chain/node/package/perseverance/preinst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ else
echo "chainflip-node is already stopped."
fi

# TODO: Uncomment after we re-re-release 0.8
#NODE_VERSION=$(chainflip-node -V)
#
#if echo "$NODE_VERSION" | grep 0.8; then
# echo "chainflip-node: Detected version 0.8, skipping migration"
# exit 0
#fi
NODE_VERSION=$(chainflip-node -V)

if echo "$NODE_VERSION" | grep 0.9; then
echo "chainflip-node: Detected version 0.9, skipping migration"
exit 0
fi

# Backup and delete systemd overrides if they exist
if [ -f /etc/systemd/system/chainflip-node.service.d/override.conf ]; then
Expand Down
6 changes: 3 additions & 3 deletions state-chain/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,11 @@ macro_rules! network_spec {
"{}-{}",
PROTOCOL_ID,
hex::encode(
SystemTime::now()
&SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis()
.to_be_bytes(),
.as_secs()
.to_be_bytes()[4..],
)
);
Ok(ChainSpec::from_genesis(
Expand Down
21 changes: 17 additions & 4 deletions state-chain/pallets/cf-validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ pub mod pallet {
},
AsyncResult::Ready(VaultStatus::Failed(offenders)) => {
rotation_state.ban(offenders);
Self::try_start_keygen(rotation_state);
Self::try_restart_keygen(rotation_state);
},
AsyncResult::Pending => {
log::debug!(target: "cf-validator", "awaiting keygen completion");
Expand Down Expand Up @@ -403,12 +403,12 @@ pub mod pallet {
log::warn!(
"{num_failed_candidates} authority candidate(s) failed to participate in key handover. Retrying from keygen.",
);
Self::try_start_keygen(rotation_state);
Self::try_restart_keygen(rotation_state);
} else {
log::warn!(
"Key handover attempt failed. Retrying with a new participant set.",
);
Self::try_start_key_handover(rotation_state, block_number)
Self::try_restart_key_handover(rotation_state, block_number)
};
},
AsyncResult::Pending => {
Expand Down Expand Up @@ -967,7 +967,7 @@ impl<T: Config> Pallet<T> {
target: "cf-validator",
"Aborting rotation at phase: {:?}.", CurrentRotationPhase::<T>::get()
);
T::VaultRotator::abort_vault_rotation();
T::VaultRotator::reset_vault_rotation();
Self::set_rotation_phase(RotationPhase::Idle);
Self::deposit_event(Event::<T>::RotationAborted);
}
Expand Down Expand Up @@ -1043,6 +1043,11 @@ impl<T: Config> Pallet<T> {
}
}

fn try_restart_keygen(rotation_state: RuntimeRotationState<T>) {
T::VaultRotator::reset_vault_rotation();
Self::try_start_keygen(rotation_state);
}

fn try_start_keygen(rotation_state: RuntimeRotationState<T>) {
let candidates = rotation_state.authority_candidates();
let SetSizeParameters { min_size, .. } = AuctionParameters::<T>::get();
Expand All @@ -1061,6 +1066,14 @@ impl<T: Config> Pallet<T> {
}
}

fn try_restart_key_handover(
rotation_state: RuntimeRotationState<T>,
block_number: BlockNumberFor<T>,
) {
T::VaultRotator::reset_vault_rotation();
Self::try_start_key_handover(rotation_state, block_number);
}

fn try_start_key_handover(
rotation_state: RuntimeRotationState<T>,
block_number: BlockNumberFor<T>,
Expand Down
10 changes: 5 additions & 5 deletions state-chain/pallets/cf-vaults/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,8 +1124,8 @@ fn can_recover_from_abort_vault_rotation_after_failed_key_gen() {
Some(VaultRotationStatus::Failed { .. })
));

// Abort the vault rotation now
VaultsPallet::abort_vault_rotation();
// Abort by resetting vault rotation state
VaultsPallet::reset_vault_rotation();

assert!(PendingVaultRotation::<Test, _>::get().is_none());
assert_eq!(KeygenResolutionPendingSince::<Test, _>::get(), 0);
Expand Down Expand Up @@ -1163,7 +1163,7 @@ fn can_recover_from_abort_vault_rotation_after_key_verification() {
));

// Abort the vault rotation now
VaultsPallet::abort_vault_rotation();
VaultsPallet::reset_vault_rotation();

assert!(PendingVaultRotation::<Test, _>::get().is_none());
assert_eq!(KeygenResolutionPendingSince::<Test, _>::get(), 0);
Expand Down Expand Up @@ -1221,8 +1221,8 @@ fn can_recover_from_abort_vault_rotation_after_key_handover_failed() {
Some(VaultRotationStatus::KeyHandoverFailed { .. })
));

// Abort the vault rotation now
VaultsPallet::abort_vault_rotation();
// Abort by resetting vault rotation state
VaultsPallet::reset_vault_rotation();

assert!(PendingVaultRotation::<Test, _>::get().is_none());
assert_eq!(KeygenResolutionPendingSince::<Test, _>::get(), 0);
Expand Down
3 changes: 1 addition & 2 deletions state-chain/pallets/cf-vaults/src/vault_rotator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,10 @@ impl<T: Config<I>, I: 'static> VaultRotator for Pallet<T, I> {
}
}

fn abort_vault_rotation() {
fn reset_vault_rotation() {
PendingVaultRotation::<T, I>::kill();
KeyHandoverResolutionPendingSince::<T, I>::kill();
KeygenResolutionPendingSince::<T, I>::kill();
Self::deposit_event(Event::<T, I>::VaultRotationAborted);
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down
8 changes: 4 additions & 4 deletions state-chain/runtime/src/chainflip/all_vaults_rotator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ where
C::activate();
}

fn abort_vault_rotation() {
A::abort_vault_rotation();
B::abort_vault_rotation();
C::abort_vault_rotation();
fn reset_vault_rotation() {
A::reset_vault_rotation();
B::reset_vault_rotation();
C::reset_vault_rotation();
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down
9 changes: 5 additions & 4 deletions state-chain/traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ pub trait VaultRotator {
/// on the contract for a smart contract chain.
fn activate();

/// Terminate the current key rotation because of Safe Mode.
/// No validators are slashed.
fn abort_vault_rotation();
/// Reset the state associated with the current key rotation
/// in preparation for a new one.
fn reset_vault_rotation();

#[cfg(feature = "runtime-benchmarks")]
fn set_status(_outcome: AsyncResult<VaultStatus<Self::ValidatorId>>);
Expand Down Expand Up @@ -551,7 +551,8 @@ where
A::is_qualified(validator_id) &&
B::is_qualified(validator_id) &&
C::is_qualified(validator_id) &&
D::is_qualified(validator_id)
D::is_qualified(validator_id) &&
E::is_qualified(validator_id)
}

fn filter_unqualified(validators: BTreeSet<Id>) -> BTreeSet<Id> {
Expand Down
2 changes: 1 addition & 1 deletion state-chain/traits/src/mocks/vault_rotator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ macro_rules! mock_vault_rotator {
Self::put_value(ROTATION_OUTCOME, AsyncResult::<VaultStatus<u64>>::Pending);
}

fn abort_vault_rotation() {
fn reset_vault_rotation() {
Self::put_value(ROTATION_OUTCOME, AsyncResult::<VaultStatus<u64>>::Void);
}

Expand Down

0 comments on commit aa553df

Please sign in to comment.