Skip to content

Commit

Permalink
Merge branch 'feat/chain-go-sdk' into sov-github-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
axenteoctavian authored Jan 31, 2025
2 parents fe0ed52 + ddaa9da commit a5cb1e6
Show file tree
Hide file tree
Showing 221 changed files with 6,783 additions and 1,547 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
15 changes: 9 additions & 6 deletions cmd/node/config/enableEpochs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -313,25 +313,28 @@
UseGasBoundedShouldFailExecutionEnableEpoch = 1

# DynamicESDTEnableEpoch represents the epoch when dynamic NFT feature is enabled
DynamicESDTEnableEpoch = 4
DynamicESDTEnableEpoch = 1

# EGLDInMultiTransferEnableEpoch represents the epoch when EGLD in multitransfer is enabled
EGLDInMultiTransferEnableEpoch = 4
EGLDInMultiTransferEnableEpoch = 1

# CryptoOpcodesV2EnableEpoch represents the epoch when BLSMultiSig, Secp256r1 and other opcodes are enabled
CryptoOpcodesV2EnableEpoch = 4
CryptoOpcodesV2EnableEpoch = 1

# UnjailCleanupEnableEpoch represents the epoch when the cleanup of the unjailed nodes is enabled
UnJailCleanupEnableEpoch = 4
UnJailCleanupEnableEpoch = 1

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

# 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 = 4
FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 1

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

# ConsensusModelV2EnableEpoch represents the epoch when the consensus model V2 is enabled
ConsensusModelV2EnableEpoch = 2
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
13 changes: 10 additions & 3 deletions cmd/sovereignnode/chainSimulator/sovereignChainSimulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func NewSovereignChainSimulator(args ArgsSovereignChainSimulator) (chainSimulato
cfg.GeneralConfig.VirtualMachine.Execution.WasmVMVersions = []config.WasmVMVersionByEpoch{{StartEpoch: 0, Version: "v1.5"}}
cfg.GeneralConfig.VirtualMachine.Querying.WasmVMVersions = []config.WasmVMVersionByEpoch{{StartEpoch: 0, Version: "v1.5"}}
cfg.SystemSCConfig.ESDTSystemSCConfig.ESDTPrefix = "sov"
cfg.GeneralConfig.Versions.VersionsByEpochs = []config.VersionByEpochs{{StartEpoch: 0, Version: string(process.SovereignHeaderVersion)}}

if alterConfigs != nil {
alterConfigs(cfg)
Expand All @@ -52,7 +53,7 @@ func NewSovereignChainSimulator(args ArgsSovereignChainSimulator) (chainSimulato
}

args.CreateRunTypeCoreComponents = func() (factory.RunTypeCoreComponentsHolder, error) {
return createSovereignRunTypeCoreComponents()
return createSovereignRunTypeCoreComponents(*configs.SovereignEpochConfig)
}
args.CreateIncomingHeaderSubscriber = func(config config.WebSocketConfig, dataPool dataRetriever.PoolsHolder, mainChainNotarizationStartRound uint64, runTypeComponents factory.RunTypeComponentsHolder) (process.IncomingHeaderSubscriber, error) {
return incomingHeader.CreateIncomingHeaderProcessor(config, dataPool, mainChainNotarizationStartRound, runTypeComponents)
Expand Down Expand Up @@ -85,17 +86,23 @@ func loadSovereignConfigs(configsPath string) (*sovereignConfig.SovereignConfig,
return nil, err
}

sovereignEpochConfig, err := sovereignConfig.LoadSovereignEpochConfig(path.Join(configsPath, "enableEpochs.toml"))
if err != nil {
return nil, err
}

return &sovereignConfig.SovereignConfig{
Configs: &config.Configs{
EpochConfig: epochConfig,
EconomicsConfig: economicsConfig,
},
SovereignExtraConfig: sovereignExtraConfig,
SovereignEpochConfig: sovereignEpochConfig,
}, nil
}

func createSovereignRunTypeCoreComponents() (factory.RunTypeCoreComponentsHolder, error) {
sovereignRunTypeCoreComponentsFactory := runType.NewSovereignRunTypeCoreComponentsFactory()
func createSovereignRunTypeCoreComponents(sovereignEpochConfig config.SovereignEpochConfig) (factory.RunTypeCoreComponentsHolder, error) {
sovereignRunTypeCoreComponentsFactory := runType.NewSovereignRunTypeCoreComponentsFactory(sovereignEpochConfig)
managedRunTypeCoreComponents, err := runType.NewManagedRunTypeCoreComponents(sovereignRunTypeCoreComponentsFactory)
if err != nil {
return nil, err
Expand Down
15 changes: 9 additions & 6 deletions cmd/sovereignnode/chainSimulator/sovereignChainSimulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"testing"
"time"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/stretchr/testify/require"

chainSimulatorCommon "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator"
chainSim "github.com/multiversx/mx-chain-go/node/chainSimulator"
"github.com/multiversx/mx-chain-go/node/chainSimulator/components/api"
"github.com/multiversx/mx-chain-go/node/chainSimulator/dtos"

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

const (
Expand Down Expand Up @@ -57,9 +57,12 @@ func TestChainSimulator_GenerateBlocksShouldWork(t *testing.T) {
PathToInitialConfig: defaultPathToInitialConfig,
GenesisTimestamp: time.Now().Unix(),
RoundDurationInMillis: uint64(6000),
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
RoundsPerEpoch: core.OptionalUint64{
HasValue: true,
Value: 20,
},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
},
})
require.Nil(t, err)
Expand Down
12 changes: 12 additions & 0 deletions cmd/sovereignnode/config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

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

"github.com/multiversx/mx-chain-go/config"
)

Expand All @@ -15,3 +16,14 @@ func LoadSovereignGeneralConfig(filepath string) (*config.SovereignConfig, error

return cfg, nil
}

// LoadSovereignEpochConfig returns the epoch config necessary by sovereign by reading it from the provided file
func LoadSovereignEpochConfig(filepath string) (*config.SovereignEpochConfig, error) {
cfg := &config.SovereignEpochConfig{}
err := core.LoadTomlFile(cfg, filepath)
if err != nil {
return nil, err
}

return cfg, nil
}
1 change: 1 addition & 0 deletions cmd/sovereignnode/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ import "github.com/multiversx/mx-chain-go/config"
type SovereignConfig struct {
*config.Configs
SovereignExtraConfig *config.SovereignConfig
SovereignEpochConfig *config.SovereignEpochConfig
}
Loading

0 comments on commit a5cb1e6

Please sign in to comment.