stasatdaglabs d922ee1be2
Add header commitments for DAA score, blue work, and finality points (#1817)
* Add DAAScore, BlueWork, and FinalityPoint to externalapi.BlockHeader.

* Add DAAScore, BlueWork, and FinalityPoint to NewImmutableBlockHeader and fix compilation errors.

* Add DAAScore, BlueWork, and FinalityPoint to protowire header types and fix failing tests.

* Check for header DAA score in validateDifficulty.

* Add DAA score to buildBlock.

* Fix failing tests.

* Add a blue work check in validateDifficultyDAAAndBlueWork.

* Add blue work to buildBlock and fix failing tests.

* Add finality point validation to ValidateHeaderInContext.

* Fix genesis blocks' finality points.

* Add finalityPoint to blockBuilder.

* Fix tests that failed due to missing reachability data.

* Make blockBuilder use VirtualFinalityPoint instead of directly calling FinalityPoint with the virtual hash.

* Don't validate the finality point for blocks with trusted data.

* Add debug logs.

* Skip finality point validation for block whose finality points are the virtual genesis.

* Revert "Add debug logs."

This reverts commit 3c18f519ccbb382f86f63904dbb1c4cd6bc68b00.

* Move checkDAAScore and checkBlueWork to validateBlockHeaderInContext.

* Add checkCoinbaseBlueScore to validateBodyInContext.

* Fix failing tests.

* Add DAAScore, blueWork, and finalityPoint to blocks' hashes.

* Generate new genesis blocks.

* Fix failing tests.

* In BuildUTXOInvalidBlock, get the bits from StageDAADataAndReturnRequiredDifficulty instead of calling RequiredDifficulty separately.
2021-08-12 13:25:00 +03:00

124 lines
4.1 KiB
Go

package consensusstatemanager
import (
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
)
// consensusStateManager manages the node's consensus state
type consensusStateManager struct {
pruningDepth uint64
maxBlockParents externalapi.KType
mergeSetSizeLimit uint64
genesisHash *externalapi.DomainHash
databaseContext model.DBManager
ghostdagManager model.GHOSTDAGManager
dagTopologyManager model.DAGTopologyManager
dagTraversalManager model.DAGTraversalManager
pastMedianTimeManager model.PastMedianTimeManager
transactionValidator model.TransactionValidator
blockValidator model.BlockValidator
coinbaseManager model.CoinbaseManager
mergeDepthManager model.MergeDepthManager
finalityManager model.FinalityManager
difficultyManager model.DifficultyManager
headersSelectedTipStore model.HeaderSelectedTipStore
blockStatusStore model.BlockStatusStore
ghostdagDataStore model.GHOSTDAGDataStore
consensusStateStore model.ConsensusStateStore
multisetStore model.MultisetStore
blockStore model.BlockStore
utxoDiffStore model.UTXODiffStore
blockRelationStore model.BlockRelationStore
acceptanceDataStore model.AcceptanceDataStore
blockHeaderStore model.BlockHeaderStore
pruningStore model.PruningStore
daaBlocksStore model.DAABlocksStore
stores []model.Store
}
// New instantiates a new ConsensusStateManager
func New(
databaseContext model.DBManager,
pruningDepth uint64,
maxBlockParents externalapi.KType,
mergeSetSizeLimit uint64,
genesisHash *externalapi.DomainHash,
ghostdagManager model.GHOSTDAGManager,
dagTopologyManager model.DAGTopologyManager,
dagTraversalManager model.DAGTraversalManager,
pastMedianTimeManager model.PastMedianTimeManager,
transactionValidator model.TransactionValidator,
blockValidator model.BlockValidator,
coinbaseManager model.CoinbaseManager,
mergeDepthManager model.MergeDepthManager,
finalityManager model.FinalityManager,
difficultyManager model.DifficultyManager,
blockStatusStore model.BlockStatusStore,
ghostdagDataStore model.GHOSTDAGDataStore,
consensusStateStore model.ConsensusStateStore,
multisetStore model.MultisetStore,
blockStore model.BlockStore,
utxoDiffStore model.UTXODiffStore,
blockRelationStore model.BlockRelationStore,
acceptanceDataStore model.AcceptanceDataStore,
blockHeaderStore model.BlockHeaderStore,
headersSelectedTipStore model.HeaderSelectedTipStore,
pruningStore model.PruningStore,
daaBlocksStore model.DAABlocksStore) (model.ConsensusStateManager, error) {
csm := &consensusStateManager{
pruningDepth: pruningDepth,
maxBlockParents: maxBlockParents,
mergeSetSizeLimit: mergeSetSizeLimit,
genesisHash: genesisHash,
databaseContext: databaseContext,
ghostdagManager: ghostdagManager,
dagTopologyManager: dagTopologyManager,
dagTraversalManager: dagTraversalManager,
pastMedianTimeManager: pastMedianTimeManager,
transactionValidator: transactionValidator,
blockValidator: blockValidator,
coinbaseManager: coinbaseManager,
mergeDepthManager: mergeDepthManager,
finalityManager: finalityManager,
difficultyManager: difficultyManager,
multisetStore: multisetStore,
blockStore: blockStore,
blockStatusStore: blockStatusStore,
ghostdagDataStore: ghostdagDataStore,
consensusStateStore: consensusStateStore,
utxoDiffStore: utxoDiffStore,
blockRelationStore: blockRelationStore,
acceptanceDataStore: acceptanceDataStore,
blockHeaderStore: blockHeaderStore,
headersSelectedTipStore: headersSelectedTipStore,
pruningStore: pruningStore,
daaBlocksStore: daaBlocksStore,
stores: []model.Store{
consensusStateStore,
acceptanceDataStore,
blockStore,
blockStatusStore,
blockRelationStore,
multisetStore,
ghostdagDataStore,
consensusStateStore,
utxoDiffStore,
blockHeaderStore,
headersSelectedTipStore,
pruningStore,
},
}
return csm, nil
}