Skip to content

Commit a25509b

Browse files
mudigalbkontur
andauthored
Wire up fast-runtime feature flag for short timeouts (#210)
* Wire up fast-runtime feature flag for short timeouts When built with --features fast-runtime, ChallengeTimeout, SettlementTimeout, RequestTimeout, and DeregisterAnnouncementPeriod use short block counts (3–10) instead of hours-long production values, making provider deregistration and challenge flows practical on previewnet. * Enable fast-runtime by default in justfile build recipes just start-chain and just start-paseo-chain now build with --features fast-runtime so local testing uses short timeouts. * Set short challenge/settlement timeouts directly; drop fast-runtime flag Replace the fast-runtime feature gate on the timeout constants with the short values baked directly into both the local (testnet) and paseo runtimes: ChallengeTimeout=10, SettlementTimeout=5, RequestTimeout=3, DeregisterAnnouncementPeriod=10 (still >= ChallengeTimeout). This makes challenge and provider-deregistration flows practical on previewnet without a separate feature build. With the constants no longer feature-dependent, remove the now-dead fast-runtime machinery: the second build.rs WASM binary, the fast_runtime_binary module in lib.rs, the fast-runtime Cargo feature, and the --features fast-runtime flags in the justfile build recipes. Drop the unused time::HOURS import. The released paseo wasm now carries the short timeouts by default; an existing previewnet chain still needs a runtime upgrade (setCode) to pick them up. Verified on remote: both runtimes build; cargo +nightly fmt --check, clippy -D warnings (both runtimes), taplo, and zepter all pass. * paseo: make storage-provider parameters runtime-settable via setStorage Convert the parameter_types! block in the paseo runtime from compile-time `pub const` to storage-backed `pub storage`. Each value remains the default but can now be overridden at runtime with `system.setStorage` (under sudo/governance) without a runtime upgrade — so previewnet timings (challenge/settlement/request timeouts, checkpoint cadence, stakes, deregister period) can be tuned live. Each `pub storage X` reads from unhashed storage falling back to the default and exposes X::key()/X::set(). Local (testnet) runtime is left as const. Verified on remote: paseo runtime builds; cargo +nightly fmt --check passes. * chore(release): v0.4.0-paseo - storage-provider-node crate 0.3.0 -> 0.4.0 (release tag validation) - storage-paseo-runtime crate 0.3.0 -> 0.4.0 - RuntimeVersion: spec_version 3_000 -> 4_000 Ships the paseo timeout changes (short challenge/settlement/request timeouts and deregister period) and the storage-backed parameter_types (runtime-settable via system.setStorage). No extrinsic encoding changes, so transaction_version stays at 2; the spec_version bump triggers any on-chain migrations on upgrade. --------- Co-authored-by: Branislav Kontur <bkontur@gmail.com>
1 parent aad4799 commit a25509b

10 files changed

Lines changed: 65 additions & 90 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provider-node/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "storage-provider-node"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
authors.workspace = true
55
edition.workspace = true
66
license.workspace = true

runtimes/web3-storage-local/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,5 @@ try-runtime = [
228228
"polkadot-runtime-common/try-runtime",
229229
"sp-runtime/try-runtime",
230230
]
231-
fast-runtime = []
232231
# Enable the metadata hash generation in the wasm builder.
233232
metadata-hash = ["substrate-wasm-builder/metadata-hash"]

runtimes/web3-storage-local/build.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,13 @@
33
#[cfg(all(not(feature = "metadata-hash"), feature = "std"))]
44
fn main() {
55
substrate_wasm_builder::WasmBuilder::build_using_defaults();
6-
7-
substrate_wasm_builder::WasmBuilder::init_with_defaults()
8-
.set_file_name("fast_runtime_binary.rs")
9-
.enable_feature("fast-runtime")
10-
.build();
116
}
127

138
#[cfg(all(feature = "metadata-hash", feature = "std"))]
149
fn main() {
1510
substrate_wasm_builder::WasmBuilder::init_with_defaults()
1611
.enable_metadata_hash("UNIT", 12)
1712
.build();
18-
19-
substrate_wasm_builder::WasmBuilder::init_with_defaults()
20-
.set_file_name("fast_runtime_binary.rs")
21-
.enable_feature("fast-runtime")
22-
.enable_metadata_hash("UNIT", 12)
23-
.build();
2413
}
2514

2615
#[cfg(not(feature = "std"))]

runtimes/web3-storage-local/src/lib.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212
#[cfg(feature = "std")]
1313
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
1414

15-
/// Provides the `WASM_BINARY` build with `fast-runtime` feature enabled.
16-
///
17-
/// This is for example useful for local test chains.
18-
#[cfg(feature = "std")]
19-
pub mod fast_runtime_binary {
20-
include!(concat!(env!("OUT_DIR"), "/fast_runtime_binary.rs"));
21-
}
22-
2315
pub mod constants;
2416
mod genesis_config_presets;
2517
mod revive;

runtimes/web3-storage-paseo/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "storage-paseo-runtime"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
authors.workspace = true
55
edition.workspace = true
66
license.workspace = true
@@ -236,6 +236,5 @@ try-runtime = [
236236
"polkadot-runtime-common/try-runtime",
237237
"sp-runtime/try-runtime",
238238
]
239-
fast-runtime = []
240239
# Enable the metadata hash generation in the wasm builder.
241240
metadata-hash = ["substrate-wasm-builder/metadata-hash"]

runtimes/web3-storage-paseo/build.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,13 @@
1616
#[cfg(all(not(feature = "metadata-hash"), feature = "std"))]
1717
fn main() {
1818
substrate_wasm_builder::WasmBuilder::build_using_defaults();
19-
20-
substrate_wasm_builder::WasmBuilder::init_with_defaults()
21-
.set_file_name("fast_runtime_binary.rs")
22-
.enable_feature("fast-runtime")
23-
.build();
2419
}
2520

2621
#[cfg(all(feature = "metadata-hash", feature = "std"))]
2722
fn main() {
2823
substrate_wasm_builder::WasmBuilder::init_with_defaults()
2924
.enable_metadata_hash("PAS", 10)
3025
.build();
31-
32-
substrate_wasm_builder::WasmBuilder::init_with_defaults()
33-
.set_file_name("fast_runtime_binary.rs")
34-
.enable_feature("fast-runtime")
35-
.enable_metadata_hash("PAS", 10)
36-
.build();
3726
}
3827

3928
#[cfg(not(feature = "std"))]

runtimes/web3-storage-paseo/src/lib.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212
#[cfg(feature = "std")]
1313
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
1414

15-
/// Provides the `WASM_BINARY` build with `fast-runtime` feature enabled.
16-
///
17-
/// This is for example useful for local test chains.
18-
#[cfg(feature = "std")]
19-
pub mod fast_runtime_binary {
20-
include!(concat!(env!("OUT_DIR"), "/fast_runtime_binary.rs"));
21-
}
22-
2315
pub mod genesis_config_presets;
2416
pub mod migrations;
2517
pub mod paseo_constants;
@@ -186,9 +178,9 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
186178
impl_name: Cow::Borrowed("paseo-web3-storage-runtime"),
187179
authoring_version: 1,
188180
// Encodes the runtime semver: major * 1_000_000 + minor * 1_000 + patch.
189-
// 0.3.0 -> 3_000. Must stay > the deployed value so the upgrade is
190-
// accepted and migrations run (previous release was `2_000`).
191-
spec_version: 3_000,
181+
// 0.4.0 -> 4_000. Must stay > the deployed value so the upgrade is
182+
// accepted and migrations run (previous release was `3_000`).
183+
spec_version: 4_000,
192184
impl_version: 0,
193185
apis: RUNTIME_API_VERSIONS,
194186
transaction_version: 2,

runtimes/web3-storage-paseo/src/storage.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,25 @@ use crate::{
1515
AccountId, Balance, Balances, BlockNumber, Runtime, RuntimeEvent,
1616
};
1717

18+
// Storage-backed parameters: each value below is the default, but can be
19+
// overridden at runtime via `system.setStorage` (under sudo/governance) without
20+
// a runtime upgrade. Useful for tuning previewnet timing without redeploying the
21+
// wasm. Each `pub storage X` exposes `X::key()` / `X::set()` and reads the
22+
// current value from unhashed storage, falling back to the default.
1823
parameter_types! {
19-
pub const MinProviderStake: Balance = 1_000 * UNIT; // 1000 tokens minimum stake
20-
pub const ChallengeTimeout: BlockNumber = 48 * HOURS; // 48 hours to respond
21-
pub const SettlementTimeout: BlockNumber = 24 * HOURS;
22-
pub const RequestTimeout: BlockNumber = 6 * HOURS;
24+
pub storage MinProviderStake: Balance = 1_000 * UNIT; // 1000 tokens minimum stake
25+
pub storage ChallengeTimeout: BlockNumber = 48 * HOURS;
26+
pub storage SettlementTimeout: BlockNumber = 24 * HOURS;
27+
pub storage RequestTimeout: BlockNumber = 6 * HOURS;
2328
// 1 token (1e12) per 1 GB (1e9 bytes) = 1000 per byte
24-
pub const MinStakePerByte: Balance = 1_000;
25-
pub const DefaultCheckpointInterval: BlockNumber = 100;
26-
pub const DefaultCheckpointGrace: BlockNumber = 20;
27-
pub const CheckpointReward: Balance = 1_000_000_000_000; // 1 token
28-
pub const CheckpointMissPenalty: Balance = 500_000_000_000; // 0.5 token
29+
pub storage MinStakePerByte: Balance = 1_000;
30+
pub storage DefaultCheckpointInterval: BlockNumber = 100;
31+
pub storage DefaultCheckpointGrace: BlockNumber = 20;
32+
pub storage CheckpointReward: Balance = 1_000_000_000_000; // 1 token
33+
pub storage CheckpointMissPenalty: Balance = 500_000_000_000; // 0.5 token
2934
/// Must be `>= ChallengeTimeout` so any challenge created up to the
3035
/// announcement block matures before the provider can withdraw stake.
31-
pub const DeregisterAnnouncementPeriod: BlockNumber = 48 * HOURS;
36+
pub storage DeregisterAnnouncementPeriod: BlockNumber = 48 * HOURS;
3237
}
3338

3439
/// Treasury account that receives slashed funds.

runtimes/web3-storage-paseo/tests/tests.rs

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -588,17 +588,9 @@ fn should_update_provider_settings() {
588588
fn should_register_provider_via_xcm() {
589589
let account = Sr25519Keyring::Alice;
590590
let who: AccountId = account.to_account_id();
591-
let stake = default_stake();
592591
let multiaddr: Vec<u8> = b"/ip4/127.0.0.1/tcp/3000".to_vec();
593592
let public_key = to_provider_public_key(account);
594593

595-
let register_provider_call =
596-
RuntimeCall::StorageProvider(StorageProviderCall::<Runtime>::register_provider {
597-
multiaddr: multiaddr.clone().try_into().unwrap(),
598-
public_key: public_key.clone(),
599-
stake,
600-
});
601-
602594
ExtBuilder::<Runtime>::default()
603595
.with_collators(vec![AccountId::from(ALICE)])
604596
.with_session_keys(vec![(
@@ -611,6 +603,16 @@ fn should_register_provider_via_xcm() {
611603
.with_tracing()
612604
.build()
613605
.execute_with(|| {
606+
// `default_stake` reads the storage-backed `MinProviderStake`, so it must
607+
// run inside the externalities provided by `execute_with`.
608+
let stake = default_stake();
609+
let register_provider_call =
610+
RuntimeCall::StorageProvider(StorageProviderCall::<Runtime>::register_provider {
611+
multiaddr: multiaddr.clone().try_into().unwrap(),
612+
public_key: public_key.clone(),
613+
stake,
614+
});
615+
614616
// Alice needs balance for both: paid XCM execution fees and the stake reserve.
615617
let _ = Balances::deposit_creating(&who, stake.saturating_mul(4));
616618

@@ -656,19 +658,23 @@ fn should_register_provider_via_xcm() {
656658
#[test]
657659
fn should_add_stake_via_xcm() {
658660
let alice_on_para = alice_on_sibling_parachain(2_000);
659-
let initial_stake = default_stake();
660661
let extra = 500 * UNIT;
661662

662-
let register_call =
663-
RuntimeCall::StorageProvider(StorageProviderCall::<Runtime>::register_provider {
664-
multiaddr: b"/ip4/127.0.0.1/tcp/3000".to_vec().try_into().unwrap(),
665-
public_key: to_provider_public_key(Sr25519Keyring::Alice),
666-
stake: initial_stake,
667-
});
668-
let add_stake_call =
669-
RuntimeCall::StorageProvider(StorageProviderCall::<Runtime>::add_stake { amount: extra });
670-
671663
xcm_test_ext().execute_with(|| {
664+
// `default_stake` reads the storage-backed `MinProviderStake`, so it must
665+
// run inside the externalities provided by `execute_with`.
666+
let initial_stake = default_stake();
667+
let register_call =
668+
RuntimeCall::StorageProvider(StorageProviderCall::<Runtime>::register_provider {
669+
multiaddr: b"/ip4/127.0.0.1/tcp/3000".to_vec().try_into().unwrap(),
670+
public_key: to_provider_public_key(Sr25519Keyring::Alice),
671+
stake: initial_stake,
672+
});
673+
let add_stake_call =
674+
RuntimeCall::StorageProvider(StorageProviderCall::<Runtime>::add_stake {
675+
amount: extra,
676+
});
677+
672678
// The dispatch origin is the sovereign `AccountId` derived from Alice-on-para.
673679
let derived: AccountId =
674680
LocationToAccountHelper::<AccountId, LocationToAccountId>::convert_location(
@@ -713,16 +719,18 @@ fn should_register_provider_via_xcm_from_sibling_parachain() {
713719
// Use a different para id from `should_add_stake_via_xcm` to make the derived sovereign
714720
// distinct, even though each test runs in a fresh ext.
715721
let alice_on_para = alice_on_sibling_parachain(3_000);
716-
let stake = default_stake();
717-
718-
let register_call =
719-
RuntimeCall::StorageProvider(StorageProviderCall::<Runtime>::register_provider {
720-
multiaddr: b"/ip4/127.0.0.1/tcp/3000".to_vec().try_into().unwrap(),
721-
public_key: to_provider_public_key(Sr25519Keyring::Alice),
722-
stake,
723-
});
724722

725723
xcm_test_ext().execute_with(|| {
724+
// `default_stake` reads the storage-backed `MinProviderStake`, so it must
725+
// run inside the externalities provided by `execute_with`.
726+
let stake = default_stake();
727+
let register_call =
728+
RuntimeCall::StorageProvider(StorageProviderCall::<Runtime>::register_provider {
729+
multiaddr: b"/ip4/127.0.0.1/tcp/3000".to_vec().try_into().unwrap(),
730+
public_key: to_provider_public_key(Sr25519Keyring::Alice),
731+
stake,
732+
});
733+
726734
let derived: AccountId =
727735
LocationToAccountHelper::<AccountId, LocationToAccountId>::convert_location(
728736
alice_on_para.clone().into(),
@@ -760,14 +768,16 @@ fn should_fail_xcm_unpaid_execution_from_unauthorized_origin() {
760768
}],
761769
);
762770

763-
let register_call =
764-
RuntimeCall::StorageProvider(StorageProviderCall::<Runtime>::register_provider {
765-
multiaddr: b"/ip4/127.0.0.1/tcp/3000".to_vec().try_into().unwrap(),
766-
public_key: to_provider_public_key(Sr25519Keyring::Alice),
767-
stake: default_stake(),
768-
});
769-
770771
xcm_test_ext().execute_with(|| {
772+
// `default_stake` reads the storage-backed `MinProviderStake`, so it must
773+
// run inside the externalities provided by `execute_with`.
774+
let register_call =
775+
RuntimeCall::StorageProvider(StorageProviderCall::<Runtime>::register_provider {
776+
multiaddr: b"/ip4/127.0.0.1/tcp/3000".to_vec().try_into().unwrap(),
777+
public_key: to_provider_public_key(Sr25519Keyring::Alice),
778+
stake: default_stake(),
779+
});
780+
771781
// `None` fee → `RuntimeHelper` builds an `UnpaidExecution + Transact` message.
772782
let outcome = RuntimeHelper::<Runtime, AllPalletsWithoutSystem>::execute_as_origin(
773783
(alice_on_relay, OriginKind::SovereignAccount),

0 commit comments

Comments
 (0)