@agoric/cosmos 0.35.0-u17.0 → 0.35.0-u18.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/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [0.35.0-u17.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/cosmos@0.34.1...@agoric/cosmos@0.35.0-u17.0) (2024-09-17)
6
+ ## [0.35.0-u18.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/cosmos@0.34.1...@agoric/cosmos@0.35.0-u18.0) (2024-10-31)
7
7
 
8
8
 
9
9
  ### ⚠ BREAKING CHANGES
@@ -22,6 +22,8 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
22
22
  * Add consensus-independent vat transcript archiving configuration to AG_COSMOS_INIT ([d2d5803](https://github.com/Agoric/agoric-sdk/commit/d2d5803baab6e6379d179723244b2e92aac6319a)), closes [#10036](https://github.com/Agoric/agoric-sdk/issues/10036)
23
23
  * Add consensus-independent vat transcript span retention configuration to AG_COSMOS_INIT ([3cf6b57](https://github.com/Agoric/agoric-sdk/commit/3cf6b57d9e1968c6197147419d5d177b5c42e62b)), closes [#9174](https://github.com/Agoric/agoric-sdk/issues/9174) [#9386](https://github.com/Agoric/agoric-sdk/issues/9386)
24
24
  * add priceFeed for StkAtom ([6a861df](https://github.com/Agoric/agoric-sdk/commit/6a861dfa14f42b4547a24ba31175a3b1a74c97c1))
25
+ * add zoe upgrade to upgrade.go ([faaa41f](https://github.com/Agoric/agoric-sdk/commit/faaa41f293ff7b44e414e31bcdcdd4f63f4f64fe))
26
+ * added replace electorate proposal in chain upgrade ([4e88d9f](https://github.com/Agoric/agoric-sdk/commit/4e88d9f0412fe2b90efda30df0afbb61887bf35f))
25
27
  * agd vstorage 'path' for data or children ([2b56fc6](https://github.com/Agoric/agoric-sdk/commit/2b56fc66335c44b5d8ba06480841b14a6c4a83fb))
26
28
  * **agd:** try harder to find cosmic-swingset ([dd547f0](https://github.com/Agoric/agoric-sdk/commit/dd547f0a8057109a0bbe27a814fb3fc403ad3fd1))
27
29
  * **agvm:** use envvars to pass file descriptor numbers ([47b2e8c](https://github.com/Agoric/agoric-sdk/commit/47b2e8c5b2ef54118083baebd6f07cd654c32281))
@@ -46,7 +48,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
46
48
  * **cosmos:** impose defaults when sending VM actions ([a710d68](https://github.com/Agoric/agoric-sdk/commit/a710d68512cf9983bdf5230e2e99f267521c7210))
47
49
  * **cosmos:** KVEntry implements json Marshaler and Unmarshaller ([1bba859](https://github.com/Agoric/agoric-sdk/commit/1bba8592eee0e24e480c407095f0f63ccca4a242))
48
50
  * **cosmos:** make vm comms use `context.Context` ([fa1754c](https://github.com/Agoric/agoric-sdk/commit/fa1754c791ba6c848e6b94f3a75051c6b4cc69f6))
49
- * **cosmos:** Next upgrade is agoric-upgrade-17 ([ea47c4c](https://github.com/Agoric/agoric-sdk/commit/ea47c4cb05490b97533f3a3ffa1ad2081ec30223))
51
+ * **cosmos:** Next upgrade is agoric-upgrade-18 ([#10361](https://github.com/Agoric/agoric-sdk/issues/10361)) ([6ddbef0](https://github.com/Agoric/agoric-sdk/commit/6ddbef09f18c18f205e8d166c363ff4884115ce9))
50
52
  * **cosmos:** prevent VM port handlers from panicking ([afd6017](https://github.com/Agoric/agoric-sdk/commit/afd60170d453865cfa871a01e8d8a74ffef9221a))
51
53
  * **cosmos:** propagate and handle shutdown message ([ac12e6d](https://github.com/Agoric/agoric-sdk/commit/ac12e6d57b3a50e079744f7a6faced7f4bebb957))
52
54
  * **cosmos:** separate swing-store export data from genesis file ([f476bd5](https://github.com/Agoric/agoric-sdk/commit/f476bd50fb3ca5df0c4f43b20e059e05a2659b4c))
@@ -56,6 +58,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
56
58
  * **cosmos:** support snapshot export ([4386f8e](https://github.com/Agoric/agoric-sdk/commit/4386f8e67136f184b94febb5d65990a26e101cf3))
57
59
  * **cosmos:** un-wire x/crisis ([#8582](https://github.com/Agoric/agoric-sdk/issues/8582)) ([7153535](https://github.com/Agoric/agoric-sdk/commit/7153535c5c10fed309dc60f12f981c81841fdb93))
58
60
  * **cosmos:** upgrade provisioning vat ([#8901](https://github.com/Agoric/agoric-sdk/issues/8901)) ([174e37d](https://github.com/Agoric/agoric-sdk/commit/174e37d7499b372c33ecaf6e05f82f43ebfff902))
61
+ * **cosmos:** upgrade skips proposals with no variant ([4ce1372](https://github.com/Agoric/agoric-sdk/commit/4ce13721201d9a62a40352d909f97a44d8e5b25d))
59
62
  * **cosmos:** use operational artifact level for swingset state export/restore ([161ddd3](https://github.com/Agoric/agoric-sdk/commit/161ddd34ca6c16da0ad3ef716fa5da3d2ba86b68))
60
63
  * **cosmos:** wire in vlocalchain to the Cosmos app ([3ea527d](https://github.com/Agoric/agoric-sdk/commit/3ea527d9844dcf2b5f2c60d1bfb1760e064ec0f7))
61
64
  * **cosmos:** wire new swingset port handler ([ea582bf](https://github.com/Agoric/agoric-sdk/commit/ea582bf7738f82d0abe5529ee1ac9f2e117c957a))
@@ -111,6 +114,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
111
114
  * **cosmos:** correctly detect presence of Agoric VM ([c7e266e](https://github.com/Agoric/agoric-sdk/commit/c7e266e035cc454bf74e88e96959f862ece146f8))
112
115
  * **cosmos:** don't init controller before upgrade ([b4260af](https://github.com/Agoric/agoric-sdk/commit/b4260afd158c9f1c6faae8ee95019e1e7c385e5f))
113
116
  * **cosmos:** don't rerun store migrations on upgrade ([8738a9b](https://github.com/Agoric/agoric-sdk/commit/8738a9bee247096da1dc72e2d2ba9c338a0cb739))
117
+ * **cosmos:** express dependency between proposals ([3cb85b8](https://github.com/Agoric/agoric-sdk/commit/3cb85b8a67fb69adf1bb0404cd101d205e05cd20))
114
118
  * **cosmos:** make agd upgrade work ([1aa1d26](https://github.com/Agoric/agoric-sdk/commit/1aa1d26f05875c91fd47da1ad7386d8979f94b03))
115
119
  * **cosmos:** module order independent init and bootstrap ([e7f5b65](https://github.com/Agoric/agoric-sdk/commit/e7f5b658b67a18c0a13544515f61216598326265))
116
120
  * **cosmos:** no global state in `vm` ([ab02669](https://github.com/Agoric/agoric-sdk/commit/ab0266908ec9f36587d3521287808f7a30ed9207))
@@ -129,6 +133,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
129
133
  * handle hang-on-halt behavior from agoric-labs/cosmos-sdk[#305](https://github.com/Agoric/agoric-sdk/issues/305) ([a4fd510](https://github.com/Agoric/agoric-sdk/commit/a4fd51067ff86d84c084292d1f38b2ca3de639b9))
130
134
  * **network:** introduce `Finalizer` to close network ([54b9b00](https://github.com/Agoric/agoric-sdk/commit/54b9b009fff3fd3ab54f731adee97195acaa238f))
131
135
  * pick up snapshot initiation fix ([38f6c3f](https://github.com/Agoric/agoric-sdk/commit/38f6c3f8dfd4a5ee35f6e7f85bc59853cb7325d9))
136
+ * remove unesesary error checks and returns ([5f789e8](https://github.com/Agoric/agoric-sdk/commit/5f789e8ea8079f9176723ca318c6aeabb3b1ccfa))
132
137
  * unwrap account keeper for app module ([20a89f0](https://github.com/Agoric/agoric-sdk/commit/20a89f06061cae01166b1b2ca738815c58dc32ed))
133
138
  * update dependencies to fix tests ([75d6b1d](https://github.com/Agoric/agoric-sdk/commit/75d6b1dcc0d7286770679bd6d042b38fa76c4312))
134
139
  * update protobuf download and generation for ibc-go v4 ([9cdfaef](https://github.com/Agoric/agoric-sdk/commit/9cdfaefcf236711676a0f3ed6e47dbf3c6d77402))
@@ -136,6 +141,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
136
141
  * **vibc:** accommodate ibc-go v3 breaking changes ([10bcb5c](https://github.com/Agoric/agoric-sdk/commit/10bcb5cf67bad097e3d76238a333394d6e4c3122))
137
142
  * **vibc:** propagate `Relayer` account address ([739c509](https://github.com/Agoric/agoric-sdk/commit/739c5092123f72a881cea2178b99dfe473c72adc))
138
143
  * **vibc:** put extraneous `CounterpartyChannelID` in `Counterparty` struct ([76bdc3f](https://github.com/Agoric/agoric-sdk/commit/76bdc3f4ae23505cd4e4e11b8a9ce114d5f7498f))
144
+ * **vlocalchain:** refuse to use existing account ([4a05141](https://github.com/Agoric/agoric-sdk/commit/4a05141902b2d48da30de8505009f4834e031803))
139
145
  * **vlocalchain:** sdkerrors.Wrap is deprecated ([fbef641](https://github.com/Agoric/agoric-sdk/commit/fbef6411fbcae072486e0c6a8370c628d2dee646))
140
146
  * **vstorage:** Enforce path validation ([03871e8](https://github.com/Agoric/agoric-sdk/commit/03871e8429b81d8f051cef132968abf3a5590e12)), closes [#8337](https://github.com/Agoric/agoric-sdk/issues/8337)
141
147
  * **vtransfer:** implement and manually test middleware ([23e3da9](https://github.com/Agoric/agoric-sdk/commit/23e3da9b3c1e621d46d5f9b0c7896c746f9e99f3))
package/app/app.go CHANGED
@@ -655,6 +655,7 @@ func NewAgoricApp(
655
655
  keys[vlocalchain.StoreKey],
656
656
  app.BaseApp.MsgServiceRouter(),
657
657
  app.BaseApp.GRPCQueryRouter(),
658
+ app.AccountKeeper,
658
659
  )
659
660
  app.vlocalchainPort = app.AgdServer.MustRegisterPortHandler(
660
661
  "vlocalchain",
@@ -876,7 +877,7 @@ func NewAgoricApp(
876
877
  for _, name := range upgradeNamesOfThisVersion {
877
878
  app.UpgradeKeeper.SetUpgradeHandler(
878
879
  name,
879
- upgrade17Handler(app, name),
880
+ upgrade18Handler(app, name),
880
881
  )
881
882
  }
882
883
 
package/app/upgrade.go CHANGED
@@ -1,7 +1,10 @@
1
1
  package gaia
2
2
 
3
3
  import (
4
+ "encoding/json"
4
5
  "fmt"
6
+ "strings"
7
+ "text/template"
5
8
 
6
9
  "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
7
10
  swingsetkeeper "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/keeper"
@@ -11,7 +14,11 @@ import (
11
14
  )
12
15
 
13
16
  var upgradeNamesOfThisVersion = []string{
14
- "agoric-upgrade-17",
17
+ "agoric-upgrade-18-mainnet",
18
+ "agoric-upgrade-18-devnet",
19
+ "agoric-upgrade-18-emerynet",
20
+ "agoric-upgrade-18-basic",
21
+ "agoric-upgrade-18-a3p",
15
22
  }
16
23
 
17
24
  // isUpgradeNameOfThisVersion returns whether the provided plan name is a
@@ -45,7 +52,11 @@ func isPrimaryUpgradeName(name string) bool {
45
52
  return false
46
53
  }
47
54
  switch name {
48
- case validUpgradeName("agoric-upgrade-17"):
55
+ case validUpgradeName("agoric-upgrade-18-mainnet"),
56
+ validUpgradeName("agoric-upgrade-18-devnet"),
57
+ validUpgradeName("agoric-upgrade-18-emerynet"),
58
+ validUpgradeName("agoric-upgrade-18-basic"),
59
+ validUpgradeName("agoric-upgrade-18-a3p"):
49
60
  return true
50
61
  default:
51
62
  panic(fmt.Errorf("unexpected upgrade name %s", validUpgradeName(name)))
@@ -63,8 +74,87 @@ func isFirstTimeUpgradeOfThisVersion(app *GaiaApp, ctx sdk.Context) bool {
63
74
  return true
64
75
  }
65
76
 
66
- // upgrade17Handler performs standard upgrade actions plus custom actions for upgrade-17.
67
- func upgrade17Handler(app *GaiaApp, targetUpgrade string) func(sdk.Context, upgradetypes.Plan, module.VersionMap) (module.VersionMap, error) {
77
+ func buildProposalStepWithArgs(moduleName string, entrypoint string, opts map[string]any) (vm.CoreProposalStep, error) {
78
+ t := template.Must(template.New("").Parse(`{
79
+ "module": "{{.moduleName}}",
80
+ "entrypoint": "{{.entrypoint}}",
81
+ "args": [ {{.optsArg}} ]
82
+ }`))
83
+
84
+ optsArg, err := json.Marshal(opts)
85
+ if err != nil {
86
+ return nil, err
87
+ }
88
+
89
+ var result strings.Builder
90
+ err = t.Execute(&result, map[string]any{
91
+ "moduleName": moduleName,
92
+ "entrypoint": entrypoint,
93
+ "optsArg": string(optsArg),
94
+ })
95
+ if err != nil {
96
+ return nil, err
97
+ }
98
+ jsonStr := result.String()
99
+ jsonBz := []byte(jsonStr)
100
+ if !json.Valid(jsonBz) {
101
+ return nil, fmt.Errorf("invalid JSON: %s", jsonStr)
102
+ }
103
+ proposal := vm.ArbitraryCoreProposal{Json: jsonBz}
104
+ return vm.CoreProposalStepForModules(proposal), nil
105
+ }
106
+
107
+ func getVariantFromUpgradeName(upgradeName string) string {
108
+ switch upgradeName {
109
+ case "agoric-upgrade-18-mainnet":
110
+ return "MAINNET"
111
+ case "agoric-upgrade-18-devnet":
112
+ return "DEVNET"
113
+ case "agoric-upgrade-18-emerynet":
114
+ return "EMERYNET"
115
+ case "agoric-upgrade-18-basic":
116
+ return ""
117
+ case "agoric-upgrade-18-a3p":
118
+ return "A3P_INTEGRATION"
119
+ default:
120
+ return ""
121
+ }
122
+ }
123
+
124
+ func replaceElectorateCoreProposalStep(upgradeName string) (vm.CoreProposalStep, error) {
125
+ variant := getVariantFromUpgradeName(upgradeName)
126
+
127
+ if variant == "" {
128
+ return nil, nil
129
+ }
130
+
131
+ return buildProposalStepWithArgs(
132
+ "@agoric/builders/scripts/inter-protocol/replace-electorate-core.js",
133
+ "defaultProposalBuilder",
134
+ map[string]any{
135
+ "variant": variant,
136
+ },
137
+ )
138
+ }
139
+
140
+ func replacePriceFeedsCoreProposal(upgradeName string) (vm.CoreProposalStep, error) {
141
+ variant := getVariantFromUpgradeName(upgradeName)
142
+
143
+ if variant == "" {
144
+ return nil, nil
145
+ }
146
+
147
+ return buildProposalStepWithArgs(
148
+ "@agoric/builders/scripts/inter-protocol/updatePriceFeeds.js",
149
+ "defaultProposalBuilder",
150
+ map[string]any{
151
+ "variant": variant,
152
+ },
153
+ )
154
+ }
155
+
156
+ // upgrade18Handler performs standard upgrade actions plus custom actions for upgrade-18.
157
+ func upgrade18Handler(app *GaiaApp, targetUpgrade string) func(sdk.Context, upgradetypes.Plan, module.VersionMap) (module.VersionMap, error) {
68
158
  return func(ctx sdk.Context, plan upgradetypes.Plan, fromVm module.VersionMap) (module.VersionMap, error) {
69
159
  app.CheckControllerInited(false)
70
160
 
@@ -80,22 +170,45 @@ func upgrade17Handler(app *GaiaApp, targetUpgrade string) func(sdk.Context, upgr
80
170
  return module.VersionMap{}, fmt.Errorf("cannot run %s as first upgrade", plan.Name)
81
171
  }
82
172
 
173
+ replaceElectorateStep, err := replaceElectorateCoreProposalStep(targetUpgrade)
174
+ if err != nil {
175
+ return nil, err
176
+ } else if replaceElectorateStep != nil {
177
+ CoreProposalSteps = append(CoreProposalSteps, replaceElectorateStep)
178
+ }
179
+
180
+ priceFeedUpdate, err := replacePriceFeedsCoreProposal(targetUpgrade)
181
+ if err != nil {
182
+ return nil, err
183
+ } else if priceFeedUpdate != nil {
184
+ CoreProposalSteps = append(CoreProposalSteps,
185
+ priceFeedUpdate,
186
+ // The following have a dependency onto the price feed proposal
187
+ vm.CoreProposalStepForModules(
188
+ "@agoric/builders/scripts/vats/add-auction.js",
189
+ ),
190
+ vm.CoreProposalStepForModules(
191
+ "@agoric/builders/scripts/vats/upgradeVaults.js",
192
+ ),
193
+ )
194
+ }
195
+
83
196
  // Each CoreProposalStep runs sequentially, and can be constructed from
84
197
  // one or more modules executing in parallel within the step.
85
- CoreProposalSteps = []vm.CoreProposalStep{
198
+ CoreProposalSteps = append(CoreProposalSteps,
86
199
  vm.CoreProposalStepForModules(
87
- // Upgrade to new liveslots for repaired vow usage.
88
- "@agoric/builders/scripts/vats/upgrade-orch-core.js",
200
+ // Upgrade Zoe (no new ZCF needed).
201
+ "@agoric/builders/scripts/vats/upgrade-zoe.js",
89
202
  ),
203
+ // Revive KREAd characters
90
204
  vm.CoreProposalStepForModules(
91
- // Upgrade to new liveslots and support vows.
92
- "@agoric/builders/scripts/smart-wallet/build-wallet-factory2-upgrade.js",
205
+ "@agoric/builders/scripts/vats/revive-kread.js",
93
206
  ),
94
207
  vm.CoreProposalStepForModules(
95
- // Create vat-orchestration.
96
- "@agoric/builders/scripts/vats/init-orchestration.js",
208
+ // Upgrade to include a cleanup from https://github.com/Agoric/agoric-sdk/pull/10319
209
+ "@agoric/builders/scripts/smart-wallet/build-wallet-factory2-upgrade.js",
97
210
  ),
98
- }
211
+ )
99
212
  }
100
213
 
101
214
  app.upgradeDetails = &upgradeDetails{
package/cmd/agd/agvm.go CHANGED
@@ -27,9 +27,9 @@ func NewVMCommand(logger log.Logger, binary string, args []string, vmFromAgd, vm
27
27
  fdToAgd := fdFromAgd + 1
28
28
 
29
29
  // ExtraFiles begins at fd numStdFiles, so we need to compute the array.
30
- cmd.ExtraFiles = make([]*os.File, fdToAgd - numStdFiles + 1)
31
- cmd.ExtraFiles[fdFromAgd - numStdFiles] = vmFromAgd
32
- cmd.ExtraFiles[fdToAgd - numStdFiles] = vmToAgd
30
+ cmd.ExtraFiles = make([]*os.File, fdToAgd-numStdFiles+1)
31
+ cmd.ExtraFiles[fdFromAgd-numStdFiles] = vmFromAgd
32
+ cmd.ExtraFiles[fdToAgd-numStdFiles] = vmToAgd
33
33
 
34
34
  // Pass the file descriptor numbers in the environment.
35
35
  cmd.Env = append(
@@ -8,7 +8,7 @@ import (
8
8
 
9
9
  // FindBinaryNextToMe looks for binName next to the current executable.
10
10
  // It returns an absolute filename for binName, or an error.
11
- func FindBinaryNextToMe(walkUp int, path... string) (string, error) {
11
+ func FindBinaryNextToMe(walkUp int, path ...string) (string, error) {
12
12
  ex, err := os.Executable()
13
13
  if err != nil {
14
14
  return "", err
@@ -32,7 +32,7 @@ func FindBinaryNextToMe(walkUp int, path... string) (string, error) {
32
32
  if _, err = os.Stat(bin); err != nil {
33
33
  return "", err
34
34
  }
35
-
35
+
36
36
  return bin, nil
37
37
  }
38
38
 
package/git-revision.txt CHANGED
@@ -1 +1 @@
1
- 515c4c0ef
1
+ c22e72501
package/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- /* global module require */
1
+ /* eslint-env node */
2
2
  module.exports = require('bindings')('agcosmosdaemon.node');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/cosmos",
3
- "version": "0.35.0-u17.0",
3
+ "version": "0.35.0-u18.0",
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": "515c4c0efccfc91b97da30037c10fc4b076851e2"
42
+ "gitHead": "c22e7250188bbdb07bc021dffdb88af0309a7aa8"
43
43
  }
package/vm/action.go CHANGED
@@ -86,7 +86,7 @@ func PopulateAction(ctx sdk.Context, action Action) Action {
86
86
  var headerPtr *ActionHeader
87
87
  if fieldType.Type == actionHeaderType {
88
88
  headerPtr = field.Addr().Interface().(*ActionHeader)
89
- } else if fieldType.Type == reflect.PtrTo(actionHeaderType) {
89
+ } else if fieldType.Type == reflect.PointerTo(actionHeaderType) {
90
90
  if field.IsNil() {
91
91
  headerPtr = &ActionHeader{}
92
92
  } else {
package/vm/client.go CHANGED
@@ -12,8 +12,8 @@ const ReceiveMessageMethod = "agvm.ReceiveMessage"
12
12
 
13
13
  // Message is what we send to the VM.
14
14
  type Message struct {
15
- Port int
16
- Data string
15
+ Port int
16
+ Data string
17
17
  NeedsReply bool
18
18
  }
19
19
 
@@ -24,7 +24,9 @@ var _ rpc.ClientCodec = (*ClientCodec)(nil)
24
24
  // runtime and the VM in the single-process dual-runtime configuration.
25
25
  //
26
26
  // We expect to call it via the legacy API with signature:
27
- // sendToController func(needsReply bool, msg string) (string, error)
27
+ //
28
+ // sendToController func(needsReply bool, msg string) (string, error)
29
+ //
28
30
  // where msg and the returned string are JSON-encoded values.
29
31
  //
30
32
  // Note that the net/rpc framework cannot express a call that does not expect a
@@ -32,22 +34,22 @@ var _ rpc.ClientCodec = (*ClientCodec)(nil)
32
34
  // having the WriteRequest() method fabricate a Receive() call to clear the rpc
33
35
  // state.
34
36
  type ClientCodec struct {
35
- ctx context.Context
36
- send func(port, rPort int, msg string)
37
- outbound map[int]rpc.Request
38
- inbound chan *rpc.Response
39
- replies map[uint64]string
37
+ ctx context.Context
38
+ send func(port, rPort int, msg string)
39
+ outbound map[int]rpc.Request
40
+ inbound chan *rpc.Response
41
+ replies map[uint64]string
40
42
  replyToRead uint64
41
43
  }
42
44
 
43
45
  // NewClientCodec creates a new ClientCodec.
44
46
  func NewClientCodec(ctx context.Context, send func(int, int, string)) *ClientCodec {
45
47
  return &ClientCodec{
46
- ctx: ctx,
47
- send: send,
48
+ ctx: ctx,
49
+ send: send,
48
50
  outbound: make(map[int]rpc.Request),
49
- inbound: make(chan *rpc.Response),
50
- replies: make(map[uint64]string),
51
+ inbound: make(chan *rpc.Response),
52
+ replies: make(map[uint64]string),
51
53
  }
52
54
  }
53
55
 
@@ -97,7 +99,7 @@ func (cc *ClientCodec) Receive(rPort int, isError bool, data string) error {
97
99
  delete(cc.outbound, rPort)
98
100
  resp := &rpc.Response{
99
101
  ServiceMethod: outb.ServiceMethod,
100
- Seq: outb.Seq,
102
+ Seq: outb.Seq,
101
103
  }
102
104
  if isError {
103
105
  resp.Error = data
@@ -7,7 +7,7 @@ const (
7
7
  // StoreKey to be used when creating the KVStore
8
8
  StoreKey = ModuleName
9
9
 
10
- ReservePoolName = "vbank/reserve"
11
- GiveawayPoolName = "vbank/giveaway"
12
- ProvisionPoolName = "vbank/provision"
10
+ ReservePoolName = "vbank/reserve"
11
+ GiveawayPoolName = "vbank/giveaway"
12
+ ProvisionPoolName = "vbank/provision"
13
13
  )
package/x/vbank/vbank.go CHANGED
@@ -144,11 +144,9 @@ func (ch portHandler) Receive(cctx context.Context, str string) (ret string, err
144
144
  }
145
145
  coin := keeper.GetBalance(ctx, addr, msg.Denom)
146
146
  packet := coin.Amount.String()
147
+ bytes, err := json.Marshal(&packet)
147
148
  if err == nil {
148
- bytes, err := json.Marshal(&packet)
149
- if err == nil {
150
- ret = string(bytes)
151
- }
149
+ ret = string(bytes)
152
150
  }
153
151
 
154
152
  case "VBANK_GRAB":
@@ -216,9 +214,6 @@ func (ch portHandler) Receive(cctx context.Context, str string) (ret string, err
216
214
  if err := keeper.StoreRewardCoins(ctx, coins); err != nil {
217
215
  return "", fmt.Errorf("cannot store reward %s coins: %s", coins.Sort().String(), err)
218
216
  }
219
- if err != nil {
220
- return "", err
221
- }
222
217
  state := keeper.GetState(ctx)
223
218
  state.RewardPool = state.RewardPool.Add(coins...)
224
219
  keeper.SetState(ctx, state)
@@ -28,6 +28,7 @@ type Keeper struct {
28
28
  cdc codec.Codec
29
29
  msgRouter types.MsgRouter
30
30
  queryRouter types.GRPCQueryRouter
31
+ acctKeeper types.AccountKeeper
31
32
  }
32
33
 
33
34
  // NewKeeper creates a new dIBC Keeper instance
@@ -36,12 +37,14 @@ func NewKeeper(
36
37
  key storetypes.StoreKey,
37
38
  msgRouter types.MsgRouter,
38
39
  queryRouter types.GRPCQueryRouter,
40
+ acctKeeper types.AccountKeeper,
39
41
  ) Keeper {
40
42
  return Keeper{
41
43
  key: key,
42
44
  cdc: cdc,
43
45
  msgRouter: msgRouter,
44
46
  queryRouter: queryRouter,
47
+ acctKeeper: acctKeeper,
45
48
  }
46
49
  }
47
50
 
@@ -266,14 +269,27 @@ func (k Keeper) AllocateAddress(cctx context.Context) sdk.AccAddress {
266
269
  localchainModuleAcc := sdkaddress.Module(types.ModuleName, []byte("localchain"))
267
270
  header := ctx.BlockHeader()
268
271
 
269
- // Increment our sequence number.
270
- seq := store.Get(types.KeyLastSequence)
271
- seq = types.NextSequence(seq)
272
- store.Set(types.KeyLastSequence, seq)
272
+ // Loop until we find an unused address.
273
+ for {
274
+ // Increment our sequence number.
275
+ seq := store.Get(types.KeyLastSequence)
276
+ seq = types.NextSequence(seq)
277
+ store.Set(types.KeyLastSequence, seq)
273
278
 
274
- buf := seq
275
- buf = append(buf, header.AppHash...)
276
- buf = append(buf, header.DataHash...)
279
+ buf := seq
280
+ buf = append(buf, header.AppHash...)
281
+ buf = append(buf, header.DataHash...)
277
282
 
278
- return sdkaddress.Derive(localchainModuleAcc, buf)
283
+ addr := sdkaddress.Derive(localchainModuleAcc, buf)
284
+ if k.acctKeeper.HasAccount(ctx, addr) {
285
+ continue
286
+ }
287
+
288
+ // We found an unused address, so create an account for it.
289
+ acct := k.acctKeeper.NewAccountWithAddress(ctx, addr)
290
+ k.acctKeeper.SetAccount(ctx, acct)
291
+
292
+ // All good, return the address.
293
+ return addr
294
+ }
279
295
  }
@@ -10,7 +10,6 @@ import (
10
10
  banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
11
11
  )
12
12
 
13
-
14
13
  func TestKeeper_ParseRequestTypeURL(t *testing.T) {
15
14
  testCases := []struct {
16
15
  name string
@@ -46,7 +45,7 @@ func TestKeeper_DeserializeTxMessages(t *testing.T) {
46
45
 
47
46
  banktypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
48
47
 
49
- keeper := NewKeeper(cdc, nil, nil, nil)
48
+ keeper := NewKeeper(cdc, nil, nil, nil, nil)
50
49
 
51
50
  expectedMsgSend := []sdk.Msg{
52
51
  &banktypes.MsgSend{
@@ -63,22 +62,22 @@ func TestKeeper_DeserializeTxMessages(t *testing.T) {
63
62
  wantErr bool
64
63
  }{
65
64
  {
66
- name: "camelCase keys",
67
- json: `{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","fromAddress":"cosmos1abc","toAddress":"cosmos1xyz","amount":[{"denom":"stake","amount":"100"}]}]}`,
65
+ name: "camelCase keys",
66
+ json: `{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","fromAddress":"cosmos1abc","toAddress":"cosmos1xyz","amount":[{"denom":"stake","amount":"100"}]}]}`,
68
67
  expected: expectedMsgSend,
69
- wantErr: false,
68
+ wantErr: false,
70
69
  },
71
70
  {
72
- name: "snake_case keys",
73
- json: `{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","from_address":"cosmos1abc","to_address":"cosmos1xyz","amount":[{"denom":"stake","amount":"100"}]}]}`,
71
+ name: "snake_case keys",
72
+ json: `{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","from_address":"cosmos1abc","to_address":"cosmos1xyz","amount":[{"denom":"stake","amount":"100"}]}]}`,
74
73
  expected: expectedMsgSend,
75
- wantErr: false,
74
+ wantErr: false,
76
75
  },
77
76
  {
78
- name: "misspelled key",
79
- json: `{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","from_addresss":"cosmos1abc","to_address":"cosmos1xyz","amount":[{"denom":"stake","amount":"100"}]}]}`,
77
+ name: "misspelled key",
78
+ json: `{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","from_addresss":"cosmos1abc","to_address":"cosmos1xyz","amount":[{"denom":"stake","amount":"100"}]}]}`,
80
79
  expected: expectedMsgSend,
81
- wantErr: true,
80
+ wantErr: true,
82
81
  },
83
82
  }
84
83
 
@@ -0,0 +1,12 @@
1
+ package types
2
+
3
+ import (
4
+ sdk "github.com/cosmos/cosmos-sdk/types"
5
+ authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
6
+ )
7
+
8
+ type AccountKeeper interface {
9
+ NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI
10
+ HasAccount(ctx sdk.Context, addr sdk.AccAddress) bool
11
+ SetAccount(ctx sdk.Context, acc authtypes.AccountI)
12
+ }
@@ -16,6 +16,7 @@ import (
16
16
  "github.com/cosmos/cosmos-sdk/store"
17
17
  storetypes "github.com/cosmos/cosmos-sdk/store/types"
18
18
  sdk "github.com/cosmos/cosmos-sdk/types"
19
+ authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
19
20
  banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
20
21
  stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
21
22
  transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types"
@@ -36,6 +37,25 @@ const (
36
37
  msgAllocateAddress = `{"type":"VLOCALCHAIN_ALLOCATE_ADDRESS"}`
37
38
  )
38
39
 
40
+ type mockAccounts struct {
41
+ existing map[string]bool
42
+ }
43
+
44
+ var _ types.AccountKeeper = (*mockAccounts)(nil)
45
+
46
+ func (a *mockAccounts) NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI {
47
+ return authtypes.NewBaseAccountWithAddress(addr)
48
+ }
49
+
50
+ func (a *mockAccounts) HasAccount(ctx sdk.Context, addr sdk.AccAddress) bool {
51
+ existing := a.existing[addr.String()]
52
+ return existing
53
+ }
54
+
55
+ func (a *mockAccounts) SetAccount(ctx sdk.Context, acc authtypes.AccountI) {
56
+ a.existing[acc.GetAddress().String()] = true
57
+ }
58
+
39
59
  type mockBank struct {
40
60
  banktypes.UnimplementedQueryServer
41
61
  banktypes.UnimplementedMsgServer
@@ -108,7 +128,7 @@ func (s *mockStaking) UnbondingDelegation(cctx context.Context, req *stakingtype
108
128
  }
109
129
 
110
130
  // makeTestKit creates a minimal Keeper and Context for use in testing.
111
- func makeTestKit(bank *mockBank, transfer *mockTransfer, staking *mockStaking) (vm.PortHandler, context.Context) {
131
+ func makeTestKit(bank *mockBank, transfer *mockTransfer, staking *mockStaking, accts *mockAccounts) (vm.PortHandler, context.Context) {
112
132
  encodingConfig := params.MakeEncodingConfig()
113
133
  cdc := encodingConfig.Marshaler
114
134
 
@@ -127,9 +147,8 @@ func makeTestKit(bank *mockBank, transfer *mockTransfer, staking *mockStaking) (
127
147
  stakingtypes.RegisterMsgServer(txRouter, staking)
128
148
  stakingtypes.RegisterQueryServer(queryRouter, staking)
129
149
 
130
-
131
150
  // create a new Keeper
132
- keeper := vlocalchain.NewKeeper(cdc, vlocalchainStoreKey, txRouter, queryRouter)
151
+ keeper := vlocalchain.NewKeeper(cdc, vlocalchainStoreKey, txRouter, queryRouter, accts)
133
152
 
134
153
  db := dbm.NewMemDB()
135
154
  ms := store.NewCommitMultiStore(db)
@@ -153,13 +172,15 @@ func TestAllocateAddress(t *testing.T) {
153
172
  bank := &mockBank{}
154
173
  transfer := &mockTransfer{}
155
174
  staking := &mockStaking{}
156
- handler, cctx := makeTestKit(bank, transfer, staking)
175
+ acct := &mockAccounts{existing: map[string]bool{
176
+ firstAddr: true,
177
+ "cosmos1c5hplwyxk5jr2dsygjqepzfqvfukwduq9c4660aah76krf99m6gs0k7hvl": true,
178
+ }}
179
+ handler, cctx := makeTestKit(bank, transfer, staking, acct)
157
180
 
158
181
  addrs := map[string]bool{
159
- firstAddr: false,
160
182
  "cosmos1yj40fakym8kf4wvgz9tky7k9f3v9msm3t7frscrmkjsdkxkpsfkqgeczkg": false,
161
183
  "cosmos1s76vryj7m8k8nm9le65a4plhf5rym5sumtt2n0vwnk5l6k4cwuhsj56ujj": false,
162
- "cosmos1c5hplwyxk5jr2dsygjqepzfqvfukwduq9c4660aah76krf99m6gs0k7hvl": false,
163
184
  "cosmos1ys3a7mtna3cad0wxcs4ddukn37stexjdvns8jfdn4uerlr95y4xqnrypf6": false,
164
185
  }
165
186
  numToTest := len(addrs)
@@ -185,6 +206,9 @@ func TestAllocateAddress(t *testing.T) {
185
206
  t.Fatalf("unexpected duplicate address[%d]: %v", i, addr)
186
207
  }
187
208
  addrs[addr] = true
209
+ if !acct.existing[addr] {
210
+ t.Fatalf("expected address[%d]: %v to be added to accounts", i, addr)
211
+ }
188
212
  }
189
213
  }
190
214
 
@@ -197,7 +221,8 @@ func TestQuery(t *testing.T) {
197
221
  }}
198
222
  transfer := &mockTransfer{}
199
223
  staking := &mockStaking{}
200
- handler, cctx := makeTestKit(bank, transfer, staking)
224
+ accts := &mockAccounts{existing: map[string]bool{}}
225
+ handler, cctx := makeTestKit(bank, transfer, staking, accts)
201
226
 
202
227
  // get balances
203
228
  testCases := []struct {
@@ -338,7 +363,8 @@ func TestExecuteTx(t *testing.T) {
338
363
  }}
339
364
  transfer := &mockTransfer{}
340
365
  staking := &mockStaking{}
341
- handler, cctx := makeTestKit(bank, transfer, staking)
366
+ accts := &mockAccounts{existing: map[string]bool{}}
367
+ handler, cctx := makeTestKit(bank, transfer, staking, accts)
342
368
 
343
369
  // create a new message
344
370
  msg := `{"type":"VLOCALCHAIN_ALLOCATE_ADDRESS"}`
@@ -426,7 +452,7 @@ func TestExecuteTx(t *testing.T) {
426
452
  if len(resp) != 1 {
427
453
  t.Fatalf("expected 1 response, got %d", len(resp))
428
454
  }
429
-
455
+
430
456
  if _, ok := resp[0]["completionTime"]; !ok {
431
457
  t.Error("expected 'completionTime' field in response")
432
458
  }