diff --git a/CHANGELOG.md b/CHANGELOG.md index 7aba9851a3..447c4d4e1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,11 @@ and this project adheres to - cosmwasm-std: Add `SubMsg:reply_never` constructor ([#1929]) - cosmwasm-std: Add optional memo field to `IbcMsg::Transfer`. ([#1878]) +- cosmwasm-std: Add `Reply::gas_used`. ([#1954]) [#1878]: https://github.com/CosmWasm/cosmwasm/pull/1878 [#1929]: https://github.com/CosmWasm/cosmwasm/pull/1929 +[#1954]: https://github.com/CosmWasm/cosmwasm/pull/1954 ### Changed diff --git a/SEMANTICS.md b/SEMANTICS.md index f4862e81af..017735f1e8 100644 --- a/SEMANTICS.md +++ b/SEMANTICS.md @@ -286,11 +286,12 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result` - pub result: ContractResult, + pub gas_used: u64, + /// SubMsgResult is just a nicely serializable version of `Result` + pub result: SubMsgResult, } -pub struct SubcallResponse { +pub struct SubMsgResponse { pub events: Vec, pub data: Option, } diff --git a/contracts/ibc-reflect/src/contract.rs b/contracts/ibc-reflect/src/contract.rs index e6bcb96555..3dd6c776ca 100644 --- a/contracts/ibc-reflect/src/contract.rs +++ b/contracts/ibc-reflect/src/contract.rs @@ -404,6 +404,7 @@ mod tests { // fake a reply and ensure this works let response = Reply { id, + gas_used: 1234567, result: SubMsgResult::Ok(SubMsgResponse { events: fake_events(&account), data: None, @@ -481,6 +482,7 @@ mod tests { // fake a reply and ensure this works let response = Reply { id, + gas_used: 1234567, result: SubMsgResult::Ok(SubMsgResponse { events: fake_events(REFLECT_ADDR), data: None, diff --git a/contracts/ibc-reflect/tests/integration.rs b/contracts/ibc-reflect/tests/integration.rs index 9f1e994fcf..542ff939ac 100644 --- a/contracts/ibc-reflect/tests/integration.rs +++ b/contracts/ibc-reflect/tests/integration.rs @@ -95,6 +95,7 @@ fn connect( // fake a reply and ensure this works let response = Reply { id, + gas_used: 1234567, result: SubMsgResult::Ok(SubMsgResponse { events: fake_events(&account), data: None, @@ -173,6 +174,7 @@ fn proper_handshake_flow() { // we get the callback from reflect let response = Reply { id, + gas_used: 1234567, result: SubMsgResult::Ok(SubMsgResponse { events: fake_events(REFLECT_ADDR), data: None, diff --git a/contracts/reflect/schema/raw/response_to_sub_msg_result.json b/contracts/reflect/schema/raw/response_to_sub_msg_result.json index d3b29ce66d..afe3b4b9b0 100644 --- a/contracts/reflect/schema/raw/response_to_sub_msg_result.json +++ b/contracts/reflect/schema/raw/response_to_sub_msg_result.json @@ -4,10 +4,17 @@ "description": "The result object returned to `reply`. We always get the ID from the submessage back and then must handle success and error cases ourselves.", "type": "object", "required": [ + "gas_used", "id", "result" ], "properties": { + "gas_used": { + "description": "The amount of gas used by the submessage, measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, "id": { "description": "The ID that the contract set when emitting the `SubMsg`. Use this to identify which submessage triggered the `reply`.", "type": "integer", diff --git a/contracts/reflect/schema/reflect.json b/contracts/reflect/schema/reflect.json index 09a84719e2..713ca2745c 100644 --- a/contracts/reflect/schema/reflect.json +++ b/contracts/reflect/schema/reflect.json @@ -1885,10 +1885,17 @@ "description": "The result object returned to `reply`. We always get the ID from the submessage back and then must handle success and error cases ourselves.", "type": "object", "required": [ + "gas_used", "id", "result" ], "properties": { + "gas_used": { + "description": "The amount of gas used by the submessage, measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, "id": { "description": "The ID that the contract set when emitting the `SubMsg`. Use this to identify which submessage triggered the `reply`.", "type": "integer", diff --git a/contracts/reflect/src/contract.rs b/contracts/reflect/src/contract.rs index 87208f2e94..4d32665c6e 100644 --- a/contracts/reflect/src/contract.rs +++ b/contracts/reflect/src/contract.rs @@ -434,11 +434,16 @@ mod tests { let id = 123u64; let data = Binary::from(b"foobar"); let events = vec![Event::new("message").add_attribute("signer", "caller-addr")]; + let gas_used = 1234567u64; let result = SubMsgResult::Ok(SubMsgResponse { events: events.clone(), data: Some(data.clone()), }); - let subcall = Reply { id, result }; + let subcall = Reply { + id, + gas_used, + result, + }; let res = reply(deps.as_mut(), mock_env(), subcall).unwrap(); assert_eq!(0, res.messages.len()); diff --git a/contracts/reflect/tests/integration.rs b/contracts/reflect/tests/integration.rs index 47714925f0..6be7f79bd2 100644 --- a/contracts/reflect/tests/integration.rs +++ b/contracts/reflect/tests/integration.rs @@ -268,11 +268,16 @@ fn reply_and_query() { let id = 123u64; let data = Binary::from(b"foobar"); let events = vec![Event::new("message").add_attribute("signer", "caller-addr")]; + let gas_used = 1234567u64; let result = SubMsgResult::Ok(SubMsgResponse { events: events.clone(), data: Some(data.clone()), }); - let subcall = Reply { id, result }; + let subcall = Reply { + id, + gas_used, + result, + }; let res: Response = reply(&mut deps, mock_env(), subcall).unwrap(); assert_eq!(0, res.messages.len()); diff --git a/packages/go-gen/src/main.rs b/packages/go-gen/src/main.rs index 8d3dcc3d40..7dd00d383f 100644 --- a/packages/go-gen/src/main.rs +++ b/packages/go-gen/src/main.rs @@ -11,7 +11,7 @@ mod schema; mod utils; fn main() -> Result<()> { - let root = cosmwasm_schema::schema_for!(cosmwasm_std::BankQuery); + let root = cosmwasm_schema::schema_for!(cosmwasm_std::Reply); let code = generate_go(root)?; println!("{}", code); diff --git a/packages/std/src/results/submessages.rs b/packages/std/src/results/submessages.rs index 176677abe4..973047c771 100644 --- a/packages/std/src/results/submessages.rs +++ b/packages/std/src/results/submessages.rs @@ -102,6 +102,9 @@ pub struct Reply { /// The ID that the contract set when emitting the `SubMsg`. /// Use this to identify which submessage triggered the `reply`. pub id: u64, + /// The amount of gas used by the submessage, + /// measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md). + pub gas_used: u64, pub result: SubMsgResult, } diff --git a/packages/vm/src/calls.rs b/packages/vm/src/calls.rs index 29d1b9a3ab..d9421c5b4f 100644 --- a/packages/vm/src/calls.rs +++ b/packages/vm/src/calls.rs @@ -900,6 +900,7 @@ mod tests { // which creates a reflect account. here we get the callback let response = Reply { id, + gas_used: 1234567, result: SubMsgResult::Ok(SubMsgResponse { events: vec![event], data: None,