mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-28 09:46:50 +00:00

* [NOD-1413] Remove /cmd/addblock * [NOD-1413] Define and implement TransactionValidator. * [NOD-1413] Make changes to ConsensusStateManager's interface. * [NOD-1413] Make changes to PruningManager's interface. * [NOD-1413] Make changes to DAGTraversalManager's interface. * [NOD-1413] Make changes to MultisetStore's interface. * [NOD-1413] Make changes to UTXODiffStore's interface. * [NOD-1413] Make changes to UTXODiffStore's interface harder. * [NOD-1413] Make changes to AcceptanceDataStore's interface harder. * [NOD-1413] Make changes to PruningStore's interface. * [NOD-1413] Delete BlockIndex. * [NOD-1413] Add FeeDataStore. * [NOD-1413] Update BlockMessageStore's interface. * [NOD-1413] Fix interface violations. * [NOD-1413] Add FeeDataStore to BlockProcessor. * [NOD-1413] Make go vet happy. * [NOD-1413] Add missing fields to ConsensusStateChanges. * [NOD-1413] Add another missing field to ConsensusStateChanges. * [NOD-1413] Add a reference to blockStore in consensusStateManager. * [NOD-1413] Add missing methods to UTXODiffStore. * [NOD-1413] Rename pruningPointStore to pruningStore everywhere. * [NOD-1413] Remove superfluous parameters from CalculateConsensusStateChanges. * [NOD-1413] Add missing dependencies to PruningManager. * [NOD-1413] Remove implementation-y functions from TransactionValidator's interface. * [NOD-1413] Make go vet happy. * [NOD-1413] Add a couple of methods to DAGTopologyManager. * [NOD-1413] Fix a typo in a file name. * [NOD-1413] Remove non-interface functions from Validator.
45 lines
1.8 KiB
Go
45 lines
1.8 KiB
Go
package consensus
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/domain/consensus/model"
|
|
)
|
|
|
|
// Consensus maintains the current core state of the node
|
|
type Consensus interface {
|
|
BuildBlock(coinbaseScriptPublicKey []byte, coinbaseExtraData []byte, transactionSelector model.TransactionSelector) *model.DomainBlock
|
|
ValidateAndInsertBlock(block *model.DomainBlock) error
|
|
UTXOByOutpoint(outpoint *model.DomainOutpoint) *model.UTXOEntry
|
|
ValidateTransactionAndCalculateFee(transaction *model.DomainTransaction, utxoEntries []*model.UTXOEntry) (fee uint64, err error)
|
|
}
|
|
|
|
type consensus struct {
|
|
blockProcessor model.BlockProcessor
|
|
consensusStateManager model.ConsensusStateManager
|
|
transactionValidator model.TransactionValidator
|
|
}
|
|
|
|
// BuildBlock builds a block over the current state, with the transactions
|
|
// selected by the given transactionSelector
|
|
func (s *consensus) BuildBlock(coinbaseScriptPublicKey []byte, coinbaseExtraData []byte,
|
|
transactionSelector model.TransactionSelector) *model.DomainBlock {
|
|
|
|
return s.blockProcessor.BuildBlock(coinbaseScriptPublicKey, coinbaseExtraData, transactionSelector)
|
|
}
|
|
|
|
// ValidateAndInsertBlock validates the given block and, if valid, applies it
|
|
// to the current state
|
|
func (s *consensus) ValidateAndInsertBlock(block *model.DomainBlock) error {
|
|
return s.blockProcessor.ValidateAndInsertBlock(block)
|
|
}
|
|
|
|
// UTXOByOutpoint returns a UTXOEntry matching the given outpoint
|
|
func (s *consensus) UTXOByOutpoint(outpoint *model.DomainOutpoint) *model.UTXOEntry {
|
|
return s.consensusStateManager.UTXOByOutpoint(outpoint)
|
|
}
|
|
|
|
// ValidateTransaction validates the given transaction using
|
|
// the given utxoEntries
|
|
func (s *consensus) ValidateTransactionAndCalculateFee(transaction *model.DomainTransaction, utxoEntries []*model.UTXOEntry) (fee uint64, err error) {
|
|
return s.transactionValidator.ValidateTransactionAndCalculateFee(transaction, utxoEntries)
|
|
}
|