Skip to content

Commit

Permalink
don't close cache in ReleasCache
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Dec 19, 2024
1 parent 7e23cac commit ae1b69e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
4 changes: 3 additions & 1 deletion internal/api/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ func InitCache(config types.VMConfig) (Cache, error) {

func ReleaseCache(cache Cache) {
currentRuntime.ReleaseCache(cache.handle)
cache.lockfile.Close()
}

func StoreCode(cache Cache, wasm []byte, persist bool) ([]byte, error) {
if cache.handle == nil {
return nil, fmt.Errorf("cache handle is nil")
}
checksum, err, _ := currentRuntime.StoreCode(wasm)
return checksum, err
}
Expand Down
26 changes: 22 additions & 4 deletions internal/runtime/wazeroruntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (w *WazeroRuntime) RemoveCode(checksum []byte) error {

mod, ok := w.compiledModules[csHex]
if !ok {
return errors.New("wasm file does not exist")
return errors.New("Wasm file does not exist")
}
mod.Close(context.Background())
delete(w.compiledModules, csHex)
Expand All @@ -108,12 +108,28 @@ func (w *WazeroRuntime) RemoveCode(checksum []byte) error {
}

func (w *WazeroRuntime) Pin(checksum []byte) error {
// no-op for wazero
if len(checksum) != 32 {
return errors.New("Checksum not of length 32")
}
w.mu.Lock()
defer w.mu.Unlock()
if _, ok := w.codeCache[hex.EncodeToString(checksum)]; !ok {
return errors.New("Error opening Wasm file for reading")
}
// no-op on success
return nil
}

func (w *WazeroRuntime) Unpin(checksum []byte) error {
// no-op for wazero
if len(checksum) != 32 {
return errors.New("Checksum not of length 32")
}
w.mu.Lock()
defer w.mu.Unlock()
if _, ok := w.codeCache[hex.EncodeToString(checksum)]; !ok {
return errors.New("Error opening Wasm file for reading")
}
// no-op on success
return nil
}

Expand Down Expand Up @@ -194,7 +210,9 @@ func (w *WazeroRuntime) GetMetrics() (*types.Metrics, error) {
}

func (w *WazeroRuntime) GetPinnedMetrics() (*types.PinnedMetrics, error) {
return &types.PinnedMetrics{}, nil
return &types.PinnedMetrics{
PerModule: []types.PerModuleEntry{},
}, nil
}

func (w *WazeroRuntime) callContractFn(fnName string, checksum, env, info, msg []byte) ([]byte, types.GasReport, error) {
Expand Down

0 comments on commit ae1b69e

Please sign in to comment.