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: Support state-sync #7225

Merged
merged 20 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
970a53f
feat(cosmic-swingset): add after-commit action
mhofman Feb 12, 2023
37858cb
fix(cosmic-swingset): remove unused saved blockTime
mhofman Mar 8, 2023
be68431
feat(cosmic-swingset): export swingStore kvData to vstorage
mhofman Feb 10, 2023
5dcc44d
feat(cosmic-swingset): remove unnecessary explicit activityhash
mhofman Mar 11, 2023
726e188
feat(vstorage): Export sub tree
mhofman Feb 11, 2023
b1072d8
feat(cosmic-swingset): basic snapshot wiring
mhofman Feb 12, 2023
30340fb
Revert "fix: disable state-sync by default, until we've implemented it"
mhofman Feb 17, 2023
c5410dd
fix(cosmic-swingset): shutdown controller on exit
mhofman Feb 24, 2023
df304d5
feat(cosmic-swingset): add kernel-db exporter
mhofman Feb 16, 2023
22bc1d5
feat(cosmic-swingset): wire snapshot taking in chain-main
mhofman Feb 19, 2023
05e2b15
feat(cosmic-swingset): execute export in a subprocess
mhofman Mar 7, 2023
a2dabd1
feat(cosmic-swingset): explicit verbose option for export db
mhofman Mar 10, 2023
4cc25f5
feat(cosmic-proto): add state-sync artifacts proto
mhofman Feb 24, 2023
7b0d99e
feat(cosmos): wire swingset SnapshotExtension
mhofman Feb 24, 2023
00fab12
feat(cosmic-swingset): add kernel-db importer
mhofman Mar 8, 2023
c94e49d
feat(cosmos): wire swingset RestoreExtension
mhofman Mar 8, 2023
9d053b7
feat(cosmic-swingset): wire snapshot restoring in chain-main
mhofman Mar 8, 2023
2faa1fb
feat(deployment): Enable state-sync on validator nodes
mhofman Mar 14, 2023
27b97c1
feat(ci): Use state-sync in deployment loadgen test
mhofman Mar 14, 2023
283fded
feat(cosmos): Export KVData as artifact
mhofman Feb 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ replace google.golang.org/grpc => google.golang.org/grpc v1.33.2
replace github.com/tendermint/tendermint => github.com/agoric-labs/tendermint v0.34.23-alpha.agoric.3

// 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.1.0.20230320225042-2109765fd835
replace github.com/cosmos/cosmos-sdk => github.com/agoric-labs/cosmos-sdk v0.45.11-alpha.agoric.1.0.20230323035240-8551678e04db

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

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ 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.1.0.20230320225042-2109765fd835 h1:Mmw52cHAUNwtaNXpk7b3lTeoCRd5Vw9Fdrly5ABIxCA=
github.com/agoric-labs/cosmos-sdk v0.45.11-alpha.agoric.1.0.20230320225042-2109765fd835/go.mod h1:fdXvzy+wmYB+W+N139yb0+szbT7zAGgUjmxm5DBrjto=
github.com/agoric-labs/cosmos-sdk v0.45.11-alpha.agoric.1.0.20230323035240-8551678e04db h1:FwZL+MsLF3sLqawUJI3etRSqrxxPEvqdrWqTEQTO18Y=
github.com/agoric-labs/cosmos-sdk v0.45.11-alpha.agoric.1.0.20230323035240-8551678e04db/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=
Expand Down
50 changes: 43 additions & 7 deletions golang/cosmos/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ import (
"github.com/Agoric/agoric-sdk/golang/cosmos/x/lien"
"github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset"
swingsetclient "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/client"
swingsetkeeper "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/keeper"
swingsettypes "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vbank"
vbanktypes "github.com/Agoric/agoric-sdk/golang/cosmos/x/vbank/types"
Expand Down Expand Up @@ -227,11 +228,12 @@ type GaiaApp struct { // nolint: golint
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper

SwingSetKeeper swingset.Keeper
VstorageKeeper vstorage.Keeper
VibcKeeper vibc.Keeper
VbankKeeper vbank.Keeper
LienKeeper lien.Keeper
SwingSetKeeper swingset.Keeper
SwingSetSnapshotter swingset.Snapshotter
VstorageKeeper vstorage.Keeper
VibcKeeper vibc.Keeper
VbankKeeper vbank.Keeper
LienKeeper lien.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -447,6 +449,12 @@ func NewAgoricApp(
callToController,
)

app.SwingSetSnapshotter = swingsetkeeper.NewSwingsetSnapshotter(
bApp,
app.SwingSetKeeper,
sendToController,
)

app.VibcKeeper = vibc.NewKeeper(
appCodec, keys[vibc.StoreKey],
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
Expand Down Expand Up @@ -753,6 +761,12 @@ func NewAgoricApp(
app.ScopedVibcKeeper = scopedVibcKeeper
app.ScopedTransferKeeper = scopedTransferKeeper
app.ScopedICAHostKeeper = scopedICAHostKeeper
snapshotManager := app.SnapshotManager()
if snapshotManager != nil {
if err = snapshotManager.RegisterExtensions(&app.SwingSetSnapshotter); err != nil {
panic(fmt.Errorf("failed to register snapshot extension: %s", err))
}
}

return app
}
Expand Down Expand Up @@ -847,12 +861,34 @@ func (app *GaiaApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci

// Commit tells the controller that the block is commited
func (app *GaiaApp) Commit() abci.ResponseCommit {
err := app.SwingSetSnapshotter.WaitUntilSnapshotStarted()

if err != nil {
app.Logger().Error("swingset snapshot failed to start", "err", err)
}

// Frontrun the BaseApp's Commit method
err := swingset.CommitBlock(app.SwingSetKeeper)
err = swingset.CommitBlock(app.SwingSetKeeper)
if err != nil {
panic(err.Error())
}
return app.BaseApp.Commit()

res, snapshotHeight := app.BaseApp.CommitWithoutSnapshot()

err = swingset.AfterCommitBlock(app.SwingSetKeeper)
if err != nil {
panic(err.Error())
}

if snapshotHeight > 0 {
err = app.SwingSetSnapshotter.InitiateSnapshot(snapshotHeight)

if err != nil {
app.Logger().Error("failed to initiate swingset snapshot", "err", err)
}
}

return res
}

// LoadHeight loads a particular height
Expand Down
21 changes: 8 additions & 13 deletions golang/cosmos/daemon/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,14 @@ func (ac appCreator) newApp(
panic(err)
}

// FIXME: Actually use the snapshotStore once we have a way to put SwingSet
// state into it.
var snapshotStore *snapshots.Store
if false {
snapshotDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", "snapshots")
snapshotDB, err := sdk.NewLevelDB("metadata", snapshotDir)
if err != nil {
panic(err)
}
snapshotStore, err = snapshots.NewStore(snapshotDB, snapshotDir)
if err != nil {
panic(err)
}
snapshotDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", "snapshots")
snapshotDB, err := sdk.NewLevelDB("metadata", snapshotDir)
if err != nil {
panic(err)
}
snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir)
if err != nil {
panic(err)
}

return gaia.NewAgoricApp(
Expand Down
14 changes: 14 additions & 0 deletions golang/cosmos/proto/agoric/swingset/swingset.proto
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,17 @@ message Egress {
(gogoproto.moretags) = "yaml:\"powerFlags\""
];
}

// The payload messages used by swingset state-sync
message ExtensionSnapshotterArtifactPayload {
option (gogoproto.equal) = false;
string name = 1 [
(gogoproto.jsontag) = "name",
(gogoproto.moretags) = "yaml:\"name\""
];

bytes data = 2 [
(gogoproto.jsontag) = "data",
(gogoproto.moretags) = "yaml:\"data\""
];
}
20 changes: 19 additions & 1 deletion golang/cosmos/x/swingset/abci.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package swingset

import (
// "fmt"
// "os"
"fmt"
"time"

"github.com/cosmos/cosmos-sdk/telemetry"
Expand Down Expand Up @@ -101,3 +101,21 @@ func CommitBlock(keeper Keeper) error {
}
return err
}

func AfterCommitBlock(keeper Keeper) error {
// defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), "commit_blocker")

action := &commitBlockAction{
Type: "AFTER_COMMIT_BLOCK",
BlockHeight: endBlockHeight,
BlockTime: endBlockTime,
}
_, err := keeper.BlockingSend(sdk.Context{}, action)

// fmt.Fprintf(os.Stderr, "AFTER_COMMIT_BLOCK Returned from SwingSet: %s, %v\n", out, err)
if err != nil {
// Panic here, in the hopes that a replay from scratch will fix the problem.
panic(fmt.Errorf("AFTER_COMMIT_BLOCK failed: %w. Swingset is in an irrecoverable inconsistent state", err))
}
return err
}
1 change: 1 addition & 0 deletions golang/cosmos/x/swingset/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (

type (
Keeper = keeper.Keeper
Snapshotter = keeper.SwingsetSnapshotter
Egress = types.Egress
MsgDeliverInbound = types.MsgDeliverInbound
MsgProvision = types.MsgProvision
Expand Down
18 changes: 11 additions & 7 deletions golang/cosmos/x/swingset/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import (
// Top-level paths for chain storage should remain synchronized with
// packages/internal/src/chain-storage-paths.js
const (
StoragePathActionQueue = "actionQueue"
StoragePathActivityhash = "activityhash"
StoragePathBeansOwing = "beansOwing"
StoragePathEgress = "egress"
StoragePathMailbox = "mailbox"
StoragePathCustom = "published"
StoragePathBundles = "bundles"
StoragePathActionQueue = "actionQueue"
StoragePathBeansOwing = "beansOwing"
StoragePathEgress = "egress"
StoragePathMailbox = "mailbox"
StoragePathCustom = "published"
StoragePathBundles = "bundles"
StoragePathSwingStore = "swingStore"
)

// 2 ** 256 - 1
Expand Down Expand Up @@ -443,6 +443,10 @@ func (k Keeper) SetMailbox(ctx sdk.Context, peer string, mailbox string) {
k.vstorageKeeper.LegacySetStorageAndNotify(ctx, vstoragetypes.NewStorageEntry(path, mailbox))
}

func (k Keeper) ExportSwingStore(ctx sdk.Context) []*vstoragetypes.DataEntry {
return k.vstorageKeeper.ExportStorageFromPrefix(ctx, StoragePathSwingStore)
}

func (k Keeper) PathToEncodedKey(path string) []byte {
return k.vstorageKeeper.PathToEncodedKey(path)
}
Expand Down
Loading