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: implement .transfer on CosmosOrchestrationAccount #9882

Merged
merged 14 commits into from
Aug 16, 2024

Conversation

0xpatrickdev
Copy link
Member

refs: #9193
refs: #9784

Description

These changes primarily implement the .transfer method on CosmosOrchestrationAccount. The changes require providing the exo with a ChainHub for looking up transferChannel info and TimerService for building a default timeout parameter. Notably, the .transfer() Promise resolves when the host chain submits the transfer to other remote chain. The sendThenWaitForAck logic that LocalOrchestrationAccount has is not yet implemented but tracked via #9784.

Other changes include:

  • simplified transferChannel lookup logic in LocalOrchestrationAccount
  • /boot/tools/support.ts changes to simplify sendPacket ack mocks for dibc bridge
  • bootstrap tests for LocalOrchAccount.transfer() using Transfer invitationMaker
  • /boot/tools/support.ts changes to ensure mock localChain addresses are unique
  • packetUtils interface guard change for an observed, but seemingly benign, error

Security Considerations

n/a

Scaling Considerations

n/a

Documentation Considerations

  • how to best document the differences between LOA and COA for the interim?

Testing Considerations

Includes unit and boot tests.

Upgrade Considerations

n/a, unreleased code

@@ -1,4 +1,5 @@
// @ts-check
import { createMockAckMap } from '@agoric/orchestration/tools/ibc-mocks.ts';
Copy link
Member Author

Choose a reason for hiding this comment

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

.ts doesn't seem right here. Is the correct way to address this a build step in the orchestration package.json?

Copy link
Member

Choose a reason for hiding this comment

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

Just change it to .js. TS will resolve the module.

Suggested change
import { createMockAckMap } from '@agoric/orchestration/tools/ibc-mocks.ts';
import { createMockAckMap } from '@agoric/orchestration/tools/ibc-mocks.js';

I don't recall why boot has allowImportingTsExtensions: true. I'll see about disabling it to avoid this problem.

a build step in the orchestration package.json?

Aside from cosmic-proto which uses code gen, we avoid build steps for dependencies between packages in the repo. @agoric/orchestration does transpile in its NPM publishing.

Copy link
Member Author

Choose a reason for hiding this comment

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

After rebasing on #9884 and changing to .js I see 🤔 :

$ ava test/orchestration/restart-contracts.test.ts

  Uncaught exception in test/orchestration/restart-contracts.test.ts

  Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/0xpatrick/repos/agoric-sdk/node_modules/@agoric/orchestration/tools/ibc-mocks.js' imported from /Users/0xpatrick/repos/agoric-sdk/packages/boot/tools/ibc/mocks.js

  › h (file:///Users/0xpatrick/repos/agoric-sdk/node_modules/@esbuild-kit/esm-loader/dist/index.js:12:1164)

Copy link
Member

Choose a reason for hiding this comment

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

pushed a fix in c4d45bf

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. Still seeing https://github.com/Agoric/agoric-sdk/actions/runs/10419531180/job/28857889091?pr=9882#step:5:115. The problem goes away if we rename mocks.js and mocks.test.js to .ts, but I'll hold that fixup as I suspect a different solution might be preferred.

Copy link
Member

Choose a reason for hiding this comment

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

shoot, I tested locally but missed that one I guess.

more .ts seems like the best solution to me

Copy link
Member

Choose a reason for hiding this comment

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

this branch is behind master now. when you make that change feel free to rebase on master and force push with fixups squashed

}
// An error that would be triggered before reception on another chain
return ackImmediately(obj, protoMsgMocks.error.ack);
Copy link
Member Author

Choose a reason for hiding this comment

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

// An error that would be triggered before reception on another chain

Thinking on this more, I suspect the relayer could also be delayed. Any harm in making this ackLater?

Copy link
Member

@turadg turadg Aug 13, 2024

Choose a reason for hiding this comment

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

Seems like a trade-off. IIRC:

  1. a sendPacket message could have an immediate failure before leaving the local node (i.e. just over the bridge) or after a reply from a relayer.
  2. we can't reliably distinguish between those cases here

If (2) is false, then let's distinguish.

If (2) is true then we have to pick the better way to handle both. The pro of ackLater is that it let's us test doing other work before the ack arrives. The con is that it's something someone could forget in a test, and even when they don't it's more work.

The other immediate con is that it may break some tests and need fixing.

I don't have a strong stance on which is better. Whatever infidelity you choose, please leave a comment explaining the decision.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thinking on this more, I also don't have a strong stance. It seems the main benefit of ackLater is to allow us to control timing in the test context. ackImmediately seems like a sensible default, as someone can always choose to supply a mock to the bridge that will use ackLater.

Nonetheless, sharing some thoughts/findings to your question -

  1. a sendPacket message could have an immediate failure before leaving the local node (i.e. just over the bridge) or after a reply from a relayer.

Correct, the sendPacket handler can fail via ReceiveSendPacket before leaving agoric golang and going out to a relayer.

It seems this might only fail if an invalid sourcePort and sourceChannel are provided. I'm not sure when ibc.js or network.js would allow this since .downcall() is heavily guarded with ocaps + closures - the only thing coming to mind is bad state where a channel is closed but ibc/network are unaware.

@0xpatrickdev 0xpatrickdev force-pushed the pc/cosmos-orch-transfer branch from f8370b2 to 1ba74b7 Compare August 12, 2024 23:45
Copy link

cloudflare-workers-and-pages bot commented Aug 12, 2024

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: e3ce160
Status: ✅  Deploy successful!
Preview URL: https://394bd972.agoric-sdk.pages.dev
Branch Preview URL: https://pc-cosmos-orch-transfer.agoric-sdk.pages.dev

View logs

@0xpatrickdev 0xpatrickdev force-pushed the pc/cosmos-orch-transfer branch from 1ba74b7 to d5cb94b Compare August 12, 2024 23:46
@0xpatrickdev 0xpatrickdev requested a review from turadg August 13, 2024 00:29
@0xpatrickdev 0xpatrickdev marked this pull request as ready for review August 13, 2024 00:30
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.

Good stuff! Thanks for the clean commits for reviewing. Happy to see the code improvements along the way.

packages/orchestration/src/utils/time.js Show resolved Hide resolved
packages/orchestration/index.js Outdated Show resolved Hide resolved
? 0n
: E(timestampHelper).getTimeoutTimestampNS());

// Resolves when host chain successfully submits, but not when
Copy link
Member

Choose a reason for hiding this comment

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

the commit message made me think the feature was implemented. I see it just says it's adding the method, and I suppose there will be another feat commit that it works as expected.

makeRecorderKit,
vowTools,
zcf,
{ chainHub, makeRecorderKit, timerService, vowTools, zcf },
Copy link
Member

Choose a reason for hiding this comment

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

good refactor. I suppose this should be the habit from the outset. powers tend to expand

packages/orchestration/src/proposals/start-stakeAtom.js Outdated Show resolved Hide resolved
mergify bot added a commit that referenced this pull request Aug 14, 2024
_incidental_

## Description

A couple packages had `allowImportingTsExtensions: true`. It recently caused [some confusion](#9882 (comment)).

The reason we had it is so tests written in `.js` could import `.ts` modules. (Without this `.ts` import, the Ava transpiler config wouldn't try to resolve `.js` as a `.ts` module in a `.js` file.) But most of our tests in `boot` are `.ts` now and I think it would be best for them all to be.

This removes that allowance and brings the imports into conformity. It also converts the one test that was using `.ts` in `.js` to be a `.ts` test.

### Security Considerations
n/a

### Scaling Considerations
n/a

### Documentation Considerations
n/a

### Testing Considerations
CI

### Upgrade Considerations
n/a
@0xpatrickdev 0xpatrickdev force-pushed the pc/cosmos-orch-transfer branch from d5cb94b to b79a25d Compare August 15, 2024 22:35
@0xpatrickdev 0xpatrickdev force-pushed the pc/cosmos-orch-transfer branch from c4d45bf to e3ce160 Compare August 16, 2024 14:45
@0xpatrickdev 0xpatrickdev added the automerge:rebase Automatically rebase updates, then merge label Aug 16, 2024
@mergify mergify bot merged commit bef1be9 into master Aug 16, 2024
90 checks passed
@mergify mergify bot deleted the pc/cosmos-orch-transfer branch August 16, 2024 15:49
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.

2 participants