@@ -13,31 +13,15 @@ import (
13
13
storetypes "cosmossdk.io/store/types"
14
14
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
15
15
sdk "github.com/cosmos/cosmos-sdk/types"
16
- protoio "github.com/cosmos/gogoproto/io"
17
16
"github.com/scrtlabs/SecretNetwork/x/compute/internal/types"
18
17
)
19
18
20
19
/*
21
20
API to implement:
22
21
23
- // Snapshotter is something that can create and restore snapshots, consisting of streamed binary
24
- // chunks - all of which must be read from the channel and closed. If an unsupported format is
25
- // given, it must return ErrUnknownFormat (possibly wrapped with fmt.Errorf).
26
- type Snapshotter interface {
27
- // Snapshot writes snapshot items into the protobuf writer.
28
- Snapshot(height uint64, protoWriter protoio.Writer) error
29
-
30
- // Restore restores a state snapshot from the protobuf items read from the reader.
31
- // If the ready channel is non-nil, it returns a ready signal (by being closed) once the
32
- // restorer is ready to accept chunks.
33
- Restore(height uint64, format uint32, protoReader protoio.Reader) (SnapshotItem, error)
34
- }
35
-
36
22
// ExtensionSnapshotter is an extension Snapshotter that is appended to the snapshot stream.
37
23
// ExtensionSnapshotter has an unique name and manages it's own internal formats.
38
24
type ExtensionSnapshotter interface {
39
- Snapshotter
40
-
41
25
// SnapshotName returns the name of snapshotter, it should be unique in the manager.
42
26
SnapshotName() string
43
27
@@ -48,6 +32,13 @@ type ExtensionSnapshotter interface {
48
32
49
33
// SupportedFormats returns a list of formats it can restore from.
50
34
SupportedFormats() []uint32
35
+
36
+ // SnapshotExtension writes extension payloads into the underlying protobuf stream.
37
+ SnapshotExtension(height uint64, payloadWriter ExtensionPayloadWriter) error
38
+
39
+ // RestoreExtension restores an extension state snapshot,
40
+ // the payload reader returns `io.EOF` when reached the extension boundaries.
41
+ RestoreExtension(height uint64, format uint32, payloadReader ExtensionPayloadReader) error
51
42
}
52
43
*/
53
44
@@ -81,7 +72,7 @@ func (ws *WasmSnapshotter) SupportedFormats() []uint32 {
81
72
return []uint32 {1 }
82
73
}
83
74
84
- func (ws * WasmSnapshotter ) Snapshot (height uint64 , protoWriter protoio. Writer ) error {
75
+ func (ws * WasmSnapshotter ) SnapshotExtension (height uint64 , payloadWriter snapshottypes. ExtensionPayloadWriter ) error {
85
76
// TODO: This seems more correct (historical info), but kills my tests
86
77
// Since codeIDs and wasm are immutible, it is never wrong to return new wasm data than the
87
78
// user requests
@@ -113,7 +104,7 @@ func (ws *WasmSnapshotter) Snapshot(height uint64, protoWriter protoio.Writer) e
113
104
return true
114
105
}
115
106
116
- err = snapshottypes . WriteExtensionPayload ( protoWriter , wasmBytes )
107
+ err = payloadWriter ( wasmBytes )
117
108
if err != nil {
118
109
rerr = err
119
110
return true
@@ -125,54 +116,28 @@ func (ws *WasmSnapshotter) Snapshot(height uint64, protoWriter protoio.Writer) e
125
116
return rerr
126
117
}
127
118
128
- func (ws * WasmSnapshotter ) Restore (
129
- height uint64 , format uint32 , protoReader protoio. Reader , //nolint:all
130
- ) (snapshottypes. SnapshotItem , error ) {
119
+ func (ws * WasmSnapshotter ) RestoreExtension (
120
+ height uint64 , format uint32 , payloadReader snapshottypes. ExtensionPayloadReader , //nolint:all
121
+ ) error {
131
122
if format != 1 {
132
- return snapshottypes.SnapshotItem {}, snapshottypes . ErrUnknownFormat
123
+ return snapshottypes .ErrUnknownFormat
133
124
}
134
125
135
126
for {
136
- item := snapshottypes.SnapshotItem {}
137
- err := protoReader .ReadMsg (& item )
127
+ wasmBytes , err := payloadReader ()
138
128
if err == io .EOF {
139
- return snapshottypes. SnapshotItem {}, nil
129
+ return nil
140
130
} else if err != nil {
141
- return snapshottypes.SnapshotItem {}, errorsmod .Wrap (err , "invalid protobuf message" )
142
- }
143
-
144
- // if it is not another ExtensionPayload message, then it is not for us.
145
- // we should return it an let the manager handle this one
146
- payload := item .GetExtensionPayload ()
147
- if payload == nil {
148
- return item , nil
131
+ return errorsmod .Wrap (err , "invalid protobuf message" )
149
132
}
150
133
151
- wasmBytes := payload .Payload
152
-
153
134
codeHash := sha256 .Sum256 (wasmBytes )
154
135
wasmFileName := hex .EncodeToString (codeHash [:])
155
136
wasmFilePath := filepath .Join (ws .wasmDirectory , wasmFileName )
156
137
157
138
err = os .WriteFile (wasmFilePath , wasmBytes , 0o600 /* -rw------- */ )
158
139
if err != nil {
159
- return snapshottypes. SnapshotItem {}, errorsmod .Wrapf (err , "failed to write wasm file '%v' to disk" , wasmFilePath )
140
+ return errorsmod .Wrapf (err , "failed to write wasm file '%v' to disk" , wasmFilePath )
160
141
}
161
142
}
162
143
}
163
-
164
- func (ws * WasmSnapshotter ) PruneSnapshotHeight (_ int64 ) {
165
- panic ("not implemented" )
166
- }
167
-
168
- func (ws * WasmSnapshotter ) SetSnapshotInterval (_ uint64 ) {
169
- panic ("not implemented" )
170
- }
171
-
172
- func (ws * WasmSnapshotter ) RestoreExtension (_ uint64 , _ uint32 , _ snapshottypes.ExtensionPayloadReader ) error {
173
- panic ("not implemented" )
174
- }
175
-
176
- func (ws * WasmSnapshotter ) SnapshotExtension (_ uint64 , _ snapshottypes.ExtensionPayloadWriter ) error {
177
- panic ("not implemented" )
178
- }
0 commit comments