Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vault): client release version #668

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 27 additions & 2 deletions crates/vault-registry/src/lib.rs
Expand Up @@ -29,8 +29,8 @@ use mocktopus::macros::mockable;
use primitives::VaultCurrencyPair;

use crate::types::{
BalanceOf, BtcAddress, CurrencyId, DefaultSystemVault, RichSystemVault, RichVault, SignedInner, UnsignedFixedPoint,
UpdatableVault, Version,
BalanceOf, BtcAddress, ClientRelease, CurrencyId, DefaultSystemVault, RichSystemVault, RichVault, SignedInner,
UnsignedFixedPoint, UpdatableVault, Version,
};

use crate::types::DefaultVaultCurrencyPair;
Expand Down Expand Up @@ -417,6 +417,21 @@ pub mod pallet {
Self::_set_liquidation_collateral_threshold(currency_pair, threshold);
Ok(())
}

/// Changes the collateral liquidation threshold for a currency (only executable by the Root account)
daniel-savu marked this conversation as resolved.
Show resolved Hide resolved
///
/// # Arguments
/// * `version` - the semver version, where the zero-index element is the major version
/// * `checksum` - the SHA256 checksum of the client binary
#[pallet::weight(<T as Config>::WeightInfo::set_liquidation_collateral_threshold())]
#[transactional]
pub fn set_client_release(origin: OriginFor<T>, version: [u32; 3], checksum: [u8; 32]) -> DispatchResult {
daniel-savu marked this conversation as resolved.
Show resolved Hide resolved
daniel-savu marked this conversation as resolved.
Show resolved Hide resolved
ensure_root(origin)?;
// TODO: Should the new semver version have a check that ensures it is striclty ascending?
daniel-savu marked this conversation as resolved.
Show resolved Hide resolved
LatestClientRelease::<T>::put(ClientRelease { version, checksum });
Self::deposit_event(Event::<T>::ClientRelease { version, checksum });
Ok(())
}
}

#[pallet::event]
Expand Down Expand Up @@ -528,6 +543,10 @@ pub mod pallet {
vault_id: DefaultVaultId<T>,
banned_until: T::BlockNumber,
},
ClientRelease {
daniel-savu marked this conversation as resolved.
Show resolved Hide resolved
version: [u32; 3],
checksum: [u8; 32],
daniel-savu marked this conversation as resolved.
Show resolved Hide resolved
},
}

#[pallet::error]
Expand Down Expand Up @@ -651,6 +670,12 @@ pub mod pallet {
pub(super) type TotalUserVaultCollateral<T: Config> =
StorageMap<_, Blake2_128Concat, DefaultVaultCurrencyPair<T>, BalanceOf<T>, ValueQuery>;

/// Tuple of (semver_version, sha256_checksum) indicating the latest vault client release.
/// `semver_version`: The element at index zero is the major semver version.
#[pallet::storage]
#[pallet::getter(fn latest_client_release)]
pub(super) type LatestClientRelease<T: Config> = StorageValue<_, ClientRelease, ValueQuery>;
daniel-savu marked this conversation as resolved.
Show resolved Hide resolved

#[pallet::type_value]
pub(super) fn DefaultForStorageVersion() -> Version {
Version::V0
Expand Down
8 changes: 8 additions & 0 deletions crates/vault-registry/src/types.rs
Expand Up @@ -33,6 +33,14 @@ pub enum Version {
V4,
}

#[derive(Encode, Decode, Default, TypeInfo, Eq, PartialEq, Debug)]
pub struct ClientRelease {
/// The semver version, where the zero-index element is the major version
pub version: [u32; 3],
/// SHA256 checksum of the client binary
pub checksum: [u8; 32],
}

#[derive(Debug, PartialEq)]
pub enum CurrencySource<T: frame_system::Config + orml_tokens::Config> {
/// Used by vault to back issued tokens
Expand Down
18 changes: 18 additions & 0 deletions standalone/runtime/tests/test_vault_registry.rs
Expand Up @@ -159,6 +159,8 @@ mod deposit_collateral_test {
}
}
mod withdraw_collateral_test {
use vault_registry::types::ClientRelease;

use super::{assert_eq, *};

fn required_collateral(vault_id: VaultId) -> Amount<Runtime> {
Expand Down Expand Up @@ -227,6 +229,22 @@ mod withdraw_collateral_test {
);
});
}

#[test]
fn integration_test_vault_registry_set_client_release_works() {
test_with(|_vault_id| {
let new_release = ClientRelease {
version: [1, 0, 2],
checksum: [1u8; 32],
};
assert_ok!(Call::VaultRegistry(VaultRegistryCall::set_client_release {
version: new_release.version,
checksum: new_release.checksum
})
.dispatch(root()));
assert_eq!(VaultRegistryPallet::latest_client_release(), new_release);
});
}
}

#[test]
Expand Down