-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5573 from multiversx/state-core-and-state-components
Status Core Components and State Components
- Loading branch information
Showing
7 changed files
with
320 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package processingOnlyNode | ||
|
||
// TODO implement in next PR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
Config 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.Config, | ||
Core: args.CoreComponents, | ||
StatusCore: args.StatusCore, | ||
StorageService: args.StoreService, | ||
ProcessingMode: common.Normal, | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.