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

new client-utils package #10407

Merged
merged 19 commits into from
Nov 6, 2024
Merged

new client-utils package #10407

merged 19 commits into from
Nov 6, 2024

Conversation

turadg
Copy link
Member

@turadg turadg commented Nov 6, 2024

closes: #10168

Description

Provide a new package, client-utils, as a home for utilities that are useful to clients of an Agoric chain. This doesn't currently use @agoric/rpc but over time some of it may be pushed down into that package.

Related work…

This will solve most of what we need for functional testing. Some aspects are specific to the A3P synthetic chain (like account addresses and references to history) but most of what the tests are doing with the chain are operations that any client might do.

This will contribute to those goals.

Security Considerations

Reduces authority needed to query chain (from child_process to fetch)

Scaling Considerations

This is a big package, but it's not to be run on chain. Most client apps use some form of code shaking so they'll only take what they need.

Documentation Considerations

Once this settles down it ought to be a part of docs.agoric.com

Testing Considerations

The only test yet is a live one to make sure a query to Emerynet for Swingset params succeeds as expected, even under SES.

No package CI yet. Mostly it's refactoring of existing code so those uses serve as coverage. I do think this would benefit from some additional testing.

Upgrade Considerations

Will never be on chain

@turadg turadg requested a review from a team as a code owner November 6, 2024 00:18
@@ -2,11 +2,11 @@
/* eslint-env node */
import '@endo/init';
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you tried @endo/init/legacy.js? I'd expect axios to work with that, because @agoric/rpc itself already uses axios. It would still be great to get your patch into axios itself

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you! That will help so much with #9200.

Copy link
Contributor

@samsiegart samsiegart left a comment

Choose a reason for hiding this comment

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

LGTM for now. I am curious to know if we can make this in typescript, but I think most of this code so far is taken from existing js files so I'm not going to request it be rewritten.

@turadg
Copy link
Member Author

turadg commented Nov 6, 2024

I am curious to know if we can make this in typescript

It would require a build step. #9200 will require a build step for the codegen so it wouldn't be a huge change after that.

Copy link

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

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: c3f5438
Status: ✅  Deploy successful!
Preview URL: https://a74c0988.agoric-sdk.pages.dev
Branch Preview URL: https://10168-client-utils.agoric-sdk.pages.dev

View logs

@turadg turadg added automerge:rebase Automatically rebase updates, then merge and removed automerge:rebase Automatically rebase updates, then merge labels Nov 6, 2024
Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

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

Thanks for getting this moving.

After a bit of thinking-out-loud (mostly marked suggestion), I tried to focus my review on the package boundaries. A number of requests regard dependencies such as governance and inter-protocol that, as far as I can see, aren't used.

My most substantive request is probably around doing I/O at module-load-time for networkConfig.

packages/client-utils/src/wallet-utils.js Outdated Show resolved Hide resolved
packages/client-utils/src/wallet-utils.js Show resolved Hide resolved
* @returns {Promise<StargateClient>}
*/
export const makeStargateClient = config =>
StargateClient.connect(pickEndpoint(config));
Copy link
Member

Choose a reason for hiding this comment

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

Is it important to export makeStargateClient?

StargateClient.connect uses ambient access to the nest unless you pass in an endpoint object instead of a string.
(In particular, it uses axios, which seems a little silly now that fetch is mature.)

suggestion: Perhaps apply the pattern from #10038 ? I suppose we can do that later.

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 necessary for the pollBlocks feature of WalletUtils. Passing an Endpoint object doesn't help because that's just {url, headers}.

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 think I've got it working with something from casting (so I added that dep back)

"@agoric/casting": "^0.4.2",
"@agoric/cosmic-proto": "*",
"@agoric/ertp": "^0.16.2",
"@agoric/governance": "^0.10.3",
Copy link
Member

Choose a reason for hiding this comment

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

I don't see any occurrences of governance in this new package.

request:

Suggested change
"@agoric/governance": "^0.10.3",

Copy link
Member Author

Choose a reason for hiding this comment

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

very soon

"@agoric/cosmic-proto": "*",
"@agoric/ertp": "^0.16.2",
"@agoric/governance": "^0.10.3",
"@agoric/inter-protocol": "^0.16.1",
Copy link
Member

Choose a reason for hiding this comment

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

nor inter-protocol.

request:

Suggested change
"@agoric/inter-protocol": "^0.16.1",

Copy link
Member Author

Choose a reason for hiding this comment

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

very soon

'offerStatusTuples',
'pickEndpoint',
'purseBalanceTuples',
'rpcUrl',
Copy link
Member

Choose a reason for hiding this comment

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

What rpcUrl does is reasonable, but the name suggests something more general purpose and there's no docstring.

suggestion: Rename it to include agoricNet or the like? Add a docstring?

- GUI (such as dapps)
- Tests (such as a3p-integration tests)

As such the modules cannot assume they're running in Node. There are some ambient authorities in common in the above environments (e.g. `setTimeout`) but a further constraint is that these modules will not export ambient authority. Instead they will provide interfaces that are ergonomic for creating empowered objects in the client context.
Copy link
Member

Choose a reason for hiding this comment

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

👏 good to set this direction, even though we're not quite there yet.

@@ -48,6 +48,9 @@ export const getNetworkConfig = async env => {
});
};

// TODO distribute load
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: Make this comment part of the API docs?

Suggested change
// TODO distribute load
/**
* TODO distribute load
*/

consider @deprecated too.

Copy link
Member Author

Choose a reason for hiding this comment

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

why? it's to be used to pick an endpoint from a config

Copy link
Member

Choose a reason for hiding this comment

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

why: because without documentation, the caller would reasonably expect it to make use of >1 endpoint

import * as index from '@agoric/client-utils';

test('index', t => {
t.snapshot(Object.keys(index).sort());
Copy link
Member

Choose a reason for hiding this comment

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

👏 This is very handy.

@@ -1,3 +1,4 @@
/* eslint-env node */
Copy link
Member

Choose a reason for hiding this comment

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

suggestion to follow convention:

Suggested change
/* eslint-env node */
#!/usr/bin/env node
/* eslint-env node */

@turadg turadg requested a review from dckc November 6, 2024 19:00
Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

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

Looks good.

I can live with not resolving our differences on dependency management.

@turadg turadg force-pushed the 10168-client-utils branch from 6855062 to c3f5438 Compare November 6, 2024 20:15
@turadg turadg added the automerge:rebase Automatically rebase updates, then merge label Nov 6, 2024
@mergify mergify bot merged commit d4f2864 into master Nov 6, 2024
91 checks passed
@mergify mergify bot deleted the 10168-client-utils branch November 6, 2024 20:52
@turadg turadg mentioned this pull request Nov 9, 2024
mergify bot added a commit that referenced this pull request Nov 9, 2024
incidental

## Description
A couple days ago #10407 merged a new package, `@agoric/client-utils`. It wasn't marked private, but it didn't have `publishConfig` so the job that publishes to NPM was failing,
```
E402 You must sign up for private packages
```

This adds the necessary `publishConfig`. It also includes a couple other pending cleanups.

### Security Considerations
Publishing another package. It's under the `@agoric` org so it can't be squatted.

### Scaling Considerations
n/a

### Documentation Considerations
n/a

### Testing Considerations
We might want to have caught this problem in the PR but I don't think it's worth the effort. It was caught soon enough.

### Upgrade Considerations
n/a
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

publish a JS library that provides many of the functions of agoric-cli
3 participants