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

En 6312/meta tx standard #1885

Merged
merged 26 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1cb71e8
started implementation of relayed transaction standard.
sasurobert Jun 8, 2020
4e9b0db
fixing test with new stuff.
sasurobert Jun 8, 2020
ac7c29c
fixing tests
sasurobert Jun 8, 2020
6ababdf
Merge branch 'development' into EN-6312/Meta-tx-standard
sasurobert Jun 8, 2020
4043c2e
integrating new argument parser.
sasurobert Jun 8, 2020
67da735
fixing tests with new arguments parser
sasurobert Jun 8, 2020
bfa6806
fixing tests with new arguments parser
sasurobert Jun 8, 2020
78502f6
- added converter function for conversion between int and even number…
iulianpascalau Jun 8, 2020
3df3e5a
Merge branch 'EN-6312/Meta-tx-standard' of https://github.com/ElrondN…
iulianpascalau Jun 8, 2020
0fbd2e3
fixing tests with new arguments parser
sasurobert Jun 8, 2020
75a9b60
Merge remote-tracking branch 'origin/EN-6312/Meta-tx-standard' into E…
sasurobert Jun 8, 2020
9a8078a
fix integration test.
sasurobert Jun 8, 2020
048214e
fix integration test
sasurobert Jun 9, 2020
55751ba
Merge branch 'development' into EN-6312/Meta-tx-standard
sasurobert Jun 9, 2020
45b1fde
Merge branch 'development' into EN-6312/Meta-tx-standard
sasurobert Jun 10, 2020
8f85506
no recursive relayed transactions
sasurobert Jun 10, 2020
b378168
started treating error while processing relayed transaction. original…
sasurobert Jun 10, 2020
76e5b62
relayed value is needed as well - only relayed value has to go back t…
sasurobert Jun 10, 2020
6b7993f
relayed value is needed as well - only relayed value has to go back t…
sasurobert Jun 11, 2020
f65a406
changed a few interfaces
sasurobert Jun 11, 2020
ed4042e
finished changing interfaces
sasurobert Jun 11, 2020
2c4b748
finished implementation
sasurobert Jun 11, 2020
d801110
fixing unit tests
sasurobert Jun 11, 2020
9f11316
Merge branch 'development' into EN-6312/Meta-tx-standard
iulianpascalau Jun 12, 2020
774dc6e
fix after review
sasurobert Jun 15, 2020
e490a18
fix unit tests
sasurobert Jun 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions cmd/node/factory/structs.go
Expand Up @@ -59,7 +59,7 @@ import (
"github.com/ElrondNetwork/elrond-go/storage/storageUnit"
"github.com/ElrondNetwork/elrond-go/storage/timecache"
"github.com/ElrondNetwork/elrond-go/vm"
vmcommon "github.com/ElrondNetwork/elrond-vm-common"
"github.com/ElrondNetwork/elrond-vm-common/parsers"
)

const (
Expand Down Expand Up @@ -1098,7 +1098,7 @@ func newShardBlockProcessor(
txLogsProcessor process.TransactionLogProcessor,
version string,
) (process.BlockProcessor, error) {
argsParser := vmcommon.NewAtArgumentParser()
argsParser := smartContract.NewArgumentParser()

argsBuiltIn := builtInFunctions.ArgsCreateBuiltInFunctionContainer{
GasMap: gasSchedule,
Expand Down Expand Up @@ -1170,7 +1170,7 @@ func newShardBlockProcessor(
PubkeyConverter: stateComponents.AddressPubkeyConverter,
ShardCoordinator: shardCoordinator,
BuiltInFuncNames: builtInFuncs.Keys(),
ArgumentParser: vmcommon.NewAtArgumentParser(),
ArgumentParser: parsers.NewCallArgsParser(),
}
txTypeHandler, err := coordinator.NewTxTypeHandler(argsTxTypeHandler)
if err != nil {
Expand Down Expand Up @@ -1230,6 +1230,8 @@ func newShardBlockProcessor(
economics,
receiptTxInterim,
badTxInterim,
argsParser,
scForwarder,
)
if err != nil {
return nil, errors.New("could not create transaction statisticsProcessor: " + err.Error())
Expand Down Expand Up @@ -1396,7 +1398,7 @@ func newMetaBlockProcessor(
return nil, err
}

argsParser := vmcommon.NewAtArgumentParser()
argsParser := smartContract.NewArgumentParser()

vmContainer, err := vmFactory.Create()
if err != nil {
Expand Down Expand Up @@ -1429,7 +1431,7 @@ func newMetaBlockProcessor(
PubkeyConverter: stateComponents.AddressPubkeyConverter,
ShardCoordinator: shardCoordinator,
BuiltInFuncNames: builtInFuncs.Keys(),
ArgumentParser: vmcommon.NewAtArgumentParser(),
ArgumentParser: parsers.NewCallArgsParser(),
}
txTypeHandler, err := coordinator.NewTxTypeHandler(argsTxTypeHandler)
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions cmd/node/main.go
Expand Up @@ -73,7 +73,7 @@ import (
exportFactory "github.com/ElrondNetwork/elrond-go/update/factory"
"github.com/ElrondNetwork/elrond-go/update/trigger"
"github.com/ElrondNetwork/elrond-go/vm"
vmcommon "github.com/ElrondNetwork/elrond-vm-common"
"github.com/ElrondNetwork/elrond-vm-common/parsers"
"github.com/google/gops/agent"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -879,6 +879,7 @@ func startNode(ctx *cli.Context, log logger.Logger, version string) error {
Rounder: rounder,
AddressPubkeyConverter: addressPubkeyConverter,
LatestStorageDataProvider: latestStorageDataProvider,
ArgumentsParser: smartContract.NewArgumentParser(),
StatusHandler: coreComponents.StatusHandler,
}
bootstrapper, err := bootstrap.NewEpochStartBootstrap(epochStartBootstrapArgs)
Expand Down Expand Up @@ -1925,7 +1926,7 @@ func createHardForkTrigger(
return nil, err
}

atArgumentParser := vmcommon.NewAtArgumentParser()
atArgumentParser := smartContract.NewArgumentParser()
argTrigger := trigger.ArgHardforkTrigger{
TriggerPubKeyBytes: triggerPubKeyBytes,
SelfPubKeyBytes: selfPubKeyBytes,
Expand Down Expand Up @@ -2267,7 +2268,7 @@ func createApiResolver(
PubkeyConverter: pubkeyConv,
ShardCoordinator: shardCoordinator,
BuiltInFuncNames: builtInFuncs.Keys(),
ArgumentParser: vmcommon.NewAtArgumentParser(),
ArgumentParser: parsers.NewCallArgsParser(),
}
txTypeHandler, err := coordinator.NewTxTypeHandler(argsTxTypeHandler)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions core/constants.go
Expand Up @@ -414,6 +414,9 @@ const BuiltInFunctionSaveKeyValue = "SaveKeyValue"
// BuiltInFunctionESDTTransfer is the key for the elrond standard digital token transfer built-in function
const BuiltInFunctionESDTTransfer = "ESDTTransfer"

// RelayedTransaction is the key for the elrond meta/gassless/relayed transaction standard
const RelayedTransaction = "relayedTx"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename the document (the title) to use this term instead of "meta".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


// SCDeployInitFunctionName is the key for the function which is called at smart contract deploy time
const SCDeployInitFunctionName = "_init"

Expand Down
21 changes: 21 additions & 0 deletions core/converters.go
Expand Up @@ -3,6 +3,7 @@ package core
import (
"fmt"
"math"
"math/big"
"strconv"
"strings"

Expand Down Expand Up @@ -141,3 +142,23 @@ func ShardIdToString(shardId uint32) string {
}
return fmt.Sprintf("_%d", shardId)
}

// ConvertToEvenHex converts the provided value in a hex string, even number of characters
func ConvertToEvenHex(value int) string {
str := fmt.Sprintf("%x", value)
if len(str)%2 != 0 {
str = "0" + str
}

return str
}

// ConvertToEvenHexBigInt converts the provided value in a hex string, even number of characters
func ConvertToEvenHexBigInt(value *big.Int) string {
sasurobert marked this conversation as resolved.
Show resolved Hide resolved
str := value.Text(16)
if len(str)%2 != 0 {
str = "0" + str
}

return str
}
31 changes: 31 additions & 0 deletions core/converters_test.go
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"fmt"
"math"
"math/big"
"strconv"
"strings"
"testing"

Expand Down Expand Up @@ -186,3 +188,32 @@ func TestCommunicationIdentifierBetweenShards_Metachain(t *testing.T) {
core.MetachainShardId,
))
}

func TestConvertToEvenHex(t *testing.T) {
t.Parallel()

numCompares := 100000
for i := 0; i < numCompares; i++ {
str := core.ConvertToEvenHex(i)

assert.True(t, len(str)%2 == 0)
recovered, err := strconv.ParseInt(str, 16, 32)
assert.Nil(t, err)
assert.Equal(t, i, int(recovered))
}
}

func TestConvertToEvenHexBigInt(t *testing.T) {
t.Parallel()

numCompares := 100000
for i := 0; i < numCompares; i++ {
bigInt := big.NewInt(int64(i))
str := core.ConvertToEvenHexBigInt(bigInt)

assert.True(t, len(str)%2 == 0)
recovered, err := strconv.ParseInt(str, 16, 32)
assert.Nil(t, err)
assert.Equal(t, i, int(recovered))
}
}
20 changes: 11 additions & 9 deletions data/smartContractResult/proto/smartContractResult.proto
Expand Up @@ -13,13 +13,15 @@ message SmartContractResult {
bytes Value = 2 [(gogoproto.jsontag) = "value", (gogoproto.casttypewith) = "math/big.Int;github.com/ElrondNetwork/elrond-go/data.BigIntCaster"];
bytes RcvAddr = 3 [(gogoproto.jsontag) = "receiver"];
bytes SndAddr = 4 [(gogoproto.jsontag) = "sender"];
bytes Code = 5 [(gogoproto.jsontag) = "code,omitempty"];
bytes Data = 6 [(gogoproto.jsontag) = "data,omitempty"];
bytes PrevTxHash = 7 [(gogoproto.jsontag) = "prevTxHash"];
bytes OriginalTxHash = 8 [(gogoproto.jsontag) = "originalTxHash"];
uint64 GasLimit = 9 [(gogoproto.jsontag) = "gasLimit"];
uint64 GasPrice = 10 [(gogoproto.jsontag) = "gasPrice"];
int64 CallType = 11 [(gogoproto.jsontag) = "callType", (gogoproto.casttype) = "github.com/ElrondNetwork/elrond-vm-common.CallType"];
bytes CodeMetadata = 12 [(gogoproto.jsontag) = "codeMetadata,omitempty"];
bytes ReturnMessage = 13 [(gogoproto.jsontag) = "returnMessage,omitempty"];
bytes RelayerAddr = 5 [(gogoproto.jsontag) = "relayer"];
bytes RelayedValue = 6 [(gogoproto.jsontag) = "relayedValue", (gogoproto.casttypewith) = "math/big.Int;github.com/ElrondNetwork/elrond-go/data.BigIntCaster"];
bytes Code = 7 [(gogoproto.jsontag) = "code,omitempty"];
bytes Data = 8 [(gogoproto.jsontag) = "data,omitempty"];
bytes PrevTxHash = 9 [(gogoproto.jsontag) = "prevTxHash"];
bytes OriginalTxHash = 10 [(gogoproto.jsontag) = "originalTxHash"];
uint64 GasLimit = 11 [(gogoproto.jsontag) = "gasLimit"];
uint64 GasPrice = 12 [(gogoproto.jsontag) = "gasPrice"];
int64 CallType = 13 [(gogoproto.jsontag) = "callType", (gogoproto.casttype) = "github.com/ElrondNetwork/elrond-vm-common.CallType"];
bytes CodeMetadata = 14 [(gogoproto.jsontag) = "codeMetadata,omitempty"];
bytes ReturnMessage = 15 [(gogoproto.jsontag) = "returnMessage,omitempty"];
}