Skip to content

Commit

Permalink
add resubmit_failure method to both interchain_txs and ibc_transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Aug 11, 2023
1 parent d3aec44 commit c56cdf1
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 14 deletions.
38 changes: 29 additions & 9 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion contracts/ibc_transfer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ schemars = "0.8.10"
serde = { version = "1.0.180", default-features = false, features = ["derive"] }
serde-json-wasm = { version = "0.5.1" }
cw-storage-plus = { version = "1.1.0", features = ["iterator"]}
neutron-sdk = { package = "neutron-sdk", version = "0.6.1" }
neutron-sdk = { package = "neutron-sdk", git = "https://github.com/neutron-org/neutron-sdk", rev = "bb2188561a30d0a7fb293ff05f73907724eb2020" }
protobuf = { version = "3.2.0", features = ["with-bytes"] }

[dev-dependencies]
Expand Down
22 changes: 22 additions & 0 deletions contracts/ibc_transfer/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,28 @@
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"resubmit_failure"
],
"properties": {
"resubmit_failure": {
"type": "object",
"required": [
"failure_id"
],
"properties": {
"failure_id": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
}
}
},
"additionalProperties": false
},
{
"description": "Used only in integration tests framework to simulate failures. After executing this message, contract will fail, all of this happening in sudo callback handler.",
"type": "object",
Expand Down
11 changes: 11 additions & 0 deletions contracts/ibc_transfer/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ pub enum ExecuteMsg {
timeout_fee: u128,
denom: String,
},
ResubmitFailure {
failure_id: u64,
},
/// Used only in integration tests framework to simulate failures.
/// After executing this message, contract will fail, all of this happening
/// in sudo callback handler.
Expand Down Expand Up @@ -94,6 +97,9 @@ pub fn execute(
timeout_fee,
denom,
} => execute_set_fees(deps, recv_fee, ack_fee, timeout_fee, denom),

ExecuteMsg::ResubmitFailure { failure_id } => execute_resubmit_failure(deps, failure_id),

// Used only in integration tests framework to simulate failures.
// After executing this message, contract fail, all of this happening
// in sudo callback handler.
Expand Down Expand Up @@ -258,6 +264,11 @@ fn execute_send(
Ok(Response::default().add_submessages(vec![submsg1, submsg2]))
}

fn execute_resubmit_failure(_: DepsMut, failure_id: u64) -> StdResult<Response<NeutronMsg>> {
let msg = NeutronMsg::submit_resubmit_failure(failure_id);
Ok(Response::default().add_message(msg))
}

#[allow(unreachable_code)]
#[entry_point]
pub fn sudo(deps: DepsMut, _env: Env, msg: TransferSudoMsg) -> StdResult<Response> {
Expand Down
2 changes: 1 addition & 1 deletion contracts/neutron_interchain_txs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ serde = { version = "1.0.180", default-features = false, features = ["derive"] }
serde-json-wasm = { version = "0.5.1" }
cw-storage-plus = { version = "1.1.0", features = ["iterator"]}
cosmos-sdk-proto = { version = "0.16.0", default-features = false }
neutron-sdk = { package = "neutron-sdk", version = "0.6.1" }
neutron-sdk = { package = "neutron-sdk", git = "https://github.com/neutron-org/neutron-sdk", rev = "bb2188561a30d0a7fb293ff05f73907724eb2020" }
base64 = "0.21.2"
protobuf = { version = "3.2.0", features = ["with-bytes"] }
prost = "0.11"
Expand Down
22 changes: 22 additions & 0 deletions contracts/neutron_interchain_txs/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,28 @@
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"resubmit_failure"
],
"properties": {
"resubmit_failure": {
"type": "object",
"required": [
"failure_id"
],
"properties": {
"failure_id": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
}
}
},
"additionalProperties": false
},
{
"description": "Used only in integration tests framework to simulate failures. After executing this message, any sudo call to the contract will result in an error.",
"type": "object",
Expand Down
13 changes: 10 additions & 3 deletions contracts/neutron_interchain_txs/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ use neutron_sdk::NeutronResult;
use crate::storage::{
add_error_to_queue, read_errors_from_queue, read_reply_payload, read_sudo_payload,
save_reply_payload, save_sudo_payload, AcknowledgementResult, DoubleDelegateInfo,
IntegrationTestsSudoFailureMock, IntegrationTestsSudoSubmsgFailureMock, SudoPayload, ACKNOWLEDGEMENT_RESULTS,
IBC_FEE, INTEGRATION_TESTS_SUDO_FAILURE_MOCK, INTEGRATION_TESTS_SUDO_SUBMSG_FAILURE_MOCK,
INTERCHAIN_ACCOUNTS, SUDO_FAILING_SUBMSG_REPLY_ID, SUDO_PAYLOAD_REPLY_ID,
IntegrationTestsSudoFailureMock, IntegrationTestsSudoSubmsgFailureMock, SudoPayload,
ACKNOWLEDGEMENT_RESULTS, IBC_FEE, INTEGRATION_TESTS_SUDO_FAILURE_MOCK,
INTEGRATION_TESTS_SUDO_SUBMSG_FAILURE_MOCK, INTERCHAIN_ACCOUNTS, SUDO_FAILING_SUBMSG_REPLY_ID,
SUDO_PAYLOAD_REPLY_ID,
};

// Default timeout for SubmitTX is two weeks
Expand Down Expand Up @@ -168,6 +169,7 @@ pub fn execute(
timeout_fee,
} => execute_set_fees(deps, denom, recv_fee, ack_fee, timeout_fee),
ExecuteMsg::CleanAckResults {} => execute_clean_ack_results(deps),
ExecuteMsg::ResubmitFailure { failure_id } => execute_resubmit_failure(deps, failure_id),

// The section below is used only in integration tests framework to simulate failures.
ExecuteMsg::IntegrationTestsSetSudoFailureMock {} => set_sudo_failure_mock(deps),
Expand Down Expand Up @@ -434,6 +436,11 @@ fn execute_clean_ack_results(deps: DepsMut) -> StdResult<Response<NeutronMsg>> {
Ok(Response::default())
}

fn execute_resubmit_failure(_: DepsMut, failure_id: u64) -> StdResult<Response<NeutronMsg>> {
let msg = NeutronMsg::submit_resubmit_failure(failure_id);
Ok(Response::default().add_message(msg))
}

fn integration_tests_sudo_submsg(deps: DepsMut) -> StdResult<Response<NeutronMsg>> {
if let Some(IntegrationTestsSudoSubmsgFailureMock::Enabled {}) =
INTEGRATION_TESTS_SUDO_SUBMSG_FAILURE_MOCK.may_load(deps.storage)?
Expand Down
3 changes: 3 additions & 0 deletions contracts/neutron_interchain_txs/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ pub enum ExecuteMsg {
timeout: Option<u64>,
},
CleanAckResults {},
ResubmitFailure {
failure_id: u64,
},
/// Used only in integration tests framework to simulate failures.
/// After executing this message, any sudo call to the contract will result in an error.
IntegrationTestsSetSudoFailureMock {},
Expand Down

0 comments on commit c56cdf1

Please sign in to comment.