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: upgrade walletFactory to go beyond vbank assets #8147

Merged
merged 1 commit into from
Aug 24, 2023

Conversation

dckc
Copy link
Member

@dckc dckc commented Aug 4, 2023

closes: #8156
refs: #8071

Description / Upgrade Considerations

  • proposal builder in the style of agoric run/writeCoreProposal
  • docker upgrade test using the game NFT contract from the contract uprgrade PR

Security / Scaling Considerations

none that I can think of

Documentation / Testing Considerations

Once we migrate it from mostly-bash to mostly-js, this should make a good example for...

$ cd packages/deployment/upgrade-test
$ make local_sdk build
$ make run

@dckc
Copy link
Member Author

dckc commented Aug 4, 2023

manual testing stuff

start the container with make run_bash and then start the chain:

agoric-upgrade-11# agd start --log_level=warn >>,chain.log 2>&1 &

I think there's an env.sh step in there too.

## agoric run outside the container
$ rm -rf ~/.agoric/cache; agoric run scripts/wfup.js
agoric: run: running /home/connolly/projects/agoric-sdk/packages/smart-wallet/scripts/wfup.js
agoric: run: Deploy script will run with Node.js ESM
bundle-source --to /home/connolly/projects/agoric-sdk/packages/smart-wallet/bundles /home/connolly/projects/agoric-sdk/packages/smart-wallet/src/walletFactory.js walletFactory
(Error#1)
Error#1: out of date: [ { relativePath: '', mtime: '2023-08-04T20:55:49.062Z' } ] . walletFactory bundled at 2023-08-04T20:53:27.269Z

/home/connolly/projects/agoric-sdk/packages/smart-wallet/bundles add: walletFactory from /home/connolly/projects/agoric-sdk/packages/smart-wallet/src/walletFactory.js
/home/connolly/projects/agoric-sdk/packages/smart-wallet/bundles bundled 151 files in bundle-walletFactory.js at 2023-08-04T20:56:02.570Z
creating upgrade-walletFactory-permit.json
creating upgrade-walletFactory.js
You can now run a governance submission command like:
  agd tx gov submit-proposal swingset-core-eval upgrade-walletFactory-permit.json upgrade-walletFactory.js \
    --title="Enable <something>" --description="Evaluate upgrade-walletFactory.js" --deposit=1000000ubld \
    --gas=auto --gas-adjustment=1.2
Remember to install bundles before submitting the proposal:
  agd tx swingset install-bundle @/home/connolly/.agoric/cache/b1-c3005df01654266067b7779d6267037d60f5b995c65a5f8c62b89c4ab42495dfe4ce0914d271399321f6f5575453e56c5e4e8faf791336b9c5177e1d7853c361.json
  agd tx swingset install-bundle @/home/connolly/.agoric/cache/b1-5fad04f7560ba9593321df66f4605cba796a2f03643d98044a0d3e8c3b611deb133d7eea003d06fcbb5b5f898bc0ef82b038a18baa740af64f08925e90ff7bb8.json

## copy results into the /tmp/ directory of the container. $cid comes from `docker ps`
$ for f in ./upgrade-walletFactory* ~/.agoric/cache/b1-* ; do echo $f; docker cp $f $cid:/tmp/; done
./upgrade-walletFactory.js
./upgrade-walletFactory-permit.json
/home/connolly/.agoric/cache/b1-5fad04f7560ba9593321df66f4605cba796a2f03643d98044a0d3e8c3b611deb133d7eea003d06fcbb5b5f898bc0ef82b038a18baa740af64f08925e90ff7bb8.json
/home/connolly/.agoric/cache/b1-c3005df01654266067b7779d6267037d60f5b995c65a5f8c62b89c4ab42495dfe4ce0914d271399321f6f5575453e56c5e4e8faf791336b9c5177e1d7853c361.json

Then, inside the container:

## mint a bunch of IST to pay for publish-bundle txs
agoric-upgrade-11# ./mint-ist.sh

## upload the 2 bundles
agoric-upgrade-11# ./wf-install-bundles.sh

## propose (and enact) the upgrade
agoric-upgrade-11# ./wf-propose.sh

## look at the results
agoric-upgrade-11# less -R ,chain.log

@dckc dckc changed the base branch from master to 8045-backwards-compatibility August 8, 2023 22:27
Base automatically changed from 8045-backwards-compatibility to master August 9, 2023 17:27
@dckc dckc force-pushed the 7226-sw-nft-issuer branch 2 times, most recently from ae13f1a to e0fbdc1 Compare August 14, 2023 15:42
};

/**
* Parse output of `agoric run proposal-builder.js`
Copy link
Member Author

Choose a reason for hiding this comment

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

An alternative is to teach agoric run to produce parseable output. This is the 2nd time I didn't opt to do that.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe someday. For testing purposes I think we'd just add a parse-smart version to upgradeHelper.js once that's available

const { body, slots } = JSON.parse(txt);
const theEntries = zip(JSON.parse(body.slice(1)), slots).map(
([[name, ref], boardID]) => {
const iface = ref.replace(/^\$\d+\./, '');
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 has got poor-man's-smallcaps-decoding mixed in. The smallcaps-related hacks could at least be moved into the const smallCaps = {...} widget.

@@ -48,13 +48,17 @@ export const start = async zcf => {

totalPlaces(want.Places) <= 3n || Fail`only 3 places allowed when joining`;

atomicRearrange(
Copy link
Member Author

Choose a reason for hiding this comment

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

btw... @turadg another static typing nit: getCopyBagEntries returns any.

Copy link
Member

Choose a reason for hiding this comment

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

for #7507

@dckc dckc marked this pull request as ready for review August 18, 2023 15:10
Copy link
Member

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

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

I have a few questions (most relevantly #8147 (comment) ), but the overall approach does work AFAICT.

testHasChildren() {
path=$1
min=$2
line="$(agd query vstorage children $path -o jsonlines)"
Copy link
Member

Choose a reason for hiding this comment

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

What dictates when to use -o json vs. -o jsonlines?

Copy link
Member Author

Choose a reason for hiding this comment

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

dunno. jsonlines is what I saw everywhere else.

line="$(agoric follow -lF :published.agoricNames.brand -o text)"
# find brand by name, then corresponding slot
id=$(echo $line | jq -r '.slots as $slots | .body | gsub("^#";"") | fromjson | map(.[0]) | index("'$name'") | $slots[.]')
echo $name Id: $id
Copy link
Member

Choose a reason for hiding this comment

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

Was this intentionally left in without some kind of debugging condition?

Copy link
Member Author

Choose a reason for hiding this comment

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

All over this PR I waffle about how much logging to do. This is one of the reasons I asked to discuss this with you.

Copy link
Member

Choose a reason for hiding this comment

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

since it's test code in a framework that hasn't stabilized and everyone is still learning, I think we should bias towards verbosity


line="$(agoric follow -lF :published.boardAux.$id -o jsonlines)"
displayInfo="$(echo $line | jq -c .displayInfo)"
echo test_val "$displayInfo" "$expected" "$name displayInfo from boardAux"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
echo test_val "$displayInfo" "$expected" "$name displayInfo from boardAux"
test_val "$displayInfo" "$expected" "$name displayInfo from boardAux"

Copy link
Member Author

Choose a reason for hiding this comment

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

oops!

packages/smart-wallet/scripts/wfup.js Outdated Show resolved Hide resolved
Comment on lines 153 to 156
const makeBoardAuxNode = async (chainStorage, boardId) => {
const boardAux = E(chainStorage).makeChildNode(BOARD_AUX);
return E(boardAux).makeChildNode(boardId);
};
Copy link
Member

Choose a reason for hiding this comment

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

Is anything awaiting results from makeBoardAuxNode via publishBrandInfo? Even if not, it would probably make sense to call E(chainStorage).makeChildNode(BOARD_AUX) only once rather than once for every brand.

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 thought I fixed that. Weird.

Comment on lines 163 to 165
const node = makeBoardAuxNode(chainStorage, id);
const aux = marshalData.toCapData(harden({ displayInfo }));
await E(node).setValue(JSON.stringify(aux));
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 creating a parallel hierarchy for board-published brands, right? And with a path that is keyed by boardID but lacks an obvious connection to "agoricNames"? Have the right people considered this design and possible alternatives?

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, that's what it's doing. Whether it's sufficiently considered is a good question.

Design considerations included:

  • ideally, it would be a platform thing, but add (immutable) auxiliary data to Presences? #2069 is an open research problem
  • should the mechanism be for things in agoricNames only or for any brand (or any other remotable, for that matter)?
    • we chose: any remotable on the board
  • should all the aux data for well-known brands be at one key like agoricNames.vbankAsset or should each brand have a separate key?
    • we chose a separate key

Turadg and I discussed those alternatives and agreed to this one. Sam found it inconvenient to make more than one query but eventually agreed it was better than doing O(n) work for each write.

Figuring out who are the right people is an ongoing challenge, for me. I think bringing in your perspective is useful.

Copy link
Member

Choose a reason for hiding this comment

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

This comment was marked as duplicate.

@turadg turadg requested a review from erights August 22, 2023 19:18
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.

@dckc went over the possible aux data problem with me during recorded office hours today. Since this PR was already otherwise approved and was waiting only on my evaluating of this possible problem, my additional approval here is only approving that there is no such problem here. I have not evaluated the rest of the PR.

Concretely, this is about the canonical concrete example of the problem: That we'd like a presence of a brand to carry the displayInfo. Mapping to the canonical three-party handoff, Carol in VatC is the brand. Alice in VatA sends her presence for Carol to Bob in VatB. VatB, on unmarshalling the message from VatA must form the presence for Carol and deliver it to Bob without waiting for a round trip to VatC. If the brand presence carries the displayInfo at that moment, then VatB would be believing VatA about the displayInfo associated with the brand / Carol, where only VatC should be authoritative about the state of Carol. If VatA lies, then Bob would see the wrong displayInfo.

The entire problem goes away at the cost of a round trip: If the presence itself does not carry the displayInfo, but instead, Bob asks Carol for her displayInfo, then only Carol (and therefore VatC) is taken by Bob as authoritative over Carol's displayInfo. Alice cannot both immediately communicate Carol's identity (by passing a presence) and mislead Bob to believing that identity is associated with a different displayInfo.

The scenario at stake in this PR has none of these hazards. There is no third party less trusted than VatC that can influence the client's notion of what displayInfo is associated with the brand. And the client only obtains the displayInfo after a round trip to querying info that is known only to be updated by those who are legitimately authoritative over that info.

So, if all that makes sense and correctly maps to the question at stake, LGTM. If not, please let me know and we should continue the discussion.

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.

Nice work! Just a couple requests before merging

Comment on lines 2 to 5
* @file Proposal Builder: Upgrade walletFactory
*
* Usage:
* agoric run build-game1-start.js
Copy link
Member

Choose a reason for hiding this comment

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

📝 🙌

@@ -0,0 +1,2 @@
upgrade-walletFactory-permit.json
Copy link
Member

Choose a reason for hiding this comment

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

question: should we have a global gitignore on -permit.json? if so, should we name them .permit.json to hint that it's a kind of thing?

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 is a kind of thing. (There's a static type and could be a pattern). So I'd support renaming all of them together in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

#8249, draft until this one lands

@@ -1,13 +1,11 @@
#!/bin/bash

. ./upgrade-test-scripts/env_setup.sh
SDK=${SDK:-/usr/src/agoric-sdk}
Copy link
Member

Choose a reason for hiding this comment

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

please comment what environment provides that source path. Docker? and what wants to override it

# zoe vat is at incarnation 0
test_val "$(yarn --silent node $upgrade11/vat-status.mjs zoe)" "0" "zoe vat incarnation"
test_val "$(yarn --silent node $upgrade11/tools/vat-status.mjs zoe)" "0" "zoe vat incarnation"
Copy link
Member

Choose a reason for hiding this comment

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

remark: probably useful outside upgrade11, but we will refactor in the JS port

Copy link
Member

Choose a reason for hiding this comment

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

remark: will be totally refactored after #8237

wfInstance: wfInstanceP,
ppInstance: ppInstanceP,
walletBridgeManager: walletBridgeManagerP,
// @ts-expect-error chainStorage is only falsy in testing
Copy link
Member

Choose a reason for hiding this comment

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

nit: shouldn't be necessary.

Suggested change
// @ts-expect-error chainStorage is only falsy in testing
// @ts-expect-error UNTIL https://github.com/Agoric/agoric-sdk/issues/8247

const { agoricNames, board, assetPublisher } = zcf.getTerms();
const upgrading = baggage.has('walletsByAddress');
Copy link
Member

Choose a reason for hiding this comment

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

consider: inlining the has to the conditional below. This is a valid signal of "upgrading" but we don't need that general signal.

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 moved the declaration next to the use.

Fully inlined, it seemed to need a comment. Might as well let the code speak for itself.

@@ -2,11 +2,10 @@
/* eslint @typescript-eslint/no-floating-promises: "warn" */

// deep import to avoid dependency on all of ERTP, vat-data
Copy link
Member

Choose a reason for hiding this comment

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

TIL

]),
);
// We use the deprecated stage/reallocate API
// so that we can test this with the version of zoe on mainnet1B.
Copy link
Member

Choose a reason for hiding this comment

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

👍


const marshalData = makeMarshal(_val => Fail`data only`);

// avoid importing all of ERTP
Copy link
Member

Choose a reason for hiding this comment

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

above it says a deep import would accomplish this (importing without all of it). yes or no?

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 think this dates from before I used writeCoreProposal, i.e. when import wouldn't work.

  - mint-ist.sh to pay for publish-bundle
    adapted from auctioneer-private-args branch
    - ensure GOV1ADDR is set
      so we don't give agd too few args and get a weird diagnostic
  - chore(walletFactory): initHandler / setHandler / upgrading
  - chore(walletFactory): start -> prepare for compat
  - chore(game contract): atomicRearrange -> zcf.reallocate() for compat
  - feat(smart-wallet): publishAgoricBrandsDisplayInfo to vstorage
  - test(smart-wallet): upgraded walletFactory handles game NFT
    - install game contract before walletFactory upgrade
    - move vat-status.mjs to tools/
    - move mint-ist, parseProposals to tools/
  - chore: split game1 proposal from walletFactory upgrade
@dckc dckc enabled auto-merge August 24, 2023 20:11
@dckc dckc added this pull request to the merge queue Aug 24, 2023
Merged via the queue into master with commit 22c3573 Aug 24, 2023
63 of 67 checks passed
@dckc dckc deleted the 7226-sw-nft-issuer branch August 24, 2023 20:59
@aj-agoric aj-agoric added this to the agoric-upgrade-11wf milestone Sep 7, 2023
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.

arbitrary well-known ERTP asset support in smart wallet
5 participants