Skip to content

Commit

Permalink
rebase/cherry-pick commits for upgrade 12 (#8510)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman authored Nov 10, 2023
2 parents 867dea5 + 664f59f commit cfa7cb2
Show file tree
Hide file tree
Showing 72 changed files with 1,271 additions and 1,859 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,13 @@ module.exports = {
project: false,
},
},
{
files: ['packages/**/upgrade-test-scripts/**/*.*js'],
rules: {
// NOTE: This rule is enabled for the repository in general. We turn it
// off for test code for now.
'@jessie.js/safe-await-separator': 'off',
},
},
],
};
4 changes: 3 additions & 1 deletion .github/workflows/test-all-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,9 @@ jobs:
- uses: actions/checkout@v3
- name: docker build (sdk)
run: cd packages/deployment && ./scripts/test-docker-build.sh | $TEST_COLLECT
# run: cd packages/deployment && ./scripts/test-docker-build.sh | $TEST_COLLECT
# XXX skip TAP test output and collection for now; it hides the output from the logs
run: cd packages/deployment && make docker-build-sdk
- name: docker build upgrade test
run: cd packages/deployment/upgrade-test && docker build --build-arg BOOTSTRAP_MODE=${{ matrix.bootstrap-version }} --build-arg DEST_IMAGE=ghcr.io/agoric/agoric-sdk:latest -t docker-upgrade-test:latest -f Dockerfile upgrade-test-scripts
- name: docker run upgrade final stage
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SECURITY.md @Agoric/security
2 changes: 1 addition & 1 deletion MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ in this branch. The release tags will be human-meaningful, the release branch ne
```sh
# Create a release branch.
now=`date -u +%Y%m%dT%H%M%S`
git checkout -b release-$now
git checkout -b prepare-release-$now
```

- [ ] Do a `yarn install` to generate tooling needed for the release.
Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Supported Versions

The current `master` and `release-pismo` branches are supported with security updates.
The current `master` and only the latest `agoric-upgrade-*` tagged release and pre-release are supported with security updates.

## Coordinated Vulnerability Disclosure

Expand Down
112 changes: 14 additions & 98 deletions golang/cosmos/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ import (
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"

gaiaappparams "github.com/Agoric/agoric-sdk/golang/cosmos/app/params"
Expand Down Expand Up @@ -790,13 +791,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,107 +825,17 @@ 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
}
// Reflect default BlockParams.MaxBytes change to current params
cp := app.BaseApp.GetConsensusParams(ctx)
cp.Block.MaxBytes = tmtypes.DefaultBlockParams().MaxBytes
app.BaseApp.StoreConsensusParams(ctx, cp)

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

This file was deleted.

6 changes: 3 additions & 3 deletions golang/cosmos/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/rakyll/statik v0.1.7
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.6.0
github.com/spf13/viper v1.13.0
github.com/stretchr/testify v1.8.0
github.com/tendermint/tendermint v0.34.23
github.com/tendermint/tm-db v0.6.7
Expand Down Expand Up @@ -105,7 +106,6 @@ require (
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.13.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tendermint/btcd v0.1.1 // indirect
Expand Down Expand Up @@ -142,10 +142,10 @@ replace google.golang.org/grpc => google.golang.org/grpc v1.33.2

// At least until post-v0.34.14 is released with
// https://github.com/tendermint/tendermint/issue/6899 resolved.
replace github.com/tendermint/tendermint => github.com/agoric-labs/tendermint v0.34.23-alpha.agoric.3
replace github.com/tendermint/tendermint => github.com/agoric-labs/tendermint v0.34.23-alpha.agoric.4

// We need a fork of cosmos-sdk until all of the differences are merged.
replace github.com/cosmos/cosmos-sdk => github.com/agoric-labs/cosmos-sdk v0.45.11-alpha.agoric.3
replace github.com/cosmos/cosmos-sdk => github.com/agoric-labs/cosmos-sdk v0.45.11-alpha.agoric.4

replace github.com/cosmos/gaia/v7 => github.com/Agoric/ag0/v7 v7.0.2-alpha.agoric.1

Expand Down
8 changes: 4 additions & 4 deletions golang/cosmos/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20201201074141-dd0ecada1be6/go.mod h1:
github.com/adlio/schema v1.3.3 h1:oBJn8I02PyTB466pZO1UZEn1TV5XLlifBSyMrmHl/1I=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
github.com/agoric-labs/cosmos-sdk v0.45.11-alpha.agoric.3 h1:CMWOJYFHoRpKnNt2l90e5tEMy9phxkDEjQKfsCUHtgU=
github.com/agoric-labs/cosmos-sdk v0.45.11-alpha.agoric.3/go.mod h1:fdXvzy+wmYB+W+N139yb0+szbT7zAGgUjmxm5DBrjto=
github.com/agoric-labs/cosmos-sdk v0.45.11-alpha.agoric.4 h1:OU1rRq0qS+5KNe7eF7ceXPpHeXWj+JSbUpHgiQTml2E=
github.com/agoric-labs/cosmos-sdk v0.45.11-alpha.agoric.4/go.mod h1:fdXvzy+wmYB+W+N139yb0+szbT7zAGgUjmxm5DBrjto=
github.com/agoric-labs/cosmos-sdk/ics23/go v0.8.0-alpha.agoric.1 h1:2jvHI/2d+psWAZy6FQ0vXJCHUtfU3ZbbW+pQFL04arQ=
github.com/agoric-labs/cosmos-sdk/ics23/go v0.8.0-alpha.agoric.1/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg=
github.com/agoric-labs/tendermint v0.34.23-alpha.agoric.3 h1:aq6F1r3RQkKUYNeMNjRxgGn3dayvKnDK/R6gQF0WoFs=
github.com/agoric-labs/tendermint v0.34.23-alpha.agoric.3/go.mod h1:rXVrl4OYzmIa1I91av3iLv2HS0fGSiucyW9J4aMTpKI=
github.com/agoric-labs/tendermint v0.34.23-alpha.agoric.4 h1:NWqGDUk5UkkXxsEVRtCWFpMeuCtu2MyRtC0Cib7sKH8=
github.com/agoric-labs/tendermint v0.34.23-alpha.agoric.4/go.mod h1:rXVrl4OYzmIa1I91av3iLv2HS0fGSiucyW9J4aMTpKI=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
Expand Down
3 changes: 1 addition & 2 deletions golang/cosmos/x/vibc/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ type channelOpenAckEvent struct {
Event string `json:"event"` // channelOpenAck
PortID string `json:"portID"`
ChannelID string `json:"channelID"`
CounterpartyChannelID string `json:"counterpartyChannelID"`
CounterpartyVersion string `json:"counterpartyVersion"`
Counterparty channeltypes.Counterparty `json:"counterparty"`
ConnectionHops []string `json:"connectionHops"`
Expand All @@ -247,12 +246,12 @@ func (im IBCModule) OnChanOpenAck(
// returns an empty channel object that we can still use without crashing.
channel, _ := im.keeper.GetChannel(ctx, portID, channelID)

channel.Counterparty.ChannelId = counterpartyChannelID
event := channelOpenAckEvent{
Type: "IBC_EVENT",
Event: "channelOpenAck",
PortID: portID,
ChannelID: channelID,
CounterpartyChannelID: counterpartyChannelID,
CounterpartyVersion: counterpartyVersion,
Counterparty: channel.Counterparty,
ConnectionHops: channel.ConnectionHops,
Expand Down
16 changes: 1 addition & 15 deletions golang/cosmos/x/vibc/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,7 @@ func (k Keeper) ChanOpenInit(ctx sdk.Context, order channeltypes.Order, connecti
return err
}

// We need to emit a channel event to notify the relayer.
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory),
),
})
k.channelKeeper.WriteOpenInitChannel(ctx, portID, channelID, order, connectionHops, counterparty, version)
return nil
}

Expand Down Expand Up @@ -157,14 +151,6 @@ func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string) error {
if err != nil {
return err
}

// We need to emit a channel event to notify the relayer.
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory),
),
})
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion golang/cosmos/x/vibc/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ type ChannelKeeper interface {
WriteAcknowledgement(ctx sdk.Context, channelCap *capability.Capability, packet ibcexported.PacketI, acknowledgement ibcexported.Acknowledgement) error
ChanOpenInit(ctx sdk.Context, order channel.Order, connectionHops []string, portID string,
portCap *capability.Capability, counterparty channel.Counterparty, version string) (string, *capability.Capability, error)

WriteOpenInitChannel(ctx sdk.Context, portID, channelID string, order channel.Order,
connectionHops []string, counterparty channel.Counterparty, version string)
ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capability.Capability) error
TimeoutExecuted(ctx sdk.Context, channelCap *capability.Capability, packet ibcexported.PacketI) error
}
Expand Down
42 changes: 31 additions & 11 deletions golang/cosmos/x/vstorage/keeper/querier.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package keeper

import (
"strings"

abci "github.com/tendermint/tendermint/abci/types"

"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -18,14 +16,36 @@ const (
QueryChildren = "children"
)

// NewQuerier is the module level router for state queries
// getVstorageEntryPath validates that a request URL path represents a valid
// entry path with no extra data, and returns the path of that vstorage entry.
func getVstorageEntryPath(urlPathSegments []string) (string, error) {
if len(urlPathSegments) != 1 || types.ValidatePath(urlPathSegments[0]) != nil {
return "", sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid vstorage entry path")
}
return urlPathSegments[0], nil
}

// NewQuerier returns the function for handling queries routed to this module.
// It performs its own routing based on the first slash-separated URL path
// segment (e.g., URL path `/data/foo.bar` is a request for the value associated
// with vstorage path "foo.bar", and `/children/foo.bar` is a request for the
// child path segments immediately underneath vstorage path "foo.bar" which may
// be used to extend it to a vstorage path such as "foo.bar.baz").
func NewQuerier(keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
return func(ctx sdk.Context, path []string, req abci.RequestQuery) (res []byte, err error) {
switch path[0] {
return func(ctx sdk.Context, urlPathSegments []string, req abci.RequestQuery) (res []byte, err error) {
switch urlPathSegments[0] {
case QueryData:
return queryData(ctx, strings.Join(path[1:], "/"), req, keeper, legacyQuerierCdc)
entryPath, entryPathErr := getVstorageEntryPath(urlPathSegments[1:])
if entryPathErr != nil {
return nil, entryPathErr
}
return queryData(ctx, entryPath, req, keeper, legacyQuerierCdc)
case QueryChildren:
return queryChildren(ctx, strings.Join(path[1:], "/"), req, keeper, legacyQuerierCdc)
entryPath, entryPathErr := getVstorageEntryPath(urlPathSegments[1:])
if entryPathErr != nil {
return nil, entryPathErr
}
return queryChildren(ctx, entryPath, req, keeper, legacyQuerierCdc)
default:
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "unknown vstorage query endpoint")
}
Expand All @@ -36,12 +56,12 @@ func NewQuerier(keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier
func queryData(ctx sdk.Context, path string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) (res []byte, err error) {
entry := keeper.GetEntry(ctx, path)
if !entry.HasValue() {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "could not get vstorage path")
return nil, sdkerrors.Wrap(sdkerrors.ErrNotFound, "no data for vstorage path")
}

bz, err2 := codec.MarshalJSONIndent(legacyQuerierCdc, types.Data{Value: entry.StringValue()})
if err2 != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err2.Error())
bz, marshalErr := codec.MarshalJSONIndent(legacyQuerierCdc, types.Data{Value: entry.StringValue()})
if marshalErr != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, marshalErr.Error())
}

return bz, nil
Expand Down
Loading

0 comments on commit cfa7cb2

Please sign in to comment.