Skip to content

Commit 42024a6

Browse files
committed
wip
1 parent 6dcbe8c commit 42024a6

File tree

6 files changed

+33
-33
lines changed

6 files changed

+33
-33
lines changed

golang/cosmos/proto/agoric/swingset/msgs.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ message MsgSendChunkResponse {
187187
(gogoproto.jsontag) = "chunk",
188188
(gogoproto.moretags) = "yaml:\"chunk\""
189189
];
190+
// If this chunk completed the installation, this is the response from the chain.
190191
MsgInstallBundleResponse install_response = 3 [
191192
(gogoproto.jsontag) = "install_response",
192193
(gogoproto.moretags) = "yaml:\"install_response\""

golang/cosmos/proto/agoric/swingset/swingset.proto

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,23 +218,18 @@ message SwingStoreArtifact {
218218
];
219219
}
220220

221+
// FIXME: mhofman: ChunkedArtifact?
221222
// BundleChunks is the manifest for a chunked InstallBundle.
222223
message BundleChunks {
223-
// The hash of the complete bundle.
224-
string bundle_hash = 1 [
225-
(gogoproto.jsontag) = "bundle_hash",
226-
(gogoproto.moretags) = "yaml:\"bundle_hash\""
227-
];
228-
229-
// The size of the final bundle artifact in bytes.
230-
uint64 bundle_size = 2 [
231-
(gogoproto.jsontag) = "bundle_size",
232-
(gogoproto.moretags) = "yaml:\"bundle_size\""
224+
// The size of the final artifact in bytes.
225+
uint64 total_size = 1 [
226+
(gogoproto.jsontag) = "total_size",
227+
(gogoproto.moretags) = "yaml:\"total_size\""
233228
];
234229

235230
// Information about the chunks that will be concatenated to form this
236231
// bundle.
237-
repeated ChunkInfo chunks = 3 [
232+
repeated ChunkInfo chunks = 2 [
238233
(gogoproto.jsontag) = "chunks",
239234
(gogoproto.moretags) = "yaml:\"chunks\""
240235
];

golang/cosmos/x/swingset/abci.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ type afterCommitBlockAction struct {
3535
func BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock, keeper Keeper) error {
3636
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)
3737

38-
keeper.PruneExpiredBundleInstalls(ctx)
39-
4038
action := beginBlockAction{
4139
ChainID: ctx.ChainID(),
4240
Params: keeper.GetParams(ctx),
@@ -68,6 +66,9 @@ func EndBlock(ctx sdk.Context, req abci.RequestEndBlock, keeper Keeper) ([]abci.
6866
panic(err)
6967
}
7068

69+
// Remove expired bundle installs.
70+
keeper.PruneExpiredBundleInstalls(ctx)
71+
7172
// Save our EndBlock status.
7273
endBlockHeight = ctx.BlockHeight()
7374
endBlockTime = ctx.BlockTime().Unix()

golang/cosmos/x/swingset/keeper/msg_server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ func (keeper msgServer) InstallBundle(goCtx context.Context, msg *types.MsgInsta
203203
bc.Chunks = make([]*types.ChunkInfo, len(bc.Chunks))
204204
for i, chunk := range bc.Chunks {
205205
ci := *chunk
206+
if ci.State != types.ChunkState_CHUNK_STATE_UNSPECIFIED {
207+
return nil, fmt.Errorf("chunk %d state is not unspecified for pending Id %d", i, msg.PendingId)
208+
}
206209
ci.State = types.ChunkState_CHUNK_STATE_IN_FLIGHT
207210
bc.Chunks[i] = &ci
208211
}

golang/cosmos/x/swingset/types/msgs.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ type InboundQueueRecord struct {
5959
}
6060

6161
const (
62-
// bundleUncompressedSizeLimit is the (exclusive) limit on uncompressed bundle size.
62+
// BundleUncompressedSizeLimit is the (exclusive) limit on uncompressed bundle size.
6363
// We must ensure there is an exclusive int64 limit in order to detect an underflow.
64-
bundleUncompressedSizeLimit uint64 = 10 * 1024 * 1024 // 10MB
65-
chunkSizeLimit uint64 = 512 * 1024 // 512KB
66-
chunkIndexLimit uint64 = (bundleUncompressedSizeLimit + chunkSizeLimit - 1) / chunkSizeLimit
67-
hashLimit int = 128
64+
BundleUncompressedSizeLimit uint64 = 10 * 1024 * 1024 // 10MB
65+
ChunkSizeLimit uint64 = 512 * 1024 // 512KB
66+
ChunkIndexLimit uint64 = (BundleUncompressedSizeLimit + ChunkSizeLimit - 1) / ChunkSizeLimit
67+
HashSize int = 256 / 8 * 2
6868
)
6969

7070
// Charge an account address for the beans associated with given messages and storage.
@@ -441,7 +441,7 @@ func (msg MsgInstallBundle) ValidateBasic() error {
441441
return sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, "Uncompressed size must be set with a compressed bundle")
442442
case msg.UncompressedSize != 0 && hasBundle:
443443
return sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, "Uncompressed size cannot be set with a legacy bundle")
444-
case uint64(msg.UncompressedSize) >= bundleUncompressedSizeLimit:
444+
case uint64(msg.UncompressedSize) >= BundleUncompressedSizeLimit:
445445
// must enforce a limit to avoid overflow when computing its successor in Uncompress()
446446
return sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, "Uncompressed size out of range")
447447
}
@@ -523,26 +523,26 @@ func (bc BundleChunks) ValidateBasic() error {
523523
if len(bc.Chunks) == 0 {
524524
return sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, "Bundle chunks cannot be empty")
525525
}
526-
if uint64(len(bc.Chunks)) >= chunkIndexLimit {
527-
return sdkioerrors.Wrapf(sdkerrors.ErrUnknownRequest, "Number of bundle chunks must be less than %d", chunkIndexLimit)
526+
if uint64(len(bc.Chunks)) >= ChunkIndexLimit {
527+
return sdkioerrors.Wrapf(sdkerrors.ErrUnknownRequest, "Number of bundle chunks must be less than %d", ChunkIndexLimit)
528528
}
529-
if len(bc.BundleHash) > hashLimit {
530-
return sdkioerrors.Wrapf(sdkerrors.ErrUnknownRequest, "Bundle hash must not exceed %d characters", hashLimit)
529+
if len(bc.BundleHash) != HashSize {
530+
return sdkioerrors.Wrapf(sdkerrors.ErrUnknownRequest, "Bundle hash must be %d characters", HashSize)
531531
}
532532
if !IsHexBytes(bc.BundleHash) {
533533
return sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, "Bundle hash must be a hex byte string")
534534
}
535-
if bc.BundleSize <= 0 || bc.BundleSize >= bundleUncompressedSizeLimit {
535+
if bc.BundleSize <= 0 || bc.BundleSize >= BundleUncompressedSizeLimit {
536536
return sdkioerrors.Wrapf(sdkerrors.ErrUnknownRequest, "Bundle size out of range")
537537
}
538538
totalChunkSize := uint64(0)
539539
for i, chunk := range bc.Chunks {
540-
if chunk.ChunkSize <= 0 || chunk.ChunkSize >= chunkSizeLimit {
540+
if chunk.ChunkSize <= 0 || chunk.ChunkSize >= ChunkSizeLimit {
541541
return sdkioerrors.Wrapf(sdkerrors.ErrUnknownRequest, "Chunk %d size out of range", i)
542542
}
543543
totalChunkSize += chunk.ChunkSize
544-
if len(chunk.Hash) > hashLimit {
545-
return sdkioerrors.Wrapf(sdkerrors.ErrUnknownRequest, "Chunk %d hash must not exceed %d characters", i, hashLimit)
544+
if len(chunk.Hash) != HashSize {
545+
return sdkioerrors.Wrapf(sdkerrors.ErrUnknownRequest, "Chunk %d hash must be %d characters", i, HashSize)
546546
}
547547
if !IsHexBytes(chunk.Hash) {
548548
return sdkioerrors.Wrapf(sdkerrors.ErrUnknownRequest, "Chunk %d hash must be a hex byte string", i)
@@ -610,11 +610,11 @@ func (msg MsgSendChunk) ValidateBasic() error {
610610
if len(msg.ChunkData) == 0 {
611611
return sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, "Chunk data cannot be empty")
612612
}
613-
if uint64(len(msg.ChunkData)) >= chunkSizeLimit {
614-
return sdkioerrors.Wrapf(sdkerrors.ErrUnknownRequest, "Chunk size must be less than than %d", chunkSizeLimit)
613+
if uint64(len(msg.ChunkData)) >= ChunkSizeLimit {
614+
return sdkioerrors.Wrapf(sdkerrors.ErrUnknownRequest, "Chunk size must be less than than %d", ChunkSizeLimit)
615615
}
616-
if msg.ChunkIndex >= chunkIndexLimit {
617-
return sdkioerrors.Wrapf(sdkerrors.ErrUnknownRequest, "Chunk index must be less than %d", chunkIndexLimit)
616+
if msg.ChunkIndex >= ChunkIndexLimit {
617+
return sdkioerrors.Wrapf(sdkerrors.ErrUnknownRequest, "Chunk index must be less than %d", ChunkIndexLimit)
618618
}
619619
return nil
620620
}

golang/cosmos/x/swingset/types/msgs_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func TestInstallBundle_ValidateBasic(t *testing.T) {
151151
msg: &MsgInstallBundle{
152152
Submitter: addr,
153153
CompressedBundle: []byte{1, 2, 3},
154-
UncompressedSize: int64(bundleUncompressedSizeLimit - 1),
154+
UncompressedSize: int64(BundleUncompressedSizeLimit - 1),
155155
},
156156
},
157157

@@ -160,7 +160,7 @@ func TestInstallBundle_ValidateBasic(t *testing.T) {
160160
msg: &MsgInstallBundle{
161161
Submitter: addr,
162162
CompressedBundle: []byte{1, 2, 3},
163-
UncompressedSize: int64(bundleUncompressedSizeLimit),
163+
UncompressedSize: int64(BundleUncompressedSizeLimit),
164164
},
165165
shouldErr: true,
166166
},

0 commit comments

Comments
 (0)