Skip to content

Commit

Permalink
Merge pull request #6756 from multiversx/merge-rc/barnard-in-feat/acc…
Browse files Browse the repository at this point in the history
…ounts-storage-iterator-29jan

Merge rc/barnard in feat/accounts storage iterator 29jan
  • Loading branch information
BeniaminDrasovean authored Jan 29, 2025
2 parents 42292a0 + 491e963 commit e71d7bd
Show file tree
Hide file tree
Showing 154 changed files with 5,271 additions and 1,073 deletions.
8 changes: 7 additions & 1 deletion api/groups/blockGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
urlParamTokensFilter = "tokens"
urlParamWithTxs = "withTxs"
urlParamWithLogs = "withLogs"
urlParamForHyperblock = "forHyperblock"
)

// blockFacadeHandler defines the methods to be implemented by a facade for handling block requests
Expand Down Expand Up @@ -219,7 +220,12 @@ func parseBlockQueryOptions(c *gin.Context) (api.BlockQueryOptions, error) {
return api.BlockQueryOptions{}, err
}

options := api.BlockQueryOptions{WithTransactions: withTxs, WithLogs: withLogs}
forHyperBlock, err := parseBoolUrlParam(c, urlParamForHyperblock)
if err != nil {
return api.BlockQueryOptions{}, err
}

options := api.BlockQueryOptions{WithTransactions: withTxs, WithLogs: withLogs, ForHyperblock: forHyperBlock}
return options, nil
}

Expand Down
4 changes: 2 additions & 2 deletions api/groups/blockGroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestBlockGroup_getBlockByNonce(t *testing.T) {
t.Parallel()

providedNonce := uint64(37)
expectedOptions := api.BlockQueryOptions{WithTransactions: true}
expectedOptions := api.BlockQueryOptions{WithTransactions: true, ForHyperblock: true}
expectedBlock := api.Block{
Nonce: 37,
Round: 39,
Expand All @@ -107,7 +107,7 @@ func TestBlockGroup_getBlockByNonce(t *testing.T) {
loadBlockGroupResponse(
t,
facade,
fmt.Sprintf("/block/by-nonce/%d?withTxs=true", providedNonce),
fmt.Sprintf("/block/by-nonce/%d?withTxs=true&forHyperblock=true", providedNonce),
"GET",
nil,
response,
Expand Down
2 changes: 1 addition & 1 deletion api/groups/networkGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func NewNetworkGroup(facade networkFacadeHandler) (*networkGroup, error) {
{
Path: getNFTsPath,
Method: http.MethodGet,
Handler: ng.getHandlerFuncForEsdt(core.NonFungibleESDT),
Handler: ng.getHandlerFuncForEsdt(core.NonFungibleESDTv2),
},
{
Path: directStakedInfoPath,
Expand Down
30 changes: 30 additions & 0 deletions api/groups/networkGroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,36 @@ func TestNetworkConfigMetrics_GasLimitGuardedTxShouldWork(t *testing.T) {
assert.True(t, keyAndValueFoundInResponse)
}

func TestNetworkConfigMetrics_GasLimitRelayedTxShouldWork(t *testing.T) {
t.Parallel()

statusMetricsProvider := statusHandler.NewStatusMetrics()
key := common.MetricExtraGasLimitRelayedTx
val := uint64(123)
statusMetricsProvider.SetUInt64Value(key, val)

facade := mock.FacadeStub{}
facade.StatusMetricsHandler = func() external.StatusMetricsHandler {
return statusMetricsProvider
}

networkGroup, err := groups.NewNetworkGroup(&facade)
require.NoError(t, err)

ws := startWebServer(networkGroup, "network", getNetworkRoutesConfig())

req, _ := http.NewRequest("GET", "/network/config", nil)
resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)

respBytes, _ := io.ReadAll(resp.Body)
respStr := string(respBytes)
assert.Equal(t, resp.Code, http.StatusOK)

keyAndValueFoundInResponse := strings.Contains(respStr, key) && strings.Contains(respStr, fmt.Sprintf("%d", val))
assert.True(t, keyAndValueFoundInResponse)
}

func TestNetworkStatusMetrics_ShouldWork(t *testing.T) {
t.Parallel()

Expand Down
32 changes: 17 additions & 15 deletions api/groups/transactionGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,21 +720,23 @@ func (tg *transactionGroup) getTransactionsPoolNonceGapsForSender(sender string,

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,
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.RelayerAddr,
RelayerSignatureHex: receivedTx.RelayerSignature,
}
start := time.Now()
tx, txHash, err := tg.getFacade().CreateTransaction(txArgs)
Expand Down
4 changes: 2 additions & 2 deletions cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@
[TxDataPool]
Name = "TxDataPool"
Capacity = 600000
SizePerSender = 20000
SizePerSender = 5001
SizeInBytes = 419430400 #400MB
SizeInBytesPerSender = 12288000
SizeInBytesPerSender = 12288000 #12MB
Type = "TxCache"
Shards = 16

Expand Down
3 changes: 3 additions & 0 deletions cmd/node/config/enableEpochs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@
# FixRelayedMoveBalanceToNonPayableSCEnableEpoch represents the epoch when the fix for relayed move balance to non payable sc will be enabled
FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 1

# RelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions v3 will be enabled
RelayedTransactionsV3EnableEpoch = 2

# BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers
BLSMultiSignerEnableEpoch = [
{ EnableEpoch = 0, Type = "no-KOSK" },
Expand Down
1 change: 1 addition & 0 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ func attachFileLogger(log logger.Logger, flagsConfig *config.ContextFlagsConfig)
logger.ToggleCorrelation(flagsConfig.EnableLogCorrelation)
logger.ToggleLoggerName(flagsConfig.EnableLogName)
logLevelFlagValue := flagsConfig.LogLevel

err = logger.SetLogLevel(logLevelFlagValue)
if err != nil {
return nil, err
Expand Down
26 changes: 26 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package common

import "github.com/multiversx/mx-chain-core-go/data"

// IsValidRelayedTxV3 returns true if the provided transaction is a valid transaction of type relayed v3
func IsValidRelayedTxV3(tx data.TransactionHandler) bool {
relayedTx, isRelayedV3 := tx.(data.RelayedTransactionHandler)
if !isRelayedV3 {
return false
}
hasValidRelayer := len(relayedTx.GetRelayerAddr()) == len(tx.GetSndAddr()) && len(relayedTx.GetRelayerAddr()) > 0
hasValidRelayerSignature := len(relayedTx.GetRelayerSignature()) == len(relayedTx.GetSignature()) && len(relayedTx.GetRelayerSignature()) > 0
return hasValidRelayer && hasValidRelayerSignature
}

// IsRelayedTxV3 returns true if the provided transaction is a transaction of type relayed v3, without any further checks
func IsRelayedTxV3(tx data.TransactionHandler) bool {
relayedTx, isRelayedV3 := tx.(data.RelayedTransactionHandler)
if !isRelayedV3 {
return false
}

hasRelayer := len(relayedTx.GetRelayerAddr()) > 0
hasRelayerSignature := len(relayedTx.GetRelayerSignature()) > 0
return hasRelayer || hasRelayerSignature
}
70 changes: 70 additions & 0 deletions common/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package common

import (
"math/big"
"testing"

"github.com/multiversx/mx-chain-core-go/data/smartContractResult"
"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/stretchr/testify/require"
)

func TestIsValidRelayedTxV3(t *testing.T) {
t.Parallel()

scr := &smartContractResult.SmartContractResult{}
require.False(t, IsValidRelayedTxV3(scr))
require.False(t, IsRelayedTxV3(scr))

notRelayedTxV3 := &transaction.Transaction{
Nonce: 1,
Value: big.NewInt(100),
RcvAddr: []byte("receiver"),
SndAddr: []byte("sender0"),
GasPrice: 100,
GasLimit: 10,
Signature: []byte("signature"),
}
require.False(t, IsValidRelayedTxV3(notRelayedTxV3))
require.False(t, IsRelayedTxV3(notRelayedTxV3))

invalidRelayedTxV3 := &transaction.Transaction{
Nonce: 1,
Value: big.NewInt(100),
RcvAddr: []byte("receiver"),
SndAddr: []byte("sender0"),
GasPrice: 100,
GasLimit: 10,
Signature: []byte("signature"),
RelayerAddr: []byte("relayer"),
}
require.False(t, IsValidRelayedTxV3(invalidRelayedTxV3))
require.True(t, IsRelayedTxV3(invalidRelayedTxV3))

invalidRelayedTxV3 = &transaction.Transaction{
Nonce: 1,
Value: big.NewInt(100),
RcvAddr: []byte("receiver"),
SndAddr: []byte("sender0"),
GasPrice: 100,
GasLimit: 10,
Signature: []byte("signature"),
RelayerSignature: []byte("signature"),
}
require.False(t, IsValidRelayedTxV3(invalidRelayedTxV3))
require.True(t, IsRelayedTxV3(invalidRelayedTxV3))

relayedTxV3 := &transaction.Transaction{
Nonce: 1,
Value: big.NewInt(100),
RcvAddr: []byte("receiver"),
SndAddr: []byte("sender1"),
GasPrice: 100,
GasLimit: 10,
Signature: []byte("signature"),
RelayerAddr: []byte("relayer"),
RelayerSignature: []byte("signature"),
}
require.True(t, IsValidRelayedTxV3(relayedTxV3))
require.True(t, IsRelayedTxV3(relayedTxV3))
}
7 changes: 7 additions & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ const MetricMinGasLimit = "erd_min_gas_limit"
// MetricExtraGasLimitGuardedTx specifies the extra gas limit required for guarded transactions
const MetricExtraGasLimitGuardedTx = "erd_extra_gas_limit_guarded_tx"

// MetricExtraGasLimitRelayedTx specifies the extra gas limit required for relayed v3 transactions
const MetricExtraGasLimitRelayedTx = "erd_extra_gas_limit_relayed_tx"

// MetricRewardsTopUpGradientPoint is the metric that specifies the rewards top up gradient point
const MetricRewardsTopUpGradientPoint = "erd_rewards_top_up_gradient_point"

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

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

// MetricMaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch
MetricMaxNodesChangeEnableEpoch = "erd_max_nodes_change_enable_epoch"

Expand Down Expand Up @@ -1234,5 +1240,6 @@ const (
FixRelayedBaseCostFlag core.EnableEpochFlag = "FixRelayedBaseCostFlag"
MultiESDTNFTTransferAndExecuteByUserFlag core.EnableEpochFlag = "MultiESDTNFTTransferAndExecuteByUserFlag"
FixRelayedMoveBalanceToNonPayableSCFlag core.EnableEpochFlag = "FixRelayedMoveBalanceToNonPayableSCFlag"
RelayedTransactionsV3Flag core.EnableEpochFlag = "RelayedTransactionsV3Flag"
// all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined
)
6 changes: 6 additions & 0 deletions common/enablers/enableEpochsHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,12 @@ func (handler *enableEpochsHandler) createAllFlagsMap() {
},
activationEpoch: handler.enableEpochsConfig.FixRelayedMoveBalanceToNonPayableSCEnableEpoch,
},
common.RelayedTransactionsV3Flag: {
isActiveInEpoch: func(epoch uint32) bool {
return epoch >= handler.enableEpochsConfig.RelayedTransactionsV3EnableEpoch
},
activationEpoch: handler.enableEpochsConfig.RelayedTransactionsV3EnableEpoch,
},
}
}

Expand Down
2 changes: 2 additions & 0 deletions common/enablers/enableEpochsHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func createEnableEpochsConfig() config.EnableEpochs {
MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 106,
FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 107,
UseGasBoundedShouldFailExecutionEnableEpoch: 108,
RelayedTransactionsV3EnableEpoch: 109,
}
}

Expand Down Expand Up @@ -448,6 +449,7 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) {
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))
require.Equal(t, cfg.RelayedTransactionsV3EnableEpoch, handler.GetActivationEpoch(common.RelayedTransactionsV3Flag))
}

func TestEnableEpochsHandler_IsInterfaceNil(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions common/reflectcommon/structFieldsUpdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func trySetTheNewValue(value *reflect.Value, newValue interface{}) error {
case reflect.Map:
mapValue := reflect.ValueOf(newValue)

return tryUpdateMapValue(value, mapValue)
return trySetMapValue(value, mapValue)
default:
return fmt.Errorf("unsupported type <%s> when trying to set the value '%v' of type <%s>", valueKind, newValue, reflect.TypeOf(newValue))
}
Expand All @@ -141,7 +141,7 @@ func trySetSliceValue(value *reflect.Value, newValue interface{}) error {
item := sliceVal.Index(i)
newItem := reflect.New(value.Type().Elem()).Elem()

err := trySetStructValue(&newItem, item)
err := trySetTheNewValue(&newItem, item.Interface())
if err != nil {
return err
}
Expand All @@ -167,7 +167,7 @@ func trySetStructValue(value *reflect.Value, newValue reflect.Value) error {
}
}

func tryUpdateMapValue(value *reflect.Value, newValue reflect.Value) error {
func trySetMapValue(value *reflect.Value, newValue reflect.Value) error {
if value.IsNil() {
value.Set(reflect.MakeMap(value.Type()))
}
Expand Down
Loading

0 comments on commit e71d7bd

Please sign in to comment.