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

Relayed v3 with multiple transactions #6118

Open
wants to merge 17 commits into
base: feat/relayedv3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
248 changes: 141 additions & 107 deletions api/groups/transactionGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,35 +182,42 @@ func (tg *transactionGroup) simulateTransaction(c *gin.Context) {
return
}

var innerTx *transaction.Transaction
if ftx.InnerTransaction != nil {
if ftx.InnerTransaction.InnerTransaction != nil {
c.JSON(
http.StatusBadRequest,
shared.GenericAPIResponse{
Data: nil,
Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errors.ErrRecursiveRelayedTxIsNotAllowed.Error()),
Code: shared.ReturnCodeRequestError,
},
)
return
}
innerTxs := make([]*transaction.Transaction, 0, len(ftx.InnerTransactions))
if len(ftx.InnerTransactions) != 0 {
for _, innerTx := range ftx.InnerTransactions {
if len(innerTx.InnerTransactions) != 0 {
c.JSON(
http.StatusBadRequest,
shared.GenericAPIResponse{
Data: nil,
Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errors.ErrRecursiveRelayedTxIsNotAllowed.Error()),
Code: shared.ReturnCodeRequestError,
},
)
return
}

innerTx, _, err = tg.createTransaction(ftx.InnerTransaction, nil)
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
newInnerTx, _, err := tg.createTransaction(innerTx, nil)
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
}

innerTxs = append(innerTxs, newInnerTx)
}
}

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

var innerTx *transaction.Transaction
if ftx.InnerTransaction != nil {
if ftx.InnerTransaction.InnerTransaction != nil {
c.JSON(
http.StatusBadRequest,
shared.GenericAPIResponse{
Data: nil,
Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errors.ErrRecursiveRelayedTxIsNotAllowed.Error()),
Code: shared.ReturnCodeRequestError,
},
)
return
}
innerTxs := make([]*transaction.Transaction, 0, len(ftx.InnerTransactions))
if len(ftx.InnerTransactions) != 0 {
for _, innerTx := range ftx.InnerTransactions {
if len(innerTx.InnerTransactions) != 0 {
c.JSON(
http.StatusBadRequest,
shared.GenericAPIResponse{
Data: nil,
Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errors.ErrRecursiveRelayedTxIsNotAllowed.Error()),
Code: shared.ReturnCodeRequestError,
},
)
return
}

innerTx, _, err = tg.createTransaction(ftx.InnerTransaction, nil)
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
newInnerTx, _, err := tg.createTransaction(innerTx, nil)
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
}

innerTxs = append(innerTxs, newInnerTx)
}
}

tx, txHash, err := tg.createTransaction(&ftx, innerTx)
if len(innerTxs) == 0 {
innerTxs = nil
}
tx, txHash, err := tg.createTransaction(&ftx, innerTxs)
if err != nil {
c.JSON(
http.StatusBadRequest,
Expand Down Expand Up @@ -387,23 +401,36 @@ func (tg *transactionGroup) sendMultipleTransactions(c *gin.Context) {
var start time.Time
txsHashes := make(map[int]string)
for idx, receivedTx := range ftxs {
var innerTx *transaction.Transaction
if receivedTx.InnerTransaction != nil {
innerTx, _, err = tg.createTransaction(receivedTx.InnerTransaction, nil)
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
innerTxs := make([]*transaction.Transaction, 0, len(receivedTx.InnerTransactions))
if len(receivedTx.InnerTransactions) != 0 {
for _, innerTx := range receivedTx.InnerTransactions {
if len(innerTx.InnerTransactions) != 0 {
// if one of the inner txs is invalid, break the loop and move to the next transaction received
break
}

newInnerTx, _, err := tg.createTransaction(innerTx, nil)
if err != nil {
// if one of the inner txs is invalid, return bad request
c.JSON(
http.StatusBadRequest,
shared.GenericAPIResponse{
Data: nil,
Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()),
Code: shared.ReturnCodeInternalError,
},
)
return
}

innerTxs = append(innerTxs, newInnerTx)
}
}

tx, txHash, err = tg.createTransaction(&receivedTx, innerTx)
if len(innerTxs) == 0 {
innerTxs = nil
}
tx, txHash, err = tg.createTransaction(&receivedTx, innerTxs)
if err != nil {
continue
}
Expand Down Expand Up @@ -514,35 +541,42 @@ func (tg *transactionGroup) computeTransactionGasLimit(c *gin.Context) {
return
}

var innerTx *transaction.Transaction
if ftx.InnerTransaction != nil {
if ftx.InnerTransaction.InnerTransaction != nil {
c.JSON(
http.StatusBadRequest,
shared.GenericAPIResponse{
Data: nil,
Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errors.ErrRecursiveRelayedTxIsNotAllowed.Error()),
Code: shared.ReturnCodeRequestError,
},
)
return
}
innerTxs := make([]*transaction.Transaction, 0, len(ftx.InnerTransactions))
if len(ftx.InnerTransactions) != 0 {
for _, innerTx := range ftx.InnerTransactions {
if len(innerTx.InnerTransactions) != 0 {
c.JSON(
http.StatusBadRequest,
shared.GenericAPIResponse{
Data: nil,
Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errors.ErrRecursiveRelayedTxIsNotAllowed.Error()),
Code: shared.ReturnCodeRequestError,
},
)
return
}

innerTx, _, err = tg.createTransaction(ftx.InnerTransaction, nil)
if err != nil {
c.JSON(
http.StatusInternalServerError,
shared.GenericAPIResponse{
Data: nil,
Error: err.Error(),
Code: shared.ReturnCodeInternalError,
},
)
return
newInnerTx, _, err := tg.createTransaction(innerTx, nil)
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
}

innerTxs = append(innerTxs, newInnerTx)
}
}

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

func (tg *transactionGroup) createTransaction(receivedTx *transaction.FrontendTransaction, innerTx *transaction.Transaction) (*transaction.Transaction, []byte, error) {
func (tg *transactionGroup) createTransaction(receivedTx *transaction.FrontendTransaction, innerTxs []*transaction.Transaction) (*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,
InnerTransaction: innerTx,
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,
}
start := time.Now()
tx, txHash, err := tg.getFacade().CreateTransaction(txArgs)
Expand Down
4 changes: 2 additions & 2 deletions api/groups/transactionGroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1155,15 +1155,15 @@ func testRecursiveRelayedV3(url string) func(t *testing.T) {
value,
signature,
)
userTx2 := fmt.Sprintf(`{"nonce": %d, "sender":"%s", "receiver":"%s", "value":"%s", "signature":"%s", "innerTransaction":%s}`,
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", "innerTransaction":%s}`,
tx := fmt.Sprintf(`{"nonce": %d, "sender":"%s", "receiver":"%s", "value":"%s", "signature":"%s", "innerTransactions":[%s]}`,
nonce,
sender,
receiver,
Expand Down
3 changes: 3 additions & 0 deletions cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,6 @@
# 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: 7 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ type Config struct {
PeersRatingConfig PeersRatingConfig
PoolsCleanersConfig PoolsCleanersConfig
Redundancy RedundancyConfig

RelayedTransactionConfig RelayedTransactionConfig
}

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

// RelayedTransactionConfig represents the config options to be used for relayed transactions
type RelayedTransactionConfig struct {
MaxTransactionsAllowed int
}
22 changes: 11 additions & 11 deletions dataRetriever/txpool/memorytests/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ func TestShardedTxPool_MemoryFootprint(t *testing.T) {
journals = append(journals, runScenario(t, newScenario(200, 1, core.MegabyteSize, "0"), memoryAssertion{200, 200}, memoryAssertion{0, 1}))
journals = append(journals, runScenario(t, newScenario(10, 1000, 20480, "0"), memoryAssertion{190, 205}, memoryAssertion{1, 4}))
journals = append(journals, runScenario(t, newScenario(10000, 1, 1024, "0"), memoryAssertion{10, 16}, memoryAssertion{4, 10}))
journals = append(journals, runScenario(t, newScenario(1, 60000, 256, "0"), memoryAssertion{30, 38}, memoryAssertion{10, 16}))
journals = append(journals, runScenario(t, newScenario(10, 10000, 100, "0"), memoryAssertion{36, 50}, memoryAssertion{16, 24}))
journals = append(journals, runScenario(t, newScenario(100000, 1, 1024, "0"), memoryAssertion{120, 136}, memoryAssertion{56, 60}))
journals = append(journals, runScenario(t, newScenario(1, 60000, 256, "0"), memoryAssertion{30, 40}, memoryAssertion{10, 16}))
journals = append(journals, runScenario(t, newScenario(10, 10000, 100, "0"), memoryAssertion{36, 52}, memoryAssertion{16, 24}))
journals = append(journals, runScenario(t, newScenario(100000, 1, 1024, "0"), memoryAssertion{120, 138}, memoryAssertion{56, 60}))

// With larger memory footprint

journals = append(journals, runScenario(t, newScenario(100000, 3, 650, "0"), memoryAssertion{290, 330}, memoryAssertion{95, 120}))
journals = append(journals, runScenario(t, newScenario(150000, 2, 650, "0"), memoryAssertion{290, 330}, memoryAssertion{120, 140}))
journals = append(journals, runScenario(t, newScenario(300000, 1, 650, "0"), memoryAssertion{290, 330}, memoryAssertion{170, 190}))
journals = append(journals, runScenario(t, newScenario(30, 10000, 650, "0"), memoryAssertion{290, 330}, memoryAssertion{60, 75}))
journals = append(journals, runScenario(t, newScenario(300, 1000, 650, "0"), memoryAssertion{290, 330}, memoryAssertion{60, 80}))
journals = append(journals, runScenario(t, newScenario(100000, 3, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{95, 120}))
journals = append(journals, runScenario(t, newScenario(150000, 2, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{120, 140}))
journals = append(journals, runScenario(t, newScenario(300000, 1, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{170, 190}))
journals = append(journals, runScenario(t, newScenario(30, 10000, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{60, 75}))
journals = append(journals, runScenario(t, newScenario(300, 1000, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{60, 80}))

// Scenarios where destination == me

journals = append(journals, runScenario(t, newScenario(100, 1, core.MegabyteSize, "1_0"), memoryAssertion{90, 100}, memoryAssertion{0, 1}))
journals = append(journals, runScenario(t, newScenario(10000, 1, 10240, "1_0"), memoryAssertion{96, 128}, memoryAssertion{0, 4}))
journals = append(journals, runScenario(t, newScenario(10, 10000, 1000, "1_0"), memoryAssertion{96, 136}, memoryAssertion{16, 25}))
journals = append(journals, runScenario(t, newScenario(150000, 1, 128, "1_0"), memoryAssertion{50, 75}, memoryAssertion{30, 40}))
journals = append(journals, runScenario(t, newScenario(1, 150000, 128, "1_0"), memoryAssertion{50, 75}, memoryAssertion{30, 40}))
journals = append(journals, runScenario(t, newScenario(10, 10000, 1000, "1_0"), memoryAssertion{96, 140}, memoryAssertion{16, 25}))
journals = append(journals, runScenario(t, newScenario(150000, 1, 128, "1_0"), memoryAssertion{50, 80}, memoryAssertion{30, 40}))
journals = append(journals, runScenario(t, newScenario(1, 150000, 128, "1_0"), memoryAssertion{50, 80}, memoryAssertion{30, 40}))

for _, journal := range journals {
journal.displayFootprintsSummary()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
disabledFactory "github.com/multiversx/mx-chain-go/factory/disabled"
disabledGenesis "github.com/multiversx/mx-chain-go/genesis/process/disabled"
"github.com/multiversx/mx-chain-go/process"
processDisabled "github.com/multiversx/mx-chain-go/process/disabled"
"github.com/multiversx/mx-chain-go/process/factory/interceptorscontainer"
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/storage/cache"
Expand Down Expand Up @@ -108,6 +109,7 @@ func NewEpochStartInterceptorsContainer(args ArgsEpochStartInterceptorContainer)
FullArchivePeerShardMapper: fullArchivePeerShardMapper,
HardforkTrigger: hardforkTrigger,
NodeOperationMode: args.NodeOperationMode,
RelayedTxV3Processor: processDisabled.NewRelayedTxV3Processor(),
}

interceptorsContainerFactory, err := interceptorscontainer.NewMetaInterceptorsContainerFactory(containerFactoryArgs)
Expand Down