Skip to content

Commit

Permalink
Merge pull request #6546 from multiversx/revert_relayedv3
Browse files Browse the repository at this point in the history
Revert relayed v3
  • Loading branch information
sstanculeanu authored Oct 25, 2024
2 parents d9d3dc7 + 1c6dc0c commit 17a4819
Show file tree
Hide file tree
Showing 96 changed files with 1,137 additions and 4,485 deletions.
128 changes: 20 additions & 108 deletions api/groups/transactionGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,23 +197,7 @@ func (tg *transactionGroup) simulateTransaction(c *gin.Context) {
return
}

innerTxs, err := tg.extractInnerTransactions(ftx.InnerTransactions)
if err != nil {
c.JSON(
http.StatusBadRequest,
shared.GenericAPIResponse{
Data: nil,
Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()),
Code: shared.ReturnCodeRequestError,
},
)
return
}

if len(innerTxs) == 0 {
innerTxs = nil
}
tx, txHash, err := tg.createTransaction(&ftx, innerTxs)
tx, txHash, err := tg.createTransaction(&ftx)
if err != nil {
c.JSON(
http.StatusBadRequest,
Expand Down Expand Up @@ -283,23 +267,7 @@ func (tg *transactionGroup) sendTransaction(c *gin.Context) {
return
}

innerTxs, err := tg.extractInnerTransactions(ftx.InnerTransactions)
if err != nil {
c.JSON(
http.StatusBadRequest,
shared.GenericAPIResponse{
Data: nil,
Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()),
Code: shared.ReturnCodeRequestError,
},
)
return
}

if len(innerTxs) == 0 {
innerTxs = nil
}
tx, txHash, err := tg.createTransaction(&ftx, innerTxs)
tx, txHash, err := tg.createTransaction(&ftx)
if err != nil {
c.JSON(
http.StatusBadRequest,
Expand Down Expand Up @@ -378,23 +346,7 @@ func (tg *transactionGroup) sendMultipleTransactions(c *gin.Context) {
var start time.Time
txsHashes := make(map[int]string)
for idx, receivedTx := range ftxs {
innerTxs, errExtractInnerTransactions := tg.extractInnerTransactions(receivedTx.InnerTransactions)
if errExtractInnerTransactions != nil {
c.JSON(
http.StatusBadRequest,
shared.GenericAPIResponse{
Data: nil,
Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()),
Code: shared.ReturnCodeInternalError,
},
)
return
}

if len(innerTxs) == 0 {
innerTxs = nil
}
tx, txHash, err = tg.createTransaction(&receivedTx, innerTxs)
tx, txHash, err = tg.createTransaction(&receivedTx)
if err != nil {
continue
}
Expand Down Expand Up @@ -556,23 +508,7 @@ func (tg *transactionGroup) computeTransactionGasLimit(c *gin.Context) {
return
}

innerTxs, errExtractInnerTransactions := tg.extractInnerTransactions(ftx.InnerTransactions)
if errExtractInnerTransactions != nil {
c.JSON(
http.StatusBadRequest,
shared.GenericAPIResponse{
Data: nil,
Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errExtractInnerTransactions.Error()),
Code: shared.ReturnCodeInternalError,
},
)
return
}

if len(innerTxs) == 0 {
innerTxs = nil
}
tx, _, err := tg.createTransaction(&ftx, innerTxs)
tx, _, err := tg.createTransaction(&ftx)
if err != nil {
c.JSON(
http.StatusInternalServerError,
Expand Down Expand Up @@ -782,25 +718,23 @@ func (tg *transactionGroup) getTransactionsPoolNonceGapsForSender(sender string,
)
}

func (tg *transactionGroup) createTransaction(receivedTx *transaction.FrontendTransaction, innerTxs []*transaction.Transaction) (*transaction.Transaction, []byte, error) {
func (tg *transactionGroup) createTransaction(receivedTx *transaction.FrontendTransaction) (*transaction.Transaction, []byte, error) {
txArgs := &external.ArgsCreateTransaction{
Nonce: receivedTx.Nonce,
Value: receivedTx.Value,
Receiver: receivedTx.Receiver,
ReceiverUsername: receivedTx.ReceiverUsername,
Sender: receivedTx.Sender,
SenderUsername: receivedTx.SenderUsername,
GasPrice: receivedTx.GasPrice,
GasLimit: receivedTx.GasLimit,
DataField: receivedTx.Data,
SignatureHex: receivedTx.Signature,
ChainID: receivedTx.ChainID,
Version: receivedTx.Version,
Options: receivedTx.Options,
Guardian: receivedTx.GuardianAddr,
GuardianSigHex: receivedTx.GuardianSignature,
Relayer: receivedTx.Relayer,
InnerTransactions: innerTxs,
Nonce: receivedTx.Nonce,
Value: receivedTx.Value,
Receiver: receivedTx.Receiver,
ReceiverUsername: receivedTx.ReceiverUsername,
Sender: receivedTx.Sender,
SenderUsername: receivedTx.SenderUsername,
GasPrice: receivedTx.GasPrice,
GasLimit: receivedTx.GasLimit,
DataField: receivedTx.Data,
SignatureHex: receivedTx.Signature,
ChainID: receivedTx.ChainID,
Version: receivedTx.Version,
Options: receivedTx.Options,
Guardian: receivedTx.GuardianAddr,
GuardianSigHex: receivedTx.GuardianSignature,
}
start := time.Now()
tx, txHash, err := tg.getFacade().CreateTransaction(txArgs)
Expand Down Expand Up @@ -906,28 +840,6 @@ func (tg *transactionGroup) getFacade() transactionFacadeHandler {
return tg.facade
}

func (tg *transactionGroup) extractInnerTransactions(
innerTransactions []*transaction.FrontendTransaction,
) ([]*transaction.Transaction, error) {
innerTxs := make([]*transaction.Transaction, 0, len(innerTransactions))
if len(innerTransactions) != 0 {
for _, innerTx := range innerTransactions {
if len(innerTx.InnerTransactions) != 0 {
return innerTxs, errors.ErrRecursiveRelayedTxIsNotAllowed
}

newInnerTx, _, err := tg.createTransaction(innerTx, nil)
if err != nil {
return innerTxs, err
}

innerTxs = append(innerTxs, newInnerTx)
}
}

return innerTxs, nil
}

// UpdateFacade will update the facade
func (tg *transactionGroup) UpdateFacade(newFacade interface{}) error {
if newFacade == nil {
Expand Down
62 changes: 0 additions & 62 deletions api/groups/transactionGroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ func TestTransactionGroup_sendTransaction(t *testing.T) {
expectedErr,
)
})
t.Run("recursive relayed v3 should error", testRecursiveRelayedV3("/transaction/send"))
t.Run("should work", func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -591,7 +590,6 @@ func TestTransactionGroup_computeTransactionGasLimit(t *testing.T) {
expectedErr,
)
})
t.Run("recursive relayed v3 should error", testRecursiveRelayedV3("/transaction/cost"))
t.Run("should work", func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -712,7 +710,6 @@ func TestTransactionGroup_simulateTransaction(t *testing.T) {
expectedErr,
)
})
t.Run("recursive relayed v3 should error", testRecursiveRelayedV3("/transaction/simulate"))
t.Run("should work", func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1201,62 +1198,3 @@ func getTransactionRoutesConfig() config.ApiRoutesConfig {
},
}
}

func testRecursiveRelayedV3(url string) func(t *testing.T) {
return func(t *testing.T) {
t.Parallel()

facade := &mock.FacadeStub{
CreateTransactionHandler: func(txArgs *external.ArgsCreateTransaction) (*dataTx.Transaction, []byte, error) {
txHash, _ := hex.DecodeString(hexTxHash)
return nil, txHash, nil
},
SendBulkTransactionsHandler: func(txs []*dataTx.Transaction) (u uint64, err error) {
return 1, nil
},
ValidateTransactionHandler: func(tx *dataTx.Transaction) error {
return nil
},
}

userTx1 := fmt.Sprintf(`{"nonce": %d, "sender":"%s", "receiver":"%s", "value":"%s", "signature":"%s"}`,
nonce,
sender,
receiver,
value,
signature,
)
userTx2 := fmt.Sprintf(`{"nonce": %d, "sender":"%s", "receiver":"%s", "value":"%s", "signature":"%s", "innerTransactions":[%s]}`,
nonce,
sender,
receiver,
value,
signature,
userTx1,
)
tx := fmt.Sprintf(`{"nonce": %d, "sender":"%s", "receiver":"%s", "value":"%s", "signature":"%s", "innerTransactions":[%s]}`,
nonce,
sender,
receiver,
value,
signature,
userTx2,
)

transactionGroup, err := groups.NewTransactionGroup(facade)
require.NoError(t, err)

ws := startWebServer(transactionGroup, "transaction", getTransactionRoutesConfig())

req, _ := http.NewRequest("POST", url, bytes.NewBuffer([]byte(tx)))
resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)

txResp := shared.GenericAPIResponse{}
loadResponse(resp.Body, &txResp)

assert.Equal(t, http.StatusBadRequest, resp.Code)
assert.True(t, strings.Contains(txResp.Error, apiErrors.ErrRecursiveRelayedTxIsNotAllowed.Error()))
assert.Empty(t, txResp.Data)
}
}
3 changes: 0 additions & 3 deletions cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,3 @@
# MaxRoundsOfInactivityAccepted defines the number of rounds missed by a main or higher level backup machine before
# the current machine will take over and propose/sign blocks. Used in both single-key and multi-key modes.
MaxRoundsOfInactivityAccepted = 3

[RelayedTransactionConfig]
MaxTransactionsAllowed = 50
7 changes: 2 additions & 5 deletions cmd/node/config/enableEpochs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -324,17 +324,14 @@
# UnjailCleanupEnableEpoch represents the epoch when the cleanup of the unjailed nodes is enabled
UnJailCleanupEnableEpoch = 4

# RelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions V3 will be enabled
RelayedTransactionsV3EnableEpoch = 7

# FixRelayedBaseCostEnableEpoch represents the epoch when the fix for relayed base cost will be enabled
FixRelayedBaseCostEnableEpoch = 7
FixRelayedBaseCostEnableEpoch = 4

# MultiESDTNFTTransferAndExecuteByUserEnableEpoch represents the epoch when enshrined sovereign cross chain opcodes are enabled
MultiESDTNFTTransferAndExecuteByUserEnableEpoch = 9999999

# FixRelayedMoveBalanceToNonPayableSCEnableEpoch represents the epoch when the fix for relayed move balance to non payable sc will be enabled
FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 7
FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 4

# BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers
BLSMultiSignerEnableEpoch = [
Expand Down
4 changes: 0 additions & 4 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,6 @@ const (
// MetricRelayedTransactionsV2EnableEpoch represents the epoch when the relayed transactions v2 is enabled
MetricRelayedTransactionsV2EnableEpoch = "erd_relayed_transactions_v2_enable_epoch"

// MetricRelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions v3 is enabled
MetricRelayedTransactionsV3EnableEpoch = "erd_relayed_transactions_v3_enable_epoch"

// MetricFixRelayedBaseCostEnableEpoch represents the epoch when the fix for relayed base cost is enabled
MetricFixRelayedBaseCostEnableEpoch = "erd_fix_relayed_base_cost_enable_epoch"

Expand Down Expand Up @@ -1234,7 +1231,6 @@ const (
EGLDInESDTMultiTransferFlag core.EnableEpochFlag = "EGLDInESDTMultiTransferFlag"
CryptoOpcodesV2Flag core.EnableEpochFlag = "CryptoOpcodesV2Flag"
UnJailCleanupFlag core.EnableEpochFlag = "UnJailCleanupFlag"
RelayedTransactionsV3Flag core.EnableEpochFlag = "RelayedTransactionsV3Flag"
FixRelayedBaseCostFlag core.EnableEpochFlag = "FixRelayedBaseCostFlag"
MultiESDTNFTTransferAndExecuteByUserFlag core.EnableEpochFlag = "MultiESDTNFTTransferAndExecuteByUserFlag"
FixRelayedMoveBalanceToNonPayableSCFlag core.EnableEpochFlag = "FixRelayedMoveBalanceToNonPayableSCFlag"
Expand Down
6 changes: 0 additions & 6 deletions common/enablers/enableEpochsHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,12 +762,6 @@ func (handler *enableEpochsHandler) createAllFlagsMap() {
},
activationEpoch: handler.enableEpochsConfig.UnJailCleanupEnableEpoch,
},
common.RelayedTransactionsV3Flag: {
isActiveInEpoch: func(epoch uint32) bool {
return epoch >= handler.enableEpochsConfig.RelayedTransactionsV3EnableEpoch
},
activationEpoch: handler.enableEpochsConfig.RelayedTransactionsV3EnableEpoch,
},
common.FixRelayedBaseCostFlag: {
isActiveInEpoch: func(epoch uint32) bool {
return epoch >= handler.enableEpochsConfig.FixRelayedBaseCostEnableEpoch
Expand Down
11 changes: 4 additions & 7 deletions common/enablers/enableEpochsHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,10 @@ func createEnableEpochsConfig() config.EnableEpochs {
DynamicESDTEnableEpoch: 102,
EGLDInMultiTransferEnableEpoch: 103,
CryptoOpcodesV2EnableEpoch: 104,
RelayedTransactionsV3EnableEpoch: 105,
FixRelayedBaseCostEnableEpoch: 106,
MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 107,
FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 108,
UseGasBoundedShouldFailExecutionEnableEpoch: 110,
FixRelayedBaseCostEnableEpoch: 105,
MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 106,
FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 107,
UseGasBoundedShouldFailExecutionEnableEpoch: 108,
}
}

Expand Down Expand Up @@ -324,7 +323,6 @@ func TestEnableEpochsHandler_IsFlagEnabled(t *testing.T) {
require.True(t, handler.IsFlagEnabled(common.StakingV4StartedFlag))
require.True(t, handler.IsFlagEnabled(common.AlwaysMergeContextsInEEIFlag))
require.True(t, handler.IsFlagEnabled(common.DynamicESDTFlag))
require.True(t, handler.IsFlagEnabled(common.RelayedTransactionsV3Flag))
require.True(t, handler.IsFlagEnabled(common.FixRelayedBaseCostFlag))
require.True(t, handler.IsFlagEnabled(common.FixRelayedMoveBalanceToNonPayableSCFlag))
}
Expand Down Expand Up @@ -447,7 +445,6 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) {
require.Equal(t, cfg.DynamicESDTEnableEpoch, handler.GetActivationEpoch(common.DynamicESDTFlag))
require.Equal(t, cfg.EGLDInMultiTransferEnableEpoch, handler.GetActivationEpoch(common.EGLDInESDTMultiTransferFlag))
require.Equal(t, cfg.CryptoOpcodesV2EnableEpoch, handler.GetActivationEpoch(common.CryptoOpcodesV2Flag))
require.Equal(t, cfg.RelayedTransactionsV3EnableEpoch, handler.GetActivationEpoch(common.RelayedTransactionsV3Flag))
require.Equal(t, cfg.FixRelayedBaseCostEnableEpoch, handler.GetActivationEpoch(common.FixRelayedBaseCostFlag))
require.Equal(t, cfg.MultiESDTNFTTransferAndExecuteByUserEnableEpoch, handler.GetActivationEpoch(common.MultiESDTNFTTransferAndExecuteByUserFlag))
require.Equal(t, cfg.FixRelayedMoveBalanceToNonPayableSCEnableEpoch, handler.GetActivationEpoch(common.FixRelayedMoveBalanceToNonPayableSCFlag))
Expand Down
7 changes: 0 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ type Config struct {
PeersRatingConfig PeersRatingConfig
PoolsCleanersConfig PoolsCleanersConfig
Redundancy RedundancyConfig

RelayedTransactionConfig RelayedTransactionConfig
}

// PeersRatingConfig will hold settings related to peers rating
Expand Down Expand Up @@ -642,8 +640,3 @@ type PoolsCleanersConfig struct {
type RedundancyConfig struct {
MaxRoundsOfInactivityAccepted int
}

// RelayedTransactionConfig represents the config options to be used for relayed transactions
type RelayedTransactionConfig struct {
MaxTransactionsAllowed int
}
1 change: 0 additions & 1 deletion config/epochConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ type EnableEpochs struct {
EGLDInMultiTransferEnableEpoch uint32
CryptoOpcodesV2EnableEpoch uint32
UnJailCleanupEnableEpoch uint32
RelayedTransactionsV3EnableEpoch uint32
FixRelayedBaseCostEnableEpoch uint32
MultiESDTNFTTransferAndExecuteByUserEnableEpoch uint32
FixRelayedMoveBalanceToNonPayableSCEnableEpoch uint32
Expand Down
Loading

0 comments on commit 17a4819

Please sign in to comment.