Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make cantract_call costs instantiation cost to each instantiating callee VM #83

Merged
merged 4 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ typedef struct GoQuerier {
typedef struct GoApi_vtable {
int32_t (*humanize_address)(const struct api_t*, struct U8SliceView, struct UnmanagedVector*, struct UnmanagedVector*, uint64_t*);
int32_t (*canonicalize_address)(const struct api_t*, struct U8SliceView, struct UnmanagedVector*, struct UnmanagedVector*, uint64_t*);
int32_t (*get_contract_env)(const struct api_t*, struct U8SliceView, struct UnmanagedVector*, struct cache_t**, struct Db*, struct GoQuerier*, struct UnmanagedVector*, struct UnmanagedVector*, uint64_t*);
int32_t (*get_contract_env)(const struct api_t*, struct U8SliceView, uint64_t, struct UnmanagedVector*, struct cache_t**, struct Db*, struct GoQuerier*, struct UnmanagedVector*, struct UnmanagedVector*, uint64_t*, uint64_t*);
} GoApi_vtable;

typedef struct GoApi {
Expand Down
10 changes: 6 additions & 4 deletions api/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ GoError cNext_cgo(iterator_t *ptr, gas_meter_t *gas_meter, uint64_t *used_gas, U
// api
GoError cHumanAddress_cgo(api_t *ptr, U8SliceView src, UnmanagedVector *dest, UnmanagedVector *errOut, uint64_t *used_gas);
GoError cCanonicalAddress_cgo(api_t *ptr, U8SliceView src, UnmanagedVector *dest, UnmanagedVector *errOut, uint64_t *used_gas);
GoError cGetContractEnv_cgo(api_t *ptr, U8SliceView contractAddr, UnmanagedVector *contractEnvOut, cache_t **cachePtrOut, Db *dbOut, GoQuerier* querierOut, UnmanagedVector *checksumOut, UnmanagedVector *errOut, uint64_t *used_gas);
GoError cGetContractEnv_cgo(api_t *ptr, U8SliceView contractAddr, uint64_t inputLength, UnmanagedVector *contractEnvOut, cache_t **cachePtrOut, Db *dbOut, GoQuerier* querierOut, UnmanagedVector *checksumOut, UnmanagedVector *errOut, uint64_t *instantiate_cost, uint64_t *used_gas);
// and querier
GoError cQueryExternal_cgo(querier_t *ptr, uint64_t gas_limit, uint64_t *used_gas, U8SliceView request, UnmanagedVector *result, UnmanagedVector *errOut);

Expand Down Expand Up @@ -370,7 +370,7 @@ func cNext(ref C.iterator_t, gasMeter *C.gas_meter_t, usedGas *C.uint64_t, key *
type (
HumanizeAddress func([]byte) (string, uint64, error)
CanonicalizeAddress func(string) ([]byte, uint64, error)
GetContractEnv func(string) (Env, *Cache, KVStore, Querier, GasMeter, []byte, uint64, error)
GetContractEnv func(string, uint64) (Env, *Cache, KVStore, Querier, GasMeter, []byte, uint64, uint64, error)
)

type GoAPI struct {
Expand Down Expand Up @@ -450,7 +450,7 @@ func cCanonicalAddress(ptr *C.api_t, src C.U8SliceView, dest *C.UnmanagedVector,
}

//export cGetContractEnv
func cGetContractEnv(ptr *C.api_t, contractAddr C.U8SliceView, contractEnvOut *C.UnmanagedVector, cachePtrOut **C.cache_t, dbOut *C.Db, querierOut *C.GoQuerier, checksumOut *C.UnmanagedVector, errOut *C.UnmanagedVector, used_gas *cu64) (ret C.GoError) {
func cGetContractEnv(ptr *C.api_t, contractAddr C.U8SliceView, inputLength cu64, contractEnvOut *C.UnmanagedVector, cachePtrOut **C.cache_t, dbOut *C.Db, querierOut *C.GoQuerier, checksumOut *C.UnmanagedVector, errOut *C.UnmanagedVector, instantiate_cost *cu64, used_gas *cu64) (ret C.GoError) {
defer recoverPanic(&ret)

if contractEnvOut == nil || cachePtrOut == nil || dbOut == nil || querierOut == nil || checksumOut == nil || errOut == nil {
Expand All @@ -462,8 +462,10 @@ func cGetContractEnv(ptr *C.api_t, contractAddr C.U8SliceView, contractEnvOut *C

api := (*GoAPI)(unsafe.Pointer(ptr))
s := string(copyU8Slice(contractAddr))
contractEnv, cache, store, querier, gasMeter, checksum, cost, err := api.GetContractEnv(s)
l := uint64(inputLength)
contractEnv, cache, store, querier, gasMeter, checksum, instantiateCost, cost, err := api.GetContractEnv(s, l)
*used_gas = cu64(cost)
*instantiate_cost = cu64(instantiateCost)
if err != nil {
// store the actual error message in the return buffer
*errOut = newUnmanagedVector([]byte(err.Error()))
Expand Down
6 changes: 3 additions & 3 deletions api/callbacks_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GoError cNext(iterator_t *ptr, gas_meter_t *gas_meter, uint64_t *used_gas, Unman
// imports (api)
GoError cHumanAddress(api_t *ptr, U8SliceView src, UnmanagedVector *dest, UnmanagedVector *errOut, uint64_t *used_gas);
GoError cCanonicalAddress(api_t *ptr, U8SliceView src, UnmanagedVector *dest, UnmanagedVector *errOut, uint64_t *used_gas);
GoError cGetContractEnv(api_t *ptr, U8SliceView contractAddr, UnmanagedVector *contractEnvOut, cache_t **cachePtrOut, Db *dbOut, GoQuerier* querierOut, UnmanagedVector *checksumOut, UnmanagedVector *errOut, uint64_t *used_gas);
GoError cGetContractEnv(api_t *ptr, U8SliceView contractAddr, uint64_t input_length, UnmanagedVector *contractEnvOut, cache_t **cachePtrOut, Db *dbOut, GoQuerier* querierOut, UnmanagedVector *checksumOut, UnmanagedVector *errOut, uint64_t *instantiate_cost, uint64_t *used_gas);
// imports (querier)
GoError cQueryExternal(querier_t *ptr, uint64_t gas_limit, uint64_t *used_gas, U8SliceView request, UnmanagedVector *result, UnmanagedVector *errOut);

Expand Down Expand Up @@ -44,8 +44,8 @@ GoError cCanonicalAddress_cgo(api_t *ptr, U8SliceView src, UnmanagedVector *dest
GoError cHumanAddress_cgo(api_t *ptr, U8SliceView src, UnmanagedVector *dest, UnmanagedVector *errOut, uint64_t *used_gas) {
return cHumanAddress(ptr, src, dest, errOut, used_gas);
}
GoError cGetContractEnv_cgo(api_t *ptr, U8SliceView contractAddr, UnmanagedVector *contractEnvOut, cache_t **cachePtrOut, Db *dbOut, GoQuerier* querierOut, UnmanagedVector *checksumOut, UnmanagedVector *errOut, uint64_t *used_gas) {
return cGetContractEnv(ptr, contractAddr, contractEnvOut, cachePtrOut, dbOut, querierOut, checksumOut, errOut, used_gas);
GoError cGetContractEnv_cgo(api_t *ptr, U8SliceView contractAddr, uint64_t input_length, UnmanagedVector *contractEnvOut, cache_t **cachePtrOut, Db *dbOut, GoQuerier* querierOut, UnmanagedVector *checksumOut, UnmanagedVector *errOut, uint64_t *instantiate_cost, uint64_t *used_gas) {
return cGetContractEnv(ptr, contractAddr, input_length, contractEnvOut, cachePtrOut, dbOut, querierOut, checksumOut, errOut, instantiate_cost, used_gas);
}

// Gateway functions (querier)
Expand Down
Binary file modified api/libwasmvm.aarch64.so
Binary file not shown.
Binary file modified api/libwasmvm.dylib
Binary file not shown.
Binary file modified api/libwasmvm.x86_64.so
Binary file not shown.
60 changes: 20 additions & 40 deletions libwasmvm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions libwasmvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ default = []
backtraces = []

[dependencies]
cosmwasm-std = { git = "https://github.com/line/cosmwasm", rev = "5a2058abef4b2ce2237380a594224172b541234f", features = ["iterator","staking","stargate"] }
cosmwasm-vm = { git = "https://github.com/line/cosmwasm", rev = "5a2058abef4b2ce2237380a594224172b541234f", features = ["iterator","staking","stargate"] }
cosmwasm-std = { git = "https://github.com/line/cosmwasm", rev = "324f59e22bbfc210333eea0d34ea65c92d8b0b8e", features = ["iterator","staking","stargate"] }
cosmwasm-vm = { git = "https://github.com/line/cosmwasm", rev = "324f59e22bbfc210333eea0d34ea65c92d8b0b8e", features = ["iterator","staking","stargate"] }
errno = "0.2"
serde_json = "1.0"
thiserror = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion libwasmvm/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ typedef struct GoQuerier {
typedef struct GoApi_vtable {
int32_t (*humanize_address)(const struct api_t*, struct U8SliceView, struct UnmanagedVector*, struct UnmanagedVector*, uint64_t*);
int32_t (*canonicalize_address)(const struct api_t*, struct U8SliceView, struct UnmanagedVector*, struct UnmanagedVector*, uint64_t*);
int32_t (*get_contract_env)(const struct api_t*, struct U8SliceView, struct UnmanagedVector*, struct cache_t**, struct Db*, struct GoQuerier*, struct UnmanagedVector*, struct UnmanagedVector*, uint64_t*);
int32_t (*get_contract_env)(const struct api_t*, struct U8SliceView, uint64_t, struct UnmanagedVector*, struct cache_t**, struct Db*, struct GoQuerier*, struct UnmanagedVector*, struct UnmanagedVector*, uint64_t*, uint64_t*);
} GoApi_vtable;

typedef struct GoApi {
Expand Down
Loading