mirror of
https://github.com/kaspanet/kaspad.git
synced 2026-02-27 13:43:19 +00:00
* Added model and stubs for all main methods
* Add constructors to all main objects
* Implement BlockCandidateTransactions
* implement expireOldTransactions and expireOrphanTransactions
* Rename isHighPriority to neverExpires
* Add stub for checkDoubleSpends
* Revert "Rename isHighPriority to neverExpires"
This reverts commit b2da9a4a00.
* Imeplement transactionsOrderedByFeeRate
* Orphan maps should be idToOrphan
* Add error.go to mempool
* Invert the condition for banning when mempool rejects a transaction
* Move all model objects to model package
* Implement getParentsInPool
* Implemented mempoolUTXOSet.addTransaction
* Implement removeTransaction, remove sanity checks
* Implemented mempoolUTXOSet.checkDoubleSpends
* Implemented removeOrphan
* Implement removeOrphan
* Implement maybeAddOrphan and AddOrphan
* Implemented processOrphansAfterAcceptedTransaction
* Implement transactionsPool.addTransaction
* Implement RemoveTransaction
* If a transaction was removed from the mempool - update it's redeemers in orphan pool as well
* Use maximumOrphanTransactionCount
* Add allowOrphans to ValidateAndInsertTransaction stub
* Implement validateTransaction functions
* Implement fillInputs
* Implement ValidateAndInsertTransaction
* Implement HandleNewBlockTransactions
* Implement missing mempool interface methods
* Add comments to exported functions
* Call ValidateTransactionInIsolation where needed
* Implement RevalidateHighPriorityTransactions
* Rewire kaspad to use new mempool, and fix compilation errors
* Update rebroadcast logic to use new structure
* Handle non-standard transaction errors properly
* Add mutex to mempool
* bugfix: GetTransaction panics when ok is false
* properly calculate targetBlocksPerSecond in config.go
* Fix various lint errors and tests
* Fix expected text in test for duplicate transactions
* Skip the coinbase transaction in HandleNewBlockTransactions
* Unorphan the correct transactions
* Call ValidateTransactionAndPopulateWithConsensusData on unorphanTransaction
* Re-apply policy_test as check_transactions_standard_test
* removeTransaction: Remove redeemers in orphan pool as well
* Remove redundant check for uint64 < 0
* Export and rename isDust -> IsTransactionOutputDust to allow usage by rothschild
* Add allowOrphan to SubmitTransaction RPC request
* Remove all implementation from mempool.go
* tidy go mod
* Don't pass acceptedOrphans to handleNewBlockTransactions
* Use t.Errorf in stead of t.Fatalf
* Remove minimum relay fee from TestDust, as it's no longer configurable
* Add separate VirtualDAASCore method for faster retrieval where it's repeated multiple times
* Broadcast all transactions that were accepted
* Don't re-use GetVirtualDAAScore in GetVirtualInfo - this causes a deadlock
* Use real transaction count, and not Orphan
* Get mempool config from outside, incorporating values received from cli
* Use MinRelayFee and MaxOrphanTxs from global kaspad config
* Add explanation for the seemingly redundant check for transaction version in checkTransactionStandard
* Update some comment
* Convert creation of acceptedTransactions to a single line
* Move mempoolUTXOSet out of checkDoubleSpends
* Add test for attempt to insert double spend into mempool
* fillInputs: Skip check for coinbase - it's always false in mempool
* Clarify comment about removeRedeemers when removing random orphan
* Don't remove high-priority transactions in limitTransactionCount
* Use mempool.removeTransaction in limitTransactionCount
* Add mutex comment to handleNewBlockTransactions
* Return error from limitTransactionCount
* Pluralize the map types
* mempoolUTXOSet.removeTransaction: Don't restore utxo if it was not created in mempool
* Don't evacuate from orphanPool high-priority transactions
* Disallow double-spends in orphan pool
* Don't use exported (and locking) methods from inside mempool
* Check for double spends in mempool during revalidateTransaction
* Add checkOrphanDuplicate
* Add orphan to acceptedOrphans, not current
* Add TestHighPriorityTransactions
* Fix off-by-one error in limitTransactionCount
* Add TestRevalidateHighPriorityTransactions
* Remove checkDoubleSpends from revalidateTransaction
* Fix TestRevalidateHighPriorityTransactions
* Move check for MaximumOrphanCount to beggining of maybeAddOrphan
* Rename all map type to singulateToSingularMap
* limitOrphanPool only after the orphan was added
* TestDoubleSpendInMempool: use createChildTxWhenParentTxWasAddedByConsensus instead of createTransactionWithUTXOEntry
* Fix some comments
* Have separate min/max transaction versions for mempool
* Add comment on defaultMaximumOrphanTransactionCount to keep it small as long as we have recursion
* Fix comment
* Rename: createChildTxWhenParentTxWasAddedByConsensus -> createChildTxWhereParentTxWasAddedByConsensus
* Handle error from createChildTxWhereParentTxWasAddedByConsensus
* Rename createChildTxWhereParentTxWasAddedByConsensus -> createChildAndParentTxsAndAddParentToConsensus
* Convert all MaximumXXX constants to uint64
* Add comment
* remove mutex comments
170 lines
4.6 KiB
Go
170 lines
4.6 KiB
Go
package app
|
|
|
|
import (
|
|
"fmt"
|
|
"sync/atomic"
|
|
|
|
"github.com/kaspanet/kaspad/domain/miningmanager/mempool"
|
|
|
|
"github.com/kaspanet/kaspad/app/protocol"
|
|
"github.com/kaspanet/kaspad/app/rpc"
|
|
"github.com/kaspanet/kaspad/domain"
|
|
"github.com/kaspanet/kaspad/domain/consensus"
|
|
"github.com/kaspanet/kaspad/domain/utxoindex"
|
|
"github.com/kaspanet/kaspad/infrastructure/config"
|
|
infrastructuredatabase "github.com/kaspanet/kaspad/infrastructure/db/database"
|
|
"github.com/kaspanet/kaspad/infrastructure/network/addressmanager"
|
|
"github.com/kaspanet/kaspad/infrastructure/network/connmanager"
|
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter"
|
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/id"
|
|
"github.com/kaspanet/kaspad/util/panics"
|
|
)
|
|
|
|
// ComponentManager is a wrapper for all the kaspad services
|
|
type ComponentManager struct {
|
|
cfg *config.Config
|
|
addressManager *addressmanager.AddressManager
|
|
protocolManager *protocol.Manager
|
|
rpcManager *rpc.Manager
|
|
connectionManager *connmanager.ConnectionManager
|
|
netAdapter *netadapter.NetAdapter
|
|
|
|
started, shutdown int32
|
|
}
|
|
|
|
// Start launches all the kaspad services.
|
|
func (a *ComponentManager) Start() {
|
|
// Already started?
|
|
if atomic.AddInt32(&a.started, 1) != 1 {
|
|
return
|
|
}
|
|
|
|
log.Trace("Starting kaspad")
|
|
|
|
err := a.netAdapter.Start()
|
|
if err != nil {
|
|
panics.Exit(log, fmt.Sprintf("Error starting the net adapter: %+v", err))
|
|
}
|
|
|
|
a.connectionManager.Start()
|
|
}
|
|
|
|
// Stop gracefully shuts down all the kaspad services.
|
|
func (a *ComponentManager) Stop() {
|
|
// Make sure this only happens once.
|
|
if atomic.AddInt32(&a.shutdown, 1) != 1 {
|
|
log.Infof("Kaspad is already in the process of shutting down")
|
|
return
|
|
}
|
|
|
|
log.Warnf("Kaspad shutting down")
|
|
|
|
a.connectionManager.Stop()
|
|
|
|
err := a.netAdapter.Stop()
|
|
if err != nil {
|
|
log.Errorf("Error stopping the net adapter: %+v", err)
|
|
}
|
|
|
|
a.protocolManager.Close()
|
|
|
|
return
|
|
}
|
|
|
|
// NewComponentManager returns a new ComponentManager instance.
|
|
// Use Start() to begin all services within this ComponentManager
|
|
func NewComponentManager(cfg *config.Config, db infrastructuredatabase.Database, interrupt chan<- struct{}) (
|
|
*ComponentManager, error) {
|
|
|
|
consensusConfig := consensus.Config{
|
|
Params: *cfg.ActiveNetParams,
|
|
IsArchival: cfg.IsArchivalNode,
|
|
EnableSanityCheckPruningUTXOSet: cfg.EnableSanityCheckPruningUTXOSet,
|
|
}
|
|
mempoolConfig := mempool.DefaultConfig(&consensusConfig.Params)
|
|
mempoolConfig.MaximumOrphanTransactionCount = cfg.MaxOrphanTxs
|
|
mempoolConfig.MinimumRelayTransactionFee = cfg.MinRelayTxFee
|
|
|
|
domain, err := domain.New(&consensusConfig, mempoolConfig, db)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
netAdapter, err := netadapter.NewNetAdapter(cfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
addressManager, err := addressmanager.New(addressmanager.NewConfig(cfg), db)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var utxoIndex *utxoindex.UTXOIndex
|
|
if cfg.UTXOIndex {
|
|
utxoIndex, err = utxoindex.New(domain.Consensus(), db)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
log.Infof("UTXO index started")
|
|
}
|
|
|
|
connectionManager, err := connmanager.New(cfg, netAdapter, addressManager)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
protocolManager, err := protocol.NewManager(cfg, domain, netAdapter, addressManager, connectionManager)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
rpcManager := setupRPC(cfg, domain, netAdapter, protocolManager, connectionManager, addressManager, utxoIndex, interrupt)
|
|
|
|
return &ComponentManager{
|
|
cfg: cfg,
|
|
protocolManager: protocolManager,
|
|
rpcManager: rpcManager,
|
|
connectionManager: connectionManager,
|
|
netAdapter: netAdapter,
|
|
addressManager: addressManager,
|
|
}, nil
|
|
|
|
}
|
|
|
|
func setupRPC(
|
|
cfg *config.Config,
|
|
domain domain.Domain,
|
|
netAdapter *netadapter.NetAdapter,
|
|
protocolManager *protocol.Manager,
|
|
connectionManager *connmanager.ConnectionManager,
|
|
addressManager *addressmanager.AddressManager,
|
|
utxoIndex *utxoindex.UTXOIndex,
|
|
shutDownChan chan<- struct{},
|
|
) *rpc.Manager {
|
|
|
|
rpcManager := rpc.NewManager(
|
|
cfg,
|
|
domain,
|
|
netAdapter,
|
|
protocolManager,
|
|
connectionManager,
|
|
addressManager,
|
|
utxoIndex,
|
|
shutDownChan,
|
|
)
|
|
protocolManager.SetOnBlockAddedToDAGHandler(rpcManager.NotifyBlockAddedToDAG)
|
|
protocolManager.SetOnPruningPointUTXOSetOverrideHandler(rpcManager.NotifyPruningPointUTXOSetOverride)
|
|
|
|
return rpcManager
|
|
}
|
|
|
|
// P2PNodeID returns the network ID associated with this ComponentManager
|
|
func (a *ComponentManager) P2PNodeID() *id.ID {
|
|
return a.netAdapter.ID()
|
|
}
|
|
|
|
// AddressManager returns the AddressManager associated with this ComponentManager
|
|
func (a *ComponentManager) AddressManager() *addressmanager.AddressManager {
|
|
return a.addressManager
|
|
}
|