@agoric/cosmos 0.34.2-dev-3573f79.0 → 0.34.2-dev-fed2b5e.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 +41 -23
- package/git-revision.txt +1 -1
- package/package.json +2 -2
- package/proto/agoric/swingset/genesis.proto +10 -0
- package/types/kv_entry.go +114 -0
- package/types/kv_entry_helpers.go +234 -0
- package/types/kv_entry_helpers_test.go +237 -0
- package/types/kv_entry_test.go +143 -0
- package/x/swingset/genesis.go +30 -8
- package/x/swingset/keeper/extension_snapshotter.go +25 -37
- package/x/swingset/keeper/extension_snapshotter_test.go +0 -2
- package/x/swingset/keeper/keeper.go +14 -9
- package/x/swingset/keeper/keeper_test.go +77 -0
- package/x/swingset/keeper/querier.go +1 -1
- package/x/swingset/keeper/swing_store_exports_handler.go +23 -44
- package/x/swingset/keeper/swing_store_exports_handler_test.go +1 -1
- package/x/swingset/swingset.go +71 -0
- package/x/swingset/types/genesis.pb.go +308 -18
- package/x/vstorage/keeper/grpc_query.go +1 -1
- package/x/vstorage/keeper/keeper.go +19 -19
- package/x/vstorage/keeper/keeper_grpc_test.go +3 -2
- package/x/vstorage/keeper/keeper_test.go +21 -20
- package/x/vstorage/keeper/querier.go +1 -1
- package/x/vstorage/types/types.go +0 -66
- package/x/vstorage/vstorage.go +19 -22
- package/x/vstorage/vstorage_test.go +14 -14
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
package keeper
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
+
"fmt"
|
|
5
|
+
"reflect"
|
|
4
6
|
"testing"
|
|
5
7
|
|
|
6
8
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
|
|
9
|
+
"github.com/cosmos/cosmos-sdk/store"
|
|
10
|
+
prefixstore "github.com/cosmos/cosmos-sdk/store/prefix"
|
|
11
|
+
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
|
7
12
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
13
|
+
|
|
14
|
+
dbm "github.com/tendermint/tm-db"
|
|
8
15
|
)
|
|
9
16
|
|
|
10
17
|
func mkcoin(denom string) func(amt int64) sdk.Coin {
|
|
@@ -181,3 +188,73 @@ func Test_calculateFees(t *testing.T) {
|
|
|
181
188
|
})
|
|
182
189
|
}
|
|
183
190
|
}
|
|
191
|
+
|
|
192
|
+
var (
|
|
193
|
+
swingsetStoreKey = storetypes.NewKVStoreKey(types.StoreKey)
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
func makeTestStore() sdk.KVStore {
|
|
197
|
+
db := dbm.NewMemDB()
|
|
198
|
+
ms := store.NewCommitMultiStore(db)
|
|
199
|
+
ms.MountStoreWithDB(swingsetStoreKey, sdk.StoreTypeIAVL, db)
|
|
200
|
+
err := ms.LoadLatestVersion()
|
|
201
|
+
if err != nil {
|
|
202
|
+
panic(err)
|
|
203
|
+
}
|
|
204
|
+
kvStore := ms.GetKVStore(swingsetStoreKey)
|
|
205
|
+
prefixStore := prefixstore.NewStore(kvStore, []byte("swingStore."))
|
|
206
|
+
return prefixStore
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
func TestSwingStore(t *testing.T) {
|
|
210
|
+
store := makeTestStore()
|
|
211
|
+
|
|
212
|
+
// Test that we can store and retrieve a value.
|
|
213
|
+
store.Set([]byte("someKey"), []byte("someValue"))
|
|
214
|
+
if got := string(store.Get([]byte("someKey"))); got != "someValue" {
|
|
215
|
+
t.Errorf("got %q, want %q", got, "someValue")
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Test that we can update and retrieve an updated value.
|
|
219
|
+
store.Set([]byte("someKey"), []byte("someNewValue"))
|
|
220
|
+
if got := string(store.Get([]byte("someKey"))); got != "someNewValue" {
|
|
221
|
+
t.Errorf("got %q, want %q", got, "someNewValue")
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Test that we can store and retrieve empty values
|
|
225
|
+
store.Set([]byte("someEmptyKey"), []byte(""))
|
|
226
|
+
if got := store.Get([]byte("someEmptyKey")); got == nil || string(got) != "" {
|
|
227
|
+
t.Errorf("got %#v, want empty string", got)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Test that we can store and delete values.
|
|
231
|
+
store.Set([]byte("someOtherKey"), []byte("someOtherValue"))
|
|
232
|
+
store.Delete([]byte("someOtherKey"))
|
|
233
|
+
if store.Has([]byte("someOtherKey")) {
|
|
234
|
+
t.Errorf("has value, expected not")
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Test that we can delete non existing keys (e.g. delete twice)
|
|
238
|
+
store.Delete([]byte("someMissingKey"))
|
|
239
|
+
|
|
240
|
+
// Check the iterated values
|
|
241
|
+
expectedEntries := [][2]string{
|
|
242
|
+
{"someEmptyKey", "[]byte{}"},
|
|
243
|
+
{"someKey", "[]byte{0x73, 0x6f, 0x6d, 0x65, 0x4e, 0x65, 0x77, 0x56, 0x61, 0x6c, 0x75, 0x65}"},
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
iter := store.Iterator(nil, nil)
|
|
247
|
+
gotEntries := [][2]string{}
|
|
248
|
+
for ; iter.Valid(); iter.Next() {
|
|
249
|
+
entry := [2]string{
|
|
250
|
+
string(iter.Key()),
|
|
251
|
+
fmt.Sprintf("%#v", iter.Value()),
|
|
252
|
+
}
|
|
253
|
+
gotEntries = append(gotEntries, entry)
|
|
254
|
+
}
|
|
255
|
+
iter.Close()
|
|
256
|
+
|
|
257
|
+
if !reflect.DeepEqual(gotEntries, expectedEntries) {
|
|
258
|
+
t.Errorf("got export %q, want %q", gotEntries, expectedEntries)
|
|
259
|
+
}
|
|
260
|
+
}
|
|
@@ -80,7 +80,7 @@ func queryMailbox(ctx sdk.Context, path []string, req abci.RequestQuery, keeper
|
|
|
80
80
|
// nolint: unparam
|
|
81
81
|
func legacyQueryStorage(ctx sdk.Context, path string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) (res []byte, err error) {
|
|
82
82
|
entry := keeper.vstorageKeeper.GetEntry(ctx, path)
|
|
83
|
-
if !entry.
|
|
83
|
+
if !entry.HasValue() {
|
|
84
84
|
return []byte{}, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "could not get swingset %+v", path)
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -9,9 +9,9 @@ import (
|
|
|
9
9
|
"path/filepath"
|
|
10
10
|
"regexp"
|
|
11
11
|
|
|
12
|
+
agoric "github.com/Agoric/agoric-sdk/golang/cosmos/types"
|
|
12
13
|
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
13
14
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
|
|
14
|
-
vstoragetypes "github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/types"
|
|
15
15
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
16
16
|
"github.com/tendermint/tendermint/libs/log"
|
|
17
17
|
)
|
|
@@ -177,8 +177,8 @@ type SwingStoreExportOptions struct {
|
|
|
177
177
|
// packages/swing-store/src/swingStore.js makeSwingStoreExporter
|
|
178
178
|
ExportMode string `json:"exportMode,omitempty"`
|
|
179
179
|
// A flag indicating whether "export data" should be part of the swing-store export
|
|
180
|
-
// If false, the resulting SwingStoreExportProvider's
|
|
181
|
-
// return
|
|
180
|
+
// If false, the resulting SwingStoreExportProvider's GetExportDataReader
|
|
181
|
+
// will return nil
|
|
182
182
|
IncludeExportData bool `json:"includeExportData,omitempty"`
|
|
183
183
|
}
|
|
184
184
|
|
|
@@ -364,11 +364,12 @@ func checkNotActive() error {
|
|
|
364
364
|
type SwingStoreExportProvider struct {
|
|
365
365
|
// BlockHeight is the block height of the SwingStore export.
|
|
366
366
|
BlockHeight uint64
|
|
367
|
-
//
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
//
|
|
371
|
-
|
|
367
|
+
// GetExportDataReader returns a KVEntryReader for the "export data" of the
|
|
368
|
+
// SwingStore export, or nil if the "export data" is not part of this export.
|
|
369
|
+
GetExportDataReader func() (agoric.KVEntryReader, error)
|
|
370
|
+
// ReadNextArtifact is a function to return the next unread artifact in the SwingStore export.
|
|
371
|
+
// It errors with io.EOF upon reaching the end of the list of available artifacts.
|
|
372
|
+
ReadNextArtifact func() (types.SwingStoreArtifact, error)
|
|
372
373
|
}
|
|
373
374
|
|
|
374
375
|
// SwingStoreExportEventHandler is used to handle events that occur while generating
|
|
@@ -615,41 +616,22 @@ func (exportsHandler SwingStoreExportsHandler) retrieveExport(onExportRetrieved
|
|
|
615
616
|
return fmt.Errorf("export manifest blockHeight (%d) doesn't match (%d)", manifest.BlockHeight, blockHeight)
|
|
616
617
|
}
|
|
617
618
|
|
|
618
|
-
|
|
619
|
-
entries := []*vstoragetypes.DataEntry{}
|
|
619
|
+
getExportDataReader := func() (agoric.KVEntryReader, error) {
|
|
620
620
|
if manifest.Data == "" {
|
|
621
|
-
return
|
|
621
|
+
return nil, nil
|
|
622
622
|
}
|
|
623
623
|
|
|
624
624
|
dataFile, err := os.Open(filepath.Join(exportDir, manifest.Data))
|
|
625
625
|
if err != nil {
|
|
626
626
|
return nil, err
|
|
627
627
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
decoder := json.NewDecoder(dataFile)
|
|
631
|
-
for {
|
|
632
|
-
var jsonEntry []string
|
|
633
|
-
err = decoder.Decode(&jsonEntry)
|
|
634
|
-
if err == io.EOF {
|
|
635
|
-
break
|
|
636
|
-
} else if err != nil {
|
|
637
|
-
return nil, err
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
if len(jsonEntry) != 2 {
|
|
641
|
-
return nil, fmt.Errorf("invalid export data entry (length %d)", len(jsonEntry))
|
|
642
|
-
}
|
|
643
|
-
entry := vstoragetypes.DataEntry{Path: jsonEntry[0], Value: jsonEntry[1]}
|
|
644
|
-
entries = append(entries, &entry)
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
return entries, nil
|
|
628
|
+
exportDataReader := agoric.NewJsonlKVEntryDecoderReader(dataFile)
|
|
629
|
+
return exportDataReader, nil
|
|
648
630
|
}
|
|
649
631
|
|
|
650
632
|
nextArtifact := 0
|
|
651
633
|
|
|
652
|
-
|
|
634
|
+
readNextArtifact := func() (artifact types.SwingStoreArtifact, err error) {
|
|
653
635
|
if nextArtifact == len(manifest.Artifacts) {
|
|
654
636
|
return artifact, io.EOF
|
|
655
637
|
} else if nextArtifact > len(manifest.Artifacts) {
|
|
@@ -670,7 +652,7 @@ func (exportsHandler SwingStoreExportsHandler) retrieveExport(onExportRetrieved
|
|
|
670
652
|
return artifact, err
|
|
671
653
|
}
|
|
672
654
|
|
|
673
|
-
err = onExportRetrieved(SwingStoreExportProvider{BlockHeight: manifest.BlockHeight,
|
|
655
|
+
err = onExportRetrieved(SwingStoreExportProvider{BlockHeight: manifest.BlockHeight, GetExportDataReader: getExportDataReader, ReadNextArtifact: readNextArtifact})
|
|
674
656
|
if err != nil {
|
|
675
657
|
return err
|
|
676
658
|
}
|
|
@@ -724,12 +706,14 @@ func (exportsHandler SwingStoreExportsHandler) RestoreExport(provider SwingStore
|
|
|
724
706
|
BlockHeight: blockHeight,
|
|
725
707
|
}
|
|
726
708
|
|
|
727
|
-
|
|
709
|
+
exportDataReader, err := provider.GetExportDataReader()
|
|
728
710
|
if err != nil {
|
|
729
711
|
return err
|
|
730
712
|
}
|
|
731
713
|
|
|
732
|
-
if
|
|
714
|
+
if exportDataReader != nil {
|
|
715
|
+
defer exportDataReader.Close()
|
|
716
|
+
|
|
733
717
|
manifest.Data = exportDataFilename
|
|
734
718
|
exportDataFile, err := os.OpenFile(filepath.Join(exportDir, exportDataFilename), os.O_CREATE|os.O_WRONLY, exportedFilesMode)
|
|
735
719
|
if err != nil {
|
|
@@ -737,14 +721,9 @@ func (exportsHandler SwingStoreExportsHandler) RestoreExport(provider SwingStore
|
|
|
737
721
|
}
|
|
738
722
|
defer exportDataFile.Close()
|
|
739
723
|
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
entry := []string{dataEntry.Path, dataEntry.Value}
|
|
744
|
-
err := encoder.Encode(entry)
|
|
745
|
-
if err != nil {
|
|
746
|
-
return err
|
|
747
|
-
}
|
|
724
|
+
err = agoric.EncodeKVEntryReaderToJsonl(exportDataReader, exportDataFile)
|
|
725
|
+
if err != nil {
|
|
726
|
+
return err
|
|
748
727
|
}
|
|
749
728
|
|
|
750
729
|
err = exportDataFile.Sync()
|
|
@@ -758,7 +737,7 @@ func (exportsHandler SwingStoreExportsHandler) RestoreExport(provider SwingStore
|
|
|
758
737
|
}
|
|
759
738
|
|
|
760
739
|
for {
|
|
761
|
-
artifact, err := provider.
|
|
740
|
+
artifact, err := provider.ReadNextArtifact()
|
|
762
741
|
if err == io.EOF {
|
|
763
742
|
break
|
|
764
743
|
} else if err != nil {
|
|
@@ -31,7 +31,7 @@ func newTestSwingStoreEventHandler() testSwingStoreEventHandler {
|
|
|
31
31
|
},
|
|
32
32
|
onExportRetrieved: func(provider SwingStoreExportProvider) error {
|
|
33
33
|
for {
|
|
34
|
-
_, err := provider.
|
|
34
|
+
_, err := provider.ReadNextArtifact()
|
|
35
35
|
if err == io.EOF {
|
|
36
36
|
return nil
|
|
37
37
|
} else if err != nil {
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
package swingset
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"encoding/json"
|
|
5
|
+
"fmt"
|
|
6
|
+
"io"
|
|
7
|
+
|
|
8
|
+
agoric "github.com/Agoric/agoric-sdk/golang/cosmos/types"
|
|
9
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
10
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
// portHandler implements vm.PortHandler
|
|
14
|
+
// for processing inbound messages from Swingset.
|
|
15
|
+
type portHandler struct {
|
|
16
|
+
keeper Keeper
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type swingsetMessage struct {
|
|
20
|
+
Method string `json:"method"`
|
|
21
|
+
Args []json.RawMessage `json:"args"`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const (
|
|
25
|
+
SwingStoreUpdateExportData = "swingStoreUpdateExportData"
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
// NewPortHandler returns a port handler for a swingset Keeper.
|
|
29
|
+
func NewPortHandler(k Keeper) vm.PortHandler {
|
|
30
|
+
return portHandler{keeper: k}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Receive implements the vm.PortHandler method.
|
|
34
|
+
// It receives and processes an inbound message, returning the
|
|
35
|
+
// JSON-serialized response or an error.
|
|
36
|
+
func (ph portHandler) Receive(ctx *vm.ControllerContext, str string) (string, error) {
|
|
37
|
+
var msg swingsetMessage
|
|
38
|
+
err := json.Unmarshal([]byte(str), &msg)
|
|
39
|
+
if err != nil {
|
|
40
|
+
return "", err
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
switch msg.Method {
|
|
44
|
+
case SwingStoreUpdateExportData:
|
|
45
|
+
return ph.handleSwingStoreUpdateExportData(ctx.Context, msg.Args)
|
|
46
|
+
|
|
47
|
+
default:
|
|
48
|
+
return "", fmt.Errorf("unrecognized swingset method %s", msg.Method)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
func (ph portHandler) handleSwingStoreUpdateExportData(ctx sdk.Context, entries []json.RawMessage) (ret string, err error) {
|
|
53
|
+
store := ph.keeper.GetSwingStore(ctx)
|
|
54
|
+
exportDataReader := agoric.NewJsonRawMessageKVEntriesReader(entries)
|
|
55
|
+
defer exportDataReader.Close()
|
|
56
|
+
for {
|
|
57
|
+
entry, err := exportDataReader.Read()
|
|
58
|
+
if err == io.EOF {
|
|
59
|
+
return "true", nil
|
|
60
|
+
} else if err != nil {
|
|
61
|
+
return ret, err
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
key := []byte(entry.Key())
|
|
65
|
+
if !entry.HasValue() {
|
|
66
|
+
store.Delete(key)
|
|
67
|
+
} else {
|
|
68
|
+
store.Set(key, []byte(entry.StringValue()))
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|