Skip to content

Commit

Permalink
Merge branch 'master' into mhofman/8279-atomic-swingset-upgrade-plan
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman committed Aug 31, 2023
2 parents 84246bb + 9f085d3 commit 0f63e41
Show file tree
Hide file tree
Showing 35 changed files with 284 additions and 277 deletions.
108 changes: 9 additions & 99 deletions golang/cosmos/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,13 +790,18 @@ func NewAgoricApp(
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)

const (
upgradeName = "agoric-upgrade-12"
upgradeNameTest = "agorictest-upgrade-12"
)

app.UpgradeKeeper.SetUpgradeHandler(
upgradeName,
upgrade11Handler(app, upgradeName),
upgrade12Handler(app, upgradeName),
)
app.UpgradeKeeper.SetUpgradeHandler(
upgradeNameTest,
upgrade11Handler(app, upgradeNameTest),
upgrade12Handler(app, upgradeNameTest),
)

if loadLatest {
Expand All @@ -819,108 +824,13 @@ func NewAgoricApp(
return app
}

type swingStoreMigrationEventHandler struct {
swingStore sdk.KVStore
}

func (eventHandler swingStoreMigrationEventHandler) OnExportStarted(height uint64, retrieveSwingStoreExport func() error) error {
return retrieveSwingStoreExport()
}

func (eventHandler swingStoreMigrationEventHandler) OnExportRetrieved(provider swingsetkeeper.SwingStoreExportProvider) (err error) {
exportDataReader, err := provider.GetExportDataReader()
if err != nil {
return err
}
defer exportDataReader.Close()

var hasExportData bool

for {
entry, err := exportDataReader.Read()
if err == io.EOF {
break
} else if err != nil {
return err
}
hasExportData = true
if !entry.HasValue() {
return fmt.Errorf("no value for export data key %s", entry.Key())
}
eventHandler.swingStore.Set([]byte(entry.Key()), []byte(entry.StringValue()))
}
if !hasExportData {
return fmt.Errorf("export data had no entries")
}
return nil
}

// upgrade11Handler performs standard upgrade actions plus custom actions for upgrade-11.
func upgrade11Handler(app *GaiaApp, targetUpgrade string) func(sdk.Context, upgradetypes.Plan, module.VersionMap) (module.VersionMap, error) {
// upgrade12Handler performs standard upgrade actions plus custom actions for upgrade-12.
func upgrade12Handler(app *GaiaApp, targetUpgrade string) func(sdk.Context, upgradetypes.Plan, module.VersionMap) (module.VersionMap, error) {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVm module.VersionMap) (module.VersionMap, error) {
app.CheckControllerInited(false)
// Record the plan to send to SwingSet
app.upgradePlan = &plan

// Perform swing-store migrations. We do this in the app upgrade handler
// since it involves multiple modules (x/vstorage and x/swingset) which
// don't strictly have a version change on their own.

// We are at the begining of the upgrade block, so all stores are commited
// as of the end of the previous block
savedBlockHeight := uint64(ctx.BlockHeight() - 1)

// First, repair swing-store metadata in case this node was previously
// initialized from a state-sync snapshot. This is done with a check on the
// block height to catch early any hangover related mismatch.
// Only entries related to missing historical metadata are imported, but we
// don't know what these look like here, so we provide it all.
getSwingStoreExportDataFromVstorage := func() (reader agorictypes.KVEntryReader, err error) {
return agorictypes.NewVstorageDataEntriesReader(
app.VstorageKeeper.ExportStorageFromPrefix(ctx, swingsetkeeper.StoragePathSwingStore),
), nil
}

// We're not restoring any artifact to swing-store, nor have any to provide
readNoArtifact := func() (artifact swingsettypes.SwingStoreArtifact, err error) {
return artifact, io.EOF
}

err := app.SwingStoreExportsHandler.RestoreExport(
swingsetkeeper.SwingStoreExportProvider{
BlockHeight: savedBlockHeight,
GetExportDataReader: getSwingStoreExportDataFromVstorage,
ReadNextArtifact: readNoArtifact,
},
swingsetkeeper.SwingStoreRestoreOptions{
ArtifactMode: swingsetkeeper.SwingStoreArtifactModeNone,
ExportDataMode: swingsetkeeper.SwingStoreExportDataModeRepairMetadata,
},
)
if err != nil {
return nil, err
}

// Then migrate the swing-store shadow copy:
// 1. Remove the swing-store "export data" shadow-copy entries from vstorage.
// 2. Export swing-store "export-data" (as of the previous block) through a
// handler that writes every entry into the swingset module's new Store.
app.VstorageKeeper.RemoveEntriesWithPrefix(ctx, swingsetkeeper.StoragePathSwingStore)
err = app.SwingStoreExportsHandler.InitiateExport(
savedBlockHeight,
swingStoreMigrationEventHandler{swingStore: app.SwingSetKeeper.GetSwingStore(ctx)},
swingsetkeeper.SwingStoreExportOptions{
ArtifactMode: swingsetkeeper.SwingStoreArtifactModeNone,
ExportDataMode: swingsetkeeper.SwingStoreExportDataModeAll,
},
)
if err == nil {
err = swingsetkeeper.WaitUntilSwingStoreExportDone()
}
if err != nil {
return nil, err
}

// Always run module migrations
mvm, err := app.mm.RunMigrations(ctx, app.configurator, fromVm)
if err != nil {
Expand Down
6 changes: 0 additions & 6 deletions golang/cosmos/app/const.go

This file was deleted.

1 change: 1 addition & 0 deletions packages/access-token/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"test": "ava",
"test:c8": "c8 $C8_OPTIONS ava --config=ava-nesm.config.js",
"test:xs": "exit 0",
"lint": "run-s --continue-on-error lint:*",
"lint-fix": "yarn lint:eslint --fix",
"lint:eslint": "eslint ."
},
Expand Down
2 changes: 1 addition & 1 deletion packages/boot/test/bootstrapTests/test-zcf-upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ test('run restart-vats proposal', async t => {
const zcfProbeBundle = await bundleSource(source);
await controller.validateAndInstallBundle(zcfProbeBundle);
// This test self-sufficiently builds all the artifacts it needs. The test in
// .../packages/deployment/upgradeTest/upgradeTest-scripts/agoric-upgrade-11/zoe-upgrade/
// .../packages/deployment/upgradeTest/upgradeTest-scripts/agoric-upgrade-12/zoe-upgrade/
// needs a bundled copy of ./zcfProbe.js as of the final commit that will be
// installed on-chain. Uncomment the following line and add
// `import fs from "fs";` to generate a bundle of the contract.
Expand Down
73 changes: 61 additions & 12 deletions packages/deployment/upgrade-test/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Defaults
ARG DEST_IMAGE=ghcr.io/agoric/agoric-sdk:dev
ARG BOOTSTRAP_MODE=main

# TODO different naming scheme for upgrade handler (in app.go) and the image name

###
# Kinds of layers:
# START ag0, start of the chain
# UPGRADE+TEST legacy layer type in which the chain upgrade and its tests are comingled
# UPGRADE layer that only runs the upgrade handler
# TEST layer that only tests a previous upgrade
# DEST the final layer this build is producing, opening an interactive shell

## START
# on agoric-uprade-7-2, with upgrade to agoric-upgrade-8
FROM ghcr.io/agoric/ag0:agoric-upgrade-7-2 as agoric-upgrade-7-2
ARG BOOTSTRAP_MODE
Expand All @@ -11,27 +24,31 @@ WORKDIR /usr/src/agoric-sdk/
COPY ./start_ag0.sh ./upgrade-test-scripts/
COPY ./bash_entrypoint.sh ./env_setup.sh ./start_to_to.sh ./upgrade-test-scripts/
SHELL ["/bin/bash", "-c"]
# this is the only layer that starts ag0
RUN . ./upgrade-test-scripts/start_ag0.sh

## UPGRADE+TEST
## this is agoric-upgrade-8 aka pismoA
FROM ghcr.io/agoric/agoric-sdk:29 as agoric-upgrade-8
ARG BOOTSTRAP_MODE
ENV THIS_NAME=agoric-upgrade-8 BOOTSTRAP_MODE=${BOOTSTRAP_MODE}
WORKDIR /usr/src/agoric-sdk/
# copy from previous build
COPY --from=agoric-upgrade-7-2 /root/.agoric /root/.agoric

# boilerplate to copy scripts for this upgrade
WORKDIR /usr/src/agoric-sdk/
COPY ./bash_entrypoint.sh ./env_setup.sh ./start_to_to.sh ./upgrade-test-scripts/
COPY ./${THIS_NAME} ./upgrade-test-scripts/${THIS_NAME}/
COPY --from=agoric-upgrade-7-2 /root/.agoric /root/.agoric
RUN chmod +x ./upgrade-test-scripts/*.sh
SHELL ["/bin/bash", "-c"]
RUN . ./upgrade-test-scripts/start_to_to.sh

## UPGRADE+TEST
ARG DEST_IMAGE
#this is agoric-upgrade-8-1 aka pismoB
FROM ghcr.io/agoric/agoric-sdk:30 as agoric-upgrade-8-1
ARG BOOTSTRAP_MODE UPGRADE_INFO_9
ENV THIS_NAME=agoric-upgrade-8-1 UPGRADE_TO=agoric-upgrade-9 UPGRADE_INFO=${UPGRADE_INFO_9} BOOTSTRAP_MODE=${BOOTSTRAP_MODE}

WORKDIR /usr/src/agoric-sdk/
COPY ./bash_entrypoint.sh ./env_setup.sh ./start_to_to.sh ./upgrade-test-scripts/
COPY ./${THIS_NAME} ./upgrade-test-scripts/${THIS_NAME}/
Expand All @@ -40,6 +57,7 @@ RUN chmod +x ./upgrade-test-scripts/*.sh
SHELL ["/bin/bash", "-c"]
RUN . ./upgrade-test-scripts/start_to_to.sh

# UPGRADE+TEST
ARG DEST_IMAGE
# this is agoric-upgrade-9 / pismoC with upgrade to agoric-upgrade-10
FROM ghcr.io/agoric/agoric-sdk:31 as agoric-upgrade-9
Expand All @@ -55,7 +73,7 @@ RUN chmod +x ./upgrade-test-scripts/*.sh
SHELL ["/bin/bash", "-c"]
RUN . ./upgrade-test-scripts/start_to_to.sh


# UPGRADE+TEST
ARG DEST_IMAGE
#this is agoric-upgrade-10 / vaults
FROM ghcr.io/agoric/agoric-sdk:35 as agoric-upgrade-10
Expand All @@ -70,15 +88,15 @@ RUN chmod +x ./upgrade-test-scripts/*.sh
SHELL ["/bin/bash", "-c"]
RUN . ./upgrade-test-scripts/start_to_to.sh

# UPGRADE
ARG DEST_IMAGE
#this is agoric-upgrade-10 upgrading to 11
#it's a separate target because agoric-upgrade-10 takes so long to test
FROM ghcr.io/agoric/agoric-sdk:35 as agoric-upgrade-10-to-11
FROM ghcr.io/agoric/agoric-sdk:35 as propose-agoric-upgrade-11
# This default UPGRADE_INFO_11 is to test core proposals like the network vat.
# TODO: Maybe replace with a Zoe core proposal, or remove when other paths test it.
ARG BOOTSTRAP_MODE UPGRADE_INFO_11='{"coreProposals":["@agoric/builders/scripts/vats/init-network.js"]}'
ENV THIS_NAME=agoric-upgrade-10-to-11 UPGRADE_TO=agoric-upgrade-11 UPGRADE_INFO=${UPGRADE_INFO_11} BOOTSTRAP_MODE=${BOOTSTRAP_MODE}

ARG BOOTSTRAP_MODE UPGRADE_INFO_11
ENV THIS_NAME=propose-agoric-upgrade-11 UPGRADE_TO=agoric-upgrade-11 UPGRADE_INFO=${UPGRADE_INFO_11} BOOTSTRAP_MODE=${BOOTSTRAP_MODE}
WORKDIR /usr/src/agoric-sdk/
COPY ./bash_entrypoint.sh ./env_setup.sh ./start_to_to.sh ./upgrade-test-scripts/
COPY ./${THIS_NAME} ./upgrade-test-scripts/${THIS_NAME}/
Expand All @@ -87,18 +105,49 @@ RUN chmod +x ./upgrade-test-scripts/*.sh
SHELL ["/bin/bash", "-c"]
RUN . ./upgrade-test-scripts/start_to_to.sh

ARG DEST_IMAGE
# TEST
#this is agoric-upgrade-11 / vaults+1
FROM ${DEST_IMAGE} as agoric-upgrade-11
ARG DEST_IMAGE
FROM ghcr.io/agoric/agoric-sdk:36 as agoric-upgrade-11
ARG BOOTSTRAP_MODE
ENV THIS_NAME=agoric-upgrade-11 BOOTSTRAP_MODE=${BOOTSTRAP_MODE}
# this boot doesn't need an upgrade
# start-chain boilerplate
WORKDIR /usr/src/agoric-sdk/
COPY ./bash_entrypoint.sh ./env_setup.sh ./start_to_to.sh ./upgrade-test-scripts/
COPY ./${THIS_NAME} ./upgrade-test-scripts/${THIS_NAME}/
COPY --from=propose-agoric-upgrade-11 /root/.agoric /root/.agoric
RUN chmod +x ./upgrade-test-scripts/*.sh
SHELL ["/bin/bash", "-c"]
RUN . ./upgrade-test-scripts/start_to_to.sh

# UPGRADE
ARG DEST_IMAGE
FROM ghcr.io/agoric/agoric-sdk:36 as propose-agoric-upgrade-12
# TODO: Replace with actual Zoe core proposal for upgrade 12 (MCS, Kread, Zoe, restart-contracts, etc)
ARG BOOTSTRAP_MODE UPGRADE_INFO_12='{"coreProposals":["@agoric/builders/scripts/vats/init-network.js"]}'
ENV THIS_NAME=propose-agoric-upgrade-12 UPGRADE_TO=agoric-upgrade-12 UPGRADE_INFO=${UPGRADE_INFO_12} BOOTSTRAP_MODE=${BOOTSTRAP_MODE}
COPY --from=agoric-upgrade-11 /root/.agoric /root/.agoric
# start-chain boilerplate
WORKDIR /usr/src/agoric-sdk/
COPY ./bash_entrypoint.sh ./env_setup.sh ./start_to_to.sh ./upgrade-test-scripts/
COPY ./${THIS_NAME} ./upgrade-test-scripts/${THIS_NAME}/
COPY --from=agoric-upgrade-10-to-11 /root/.agoric /root/.agoric
RUN chmod +x ./upgrade-test-scripts/*.sh
SHELL ["/bin/bash", "-c"]
RUN . ./upgrade-test-scripts/start_to_to.sh

# DEST (TEST)
#this is agoric-upgrade-12 / multi-collateral, etc.
ARG DEST_IMAGE
FROM ${DEST_IMAGE} as agoric-upgrade-12
ARG BOOTSTRAP_MODE
ENV THIS_NAME=agoric-upgrade-12 BOOTSTRAP_MODE=${BOOTSTRAP_MODE}
COPY --from=propose-agoric-upgrade-12 /root/.agoric /root/.agoric
# start-chain boilerplate
WORKDIR /usr/src/agoric-sdk/
COPY ./bash_entrypoint.sh ./env_setup.sh ./start_to_to.sh ./package.json ./*.mjs ./upgrade-test-scripts/
COPY ./${THIS_NAME} ./upgrade-test-scripts/${THIS_NAME}/
RUN apt install -y tmux
SHELL ["/bin/bash", "-c"]
RUN chmod +x ./upgrade-test-scripts/*.sh
# enter image in interactive shell
ENTRYPOINT /usr/src/agoric-sdk/upgrade-test-scripts/start_to_to.sh
16 changes: 11 additions & 5 deletions packages/deployment/upgrade-test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ifeq ($(BOOTSTRAP_MODE),main)
else
TAG_SUFFIX=-$(BOOTSTRAP_MODE)
endif
TARGET?=agoric-upgrade-11
TARGET?=agoric-upgrade-12
dockerLabel?=$(TARGET)
ifdef TMUX_CC
tmuxCC=1
Expand Down Expand Up @@ -38,12 +38,18 @@ agoric-upgrade-9: agoric-upgrade-8-1
agoric-upgrade-10: agoric-upgrade-9
$(BUILD) --target agoric-upgrade-10 -t $(REPOSITORY):agoric-upgrade-10$(TAG_SUFFIX)

agoric-upgrade-10-to-11: agoric-upgrade-10
$(BUILD) --target agoric-upgrade-10-to-11 -t $(REPOSITORY):agoric-upgrade-10-to-11$(TAG_SUFFIX)
propose-agoric-upgrade-11: agoric-upgrade-10
$(BUILD) --target propose-agoric-upgrade-11 -t $(REPOSITORY):propose-agoric-upgrade-11$(TAG_SUFFIX)

agoric-upgrade-11: agoric-upgrade-10-to-11
agoric-upgrade-11: propose-agoric-upgrade-11
$(BUILD) --target agoric-upgrade-11 -t $(REPOSITORY):agoric-upgrade-11$(TAG_SUFFIX)

propose-agoric-upgrade-12: agoric-upgrade-11
$(BUILD) --target propose-agoric-upgrade-12 -t $(REPOSITORY):propose-agoric-upgrade-12$(TAG_SUFFIX)

agoric-upgrade-12: propose-agoric-upgrade-12
$(BUILD) --target agoric-upgrade-12 -t $(REPOSITORY):agoric-upgrade-12$(TAG_SUFFIX)

# build main bootstrap
build: $(TARGET)

Expand All @@ -68,4 +74,4 @@ run_test:
run_bash:
$(RUN) --entrypoint /bin/bash $(REPOSITORY):$(dockerLabel)

.PHONY: local_sdk agoric-upgrade-7-2 agoric-upgrade-8 agoric-upgrade-8-1 agoric-upgrade-9 agoric-upgrade-10 agoric-upgrade-11 build build_test run
.PHONY: local_sdk agoric-upgrade-7-2 agoric-upgrade-8 agoric-upgrade-8-1 agoric-upgrade-9 agoric-upgrade-10 agoric-upgrade-11 agoric-upgrade-12 build build_test run
15 changes: 15 additions & 0 deletions packages/deployment/upgrade-test/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ docker exec -it sweet_edison bash
To make the wallet ui talk to your local chain, set the network config to
`https://local.agoric.net/network-config`

## To add an upgrade

1. Update the upgrade handler in app.go
2. Duplicate the last pair of UPGRADE and TEST blocks
3. Update their number from the UPGRADE / DEST block at the end
4. Make directory for tests (e.g. `agoric-upgrade-12`)
4. Make directory for ugprade (e.g. `propose-agoric-upgrade-12` with a `.keep`)
5. Update the UPGRADE/DEST pair to be your new upgrade (THIS_NAME matching the upgrade handler string in app.go)
6. Update the `Makefile`
- the two targets to `Makefile` (e.g. `propose-agoric-upgrade-12` and `agoric-upgrade-12`)
- set the default TARGET (e.g. `agoric-upgrade-12`)
- add the DEST target to the `.phony` in `Makefile`
7. Test with `make local_sdk build run`


## Development

You can iterate on a particular upgrade by targeting. When you exit and run again, it will be a fresh state.
Expand Down
Loading

0 comments on commit 0f63e41

Please sign in to comment.