package consensus import ( "github.com/kaspanet/kaspad/domain/consensus/datastructures/acceptancedatastore" "github.com/kaspanet/kaspad/domain/consensus/datastructures/blockindex" "github.com/kaspanet/kaspad/domain/consensus/datastructures/blockmessagestore" "github.com/kaspanet/kaspad/domain/consensus/datastructures/blockrelationstore" "github.com/kaspanet/kaspad/domain/consensus/datastructures/blockstatusstore" "github.com/kaspanet/kaspad/domain/consensus/datastructures/consensusstatestore" "github.com/kaspanet/kaspad/domain/consensus/datastructures/ghostdagdatastore" "github.com/kaspanet/kaspad/domain/consensus/datastructures/multisetstore" "github.com/kaspanet/kaspad/domain/consensus/datastructures/pruningpointstore" "github.com/kaspanet/kaspad/domain/consensus/datastructures/reachabilitydatastore" "github.com/kaspanet/kaspad/domain/consensus/datastructures/utxodiffstore" "github.com/kaspanet/kaspad/domain/consensus/processes/blockprocessor" "github.com/kaspanet/kaspad/domain/consensus/processes/blockvalidator" "github.com/kaspanet/kaspad/domain/consensus/processes/consensusstatemanager" "github.com/kaspanet/kaspad/domain/consensus/processes/dagtopologymanager" "github.com/kaspanet/kaspad/domain/consensus/processes/dagtraversalmanager" "github.com/kaspanet/kaspad/domain/consensus/processes/ghostdagmanager" "github.com/kaspanet/kaspad/domain/consensus/processes/pruningmanager" "github.com/kaspanet/kaspad/domain/consensus/processes/reachabilitytree" "github.com/kaspanet/kaspad/domain/dagconfig" "github.com/kaspanet/kaspad/infrastructure/db/dbaccess" ) // Factory instantiates new Consensuses type Factory interface { NewConsensus(dagParams *dagconfig.Params, databaseContext *dbaccess.DatabaseContext) Consensus } type factory struct{} // NewConsensus instantiates a new Consensus func (f *factory) NewConsensus(dagParams *dagconfig.Params, databaseContext *dbaccess.DatabaseContext) Consensus { // Data Structures acceptanceDataStore := acceptancedatastore.New() blockIndex := blockindex.New() blockMessageStore := blockmessagestore.New() blockRelationStore := blockrelationstore.New() blockStatusStore := blockstatusstore.New() multisetStore := multisetstore.New() pruningPointStore := pruningpointstore.New() reachabilityDataStore := reachabilitydatastore.New() utxoDiffStore := utxodiffstore.New() consensusStateStore := consensusstatestore.New() ghostdagDataStore := ghostdagdatastore.New() // Processes blockValidator := blockvalidator.New() reachabilityTree := reachabilitytree.New( blockRelationStore, reachabilityDataStore) dagTopologyManager := dagtopologymanager.New( reachabilityTree, blockRelationStore) ghostdagManager := ghostdagmanager.New( dagTopologyManager, ghostdagDataStore) dagTraversalManager := dagtraversalmanager.New( dagTopologyManager, ghostdagManager) pruningManager := pruningmanager.New( dagTraversalManager, pruningPointStore) consensusStateManager := consensusstatemanager.New( dagParams, consensusStateStore, multisetStore, utxoDiffStore) blockProcessor := blockprocessor.New( dagParams, databaseContext, consensusStateManager, pruningManager, blockValidator, dagTopologyManager, reachabilityTree, acceptanceDataStore, blockIndex, blockMessageStore, blockStatusStore) return &consensus{ consensusStateManager: consensusStateManager, blockProcessor: blockProcessor, } } // NewFactory creates a new Consensus factory func NewFactory() Factory { return &factory{} }