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(orchestration): send message #9195

Merged
merged 3 commits into from
Apr 9, 2024
Merged

feat(orchestration): send message #9195

merged 3 commits into from
Apr 9, 2024

Conversation

0xpatrickdev
Copy link
Member

@0xpatrickdev 0xpatrickdev commented Apr 4, 2024

closes: #8881
refs: #9042

Description

  • Implement .executeEncodedTx on ChainAccount

    • accepts array of {typeUrl: string, value: Base64Bytes}. The Base64Bytes value keys are converted to Uint8Array, and the array of messages are then encoded inside TxBody.
    • the .send() is a JSON string in the event of success or failure. If a result key is present it is returned. If an error key is present, or neither key is found, an error is thrown.
  • Implement delegate for StakeAtom

  • Improved ibc mocks and bridge i/o in bootstrap style testing. Currently, delegating 10uatom from cosmos1test to cosmosvaloper1test should result in a successful TX. Others, like delegating to cosmosvaloper1fail will fail.

Security Considerations

Scaling Considerations

Documentation Considerations

Testing Considerations

Upgrade Considerations

@turadg turadg force-pushed the 9111-proto-messages branch from 2f54b74 to d717eb4 Compare April 4, 2024 22:39
@0xpatrickdev 0xpatrickdev force-pushed the 8881-ica-send-message branch from aa39e09 to 4982dda Compare April 4, 2024 22:56
@turadg turadg force-pushed the 9111-proto-messages branch from d717eb4 to 7b7e823 Compare April 4, 2024 23:28
@0xpatrickdev 0xpatrickdev force-pushed the 8881-ica-send-message branch from 4982dda to d0f7120 Compare April 5, 2024 03:53
@turadg turadg force-pushed the 9111-proto-messages branch 2 times, most recently from 32f2624 to 25790ee Compare April 5, 2024 16:05
@0xpatrickdev 0xpatrickdev force-pushed the 8881-ica-send-message branch from d0f7120 to e58050b Compare April 5, 2024 17:46
@0xpatrickdev 0xpatrickdev marked this pull request as ready for review April 5, 2024 17:53
@0xpatrickdev 0xpatrickdev changed the title feat(orchestration): executeEncodeTx feat(orchestration): send message Apr 5, 2024
* @param {ChannelOpenInitPacket} obj
*/
channelOpenAck: obj => {
const icaControllerNonce = obj?.packet?.source_port?.split('-')?.[1];
Copy link
Member

@michaelfig michaelfig Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems suspicious, since channelId's are frequently different between the subject chain and the counterparty, and also have no relation to the port number. Could you maybe separate and document what these numbers actually are:

Suggested change
const icaControllerNonce = obj?.packet?.source_port?.split('-')?.[1];
const sourcePortSuffix = obj?.packet?.source_port?.split('-')?.at(-1);
const destPortSuffix = obj?.packet?.destination_port?.split('-')?.at(-1);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I will add your suggestions so this mocking is documented clearly.

Copy link
Member

@michaelfig michaelfig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I have enough context to be able to officially approve, but AFAIK you can merge directly into 9111-proto-messages without my approval.

Comment on lines 67 to 70
channelID: `channel-${icaControllerNonce}`,
counterparty: {
port_id: obj.packet.destination_port,
channel_id: `channel-${icaControllerNonce}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
channelID: `channel-${icaControllerNonce}`,
counterparty: {
port_id: obj.packet.destination_port,
channel_id: `channel-${icaControllerNonce}`,
// Fake a channel ID from its port suffix.
channelID: `channel-${sourcePortSuffix}`,
counterparty: {
port_id: obj.packet.destination_port,
// Fake a channelID from its port suffix.
channel_id: `channel-${destPortSuffix}`,

Comment on lines 5 to 6
/** @import { Proto3Msg } from '../types'; */

/** @typedef {string} Base64Bytes - Uint8Array, base64 encoded */
/** @typedef {{ typeUrl: string; value: Base64Bytes; }} Proto3Msg */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the two different definitions of Proto3Msg?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not intentional, thank you

@turadg
Copy link
Member

turadg commented Apr 5, 2024

I'm not sure I have enough context to be able to officially approve, but AFAIK you can merge directly into 9111-proto-messages without my approval.

@0xpatrickdev please don't. I'd like to land that branch, #9112, today. It's green and just needs approval.

@turadg turadg force-pushed the 9111-proto-messages branch from 25790ee to e315f6d Compare April 5, 2024 20:44
@0xpatrickdev
Copy link
Member Author

I'm not sure I have enough context to be able to officially approve, but AFAIK you can merge directly into 9111-proto-messages without my approval.

@0xpatrickdev please don't. I'd like to land that branch, #9112, today. It's green and just needs approval.

Planning to go to master. Based against 9111-proto-messages as this PR is dependent on it.


/**
* @param {string} versionString version string
* @param {{ address: string; }} [params]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

params is optional but what's the point of calling this without it?

*/

/**
* @param {string} versionString version string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please convey that this string itself must be in JSON

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an arbitrary string. ICA happens to use a JSON format, but IBC transfer uses a non-JSON string of just seven bytes: ics20-1.

I'm increasingly hesitant to impose more structure than the IBC spec describes (more than just ICA or the "IBC transfer" protocol). There's a sweet spot to be found between making APIs with useful guard rails versus types that are flexible enough to express legitimate uses of IBC we haven't yet imagined.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

impose more structure than the IBC spec describes

💯 we should stick to the spec. Are there types for the spec that we could import? If not, I propose we have a separate file with just the types from the spec that code implementing parts of it imports.

But for parts of the code that do not support the full spec, shouldn't we document what they are expecting?

*/
msgDelegateResponse: (obj, sequence = 1) => {
return {
// {"result":"+/cosmos.staking.v1beta1.MsgDelegateResponse"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this comment meant to convey?

Copy link
Member Author

@0xpatrickdev 0xpatrickdev Apr 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These code comments are the decoded acknowledgement packets. I refactored mocks.js and support.ts per your feedback, lmk if this reads better:

https://github.com/Agoric/agoric-sdk/pull/9195/files#diff-6c46d78f5e5132e1c8596f11536961851d788b0ea13d1d60b47f87faf3a6e436R29-R53

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep!

*/
acknowledgementPacketFailure: (obj, sequence = 1) => {
return {
// {"error":"ABCI code: 5: error handling packet: see events for details"} (ErrPacketTimeout?)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto, why the commented out code?

@@ -367,6 +368,50 @@ export const makeSwingsetTestKit = async (
icaMocks.startChannelOpenInit.channelOpenAck(obj),
);
return undefined;
case 'sendPacket':
switch (obj.packet.data) {
case 'eyJ0eXBlIjoxLCJkYXRhIjoiQ2xVS0l5OWpiM050YjNNdWMzUmhhMmx1Wnk1Mk1XSmxkR0V4TGsxelowUmxiR1ZuWVhSbEVpNEtDMk52YzIxdmN6RjBaWE4wRWhKamIzTnRiM04yWVd4dmNHVnlNWFJsYzNRYUN3b0ZkV0YwYjIwU0FqRXciLCJtZW1vIjoiIn0=':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is pretty specific to particular tests. please make these exported constants so it's easy to see where they're used

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packages/orchestration/src/orchestration.js Outdated Show resolved Hide resolved
packages/orchestration/src/orchestration.js Outdated Show resolved Hide resolved
export type DestinationPort = 'icahost' | 'icqhost';
export type SourcePortPrefix = 'icacontroller' | 'icqcontroller';
export type SourcePort = `${SourcePortPrefix}-${number}`;
// TODO improve. sometimes expressed uppercase, others lowercase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, I don't get it

Copy link
Member Author

@0xpatrickdev 0xpatrickdev Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this type (ChannelOrdering) in favor of the now exported @typedef {'ORDERED' | 'UNORDERED'} IBCChannelOrdering from @agoric/vats. It seems like the lowercase variant is used when creating an address string, and the uppercase variant in packets. There is no type checking against address strings in this PR, but we could maybe add something like type AddressChannelOrdering = Lowercase<IBCChannelOrdering> if we wanted to do that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the lowercase variant is used when creating an address string, and the uppercase variant in packets.

Agreed, but I don't understand why

@0xpatrickdev 0xpatrickdev force-pushed the 8881-ica-send-message branch from 03f697f to a1dc02a Compare April 6, 2024 00:35
@turadg turadg force-pushed the 9111-proto-messages branch 3 times, most recently from 6482df5 to 722015f Compare April 8, 2024 14:29
Base automatically changed from 9111-proto-messages to master April 8, 2024 16:10
@0xpatrickdev 0xpatrickdev force-pushed the 8881-ica-send-message branch 2 times, most recently from c421d1b to 3ae138b Compare April 8, 2024 19:57
packages/boot/test/bootstrapTests/test-orchestration.ts Outdated Show resolved Hide resolved
packages/boot/test/bootstrapTests/test-orchestration.ts Outdated Show resolved Hide resolved
return E.when(
E(connection).send(makeTxPacket(msgs, opts)),
// if parsePacketAck cannot find a `result` key, it throws
ack => parsePacketAck(ack),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that that throw will not be caught by the catch below

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. This was intended to capture a failure on the initial send. Since we are doing extra handling, I've removed the catch

const port = await E(network)
.bind(`/ibc-port/icacontroller-${this.state.icaControllerNonce}`)
.catch(e => Fail`Failed to bind port: ${e}`);
const port = await E(network).bind(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of scope but it strikes me that .bind( is 99% of the time the JS function bind to this.

@iomekam WDYT of a name that's less likely to be confused?

Copy link
Member Author

@0xpatrickdev 0xpatrickdev Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe bindPort?

I can see how E(port).bindPort() might sound odd, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant > confusing ;-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bindPort is a perfect name. It's not E(port).bindPort(), it's E(network).bindPort().

packages/orchestration/src/orchestration.js Outdated Show resolved Hide resolved
packages/orchestration/src/proposals/start-stakeAtom.js Outdated Show resolved Hide resolved
packages/vats/src/ibc.js Outdated Show resolved Hide resolved
@turadg turadg mentioned this pull request Apr 8, 2024
packages/boot/tools/ibc/mocks.js Show resolved Hide resolved
@@ -51,17 +49,17 @@ const getPower = (powers, name) => {
return /** @type {OrchestrationPowers[K]} */ (powers.get(name));
};

export const Proto3Shape = {
typeUrl: M.string(),
value: M.string(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think we should have a different key for when value is bytes vs base64 string. e.g. valueB64. not a blocker

@@ -106,4 +106,139 @@ export type BridgeManager = {
) => ScopedBridgeManager;
};

export type * from './ibc.js';
export type IBCPortID = string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you move these from ibc.js? I suppose to get .ts syntax. I expect there's a better place for these but I can't think of a good suggestion atm

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes for TS syntax, plus this ballooned to quite a few lines at the top of the file.

I attempted ibc.d.ts in the same directory but this caused issues with things looking for exports from ibc.js. I also did not observe a pattern of multiple .d.ts files in a single package in the repo

@0xpatrickdev 0xpatrickdev force-pushed the 8881-ica-send-message branch from 330fe8c to 38c7bc3 Compare April 9, 2024 17:35
@0xpatrickdev 0xpatrickdev force-pushed the 8881-ica-send-message branch from 38c7bc3 to 54d830f Compare April 9, 2024 17:50
@0xpatrickdev 0xpatrickdev requested a review from turadg April 9, 2024 17:54
Copy link
Member

@turadg turadg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';
import { addParamsIfJsonVersion } from '../../../tools/ibc/mocks.js';

test('addParamsToVersion', t => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: addParamsIfJsonVersion, not worth CI

];

for (const { version, expected, message } of scenarios) {
t.is(addParamsIfJsonVersion(version, params), expected, message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the future consider an Ava macro for multiple test cases

@0xpatrickdev 0xpatrickdev added the automerge:rebase Automatically rebase updates, then merge label Apr 9, 2024
@mergify mergify bot merged commit e468caa into master Apr 9, 2024
74 checks passed
@mergify mergify bot deleted the 8881-ica-send-message branch April 9, 2024 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vat-orchestration - create ICAs - allow send message
3 participants