Skip to content

Commit

Permalink
addressed some reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
kishansagathiya committed Jan 20, 2022
1 parent 3a5c8a5 commit 70395ed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/ipfs/go-ds-badger2 v0.1.1
github.com/ipfs/go-ipns v0.1.2 //indirect
github.com/jpillora/ipfilter v1.2.3
github.com/klauspost/compress v1.12.3
github.com/libp2p/go-libp2p v0.15.1
github.com/libp2p/go-libp2p-core v0.9.0
github.com/libp2p/go-libp2p-discovery v0.5.1
Expand Down Expand Up @@ -84,7 +85,6 @@ require (
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/jcelliott/lumber v0.0.0-20160324203708-dd349441af25 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/klauspost/compress v1.12.3 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/koron/go-ssdp v0.0.2 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
Expand Down
10 changes: 5 additions & 5 deletions lib/runtime/wasmer/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ import (
// Name represents the name of the interpreter
const Name = "wasmer"

// Check that runtime interfaces are satisfied
var (
// Check that runtime interfaces are satisfied
_ runtime.Instance = (*Instance)(nil)
_ runtime.Memory = (*wasm.Memory)(nil)

logger = log.NewFromGlobal(
log.AddContext("pkg", "runtime"),
log.AddContext("module", "go-wasmer"),
)

substrateWasmCompressionFlag = []byte{82, 188, 83, 118, 70, 219, 142, 5}
)

// Config represents a wasmer configuration
Expand Down Expand Up @@ -99,15 +101,13 @@ func NewInstance(code []byte, cfg *Config) (*Instance, error) {

// Substrate Wasm compression
// https://github.com/paritytech/substrate/blob/master/primitives/maybe-compressed-blob/src/lib.rs
const compressionFlag = []byte{82, 188, 83, 118, 70, 219, 142, 5}
if bytes.HasPrefix(code, compressionFlag) {
logger.Debug("Decompressing Wasm runtime code")
if bytes.HasPrefix(code, substrateWasmCompressionFlag) {
decoder, err := zstd.NewReader(nil)
if err != nil {
return nil, fmt.Errorf("failed to create zstd decoder: %w", err)
}

code, err = decoder.DecodeAll(code[len(compressionFlag):], nil)
code, err = decoder.DecodeAll(code[len(substrateWasmCompressionFlag):], nil)
if err != nil {
return nil, fmt.Errorf("failed to decompress compressed wasm code: %w", err)
}
Expand Down

0 comments on commit 70395ed

Please sign in to comment.