@agoric/cosmos 0.34.2-upgrade-16-dev-d45b478.0 → 0.34.2-upgrade-16-dev-0549112.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/app.go +2 -80
- package/app/upgrade.go +215 -0
- package/daemon/cmd/root.go +103 -44
- package/git-revision.txt +1 -1
- package/package.json +2 -2
- package/proto/agoric/swingset/genesis.proto +4 -0
- package/types/kv_entry_helpers.go +42 -0
- package/vm/core_proposals.go +22 -2
- package/x/swingset/genesis.go +82 -21
- package/x/swingset/keeper/swing_store_exports_handler.go +14 -3
- package/x/swingset/types/genesis.pb.go +78 -25
package/app/app.go
CHANGED
|
@@ -110,6 +110,8 @@ import (
|
|
|
110
110
|
|
|
111
111
|
appante "github.com/Agoric/agoric-sdk/golang/cosmos/ante"
|
|
112
112
|
agorictypes "github.com/Agoric/agoric-sdk/golang/cosmos/types"
|
|
113
|
+
|
|
114
|
+
// conv "github.com/Agoric/agoric-sdk/golang/cosmos/types/conv"
|
|
113
115
|
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
114
116
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset"
|
|
115
117
|
swingsetclient "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/client"
|
|
@@ -907,86 +909,6 @@ func NewAgoricApp(
|
|
|
907
909
|
return app
|
|
908
910
|
}
|
|
909
911
|
|
|
910
|
-
var upgradeNamesOfThisVersion = map[string]bool{
|
|
911
|
-
"agoric-upgrade-16": true,
|
|
912
|
-
"agorictest-upgrade-16": true,
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
func isFirstTimeUpgradeOfThisVersion(app *GaiaApp, ctx sdk.Context) bool {
|
|
916
|
-
for name := range upgradeNamesOfThisVersion {
|
|
917
|
-
if app.UpgradeKeeper.GetDoneHeight(ctx, name) != 0 {
|
|
918
|
-
return false
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
return true
|
|
922
|
-
}
|
|
923
|
-
|
|
924
|
-
// upgrade16Handler performs standard upgrade actions plus custom actions for upgrade-16.
|
|
925
|
-
func upgrade16Handler(app *GaiaApp, targetUpgrade string) func(sdk.Context, upgradetypes.Plan, module.VersionMap) (module.VersionMap, error) {
|
|
926
|
-
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVm module.VersionMap) (module.VersionMap, error) {
|
|
927
|
-
app.CheckControllerInited(false)
|
|
928
|
-
|
|
929
|
-
CoreProposalSteps := []vm.CoreProposalStep{}
|
|
930
|
-
|
|
931
|
-
// These CoreProposalSteps are not idempotent and should only be executed
|
|
932
|
-
// as part of the first upgrade using this handler on any given chain.
|
|
933
|
-
if isFirstTimeUpgradeOfThisVersion(app, ctx) {
|
|
934
|
-
// Each CoreProposalStep runs sequentially, and can be constructed from
|
|
935
|
-
// one or more modules executing in parallel within the step.
|
|
936
|
-
CoreProposalSteps = []vm.CoreProposalStep{
|
|
937
|
-
// Upgrade ZCF only
|
|
938
|
-
vm.CoreProposalStepForModules("@agoric/builders/scripts/vats/upgrade-zcf.js"),
|
|
939
|
-
|
|
940
|
-
// upgrade the provisioning vat
|
|
941
|
-
vm.CoreProposalStepForModules("@agoric/builders/scripts/vats/replace-provisioning.js"),
|
|
942
|
-
// Enable low-level Orchestration.
|
|
943
|
-
vm.CoreProposalStepForModules(
|
|
944
|
-
"@agoric/builders/scripts/vats/init-network.js",
|
|
945
|
-
"@agoric/builders/scripts/vats/init-localchain.js",
|
|
946
|
-
"@agoric/builders/scripts/vats/init-transfer.js",
|
|
947
|
-
),
|
|
948
|
-
// Add new vats for price feeds. The existing ones will be retired shortly.
|
|
949
|
-
vm.CoreProposalStepForModules(
|
|
950
|
-
"@agoric/builders/scripts/vats/updateAtomPriceFeed.js",
|
|
951
|
-
"@agoric/builders/scripts/vats/updateStAtomPriceFeed.js",
|
|
952
|
-
"@agoric/builders/scripts/vats/updateStOsmoPriceFeed.js",
|
|
953
|
-
"@agoric/builders/scripts/vats/updateStTiaPriceFeed.js",
|
|
954
|
-
"@agoric/builders/scripts/vats/updateStkAtomPriceFeed.js",
|
|
955
|
-
),
|
|
956
|
-
// Add new auction contract. The old one will be retired shortly.
|
|
957
|
-
vm.CoreProposalStepForModules("@agoric/builders/scripts/vats/add-auction.js"),
|
|
958
|
-
// upgrade vaultFactory.
|
|
959
|
-
vm.CoreProposalStepForModules("@agoric/builders/scripts/vats/upgradeVaults.js"),
|
|
960
|
-
// upgrade scaledPriceAuthorities.
|
|
961
|
-
vm.CoreProposalStepForModules("@agoric/builders/scripts/vats/upgradeScaledPriceAuthorities.js"),
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
app.upgradeDetails = &upgradeDetails{
|
|
966
|
-
// Record the plan to send to SwingSet
|
|
967
|
-
Plan: plan,
|
|
968
|
-
// Core proposals that should run during the upgrade block
|
|
969
|
-
// These will be merged with any coreProposals specified in the
|
|
970
|
-
// upgradeInfo field of the upgrade plan ran as subsequent steps
|
|
971
|
-
CoreProposals: vm.CoreProposalsFromSteps(CoreProposalSteps...),
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
// Always run module migrations
|
|
975
|
-
mvm, err := app.mm.RunMigrations(ctx, app.configurator, fromVm)
|
|
976
|
-
if err != nil {
|
|
977
|
-
return mvm, err
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
m := swingsetkeeper.NewMigrator(app.SwingSetKeeper)
|
|
981
|
-
err = m.MigrateParams(ctx)
|
|
982
|
-
if err != nil {
|
|
983
|
-
return mvm, err
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
return mvm, nil
|
|
987
|
-
}
|
|
988
|
-
}
|
|
989
|
-
|
|
990
912
|
// normalizeModuleAccount ensures that the given account is a module account,
|
|
991
913
|
// initializing or updating it if necessary. The account name must be listed in maccPerms.
|
|
992
914
|
func normalizeModuleAccount(ctx sdk.Context, ak authkeeper.AccountKeeper, name string) {
|
package/app/upgrade.go
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
package gaia
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"encoding/json"
|
|
5
|
+
"fmt"
|
|
6
|
+
"strings"
|
|
7
|
+
"text/template"
|
|
8
|
+
|
|
9
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
10
|
+
swingsetkeeper "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/keeper"
|
|
11
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
12
|
+
"github.com/cosmos/cosmos-sdk/types/module"
|
|
13
|
+
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
var upgradeNamesOfThisVersion = map[string]bool{
|
|
17
|
+
"agoric-upgrade-16-basic": true, // no-frills
|
|
18
|
+
"agoric-upgrade-16-a3p-integration": true,
|
|
19
|
+
"agoric-upgrade-16-main": true,
|
|
20
|
+
"agoric-upgrade-16-devnet": true,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func isFirstTimeUpgradeOfThisVersion(app *GaiaApp, ctx sdk.Context) bool {
|
|
24
|
+
for name := range upgradeNamesOfThisVersion {
|
|
25
|
+
if app.UpgradeKeeper.GetDoneHeight(ctx, name) != 0 {
|
|
26
|
+
return false
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return true
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// upgradePriceFeedCoreProposalSteps returns the core proposal steps for the
|
|
33
|
+
// price feed upgrade and associated changes to scaledPriceAuthority and
|
|
34
|
+
// vaultManager.
|
|
35
|
+
func upgradePriceFeedCoreProposalSteps(upgradeName string) ([]vm.CoreProposalStep, error) {
|
|
36
|
+
isThisUpgrade := func(expectedUpgradeName string) bool {
|
|
37
|
+
if !upgradeNamesOfThisVersion[expectedUpgradeName] {
|
|
38
|
+
panic(fmt.Errorf("invalid upgrade name: %s", expectedUpgradeName))
|
|
39
|
+
}
|
|
40
|
+
return upgradeName == expectedUpgradeName
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
t := template.Must(template.New("").Parse(`{
|
|
44
|
+
"module": "@agoric/builders/scripts/vats/priceFeedSupport.js",
|
|
45
|
+
"entrypoint": {{.entrypointJson}},
|
|
46
|
+
"args": [{
|
|
47
|
+
"AGORIC_INSTANCE_NAME": {{.instanceNameJson}},
|
|
48
|
+
"ORACLE_ADDRESSES": {{.oracleAddressesJson}},
|
|
49
|
+
"IN_BRAND_LOOKUP": {{.inBrandLookupJson}},
|
|
50
|
+
"IN_BRAND_DECIMALS": 6,
|
|
51
|
+
"OUT_BRAND_LOOKUP": ["agoricNames", "oracleBrand", "USD"],
|
|
52
|
+
"OUT_BRAND_DECIMALS": 4
|
|
53
|
+
}]
|
|
54
|
+
}`))
|
|
55
|
+
|
|
56
|
+
var oracleAddresses []string
|
|
57
|
+
|
|
58
|
+
var entrypoint string
|
|
59
|
+
switch {
|
|
60
|
+
case isThisUpgrade("agoric-upgrade-16-a3p-integration"):
|
|
61
|
+
entrypoint = "deprecatedPriceFeedProposalBuilder"
|
|
62
|
+
case isThisUpgrade("agoric-upgrade-16-main"):
|
|
63
|
+
oracleAddresses = []string{
|
|
64
|
+
"agoric144rrhh4m09mh7aaffhm6xy223ym76gve2x7y78", // DSRV
|
|
65
|
+
"agoric19d6gnr9fyp6hev4tlrg87zjrzsd5gzr5qlfq2p", // Stakin
|
|
66
|
+
"agoric19uscwxdac6cf6z7d5e26e0jm0lgwstc47cpll8", // 01node
|
|
67
|
+
"agoric1krunjcqfrf7la48zrvdfeeqtls5r00ep68mzkr", // Simply Staking
|
|
68
|
+
"agoric1n4fcxsnkxe4gj6e24naec99hzmc4pjfdccy5nj", // P2P
|
|
69
|
+
}
|
|
70
|
+
entrypoint = "strictPriceFeedProposalBuilder"
|
|
71
|
+
case isThisUpgrade("agoric-upgrade-16-devnet"):
|
|
72
|
+
oracleAddresses = []string{
|
|
73
|
+
"agoric1lw4e4aas9q84tq0q92j85rwjjjapf8dmnllnft", // DSRV
|
|
74
|
+
"agoric1zj6vrrrjq4gsyr9lw7dplv4vyejg3p8j2urm82", // Stakin
|
|
75
|
+
"agoric1ra0g6crtsy6r3qnpu7ruvm7qd4wjnznyzg5nu4", // 01node
|
|
76
|
+
"agoric1qj07c7vfk3knqdral0sej7fa6eavkdn8vd8etf", // Simply Staking
|
|
77
|
+
"agoric10vjkvkmpp9e356xeh6qqlhrny2htyzp8hf88fk", // P2P
|
|
78
|
+
}
|
|
79
|
+
entrypoint = "strictPriceFeedProposalBuilder"
|
|
80
|
+
|
|
81
|
+
// No price feed upgrade for this version.
|
|
82
|
+
case isThisUpgrade("agoric-upgrade-16-basic"):
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if entrypoint == "" {
|
|
86
|
+
return []vm.CoreProposalStep{}, nil
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
entrypointJson, err := json.Marshal(entrypoint)
|
|
90
|
+
if err != nil {
|
|
91
|
+
return nil, err
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
var inBrandNames []string
|
|
95
|
+
switch {
|
|
96
|
+
case isThisUpgrade("agoric-upgrade-16-a3p-integration"), isThisUpgrade("agoric-upgrade-16-main"):
|
|
97
|
+
inBrandNames = []string{
|
|
98
|
+
"ATOM",
|
|
99
|
+
"stATOM",
|
|
100
|
+
"stOSMO",
|
|
101
|
+
"stTIA",
|
|
102
|
+
"stkATOM",
|
|
103
|
+
}
|
|
104
|
+
case isThisUpgrade("agoric-upgrade-16-devnet"):
|
|
105
|
+
inBrandNames = []string{
|
|
106
|
+
"ATOM",
|
|
107
|
+
"stTIA",
|
|
108
|
+
"stkATOM",
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
oracleAddressesJson, err := json.Marshal(oracleAddresses)
|
|
113
|
+
if err != nil {
|
|
114
|
+
return nil, err
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
proposals := make(vm.CoreProposalStep, 0, len(inBrandNames))
|
|
118
|
+
for _, inBrandName := range inBrandNames {
|
|
119
|
+
instanceName := inBrandName + "-USD price feed"
|
|
120
|
+
instanceNameJson, err := json.Marshal(instanceName)
|
|
121
|
+
if err != nil {
|
|
122
|
+
return nil, err
|
|
123
|
+
}
|
|
124
|
+
inBrandLookup := []string{"agoricNames", "oracleBrand", inBrandName}
|
|
125
|
+
inBrandLookupJson, err := json.Marshal(inBrandLookup)
|
|
126
|
+
if err != nil {
|
|
127
|
+
return nil, err
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
var result strings.Builder
|
|
131
|
+
err = t.Execute(&result, map[string]any{
|
|
132
|
+
"entrypointJson": string(entrypointJson),
|
|
133
|
+
"inBrandLookupJson": string(inBrandLookupJson),
|
|
134
|
+
"instanceNameJson": string(instanceNameJson),
|
|
135
|
+
"oracleAddressesJson": string(oracleAddressesJson),
|
|
136
|
+
})
|
|
137
|
+
if err != nil {
|
|
138
|
+
return nil, err
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
jsonStr := result.String()
|
|
142
|
+
jsonBz := []byte(jsonStr)
|
|
143
|
+
if !json.Valid(jsonBz) {
|
|
144
|
+
return nil, fmt.Errorf("invalid JSON: %s", jsonStr)
|
|
145
|
+
}
|
|
146
|
+
proposals = append(proposals, vm.ArbitraryCoreProposal{Json: jsonBz})
|
|
147
|
+
}
|
|
148
|
+
return []vm.CoreProposalStep{
|
|
149
|
+
// Add new vats for price feeds. The existing ones will be retired shortly.
|
|
150
|
+
vm.CoreProposalStepForModules(proposals...),
|
|
151
|
+
// Add new auction contract. The old one will be retired shortly.
|
|
152
|
+
vm.CoreProposalStepForModules("@agoric/builders/scripts/vats/add-auction.js"),
|
|
153
|
+
// upgrade vaultFactory.
|
|
154
|
+
vm.CoreProposalStepForModules("@agoric/builders/scripts/vats/upgradeVaults.js"),
|
|
155
|
+
}, nil
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// upgrade16Handler performs standard upgrade actions plus custom actions for upgrade-16.
|
|
159
|
+
func upgrade16Handler(app *GaiaApp, targetUpgrade string) func(sdk.Context, upgradetypes.Plan, module.VersionMap) (module.VersionMap, error) {
|
|
160
|
+
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVm module.VersionMap) (module.VersionMap, error) {
|
|
161
|
+
app.CheckControllerInited(false)
|
|
162
|
+
|
|
163
|
+
CoreProposalSteps := []vm.CoreProposalStep{}
|
|
164
|
+
|
|
165
|
+
// These CoreProposalSteps are not idempotent and should only be executed
|
|
166
|
+
// as part of the first upgrade using this handler on any given chain.
|
|
167
|
+
if isFirstTimeUpgradeOfThisVersion(app, ctx) {
|
|
168
|
+
// Each CoreProposalStep runs sequentially, and can be constructed from
|
|
169
|
+
// one or more modules executing in parallel within the step.
|
|
170
|
+
CoreProposalSteps = []vm.CoreProposalStep{
|
|
171
|
+
// Upgrade Zoe + ZCF
|
|
172
|
+
vm.CoreProposalStepForModules("@agoric/builders/scripts/vats/replace-zoe.js"),
|
|
173
|
+
// Revive KREAd characters
|
|
174
|
+
vm.CoreProposalStepForModules("@agoric/builders/scripts/vats/revive-kread.js"),
|
|
175
|
+
|
|
176
|
+
// upgrade the provisioning vat
|
|
177
|
+
vm.CoreProposalStepForModules("@agoric/builders/scripts/vats/replace-provisioning.js"),
|
|
178
|
+
// Enable low-level Orchestration.
|
|
179
|
+
vm.CoreProposalStepForModules(
|
|
180
|
+
"@agoric/builders/scripts/vats/init-network.js",
|
|
181
|
+
"@agoric/builders/scripts/vats/init-localchain.js",
|
|
182
|
+
"@agoric/builders/scripts/vats/init-transfer.js",
|
|
183
|
+
),
|
|
184
|
+
}
|
|
185
|
+
priceFeedSteps, err := upgradePriceFeedCoreProposalSteps(targetUpgrade)
|
|
186
|
+
if err != nil {
|
|
187
|
+
return nil, err
|
|
188
|
+
}
|
|
189
|
+
CoreProposalSteps = append(CoreProposalSteps, priceFeedSteps...)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
app.upgradeDetails = &upgradeDetails{
|
|
193
|
+
// Record the plan to send to SwingSet
|
|
194
|
+
Plan: plan,
|
|
195
|
+
// Core proposals that should run during the upgrade block
|
|
196
|
+
// These will be merged with any coreProposals specified in the
|
|
197
|
+
// upgradeInfo field of the upgrade plan ran as subsequent steps
|
|
198
|
+
CoreProposals: vm.CoreProposalsFromSteps(CoreProposalSteps...),
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Always run module migrations
|
|
202
|
+
mvm, err := app.mm.RunMigrations(ctx, app.configurator, fromVm)
|
|
203
|
+
if err != nil {
|
|
204
|
+
return mvm, err
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
m := swingsetkeeper.NewMigrator(app.SwingSetKeeper)
|
|
208
|
+
err = m.MigrateParams(ctx)
|
|
209
|
+
if err != nil {
|
|
210
|
+
return mvm, err
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return mvm, nil
|
|
214
|
+
}
|
|
215
|
+
}
|
package/daemon/cmd/root.go
CHANGED
|
@@ -8,7 +8,6 @@ import (
|
|
|
8
8
|
|
|
9
9
|
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
|
|
10
10
|
|
|
11
|
-
"github.com/cosmos/cosmos-sdk/baseapp"
|
|
12
11
|
"github.com/cosmos/cosmos-sdk/client"
|
|
13
12
|
"github.com/cosmos/cosmos-sdk/client/config"
|
|
14
13
|
"github.com/cosmos/cosmos-sdk/client/debug"
|
|
@@ -19,9 +18,6 @@ import (
|
|
|
19
18
|
"github.com/cosmos/cosmos-sdk/client/snapshot"
|
|
20
19
|
"github.com/cosmos/cosmos-sdk/server"
|
|
21
20
|
servertypes "github.com/cosmos/cosmos-sdk/server/types"
|
|
22
|
-
"github.com/cosmos/cosmos-sdk/snapshots"
|
|
23
|
-
snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types"
|
|
24
|
-
"github.com/cosmos/cosmos-sdk/store"
|
|
25
21
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
26
22
|
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
|
27
23
|
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
@@ -39,6 +35,7 @@ import (
|
|
|
39
35
|
gaia "github.com/Agoric/agoric-sdk/golang/cosmos/app"
|
|
40
36
|
"github.com/Agoric/agoric-sdk/golang/cosmos/app/params"
|
|
41
37
|
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
38
|
+
swingsetkeeper "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/keeper"
|
|
42
39
|
)
|
|
43
40
|
|
|
44
41
|
var AppName = "agd"
|
|
@@ -142,16 +139,27 @@ func initRootCmd(sender vm.Sender, rootCmd *cobra.Command, encodingConfig params
|
|
|
142
139
|
testnetCmd(gaia.ModuleBasics, banktypes.GenesisBalancesIterator{}),
|
|
143
140
|
debug.Cmd(),
|
|
144
141
|
config.Cmd(),
|
|
145
|
-
pruning.Cmd(ac.
|
|
146
|
-
snapshot.Cmd(ac.
|
|
142
|
+
pruning.Cmd(ac.newSnapshotsApp, gaia.DefaultNodeHome),
|
|
143
|
+
snapshot.Cmd(ac.newSnapshotsApp),
|
|
147
144
|
)
|
|
148
145
|
|
|
149
146
|
server.AddCommands(rootCmd, gaia.DefaultNodeHome, ac.newApp, ac.appExport, addModuleInitFlags)
|
|
150
147
|
|
|
151
148
|
for _, command := range rootCmd.Commands() {
|
|
152
|
-
|
|
149
|
+
switch command.Name() {
|
|
150
|
+
case "export":
|
|
151
|
+
addAgoricVMFlags(command)
|
|
153
152
|
extendCosmosExportCommand(command)
|
|
154
|
-
|
|
153
|
+
case "snapshots":
|
|
154
|
+
for _, subCommand := range command.Commands() {
|
|
155
|
+
switch subCommand.Name() {
|
|
156
|
+
case "restore":
|
|
157
|
+
addAgoricVMFlags(subCommand)
|
|
158
|
+
case "export":
|
|
159
|
+
addAgoricVMFlags(subCommand)
|
|
160
|
+
replaceCosmosSnapshotExportCommand(subCommand, ac)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
155
163
|
}
|
|
156
164
|
}
|
|
157
165
|
|
|
@@ -264,22 +272,13 @@ func (ac appCreator) newApp(
|
|
|
264
272
|
}
|
|
265
273
|
}
|
|
266
274
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) {
|
|
270
|
-
cache = store.NewCommitKVStoreCacheManager()
|
|
271
|
-
}
|
|
275
|
+
baseappOptions := server.DefaultBaseappOptions(appOpts)
|
|
272
276
|
|
|
273
277
|
skipUpgradeHeights := make(map[int64]bool)
|
|
274
278
|
for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) {
|
|
275
279
|
skipUpgradeHeights[int64(h)] = true
|
|
276
280
|
}
|
|
277
281
|
|
|
278
|
-
pruningOpts, err := server.GetPruningOptionsFromFlags(appOpts)
|
|
279
|
-
if err != nil {
|
|
280
|
-
panic(err)
|
|
281
|
-
}
|
|
282
|
-
|
|
283
282
|
homePath := cast.ToString(appOpts.Get(flags.FlagHome))
|
|
284
283
|
|
|
285
284
|
// Set a default value for FlagSwingStoreExportDir based on the homePath
|
|
@@ -289,39 +288,41 @@ func (ac appCreator) newApp(
|
|
|
289
288
|
viper.Set(gaia.FlagSwingStoreExportDir, filepath.Join(homePath, "config", ExportedSwingStoreDirectoryName))
|
|
290
289
|
}
|
|
291
290
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
snapshotOptions := snapshottypes.NewSnapshotOptions(
|
|
302
|
-
cast.ToUint64(appOpts.Get(server.FlagStateSyncSnapshotInterval)),
|
|
303
|
-
cast.ToUint32(appOpts.Get(server.FlagStateSyncSnapshotKeepRecent)),
|
|
291
|
+
return gaia.NewAgoricApp(
|
|
292
|
+
ac.sender, ac.agdServer,
|
|
293
|
+
logger, db, traceStore, true, skipUpgradeHeights,
|
|
294
|
+
homePath,
|
|
295
|
+
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
|
|
296
|
+
ac.encCfg,
|
|
297
|
+
appOpts,
|
|
298
|
+
baseappOptions...,
|
|
304
299
|
)
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
func (ac appCreator) newSnapshotsApp(
|
|
303
|
+
logger log.Logger,
|
|
304
|
+
db dbm.DB,
|
|
305
|
+
traceStore io.Writer,
|
|
306
|
+
appOpts servertypes.AppOptions,
|
|
307
|
+
) servertypes.Application {
|
|
308
|
+
if OnExportHook != nil {
|
|
309
|
+
if err := OnExportHook(ac.agdServer, logger, appOpts); err != nil {
|
|
310
|
+
panic(err)
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
baseappOptions := server.DefaultBaseappOptions(appOpts)
|
|
315
|
+
|
|
316
|
+
homePath := cast.ToString(appOpts.Get(flags.FlagHome))
|
|
305
317
|
|
|
306
318
|
return gaia.NewAgoricApp(
|
|
307
319
|
ac.sender, ac.agdServer,
|
|
308
|
-
logger, db, traceStore, true,
|
|
320
|
+
logger, db, traceStore, true, map[int64]bool{},
|
|
309
321
|
homePath,
|
|
310
322
|
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
|
|
311
323
|
ac.encCfg,
|
|
312
324
|
appOpts,
|
|
313
|
-
|
|
314
|
-
baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))),
|
|
315
|
-
baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(server.FlagHaltHeight))),
|
|
316
|
-
baseapp.SetHaltTime(cast.ToUint64(appOpts.Get(server.FlagHaltTime))),
|
|
317
|
-
baseapp.SetMinRetainBlocks(cast.ToUint64(appOpts.Get(server.FlagMinRetainBlocks))),
|
|
318
|
-
baseapp.SetInterBlockCache(cache),
|
|
319
|
-
baseapp.SetTrace(cast.ToBool(appOpts.Get(server.FlagTrace))),
|
|
320
|
-
baseapp.SetIndexEvents(cast.ToStringSlice(appOpts.Get(server.FlagIndexEvents))),
|
|
321
|
-
baseapp.SetSnapshot(snapshotStore, snapshotOptions),
|
|
322
|
-
baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(server.FlagIAVLCacheSize))),
|
|
323
|
-
baseapp.SetIAVLDisableFastNode(cast.ToBool(appOpts.Get(server.FlagDisableIAVLFastNode))),
|
|
324
|
-
baseapp.SetIAVLLazyLoading(cast.ToBool(appOpts.Get(server.FlagIAVLLazyLoading))),
|
|
325
|
+
baseappOptions...,
|
|
325
326
|
)
|
|
326
327
|
}
|
|
327
328
|
|
|
@@ -342,7 +343,6 @@ const (
|
|
|
342
343
|
// cosmos-sdk to add a required "export-dir" command-line flag, and create the
|
|
343
344
|
// genesis export in the specified directory if the VM is running.
|
|
344
345
|
func extendCosmosExportCommand(cmd *cobra.Command) {
|
|
345
|
-
addAgoricVMFlags(cmd)
|
|
346
346
|
cmd.Flags().String(FlagExportDir, "", "The directory where to create the genesis export")
|
|
347
347
|
err := cmd.MarkFlagRequired(FlagExportDir)
|
|
348
348
|
if err != nil {
|
|
@@ -443,3 +443,62 @@ func (ac appCreator) appExport(
|
|
|
443
443
|
|
|
444
444
|
return gaiaApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs)
|
|
445
445
|
}
|
|
446
|
+
|
|
447
|
+
// replaceCosmosSnapshotExportCommand monkey-patches the "snapshots export" command
|
|
448
|
+
// added by cosmos-sdk and replaces its implementation with one suitable for
|
|
449
|
+
// our modifications to the cosmos snapshots process
|
|
450
|
+
func replaceCosmosSnapshotExportCommand(cmd *cobra.Command, ac appCreator) {
|
|
451
|
+
// Copy of RunE is cosmos-sdk/client/snapshot/export.go
|
|
452
|
+
replacedRunE := func(cmd *cobra.Command, args []string) error {
|
|
453
|
+
ctx := server.GetServerContextFromCmd(cmd)
|
|
454
|
+
|
|
455
|
+
height, err := cmd.Flags().GetInt64("height")
|
|
456
|
+
if err != nil {
|
|
457
|
+
return err
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
home := ctx.Config.RootDir
|
|
461
|
+
dataDir := filepath.Join(home, "data")
|
|
462
|
+
db, err := dbm.NewDB("application", server.GetAppDBBackend(ctx.Viper), dataDir)
|
|
463
|
+
if err != nil {
|
|
464
|
+
return err
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
app := ac.newSnapshotsApp(ctx.Logger, db, nil, ctx.Viper)
|
|
468
|
+
gaiaApp := app.(*gaia.GaiaApp)
|
|
469
|
+
|
|
470
|
+
if height == 0 {
|
|
471
|
+
height = app.CommitMultiStore().LastCommitID().Version
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
cmd.Printf("Exporting snapshot for height %d\n", height)
|
|
475
|
+
|
|
476
|
+
err = gaiaApp.SwingSetSnapshotter.InitiateSnapshot(height)
|
|
477
|
+
if err != nil {
|
|
478
|
+
return err
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
err = swingsetkeeper.WaitUntilSwingStoreExportDone()
|
|
482
|
+
if err != nil {
|
|
483
|
+
return err
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
snapshotList, err := app.SnapshotManager().List()
|
|
487
|
+
if err != nil {
|
|
488
|
+
return err
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
snapshotHeight := uint64(height)
|
|
492
|
+
|
|
493
|
+
for _, snapshot := range snapshotList {
|
|
494
|
+
if snapshot.Height == snapshotHeight {
|
|
495
|
+
cmd.Printf("Snapshot created at height %d, format %d, chunks %d\n", snapshot.Height, snapshot.Format, snapshot.Chunks)
|
|
496
|
+
break
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
return nil
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
cmd.RunE = replacedRunE
|
|
504
|
+
}
|
package/git-revision.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
0549112
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/cosmos",
|
|
3
|
-
"version": "0.34.2-upgrade-16-dev-
|
|
3
|
+
"version": "0.34.2-upgrade-16-dev-0549112.0+0549112",
|
|
4
4
|
"description": "Connect JS to the Cosmos blockchain SDK",
|
|
5
5
|
"parsers": {
|
|
6
6
|
"js": "mjs"
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"typeCoverage": {
|
|
40
40
|
"atLeast": 0
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "05491122ee61362c8310a7924ac67f033b02e38f"
|
|
43
43
|
}
|
|
@@ -17,6 +17,10 @@ message GenesisState {
|
|
|
17
17
|
repeated SwingStoreExportDataEntry swing_store_export_data = 4 [
|
|
18
18
|
(gogoproto.jsontag) = "swingStoreExportData"
|
|
19
19
|
];
|
|
20
|
+
|
|
21
|
+
string swing_store_export_data_hash = 5 [
|
|
22
|
+
(gogoproto.jsontag) = "swingStoreExportDataHash"
|
|
23
|
+
];
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
// A SwingStore "export data" entry.
|
|
@@ -232,3 +232,45 @@ func EncodeKVEntryReaderToJsonl(reader KVEntryReader, bytesWriter io.Writer) (er
|
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
|
+
|
|
236
|
+
var _ KVEntryReader = &kvHookingReader{}
|
|
237
|
+
|
|
238
|
+
// kvHookingReader is a KVEntryReader backed by another KVEntryReader which
|
|
239
|
+
// provides callbacks for read and close
|
|
240
|
+
type kvHookingReader struct {
|
|
241
|
+
reader KVEntryReader
|
|
242
|
+
onRead func(entry KVEntry) error
|
|
243
|
+
onClose func() error
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// NewKVHookingReader returns a KVEntryReader backed by another KVEntryReader
|
|
247
|
+
func NewKVHookingReader(reader KVEntryReader, onRead func(entry KVEntry) error, onClose func() error) KVEntryReader {
|
|
248
|
+
return &kvHookingReader{
|
|
249
|
+
reader,
|
|
250
|
+
onRead,
|
|
251
|
+
onClose,
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Read yields the next KVEntry from the source reader
|
|
256
|
+
// Implements KVEntryReader
|
|
257
|
+
func (hr kvHookingReader) Read() (next KVEntry, err error) {
|
|
258
|
+
next, err = hr.reader.Read()
|
|
259
|
+
|
|
260
|
+
if err == nil {
|
|
261
|
+
err = hr.onRead(next)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return next, err
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Close releases the underlying source reader
|
|
268
|
+
// Implements KVEntryReader
|
|
269
|
+
func (hr kvHookingReader) Close() error {
|
|
270
|
+
err := hr.reader.Close()
|
|
271
|
+
if err == nil {
|
|
272
|
+
err = hr.onClose()
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return err
|
|
276
|
+
}
|
package/vm/core_proposals.go
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
package vm
|
|
2
2
|
|
|
3
|
+
import (
|
|
4
|
+
"encoding/json"
|
|
5
|
+
"fmt"
|
|
6
|
+
)
|
|
7
|
+
|
|
3
8
|
// CoreProposalStep is a set of core proposal configs which are executed
|
|
4
9
|
// concurrently
|
|
5
10
|
type CoreProposalStep []Jsonable
|
|
@@ -11,12 +16,27 @@ type CoreProposals struct {
|
|
|
11
16
|
Steps []CoreProposalStep `json:"steps"`
|
|
12
17
|
}
|
|
13
18
|
|
|
19
|
+
type ArbitraryCoreProposal struct {
|
|
20
|
+
Json json.RawMessage
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func NewArbitraryCoreProposal(jsonStr string) *ArbitraryCoreProposal {
|
|
24
|
+
return &ArbitraryCoreProposal{Json: []byte(jsonStr)}
|
|
25
|
+
}
|
|
26
|
+
|
|
14
27
|
// CoreProposalStepForModules generates a single core proposal step from
|
|
15
28
|
// the given modules, which will be executed concurrently during that step
|
|
16
|
-
func CoreProposalStepForModules(modules ...
|
|
29
|
+
func CoreProposalStepForModules(modules ...Jsonable) CoreProposalStep {
|
|
17
30
|
step := make([]Jsonable, len(modules))
|
|
18
31
|
for i := range modules {
|
|
19
|
-
|
|
32
|
+
switch m := modules[i].(type) {
|
|
33
|
+
case ArbitraryCoreProposal:
|
|
34
|
+
step[i] = m.Json
|
|
35
|
+
case string:
|
|
36
|
+
step[i] = m
|
|
37
|
+
default:
|
|
38
|
+
panic(fmt.Errorf("unexpected step type %T", m))
|
|
39
|
+
}
|
|
20
40
|
}
|
|
21
41
|
return step
|
|
22
42
|
}
|
package/x/swingset/genesis.go
CHANGED
|
@@ -2,7 +2,13 @@ package swingset
|
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
4
|
// "os"
|
|
5
|
+
"bytes"
|
|
6
|
+
"crypto/sha256"
|
|
7
|
+
"encoding/hex"
|
|
8
|
+
"encoding/json"
|
|
5
9
|
"fmt"
|
|
10
|
+
"hash"
|
|
11
|
+
"strings"
|
|
6
12
|
|
|
7
13
|
agoric "github.com/Agoric/agoric-sdk/golang/cosmos/types"
|
|
8
14
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/keeper"
|
|
@@ -35,8 +41,10 @@ func InitGenesis(ctx sdk.Context, k Keeper, swingStoreExportsHandler *SwingStore
|
|
|
35
41
|
k.SetState(ctx, data.GetState())
|
|
36
42
|
|
|
37
43
|
swingStoreExportData := data.GetSwingStoreExportData()
|
|
38
|
-
if len(swingStoreExportData) == 0 {
|
|
44
|
+
if len(swingStoreExportData) == 0 && data.SwingStoreExportDataHash == "" {
|
|
39
45
|
return true
|
|
46
|
+
} else if data.SwingStoreExportDataHash != "" && len(swingStoreExportData) > 0 {
|
|
47
|
+
panic("Swingset genesis state cannot have both export data and hash of export data")
|
|
40
48
|
}
|
|
41
49
|
|
|
42
50
|
artifactProvider, err := keeper.OpenSwingStoreExportDirectory(swingStoreExportDir)
|
|
@@ -46,15 +54,62 @@ func InitGenesis(ctx sdk.Context, k Keeper, swingStoreExportsHandler *SwingStore
|
|
|
46
54
|
|
|
47
55
|
swingStore := k.GetSwingStore(ctx)
|
|
48
56
|
|
|
49
|
-
for _, entry := range swingStoreExportData {
|
|
50
|
-
swingStore.Set([]byte(entry.Key), []byte(entry.Value))
|
|
51
|
-
}
|
|
52
|
-
|
|
53
57
|
snapshotHeight := uint64(ctx.BlockHeight())
|
|
54
58
|
|
|
55
|
-
getExportDataReader
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
var getExportDataReader func() (agoric.KVEntryReader, error)
|
|
60
|
+
|
|
61
|
+
if len(swingStoreExportData) > 0 {
|
|
62
|
+
for _, entry := range swingStoreExportData {
|
|
63
|
+
swingStore.Set([]byte(entry.Key), []byte(entry.Value))
|
|
64
|
+
}
|
|
65
|
+
getExportDataReader = func() (agoric.KVEntryReader, error) {
|
|
66
|
+
exportDataIterator := swingStore.Iterator(nil, nil)
|
|
67
|
+
return agoric.NewKVIteratorReader(exportDataIterator), nil
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
hashParts := strings.SplitN(data.SwingStoreExportDataHash, ":", 2)
|
|
71
|
+
if len(hashParts) != 2 {
|
|
72
|
+
panic(fmt.Errorf("invalid swing-store export data hash %s", data.SwingStoreExportDataHash))
|
|
73
|
+
}
|
|
74
|
+
if hashParts[0] != "sha256" {
|
|
75
|
+
panic(fmt.Errorf("invalid swing-store export data hash algorithm %s, expected sha256", hashParts[0]))
|
|
76
|
+
}
|
|
77
|
+
sha256Hash, err := hex.DecodeString(hashParts[1])
|
|
78
|
+
if err != nil {
|
|
79
|
+
panic(err)
|
|
80
|
+
}
|
|
81
|
+
getExportDataReader = func() (agoric.KVEntryReader, error) {
|
|
82
|
+
kvReader, err := artifactProvider.GetExportDataReader()
|
|
83
|
+
if err != nil {
|
|
84
|
+
return nil, err
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if kvReader == nil {
|
|
88
|
+
return nil, fmt.Errorf("swing-store export has no export data")
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
hasher := sha256.New()
|
|
92
|
+
encoder := json.NewEncoder(hasher)
|
|
93
|
+
encoder.SetEscapeHTML(false)
|
|
94
|
+
|
|
95
|
+
return agoric.NewKVHookingReader(kvReader, func(entry agoric.KVEntry) error {
|
|
96
|
+
key := []byte(entry.Key())
|
|
97
|
+
|
|
98
|
+
if !entry.HasValue() {
|
|
99
|
+
swingStore.Delete(key)
|
|
100
|
+
} else {
|
|
101
|
+
swingStore.Set(key, []byte(entry.StringValue()))
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return encoder.Encode(entry)
|
|
105
|
+
}, func() error {
|
|
106
|
+
sum := hasher.Sum(nil)
|
|
107
|
+
if !bytes.Equal(sum, sha256Hash) {
|
|
108
|
+
return fmt.Errorf("swing-store data sha256sum didn't match. expected %x, got %x", sha256Hash, sum)
|
|
109
|
+
}
|
|
110
|
+
return nil
|
|
111
|
+
}), nil
|
|
112
|
+
}
|
|
58
113
|
}
|
|
59
114
|
|
|
60
115
|
err = swingStoreExportsHandler.RestoreExport(
|
|
@@ -79,25 +134,17 @@ func ExportGenesis(ctx sdk.Context, k Keeper, swingStoreExportsHandler *SwingSto
|
|
|
79
134
|
gs := &types.GenesisState{
|
|
80
135
|
Params: k.GetParams(ctx),
|
|
81
136
|
State: k.GetState(ctx),
|
|
82
|
-
SwingStoreExportData:
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
exportDataIterator := k.GetSwingStore(ctx).Iterator(nil, nil)
|
|
86
|
-
defer exportDataIterator.Close()
|
|
87
|
-
for ; exportDataIterator.Valid(); exportDataIterator.Next() {
|
|
88
|
-
entry := types.SwingStoreExportDataEntry{
|
|
89
|
-
Key: string(exportDataIterator.Key()),
|
|
90
|
-
Value: string(exportDataIterator.Value()),
|
|
91
|
-
}
|
|
92
|
-
gs.SwingStoreExportData = append(gs.SwingStoreExportData, &entry)
|
|
137
|
+
SwingStoreExportData: nil,
|
|
93
138
|
}
|
|
94
139
|
|
|
95
140
|
snapshotHeight := uint64(ctx.BlockHeight())
|
|
96
141
|
|
|
142
|
+
eventHandler := swingStoreGenesisEventHandler{exportDir: swingStoreExportDir, snapshotHeight: snapshotHeight, swingStore: k.GetSwingStore(ctx), hasher: sha256.New()}
|
|
143
|
+
|
|
97
144
|
err := swingStoreExportsHandler.InitiateExport(
|
|
98
145
|
// The export will fail if the export of a historical height was requested
|
|
99
146
|
snapshotHeight,
|
|
100
|
-
|
|
147
|
+
eventHandler,
|
|
101
148
|
keeper.SwingStoreExportOptions{
|
|
102
149
|
ArtifactMode: keeper.SwingStoreArtifactModeOperational,
|
|
103
150
|
ExportDataMode: keeper.SwingStoreExportDataModeSkip,
|
|
@@ -112,12 +159,16 @@ func ExportGenesis(ctx sdk.Context, k Keeper, swingStoreExportsHandler *SwingSto
|
|
|
112
159
|
panic(err)
|
|
113
160
|
}
|
|
114
161
|
|
|
162
|
+
gs.SwingStoreExportDataHash = fmt.Sprintf("sha256:%x", eventHandler.hasher.Sum(nil))
|
|
163
|
+
|
|
115
164
|
return gs
|
|
116
165
|
}
|
|
117
166
|
|
|
118
167
|
type swingStoreGenesisEventHandler struct {
|
|
119
168
|
exportDir string
|
|
120
169
|
snapshotHeight uint64
|
|
170
|
+
swingStore sdk.KVStore
|
|
171
|
+
hasher hash.Hash
|
|
121
172
|
}
|
|
122
173
|
|
|
123
174
|
func (eventHandler swingStoreGenesisEventHandler) OnExportStarted(height uint64, retrieveSwingStoreExport func() error) error {
|
|
@@ -131,7 +182,17 @@ func (eventHandler swingStoreGenesisEventHandler) OnExportRetrieved(provider kee
|
|
|
131
182
|
|
|
132
183
|
artifactsProvider := keeper.SwingStoreExportProvider{
|
|
133
184
|
GetExportDataReader: func() (agoric.KVEntryReader, error) {
|
|
134
|
-
|
|
185
|
+
exportDataIterator := eventHandler.swingStore.Iterator(nil, nil)
|
|
186
|
+
kvReader := agoric.NewKVIteratorReader(exportDataIterator)
|
|
187
|
+
eventHandler.hasher.Reset()
|
|
188
|
+
encoder := json.NewEncoder(eventHandler.hasher)
|
|
189
|
+
encoder.SetEscapeHTML(false)
|
|
190
|
+
|
|
191
|
+
return agoric.NewKVHookingReader(kvReader, func(entry agoric.KVEntry) error {
|
|
192
|
+
return encoder.Encode(entry)
|
|
193
|
+
}, func() error {
|
|
194
|
+
return nil
|
|
195
|
+
}), nil
|
|
135
196
|
},
|
|
136
197
|
ReadNextArtifact: provider.ReadNextArtifact,
|
|
137
198
|
}
|
|
@@ -787,7 +787,18 @@ func (exportsHandler SwingStoreExportsHandler) RestoreExport(provider SwingStore
|
|
|
787
787
|
// a jsonl-like file, before saving the export manifest linking these together.
|
|
788
788
|
// The export manifest filename and overall export format is common with the JS
|
|
789
789
|
// swing-store import/export logic.
|
|
790
|
-
func WriteSwingStoreExportToDirectory(provider SwingStoreExportProvider, exportDir string) error {
|
|
790
|
+
func WriteSwingStoreExportToDirectory(provider SwingStoreExportProvider, exportDir string) (err error) {
|
|
791
|
+
handleDeferError := func(fn func() error) {
|
|
792
|
+
deferError := fn()
|
|
793
|
+
if err == nil {
|
|
794
|
+
err = deferError
|
|
795
|
+
} else if deferError != nil {
|
|
796
|
+
// Safe to wrap error and use detailed error info since this error
|
|
797
|
+
// will not go back into swingset layers
|
|
798
|
+
err = sdkioerrors.Wrapf(err, "deferred error %+v", deferError)
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
|
|
791
802
|
manifest := exportManifest{
|
|
792
803
|
BlockHeight: provider.BlockHeight,
|
|
793
804
|
}
|
|
@@ -798,14 +809,14 @@ func WriteSwingStoreExportToDirectory(provider SwingStoreExportProvider, exportD
|
|
|
798
809
|
}
|
|
799
810
|
|
|
800
811
|
if exportDataReader != nil {
|
|
801
|
-
defer exportDataReader.Close
|
|
812
|
+
defer handleDeferError(exportDataReader.Close)
|
|
802
813
|
|
|
803
814
|
manifest.Data = exportDataFilename
|
|
804
815
|
exportDataFile, err := os.OpenFile(filepath.Join(exportDir, exportDataFilename), os.O_CREATE|os.O_WRONLY, exportedFilesMode)
|
|
805
816
|
if err != nil {
|
|
806
817
|
return err
|
|
807
818
|
}
|
|
808
|
-
defer exportDataFile.Close
|
|
819
|
+
defer handleDeferError(exportDataFile.Close)
|
|
809
820
|
|
|
810
821
|
err = agoric.EncodeKVEntryReaderToJsonl(exportDataReader, exportDataFile)
|
|
811
822
|
if err != nil {
|
|
@@ -25,9 +25,10 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
|
|
25
25
|
|
|
26
26
|
// The initial or exported state.
|
|
27
27
|
type GenesisState struct {
|
|
28
|
-
Params
|
|
29
|
-
State
|
|
30
|
-
SwingStoreExportData
|
|
28
|
+
Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"`
|
|
29
|
+
State State `protobuf:"bytes,3,opt,name=state,proto3" json:"state"`
|
|
30
|
+
SwingStoreExportData []*SwingStoreExportDataEntry `protobuf:"bytes,4,rep,name=swing_store_export_data,json=swingStoreExportData,proto3" json:"swingStoreExportData"`
|
|
31
|
+
SwingStoreExportDataHash string `protobuf:"bytes,5,opt,name=swing_store_export_data_hash,json=swingStoreExportDataHash,proto3" json:"swingStoreExportDataHash"`
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
func (m *GenesisState) Reset() { *m = GenesisState{} }
|
|
@@ -84,6 +85,13 @@ func (m *GenesisState) GetSwingStoreExportData() []*SwingStoreExportDataEntry {
|
|
|
84
85
|
return nil
|
|
85
86
|
}
|
|
86
87
|
|
|
88
|
+
func (m *GenesisState) GetSwingStoreExportDataHash() string {
|
|
89
|
+
if m != nil {
|
|
90
|
+
return m.SwingStoreExportDataHash
|
|
91
|
+
}
|
|
92
|
+
return ""
|
|
93
|
+
}
|
|
94
|
+
|
|
87
95
|
// A SwingStore "export data" entry.
|
|
88
96
|
type SwingStoreExportDataEntry struct {
|
|
89
97
|
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
|
|
@@ -145,28 +153,30 @@ func init() {
|
|
|
145
153
|
func init() { proto.RegisterFile("agoric/swingset/genesis.proto", fileDescriptor_49b057311de9d296) }
|
|
146
154
|
|
|
147
155
|
var fileDescriptor_49b057311de9d296 = []byte{
|
|
148
|
-
//
|
|
149
|
-
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74,
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
156
|
+
// 363 bytes of a gzipped FileDescriptorProto
|
|
157
|
+
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xcd, 0x4a, 0xc3, 0x40,
|
|
158
|
+
0x14, 0x85, 0x93, 0xfe, 0x41, 0xa7, 0x82, 0x12, 0x8a, 0x8d, 0xa5, 0x26, 0xa5, 0xab, 0x22, 0x98,
|
|
159
|
+
0x40, 0xc5, 0x8d, 0xae, 0x8c, 0x16, 0x5d, 0x4a, 0x8a, 0x1b, 0x11, 0xc2, 0xb4, 0x1d, 0x26, 0xa1,
|
|
160
|
+
0x6d, 0x26, 0xe4, 0x4e, 0xb5, 0xc5, 0x97, 0xf0, 0x11, 0x7c, 0x9c, 0x2e, 0xbb, 0x14, 0x17, 0x45,
|
|
161
|
+
0xda, 0x8d, 0xf4, 0x29, 0x24, 0x33, 0x2d, 0x42, 0x7f, 0x76, 0x27, 0xf9, 0xce, 0x39, 0x37, 0xdc,
|
|
162
|
+
0x1b, 0x74, 0x8a, 0x29, 0x8b, 0x83, 0x8e, 0x0d, 0x6f, 0x41, 0x48, 0x81, 0x70, 0x9b, 0x92, 0x90,
|
|
163
|
+
0x40, 0x00, 0x56, 0x14, 0x33, 0xce, 0xb4, 0x43, 0x89, 0xad, 0x35, 0x2e, 0x17, 0x29, 0xa3, 0x4c,
|
|
164
|
+
0x30, 0x3b, 0x51, 0xd2, 0x56, 0x36, 0x36, 0x5b, 0xd6, 0x42, 0xf2, 0xda, 0x77, 0x0a, 0x1d, 0xdc,
|
|
165
|
+
0xcb, 0xe2, 0x16, 0xc7, 0x9c, 0x68, 0x97, 0x28, 0x17, 0xe1, 0x18, 0x0f, 0x40, 0x4f, 0x55, 0xd5,
|
|
166
|
+
0x7a, 0xa1, 0x51, 0xb2, 0x36, 0x06, 0x59, 0x8f, 0x02, 0x3b, 0x99, 0xc9, 0xcc, 0x54, 0xdc, 0x95,
|
|
167
|
+
0x59, 0x6b, 0xa0, 0x2c, 0x24, 0x79, 0x3d, 0x2d, 0x52, 0xc7, 0x5b, 0x29, 0xd1, 0xbe, 0x0a, 0x49,
|
|
168
|
+
0xab, 0xf6, 0x8e, 0x4a, 0x02, 0x7b, 0xc0, 0x59, 0x4c, 0x3c, 0x32, 0x8a, 0x58, 0xcc, 0xbd, 0x2e,
|
|
169
|
+
0xe6, 0x58, 0xcf, 0x54, 0xd3, 0xf5, 0x42, 0xe3, 0x6c, 0xbb, 0x25, 0x11, 0xad, 0xc4, 0xde, 0x14,
|
|
170
|
+
0xee, 0x3b, 0xcc, 0x71, 0x33, 0xe4, 0xf1, 0xd8, 0xd1, 0x97, 0x33, 0xb3, 0x08, 0x3b, 0xb0, 0xbb,
|
|
171
|
+
0xf3, 0xad, 0xf6, 0x82, 0x2a, 0x7b, 0x86, 0x7b, 0x3e, 0x06, 0x5f, 0xcf, 0x56, 0xd5, 0x7a, 0xde,
|
|
172
|
+
0xa9, 0x2c, 0x67, 0xa6, 0xbe, 0x2b, 0xff, 0x80, 0xc1, 0x77, 0xf7, 0x92, 0xab, 0xcc, 0xef, 0xa7,
|
|
173
|
+
0xa9, 0xd4, 0x6e, 0xd1, 0xc9, 0xde, 0x0f, 0xd6, 0x8e, 0x50, 0xba, 0x47, 0xc6, 0xba, 0x9a, 0xcc,
|
|
174
|
+
0x71, 0x13, 0xa9, 0x15, 0x51, 0xf6, 0x15, 0xf7, 0x87, 0x44, 0x6c, 0x3e, 0xef, 0xca, 0x07, 0xe7,
|
|
175
|
+
0x69, 0x32, 0x37, 0xd4, 0xe9, 0xdc, 0x50, 0x7f, 0xe6, 0x86, 0xfa, 0xb1, 0x30, 0x94, 0xe9, 0xc2,
|
|
176
|
+
0x50, 0xbe, 0x16, 0x86, 0xf2, 0x7c, 0x4d, 0x03, 0xee, 0x0f, 0xdb, 0x56, 0x87, 0x0d, 0xec, 0x1b,
|
|
177
|
+
0x79, 0x66, 0xb9, 0xaf, 0x73, 0xe8, 0xf6, 0x6c, 0xca, 0xfa, 0x38, 0xa4, 0x76, 0x87, 0xc1, 0x80,
|
|
178
|
+
0x81, 0x3d, 0xfa, 0xff, 0x03, 0xf8, 0x38, 0x22, 0xd0, 0xce, 0x89, 0xfb, 0x5f, 0xfc, 0x05, 0x00,
|
|
179
|
+
0x00, 0xff, 0xff, 0x1b, 0x95, 0x41, 0xea, 0x67, 0x02, 0x00, 0x00,
|
|
170
180
|
}
|
|
171
181
|
|
|
172
182
|
func (m *GenesisState) Marshal() (dAtA []byte, err error) {
|
|
@@ -189,6 +199,13 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
|
|
189
199
|
_ = i
|
|
190
200
|
var l int
|
|
191
201
|
_ = l
|
|
202
|
+
if len(m.SwingStoreExportDataHash) > 0 {
|
|
203
|
+
i -= len(m.SwingStoreExportDataHash)
|
|
204
|
+
copy(dAtA[i:], m.SwingStoreExportDataHash)
|
|
205
|
+
i = encodeVarintGenesis(dAtA, i, uint64(len(m.SwingStoreExportDataHash)))
|
|
206
|
+
i--
|
|
207
|
+
dAtA[i] = 0x2a
|
|
208
|
+
}
|
|
192
209
|
if len(m.SwingStoreExportData) > 0 {
|
|
193
210
|
for iNdEx := len(m.SwingStoreExportData) - 1; iNdEx >= 0; iNdEx-- {
|
|
194
211
|
{
|
|
@@ -290,6 +307,10 @@ func (m *GenesisState) Size() (n int) {
|
|
|
290
307
|
n += 1 + l + sovGenesis(uint64(l))
|
|
291
308
|
}
|
|
292
309
|
}
|
|
310
|
+
l = len(m.SwingStoreExportDataHash)
|
|
311
|
+
if l > 0 {
|
|
312
|
+
n += 1 + l + sovGenesis(uint64(l))
|
|
313
|
+
}
|
|
293
314
|
return n
|
|
294
315
|
}
|
|
295
316
|
|
|
@@ -445,6 +466,38 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error {
|
|
|
445
466
|
return err
|
|
446
467
|
}
|
|
447
468
|
iNdEx = postIndex
|
|
469
|
+
case 5:
|
|
470
|
+
if wireType != 2 {
|
|
471
|
+
return fmt.Errorf("proto: wrong wireType = %d for field SwingStoreExportDataHash", wireType)
|
|
472
|
+
}
|
|
473
|
+
var stringLen uint64
|
|
474
|
+
for shift := uint(0); ; shift += 7 {
|
|
475
|
+
if shift >= 64 {
|
|
476
|
+
return ErrIntOverflowGenesis
|
|
477
|
+
}
|
|
478
|
+
if iNdEx >= l {
|
|
479
|
+
return io.ErrUnexpectedEOF
|
|
480
|
+
}
|
|
481
|
+
b := dAtA[iNdEx]
|
|
482
|
+
iNdEx++
|
|
483
|
+
stringLen |= uint64(b&0x7F) << shift
|
|
484
|
+
if b < 0x80 {
|
|
485
|
+
break
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
intStringLen := int(stringLen)
|
|
489
|
+
if intStringLen < 0 {
|
|
490
|
+
return ErrInvalidLengthGenesis
|
|
491
|
+
}
|
|
492
|
+
postIndex := iNdEx + intStringLen
|
|
493
|
+
if postIndex < 0 {
|
|
494
|
+
return ErrInvalidLengthGenesis
|
|
495
|
+
}
|
|
496
|
+
if postIndex > l {
|
|
497
|
+
return io.ErrUnexpectedEOF
|
|
498
|
+
}
|
|
499
|
+
m.SwingStoreExportDataHash = string(dAtA[iNdEx:postIndex])
|
|
500
|
+
iNdEx = postIndex
|
|
448
501
|
default:
|
|
449
502
|
iNdEx = preIndex
|
|
450
503
|
skippy, err := skipGenesis(dAtA[iNdEx:])
|