Skip to content

Commit

Permalink
Merge branch 'feat/demo-refactor' into MX-14985-sovereign-config-xday
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusmihaic authored Jan 30, 2024
2 parents cfa54cb + a8de4a2 commit 26bc5f8
Show file tree
Hide file tree
Showing 45 changed files with 1,369 additions and 241 deletions.
55 changes: 30 additions & 25 deletions cmd/sovereignnode/sovereignNodeRunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import (
"github.com/multiversx/mx-chain-go/health"
"github.com/multiversx/mx-chain-go/node"
"github.com/multiversx/mx-chain-go/node/metrics"
trieIteratorsFactory "github.com/multiversx/mx-chain-go/node/trieIterators/factory"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/process/block/preprocess"
"github.com/multiversx/mx-chain-go/process/factory/interceptorscontainer"
Expand Down Expand Up @@ -518,7 +519,7 @@ func (snr *sovereignNodeRunner) executeOneComponentCreationCycle(
n.AddClosableComponent(sovereignWsReceiver)
return nil
}
currentNode, err := node.CreateNode(
nodeHandler, err := node.CreateNode(
configs.GeneralConfig,
managedStatusCoreComponents,
managedBootstrapComponents,
Expand All @@ -533,6 +534,7 @@ func (snr *sovereignNodeRunner) executeOneComponentCreationCycle(
managedConsensusComponents,
flagsConfig.BootstrapRoundIndex,
configs.ImportDbConfig.IsImportDBMode,
node.NewSovereignNodeFactory(),
extraOption,
)
if err != nil {
Expand All @@ -543,7 +545,7 @@ func (snr *sovereignNodeRunner) executeOneComponentCreationCycle(
allowExternalVMQueriesChan := make(chan struct{})

log.Debug("updating the API service after creating the node facade")
ef, err := snr.createApiFacade(currentNode, webServerHandler, gasScheduleNotifier, allowExternalVMQueriesChan)
ef, err := snr.createApiFacade(nodeHandler, webServerHandler, gasScheduleNotifier, allowExternalVMQueriesChan)
if err != nil {
return true, err
}
Expand Down Expand Up @@ -571,7 +573,7 @@ func (snr *sovereignNodeRunner) executeOneComponentCreationCycle(
healthService,
ef,
webServerHandler,
currentNode,
nodeHandler,
goRoutinesNumberStart,
)
if err != nil {
Expand Down Expand Up @@ -668,7 +670,7 @@ func getBaseAccountSyncerArgs(
}

func (snr *sovereignNodeRunner) createApiFacade(
currentNode *node.Node,
nodeHandler node.NodeHandler,
upgradableHttpServer shared.UpgradeableHttpServerHandler,
gasScheduleNotifier common.GasScheduleNotifierAPI,
allowVMQueriesChan chan struct{},
Expand All @@ -678,19 +680,22 @@ func (snr *sovereignNodeRunner) createApiFacade(
log.Debug("creating api resolver structure")

apiResolverArgs := &apiComp.ApiResolverArgs{
Configs: configs.Configs,
CoreComponents: currentNode.GetCoreComponents(),
DataComponents: currentNode.GetDataComponents(),
StateComponents: currentNode.GetStateComponents(),
BootstrapComponents: currentNode.GetBootstrapComponents(),
CryptoComponents: currentNode.GetCryptoComponents(),
ProcessComponents: currentNode.GetProcessComponents(),
StatusCoreComponents: currentNode.GetStatusCoreComponents(),
GasScheduleNotifier: gasScheduleNotifier,
Bootstrapper: currentNode.GetConsensusComponents().Bootstrapper(),
AllowVMQueriesChan: allowVMQueriesChan,
StatusComponents: currentNode.GetStatusComponents(),
ChainRunType: common.ChainRunTypeSovereign,
Configs: configs.Configs,
CoreComponents: nodeHandler.GetCoreComponents(),
DataComponents: nodeHandler.GetDataComponents(),
StateComponents: nodeHandler.GetStateComponents(),
BootstrapComponents: nodeHandler.GetBootstrapComponents(),
CryptoComponents: nodeHandler.GetCryptoComponents(),
ProcessComponents: nodeHandler.GetProcessComponents(),
StatusCoreComponents: nodeHandler.GetStatusCoreComponents(),
GasScheduleNotifier: gasScheduleNotifier,
Bootstrapper: nodeHandler.GetConsensusComponents().Bootstrapper(),
AllowVMQueriesChan: allowVMQueriesChan,
StatusComponents: nodeHandler.GetStatusComponents(),
ChainRunType: common.ChainRunTypeSovereign,
DelegatedListFactoryHandler: trieIteratorsFactory.NewSovereignDelegatedListProcessorFactory(),
DirectStakedListFactoryHandler: trieIteratorsFactory.NewSovereignDirectStakedListProcessorFactory(),
TotalStakedValueFactoryHandler: trieIteratorsFactory.NewSovereignTotalStakedValueProcessorFactory(),
}

apiResolver, err := apiComp.CreateApiResolver(apiResolverArgs)
Expand All @@ -703,7 +708,7 @@ func (snr *sovereignNodeRunner) createApiFacade(
flagsConfig := configs.FlagsConfig

argNodeFacade := facade.ArgNodeFacade{
Node: currentNode,
Node: nodeHandler,
ApiResolver: apiResolver,
RestAPIServerDebugMode: flagsConfig.EnableRestAPIServerDebugMode,
WsAntifloodConfig: configs.GeneralConfig.WebServerAntiflood,
Expand All @@ -712,17 +717,17 @@ func (snr *sovereignNodeRunner) createApiFacade(
PprofEnabled: flagsConfig.EnablePprof,
},
ApiRoutesConfig: *configs.ApiRoutesConfig,
AccountsState: currentNode.GetStateComponents().AccountsAdapter(),
PeerState: currentNode.GetStateComponents().PeerAccounts(),
Blockchain: currentNode.GetDataComponents().Blockchain(),
AccountsState: nodeHandler.GetStateComponents().AccountsAdapter(),
PeerState: nodeHandler.GetStateComponents().PeerAccounts(),
Blockchain: nodeHandler.GetDataComponents().Blockchain(),
}

ef, err := facade.NewNodeFacade(argNodeFacade)
if err != nil {
return nil, fmt.Errorf("%w while creating NodeFacade", err)
}

ef.SetSyncer(currentNode.GetCoreComponents().SyncTimer())
ef.SetSyncer(nodeHandler.GetCoreComponents().SyncTimer())

err = upgradableHttpServer.UpdateFacade(ef)
if err != nil {
Expand Down Expand Up @@ -925,7 +930,7 @@ func waitForSignal(
healthService closing.Closer,
ef closing.Closer,
httpServer shared.UpgradeableHttpServerHandler,
currentNode *node.Node,
nodeHandler node.NodeHandler,
goRoutinesNumberStart int,
) error {
var sig endProcess.ArgEndProcess
Expand All @@ -949,7 +954,7 @@ func waitForSignal(

chanCloseComponents := make(chan struct{})
go func() {
closeAllComponents(healthService, ef, httpServer, currentNode, chanCloseComponents)
closeAllComponents(healthService, ef, httpServer, nodeHandler, chanCloseComponents)
}()

select {
Expand Down Expand Up @@ -1536,7 +1541,7 @@ func closeAllComponents(
healthService io.Closer,
facade mainFactory.Closer,
httpServer shared.UpgradeableHttpServerHandler,
node *node.Node,
node node.NodeHandler,
chanCloseComponents chan struct{},
) {
log.Debug("closing health service...")
Expand Down
3 changes: 3 additions & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,3 +655,6 @@ var ErrInvalidReceivedExtendedShardHeader = errors.New("invalid extended shard h

// ErrNilTxPreProcessorCreator signals that a nil tx pre-processor creator has been provided
var ErrNilTxPreProcessorCreator = errors.New("nil tx pre-processor creator has been provided")

// ErrNilNode signals that a nil node was provided
var ErrNilNode = errors.New("nil node")
3 changes: 0 additions & 3 deletions facade/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import "github.com/pkg/errors"
// ErrHeartbeatsNotActive signals that the heartbeat system is not active
var ErrHeartbeatsNotActive = errors.New("heartbeat system not active")

// ErrNilNode signals that a nil node instance has been provided
var ErrNilNode = errors.New("nil node")

// ErrNilApiResolver signals that a nil api resolver instance has been provided
var ErrNilApiResolver = errors.New("nil api resolver")

Expand Down
7 changes: 4 additions & 3 deletions facade/nodeFacade.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/debug"
"github.com/multiversx/mx-chain-go/epochStart/bootstrap/disabled"
"github.com/multiversx/mx-chain-go/errors"
"github.com/multiversx/mx-chain-go/heartbeat/data"
"github.com/multiversx/mx-chain-go/node/external"
"github.com/multiversx/mx-chain-go/ntp"
Expand All @@ -36,7 +37,7 @@ import (
const DefaultRestInterface = "localhost:8080"

// DefaultRestPortOff is the default value that should be passed if it is desired
// to start the node without a REST endpoint available
// to start the node without a REST endpoint available
const DefaultRestPortOff = "off"

var log = logger.GetOrCreate("facade")
Expand Down Expand Up @@ -72,7 +73,7 @@ type nodeFacade struct {
// NewNodeFacade creates a new Facade with a NodeWrapper
func NewNodeFacade(arg ArgNodeFacade) (*nodeFacade, error) {
if check.IfNil(arg.Node) {
return nil, ErrNilNode
return nil, errors.ErrNilNode
}
if check.IfNil(arg.ApiResolver) {
return nil, ErrNilApiResolver
Expand Down Expand Up @@ -163,7 +164,7 @@ func (nf *nodeFacade) RestAPIServerDebugMode() bool {

// RestApiInterface returns the interface on which the rest API should start on, based on the config file provided.
// The API will start on the DefaultRestInterface value unless a correct value is passed or
// the value is explicitly set to off, in which case it will not start at all
// the value is explicitly set to off, in which case it will not start at all
func (nf *nodeFacade) RestApiInterface() string {
if nf.config.RestApiInterface == "" {
return DefaultRestInterface
Expand Down
3 changes: 2 additions & 1 deletion facade/nodeFacade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/debug"
errorsMx "github.com/multiversx/mx-chain-go/errors"
"github.com/multiversx/mx-chain-go/facade/mock"
"github.com/multiversx/mx-chain-go/heartbeat/data"
"github.com/multiversx/mx-chain-go/node/external"
Expand Down Expand Up @@ -84,7 +85,7 @@ func TestNewNodeFacade(t *testing.T) {
nf, err := NewNodeFacade(arg)

require.Nil(t, nf)
require.Equal(t, ErrNilNode, err)
require.Equal(t, errorsMx.ErrNilNode, err)
})
t.Run("nil ApiResolver should error", func(t *testing.T) {
t.Parallel()
Expand Down
Loading

0 comments on commit 26bc5f8

Please sign in to comment.