Skip to content

Commit 4afb0de

Browse files
authored
Merge pull request #6632 from multiversx/feat/relayedv3
Feat/relayedv3
2 parents 1a2c25d + 6bd3142 commit 4afb0de

File tree

85 files changed

+3378
-472
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+3378
-472
lines changed

api/groups/networkGroup_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,36 @@ func TestNetworkConfigMetrics_GasLimitGuardedTxShouldWork(t *testing.T) {
206206
assert.True(t, keyAndValueFoundInResponse)
207207
}
208208

209+
func TestNetworkConfigMetrics_GasLimitRelayedTxShouldWork(t *testing.T) {
210+
t.Parallel()
211+
212+
statusMetricsProvider := statusHandler.NewStatusMetrics()
213+
key := common.MetricExtraGasLimitRelayedTx
214+
val := uint64(123)
215+
statusMetricsProvider.SetUInt64Value(key, val)
216+
217+
facade := mock.FacadeStub{}
218+
facade.StatusMetricsHandler = func() external.StatusMetricsHandler {
219+
return statusMetricsProvider
220+
}
221+
222+
networkGroup, err := groups.NewNetworkGroup(&facade)
223+
require.NoError(t, err)
224+
225+
ws := startWebServer(networkGroup, "network", getNetworkRoutesConfig())
226+
227+
req, _ := http.NewRequest("GET", "/network/config", nil)
228+
resp := httptest.NewRecorder()
229+
ws.ServeHTTP(resp, req)
230+
231+
respBytes, _ := io.ReadAll(resp.Body)
232+
respStr := string(respBytes)
233+
assert.Equal(t, resp.Code, http.StatusOK)
234+
235+
keyAndValueFoundInResponse := strings.Contains(respStr, key) && strings.Contains(respStr, fmt.Sprintf("%d", val))
236+
assert.True(t, keyAndValueFoundInResponse)
237+
}
238+
209239
func TestNetworkStatusMetrics_ShouldWork(t *testing.T) {
210240
t.Parallel()
211241

api/groups/transactionGroup.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -720,21 +720,23 @@ func (tg *transactionGroup) getTransactionsPoolNonceGapsForSender(sender string,
720720

721721
func (tg *transactionGroup) createTransaction(receivedTx *transaction.FrontendTransaction) (*transaction.Transaction, []byte, error) {
722722
txArgs := &external.ArgsCreateTransaction{
723-
Nonce: receivedTx.Nonce,
724-
Value: receivedTx.Value,
725-
Receiver: receivedTx.Receiver,
726-
ReceiverUsername: receivedTx.ReceiverUsername,
727-
Sender: receivedTx.Sender,
728-
SenderUsername: receivedTx.SenderUsername,
729-
GasPrice: receivedTx.GasPrice,
730-
GasLimit: receivedTx.GasLimit,
731-
DataField: receivedTx.Data,
732-
SignatureHex: receivedTx.Signature,
733-
ChainID: receivedTx.ChainID,
734-
Version: receivedTx.Version,
735-
Options: receivedTx.Options,
736-
Guardian: receivedTx.GuardianAddr,
737-
GuardianSigHex: receivedTx.GuardianSignature,
723+
Nonce: receivedTx.Nonce,
724+
Value: receivedTx.Value,
725+
Receiver: receivedTx.Receiver,
726+
ReceiverUsername: receivedTx.ReceiverUsername,
727+
Sender: receivedTx.Sender,
728+
SenderUsername: receivedTx.SenderUsername,
729+
GasPrice: receivedTx.GasPrice,
730+
GasLimit: receivedTx.GasLimit,
731+
DataField: receivedTx.Data,
732+
SignatureHex: receivedTx.Signature,
733+
ChainID: receivedTx.ChainID,
734+
Version: receivedTx.Version,
735+
Options: receivedTx.Options,
736+
Guardian: receivedTx.GuardianAddr,
737+
GuardianSigHex: receivedTx.GuardianSignature,
738+
Relayer: receivedTx.RelayerAddr,
739+
RelayerSignatureHex: receivedTx.RelayerSignature,
738740
}
739741
start := time.Now()
740742
tx, txHash, err := tg.getFacade().CreateTransaction(txArgs)

cmd/node/config/enableEpochs.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@
333333
# FixRelayedMoveBalanceToNonPayableSCEnableEpoch represents the epoch when the fix for relayed move balance to non payable sc will be enabled
334334
FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 1
335335

336+
# RelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions v3 will be enabled
337+
RelayedTransactionsV3EnableEpoch = 2
338+
336339
# BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers
337340
BLSMultiSignerEnableEpoch = [
338341
{ EnableEpoch = 0, Type = "no-KOSK" },

common/common.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package common
2+
3+
import "github.com/multiversx/mx-chain-core-go/data"
4+
5+
// IsValidRelayedTxV3 returns true if the provided transaction is a valid transaction of type relayed v3
6+
func IsValidRelayedTxV3(tx data.TransactionHandler) bool {
7+
relayedTx, isRelayedV3 := tx.(data.RelayedTransactionHandler)
8+
if !isRelayedV3 {
9+
return false
10+
}
11+
hasValidRelayer := len(relayedTx.GetRelayerAddr()) == len(tx.GetSndAddr()) && len(relayedTx.GetRelayerAddr()) > 0
12+
hasValidRelayerSignature := len(relayedTx.GetRelayerSignature()) == len(relayedTx.GetSignature()) && len(relayedTx.GetRelayerSignature()) > 0
13+
return hasValidRelayer && hasValidRelayerSignature
14+
}
15+
16+
// IsRelayedTxV3 returns true if the provided transaction is a transaction of type relayed v3, without any further checks
17+
func IsRelayedTxV3(tx data.TransactionHandler) bool {
18+
relayedTx, isRelayedV3 := tx.(data.RelayedTransactionHandler)
19+
if !isRelayedV3 {
20+
return false
21+
}
22+
23+
hasRelayer := len(relayedTx.GetRelayerAddr()) > 0
24+
hasRelayerSignature := len(relayedTx.GetRelayerSignature()) > 0
25+
return hasRelayer || hasRelayerSignature
26+
}

common/common_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package common
2+
3+
import (
4+
"math/big"
5+
"testing"
6+
7+
"github.com/multiversx/mx-chain-core-go/data/smartContractResult"
8+
"github.com/multiversx/mx-chain-core-go/data/transaction"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func TestIsValidRelayedTxV3(t *testing.T) {
13+
t.Parallel()
14+
15+
scr := &smartContractResult.SmartContractResult{}
16+
require.False(t, IsValidRelayedTxV3(scr))
17+
require.False(t, IsRelayedTxV3(scr))
18+
19+
notRelayedTxV3 := &transaction.Transaction{
20+
Nonce: 1,
21+
Value: big.NewInt(100),
22+
RcvAddr: []byte("receiver"),
23+
SndAddr: []byte("sender0"),
24+
GasPrice: 100,
25+
GasLimit: 10,
26+
Signature: []byte("signature"),
27+
}
28+
require.False(t, IsValidRelayedTxV3(notRelayedTxV3))
29+
require.False(t, IsRelayedTxV3(notRelayedTxV3))
30+
31+
invalidRelayedTxV3 := &transaction.Transaction{
32+
Nonce: 1,
33+
Value: big.NewInt(100),
34+
RcvAddr: []byte("receiver"),
35+
SndAddr: []byte("sender0"),
36+
GasPrice: 100,
37+
GasLimit: 10,
38+
Signature: []byte("signature"),
39+
RelayerAddr: []byte("relayer"),
40+
}
41+
require.False(t, IsValidRelayedTxV3(invalidRelayedTxV3))
42+
require.True(t, IsRelayedTxV3(invalidRelayedTxV3))
43+
44+
invalidRelayedTxV3 = &transaction.Transaction{
45+
Nonce: 1,
46+
Value: big.NewInt(100),
47+
RcvAddr: []byte("receiver"),
48+
SndAddr: []byte("sender0"),
49+
GasPrice: 100,
50+
GasLimit: 10,
51+
Signature: []byte("signature"),
52+
RelayerSignature: []byte("signature"),
53+
}
54+
require.False(t, IsValidRelayedTxV3(invalidRelayedTxV3))
55+
require.True(t, IsRelayedTxV3(invalidRelayedTxV3))
56+
57+
relayedTxV3 := &transaction.Transaction{
58+
Nonce: 1,
59+
Value: big.NewInt(100),
60+
RcvAddr: []byte("receiver"),
61+
SndAddr: []byte("sender1"),
62+
GasPrice: 100,
63+
GasLimit: 10,
64+
Signature: []byte("signature"),
65+
RelayerAddr: []byte("relayer"),
66+
RelayerSignature: []byte("signature"),
67+
}
68+
require.True(t, IsValidRelayedTxV3(relayedTxV3))
69+
require.True(t, IsRelayedTxV3(relayedTxV3))
70+
}

common/constants.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ const MetricMinGasLimit = "erd_min_gas_limit"
340340
// MetricExtraGasLimitGuardedTx specifies the extra gas limit required for guarded transactions
341341
const MetricExtraGasLimitGuardedTx = "erd_extra_gas_limit_guarded_tx"
342342

343+
// MetricExtraGasLimitRelayedTx specifies the extra gas limit required for relayed v3 transactions
344+
const MetricExtraGasLimitRelayedTx = "erd_extra_gas_limit_relayed_tx"
345+
343346
// MetricRewardsTopUpGradientPoint is the metric that specifies the rewards top up gradient point
344347
const MetricRewardsTopUpGradientPoint = "erd_rewards_top_up_gradient_point"
345348

@@ -737,6 +740,9 @@ const (
737740
// MetricFixRelayedMoveBalanceToNonPayableSCEnableEpoch represents the epoch when the fix for relayed move balance to non-payable sc is enabled
738741
MetricFixRelayedMoveBalanceToNonPayableSCEnableEpoch = "erd_fix_relayed_move_balance_to_non_payable_sc_enable_epoch"
739742

743+
// MetricRelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions v3 are enabled
744+
MetricRelayedTransactionsV3EnableEpoch = "erd_relayed_transactions_v3_enable_epoch"
745+
740746
// MetricMaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch
741747
MetricMaxNodesChangeEnableEpoch = "erd_max_nodes_change_enable_epoch"
742748

@@ -1234,5 +1240,6 @@ const (
12341240
FixRelayedBaseCostFlag core.EnableEpochFlag = "FixRelayedBaseCostFlag"
12351241
MultiESDTNFTTransferAndExecuteByUserFlag core.EnableEpochFlag = "MultiESDTNFTTransferAndExecuteByUserFlag"
12361242
FixRelayedMoveBalanceToNonPayableSCFlag core.EnableEpochFlag = "FixRelayedMoveBalanceToNonPayableSCFlag"
1243+
RelayedTransactionsV3Flag core.EnableEpochFlag = "RelayedTransactionsV3Flag"
12371244
// all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined
12381245
)

common/enablers/enableEpochsHandler.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,12 @@ func (handler *enableEpochsHandler) createAllFlagsMap() {
780780
},
781781
activationEpoch: handler.enableEpochsConfig.FixRelayedMoveBalanceToNonPayableSCEnableEpoch,
782782
},
783+
common.RelayedTransactionsV3Flag: {
784+
isActiveInEpoch: func(epoch uint32) bool {
785+
return epoch >= handler.enableEpochsConfig.RelayedTransactionsV3EnableEpoch
786+
},
787+
activationEpoch: handler.enableEpochsConfig.RelayedTransactionsV3EnableEpoch,
788+
},
783789
}
784790
}
785791

common/enablers/enableEpochsHandler_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ func createEnableEpochsConfig() config.EnableEpochs {
123123
MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 106,
124124
FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 107,
125125
UseGasBoundedShouldFailExecutionEnableEpoch: 108,
126+
RelayedTransactionsV3EnableEpoch: 109,
126127
}
127128
}
128129

@@ -448,6 +449,7 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) {
448449
require.Equal(t, cfg.FixRelayedBaseCostEnableEpoch, handler.GetActivationEpoch(common.FixRelayedBaseCostFlag))
449450
require.Equal(t, cfg.MultiESDTNFTTransferAndExecuteByUserEnableEpoch, handler.GetActivationEpoch(common.MultiESDTNFTTransferAndExecuteByUserFlag))
450451
require.Equal(t, cfg.FixRelayedMoveBalanceToNonPayableSCEnableEpoch, handler.GetActivationEpoch(common.FixRelayedMoveBalanceToNonPayableSCFlag))
452+
require.Equal(t, cfg.RelayedTransactionsV3EnableEpoch, handler.GetActivationEpoch(common.RelayedTransactionsV3Flag))
451453
}
452454

453455
func TestEnableEpochsHandler_IsInterfaceNil(t *testing.T) {

config/epochConfig.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ type EnableEpochs struct {
122122
FixRelayedBaseCostEnableEpoch uint32
123123
MultiESDTNFTTransferAndExecuteByUserEnableEpoch uint32
124124
FixRelayedMoveBalanceToNonPayableSCEnableEpoch uint32
125+
RelayedTransactionsV3EnableEpoch uint32
125126
BLSMultiSignerEnableEpoch []MultiSignerConfig
126127
}
127128

config/tomlConfig_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,9 @@ func TestEnableEpochConfig(t *testing.T) {
884884
# FixRelayedMoveBalanceToNonPayableSCEnableEpoch represents the epoch when the fix for relayed move balance to non payable sc will be enabled
885885
FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 102
886886
887+
# RelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions v3 will be enabled
888+
RelayedTransactionsV3EnableEpoch = 103
889+
887890
# MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch
888891
MaxNodesChangeEnableEpoch = [
889892
{ EpochEnable = 44, MaxNumNodes = 2169, NodesToShufflePerShard = 80 },
@@ -1004,6 +1007,7 @@ func TestEnableEpochConfig(t *testing.T) {
10041007
FixRelayedBaseCostEnableEpoch: 100,
10051008
MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 101,
10061009
FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 102,
1010+
RelayedTransactionsV3EnableEpoch: 103,
10071011
MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{
10081012
{
10091013
EpochEnable: 44,

0 commit comments

Comments
 (0)