Skip to content

Commit

Permalink
Merge pull request #5573 from multiversx/state-core-and-state-components
Browse files Browse the repository at this point in the history
Status Core Components and State Components
  • Loading branch information
iulianpascalau authored Sep 12, 2023
2 parents f8ec6ce + 8fc962e commit f3597b2
Show file tree
Hide file tree
Showing 7 changed files with 320 additions and 15 deletions.
26 changes: 13 additions & 13 deletions node/processingOnlyNode/coreComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type coreComponentsHolder struct {

// ArgsCoreComponentsHolder will hold arguments needed for the core components holder
type ArgsCoreComponentsHolder struct {
Cfg config.Config
Config config.Config
EnableEpochsConfig config.EnableEpochs
RoundsConfig config.RoundConfig
EconomicsConfig config.EconomicsConfig
Expand All @@ -92,40 +92,40 @@ func CreateCoreComponentsHolder(args ArgsCoreComponentsHolder) (factory.CoreComp
var err error
instance := &coreComponentsHolder{}

instance.internalMarshaller, err = marshalFactory.NewMarshalizer(args.Cfg.Marshalizer.Type)
instance.internalMarshaller, err = marshalFactory.NewMarshalizer(args.Config.Marshalizer.Type)
if err != nil {
return nil, err
}
instance.txMarshaller, err = marshalFactory.NewMarshalizer(args.Cfg.TxSignMarshalizer.Type)
instance.txMarshaller, err = marshalFactory.NewMarshalizer(args.Config.TxSignMarshalizer.Type)
if err != nil {
return nil, err
}
instance.vmMarshaller, err = marshalFactory.NewMarshalizer(args.Cfg.VmMarshalizer.Type)
instance.vmMarshaller, err = marshalFactory.NewMarshalizer(args.Config.VmMarshalizer.Type)
if err != nil {
return nil, err
}
instance.hasher, err = hashingFactory.NewHasher(args.Cfg.Hasher.Type)
instance.hasher, err = hashingFactory.NewHasher(args.Config.Hasher.Type)
if err != nil {
return nil, err
}
instance.txSignHasher, err = hashingFactory.NewHasher(args.Cfg.TxSignHasher.Type)
instance.txSignHasher, err = hashingFactory.NewHasher(args.Config.TxSignHasher.Type)
if err != nil {
return nil, err
}
instance.uint64SliceConverter = uint64ByteSlice.NewBigEndianConverter()
instance.addressPubKeyConverter, err = factoryPubKey.NewPubkeyConverter(args.Cfg.AddressPubkeyConverter)
instance.addressPubKeyConverter, err = factoryPubKey.NewPubkeyConverter(args.Config.AddressPubkeyConverter)
if err != nil {
return nil, err
}
instance.validatorPubKeyConverter, err = factoryPubKey.NewPubkeyConverter(args.Cfg.ValidatorPubkeyConverter)
instance.validatorPubKeyConverter, err = factoryPubKey.NewPubkeyConverter(args.Config.ValidatorPubkeyConverter)
if err != nil {
return nil, err
}

instance.pathHandler, err = storageFactory.CreatePathManager(
storageFactory.ArgCreatePathManager{
WorkingDir: args.WorkingDir,
ChainID: args.Cfg.GeneralSettings.ChainID,
ChainID: args.Config.GeneralSettings.ChainID,
},
)
if err != nil {
Expand All @@ -139,7 +139,7 @@ func CreateCoreComponentsHolder(args ArgsCoreComponentsHolder) (factory.CoreComp
//instance.roundHandler

instance.wasmVMChangeLocker = &sync.RWMutex{}
instance.txVersionChecker = versioning.NewTxVersionChecker(args.Cfg.GeneralSettings.MinTransactionVersion)
instance.txVersionChecker = versioning.NewTxVersionChecker(args.Config.GeneralSettings.MinTransactionVersion)
instance.epochNotifier = forking.NewGenericEpochNotifier()
instance.enableEpochsHandler, err = enablers.NewEnableEpochsHandler(args.EnableEpochsConfig, instance.epochNotifier)
if err != nil {
Expand Down Expand Up @@ -206,8 +206,8 @@ func CreateCoreComponentsHolder(args ArgsCoreComponentsHolder) (factory.CoreComp
instance.epochStartNotifierWithConfirm = notifier.NewEpochStartSubscriptionHandler()
instance.chanStopNodeProcess = args.ChanStopNodeProcess
instance.genesisTime = time.Unix(instance.genesisNodesSetup.GetStartTime(), 0)
instance.chainID = args.Cfg.GeneralSettings.ChainID
instance.minTransactionVersion = args.Cfg.GeneralSettings.MinTransactionVersion
instance.chainID = args.Config.GeneralSettings.ChainID
instance.minTransactionVersion = args.Config.GeneralSettings.MinTransactionVersion
instance.encodedAddressLen, err = computeEncodedAddressLen(instance.addressPubKeyConverter)
if err != nil {
return nil, err
Expand All @@ -216,7 +216,7 @@ func CreateCoreComponentsHolder(args ArgsCoreComponentsHolder) (factory.CoreComp
instance.nodeTypeProvider = nodetype.NewNodeTypeProvider(core.NodeTypeObserver)
instance.processStatusHandler = statusHandler.NewProcessStatusHandler()

pubKeyBytes, err := instance.validatorPubKeyConverter.Decode(args.Cfg.Hardfork.PublicKeyToListenFrom)
pubKeyBytes, err := instance.validatorPubKeyConverter.Decode(args.Config.Hardfork.PublicKeyToListenFrom)
if err != nil {
return nil, err
}
Expand Down
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 {
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
}
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) {
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
Loading

0 comments on commit f3597b2

Please sign in to comment.