-
Notifications
You must be signed in to change notification settings - Fork 208
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
fix(orchestration): subscribeToTransfers() atomically #10553
Conversation
These are two tests we have that cover this path (via
I assume they don't have the same symptoms we are currently facing due to these async calls in between agoric-sdk/packages/orchestration/src/examples/auto-stake-it.flows.js Lines 45 to 78 in 0105e1a
But their passing should help towards giving us confidence this change does not introduce a regression. |
Deploying agoric-sdk with Cloudflare Pages
|
9d52108
to
29fad09
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know all the possible ramifications of this change so I don't feel qualified to Approve. I think we need @iomekam or @michaelfig who I think made packet-tools.
Guilty as charged! (Thanks for the ping, I'm taking a look now.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend a different tactic that can robustly avoid the race. Let me know what you think.
@@ -340,6 +340,7 @@ export const preparePacketTools = (zone, vowTools) => { | |||
const { tap } = this.facets; | |||
// XXX racy; fails if subscribeToTransfers is called while this promise is in flight | |||
// e.g. 'Target "agoric1fakeLCAAddress" already registered' | |||
this.state.reg = 'RACING'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's how I would solve the race: check for the cached registration, and if it's not present, atomically replace it with a vow.
subscribeToTransfers() {
// Subscribe to the transfers for this account.
const { lca, reg: cachedReg } = this.state;
if (cachedReg) {
return when(cachedReg);
}
// Atomically update the registration.
const { tap } = this.facets;
const reg = watch(E(lca).monitorTransfers(tap));
this.state.reg = reg;
return when(reg);
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, and the FIXME comment on line 330-331 is no longer needed:
// FIXME when it returns undefined this causes an error:
// In "unsubscribeFromTransfers" method of (PacketToolsKit utils): result: undefined "[undefined]" - Must be a promise
It was solved 3 months ago by @0xpatrickdev changing decrPendingPatterns
's method guard to use .returns(M.undefined())
.
@@ -126,7 +126,7 @@ export const preparePacketTools = (zone, vowTools) => { | |||
const resolverToPattern = zone.detached().mapStore('resolverToPattern'); | |||
return { | |||
lca, | |||
reg: /** @type {Remote<TargetRegistration> | null} */ (null), | |||
reg: /** @type {Remote<TargetRegistration> | 'RACING' | null} */ (null), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reg: /** @type {Remote<TargetRegistration> | 'RACING' | null} */ (null), | |
reg: /** @type {Vow<Remote<TargetRegistration>> | null} */ (null), |
29fad09
to
96830ca
Compare
96830ca
to
7b77993
Compare
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: - [ ] #10553 It's included in this PR for now but is expected to land separately DRAFT until - [x] test "Settlement for unknown transaction" case ### Upgrade Considerations This is a new component.
refs: #10391
Description
There was a race in subscribeToTransfers. Use a
Vow
to avoid the race.Security / Scaling / Upgrade / Documentation Considerations
can't think of any
Testing Considerations
I'm not sure how to make a test for this. The purpose of this fix is mostly to stop other tests from failing.