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

Status Core Components and State Components #5573

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions node/processingOnlyNode/cryptoComponents.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package processingOnlyNode

// TODO implement in next PR
118 changes: 118 additions & 0 deletions node/processingOnlyNode/stateComponents.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package processingOnlyNode

import (
chainData "github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/dataRetriever"
"github.com/multiversx/mx-chain-go/factory"
factoryState "github.com/multiversx/mx-chain-go/factory/state"
"github.com/multiversx/mx-chain-go/state"
)

// ArgsStateComponents will hold the components needed for state components
type ArgsStateComponents struct {
Cfg config.Config
Copy link
Contributor

Choose a reason for hiding this comment

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

might rename to Config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

CoreComponents factory.CoreComponentsHolder
StatusCore factory.StatusCoreComponentsHolder
StoreService dataRetriever.StorageService
ChainHandler chainData.ChainHandler
}

type stateComponentsHolder struct {
peerAccount state.AccountsAdapter
accountsAdapter state.AccountsAdapter
accountsAdapterAPI state.AccountsAdapter
accountsRepository state.AccountsRepository
triesContainer common.TriesHolder
triesStorageManager map[string]common.StorageManager
missingTrieNodesNotifier common.MissingTrieNodesNotifier
closeFunc func() error
}

// CreateStateComponents will create the state components holder
func CreateStateComponents(args ArgsStateComponents) (factory.StateComponentsHolder, error) {
stateComponentsFactory, err := factoryState.NewStateComponentsFactory(factoryState.StateComponentsFactoryArgs{
Config: args.Cfg,
Core: args.CoreComponents,
StatusCore: args.StatusCore,
StorageService: args.StoreService,
ProcessingMode: 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

might replace 0 with a constant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

ShouldSerializeSnapshots: false,
ChainHandler: args.ChainHandler,
})
if err != nil {
return nil, err
}

stateComp, err := factoryState.NewManagedStateComponents(stateComponentsFactory)
if err != nil {
return nil, err
}

err = stateComp.Create()
if err != nil {
return nil, err
}

err = stateComp.CheckSubcomponents()
if err != nil {
return nil, err
}

return &stateComponentsHolder{
peerAccount: stateComp.PeerAccounts(),
accountsAdapter: stateComp.AccountsAdapter(),
accountsAdapterAPI: stateComp.AccountsAdapterAPI(),
accountsRepository: stateComp.AccountsRepository(),
triesContainer: stateComp.TriesContainer(),
triesStorageManager: stateComp.TrieStorageManagers(),
missingTrieNodesNotifier: stateComp.MissingTrieNodesNotifier(),
closeFunc: stateComp.Close,
}, nil
}

// PeerAccounts will return peer accounts
func (s *stateComponentsHolder) PeerAccounts() state.AccountsAdapter {
return s.peerAccount
}

// AccountsAdapter will return accounts adapter
func (s *stateComponentsHolder) AccountsAdapter() state.AccountsAdapter {
return s.accountsAdapter
}

// AccountsAdapterAPI will return accounts adapter api
func (s *stateComponentsHolder) AccountsAdapterAPI() state.AccountsAdapter {
return s.accountsAdapterAPI
}

// AccountsRepository will return accounts repository
func (s *stateComponentsHolder) AccountsRepository() state.AccountsRepository {
return s.accountsRepository
}

// TriesContainer will return tries container
func (s *stateComponentsHolder) TriesContainer() common.TriesHolder {
return s.triesContainer
}

// TrieStorageManagers will return trie storage managers
func (s *stateComponentsHolder) TrieStorageManagers() map[string]common.StorageManager {
return s.triesStorageManager
}

// MissingTrieNodesNotifier will return missing trie nodes notifier
func (s *stateComponentsHolder) MissingTrieNodesNotifier() common.MissingTrieNodesNotifier {
return s.missingTrieNodesNotifier
}

// Close will close the state components
func (s *stateComponentsHolder) Close() error {
return s.closeFunc()
}

// IsInterfaceNil returns true if there is no value under the interface
func (s *stateComponentsHolder) IsInterfaceNil() bool {
return s == nil
}
57 changes: 57 additions & 0 deletions node/processingOnlyNode/statusComponents.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package processingOnlyNode

import (
"time"

outportCfg "github.com/multiversx/mx-chain-core-go/data/outport"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/common/statistics"
"github.com/multiversx/mx-chain-go/factory"
"github.com/multiversx/mx-chain-go/integrationTests/mock"
"github.com/multiversx/mx-chain-go/outport"
"github.com/multiversx/mx-chain-go/testscommon"
)

type statusComponentsHolder struct {
outportHandler outport.OutportHandler
softwareVersionChecker statistics.SoftwareVersionChecker
managedPeerMonitor common.ManagedPeersMonitor
}

// CreateStatusComponentsHolder will create a new instance of status components holder
func CreateStatusComponentsHolder(shardID uint32) (factory.StatusComponentsHolder, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

missing comments on all exported items in this file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

var err error
instance := &statusComponentsHolder{}

// TODO add drivers to index data
instance.outportHandler, err = outport.NewOutport(100*time.Millisecond, outportCfg.OutportConfig{
ShardID: shardID,
})
if err != nil {
return nil, err
}
instance.softwareVersionChecker = &mock.SoftwareVersionCheckerMock{}
instance.managedPeerMonitor = &testscommon.ManagedPeersMonitorStub{}

return instance, nil
}

// OutportHandler will return the outport handler
func (s *statusComponentsHolder) OutportHandler() outport.OutportHandler {
return s.outportHandler
}

// SoftwareVersionChecker will return the software version checker
func (s *statusComponentsHolder) SoftwareVersionChecker() statistics.SoftwareVersionChecker {
return s.softwareVersionChecker
}

// ManagedPeersMonitor will return the managed peers monitor
func (s *statusComponentsHolder) ManagedPeersMonitor() common.ManagedPeersMonitor {
return s.managedPeerMonitor
}

// IsInterfaceNil returns true if there is no value under the interface
func (s *statusComponentsHolder) IsInterfaceNil() bool {
return s == nil
}
80 changes: 80 additions & 0 deletions node/processingOnlyNode/statusCoreComponents.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package processingOnlyNode

import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-go/cmd/termui/presenter"
"github.com/multiversx/mx-chain-go/common/statistics"
"github.com/multiversx/mx-chain-go/common/statistics/machine"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/factory"
"github.com/multiversx/mx-chain-go/node/external"
"github.com/multiversx/mx-chain-go/statusHandler"
"github.com/multiversx/mx-chain-go/statusHandler/persister"
statisticsTrie "github.com/multiversx/mx-chain-go/trie/statistics"
)

type statusCoreComponentsHolder struct {
resourceMonitor factory.ResourceMonitor
networkStatisticsProvider factory.NetworkStatisticsProvider
trieSyncStatisticsProvider factory.TrieSyncStatisticsProvider
statusHandler core.AppStatusHandler
statusMetrics external.StatusMetricsHandler
persistentStatusHandler factory.PersistentStatusHandler
}

// CreateStatusCoreComponentsHolder will create a new instance of factory.StatusCoreComponentsHolder
func CreateStatusCoreComponentsHolder(cfg config.Config, coreComponents factory.CoreComponentsHolder) (factory.StatusCoreComponentsHolder, error) {
var err error
instance := &statusCoreComponentsHolder{
networkStatisticsProvider: machine.NewNetStatistics(),
trieSyncStatisticsProvider: statisticsTrie.NewTrieSyncStatistics(),
statusHandler: presenter.NewPresenterStatusHandler(),
statusMetrics: statusHandler.NewStatusMetrics(),
}

instance.resourceMonitor, err = statistics.NewResourceMonitor(cfg, instance.networkStatisticsProvider)
if err != nil {
return nil, err
}
instance.persistentStatusHandler, err = persister.NewPersistentStatusHandler(coreComponents.InternalMarshalizer(), coreComponents.Uint64ByteSliceConverter())
if err != nil {
return nil, err
}

return instance, nil
}

// ResourceMonitor will return the resource monitor
func (s *statusCoreComponentsHolder) ResourceMonitor() factory.ResourceMonitor {
return s.resourceMonitor
}

// NetworkStatistics will return the network statistics provider
func (s *statusCoreComponentsHolder) NetworkStatistics() factory.NetworkStatisticsProvider {
return s.networkStatisticsProvider
}

// TrieSyncStatistics will return trie sync statistics provider
func (s *statusCoreComponentsHolder) TrieSyncStatistics() factory.TrieSyncStatisticsProvider {
return s.trieSyncStatisticsProvider
}

// AppStatusHandler will return the status handler
func (s *statusCoreComponentsHolder) AppStatusHandler() core.AppStatusHandler {
return s.statusHandler
}

// StatusMetrics will return the status metrics handler
func (s *statusCoreComponentsHolder) StatusMetrics() external.StatusMetricsHandler {
return s.statusMetrics
}

// PersistentStatusHandler will return the persistent status handler
func (s *statusCoreComponentsHolder) PersistentStatusHandler() factory.PersistentStatusHandler {
return s.persistentStatusHandler
}

// IsInterfaceNil returns true if there is no value under the interface
func (s *statusCoreComponentsHolder) IsInterfaceNil() bool {
return s == nil
}
4 changes: 4 additions & 0 deletions node/processingOnlyNode/storageService.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func CreateStore(numOfShards uint32) dataRetriever.StorageService {
store.AddStorer(dataRetriever.ReceiptsUnit, CreateMemUnit())
store.AddStorer(dataRetriever.ScheduledSCRsUnit, CreateMemUnit())
store.AddStorer(dataRetriever.TxLogsUnit, CreateMemUnit())
store.AddStorer(dataRetriever.UserAccountsUnit, CreateMemUnit())
store.AddStorer(dataRetriever.UserAccountsCheckpointsUnit, CreateMemUnit())
store.AddStorer(dataRetriever.PeerAccountsUnit, CreateMemUnit())
store.AddStorer(dataRetriever.PeerAccountsCheckpointsUnit, CreateMemUnit())
// TODO add the rest of units

for i := uint32(0); i < numOfShards; i++ {
Expand Down
45 changes: 44 additions & 1 deletion node/processingOnlyNode/testOnlyProcessingNode.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package processingOnlyNode

import (
"github.com/multiversx/mx-chain-core-go/core"
chainData "github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/endProcess"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/dataRetriever"
"github.com/multiversx/mx-chain-go/dataRetriever/blockchain"
dataRetrieverFactory "github.com/multiversx/mx-chain-go/dataRetriever/factory"
"github.com/multiversx/mx-chain-go/factory"
"github.com/multiversx/mx-chain-go/process"
Expand All @@ -29,8 +32,12 @@ type ArgsTestOnlyProcessingNode struct {
}

type testOnlyProcessingNode struct {
CoreComponentsHolder factory.CoreComponentsHolder
CoreComponentsHolder factory.CoreComponentsHolder
StatusCoreComponents factory.StatusCoreComponentsHolder
StateComponentsHolder factory.StateComponentsHolder
StatusComponentsHolder factory.StatusComponentsHolder

ChainHandler chainData.ChainHandler
ShardCoordinator sharding.Coordinator
ArgumentsParser process.ArgumentsParser
TransactionFeeHandler process.TransactionFeeHandler
Expand Down Expand Up @@ -66,6 +73,31 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces
return nil, err
}

instance.StatusCoreComponents, err = CreateStatusCoreComponentsHolder(args.Config, instance.CoreComponentsHolder)
if err != nil {
return nil, err
}

err = instance.createBlockChain(args.ShardID)
if err != nil {
return nil, err
}

instance.StateComponentsHolder, err = CreateStateComponents(ArgsStateComponents{
Cfg: args.Config,
CoreComponents: instance.CoreComponentsHolder,
StatusCore: instance.StatusCoreComponents,
StoreService: instance.StoreService,
ChainHandler: instance.ChainHandler,
})
if err != nil {
return nil, err
}
instance.StatusComponentsHolder, err = CreateStatusComponentsHolder(args.ShardID)
if err != nil {
return nil, err
}

err = instance.createDataPool(args)
if err != nil {
return nil, err
Expand Down Expand Up @@ -93,6 +125,17 @@ func (node *testOnlyProcessingNode) createBasicComponents(numShards, selfShardID
return nil
}

func (node *testOnlyProcessingNode) createBlockChain(selfShardID uint32) error {
var err error
if selfShardID == core.MetachainShardId {
node.ChainHandler, err = blockchain.NewMetaChain(node.StatusCoreComponents.AppStatusHandler())
} else {
node.ChainHandler, err = blockchain.NewBlockChain(node.StatusCoreComponents.AppStatusHandler())
}

return err
}

func (node *testOnlyProcessingNode) createDataPool(args ArgsTestOnlyProcessingNode) error {
var err error

Expand Down