Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: commit reveal timeouts #24

Merged
merged 5 commits into from
Oct 1, 2024
Merged
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
2 changes: 1 addition & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ imports_granularity = "Crate"
imports_layout = "HorizontalVertical"
reorder_impl_items = true
struct_field_align_threshold = 120
version = "Two"
style_edition = "2021"
wrap_comments = true
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
10 changes: 10 additions & 0 deletions src/msgs/data_requests/sudo/expire_data_requests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)]
#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))]
#[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))]
pub struct Sudo {}

impl From<Sudo> for crate::msgs::SudoMsg {
fn from(value: Sudo) -> Self {
super::SudoMsg::ExpireDataRequests(value).into()
}
}
2 changes: 2 additions & 0 deletions src/msgs/data_requests/sudo/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::*;

pub mod expire_data_requests;
pub mod post_results;

#[cfg_attr(feature = "cosmwasm", cw_serde)]
Expand All @@ -23,6 +24,7 @@ impl From<PostResult> for crate::msgs::SudoMsg {
pub enum SudoMsg {
PostDataResult(PostResult),
PostDataResults(post_results::Sudo),
ExpireDataRequests(expire_data_requests::Sudo),
}

impl From<SudoMsg> for super::SudoMsg {
Expand Down
10 changes: 10 additions & 0 deletions src/msgs/data_requests/sudo_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,13 @@ fn json_post_result() {
#[cfg(feature = "cosmwasm")]
assert_json_deser(msg, expected_json);
}

#[test]
fn json_remove_timed_out_data_requests() {
let expected_json = json!({"expire_data_requests": {}});
let msg: SudoMsg = expire_data_requests::Sudo {}.into();
#[cfg(not(feature = "cosmwasm"))]
assert_json_ser(msg, expected_json);
#[cfg(feature = "cosmwasm")]
assert_json_deser(msg, expected_json);
}
17 changes: 17 additions & 0 deletions src/msgs/data_requests/types.rs
Original file line number Diff line number Diff line change
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