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

Fixes outport refactor #5135

Merged
merged 4 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions outport/process/executionOrder/transactionsExecutionOrder.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (s *sorter) getInvalidTxsExecutedInCurrentBlock(scheduledMbsFromPreviousBlo
for _, hash := range mb.TxHashes {
_, found := allScheduledTxs[string(hash)]
if found {
scheduledExecutedInvalidTxsHashesPrevBlock = append(scheduledExecutedInvalidTxsHashesPrevBlock, string(hash))
scheduledExecutedInvalidTxsHashesPrevBlock = append(scheduledExecutedInvalidTxsHashesPrevBlock, hex.EncodeToString(hash))
Copy link
Contributor

Choose a reason for hiding this comment

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

is this still backward compatible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes is not a problem. because this part is used only in indexer

Copy link
Contributor

Choose a reason for hiding this comment

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

agree, did not noticed that the package was actually outport...

continue
}
invalidTxHashes = append(invalidTxHashes, hash)
Expand Down Expand Up @@ -249,9 +249,10 @@ func getRewardsTxsFromMe(pool *outport.TransactionPool, blockBody *block.Body, h
func extractTxsFromMap(txsHashes [][]byte, txs map[string]*outport.TxInfo) ([]data.TxWithExecutionOrderHandler, error) {
result := make([]data.TxWithExecutionOrderHandler, 0, len(txsHashes))
for _, txHash := range txsHashes {
tx, found := txs[string(txHash)]
txHashHex := hex.EncodeToString(txHash)
tx, found := txs[txHashHex]
if !found {
return nil, fmt.Errorf("cannot find transaction in pool, txHash: %s", hex.EncodeToString(txHash))
return nil, fmt.Errorf("cannot find transaction in pool, txHash: %s", txHashHex)
}
result = append(result, tx)
}
Expand All @@ -262,9 +263,10 @@ func extractTxsFromMap(txsHashes [][]byte, txs map[string]*outport.TxInfo) ([]da
func extractSCRsFromMap(txsHashes [][]byte, scrs map[string]*outport.SCRInfo) ([]data.TxWithExecutionOrderHandler, error) {
result := make([]data.TxWithExecutionOrderHandler, 0, len(txsHashes))
for _, txHash := range txsHashes {
scr, found := scrs[string(txHash)]
txHashHex := hex.EncodeToString(txHash)
scr, found := scrs[txHashHex]
if !found {
return nil, fmt.Errorf("cannot find scr in pool, txHash: %s", hex.EncodeToString(txHash))
return nil, fmt.Errorf("cannot find scr in pool, txHash: %s", txHashHex)
}
result = append(result, scr)
}
Expand All @@ -275,9 +277,10 @@ func extractSCRsFromMap(txsHashes [][]byte, scrs map[string]*outport.SCRInfo) ([
func extractRewardsFromMap(txsHashes [][]byte, rewards map[string]*outport.RewardInfo) ([]data.TxWithExecutionOrderHandler, error) {
result := make([]data.TxWithExecutionOrderHandler, 0, len(txsHashes))
for _, txHash := range txsHashes {
reward, found := rewards[string(txHash)]
txHashHex := hex.EncodeToString(txHash)
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we keep the hash in hex format? This degrades the performance of the node as the hex.EncodeToString is more CPU intensive than the regular cast to string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we need the transaction hash hex-encoded in order can send it over to the WS.
If I will let it non hex I will have problems with the marshaller because the hash is used as a string key in map structures.

Copy link
Contributor

Choose a reason for hiding this comment

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

agree, this does not degrade the performance of the validators as the code impacted is in outport... package

reward, found := rewards[txHashHex]
if !found {
return nil, fmt.Errorf("cannot find reward in pool, txHash: %s", hex.EncodeToString(txHash))
return nil, fmt.Errorf("cannot find reward in pool, txHash: %s", txHashHex)
}
result = append(result, reward)
}
Expand All @@ -299,7 +302,8 @@ func extractExecutedTxHashes(mbIndex int, mbTxHashes [][]byte, header data.Heade

func extractAndPutScrsToDestinationMap(scrsHashes [][]byte, scrsMap map[string]*outport.SCRInfo, destinationMap map[string]data.TxWithExecutionOrderHandler) {
for _, scrHash := range scrsHashes {
scr, found := scrsMap[string(scrHash)]
scrHashHex := hex.EncodeToString(scrHash)
scr, found := scrsMap[scrHashHex]
if !found {
continue
}
Expand Down
53 changes: 27 additions & 26 deletions outport/process/executionOrder/transactionsExecutionOrder_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package executionOrder

import (
"encoding/hex"
"testing"

"github.com/multiversx/mx-chain-core-go/core"
Expand Down Expand Up @@ -130,25 +131,25 @@ func TestAddExecutionOrderInTransactionPool(t *testing.T) {

pool := &outport.TransactionPool{
Transactions: map[string]*outport.TxInfo{
string(txHashToMe): {Transaction: &transaction.Transaction{Nonce: 1}},
string(txHashFromMe): {Transaction: &transaction.Transaction{Nonce: 2}},
hex.EncodeToString(txHashToMe): {Transaction: &transaction.Transaction{Nonce: 1}},
hex.EncodeToString(txHashFromMe): {Transaction: &transaction.Transaction{Nonce: 2}},
},
SmartContractResults: map[string]*outport.SCRInfo{
string(scrHashToMe): {SmartContractResult: &smartContractResult.SmartContractResult{Nonce: 3}},
string(scrHashFromMe): {SmartContractResult: &smartContractResult.SmartContractResult{
hex.EncodeToString(scrHashToMe): {SmartContractResult: &smartContractResult.SmartContractResult{Nonce: 3}},
hex.EncodeToString(scrHashFromMe): {SmartContractResult: &smartContractResult.SmartContractResult{
Nonce: 4,
OriginalTxHash: txHashToMe,
}},
string(scrHashIntra): {SmartContractResult: &smartContractResult.SmartContractResult{
hex.EncodeToString(scrHashIntra): {SmartContractResult: &smartContractResult.SmartContractResult{
Nonce: 0,
OriginalTxHash: txHashToMe,
}},
},
Rewards: map[string]*outport.RewardInfo{
string(rewardTxHash): {Reward: &rewardTx.RewardTx{}},
hex.EncodeToString(rewardTxHash): {Reward: &rewardTx.RewardTx{}},
},
InvalidTxs: map[string]*outport.TxInfo{
string(invalidTxHash): {Transaction: &transaction.Transaction{Nonce: 5}},
hex.EncodeToString(invalidTxHash): {Transaction: &transaction.Transaction{Nonce: 5}},
},
Receipts: map[string]*receipt.Receipt{},
Logs: nil,
Expand All @@ -159,28 +160,28 @@ func TestAddExecutionOrderInTransactionPool(t *testing.T) {

require.Equal(t, &outport.TransactionPool{
Transactions: map[string]*outport.TxInfo{
string(txHashToMe): {
hex.EncodeToString(txHashToMe): {
Transaction: &transaction.Transaction{Nonce: 1},
ExecutionOrder: 0,
},
string(txHashFromMe): {
hex.EncodeToString(txHashFromMe): {
Transaction: &transaction.Transaction{Nonce: 2},
ExecutionOrder: 3,
},
},
SmartContractResults: map[string]*outport.SCRInfo{
string(scrHashToMe): {
hex.EncodeToString(scrHashToMe): {
SmartContractResult: &smartContractResult.SmartContractResult{Nonce: 3},
ExecutionOrder: 1,
},
string(scrHashFromMe): {
hex.EncodeToString(scrHashFromMe): {
SmartContractResult: &smartContractResult.SmartContractResult{
Nonce: 4,
OriginalTxHash: txHashToMe,
},
ExecutionOrder: 0,
},
string(scrHashIntra): {
hex.EncodeToString(scrHashIntra): {
SmartContractResult: &smartContractResult.SmartContractResult{
Nonce: 0,
OriginalTxHash: txHashToMe,
Expand All @@ -189,13 +190,13 @@ func TestAddExecutionOrderInTransactionPool(t *testing.T) {
},
},
Rewards: map[string]*outport.RewardInfo{
string(rewardTxHash): {
hex.EncodeToString(rewardTxHash): {
Reward: &rewardTx.RewardTx{},
ExecutionOrder: 2,
},
},
InvalidTxs: map[string]*outport.TxInfo{
string(invalidTxHash): {
hex.EncodeToString(invalidTxHash): {
Transaction: &transaction.Transaction{Nonce: 5},
ExecutionOrder: 4,
},
Expand Down Expand Up @@ -256,8 +257,8 @@ func TestAddExecutionOrderInTransactionPoolFromMeTransactionAndScheduled(t *test

pool := &outport.TransactionPool{
Transactions: map[string]*outport.TxInfo{
string(firstTxHash): {Transaction: &transaction.Transaction{Nonce: 1}},
string(secondTxHash): {Transaction: &transaction.Transaction{Nonce: 2}},
hex.EncodeToString(firstTxHash): {Transaction: &transaction.Transaction{Nonce: 1}},
hex.EncodeToString(secondTxHash): {Transaction: &transaction.Transaction{Nonce: 2}},
},
}

Expand All @@ -266,11 +267,11 @@ func TestAddExecutionOrderInTransactionPoolFromMeTransactionAndScheduled(t *test

require.Equal(t, &outport.TransactionPool{
Transactions: map[string]*outport.TxInfo{
string(firstTxHash): {
hex.EncodeToString(firstTxHash): {
Transaction: &transaction.Transaction{Nonce: 1},
ExecutionOrder: 0,
},
string(secondTxHash): {
hex.EncodeToString(secondTxHash): {
Transaction: &transaction.Transaction{Nonce: 2},
ExecutionOrder: 1,
},
Expand Down Expand Up @@ -369,13 +370,13 @@ func TestAddExecutionOrderInTransactionPoolFromMeTransactionAndScheduledInvalid(

pool := &outport.TransactionPool{
Transactions: map[string]*outport.TxInfo{
string(secondTxHash): {Transaction: &transaction.Transaction{Nonce: 2}},
hex.EncodeToString(secondTxHash): {Transaction: &transaction.Transaction{Nonce: 2}},
},
InvalidTxs: map[string]*outport.TxInfo{
string(firstTxHash): {Transaction: &transaction.Transaction{Nonce: 1}},
hex.EncodeToString(firstTxHash): {Transaction: &transaction.Transaction{Nonce: 1}},
},
SmartContractResults: map[string]*outport.SCRInfo{
string(scrHash): {SmartContractResult: &smartContractResult.SmartContractResult{
hex.EncodeToString(scrHash): {SmartContractResult: &smartContractResult.SmartContractResult{
Nonce: 3,
OriginalTxHash: scheduledTx,
}},
Expand All @@ -386,19 +387,19 @@ func TestAddExecutionOrderInTransactionPoolFromMeTransactionAndScheduledInvalid(
require.Nil(t, err)
require.Equal(t, &outport.TransactionPool{
Transactions: map[string]*outport.TxInfo{
string(secondTxHash): {
hex.EncodeToString(secondTxHash): {
Transaction: &transaction.Transaction{Nonce: 2},
ExecutionOrder: 1,
},
},
InvalidTxs: map[string]*outport.TxInfo{
string(firstTxHash): {
hex.EncodeToString(firstTxHash): {
Transaction: &transaction.Transaction{Nonce: 1},
ExecutionOrder: 0,
},
},
SmartContractResults: map[string]*outport.SCRInfo{
string(scrHash): {
hex.EncodeToString(scrHash): {
SmartContractResult: &smartContractResult.SmartContractResult{
Nonce: 3,
OriginalTxHash: scheduledTx,
Expand All @@ -408,6 +409,6 @@ func TestAddExecutionOrderInTransactionPoolFromMeTransactionAndScheduledInvalid(
},
}, pool)

require.Equal(t, []string{string(scrHash)}, scrsHashes)
require.Equal(t, []string{string(scheduledInvalidTxHash)}, invalidTxsHashes)
require.Equal(t, []string{hex.EncodeToString(scrHash)}, scrsHashes)
require.Equal(t, []string{hex.EncodeToString(scheduledInvalidTxHash)}, invalidTxsHashes)
}