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(fast-usdc): settler disburses or forwards funds #10530

Merged
merged 7 commits into from
Nov 25, 2024
Merged

Conversation

dckc
Copy link
Member

@dckc dckc commented Nov 20, 2024

closes: #10391

Description

  • feat(fast-usdc): settler disburses or forwards funds

Discussion of what to do if the minted USDC shows up at each state led to some refinement of states.
So the scope of this PR expanded somewhat:

  • chore(fast-usdc): status manager: split out Advancing state
  • chore(fast-usdc): advancer: split ADVANCING state

Security Considerations

In addition to the normal case where funds are repaid to the pool and fees are distributed, the settler is responsible to forward funds in case they were not advanced.

Scaling Considerations

nothing novel

Documentation Considerations

Readers are assumed to be familiar with design docs.

Testing Considerations

Getting the tests to pass requires:

It's included in this PR for now but is expected to land separately

DRAFT until

  • test "Settlement for unknown transaction" case

Upgrade Considerations

This is a new component.

Copy link

cloudflare-workers-and-pages bot commented Nov 20, 2024

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: d67cd22
Status: ✅  Deploy successful!
Preview URL: https://12e7d7e6.agoric-sdk.pages.dev
Branch Preview URL: https://10391-settler-exo.agoric-sdk.pages.dev

View logs

@dckc dckc force-pushed the 10391-settler-exo branch 3 times, most recently from 9e90738 to 09171cb Compare November 21, 2024 21:53
@0xpatrickdev
Copy link
Member

0xpatrickdev commented Nov 22, 2024

Please see #10550 for advancer integration and status manager tests. It should be green minus the debugger; statements and unreachable code in monitorMintingDeposits. We might want to tackle monitorTransfers in a separate PR.

Edit: ea6b768 seems to be a temporary fix

@dckc dckc force-pushed the 10391-settler-exo branch from 9e5c099 to ab020c2 Compare November 22, 2024 17:13
@mergify mergify bot mentioned this pull request Nov 22, 2024
@dckc dckc force-pushed the 10391-settler-exo branch 3 times, most recently from 50f3674 to 2dc941f Compare November 22, 2024 20:53
@dckc dckc changed the title 10391 settler exo feat(fast-usdc): settler disburses or forwards funds Nov 22, 2024
@dckc dckc requested review from turadg and 0xpatrickdev November 22, 2024 20:54
@dckc dckc marked this pull request as ready for review November 22, 2024 21:00
@dckc dckc requested a review from a team as a code owner November 22, 2024 21:00
}
disbursed(txHash, address, amount) {
// TODO: store txHash -> evidence for txs pending settlement?
console.log('TODO: vstorage update', { txHash, address, amount });
Copy link
Member

Choose a reason for hiding this comment

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

can wait for another PR but should at least have a TODO in this one…

define the states and valid transitions in constants, and when transitioning state verify that it's a valid transition. like in

/**
* @typedef {Exclude<Phase, 'transfer'>} VaultPhase
* @type {{ [K in VaultPhase]: VaultPhase[] }}
*/
const validTransitions = {
[Phase.ACTIVE]: [Phase.LIQUIDATING, Phase.CLOSED],
[Phase.LIQUIDATING]: [Phase.LIQUIDATED, Phase.ACTIVE],
[Phase.LIQUIDATED]: [Phase.CLOSED],
[Phase.CLOSED]: [],
};

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm adding a TODO in constants.js, but in this disbursed(...) case, the previous state has been dequeued, so this exo no longer has it. In fact, I'm struggling to find anywhere that such a check would be relevant.

Copy link
Member

Choose a reason for hiding this comment

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

gotcha, maybe it doesn't make sense here with this virtual entity

recordPendingTx(evidence, PendingTxStatus.Advancing);
},

/**
Copy link
Member

Choose a reason for hiding this comment

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

please some more docs on when this is to be called

@@ -109,8 +132,34 @@ export const prepareStatusManager = zone => {
* Add a new transaction with ADVANCED status
* @param {CctpTxEvidence} evidence
*/
advance(evidence) {
recordPendingTx(evidence, PendingTxStatus.Advanced);
advancing(evidence) {
Copy link
Member

Choose a reason for hiding this comment

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

I think advance was correct. That's the transition event that will change the state to Advancing.

Consider having a naming scheme for all transition events. "send" is common in state FSMs. So here could be sendAdvance

Copy link
Member Author

Choose a reason for hiding this comment

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

restored advance

just added a TODO re naming scheme

* @param {boolean} success
* @throws {Error} if nothing to advance
*/
advanceOutcome(sender, amount, success) {
Copy link
Member

Choose a reason for hiding this comment

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

it makes sense that this takes a boolean but for the calling code consider having a more explicit sendAdvanceSuccess and sendAdvanceFailure (which could call this)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm struggling with this "sendX" phrasing. We're telling the status manager to send something?

Copy link
Member

Choose a reason for hiding this comment

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

How about settleX? To signify the transfer vow settlement.

I don't mind the Boolean. Another option is a Fulfilled | Rejected const that would be more explicit at the call site.

Also keep in mind we'll soon need settleForward (in addition to settleAdvance or whatever is decided here)

Copy link
Member

Choose a reason for hiding this comment

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

"send" phrasing is from the metaphor of sending a message to the state machine. It's in a bunch of state machine libraries.

my comment was just a "consider" which is done.

* Find an `ADVANCED` or `OBSERVED` tx waiting to be `SETTLED`
* @param {CctpTxEvidence} evidence
*/
isSeen(evidence) {
Copy link
Member

Choose a reason for hiding this comment

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

is connotes a check on the current state but Seen isn't one of the states.

hasBeenObserved?

},

/**
* Lookup all pending entries for a given address and amount
*
* XXX only used in tests. should we remove?
Copy link
Member

Choose a reason for hiding this comment

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

yes. tests need only cover what can be called in production.

Copy link
Member

Choose a reason for hiding this comment

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

I wrote this comment - some tests would need to be reworked if we were to remove this. They use this method to confirm state transitions.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if they need to do so explicitly. Kind of testing the implementation.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe a better approach is to define the stores as optional initState arguments so we can access the contents in tests.

Copy link
Member

@turadg turadg Nov 23, 2024

Choose a reason for hiding this comment

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

cleaner wrt the API surface but that's even moreso testing the implementation

Copy link
Member

@0xpatrickdev 0xpatrickdev left a comment

Choose a reason for hiding this comment

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

Nice job. My review is partial since we paired and tag teamed much of this. I think it's good to land but noted some additional requirements that could be part of #10391 or a follow up ticket.

/** fallback: do not collect fees */
Forwarded: 'FORWARDED',
/** failed to forward to EUD */
ForwardFailed: 'FORWARD_FAILED',
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
ForwardFailed: 'FORWARD_FAILED',
ForwardFailed: 'FORWARD_FAILED',
/** started IBC transfer for fallback path */
Forwarding: 'FORWARDING',

dest,
AmountMath.make(USDC, amount),
);
await vowTools.when(txfrV); // TODO: watch, handle failure
Copy link
Member

Choose a reason for hiding this comment

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

This PR tackles a lot so I won't push to include here - but please create a follow up ticket or update this to refs that captures work needed for Forwarding and ForwardFailed states.

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't in general have issues for all TODOs, do we? Is this one special?

}

const { status, txHash } = pending[dequeueIdx];
// TODO: store txHash -> evidence for txs pending settlement?
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
// TODO: store txHash -> evidence for txs pending settlement?
// TODO: store txHash -> evidence for txs pending settlement?
// If necessary for vstorage writes in `forwarded` and `settled`

* @param {NobleAddress} address
* @param {bigint} amount
* @returns {PendingTx[]}
*/
lookupPending(address, amount) {
const key = makePendingTxKey(address, amount);
if (!pendingTxs.has(key)) {
throw makeError(`Key ${q(key)} not yet observed`);
return [];
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
return [];
return harden([]);

Comment on lines 111 to 119
// TODO #10390 log all early returns
// only interested in packets from the issuing chain
return;
Copy link
Member

Choose a reason for hiding this comment

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

Before closing #10390, please log all early returns. This was a previous request: https://github.com/Agoric/agoric-sdk/pull/10406/files#r1831815520

@0xpatrickdev 0xpatrickdev requested review from 0xpatrickdev and removed request for 0xpatrickdev November 22, 2024 21:42
const pending = pendingTxs.get(key);
return !!pending.length;
if (!pending.length) return undefined;
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
if (!pending.length) return undefined;

We might be able to remove this - it seems unreachable with the pendingTxs.delete logic in dequeueStatus. (Also the only line popping up on test:c8)

Copy link
Member Author

Choose a reason for hiding this comment

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

it's also taken care of by the dequeueIdx < 0 check after find. it's at best an optimization.

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.

LGTM.

@dckc dckc force-pushed the 10391-settler-exo branch from cb93488 to e4bf666 Compare November 23, 2024 00:23
@dckc dckc added the automerge:rebase Automatically rebase updates, then merge label Nov 23, 2024
@dckc dckc force-pushed the 10391-settler-exo branch from e4bf666 to 0ab9e37 Compare November 23, 2024 00:43
@dckc
Copy link
Member Author

dckc commented Nov 25, 2024

I'm struggling with this ci mystery:

 Error {
    message: 'tryExitOffer failed to reclaim stuck payment  condition failed after 15 retries.',

I re-ran it; it still failed.

@turadg turadg added this to the FU1: package integration milestone Nov 25, 2024
@dckc dckc removed the automerge:rebase Automatically rebase updates, then merge label Nov 25, 2024
@Jorge-Lopes
Copy link
Collaborator

Jorge-Lopes commented Nov 25, 2024

 Error {
    message: 'tryExitOffer failed to reclaim stuck payment  condition failed after 15 retries.',

It’s strange—I can see in the logs the message:
wallet agoric1ee9hr0jyrxhy999y755mp862ljgycmwyp4pl7q reclaimed [ { brand: Object [Alleged: IST brand] {}, value: 15_000n } ] from bad-invitation-15,
which indicates that the stuck payment was reclaimed and the wallet’s IST balance should have increased and satisfied the expected condition.

However, since the istBalanceBefore value isn’t being logged, we cannot properly verify this.
Here’s the link to the relevant logs:
GitHub Action Logs.

What I don’t understand is why this test doesn’t fail when running the a3p-integration acceptance tests locally or in other PRs (for example here, where the acceptance wallet test is passing), but it’s failing here—even though I don’t see any changes being introduced that to a3p-integration proposals.

Am I failing to notice any change being introduced in this PR that may conflict with the any a3p-integration acceptance test?

@dckc
Copy link
Member Author

dckc commented Nov 25, 2024

Am I failing to notice any change being introduced in this PR that may conflict with the any a3p-integration acceptance test?

I can't imagine any. All the changes are in the fast-usdc package, which isn't even deployed in the z:acceptance context.
With 1 exception: a tweak in orchestration. I can't imagine it's causing problems, but I don't suppose I can say for certain that it's not.

@dckc
Copy link
Member Author

dckc commented Nov 25, 2024

I see some earlier symptoms, at 4370:

    Error: error in json rpc client, with http response metadata: (Status: 200 OK, Protocol HTTP/1.1). RPC error -32603 - Internal error: timed out waiting for tx to be included in a block

@dckc dckc force-pushed the 10391-settler-exo branch from 0ab9e37 to d67cd22 Compare November 25, 2024 19:54
@dckc
Copy link
Member Author

dckc commented Nov 25, 2024

rebased now that #10553 has landed

@dckc dckc added the automerge:rebase Automatically rebase updates, then merge label Nov 25, 2024
@turadg turadg added the bypass:integration Prevent integration tests from running on PR label Nov 25, 2024
@turadg
Copy link
Member

turadg commented Nov 25, 2024

I'm bypassing integration because this is passing every integration test but this flake,

@mergify mergify bot merged commit aa11d5c into master Nov 25, 2024
99 of 101 checks passed
@mergify mergify bot deleted the 10391-settler-exo branch November 25, 2024 21:44
mergify bot added a commit that referenced this pull request Nov 26, 2024
refs: #10565

## Description

#10530 was failing repeatedly due to this test problem,
- #10565

I thought it was a flake so I [bypassed the check](#10530 (comment)) but it turns out to fail deterministically due to the changes in #10530. But those changes should have not affected the test, so the problem is with the test.

This marks it as failing until it can be solved.

### Security Considerations
none

### Scaling Considerations
none

### Documentation Considerations
none

### Testing Considerations
I used `failing` instead of `skip` to help confirm that it's deterministic. Also if something happens to resolve it inadvertently it'll be detected so we re-enable it.

### Upgrade Considerations
none
mergify bot added a commit that referenced this pull request Dec 26, 2024
closes: #10565
refs: #10774

## Description

Test named `exitOffer tool reclaims stuck payment` was flakey and this prevented landing other PRs like #10530.

### Security Considerations

None.

### Scaling Considerations

None.

### Documentation Considerations

None.

### Testing Considerations

The flakey test was being skipped before. Now we included it back in and the CI should pass.

### Upgrade Considerations

This test concerns current and all future upgrades as the acceptance should pass before landing upgrades.
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 bypass:integration Prevent integration tests from running on PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Settler exo
4 participants