From c5675589b423bf59843894fb80e5077e55883fd1 Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Thu, 26 Sep 2024 13:40:00 -0700 Subject: [PATCH] feat: timeout config --- src/msgs/data_requests/execute/mod.rs | 1 + src/msgs/data_requests/types.rs | 19 ++++++++++++++++++- src/msgs/data_requests/types_tests.rs | 20 +++++++++++++++++++- src/msgs/staking/types.rs | 2 +- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/msgs/data_requests/execute/mod.rs b/src/msgs/data_requests/execute/mod.rs index f26f17b..8fe6eb8 100644 --- a/src/msgs/data_requests/execute/mod.rs +++ b/src/msgs/data_requests/execute/mod.rs @@ -11,6 +11,7 @@ pub enum ExecuteMsg { CommitDataResult(commit_result::Execute), PostDataRequest(post_request::Execute), RevealDataResult(reveal_result::Execute), + SetTimeoutConfig(TimeoutConfig), } impl From for super::ExecuteMsg { diff --git a/src/msgs/data_requests/types.rs b/src/msgs/data_requests/types.rs index 199c155..0f2d0b4 100644 --- a/src/msgs/data_requests/types.rs +++ b/src/msgs/data_requests/types.rs @@ -1,5 +1,5 @@ #[cfg(not(feature = "cosmwasm"))] -use base64::{prelude::BASE64_STANDARD, Engine}; +use base64::{Engine, prelude::BASE64_STANDARD}; #[cfg(feature = "cosmwasm")] use cw_storage_plus::{Key, Prefixer, PrimaryKey}; use semver::Version; @@ -297,3 +297,20 @@ impl TryHashSelf for PostDataRequestArgs { Ok(dr_hasher.finalize().into()) } } + +/// Governance-controlled timeout configuration parameters +#[cfg_attr(feature = "cosmwasm", cw_serde)] +#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Deserialize, Debug, PartialEq))] +#[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] +pub struct TimeoutConfig { + /// Number of blocks after which a data request is timed out while waiting for commits. + pub commit_timeout_in_blocks: u64, + /// Number of blocks after which a data request is timed out while waiting for reveals. + pub reveal_timeout_in_blocks: u64, +} + +impl From for crate::msgs::ExecuteMsg { + fn from(config: TimeoutConfig) -> Self { + super::execute::ExecuteMsg::SetTimeoutConfig(config).into() + } +} diff --git a/src/msgs/data_requests/types_tests.rs b/src/msgs/data_requests/types_tests.rs index 487b0e4..540d36e 100644 --- a/src/msgs/data_requests/types_tests.rs +++ b/src/msgs/data_requests/types_tests.rs @@ -4,7 +4,7 @@ use serde_json::json; #[cfg(feature = "cosmwasm")] use super::Bytes; -use super::{DataRequest, DataResult, HashSelf, PostDataRequestArgs, RevealBody, U128}; +use super::{DataRequest, DataResult, HashSelf, PostDataRequestArgs, RevealBody, TimeoutConfig, U128}; use crate::msgs::*; #[test] @@ -240,3 +240,21 @@ fn json_post_data_request_args() { assert_json_ser(msg, expected_json); } + +#[test] +fn json_timeout_config() { + let expected_json = json!({ + "commit_timeout_in_blocks": 5, + "reveal_timeout_in_blocks": 10, + }); + + let msg = TimeoutConfig { + commit_timeout_in_blocks: 5, + reveal_timeout_in_blocks: 10, + }; + + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); +} diff --git a/src/msgs/staking/types.rs b/src/msgs/staking/types.rs index f40039c..e87e14c 100644 --- a/src/msgs/staking/types.rs +++ b/src/msgs/staking/types.rs @@ -10,7 +10,7 @@ pub struct Staker { pub tokens_pending_withdrawal: U128, } -/// Governance-controlled configuration parameters +/// Governance-controlled staking configuration parameters #[cfg_attr(feature = "cosmwasm", cw_serde)] #[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Deserialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))]