Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 2026-04-30
- #2798 (Non-breaking) Adds timelock support to the SDK. To use, add the `sov-timelock` module to the runtime, override the `timelock()` accessor on `HasCapabilities`, and then override `Runtime::timelock_for_callmessage` to match `CallMessage`s and return `TimelockPolicy` for those that should be timelocked. The module supports configurable cancellation policies, including delegating to a separate cancel address. See the `sov-timelock` module README for more details. Existing rollups do not need to do anything.

# 2026-04-23
- #2693 Adds new apis for statemap iteration at `/modules/{module}/state/{map_name}/items`

Expand Down
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ sov-attester-incentives = { workspace = true, features = ["native"] }
sov-chain-state = { workspace = true, features = ["native"] }
sov-value-setter = { workspace = true, features = ["native"] }
sov-test-modules = { workspace = true, features = ["native"] }
sov-timelock = { workspace = true, features = ["native"] }
sov-sequencer-registry = { workspace = true, features = ["native"] }
sov-bank = { workspace = true, features = ["native"] }
sov-accounts = { workspace = true, features = ["native"] }
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ use std::num::NonZeroU64;

use sov_modules_api::capabilities::TimelockPolicy;
use sov_modules_api::prelude::UnwrapInfallible;
use sov_test_modules::hooks_count::TxHooksCount;
use sov_modules_api::TxEffect;
use sov_test_utils::runtime::genesis::optimistic::HighLevelOptimisticGenesisConfig;
use sov_test_utils::runtime::{TestRunner, ValueSetter};
use sov_test_utils::{
generate_optimistic_runtime_with_kernel, AsUser, TestUser, TransactionTestCase,
};
use sov_value_setter::{CallMessage, ValueSetterConfig};
use sov_value_setter::{CallMessage as ValueSetterCallMessage, ValueSetterConfig};

use crate::stf_blueprint::S;

generate_optimistic_runtime_with_kernel!(
TimelockRuntime <=
NoopTimelockRuntime <=
kernel_type: sov_test_utils::runtime::BasicKernel<'a, S>,
modules: [
value_setter: ValueSetter<S>,
tx_hooks_count: TxHooksCount<S>,
timelock: sov_timelock::Timelock<S>
value_setter: ValueSetter<S>
],
timelock_policy_wrapper: |call: &TimelockRuntimeCall<S>| {
timelock_policy_wrapper: |call: &NoopTimelockRuntimeCall<S>| {
match call {
TimelockRuntimeCall::ValueSetter(CallMessage::SetValue { value: 7, .. }) => {
NoopTimelockRuntimeCall::ValueSetter(
ValueSetterCallMessage::SetValue { value: 7, .. }
) => {
Some(TimelockPolicy {
unlock_seconds_from_proposal: NonZeroU64::new(60).unwrap(),
expire_seconds_after_unlock_override: Some(60),
Expand All @@ -33,7 +33,7 @@ generate_optimistic_runtime_with_kernel!(
},
);

type RT = TimelockRuntime<S>;
type RT = NoopTimelockRuntime<S>;

fn setup() -> (TestUser<S>, TestRunner<RT, S>) {
let genesis_config =
Expand All @@ -50,8 +50,6 @@ fn setup() -> (TestUser<S>, TestRunner<RT, S>) {
ValueSetterConfig {
admin: admin.address(),
},
(),
(),
);

let runner = TestRunner::new_with_genesis(genesis.into_genesis_params(), RT::default());
Expand All @@ -60,90 +58,29 @@ fn setup() -> (TestUser<S>, TestRunner<RT, S>) {
}

#[test]
fn timelocked_call_registers_proposal_without_dispatching_call() {
fn timelocked_call_is_rejected_when_timelock_capability_is_unavailable() {
let (admin, mut runner) = setup();

runner.execute_transaction(TransactionTestCase {
input: admin.create_plain_message::<RT, ValueSetter<S>>(CallMessage::SetValue {
input: admin.create_plain_message::<RT, ValueSetter<S>>(ValueSetterCallMessage::SetValue {
value: 7,
gas: None,
}),
assert: Box::new(|result, state| {
assert!(result.tx_receipt.is_successful());
let TxEffect::Reverted(contents) = &result.tx_receipt else {
panic!("expected reverted transaction, got {:?}", result.tx_receipt);
};
assert!(contents
.reason
.to_string()
.contains("Timelocks are not available"));
assert_eq!(
ValueSetter::<S>::default()
.value
.get(state)
.unwrap_infallible(),
None
);
assert_eq!(
TxHooksCount::<S>::default()
.post_dispatch_tx_hook_count
.get(state)
.unwrap_infallible(),
Some(1)
);
}),
});
}

#[test]
fn repeated_timelocked_call_still_registers_without_dispatching_call() {
let (admin, mut runner) = setup();

for count in 1..=2 {
runner.execute_transaction(TransactionTestCase {
input: admin.create_plain_message::<RT, ValueSetter<S>>(CallMessage::SetValue {
value: 7,
gas: None,
}),
assert: Box::new(move |result, state| {
assert!(result.tx_receipt.is_successful());
assert_eq!(
ValueSetter::<S>::default()
.value
.get(state)
.unwrap_infallible(),
None
);
assert_eq!(
TxHooksCount::<S>::default()
.post_dispatch_tx_hook_count
.get(state)
.unwrap_infallible(),
Some(count)
);
}),
});
}
}

#[test]
fn untimelocked_call_dispatches_normally() {
let (admin, mut runner) = setup();

runner.execute_transaction(TransactionTestCase {
input: admin.create_plain_message::<RT, ValueSetter<S>>(CallMessage::SetValue {
value: 8,
gas: None,
}),
assert: Box::new(|result, state| {
assert!(result.tx_receipt.is_successful());
assert_eq!(
ValueSetter::<S>::default()
.value
.get(state)
.unwrap_infallible(),
Some(8)
);
assert_eq!(
TxHooksCount::<S>::default()
.post_dispatch_tx_hook_count
.get(state)
.unwrap_infallible(),
Some(1)
);
}),
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,32 @@ workspace = true

[dependencies]
anyhow = { workspace = true }
borsh = { workspace = true, features = ["rc"] }
schemars = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
sov-chain-state = { workspace = true }
sov-modules-api = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
sov-test-modules = { workspace = true, features = ["native"] }
sov-test-utils = { workspace = true }
sov-timelock = { path = ".", version = "*", features = ["native"] }
sov-value-setter = { workspace = true, features = ["native"] }
strum = { workspace = true }

[features]
default = []
arbitrary = ["sov-modules-api/arbitrary"]
native = ["sov-modules-api/native"]
arbitrary = [
"sov-modules-api/arbitrary",
"sov-test-utils/arbitrary",
"sov-timelock/arbitrary"
]
native = [
"sov-chain-state/native",
"sov-modules-api/native",
"sov-test-modules/native",
"sov-timelock/native",
"sov-value-setter/native"
]
Loading
Loading