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

fix: represent storage in same order in genesis state #4147

Merged
merged 1 commit into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion golang/cosmos/proto/agoric/swingset/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ option go_package = "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types
message GenesisState {
option (gogoproto.equal) = false;

map<string, string> storage = 1 [
repeated StorageEntry storage = 1 [
(gogoproto.jsontag) = "storage",
(gogoproto.moretags) = "yaml:\"storage\""
];

Params params = 2 [(gogoproto.nullable) = false];
}

// A storage entry.
message StorageEntry {
string key = 1;
string value = 2;
}
9 changes: 4 additions & 5 deletions golang/cosmos/x/swingset/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func NewGenesisState() *types.GenesisState {
return &types.GenesisState{
Storage: make(map[string]string),
Storage: []*types.StorageEntry{},
}
}

Expand All @@ -31,7 +31,7 @@ func ValidateGenesis(data *types.GenesisState) error {
func DefaultGenesisState() *types.GenesisState {
return &types.GenesisState{
Params: types.DefaultParams(),
Storage: make(map[string]string),
Storage: []*types.StorageEntry{},
}
}

Expand All @@ -44,9 +44,8 @@ type bootstrapBlockAction struct {
func InitGenesis(ctx sdk.Context, keeper Keeper, data *types.GenesisState) []abci.ValidatorUpdate {
keeper.SetParams(ctx, data.GetParams())

// NONDETERMINISM: order of SetStorage is not deterministic
for key, value := range data.Storage {
keeper.SetStorage(ctx, key, value)
for _, entry := range data.Storage {
keeper.SetStorage(ctx, entry.Key, entry.Value)
}

// Just run the SwingSet kernel to finish bootstrap and get ready to open for
Expand Down
7 changes: 4 additions & 3 deletions golang/cosmos/x/swingset/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,18 @@ func (k Keeper) SetEgress(ctx sdk.Context, egress *types.Egress) error {
}

// ExportStorage fetches all storage
func (k Keeper) ExportStorage(ctx sdk.Context) map[string]string {
func (k Keeper) ExportStorage(ctx sdk.Context) []*types.StorageEntry {
store := ctx.KVStore(k.storeKey)
dataStore := prefix.NewStore(store, types.DataPrefix)

iterator := sdk.KVStorePrefixIterator(dataStore, nil)

exported := make(map[string]string)
exported := []*types.StorageEntry{}
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
keyStr := keyToString(iterator.Key())
exported[keyStr] = string(iterator.Value())
entry := types.StorageEntry{Key: keyStr, Value: string(iterator.Value())}
exported = append(exported, &entry)
}
return exported
}
Expand Down
Loading