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

feat(cosmos): Add a "CapData" vstorage RPC endpoint #8056

Merged
merged 11 commits into from
Jul 28, 2023

Conversation

gibson042
Copy link
Member

Fixes #7581

Description

RPC requests with path "/agoric.vstorage.Query/CapData" will get back vstorage data that has been interpreted as CapData and (lossily) formatted in the style of agoric follow or scripts/get-flattened-publication.sh.

Security Considerations

There is no expected change in security posture. Clients can continue to request the raw data; this interface just provides a convenient way for them to keep up with potential future changes in CapData representation without having to run local transformations.

Scaling Considerations

Use of the new endpoint represents more work for an RPC node and generation of some more Go garbage, but the impact should be negligible (and the responses theirselves will be smaller).

Documentation Considerations

We don't seem to have any documentation of RPC endpoints. Perhaps @Tyrosine22 has thoughts on how to address that?

Testing Considerations

I'm still considering options for how to test the CapData decoder at golang/cosmos/x/vstorage/capdata/capdata.go , and will probably add some static tests mirroring those in https://github.com/endojs/endo/tree/master/packages/marshal but would also like to roll something more into endojs/endo#1588 where endo publishes a generic conformance testing artifact that is imported and used in the testing of this Go package.

@gibson042 gibson042 requested review from turadg, dckc and michaelfig July 17, 2023 17:00
Copy link
Member

@turadg turadg left a comment

Choose a reason for hiding this comment

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

I don't know Go well enough to review the implementation. The thrust of the design makes sense to me. I'd like to see some tests that demonstrate the interface for clients. (e.g. example responses)

dckc
dckc previously requested changes Jul 17, 2023
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.

examples / tests are critical, I think

@dckc dckc dismissed their stale review July 19, 2023 18:13

now I see the relevant tests

@dckc
Copy link
Member

dckc commented Jul 19, 2023

now I see the relevant tests
oops... that was a different PR. (I won't renew my request for changes just now, though)

@gibson042 gibson042 force-pushed the gibson-7581-rpc-capdata-formatting branch from 539e2a3 to d8522cc Compare July 21, 2023 19:55
@gibson042 gibson042 force-pushed the gibson-7581-rpc-capdata-formatting branch from d8522cc to 36b921d Compare July 21, 2023 20:12
var capDataRemotableValueFormats = map[string]string{
FormatRemotableAsObject: FormatRemotableAsObject,
FormatRemotableAsString: FormatRemotableAsString,
// No default.
Copy link
Member

Choose a reason for hiding this comment

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

with no default, is it an error when the request omits this parameter? object seems to me the appropriate default as it's the most generic.

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, I decided that omitting FormatRemotableAsString should be an error because all valid values are lossy w.r.t. CapData.

Copy link
Member

Choose a reason for hiding this comment

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

ah I see. that rationale would be worth including in the comment

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Comment on lines +71 to +72
// * "object" represents each Remotable as an `{ id, allegedName }` object.
// * "string" represents each Remotable as a bracketed string such as `[Alleged: IST brand {}]`.
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 important documentation. is it published somewhere using godoc ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not that I know of (as mentioned in the PR summary, we don't seem to have any documentation of RPC endpoints). Does anyone have a place where they would expect to find it?

Copy link
Member

Choose a reason for hiding this comment

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

we don't seem to have any documentation of RPC endpoints

It's far from perfect, but we have >0 for inter protocol RPC stuff: https://github.com/Agoric/agoric-sdk/tree/master/packages/inter-protocol#reading-data-off-chain

As to the rest, yes, it's been a hole in our docs for some time; I put what notes I learn in...

In some sense, this is a different issue, since that issue was about documentation of the form "Agoric stuff is based on cosmos-sdk; go read XYZ to find out how the lower level works." It turns out that there's no obvious candidate for XYZ, btw.

Does anyone have a place where they would expect to find it?

The inter-protocol precedent suggests a readme under golang/cosmos/x/vstorage

Copy link
Member Author

@gibson042 gibson042 Jul 26, 2023

Choose a reason for hiding this comment

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

Added golang/cosmos/x/vstorage/README.md.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, it turns out that the documentation is available via godoc of the generated pb.go.

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 don't see how clients can work if Id is left out of remotable string rendering.

Comment on lines 140 to 148
// capdataRemotableToString represents a Remotable as a bracketed string
// containing its alleged name (e.g., "[Foo {}]").
func capdataRemotableToString(r *capdata.CapdataRemotable) interface{} {
iface := "Remotable"
if r.Iface != nil || *r.Iface != "" {
iface = *r.Iface
}
return fmt.Sprintf("[%s {}]", iface)
}
Copy link
Member

Choose a reason for hiding this comment

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

In order to prevent clients from relying on the Iface (aka debug name) for correctness, the rendering of a remotable must preserve the Id. Including the Iface at all is risky.

Copy link
Member Author

@gibson042 gibson042 Jul 24, 2023

Choose a reason for hiding this comment

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

Per #7581, this attempts to align with agoric follow -o jsonlines:

agoric --sdk follow :published.vaultFactory.manager0.metrics -B https://devnet.agoric.net/network-config --proof none -o jsonlines | jq .
{
  "liquidatingCollateral": {
    "brand": "[Alleged: SEVERED: IbcATOM brand {}]",
    "value": "0"
  },
  …

Who constitutes the right group to discuss well-motivated deviation? @arirubinstein?

if r.Iface != nil || *r.Iface != "" {
iface = *r.Iface
iface, _ = strings.CutPrefix(iface, "Alleged: ")
iface, _ = strings.CutSuffix(iface, " brand")
Copy link
Member

Choose a reason for hiding this comment

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

Why cut off "brand"? Why should this code have knowledge of ERTP?

cc @erights

Copy link
Member Author

Choose a reason for hiding this comment

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

This attempts to align with scripts/get-flattened-publication.sh. I'm open to deviation here as well, but again unclear about authority for making such a decision.

@gibson042 gibson042 force-pushed the gibson-7581-rpc-capdata-formatting branch from b39ca47 to a7f17fe Compare July 24, 2023 17:00
@gibson042
Copy link
Member Author

This PR now features what AFAICT is the most comprehensive Go testing in the repository, for both the capdata decoder and the CapData gRPC endpoint.

Copy link
Member

@erights erights left a comment

Choose a reason for hiding this comment

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

Title says "CapData". Did you mean "smallcaps"?

@gibson042
Copy link
Member Author

Title says "CapData". Did you mean "smallcaps"?

Nope, it's formatting CapData regardless of smallcaps vs. legacy encoding.

@gibson042 gibson042 requested a review from turadg July 27, 2023 16:56
@gibson042
Copy link
Member Author

We decided at the cosmic-swingset meeting that reducing lossiness is more important than preserving precise compatibility with agoric follow and get-flattened-publication.sh formats, both of which were based on somewhat ad hoc decisions. As of the latest push, the new Remotable representations are

  • object: { "id": $slotId, "allegedName": "$unprefixedName" }, e.g. { …, "brand": { "id": "board007", "allegedName": "IST brand" } }
  • string: "[$unmodifiedName <$slotId>]", e.g. { …, "brand": "[Alleged: IST brand <board007>]" }

@turadg, please confirm that this works for you.

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 like it

Copy link
Member

@turadg turadg left a comment

Choose a reason for hiding this comment

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

WFM. Glad to see the eventual design had support in the full cosmic-swingset group.

@gibson042 gibson042 added this pull request to the merge queue Jul 28, 2023
Merged via the queue into master with commit 91f5e93 Jul 28, 2023
@gibson042 gibson042 deleted the gibson-7581-rpc-capdata-formatting branch July 28, 2023 22:10
mhofman pushed a commit that referenced this pull request Aug 7, 2023
feat(cosmos): Add a "CapData" vstorage RPC endpoint
mhofman pushed a commit that referenced this pull request Feb 18, 2024
feat(cosmos): Add a "CapData" vstorage RPC endpoint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support agoric follow -o jsonlines style vstorage browsing in the agd api
4 participants