Skip to content

Commit

Permalink
Merge pull request #85 from neutron-org/fix/revision-number-and-height
Browse files Browse the repository at this point in the history
NTRN-383 revision number and height in query
  • Loading branch information
zavgorodnii authored Mar 22, 2023
2 parents e2d4b9d + 03e8442 commit 979e0de
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 15 deletions.
4 changes: 2 additions & 2 deletions contracts/neutron_interchain_queries/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::msg::{ExecuteMsg, GetRecipientTxsResponse, InstantiateMsg, MigrateMsg
use crate::state::{Transfer, RECIPIENT_TXS, TRANSFERS};
use neutron_sdk::bindings::msg::NeutronMsg;
use neutron_sdk::bindings::query::{InterchainQueries, QueryRegisteredQueryResponse};
use neutron_sdk::bindings::types::KVKey;
use neutron_sdk::bindings::types::{Height, KVKey};
use neutron_sdk::interchain_queries::queries::{
get_registered_query, query_balance, query_bank_total, query_delegations,
query_distribution_fee_pool, query_government_proposals, query_staking_validators,
Expand Down Expand Up @@ -268,7 +268,7 @@ pub fn sudo_tx_query_result(
deps: DepsMut<InterchainQueries>,
_env: Env,
query_id: u64,
_height: u64,
_height: Height,
data: Binary,
) -> NeutronResult<Response> {
// Decode the transaction data
Expand Down
77 changes: 69 additions & 8 deletions contracts/neutron_interchain_queries/src/testing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use neutron_sdk::bindings::query::{
InterchainQueries, QueryRegisteredQueryResponse, QueryRegisteredQueryResultResponse,
};
use neutron_sdk::bindings::types::{
decode_hex, InterchainQueryResult, KVKey, KVKeys, RegisteredQuery, StorageValue,
decode_hex, Height, InterchainQueryResult, KVKey, KVKeys, RegisteredQuery, StorageValue,
};
use neutron_sdk::interchain_queries::helpers::{
create_account_denom_balance_key, create_fee_pool_key, create_gov_proposal_key,
Expand Down Expand Up @@ -62,7 +62,10 @@ fn build_registered_query_response(
connection_id: "".to_string(),
update_period: 0,
last_submitted_result_local_height,
last_submitted_result_remote_height: 0,
last_submitted_result_remote_height: Height {
revision_number: 0,
revision_height: 0,
},
deposit: Vec::from([Coin {
denom: "stake".to_string(),
amount: Uint128::from_str("100").unwrap(),
Expand Down Expand Up @@ -706,7 +709,17 @@ fn test_sudo_tx_query_result_callback() {
// simulate neutron's SudoTxQueryResult call with the following payload:
// a sending from neutron10h9stc5v6ntgeygf5xf945njqq5h32r54rf7kf to watched_addr of 10000 stake
let data: Binary = Binary::from(base64::decode("CpMBCpABChwvY29zbW9zLmJhbmsudjFiZXRhMS5Nc2dTZW5kEnAKLm5ldXRyb24xMGg5c3RjNXY2bnRnZXlnZjV4Zjk0NW5qcXE1aDMycjU0cmY3a2YSLm5ldXRyb24xZmo2eXFya3B3NmZtcDdmN2poajU3ZHVqZnB3YWw0bTI1ZGFmengaDgoFc3Rha2USBTEwMDAwEmcKUApGCh8vY29zbW9zLmNyeXB0by5zZWNwMjU2azEuUHViS2V5EiMKIQJPYibh+Zef13ZkulPqI27rV5xswZ0H/vh1Tnymp1RHPhIECgIIARgAEhMKDQoFc3Rha2USBDEwMDAQwJoMGkAIiXNJXmA57KhyaWpKcLLr3602A5+hlvv/b4PgcDDm9y0qikC+biNZXin1dEMpHOvX9DwOWJ9utv6EKljiSyfT").unwrap());
sudo_tx_query_result(deps.as_mut(), env.clone(), query_id, height, data).unwrap();
sudo_tx_query_result(
deps.as_mut(),
env.clone(),
query_id,
Height {
revision_number: 0,
revision_height: height,
},
data,
)
.unwrap();

// ensure the callback has worked and contract's state has changed
let txs = RECIPIENT_TXS.load(&deps.storage, &watched_addr).unwrap();
Expand All @@ -723,7 +736,16 @@ fn test_sudo_tx_query_result_callback() {
// simulate neutron's SudoTxQueryResult call with the following payload:
// a sending from neutron10h9stc5v6ntgeygf5xf945njqq5h32r54rf7kf to another addr of 10000 stake
let data: Binary = Binary::from(base64::decode("CpMBCpABChwvY29zbW9zLmJhbmsudjFiZXRhMS5Nc2dTZW5kEnAKLm5ldXRyb24xMGg5c3RjNXY2bnRnZXlnZjV4Zjk0NW5qcXE1aDMycjU0cmY3a2YSLm5ldXRyb24xNHV4dnUyMmxocmF6eXhhZGFxdjVkNmxzd3UwcDI3NmxsN2hya2waDgoFc3Rha2USBTEwMDAwEmcKUApGCh8vY29zbW9zLmNyeXB0by5zZWNwMjU2azEuUHViS2V5EiMKIQJPYibh+Zef13ZkulPqI27rV5xswZ0H/vh1Tnymp1RHPhIECgIIARgAEhMKDQoFc3Rha2USBDEwMDAQwJoMGkBEv2CW/0gIrankNl4aGs9LXy2BKA6kAWyl4MUxmXnbnjRpgaNbQIyo4i7nUgVsuOpqzAdudM2M53OSU0Dmo5tF").unwrap());
let res = sudo_tx_query_result(deps.as_mut(), env.clone(), query_id, height, data);
let res = sudo_tx_query_result(
deps.as_mut(),
env.clone(),
query_id,
Height {
revision_number: 0,
revision_height: height,
},
data,
);

// ensure the callback has returned an error and contract's state hasn't changed
assert_eq!(
Expand All @@ -746,7 +768,17 @@ fn test_sudo_tx_query_result_callback() {
// simulate neutron's SudoTxQueryResult call with the following payload:
// a sending from neutron10h9stc5v6ntgeygf5xf945njqq5h32r54rf7kf to watched_addr of 10000 stake
let data: Binary = Binary::from(base64::decode("CpMBCpABChwvY29zbW9zLmJhbmsudjFiZXRhMS5Nc2dTZW5kEnAKLm5ldXRyb24xMGg5c3RjNXY2bnRnZXlnZjV4Zjk0NW5qcXE1aDMycjU0cmY3a2YSLm5ldXRyb24xZmo2eXFya3B3NmZtcDdmN2poajU3ZHVqZnB3YWw0bTI1ZGFmengaDgoFc3Rha2USBTEwMDAwEmcKUApGCh8vY29zbW9zLmNyeXB0by5zZWNwMjU2azEuUHViS2V5EiMKIQJPYibh+Zef13ZkulPqI27rV5xswZ0H/vh1Tnymp1RHPhIECgIIARgAEhMKDQoFc3Rha2USBDEwMDAQwJoMGkAIiXNJXmA57KhyaWpKcLLr3602A5+hlvv/b4PgcDDm9y0qikC+biNZXin1dEMpHOvX9DwOWJ9utv6EKljiSyfT").unwrap());
sudo_tx_query_result(deps.as_mut(), env, query_id, height, data).unwrap();
sudo_tx_query_result(
deps.as_mut(),
env,
query_id,
Height {
revision_number: 0,
revision_height: height,
},
data,
)
.unwrap();

// ensure the callback has worked and contract's state has changed again
let txs = RECIPIENT_TXS.load(&deps.storage, &watched_addr).unwrap();
Expand Down Expand Up @@ -801,7 +833,17 @@ fn test_sudo_tx_query_result_min_height_callback() {
// simulate neutron's SudoTxQueryResult call with the following payload:
// a sending from neutron10h9stc5v6ntgeygf5xf945njqq5h32r54rf7kf to watched_addr of 10000 stake
let data: Binary = Binary::from(base64::decode("CpMBCpABChwvY29zbW9zLmJhbmsudjFiZXRhMS5Nc2dTZW5kEnAKLm5ldXRyb24xMGg5c3RjNXY2bnRnZXlnZjV4Zjk0NW5qcXE1aDMycjU0cmY3a2YSLm5ldXRyb24xZmo2eXFya3B3NmZtcDdmN2poajU3ZHVqZnB3YWw0bTI1ZGFmengaDgoFc3Rha2USBTEwMDAwEmcKUApGCh8vY29zbW9zLmNyeXB0by5zZWNwMjU2azEuUHViS2V5EiMKIQJPYibh+Zef13ZkulPqI27rV5xswZ0H/vh1Tnymp1RHPhIECgIIARgAEhMKDQoFc3Rha2USBDEwMDAQwJoMGkAIiXNJXmA57KhyaWpKcLLr3602A5+hlvv/b4PgcDDm9y0qikC+biNZXin1dEMpHOvX9DwOWJ9utv6EKljiSyfT").unwrap());
sudo_tx_query_result(deps.as_mut(), env.clone(), query_id, height, data).unwrap();
sudo_tx_query_result(
deps.as_mut(),
env.clone(),
query_id,
Height {
revision_number: 0,
revision_height: height,
},
data,
)
.unwrap();

// ensure the callback has worked and contract's state has changed
let txs = RECIPIENT_TXS.load(&deps.storage, &watched_addr).unwrap();
Expand All @@ -818,7 +860,16 @@ fn test_sudo_tx_query_result_min_height_callback() {
// simulate neutron's SudoTxQueryResult call with the following payload:
// a sending from neutron10h9stc5v6ntgeygf5xf945njqq5h32r54rf7kf to another addr of 10000 stake
let data: Binary = Binary::from(base64::decode("CpMBCpABChwvY29zbW9zLmJhbmsudjFiZXRhMS5Nc2dTZW5kEnAKLm5ldXRyb24xMGg5c3RjNXY2bnRnZXlnZjV4Zjk0NW5qcXE1aDMycjU0cmY3a2YSLm5ldXRyb24xNHV4dnUyMmxocmF6eXhhZGFxdjVkNmxzd3UwcDI3NmxsN2hya2waDgoFc3Rha2USBTEwMDAwEmcKUApGCh8vY29zbW9zLmNyeXB0by5zZWNwMjU2azEuUHViS2V5EiMKIQJPYibh+Zef13ZkulPqI27rV5xswZ0H/vh1Tnymp1RHPhIECgIIARgAEhMKDQoFc3Rha2USBDEwMDAQwJoMGkBEv2CW/0gIrankNl4aGs9LXy2BKA6kAWyl4MUxmXnbnjRpgaNbQIyo4i7nUgVsuOpqzAdudM2M53OSU0Dmo5tF").unwrap());
let res = sudo_tx_query_result(deps.as_mut(), env.clone(), query_id, height, data);
let res = sudo_tx_query_result(
deps.as_mut(),
env.clone(),
query_id,
Height {
revision_number: 0,
revision_height: height,
},
data,
);

// ensure the callback has returned an error and contract's state hasn't changed
assert_eq!(
Expand All @@ -841,7 +892,17 @@ fn test_sudo_tx_query_result_min_height_callback() {
// simulate neutron's SudoTxQueryResult call with the following payload:
// a sending from neutron10h9stc5v6ntgeygf5xf945njqq5h32r54rf7kf to watched_addr of 10000 stake
let data: Binary = Binary::from(base64::decode("CpMBCpABChwvY29zbW9zLmJhbmsudjFiZXRhMS5Nc2dTZW5kEnAKLm5ldXRyb24xMGg5c3RjNXY2bnRnZXlnZjV4Zjk0NW5qcXE1aDMycjU0cmY3a2YSLm5ldXRyb24xZmo2eXFya3B3NmZtcDdmN2poajU3ZHVqZnB3YWw0bTI1ZGFmengaDgoFc3Rha2USBTEwMDAwEmcKUApGCh8vY29zbW9zLmNyeXB0by5zZWNwMjU2azEuUHViS2V5EiMKIQJPYibh+Zef13ZkulPqI27rV5xswZ0H/vh1Tnymp1RHPhIECgIIARgAEhMKDQoFc3Rha2USBDEwMDAQwJoMGkAIiXNJXmA57KhyaWpKcLLr3602A5+hlvv/b4PgcDDm9y0qikC+biNZXin1dEMpHOvX9DwOWJ9utv6EKljiSyfT").unwrap());
sudo_tx_query_result(deps.as_mut(), env, query_id, height, data).unwrap();
sudo_tx_query_result(
deps.as_mut(),
env,
query_id,
Height {
revision_number: 0,
revision_height: height,
},
data,
)
.unwrap();

// ensure the callback has worked and contract's state has changed again
let txs = RECIPIENT_TXS.load(&deps.storage, &watched_addr).unwrap();
Expand Down
24 changes: 21 additions & 3 deletions contracts/neutron_interchain_txs/schema/sudo_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@
"$ref": "#/definitions/Binary"
},
"height": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
"$ref": "#/definitions/Height"
},
"query_id": {
"type": "integer",
Expand Down Expand Up @@ -162,6 +160,26 @@
"description": "Binary is a wrapper around Vec<u8> to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec<u8>. See also <https://github.com/CosmWasm/cosmwasm/blob/main/docs/MESSAGE_TYPES.md>.",
"type": "string"
},
"Height": {
"description": "Height represents an ibc Height type",
"type": "object",
"properties": {
"revision_height": {
"description": "*revision** is a revision of remote chain",
"default": 0,
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"revision_number": {
"description": "*revision_number** is a height of remote chain",
"default": 0,
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
}
},
"RequestPacket": {
"type": "object",
"properties": {
Expand Down
4 changes: 4 additions & 0 deletions packages/neutron-sdk/schema/neutron_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@
}
},
"IbcFee": {
"description": "IbcFee defines struct for fees that refund the relayer for `SudoMsg` messages submission. Unused fee kind will be returned back to message sender. Please refer to these links for more information: IBC transaction structure - https://docs.neutron.org/neutron/interchain-txs/messages/#msgsubmittx General mechanics of fee payments - https://docs.neutron.org/neutron/feerefunder/overview/#general-mechanics",
"type": "object",
"required": [
"ack_fee",
Expand All @@ -371,18 +372,21 @@
],
"properties": {
"ack_fee": {
"description": "*ack_fee** is an amount of coins to refund relayer for submitting ack message for a particular IBC packet.",
"type": "array",
"items": {
"$ref": "#/definitions/Coin"
}
},
"recv_fee": {
"description": "**recv_fee** currently is used for compatibility with ICS-29 interface only and must be set to zero (i.e. 0untrn), because Neutron's fee module can't refund relayer for submission of Recv IBC packets due to compatibility with target chains.",
"type": "array",
"items": {
"$ref": "#/definitions/Coin"
}
},
"timeout_fee": {
"description": "*timeout_fee** amount of coins to refund relayer for submitting timeout message for a particular IBC packet.",
"type": "array",
"items": {
"$ref": "#/definitions/Coin"
Expand Down
13 changes: 12 additions & 1 deletion packages/neutron-sdk/src/bindings/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct RegisteredQuery {
pub last_submitted_result_local_height: u64,
/// The remote chain last block height when the query result was updated.
#[serde(default)]
pub last_submitted_result_remote_height: u64,
pub last_submitted_result_remote_height: Height,
/// Amount of coins deposited for the query.
#[serde(default)]
pub deposit: Vec<Coin>,
Expand All @@ -56,6 +56,17 @@ pub struct RegisteredQuery {
pub registered_at_height: u64,
}

#[derive(Default, Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct Height {
/// the revision that the client is currently on
#[serde(default)]
pub revision_number: u64,
/// **height** is a height of remote chain
#[serde(default)]
pub revision_height: u64,
}

/// InterchainQueryResult is a result data for a registered query
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
Expand Down
3 changes: 2 additions & 1 deletion packages/neutron-sdk/src/sudo/msg.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::bindings::types::Height;
use cosmwasm_std::Binary;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -41,7 +42,7 @@ pub enum SudoMsg {
},
TxQueryResult {
query_id: u64,
height: u64,
height: Height,
data: Binary,
},
#[serde(rename = "kv_query_result")]
Expand Down

0 comments on commit 979e0de

Please sign in to comment.