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(xcvm): rework protocol messages [breaking change] #4116

Merged
merged 6 commits into from
Sep 11, 2023
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
4 changes: 0 additions & 4 deletions code/Cargo.lock

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

6 changes: 3 additions & 3 deletions code/xcvm/cosmwasm/contracts/gateway/src/contract/ibc/xcvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn ibc_packet_receive(
) -> Result<IbcReceiveResponse> {
let response = IbcReceiveResponse::default().add_event(make_event("receive"));
let msg = (|| -> Result<_> {
let packet = XcPacket::try_decode(&msg.packet.data)?;
let packet = XcPacket::decode(&msg.packet.data)?;
let call_origin = CallOrigin::Remote { user_origin: packet.user_origin };
let execute_program = msg::ExecuteProgramMsg {
salt: packet.salt,
Expand Down Expand Up @@ -119,7 +119,7 @@ pub fn ibc_packet_receive(
pub fn ibc_packet_ack(_deps: DepsMut, _env: Env, msg: IbcPacketAckMsg) -> Result<IbcBasicResponse> {
let ack = XCVMAck::try_from(msg.acknowledgement.data.as_slice())
.map_err(|_| ContractError::InvalidAck)?;
XcPacket::try_decode(&msg.original_packet.data)?;
XcPacket::decode(&msg.original_packet.data)?;
Ok(IbcBasicResponse::default().add_event(make_event("ack").add_attribute("ack", ack)))
}

Expand All @@ -129,7 +129,7 @@ pub fn ibc_packet_timeout(
_env: Env,
msg: IbcPacketTimeoutMsg,
) -> Result<IbcBasicResponse> {
XcPacket::try_decode(&msg.packet.data)?;
XcPacket::decode(&msg.packet.data)?;
// https://github.com/cosmos/ibc/pull/998
Ok(IbcBasicResponse::default())
}
Expand Down
8 changes: 4 additions & 4 deletions code/xcvm/cosmwasm/contracts/interpreter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ pub fn handle_execute_step(
interpret_transfer(&mut deps, &env, &tip, to, assets),
Instruction::Call { bindings, encoded } =>
interpret_call(deps.as_ref(), &env, bindings, encoded, instruction_pointer, &tip),
Instruction::Spawn { network, salt, assets, program } =>
interpret_spawn(&mut deps, &env, network, salt, assets, program),
Instruction::Exchange { give, id, want } =>
interpret_exchange(&mut deps, give, want, id, env.contract.address.clone()),
Instruction::Spawn { network_id, salt, assets, program } =>
interpret_spawn(&mut deps, &env, network_id, salt, assets, program),
Instruction::Exchange { exchange_id, give, want } =>
interpret_exchange(&mut deps, give, want, exchange_id, env.contract.address.clone()),
}?;
// Save the intermediate IP so that if the execution fails, we can recover at which
// instruction it happened.
Expand Down
118 changes: 31 additions & 87 deletions code/xcvm/lib/core/protos/xcvm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,36 @@ import "common.proto";
package cvm.xcvm;

message PacketAsset {
AssetId assetId = 1;
cvm.common.Uint128 asset_id = 1;
cvm.common.Uint128 amount = 2;

// next tag: 3
}

message Packet {
Account interpreter = 1;
bytes interpreter = 1;
UserOrigin user_origin = 2;
Salt salt = 3;
bytes salt = 3;
Program program = 4;
repeated PacketAsset assets = 5;

// next tag: 6
}

message UserOrigin {
Network network = 1;
Account account = 2;
uint32 network_id = 1;
bytes account = 2;

// next tag: 3
}

message Program {
bytes tag = 1;
Instructions instructions = 2;
repeated Instruction instructions = 2;

// next tag: 3
}

message Instructions {
repeated Instruction instructions = 1;

// next tag: 2
}

message Instruction {
oneof instruction {
Transfer transfer = 1;
Expand Down Expand Up @@ -83,121 +77,71 @@ message Balance {
// next tag: 4
}

message Account {
bytes account = 1;

// next tag: 2
}

message AssetId {
cvm.common.Uint128 id = 1;

// next tag: 2
}

message ExchangeId {
cvm.common.Uint128 id = 1;

// next tag: 2
}

message Asset {
AssetId assetId = 1;
cvm.common.Uint128 asset_id = 1;
Balance balance = 2;

// next tag: 3
}

message Self {
uint32 self = 1;

// next tag: 2
}

message Tip {
uint32 id = 1;

// next tag: 2
}

message Result {
uint32 result = 1;

// next tag: 2
}

message AssetAmount {
AssetId assetId = 1;
cvm.common.Uint128 asset_id = 1;
Balance balance = 2;

// next tag: 3
}

message IpRegister {
uint64 ip = 1;

// next tag: 2
}

message BindingValue {
oneof type {
Self self = 1;
Tip tip = 2;
Result result = 3;
AssetAmount assetAmount = 4;
AssetId assetId = 5;
IpRegister ipRegister = 6;
Register register = 1;
cvm.common.Uint128 asset_id = 2;
AssetAmount asset_amount = 3;
}

// next tag: 7
// next tag: 4
}

message Binding {
uint32 position = 1;
BindingValue bindingValue = 2;
enum Register {
IP = 0;
TIP = 1;
THIS = 2;
RESULT = 3;

// next tag: 3
// next tag: 4
}

message Bindings {
repeated Binding bindings = 1;
message Binding {
uint32 position = 1;
BindingValue binding_value = 2;

// next tag: 2
// next tag: 3
}

message Transfer {
oneof account_type{
Account account = 1;
bytes account = 1;
Tip tip = 2;
}
repeated Asset assets = 3;

// next tag: 4
}

message Tip {
// next tag: 1
}

message Exchange {
ExchangeId id = 1;
cvm.common.Uint128 exchange_id = 1;
repeated Asset give = 5;
repeated Asset want = 6;

// next tag: 7
}

message Salt {
bytes salt = 1;

// next tag: 2
}

message Network {
uint32 networkId = 1;

// next tag: 2
}

message Spawn {
Network network = 1;
Salt salt = 3;
uint32 network_id = 1;
bytes salt = 3;
Program program = 4;
repeated Asset assets = 5;

Expand All @@ -206,7 +150,7 @@ message Spawn {

message Call {
bytes payload = 1;
Bindings bindings = 2;
repeated Binding bindings = 2;

// next tag: 3
}
24 changes: 12 additions & 12 deletions code/xcvm/lib/core/src/gateway/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ mod tests {
program: XcProgram {
tag: b"spawn_with_asset".to_vec(),
instructions: [Instruction::Spawn {
network: 3.into(),
network_id: 3.into(),
salt: b"spawn_with_asset".to_vec(),
assets: vec![(pica_on_osmosis, 1_000_000_000u128)].into(),
program: XcProgram {
Expand Down Expand Up @@ -327,7 +327,7 @@ mod tests {
"instructions": [
{
"spawn": {
"network": 3,
"network_id": 3,
"salt": "737061776e5f776974685f6173736574",
"assets": [
[
Expand Down Expand Up @@ -378,7 +378,7 @@ mod tests {
program: XcProgram {
tag: b"spawn_with_asset".to_vec(),
instructions: [Instruction::Spawn {
network: 3.into(),
network_id: 3.into(),
salt: b"spawn_with_asset".to_vec(),
assets: vec![(pica_on_osmosis, 1_000_000_000u128)].into(),
program: XcProgram {
Expand Down Expand Up @@ -414,7 +414,7 @@ mod tests {
"instructions": [
{
"spawn": {
"network": 3,
"network_id": 3,
"salt": "737061776e5f776974685f6173736574",
"assets": [
[
Expand Down Expand Up @@ -488,19 +488,19 @@ mod tests {
program: XcProgram {
tag: b"spawn_with_asset".to_vec(),
instructions: [Instruction::Spawn {
network: 3.into(),
network_id: 3.into(),
salt: b"spawn_with_asset".to_vec(),
assets: vec![(pica_on_osmosis, 1_000_000_000u128)].into(),
program: XcProgram {
tag: b"spawn_with_asset".to_vec(),
instructions: [
XcInstruction::Exchange {
id: pica_osmo_on_osmosis.into(),
exchange_id: pica_osmo_on_osmosis.into(),
give: XcFundsFilter::one(pica_on_osmosis, 1_000_000_000u128),
want: XcFundsFilter::one(osmo_on_osmosis, 1_000u128),
},
XcInstruction::Spawn {
network: 2.into(),
network_id: 2.into(),
salt: b"spawn_with_asset".to_vec(),
assets: XcFundsFilter::one(osmo_on_centauri, (100, 100)),
program: XcProgram {
Expand Down Expand Up @@ -545,7 +545,7 @@ mod tests {
"instructions": [
{
"spawn": {
"network": 3,
"network_id": 3,
"salt": "737061776e5f776974685f6173736574",
"assets": [
[
Expand All @@ -564,7 +564,7 @@ mod tests {
"instructions": [
{
"exchange": {
"id": "237684489387467420151587012609",
"exchange_id": "237684489387467420151587012609",
"give": [
[
"237684487542793012780631851009",
Expand Down Expand Up @@ -593,7 +593,7 @@ mod tests {
},
{
"spawn": {
"network": 2,
"network_id": 2,
"salt": "737061776e5f776974685f6173736574",
"assets": [
[
Expand Down Expand Up @@ -667,7 +667,7 @@ mod tests {
program: XcProgram {
tag: b"spawn_with_asset".to_vec(),
instructions: [Instruction::Spawn {
network: 2.into(),
network_id: 2.into(),
salt: b"spawn_with_asset".to_vec(),
assets: vec![(osmo_on_centauri, 1_000_000_000u128)].into(),
program: XcProgram {
Expand Down Expand Up @@ -696,7 +696,7 @@ mod tests {
"instructions": [
{
"spawn": {
"network": 2,
"network_id": 2,
"salt": "737061776e5f776974685f6173736574",
"assets": [
[
Expand Down
4 changes: 2 additions & 2 deletions code/xcvm/lib/core/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub enum Instruction<Payload, Account, Assets> {
/// The program will be spawned with the desired [`Assets`].
/// The salt is used to track the program when events are dispatched in the network.
Spawn {
network: crate::network::NetworkId,
network_id: crate::network::NetworkId,
/// If JSON, than hex encoded non prefixed lower case string.
#[serde(serialize_with = "hex::serialize", deserialize_with = "hex::deserialize")]
#[cfg_attr(feature = "std", schemars(schema_with = "String::json_schema"))]
Expand All @@ -85,7 +85,7 @@ pub enum Instruction<Payload, Account, Assets> {
program: Program<VecDeque<Self>>,
},
Exchange {
id: ExchangeId,
exchange_id: ExchangeId,
give: Assets,
want: Assets,
},
Expand Down
Loading