-
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
feat: ChainAccountKit returns vows #9562
Conversation
Deploying agoric-sdk with Cloudflare Pages
|
My only question is: are you concerned that in a non- If you're fine with that, I will review this PR having understood that you're doing it in order to accommodate linting rules. My only request before I do, is that you update it with master to make the actual changes clearer to me. Thanks! |
Per #9449 these methods must always return Vows, so must not throw. IIUC returning a rejected promise is no better. |
aea3535
to
f2fa2dc
Compare
@@ -188,15 +187,27 @@ export const prepareChainAccountKit = (zone, { watch, when }) => | |||
chainId: this.state.chainId, | |||
addressEncoding: 'bech32', | |||
}); | |||
return Promise.resolve(watch(undefined)); |
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.
Why return anything here?
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.
Consistent return type
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 relaxed the lint rule for connectionHandler > onOpen | onClose
children in 2863d1b. The connectionHandler
is only used internally by the exo, and won't/can't be called by a consumer of orchestrate
. Replying to network vat with an empty vow / promise also seems like a waste since it's not interested in our answer.
An alternative explored was adjusting the types:
diff --git a/packages/network/src/types.js b/packages/network/src/types.js
index d40be9ad1..e70033ace 100644
--- a/packages/network/src/types.js
+++ b/packages/network/src/types.js
@@ -101,7 +101,7 @@ export {};
* localAddr: Endpoint,
* remoteAddr: Endpoint,
* c: Remote<ConnectionHandler>,
- * ) => PromiseVow<void>} [onOpen]
+ * ) => PromiseVow<void> | void} [onOpen]
* The connection has been opened
* @property {(
* connection: Remote<Connection>,
@@ -114,7 +114,7 @@ export {};
* connection: Remote<Connection>,
* reason?: CloseReason,
* c?: Remote<ConnectionHandler>,
- * ) => PromiseVow<void>} [onClose]
+ * ) => PromiseVow<void | void>} [onClose]
* The connection has been closed
*
* @typedef {any | null} CloseReason The reason a connection was closed
trace(`ICA Channel onReceive`, connection, bytes); | ||
return ''; | ||
return Promise.resolve(watch('')); |
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.
Should we instead do this?
return Promise.resolve(watch('')); | |
return watch(Promise.resolve('')); |
Also, I'm not sure we need to return anything here - return ''
might be an artifact from satisfying this type guard:
agoric-sdk/packages/network/src/network.js
Line 1224 in 3027adf
.returns(Shape.Data), |
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.
There is no need for the onReceive
handler. I removed it in d6bd228
Please use the wrapper pattern recommended by @mhofman in #9454 (comment) |
f2fa2dc
to
2863d1b
Compare
@michaelfig I've commandeered 🏴☠️ Turadg's PR if you could PTAL. When we come to agreement on the approach for |
is that still true? or is it overtaken by |
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.
a few non-critical suggestions
.eslintrc.cjs
Outdated
selector: 'FunctionExpression[async=true]', | ||
selector: | ||
'FunctionExpression[async=true]:not(Property[key.name="connectionHandler"] > ObjectExpression > Property[key.name=/^(onOpen|onClose)$/] > FunctionExpression[async=true])', |
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 could sure use a comment to help read this.
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.
Added a comment in e7b839a
// TODO #9281 do not throw synchronously when returning a promise; return a rejected Vow | ||
/// see https://github.com/Agoric/agoric-sdk/pull/9454#discussion_r1626898694 |
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.
the addVow()
call means this TODO is done now, isn't it?
// TODO #9281 do not throw synchronously when returning a promise; return a rejected Vow | |
/// see https://github.com/Agoric/agoric-sdk/pull/9454#discussion_r1626898694 |
return asVow(() => { | ||
throw new Error('not yet implemented'); | ||
}); |
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.
orthogonal to this PR, but I think our preference is Error(...)
, not new Error(...)
return asVow(() => { | |
throw new Error('not yet implemented'); | |
}); | |
return asVow(() => { | |
throw Error('not yet implemented'); | |
}); |
I'm struggling to confirm from Coding Style though.
return asVow(() => { | ||
throw new Error('not yet implemented'); | ||
}); |
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.
or, for brevity:
return asVow(() => { | |
throw new Error('not yet implemented'); | |
}); | |
return asVow(() => assert.fail('not yet implemented')); |
const { connection } = this.state; | ||
// TODO #9281 do not throw synchronously when returning a promise; return a rejected Vow | ||
/// see https://github.com/Agoric/agoric-sdk/pull/9454#discussion_r1626898694 | ||
if (!connection) throw Fail`connection not available`; |
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'm partial to doing that on one line, but I'm pretty sure others prefer...
if (!connection) throw Fail`connection not available`; | |
if (!connection) { | |
throw Fail`connection not available`; | |
} |
I'm not sure why our lint tools don't require that. Maybe it's OK.
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.
if (!connection) throw Fail`connection not available`;
doesn't seem too different from:
connection || Fail`connection not available`;
from a readability standpoint.
The latter I understand to be a preferred pattern, but it unfortunately does not satisfy ts-check
.
I've implemented your other suggestions, thanks for the review!
Co-authored-by: 0xPatrick <[email protected]>
- ICA and ICQ channels only send outbound requests; they do not receive incoming requests they need to respond to - renames ConnectionHandlerI to OutboundConnectionHandlerI to better reflect the behavior
…ble rule - onOpen and onClose are event listeners that handle incoming notifications - these methods do not return values and are not expected to be resumable
error TS2741: Property 'account' is missing in type '{}' but required in type '{ account: OrchestrationAccount<any> | undefined; }'
e7b839a
to
9bc7afb
Compare
refs: #9449
Description
asVow
helperonOpen
andonClose
when they are properties ofconnectionHandler
onReceive
handler or connectionHandler forchainAccountKit
andicqConnectionKit
Security Considerations
none
Scaling Considerations
none
Documentation Considerations
none
Testing Considerations
CI for now
Upgrade Considerations
not yet deployed