Skip to content

Commit

Permalink
Fixed substrate unpooling to blocks from seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Lustyk authored and Michal Lustyk committed Jan 24, 2024
1 parent 34965c3 commit f81cb55
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "scripts/fork-test/fork-off-substrate"]
path = scripts/fork-test/fork-off-substrate
url = https://github.com/liberland/fork-off-substrate.git
[submodule "eth-bridge/contracts/lib/forge-std"]
path = eth-bridge/contracts/lib/forge-std
url = https://github.com/foundry-rs/forge-std
Expand All @@ -10,3 +7,6 @@
[submodule "eth-bridge/contracts/lib/openzeppelin-contracts"]
path = eth-bridge/contracts/lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "scripts/fork-test/liberland-fork-substrate"]
path = scripts/fork-test/liberland-fork-substrate
url = [email protected]:liberland/liberland-fork-substrate.git
8 changes: 3 additions & 5 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to 0. If only runtime
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 15,
spec_version: 16,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand All @@ -160,7 +160,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to 0. If only runtime
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 15,
spec_version: 16,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down Expand Up @@ -1846,9 +1846,7 @@ mod bounties_v4 {

// All migrations executed on runtime upgrade as a nested tuple of types implementing
// `OnRuntimeUpgrade`.
type Migrations = (
pallet_liberland_legislation::migrations::v1::Migration<Runtime>,
);
type Migrations = (pallet_llm::migrations::v3::Migration<Runtime>,);

type EventRecord = frame_system::EventRecord<
<Runtime as frame_system::Config>::RuntimeEvent,
Expand Down
4 changes: 2 additions & 2 deletions eth-bridge/contracts/script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract Deploy is Script {
3_000_000_000_000_000_000, // max supply limit
1_000_000 gwei, // min fee
100_000_000 gwei, // max fee
3 // min votes required
0 // min votes required
)
)
);
Expand Down Expand Up @@ -76,7 +76,7 @@ contract Deploy is Script {
1_000_000_000_000_000_000, // max supply limit
1_000_000 gwei, // min fee
100_000_000 gwei, // max fee
3 // min votes required
0 // min votes required
)
)
);
Expand Down
4 changes: 2 additions & 2 deletions frame/llm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ Accounts may freely transfer their not-locked LLM to other accounts.

## Genesis Config

* `unpooling_withdrawlock_duration`: duration, in seconds, for which additional unlocks should be locked after `politics_unlock`
* `unpooling_electionlock_duration`: duration, in seconds, for which politics rights should be suspended after `politics_unlock`
* `unpooling_withdrawlock_duration`: duration, in blocks, for which additional unlocks should be locked after `politics_unlock`
* `unpooling_electionlock_duration`: duration, in blocks, for which politics rights should be suspended after `politics_unlock`

## Interface

Expand Down
10 changes: 5 additions & 5 deletions frame/llm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
//!
//! ## Genesis Config
//!
//! * `unpooling_withdrawlock_duration`: duration, in seconds, for which additional unlocks should
//! * `unpooling_withdrawlock_duration`: duration, in blocks, for which additional unlocks should
//! be locked after `politics_unlock`
//! * `unpooling_electionlock_duration`: duration, in seconds, for which politics rights should be
//! * `unpooling_electionlock_duration`: duration, in blocks, for which politics rights should be
//! suspended after `politics_unlock`
//!
//! ## Interface
Expand Down Expand Up @@ -233,10 +233,10 @@ pub mod pallet {

#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
/// duration, in seconds, for which additional unlocks should be locked
/// duration, in blocks, for which additional unlocks should be locked
/// after `politics_unlock`
pub unpooling_withdrawlock_duration: T::BlockNumber,
/// duration, in seconds, for which politics rights should be suspended
/// duration, in blocks, for which politics rights should be suspended
/// after `politics_unlock`
pub unpooling_electionlock_duration: T::BlockNumber,
pub _phantom: PhantomData<T>,
Expand Down Expand Up @@ -325,7 +325,7 @@ pub mod pallet {
Locked,
}

const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
const STORAGE_VERSION: StorageVersion = StorageVersion::new(3);

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
Expand Down
43 changes: 43 additions & 0 deletions frame/llm/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,46 @@ pub mod v2 {
}
}
}

pub mod v3 {
use super::*;
pub struct Migration<T>(sp_std::marker::PhantomData<T>);

impl<T: Config> OnRuntimeUpgrade for Migration<T> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
assert!(StorageVersion::get::<Pallet<T>>() <= 2, "can only upgrade from version 2");

Ok(().encode())
}

fn on_runtime_upgrade() -> Weight {
let weight = T::DbWeight::get().reads(1);
if StorageVersion::get::<Pallet<T>>() > 2 {
log::warn!(
target: TARGET,
"skipping on_runtime_upgrade: executed on wrong storage version.\
Expected version 2 or lower"
);
return weight;
}

let duration: T::BlockNumber = 432000u32.into();
WithdrawlockDuration::<T>::put(&duration);
ElectionlockDuration::<T>::put(&duration);

let _ = Withdrawlock::<T>::clear(u32::MAX, None);
let _ = Electionlock::<T>::clear(u32::MAX, None);

StorageVersion::new(3).put::<Pallet<T>>();
weight.saturating_add(T::DbWeight::get().reads_writes(1, 1))
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), TryRuntimeError> {
assert_eq!(StorageVersion::get::<Pallet<T>>(), 3, "must upgrade");
log::info!(target: TARGET, "WithdrawlockDuration set to {:?}, ElectionlockDuration set to {:?}", WithdrawlockDuration::<T>::get(), ElectionlockDuration::<T>::get(),);
Ok(())
}
}
}
4 changes: 2 additions & 2 deletions scripts/fork-test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ set -euo pipefail
export ORIG_CHAIN WS_ENDPOINT

# Cleanup & Prepare
[ ! -e "$(dirname "$0")/fork-off-substrate/package.json" ] && git submodule update --init
cd "$(dirname "$0")/fork-off-substrate"
[ ! -e "$(dirname "$0")/liberland-fork-substrate/package.json" ] && git submodule update --init
cd "$(dirname "$0")/liberland-fork-substrate"
npm install
mkdir -p data
cp "$BINARY" data/binary
Expand Down

0 comments on commit f81cb55

Please sign in to comment.