Ori Newman 765dd170e4
Optimizations and header size reduce hardfork (#1853)
* Modify DefaultTimeout to 120 seconds

A temporary workaround for nodes having trouble to sync (currently the download of pruning point related data during IBD takes more than 30 seconds)

* Cache existence in reachability store

* Cache block level in the header

* Fix IBD indication on submit block

* Add hardForkOmitGenesisFromParentsDAAScore logic

* Fix NumThreads bug in the wallet

* Get rid of ParentsAtLevel header method

* Fix a bug in BuildPruningPointProof

* Increase race detector timeout

* Add cache to BuildPruningPointProof

* Add comments and temp comment out go vet

* Fix ParentsAtLevel

* Dont fill empty parents

* Change HardForkOmitGenesisFromParentsDAAScore in fast netsync test

* Add --allow-submit-block-when-not-synced in stability tests

* Fix TestPruning

* Return fast tests

* Fix off by one error on kaspawallet

* Fetch only one block with trusted data at a time

* Update fork DAA score

* Don't ban for unexpected message type

* Fix tests

Co-authored-by: Michael Sutton <mikisiton2@gmail.com>
Co-authored-by: Ori Newman <>
2021-11-22 09:00:39 +02:00

84 lines
2.0 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
Parents() []BlockLevelParents
DirectParents() BlockLevelParents
HashMerkleRoot() *DomainHash
AcceptedIDMerkleRoot() *DomainHash
UTXOCommitment() *DomainHash
TimeInMilliseconds() int64
Bits() uint32
Nonce() uint64
DAAScore() uint64
BlueScore() uint64
BlueWork() *big.Int
PruningPoint() *DomainHash
BlockLevel() int
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)
}