Skip to content

Commit

Permalink
feat: timeout config
Browse files Browse the repository at this point in the history
  • Loading branch information
gluax committed Sep 26, 2024
1 parent 91ee904 commit c567558
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/msgs/data_requests/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub enum ExecuteMsg {
CommitDataResult(commit_result::Execute),
PostDataRequest(post_request::Execute),
RevealDataResult(reveal_result::Execute),
SetTimeoutConfig(TimeoutConfig),
}

impl From<ExecuteMsg> for super::ExecuteMsg {
Expand Down
19 changes: 18 additions & 1 deletion src/msgs/data_requests/types.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<TimeoutConfig> for crate::msgs::ExecuteMsg {
fn from(config: TimeoutConfig) -> Self {
super::execute::ExecuteMsg::SetTimeoutConfig(config).into()
}
}
20 changes: 19 additions & 1 deletion src/msgs/data_requests/types_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion src/msgs/staking/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down

0 comments on commit c567558

Please sign in to comment.