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: save failed submsg result in reply for timelocked contract #ntrn-80 #78

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4a733f4
feat: save execution failure for proposal in timelock contract
NeverHappened Aug 28, 2023
e3f7b16
add comment for expected format of returned error
NeverHappened Sep 1, 2023
ef65e8b
feat: save lists of failures instead of one and block height with it
NeverHappened Sep 5, 2023
0c7b849
fix lint
NeverHappened Sep 5, 2023
56765ce
review fixes
NeverHappened Sep 7, 2023
e1e145d
fix schema
NeverHappened Sep 7, 2023
5ec3ca1
add test for new code
NeverHappened Sep 7, 2023
84e1123
add failed proposal errors query to single and multiple proposals
NeverHappened Sep 13, 2023
0f08386
feat: add close_proposal_on_execution_failure logic to timelocked con…
NeverHappened Sep 13, 2023
12b92f0
add query for timelock proposal module to subdao core and use it
NeverHappened Sep 14, 2023
f9fec92
check with close_proposal_on_execution_failure = false
NeverHappened Sep 14, 2023
6ca23e0
cargo fmt and cargo schema
NeverHappened Sep 14, 2023
5f767f7
fix build
NeverHappened Sep 14, 2023
f276009
add tests for reply errors in single/multiple
NeverHappened Sep 15, 2023
f316f07
fix lint on old rust version
NeverHappened Sep 15, 2023
00089ad
Merge branch 'sdk-47' into feat/save-failed-result
NeverHappened Sep 20, 2023
03a52d1
Use just string for errors since there is only one value possible. Fi…
NeverHappened Sep 29, 2023
059fdfc
fix
NeverHappened Oct 6, 2023
71b6b2c
review fixes
NeverHappened Oct 7, 2023
8b2dda5
Get back check for subdao search
NeverHappened Oct 9, 2023
27c663f
add comment explaining subdao addr check
NeverHappened Oct 10, 2023
76304ab
review fixes - rename failed_execution_proposal_errors -> failed_prop…
NeverHappened Oct 10, 2023
6cd5624
review fixes - rename arg
NeverHappened Oct 10, 2023
381a000
timelock_contract -> Addr
NeverHappened Oct 10, 2023
61ea818
Merge branch 'sdk-47' into feat/save-failed-result
NeverHappened Oct 10, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -1918,6 +1918,30 @@
}
},
"additionalProperties": false
},
{
"description": "Returns an error of the failed proposal. Expected in the form of \"codespace=? code=?\". Returns `Option<String>`",
"type": "object",
"required": [
"proposal_failed_execution_error"
],
"properties": {
"proposal_failed_execution_error": {
"type": "object",
"required": [
"proposal_id"
],
"properties": {
"proposal_id": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
]
},
Expand Down Expand Up @@ -5535,6 +5559,14 @@
]
}
}
},
"proposal_failed_execution_error": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Nullable_String",
"type": [
"string",
"null"
]
}
}
}
24 changes: 24 additions & 0 deletions contracts/subdaos/cwd-subdao-timelock-single/schema/raw/query.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@
}
},
"additionalProperties": false
},
{
"description": "Returns an error of the failed proposal. Expected in the form of \"codespace=? code=?\". Returns `Option<String>`",
"type": "object",
"required": [
"proposal_failed_execution_error"
],
"properties": {
"proposal_failed_execution_error": {
"type": "object",
"required": [
"proposal_id"
],
"properties": {
"proposal_id": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Nullable_String",
"type": [
"string",
"null"
]
}
19 changes: 17 additions & 2 deletions contracts/subdaos/cwd-subdao-timelock-single/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use neutron_subdao_timelock_single::{
};

use crate::error::ContractError;
use crate::state::{CONFIG, DEFAULT_LIMIT, PROPOSALS};
use crate::state::{CONFIG, DEFAULT_LIMIT, PROPOSALS, PROPOSAL_FAILED_EXECUTION_ERRORS};

pub(crate) const CONTRACT_NAME: &str = "crates.io:cwd-subdao-timelock-single";
pub(crate) const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down Expand Up @@ -248,6 +248,9 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
QueryMsg::ListProposals { start_after, limit } => {
query_list_proposals(deps, start_after, limit)
}
QueryMsg::ProposalFailedExecutionError { proposal_id } => {
query_proposal_failed_execution_error(deps, proposal_id)
}
}
}

Expand All @@ -274,6 +277,11 @@ pub fn query_list_proposals(
to_binary(&ProposalListResponse { proposals: props })
}

fn query_proposal_failed_execution_error(deps: Deps, proposal_id: u64) -> StdResult<Binary> {
let proposal_error = PROPOSAL_FAILED_EXECUTION_ERRORS.may_load(deps.storage, proposal_id)?;
to_binary(&proposal_error)
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError> {
// Set contract to version to latest
Expand Down Expand Up @@ -315,12 +323,19 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractE
PROPOSALS.update(deps.storage, proposal_id, |prop| match prop {
Some(mut prop) => {
prop.status = ProposalStatus::ExecutionFailed;

Ok(prop)
}
None => Err(ContractError::NoSuchProposal { id: proposal_id }),
})?;

let err = msg
.result
.into_result()
.err()
.unwrap_or_else(|| "result is not error".to_string());
// Error is reduced before cosmwasm reply and is expected in form of "codespace=? code=?"
PROPOSAL_FAILED_EXECUTION_ERRORS.save(deps.storage, proposal_id, &err)?;

Ok(Response::new().add_attribute(
"timelocked_proposal_execution_failed",
proposal_id.to_string(),
Expand Down
1 change: 1 addition & 0 deletions contracts/subdaos/cwd-subdao-timelock-single/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pub const DEFAULT_LIMIT: u64 = 30;

pub const CONFIG: Item<Config> = Item::new("config");
pub const PROPOSALS: Map<u64, SingleChoiceProposal> = Map::new("proposals");
pub const PROPOSAL_FAILED_EXECUTION_ERRORS: Map<u64, String> = Map::new("failed_proposal_errors");
6 changes: 6 additions & 0 deletions packages/neutron-subdao-timelock-single/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ pub enum QueryMsg {
/// returned.
limit: Option<u64>,
},

/// Returns an error of the failed proposal.
/// Expected in the form of "codespace=? code=?".
/// Returns `Option<String>`
#[returns(Option<String>)]
ProposalFailedExecutionError { proposal_id: u64 },
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
Expand Down