Skip to content

Commit

Permalink
[x/programs] Remove SmartPtr and HostPtr (#872)
Browse files Browse the repository at this point in the history
* support program passing in param

* fix inter-program interaction

* update fixture

* keep using `SmartPtr` for now

* remove the need of a new Param type

* lint

* remove param

* fix nits

* remove whitespace

* stop using SmartPtr

* fix tests

* Cached state values in the program state (#840)

* add cache

* implement cache reads

* actually cache reads

* implement cache delete and handle borsch errors

* use only one cache map

* remove flushed bool

* root of transactions by stateless merkledb

* make root generation a function

* preallocate memory for merkle array and consumebytes flag

* add <*.code-workspace> to .gitignore and remove it from git commit

* move root generation func to merkle package, tx root by items of [txID + result]

* rebase & blk marshal/unmarshal & merkleroot to ids.ID

* write benches for the merkle package

* use crypto/rand, fix var name, report allocs

* put the 10k bench back

* pass config by parameter

* happy clippy

* borrow V

* add TODO

* Revert "pass config by parameter"

This reverts commit 4aec589.

* Revert "put the 10k bench back"

This reverts commit 058d7e7.

* Revert "use crypto/rand, fix var name, report allocs"

This reverts commit 214005b.

* Revert "write benches for the merkle package"

This reverts commit 07993bf.

* Revert "rebase & blk marshal/unmarshal & merkleroot to ids.ID"

This reverts commit 7442836.

* Revert "move root generation func to merkle package, tx root by items of [txID + result]"

This reverts commit e551960.

* Revert "add <*.code-workspace> to .gitignore and remove it from git commit"

This reverts commit ce00289.

* Revert "preallocate memory for merkle array and consumebytes flag"

This reverts commit 68e49b6.

* Revert "make root generation a function"

This reverts commit aa44f97.

* Revert "pass config by parameter"

This reverts commit 4aec589.

* Revert "move root generation func to merkle package, tx root by items of [txID + result]"

This reverts commit e551960.

* Revert "preallocate memory for merkle array and consumebytes flag"

This reverts commit 68e49b6.

* Revert "make root generation a function"

This reverts commit aa44f97.

* merge main!

* merge imports

---------

Co-authored-by: bianyuanop <[email protected]>
Co-authored-by: Richard Pringle <[email protected]>

* stop using SmartPtr

* Cached state values in the program state (#840)

* add cache

* implement cache reads

* actually cache reads

* implement cache delete and handle borsch errors

* use only one cache map

* remove flushed bool

* root of transactions by stateless merkledb

* make root generation a function

* preallocate memory for merkle array and consumebytes flag

* add <*.code-workspace> to .gitignore and remove it from git commit

* move root generation func to merkle package, tx root by items of [txID + result]

* rebase & blk marshal/unmarshal & merkleroot to ids.ID

* write benches for the merkle package

* use crypto/rand, fix var name, report allocs

* put the 10k bench back

* pass config by parameter

* happy clippy

* borrow V

* add TODO

* Revert "pass config by parameter"

This reverts commit 4aec589.

* Revert "put the 10k bench back"

This reverts commit 058d7e7.

* Revert "use crypto/rand, fix var name, report allocs"

This reverts commit 214005b.

* Revert "write benches for the merkle package"

This reverts commit 07993bf.

* Revert "rebase & blk marshal/unmarshal & merkleroot to ids.ID"

This reverts commit 7442836.

* Revert "move root generation func to merkle package, tx root by items of [txID + result]"

This reverts commit e551960.

* Revert "add <*.code-workspace> to .gitignore and remove it from git commit"

This reverts commit ce00289.

* Revert "preallocate memory for merkle array and consumebytes flag"

This reverts commit 68e49b6.

* Revert "make root generation a function"

This reverts commit aa44f97.

* Revert "pass config by parameter"

This reverts commit 4aec589.

* Revert "move root generation func to merkle package, tx root by items of [txID + result]"

This reverts commit e551960.

* Revert "preallocate memory for merkle array and consumebytes flag"

This reverts commit 68e49b6.

* Revert "make root generation a function"

This reverts commit aa44f97.

* merge main!

* merge imports

---------

Co-authored-by: bianyuanop <[email protected]>
Co-authored-by: Richard Pringle <[email protected]>

* [x/programs] safe wrapper around C ffi interface (#869)

* macro skeleton

* write macro for ffi-safe bindings

* avoid panicking todo!

Signed-off-by: Franfran <[email protected]>

* remove unused arms

---------

Signed-off-by: Franfran <[email protected]>

* support program passing in param

* keep using `SmartPtr` for now

* remove the need of a new Param type

* lint

* stop using SmartPtr

* fix tests

* back off file

* handle put and delete return as a status and remove the `SmartPointer`

* cargo fmt

* fix test

* pass only context ptr as i32

* fix token test

* lint

* remove ignored lint

* update fixtures

* move `CPointer` from `program` to `memory`

* update fixutes to release

* cargo fmt

* Consolidate CI (#828)

* Add rust-ci local github-action

* Abstract install-go action

* Centralize Go install parameters

* Consolidate CI

* Comment out code coverage

* Finish centralizing the Go installation for CI

* Handle releases

* Fix passing secret to release-actions

* [ci] Small Tweaks (#875)

* nits

* remove labels

---------

Co-authored-by: Patrick O'Grady <[email protected]>

* Update vm-release.yml (#876)

Signed-off-by: Richard Pringle <[email protected]>

* fix inter-program interaction

* keep using `SmartPtr` for now

* lint

* remove param

* fix nits

* stop using SmartPtr

* fix tests

* Cached state values in the program state (#840)

* add cache

* implement cache reads

* actually cache reads

* implement cache delete and handle borsch errors

* use only one cache map

* remove flushed bool

* root of transactions by stateless merkledb

* make root generation a function

* preallocate memory for merkle array and consumebytes flag

* add <*.code-workspace> to .gitignore and remove it from git commit

* move root generation func to merkle package, tx root by items of [txID + result]

* rebase & blk marshal/unmarshal & merkleroot to ids.ID

* write benches for the merkle package

* use crypto/rand, fix var name, report allocs

* put the 10k bench back

* pass config by parameter

* happy clippy

* borrow V

* add TODO

* Revert "pass config by parameter"

This reverts commit 4aec589.

* Revert "put the 10k bench back"

This reverts commit 058d7e7.

* Revert "use crypto/rand, fix var name, report allocs"

This reverts commit 214005b.

* Revert "write benches for the merkle package"

This reverts commit 07993bf.

* Revert "rebase & blk marshal/unmarshal & merkleroot to ids.ID"

This reverts commit 7442836.

* Revert "move root generation func to merkle package, tx root by items of [txID + result]"

This reverts commit e551960.

* Revert "add <*.code-workspace> to .gitignore and remove it from git commit"

This reverts commit ce00289.

* Revert "preallocate memory for merkle array and consumebytes flag"

This reverts commit 68e49b6.

* Revert "make root generation a function"

This reverts commit aa44f97.

* Revert "pass config by parameter"

This reverts commit 4aec589.

* Revert "move root generation func to merkle package, tx root by items of [txID + result]"

This reverts commit e551960.

* Revert "preallocate memory for merkle array and consumebytes flag"

This reverts commit 68e49b6.

* Revert "make root generation a function"

This reverts commit aa44f97.

* merge main!

* merge imports

---------

Co-authored-by: bianyuanop <[email protected]>
Co-authored-by: Richard Pringle <[email protected]>

* stop using SmartPtr

* Cached state values in the program state (#840)

* add cache

* implement cache reads

* actually cache reads

* implement cache delete and handle borsch errors

* use only one cache map

* remove flushed bool

* root of transactions by stateless merkledb

* make root generation a function

* preallocate memory for merkle array and consumebytes flag

* add <*.code-workspace> to .gitignore and remove it from git commit

* move root generation func to merkle package, tx root by items of [txID + result]

* rebase & blk marshal/unmarshal & merkleroot to ids.ID

* write benches for the merkle package

* use crypto/rand, fix var name, report allocs

* put the 10k bench back

* pass config by parameter

* happy clippy

* borrow V

* add TODO

* Revert "pass config by parameter"

This reverts commit 4aec589.

* Revert "put the 10k bench back"

This reverts commit 058d7e7.

* Revert "use crypto/rand, fix var name, report allocs"

This reverts commit 214005b.

* Revert "write benches for the merkle package"

This reverts commit 07993bf.

* Revert "rebase & blk marshal/unmarshal & merkleroot to ids.ID"

This reverts commit 7442836.

* Revert "move root generation func to merkle package, tx root by items of [txID + result]"

This reverts commit e551960.

* Revert "add <*.code-workspace> to .gitignore and remove it from git commit"

This reverts commit ce00289.

* Revert "preallocate memory for merkle array and consumebytes flag"

This reverts commit 68e49b6.

* Revert "make root generation a function"

This reverts commit aa44f97.

* Revert "pass config by parameter"

This reverts commit 4aec589.

* Revert "move root generation func to merkle package, tx root by items of [txID + result]"

This reverts commit e551960.

* Revert "preallocate memory for merkle array and consumebytes flag"

This reverts commit 68e49b6.

* Revert "make root generation a function"

This reverts commit aa44f97.

* merge main!

* merge imports

---------

Co-authored-by: bianyuanop <[email protected]>
Co-authored-by: Richard Pringle <[email protected]>

* [x/programs] safe wrapper around C ffi interface (#869)

* macro skeleton

* write macro for ffi-safe bindings

* avoid panicking todo!

Signed-off-by: Franfran <[email protected]>

* remove unused arms

---------

Signed-off-by: Franfran <[email protected]>

* keep using `SmartPtr` for now

* fix tests

* handle put and delete return as a status and remove the `SmartPointer`

* cargo fmt

* move `CPointer` from `program` to `memory`

* cargo fmt

---------

Signed-off-by: Franfran <[email protected]>
Signed-off-by: Richard Pringle <[email protected]>
Co-authored-by: bianyuanop <[email protected]>
Co-authored-by: Richard Pringle <[email protected]>
Co-authored-by: Patrick O'Grady <[email protected]>
  • Loading branch information
4 people authored May 2, 2024
1 parent 879403b commit 3d8ddec
Show file tree
Hide file tree
Showing 20 changed files with 129 additions and 188 deletions.
1 change: 0 additions & 1 deletion x/programs/cmd/simulator/cmd/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ func programExecuteFunc(
) (ids.ID, []int64, uint64, error) {
// simulate create program transaction
programTxID, err := generateRandomID()

if err != nil {
return ids.Empty, nil, 0, err
}
Expand Down
17 changes: 10 additions & 7 deletions x/programs/examples/imports/program/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ func (i *Import) Register(link *host.Link, callContext program.Context) error {
}

// callProgramFn makes a call to an entry function of a program in the context of another program's ID.
func (i *Import) callProgramFn(callContext program.Context) func(*wasmtime.Caller, int64, int64, int64, int64) int64 {
func (i *Import) callProgramFn(callContext program.Context) func(*wasmtime.Caller, int32, int32, int32, int32, int32, int32, int64) int64 {
return func(
wasmCaller *wasmtime.Caller,
programID int64,
function int64,
args int64,
programPtr int32,
programLen int32,
functionPtr int32,
functionLen int32,
argsPtr int32,
argsLen int32,
maxUnits int64,
) int64 {
ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -80,15 +83,15 @@ func (i *Import) callProgramFn(callContext program.Context) func(*wasmtime.Calle
}

// get the entry function for invoke to call.
functionBytes, err := program.SmartPtr(function).Bytes(memory)
functionBytes, err := memory.Range(uint32(functionPtr), uint32(functionLen))
if err != nil {
i.log.Error("failed to read function name from memory",
zap.Error(err),
)
return -1
}

programIDBytes, err := program.SmartPtr(programID).Bytes(memory)
programIDBytes, err := memory.Range(uint32(programPtr), uint32(programLen))
if err != nil {
i.log.Error("failed to read id from memory",
zap.Error(err),
Expand Down Expand Up @@ -143,7 +146,7 @@ func (i *Import) callProgramFn(callContext program.Context) func(*wasmtime.Calle
}
}()

argsBytes, err := program.SmartPtr(args).Bytes(memory)
argsBytes, err := memory.Range(uint32(argsPtr), uint32(argsLen))
if err != nil {
i.log.Error("failed to read program args from memory",
zap.Error(err),
Expand Down
64 changes: 32 additions & 32 deletions x/programs/examples/imports/pstate/pstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,38 @@ func (*Import) Name() string {
func (i *Import) Register(link *host.Link, _ program.Context) error {
i.meter = link.Meter()
wrap := wrap.New(link)
if err := wrap.RegisterAnyParamFn(Name, "put", 3, i.putFnVariadic); err != nil {
if err := wrap.RegisterAnyParamFn(Name, "put", 6, i.putFnVariadic); err != nil {
return err
}
if err := wrap.RegisterAnyParamFn(Name, "get", 2, i.getFnVariadic); err != nil {
if err := wrap.RegisterAnyParamFn(Name, "get", 4, i.getFnVariadic); err != nil {
return err
}

return wrap.RegisterAnyParamFn(Name, "delete", 2, i.deleteFnVariadic)
return wrap.RegisterAnyParamFn(Name, "delete", 4, i.deleteFnVariadic)
}

func (i *Import) putFnVariadic(caller *program.Caller, args ...int64) (*types.Val, error) {
if len(args) != 3 {
return nil, errors.New("expected 3 arguments")
func (i *Import) putFnVariadic(caller *program.Caller, args ...int32) (*types.Val, error) {
if len(args) != 6 {
return nil, errors.New("expected 6 arguments")
}
return i.putFn(caller, args[0], args[1], args[2])
return i.putFn(caller, args[0], args[1], args[2], args[3], args[4], args[5])
}

func (i *Import) getFnVariadic(caller *program.Caller, args ...int64) (*types.Val, error) {
if len(args) != 2 {
return nil, errors.New("expected 2 arguments")
func (i *Import) getFnVariadic(caller *program.Caller, args ...int32) (*types.Val, error) {
if len(args) != 4 {
return nil, errors.New("expected 4 arguments")
}
return i.getFn(caller, args[0], args[1])
return i.getFn(caller, args[0], args[1], args[2], args[3])
}

func (i *Import) deleteFnVariadic(caller *program.Caller, args ...int64) (*types.Val, error) {
if len(args) != 2 {
return nil, errors.New("expected 2 arguments")
func (i *Import) deleteFnVariadic(caller *program.Caller, args ...int32) (*types.Val, error) {
if len(args) != 4 {
return nil, errors.New("expected 4 arguments")
}
return i.deleteFn(caller, args[0], args[1])
return i.deleteFn(caller, args[0], args[1], args[2], args[3])
}

func (i *Import) putFn(caller *program.Caller, id int64, key int64, value int64) (*types.Val, error) {
func (i *Import) putFn(caller *program.Caller, idPtr int32, idLen int32, keyPtr int32, keyLen int32, valuePtr int32, valueLen int32) (*types.Val, error) {
memory, err := caller.Memory()
if err != nil {
i.log.Error("failed to get memory from caller",
Expand All @@ -83,23 +83,23 @@ func (i *Import) putFn(caller *program.Caller, id int64, key int64, value int64)
return nil, err
}

programIDBytes, err := program.SmartPtr(id).Bytes(memory)
programIDBytes, err := memory.Range(uint32(idPtr), uint32(idLen))
if err != nil {
i.log.Error("failed to read program id from memory",
zap.Error(err),
)
return nil, err
}

keyBytes, err := program.SmartPtr(key).Bytes(memory)
keyBytes, err := memory.Range(uint32(keyPtr), uint32(keyLen))
if err != nil {
i.log.Error("failed to read key from memory",
zap.Error(err),
)
return nil, err
}

valueBytes, err := program.SmartPtr(value).Bytes(memory)
valueBytes, err := memory.Range(uint32(valuePtr), uint32(valueLen))
if err != nil {
i.log.Error("failed to read value from memory",
zap.Error(err),
Expand All @@ -116,10 +116,10 @@ func (i *Import) putFn(caller *program.Caller, id int64, key int64, value int64)
return nil, err
}

return types.ValI64(0), nil
return types.ValI32(0), nil
}

func (i *Import) getFn(caller *program.Caller, id int64, key int64) (*types.Val, error) {
func (i *Import) getFn(caller *program.Caller, idPtr int32, idLen int32, keyPtr int32, keyLen int32) (*types.Val, error) {
memory, err := caller.Memory()
if err != nil {
i.log.Error("failed to get memory from caller",
Expand All @@ -128,15 +128,15 @@ func (i *Import) getFn(caller *program.Caller, id int64, key int64) (*types.Val,
return nil, err
}

programIDBytes, err := program.SmartPtr(id).Bytes(memory)
programIDBytes, err := memory.Range(uint32(idPtr), uint32(idLen))
if err != nil {
i.log.Error("failed to read program id from memory",
zap.Error(err),
)
return nil, err
}

keyBytes, err := program.SmartPtr(key).Bytes(memory)
keyBytes, err := memory.Range(uint32(keyPtr), uint32(keyLen))
if err != nil {
i.log.Error("failed to read key from memory",
zap.Error(err),
Expand All @@ -148,7 +148,7 @@ func (i *Import) getFn(caller *program.Caller, id int64, key int64) (*types.Val,
if err != nil {
if errors.Is(err, database.ErrNotFound) {
// TODO: return a more descriptive error
return types.ValI64(-1), nil
return types.ValI32(-1), nil
}
i.log.Error("failed to get value from storage",
zap.Error(err),
Expand All @@ -163,7 +163,7 @@ func (i *Import) getFn(caller *program.Caller, id int64, key int64) (*types.Val,
return nil, err
}

ptr, err := program.WriteBytes(memory, val)
valPtr, err := program.WriteBytes(memory, val)
if err != nil {
{
i.log.Error("failed to write to memory",
Expand All @@ -172,18 +172,18 @@ func (i *Import) getFn(caller *program.Caller, id int64, key int64) (*types.Val,
}
return nil, err
}
argPtr, err := program.NewSmartPtr(ptr, len(val))
_, err = memory.Range(valPtr, uint32(len(val)))
if err != nil {
i.log.Error("failed to convert ptr to argument",
zap.Error(err),
)
return nil, err
}

return types.ValI64(int64(argPtr)), nil
return types.ValI32(int32(valPtr)), nil
}

func (i *Import) deleteFn(caller *program.Caller, id int64, key int64) (*types.Val, error) {
func (i *Import) deleteFn(caller *program.Caller, idPtr int32, idLen int32, keyPtr int32, keyLen int32) (*types.Val, error) {
memory, err := caller.Memory()
if err != nil {
i.log.Error("failed to get memory from caller",
Expand All @@ -192,15 +192,15 @@ func (i *Import) deleteFn(caller *program.Caller, id int64, key int64) (*types.V
return nil, err
}

programIDBytes, err := program.SmartPtr(id).Bytes(memory)
programIDBytes, err := memory.Range(uint32(idPtr), uint32(idLen))
if err != nil {
i.log.Error("failed to read program id from memory",
zap.Error(err),
)
return nil, err
}

keyBytes, err := program.SmartPtr(key).Bytes(memory)
keyBytes, err := memory.Range(uint32(keyPtr), uint32(keyLen))
if err != nil {
i.log.Error("failed to read key from memory",
zap.Error(err),
Expand All @@ -211,7 +211,7 @@ func (i *Import) deleteFn(caller *program.Caller, id int64, key int64) (*types.V
k := storage.ProgramPrefixKey(programIDBytes, keyBytes)
if err := i.mu.Remove(context.Background(), k); err != nil {
i.log.Error("failed to remove from storage", zap.Error(err))
return types.ValI64(-1), nil
return types.ValI32(-1), nil
}
return types.ValI64(0), nil
return types.ValI32(0), nil
}
14 changes: 7 additions & 7 deletions x/programs/examples/imports/wrap/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ type Wrap struct {
link *host.Link
}

// RegisterOneParamInt64Fn is a helper method for registering a function with one int64 parameter.
// RegisterAnyParamFn is a helper method for registering a function with one int64 parameter.
func (w *Wrap) RegisterAnyParamFn(name, module string, paramCount int, fn AnyParamFn) error {
return w.link.RegisterImportWrapFn(name, module, paramCount, NewImportFn[AnyParamFn](fn))
}

// AnyParamFn is a generic type that satisfies AnyParamFnType
type AnyParamFn func(*program.Caller, ...int64) (*types.Val, error)
type AnyParamFn func(*program.Caller, ...int32) (*types.Val, error)

// ImportFn is a generic type that satisfies ImportFnType
type ImportFn[F AnyParamFn] struct {
fn F
}

// Invoke calls the underlying function with the given arguments. Currently only
// supports int64 arguments and return values.
func (i ImportFn[F]) Invoke(c *program.Caller, args ...int64) (*types.Val, error) {
// supports int32 arguments and return values.
func (i ImportFn[F]) Invoke(c *program.Caller, args ...int32) (*types.Val, error) {
switch fn := any(i.fn).(type) {
case AnyParamFn:
return fn.Call(c, args...)
Expand All @@ -49,16 +49,16 @@ func (i ImportFn[F]) Invoke(c *program.Caller, args ...int64) (*types.Val, error
}
}

func (fn AnyParamFn) Call(c *program.Caller, args ...int64) (*types.Val, error) {
func (fn AnyParamFn) Call(c *program.Caller, args ...int32) (*types.Val, error) {
return fn(c, args...)
}

func NewImportFn[F AnyParamFn](src F) func(caller *program.Caller, wargs ...wasmtime.Val) (*types.Val, error) {
importFn := ImportFn[F]{fn: src}
fn := func(c *program.Caller, wargs ...wasmtime.Val) (*types.Val, error) {
args := make([]int64, 0, len(wargs))
args := make([]int32, 0, len(wargs))
for _, arg := range wargs {
args = append(args, arg.I64())
args = append(args, arg.I32())
}
return importFn.Invoke(c, args...)
}
Expand Down
2 changes: 1 addition & 1 deletion x/programs/examples/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func (t *Token) RunShort(ctx context.Context) error {
return nil
}

func (t *Token) GetUserBalanceFromState(ctx context.Context, programID ids.ID, userPublicKey ed25519.PublicKey) (res int64, err error) {
func (t *Token) GetUserBalanceFromState(ctx context.Context, programID ids.ID, userPublicKey ed25519.PublicKey) (res uint32, err error) {
key := storage.ProgramPrefixKey(programID[:], append([]byte{uint8(Balance)}, userPublicKey[:]...))
b, err := t.db.GetValue(ctx, key)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions x/programs/examples/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestTokenProgram(t *testing.T) {
t.Run("BurnUserTokens", func(t *testing.T) {
wasmBytes := tests.ReadFixture(t, "../tests/fixture/token.wasm")
require := require.New(t)
maxUnits := uint64(80000)
maxUnits := uint64(200000)
eng := engine.New(engine.NewConfig())
program := newTokenProgram(maxUnits, eng, runtime.NewConfig(), wasmBytes)
require.NoError(program.Run(context.Background()))
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestTokenProgram(t *testing.T) {
// read alice balance from state db
aliceBalance, err := program.GetUserBalanceFromState(ctx, programID, alicePublicKey)
require.NoError(err)
require.Equal(int64(1000), aliceBalance)
require.Equal(uint32(1000), aliceBalance)

alicePtr, err = writeToMem(alicePublicKey, mem)
require.NoError(err)
Expand All @@ -92,7 +92,7 @@ func TestTokenProgram(t *testing.T) {

wasmBytes := tests.ReadFixture(t, "../tests/fixture/token.wasm")
require := require.New(t)
maxUnits := uint64(80000)
maxUnits := uint64(200000)
eng := engine.New(engine.NewConfig())
program := newTokenProgram(maxUnits, eng, runtime.NewConfig(), wasmBytes)
require.NoError(program.Run(context.Background()))
Expand Down
4 changes: 2 additions & 2 deletions x/programs/host/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ func (l *Link) RegisterImportWrapFn(module, name string, paramCount int, f func(
// TODO: support other types?
valType := make([]*wasmtime.ValType, paramCount)
for i := 0; i < paramCount; i++ {
valType[i] = wasmtime.NewValType(wasmtime.KindI64)
valType[i] = wasmtime.NewValType(wasmtime.KindI32)
}

funcType := wasmtime.NewFuncType(
valType,
[]*wasmtime.ValType{wasmtime.NewValType(wasmtime.KindI64)},
[]*wasmtime.ValType{wasmtime.NewValType(wasmtime.KindI32)},
)

return l.wasmLink.FuncNew(module, name, funcType, fn)
Expand Down
2 changes: 1 addition & 1 deletion x/programs/program/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (f *Func) Call(context Context, params ...uint32) ([]int64, error) {
return nil, err
}

result, err := f.inner.Call(f.inst.GetStore(), append([]interface{}{int64(contextPtr)}, callParams...)...)
result, err := f.inner.Call(f.inst.GetStore(), append([]interface{}{int32(contextPtr)}, callParams...)...)
if err != nil {
return nil, HandleTrapError(err)
}
Expand Down
Loading

0 comments on commit 3d8ddec

Please sign in to comment.