Skip to content

Commit

Permalink
Merge b4685db into f8ec6ce
Browse files Browse the repository at this point in the history
  • Loading branch information
miiu96 committed Sep 12, 2023
2 parents f8ec6ce + b4685db commit a3cad20
Show file tree
Hide file tree
Showing 7 changed files with 322 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
120 changes: 120 additions & 0 deletions node/processingOnlyNode/stateComponents.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
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"
)

const NormalProcessingMode = 0

// 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: NormalProcessingMode,
ShouldSerializeSnapshots: false,
ChainHandler: args.ChainHandler,
})
if err != nil {
return nil, err

Check warning on line 47 in node/processingOnlyNode/stateComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/stateComponents.go#L47

Added line #L47 was not covered by tests
}

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

Check warning on line 52 in node/processingOnlyNode/stateComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/stateComponents.go#L52

Added line #L52 was not covered by tests
}

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

Check warning on line 57 in node/processingOnlyNode/stateComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/stateComponents.go#L57

Added line #L57 was not covered by tests
}

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

Check warning on line 62 in node/processingOnlyNode/stateComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/stateComponents.go#L62

Added line #L62 was not covered by tests
}

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

Check warning on line 79 in node/processingOnlyNode/stateComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/stateComponents.go#L78-L79

Added lines #L78 - L79 were not covered by tests
}

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

Check warning on line 84 in node/processingOnlyNode/stateComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/stateComponents.go#L83-L84

Added lines #L83 - L84 were not covered by tests
}

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

Check warning on line 89 in node/processingOnlyNode/stateComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/stateComponents.go#L88-L89

Added lines #L88 - L89 were not covered by tests
}

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

Check warning on line 94 in node/processingOnlyNode/stateComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/stateComponents.go#L93-L94

Added lines #L93 - L94 were not covered by tests
}

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

Check warning on line 99 in node/processingOnlyNode/stateComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/stateComponents.go#L98-L99

Added lines #L98 - L99 were not covered by tests
}

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

Check warning on line 104 in node/processingOnlyNode/stateComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/stateComponents.go#L103-L104

Added lines #L103 - L104 were not covered by tests
}

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

Check warning on line 109 in node/processingOnlyNode/stateComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/stateComponents.go#L108-L109

Added lines #L108 - L109 were not covered by tests
}

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

Check warning on line 114 in node/processingOnlyNode/stateComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/stateComponents.go#L113-L114

Added lines #L113 - L114 were not covered by tests
}

// IsInterfaceNil returns true if there is no value under the interface
func (s *stateComponentsHolder) IsInterfaceNil() bool {
return s == nil

Check warning on line 119 in node/processingOnlyNode/stateComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/stateComponents.go#L118-L119

Added lines #L118 - L119 were not covered by tests
}
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

Check warning on line 31 in node/processingOnlyNode/statusComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/statusComponents.go#L31

Added line #L31 was not covered by tests
}
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

Check warning on line 41 in node/processingOnlyNode/statusComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/statusComponents.go#L40-L41

Added lines #L40 - L41 were not covered by tests
}

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

Check warning on line 46 in node/processingOnlyNode/statusComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/statusComponents.go#L45-L46

Added lines #L45 - L46 were not covered by tests
}

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

Check warning on line 51 in node/processingOnlyNode/statusComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/statusComponents.go#L50-L51

Added lines #L50 - L51 were not covered by tests
}

// IsInterfaceNil returns true if there is no value under the interface
func (s *statusComponentsHolder) IsInterfaceNil() bool {
return s == nil

Check warning on line 56 in node/processingOnlyNode/statusComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/statusComponents.go#L55-L56

Added lines #L55 - L56 were not covered by tests
}
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

Check warning on line 37 in node/processingOnlyNode/statusCoreComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/statusCoreComponents.go#L37

Added line #L37 was not covered by tests
}
instance.persistentStatusHandler, err = persister.NewPersistentStatusHandler(coreComponents.InternalMarshalizer(), coreComponents.Uint64ByteSliceConverter())
if err != nil {
return nil, err

Check warning on line 41 in node/processingOnlyNode/statusCoreComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/statusCoreComponents.go#L41

Added line #L41 was not covered by tests
}

return instance, nil
}

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

Check warning on line 49 in node/processingOnlyNode/statusCoreComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/statusCoreComponents.go#L48-L49

Added lines #L48 - L49 were not covered by tests
}

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

Check warning on line 54 in node/processingOnlyNode/statusCoreComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/statusCoreComponents.go#L53-L54

Added lines #L53 - L54 were not covered by tests
}

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

Check warning on line 59 in node/processingOnlyNode/statusCoreComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/statusCoreComponents.go#L58-L59

Added lines #L58 - L59 were not covered by tests
}

// 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

Check warning on line 69 in node/processingOnlyNode/statusCoreComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/statusCoreComponents.go#L68-L69

Added lines #L68 - L69 were not covered by tests
}

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

Check warning on line 74 in node/processingOnlyNode/statusCoreComponents.go

View check run for this annotation

Codecov / codecov/patch

node/processingOnlyNode/statusCoreComponents.go#L73-L74

Added lines #L73 - L74 were not covered by tests
}

// 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

0 comments on commit a3cad20

Please sign in to comment.