Skip to content

Commit

Permalink
fixup! feat: close, reopen, and automatically reopen ICA channels
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed Aug 9, 2024
1 parent b51c746 commit 1063d9b
Show file tree
Hide file tree
Showing 2 changed files with 188 additions and 202 deletions.
22 changes: 16 additions & 6 deletions packages/orchestration/src/exos/ica-account-kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { NonNullish, makeTracer } from '@agoric/internal';
import { VowShape } from '@agoric/vow';
import { CLOSE_REASON_FINALIZER } from '@agoric/network';
import {
ChainAddressShape,
OutboundConnectionHandlerI,
Expand Down Expand Up @@ -187,12 +188,16 @@ export const prepareIcaAccountKit = (zone, { watch, asVow }) =>
});
},
/**
* This handler fires if the connection is closed due to external
* factors (e.g. a packet timeout). It will not fire if a holder calls
* `.close()`.
* This handler fires any time the connection closes. This could be due
* to external factors (e.g. a packet timeout), or a holder initated
* action (`.close()`).
*
* Here, we clear the connection and addresses from state as we expect
* them to change and call reopen() to re-establish the connection.
* Here, we clear the connection and addresses from state as they will
* change - a new chanel will be established if the connection is
* reopened.
*
* If the close reason is not {@link CLOSE_REASON_FINALIZER}, we
* automatically reopen the connection.
*
* @param {Remote<Connection>} _connection
* @param {unknown} reason
Expand All @@ -203,7 +208,12 @@ export const prepareIcaAccountKit = (zone, { watch, asVow }) =>
this.state.connection = undefined;
this.state.localAddress = undefined;
this.state.remoteAddress = undefined;
void watch(this.facets.account.reopen());
if (reason !== CLOSE_REASON_FINALIZER) {
trace('Automatically reopening the connection.');
void watch(this.facets.account.reopen());
} else {
trace('Channel closed by the user action. Not reopening.');
}
},
},
},
Expand Down
Loading

0 comments on commit 1063d9b

Please sign in to comment.