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

register any chain info #9452

Merged
merged 8 commits into from
Jun 5, 2024
Merged

register any chain info #9452

merged 8 commits into from
Jun 5, 2024

Conversation

turadg
Copy link
Member

@turadg turadg commented Jun 4, 2024

refs: #9187

Description

Progress on #9187

Plus incidental improvements

Security Considerations

Scaling Considerations

Documentation Considerations

Testing Considerations

Upgrade Considerations

Copy link

cloudflare-workers-and-pages bot commented Jun 4, 2024

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6d597fd
Status: ✅  Deploy successful!
Preview URL: https://88827a70.agoric-sdk.pages.dev
Branch Preview URL: https://9187-any-chaininfo.agoric-sdk.pages.dev

View logs

@turadg turadg requested review from dckc and 0xpatrickdev June 4, 2024 22:14
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.

oops; I started reviewing without noticing the DRAFT status

@@ -0,0 +1,61 @@
/**
* @file static declaration of known chain types will allow type support for
Copy link
Member

Choose a reason for hiding this comment

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

I'd expect this as a test fixture, but not a source module.

This info will vary between a3p, devnet, mainnet, etc.

oh. weird. this is just a .ts->.js rename. it was already here.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, I figure it's all prototype code still. though the .ts was less risky to have in src because it would never show up in a bundle.

can we leave this here until #8879? I'll put a TODO

/**
* cf https://github.com/cosmos/chain-registry/blob/master/chain.schema.json#L117
*/
stakingTokens?: [{ denom: string }];
Copy link
Member

Choose a reason for hiding this comment

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

That syntax gave me a strange error about [X] vs. X[]. This made it go away:

Suggested change
stakingTokens?: [{ denom: string }];
stakingTokens?: Array<{ denom: string }>;

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 imagine that's your linter. That is a better type though, because what's here is a tuple rather than an array of arbitrary length. I'll change it.

*/

/** @type {any} */
const anyVal = null;

// FIXME should be configurable
// ??? could the localchain service offer this?
const mockLocalChainInfo = {
Copy link
Member

Choose a reason for hiding this comment

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

mockX looks like test code, not src code.

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 not test code either; it's an incomplete implementation. just like all the "'fixme'" strings we've had to date

Copy link
Member Author

@turadg turadg Jun 5, 2024

Choose a reason for hiding this comment

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

I've put issues at all the fixmes to be sure they'll be addressed

Comment on lines -47 to +51
deposit(payment) {
async deposit(payment) {
Copy link
Member

Choose a reason for hiding this comment

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

orthogonal to this PR: In asyncFlow discussion yesterday, somebody said the facade methods can't be async.

Comment on lines +94 to +96
* @template {CosmosChainInfo} CCI
* @param {CCI} chainInfo
Copy link
Member

Choose a reason for hiding this comment

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

funky.

Copy link
Member Author

Choose a reason for hiding this comment

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

request?

Copy link
Member

Choose a reason for hiding this comment

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

sorry; no... it just hand't occurred to me that a type could be parameterized by a whole structure, and not just a primitive value

const chainInfo = chainInfos.has(name)
? chainInfos.get(name)
: // @ts-expect-error may be undefined
wellKnownChainInfo[name];
Copy link
Member

Choose a reason for hiding this comment

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

well known chain should come from agoricNames, yes?

Copy link
Member Author

Choose a reason for hiding this comment

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

eventually, yes. that's #9063. I'll add a TODO

Comment on lines +17 to +19
CosmosChainAccountMethods,
CosmosChainInfo,
IBCMsgTransferOptions,
Copy link
Member

Choose a reason for hiding this comment

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

This file shouldn't depend on cosmos types, should it?

Copy link
Member Author

Choose a reason for hiding this comment

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

ideally not, but it already does. I see that as independent cleanup

const result = (await handle()) as Chain<any>;
t.deepEqual(await result.getChainInfo(), mockChainInfo);

// FIXME allow re-registering. perhaps this should be called `provide`.
Copy link
Member

Choose a reason for hiding this comment

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

init / register seems like the right thing to me; I wouldn't expect to be able to re-register.

Copy link
Member Author

Choose a reason for hiding this comment

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

PTAAL; I pushed a change after you started reviewing

message: '"chainInfos" already registered: "mock"',
});

// FIXME support running again in the same zone (as will happen after an upgrade)
Copy link
Member

Choose a reason for hiding this comment

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

FIXME when? oops... I started reviewing without noticing the DRAFT status.

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 requested it, thank you. I think it's okay to land FIXME comments in master until we're ready to publish the package

}),
{
message:
'key "chainInfos" has already been used in this zone and incarnation',
Copy link
Member

Choose a reason for hiding this comment

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

darn it; I thought zone.mapStore('chainInfos', ...) already had provide semantics.

Comment on lines 172 to 176
const chainInfos = zone.mapStore('chainInfos', {
const chainInfos = makeScalarBigMapStore('chainInfos', {
Copy link
Member

Choose a reason for hiding this comment

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

did you disconnect it from the zone on purpose?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, to reduce state to maintain across upgrades. however the contract registered the chainInfo the first time, it can do again. and in many cases it won't want to because it'll have made it into the upstream wellKnown registry

@turadg turadg requested a review from dckc June 5, 2024 14:53
@turadg turadg marked this pull request as ready for review June 5, 2024 14:53
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.

I'm surprised that the way the test makes zcf passes lint. But I suppose it doesn't matter.

? IcaAccount
: {}) &
CCI extends {
stakingTokens: {};
Copy link
Member

Choose a reason for hiding this comment

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

does it matter that stakingTokens is an Array? should this be...

Suggested change
stakingTokens: {};
stakingTokens: [];

Copy link
Member

Choose a reason for hiding this comment

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

Is an array accurate? I know this is how chain-registry has it modeled, but I am skeptical. The bond_denom field in x/staking params seems to indicate just a single entry: https://buf.build/cosmos/cosmos-sdk/docs/main:cosmos.staking.v1beta1#cosmos.staking.v1beta1.Params

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it is curious. https://github.com/search?q=repo%3Acosmology-tech%2Fchain-registry+stakingTokens shows only examples of a single element in the array.

I consider this out of scope that will be resolved in already scheduled issues.


const zone = bootstrap.rootZone;

const { zcf } = await setUpZoeForTest();
Copy link
Member

Choose a reason for hiding this comment

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

does setUpZoeForTest make a zcf? I get an error when I try this (in another context).

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch. I guess the zcf isn't used in this test. I've changed it to get a working one though,

  const { zcf } = await setupZCFTest();

But I don't know why TS didn't catch this. It typed zcf as any. It goes away with noImplicitAny: true but that causes many other linting errors

Comment on lines +41 to +42
const handle = orchestrate('mock', {}, async orc => {
return orc.getChain('mock');
Copy link
Member

Choose a reason for hiding this comment

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

thinking out loud: passing the chain object outside the context of the orchestrate callback seems odd somehow. Is that consistent with the asyncFlow rules? (where do we find those rules?)

Copy link
Member Author

@turadg turadg Jun 5, 2024

Choose a reason for hiding this comment

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

IDK. But if it isn't allowed I'd like to see a test where this would break.

Copy link
Member

@0xpatrickdev 0xpatrickdev left a comment

Choose a reason for hiding this comment

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

LGTM. It seems like #8879 is out of scope for the follow up PR(s) for #9187, but bringing this mocked file to your attention to maybe update in the course of your efforts:
https://github.com/Agoric/agoric-sdk/blob/5659362b247593793bd30a6b726b261587701487/packages/orchestration/src/utils/mockChainInfo.js

Comment on lines +33 to +34
allowedMessages: [],
allowedQueries: [],
Copy link
Member

Choose a reason for hiding this comment

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

Are you planning to use these for generating Orchestration Account facets? Regardless, looking forward to seeing the approach for that in the next iteration.

Comment on lines +133 to +138
const [{ denom: bondDenom }] = chainInfo.stakingTokens || [
{
denom: null,
},
];
assert(bondDenom, 'missing bondDenom');
Copy link
Member

Choose a reason for hiding this comment

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

Mentioned here - but i don't expect we'll see an array of staking staking tokens for anyone using cosmos.staking.v1beta1

@turadg turadg added the automerge:rebase Automatically rebase updates, then merge label Jun 5, 2024
@mergify mergify bot merged commit 21a664a into master Jun 5, 2024
66 checks passed
@mergify mergify bot deleted the 9187-any-chainInfo branch June 5, 2024 17:00
mergify bot added a commit that referenced this pull request Jun 5, 2024
## Description

In a recent discussion we noticed that the test wasn't showing a type
error where it should have:
#9452 (comment)

It would have with `noImplicitAny: false` but that pulls in way too many
other errors. While investigating I noticed some other things that could
be cleaned up and tackled those here.

The remaining blocker for `skipLibCheck: false` is the Telescope output
in `dist`. The .js files have `@ts-nocheck` but the .d.ts don't.
Surprising but not worth more effort.

### Security Considerations

n/a, types
### Scaling Considerations
n/a, types

### Documentation Considerations
none


### Testing Considerations

CI

### Upgrade Considerations

Potential cherry-pick complexities but we're moving to release based on
master
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.

3 participants