-
Notifications
You must be signed in to change notification settings - Fork 197
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
Changes from 5 commits
a1a60e8
f3f7ae8
31c09ae
48582b2
9a535a5
b4685db
8fc962e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package processingOnlyNode | ||
|
||
// TODO implement in next PR |
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 | ||
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might replace There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} |
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing comments on all exported items in this file There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} |
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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might rename to
Config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done