Skip to content

Commit

Permalink
update migration and it tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Chralt98 committed Aug 14, 2024
1 parent 6133ceb commit 8892902
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ try-runtime-upgrade-battery-station:
--execute-try-runtime

try-runtime-upgrade-zeitgeist:
@$(MAKE) TRYRUNTIME_URL="wss://zeitgeist-rpc.dwellir.com:443" \
@$(MAKE) TRYRUNTIME_URL="wss://zeitgeist.api.onfinality.io:443/public-ws" \
RUNTIME_PATH="./target/release/wbuild/zeitgeist-runtime/zeitgeist_runtime.compact.compressed.wasm" \
-- \
--execute-try-runtime
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/moonwall.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
}
]
},
"envVars": ["LOG_LEVEL=debug", "VERBOSE_LOG"],
"envVars": ["LOG_LEVEL=debug", "VERBOSE_LOG=true"],
"buildBlockMode": "manual",
"connections": [
{
Expand Down Expand Up @@ -106,7 +106,7 @@
}
]
},
"envVars": ["LOG_LEVEL=debug", "VERBOSE_LOG"],
"envVars": ["LOG_LEVEL=debug", "VERBOSE_LOG=true"],
"buildBlockMode": "manual",
"connections": [
{
Expand Down
2 changes: 1 addition & 1 deletion zrml/market-commons/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mod pallet {
};

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(11);
const STORAGE_VERSION: StorageVersion = StorageVersion::new(12);

pub(crate) type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub(crate) type AssetOf<T> = Asset<MarketIdOf<T>>;
Expand Down
23 changes: 22 additions & 1 deletion zrml/market-commons/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use frame_support::{
use frame_system::pallet_prelude::BlockNumberFor;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::{Perbill, RuntimeDebug, Saturating};
use sp_runtime::{Perbill, RuntimeDebug, SaturatedConversion, Saturating};
use zeitgeist_primitives::types::{
Asset, Deadlines, EarlyClose, Market, MarketBonds, MarketCreation, MarketDisputeMechanism,
MarketPeriod, MarketStatus, MarketType, OutcomeReport, Report, ScoringRule,
Expand Down Expand Up @@ -98,6 +98,8 @@ pub enum OldMarketDisputeMechanism {
const MARKET_COMMONS_REQUIRED_STORAGE_VERSION: u16 = 11;
const MARKET_COMMONS_NEXT_STORAGE_VERSION: u16 = 12;

const CORRUPTED_MARKET_IDS_BATTERY_STATION: [u32; 5] = [879u32, 877u32, 878u32, 880u32, 882u32];

#[cfg(feature = "try-runtime")]
#[frame_support::storage_alias]
pub(crate) type Markets<T: Config> =
Expand Down Expand Up @@ -125,6 +127,18 @@ where
}
log::info!("MigrateDisputeMechanism: Starting...");

// 879, 877, 878, 880, 882 markets on Battery Station
// each have a campaign asset as the base asset, which is invalid
for market_id in CORRUPTED_MARKET_IDS_BATTERY_STATION {
let market_id = market_id.saturated_into::<MarketIdOf<T>>();
if crate::Markets::<T>::contains_key(market_id)
// this produces a decoding error for the corrupted markets
&& crate::Markets::<T>::try_get(market_id).is_err()
{
crate::Markets::<T>::remove(market_id);
}
}

let mut translated = 0u64;
crate::Markets::<T>::translate::<OldMarketOf<T>, _>(|_, old_market| {
translated.saturating_inc();
Expand Down Expand Up @@ -213,6 +227,13 @@ where
assert_eq!(old_market.bonds, new_market.bonds);
assert_eq!(old_market.early_close, new_market.early_close);
}

for market_id in CORRUPTED_MARKET_IDS_BATTERY_STATION {
let market_id = market_id.saturated_into::<MarketIdOf<T>>();
assert!(!crate::Markets::<T>::contains_key(market_id));
assert!(crate::Markets::<T>::try_get(market_id).is_err());
}

log::info!("MigrateDisputeMechanism: Post-upgrade market count is {}!", new_market_count);
Ok(())
}
Expand Down

0 comments on commit 8892902

Please sign in to comment.