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

Merge master into rc170 2023.12.28 #803

Merged
merged 15 commits into from
Dec 29, 2023
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ require (
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
github.com/gogo/protobuf v1.3.2
github.com/mitchellh/mapstructure v1.5.0
github.com/multiversx/mx-chain-core-go v1.2.19-0.20231129100534-356aa234f4ff
github.com/multiversx/mx-chain-core-go v1.2.19-0.20231214115026-a1e7279b14f1
github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231129101537-ef355850e34b
github.com/multiversx/mx-chain-logger-go v1.0.14-0.20231129101244-c44fa1c79b03
github.com/multiversx/mx-chain-scenario-go v1.2.2-0.20231129113427-ad3056f45296
github.com/multiversx/mx-chain-storage-go v1.0.14-0.20231129103407-a506e0debdd4
github.com/multiversx/mx-chain-vm-common-go v1.5.9-0.20231129110322-d07a35163513
github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20231228070003-ae14e1e0adfa
github.com/multiversx/mx-components-big-int v1.0.0
github.com/pelletier/go-toml v1.9.3
github.com/stretchr/testify v1.8.1
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/multiversx/mx-chain-core-go v1.2.19-0.20231129100534-356aa234f4ff h1:Iss44e+2C4vGtQ5sU3lOqDQ+dxvwlO+Z3mSbC8T1J64=
github.com/multiversx/mx-chain-core-go v1.2.19-0.20231129100534-356aa234f4ff/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-core-go v1.2.19-0.20231214115026-a1e7279b14f1 h1:8rz1ZpRAsWVxSEBy7PJIUStQMKiHs3I4mvpRmHUpsbI=
github.com/multiversx/mx-chain-core-go v1.2.19-0.20231214115026-a1e7279b14f1/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231129101537-ef355850e34b h1:TIE6it719ZIW0E1bFgPAgE+U3zPSkPfAloFYEIeOL3U=
github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231129101537-ef355850e34b/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI=
github.com/multiversx/mx-chain-logger-go v1.0.14-0.20231129101244-c44fa1c79b03 h1:krjJTyN9jrFTK0goMGFdgvJGy6bYSqe8EtI/HCceUmU=
Expand All @@ -91,8 +91,8 @@ github.com/multiversx/mx-chain-scenario-go v1.2.2-0.20231129113427-ad3056f45296
github.com/multiversx/mx-chain-scenario-go v1.2.2-0.20231129113427-ad3056f45296/go.mod h1:WocyahfHCC3oGILEVdRe7I4/+q/TLCORoTo1X4wGmF4=
github.com/multiversx/mx-chain-storage-go v1.0.14-0.20231129103407-a506e0debdd4 h1:TvjyE4/jNoTewu/MPNi3TltxDuIWuvzrRufhgPW+W78=
github.com/multiversx/mx-chain-storage-go v1.0.14-0.20231129103407-a506e0debdd4/go.mod h1:ioCT2oHQ+TyHQYpgjxzlUdy7dCdv56+w5HnBg9z96eY=
github.com/multiversx/mx-chain-vm-common-go v1.5.9-0.20231129110322-d07a35163513 h1:3Hm3MVIpiu4+j+aHiDOYBJBiQC62nF/rHHRJ8YIFOL4=
github.com/multiversx/mx-chain-vm-common-go v1.5.9-0.20231129110322-d07a35163513/go.mod h1:vgmpc/YegaUMAImR+WZ+kpJgv9qYF31oL12vVx/46i4=
github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20231228070003-ae14e1e0adfa h1:xdDeUC4yOfiUwctkYioYMjjigBZoZo5RZq1e5WoCVRs=
github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20231228070003-ae14e1e0adfa/go.mod h1:7jjGRykSfLeMs6iQdszlE0lGK2xp9/cctiVdeKbQLLM=
github.com/multiversx/mx-components-big-int v1.0.0 h1:Wkr8lSzK2nDqixOrrBa47VNuqdhV1m/aJhaP1EMaiS8=
github.com/multiversx/mx-components-big-int v1.0.0/go.mod h1:maIEMgHlNE2u78JaDD0oLzri+ShgU4okHfzP3LWGdQM=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
Expand Down
7 changes: 7 additions & 0 deletions integrationTests/json/scenariosContracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,10 @@ func TestCAttestation(t *testing.T) {
Run().
CheckNoError()
}

func TestRustPaymaster(t *testing.T) {
ScenariosTest(t).
Folder("paymaster/scenarios").
Run().
CheckNoError()
}
Binary file added test/paymaster/output/paymaster.wasm
Binary file not shown.
179 changes: 179 additions & 0 deletions test/paymaster/scenarios/test_forward_call_wegld.scen.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
{
"name": "paymaster",
"comment": "add then check",
"gasSchedule": "v3",
"steps": [
{
"step": "setState",
"accounts": {
"address:user": {
"nonce": "1",
"balance": "0",
"esdt": {
"str:FEE-123456": "100,000,000",
"str:WEGLD-123456": "100,000,000"
}
},
"address:owner": {
"nonce": "1"
},
"address:relayer": {
"nonce": "1",
"balance": "0"
},
"sc:wegld": {
"nonce": "0",
"balance": "100,000,000",
"esdt": {
"str:WEGLD-123456": {
"instances": [
{
"nonce": "",
"balance": "0"
}
],
"roles": [
"ESDTRoleLocalMint",
"ESDTRoleLocalBurn"
]
}
},
"storage": {
"str:wrappedEgldTokenId": "str:WEGLD-123456"
},
"code": "file:../../wegld-swap/output/multiversx-wegld-swap-sc.wasm"
}
},
"newAddresses": [
{
"creatorAddress": "address:owner",
"creatorNonce": "1",
"newAddress": "sc:paymaster"
}
]
},
{
"step": "scDeploy",
"id": "",
"tx": {
"from": "address:owner",
"contractCode": "file:../output/paymaster.wasm",
"arguments": [],
"gasLimit": "5,000,000",
"gasPrice": ""
},
"expect": {
"out": [],
"status": "0"
}
},
{
"step": "checkState",
"accounts": {
"address:user": {
"esdt": {
"str:FEE-123456": "100,000,000",
"str:WEGLD-123456": "100,000,000"
},
"storage": "*",
"code": "*",
"owner": "*",
"nonce": "*",
"balance": "0"
},
"+": ""
}
},
{
"step": "scCall",
"id": "paymaster-forward-execution",
"tx": {
"from": "address:user",
"to": "sc:paymaster",
"esdtValue": [
{
"tokenIdentifier": "str:FEE-123456",
"value": "20,000"
},
{
"tokenIdentifier": "str:WEGLD-123456",
"value": "100,000,000"
}
],
"function": "forwardExecution",
"arguments": [
"0x72656c617965725f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f",
"0x000000000000000000007765676c645f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f",
"0x756e7772617045676c64"
],
"gasLimit": "100,000,000",
"gasPrice": ""
},
"expect": {
"out": [],
"status": "0",
"gas": "*",
"refund": "*"
}
},
{
"step": "checkState",
"accounts": {
"address:relayer": {
"esdt": {
"str:FEE-123456": "20,000",
"str:WEGLD-123456": "0"
},
"storage": "*",
"code": "*",
"owner": "*",
"nonce": "1"
},
"address:user": {
"esdt": {
"str:FEE-123456": "99,980,000"
},
"balance": "100,000,000",
"storage": "*",
"code": "*",
"owner": "*",
"nonce": "2"
},
"sc:paymaster": {
"esdt": {
"str:FEE-123456": "0",
"str:WEGLD-123456": "0"
},
"balance": "0",
"storage": "*",
"code": "*",
"owner": "address:owner",
"nonce": "0"
},
"sc:wegld": {
"esdt": {
"str:FEE-123456": "0",
"str:WEGLD-123456": {
"instances": [
{
"nonce": "",
"balance": "0"
}
],
"roles": [
"ESDTRoleLocalMint",
"ESDTRoleLocalBurn"
]
}
},
"balance": "0",
"storage": "*",
"owner": "*",
"nonce": "0",
"code": "file:../../wegld-swap/output/multiversx-wegld-swap-sc.wasm"
},
"+": ""
}
}
]
}
23 changes: 15 additions & 8 deletions vmhost/contexts/instanceTracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"bytes"
"errors"
"fmt"

"github.com/multiversx/mx-chain-core-go/core/check"
Expand All @@ -15,6 +16,8 @@

type instanceCacheLevel int

var errTooManyInstances = errors.New("too many instances")

const (
// Warm indicates that the instance to track is a warm instance
Warm instanceCacheLevel = iota
Expand Down Expand Up @@ -178,27 +181,27 @@

// UseWarmInstance attempts to retrieve a warm instance for the given codeHash
// and to set it as active; returns false if not possible
func (tracker *instanceTracker) UseWarmInstance(codeHash []byte, newCode bool) bool {
func (tracker *instanceTracker) UseWarmInstance(codeHash []byte, newCode bool) (bool, error) {
instance, ok := tracker.GetWarmInstance(codeHash)
if !ok {
return false
return false, nil
}

ok = instance.Reset()
if !ok {
tracker.warmInstanceCache.Remove(codeHash)
return false
return false, nil

Check warning on line 193 in vmhost/contexts/instanceTracker.go

View check run for this annotation

Codecov / codecov/patch

vmhost/contexts/instanceTracker.go#L193

Added line #L193 was not covered by tests
}

if newCode {
// A warm instance was found, but newCode == true, meaning this is an
// upgrade; the old warm instance must be cleaned
tracker.ForceCleanInstance(false)
return false
return false, nil

Check warning on line 200 in vmhost/contexts/instanceTracker.go

View check run for this annotation

Codecov / codecov/patch

vmhost/contexts/instanceTracker.go#L200

Added line #L200 was not covered by tests
}

tracker.SetNewInstance(instance, Warm)
return true
err := tracker.SetNewInstance(instance, Warm)
return true, err
}

// ForceCleanInstance cleans the active instance and evicts it from the
Expand Down Expand Up @@ -237,7 +240,6 @@
// SaveAsWarmInstance saves the active instance into the internal warm instance cache
func (tracker *instanceTracker) SaveAsWarmInstance() {
lenCacheBeforeSaving := tracker.warmInstanceCache.Len()

codeHashInWarmCache := tracker.warmInstanceCache.Has(tracker.codeHash)

if codeHashInWarmCache {
Expand Down Expand Up @@ -289,13 +291,18 @@
}

// SetNewInstance sets the given instance as active and tracks its creation
func (tracker *instanceTracker) SetNewInstance(instance executor.Instance, cacheLevel instanceCacheLevel) {
func (tracker *instanceTracker) SetNewInstance(instance executor.Instance, cacheLevel instanceCacheLevel) error {
tracker.ReplaceInstance(instance)
tracker.cacheLevel = cacheLevel
if cacheLevel != Warm {
tracker.updateNumRunningInstances(+1)
}
tracker.instances[instance.ID()] = instance

if len(tracker.instances) >= warmCacheSize-1 {
return errTooManyInstances

Check warning on line 303 in vmhost/contexts/instanceTracker.go

View check run for this annotation

Codecov / codecov/patch

vmhost/contexts/instanceTracker.go#L303

Added line #L303 was not covered by tests
}
return nil
}

// ReplaceInstance replaces the currently active instance with the given one
Expand Down
Loading
Loading