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

81 lines
1.9 KiB
Go

package externalapi
import "math/big"
// DomainBlock represents a Kaspa block
type DomainBlock struct {
Header BlockHeader
Transactions []*DomainTransaction
}
// Clone returns a clone of DomainBlock
func (block *DomainBlock) Clone() *DomainBlock {
transactionClone := make([]*DomainTransaction, len(block.Transactions))
for i, tx := range block.Transactions {
transactionClone[i] = tx.Clone()
}
return &DomainBlock{
Header: block.Header,
Transactions: transactionClone,
}
}
// If this doesn't compile, it means the type definition has been changed, so it's
// an indication to update Equal and Clone accordingly.
var _ = DomainBlock{nil, []*DomainTransaction{}}
// Equal returns whether block equals to other
func (block *DomainBlock) Equal(other *DomainBlock) bool {
if block == nil || other == nil {
return block == other
}
if len(block.Transactions) != len(other.Transactions) {
return false
}
if !block.Header.Equal(other.Header) {
return false
}
for i, tx := range block.Transactions {
if !tx.Equal(other.Transactions[i]) {
return false
}
}
return true
}
// BlockHeader represents an immutable block header.
type BlockHeader interface {
BaseBlockHeader
ToMutable() MutableBlockHeader
}
// BaseBlockHeader represents the header part of a Kaspa block
type BaseBlockHeader interface {
Version() uint16
ParentHashes() []*DomainHash
HashMerkleRoot() *DomainHash
AcceptedIDMerkleRoot() *DomainHash
UTXOCommitment() *DomainHash
TimeInMilliseconds() int64
Bits() uint32
Nonce() uint64
DAAScore() uint64
BlueWork() *big.Int
FinalityPoint() *DomainHash
Equal(other BaseBlockHeader) bool
}
// MutableBlockHeader represents a block header that can be mutated, but only
// the fields that are relevant to mining (Nonce and TimeInMilliseconds).
type MutableBlockHeader interface {
BaseBlockHeader
ToImmutable() BlockHeader
SetNonce(nonce uint64)
SetTimeInMilliseconds(timeInMilliseconds int64)
}