Skip to content

Commit

Permalink
fix: subscribeToTransfers atomically
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig authored and dckc committed Nov 25, 2024
1 parent 136b33d commit 7b77993
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions packages/orchestration/src/exos/packet-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {Vow<TargetRegistration> | null} */ (null),
resolverToPattern,
upcallQueue: /** @type {any[] | null} */ (null),
pending: 0,
Expand Down Expand Up @@ -331,17 +331,15 @@ export const preparePacketTools = (zone, vowTools) => {
},
subscribeToTransfers() {
// Subscribe to the transfers for this account.
const { lca, reg } = this.state;
if (reg) {
return when(reg);
const { lca, reg: cachedReg } = this.state;
if (cachedReg) {
return when(cachedReg);
}
// Atomically update the registration.
const { tap } = this.facets;
// XXX racy; fails if subscribeToTransfers is called while this promise is in flight
// e.g. 'Target "agoric1fakeLCAAddress" already registered'
return when(E(lca).monitorTransfers(tap), r => {
this.state.reg = r;
return r;
});
const reg = watch(E(lca).monitorTransfers(tap));
this.state.reg = reg;
return when(reg);
},
unsubscribeFromTransfers() {
const { reg, monitor } = this.state;
Expand Down

0 comments on commit 7b77993

Please sign in to comment.