Skip to content

Commit

Permalink
Merge pull request #6588 from multiversx/merge-esdt-prefix-into-sover…
Browse files Browse the repository at this point in the history
…eign-7-nov

Merge esdt prefix into sovereign 7 nov
  • Loading branch information
axenteoctavian authored Nov 8, 2024
2 parents c07277c + ba448b5 commit 05db19a
Show file tree
Hide file tree
Showing 114 changed files with 2,102 additions and 4,478 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 @@ -947,6 +947,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

# ConsensusModelV2EnableEpoch represents the epoch when the consensus model V2 is enabled
ConsensusModelV2EnableEpoch = 2
Expand Down
2 changes: 1 addition & 1 deletion cmd/sovereignnode/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ require (
github.com/multiversx/mx-chain-scenario-go v1.4.4 // indirect
github.com/multiversx/mx-chain-storage-go v1.0.16 // indirect
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241008143259-334f3a5bafe0 // indirect
github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134141-bdba60bb6bcd // indirect
github.com/multiversx/mx-chain-vm-go v1.5.37 // indirect
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 // indirect
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 // indirect
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 // indirect
Expand Down
4 changes: 2 additions & 2 deletions cmd/sovereignnode/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1X
github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI=
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241008143259-334f3a5bafe0 h1:WpfFe6ueS+nRIq2RzVaeF1/TJStyYH/YLYPCmN8kdDM=
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241008143259-334f3a5bafe0/go.mod h1:IOE+gYAtTEKZJwUr9ZhOnjdf4vFKrZdZ9RVEyuFsEP4=
github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134141-bdba60bb6bcd h1:2vJk299/KQbtTE/dUmwFW8dkn0RTru0F7EqFqSyMneQ=
github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134141-bdba60bb6bcd/go.mod h1:EJF+vOF/9ZhACjcKhIeCUzr4CL31rWaeC9ReV8EJqfw=
github.com/multiversx/mx-chain-vm-go v1.5.37 h1:Iy3KCvM+DOq1f9UPA7uYK/rI3ZbBOXc2CVNO2/vm5zw=
github.com/multiversx/mx-chain-vm-go v1.5.37/go.mod h1:nzLrWeXvfxCIiwj5uNBZq3d7stkXyeY+Fktfr4tTaiY=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI=
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc=
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 @@ -766,12 +766,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 @@ -120,11 +120,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 @@ -325,7 +324,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))
require.True(t, handler.IsFlagEnabled(common.ConsensusModelV2Flag))
Expand Down Expand Up @@ -449,7 +447,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 @@ -229,8 +229,6 @@ type Config struct {
PoolsCleanersConfig PoolsCleanersConfig
Redundancy RedundancyConfig

RelayedTransactionConfig RelayedTransactionConfig

// TODO: (RaduChis): When we have separate factories to pass configs from node runners,
// we need to remove this from here
SovereignConfig SovereignConfig
Expand Down Expand Up @@ -646,8 +644,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 05db19a

Please sign in to comment.