Documentation ¶
Index ¶
- Constants
- func HashesEqual(a, b []*DomainHash) bool
- type AcceptanceData
- type BaseBlockHeader
- type BlockAcceptanceData
- type BlockHeader
- type BlockInfo
- type BlockInsertionResult
- type BlockLocator
- type BlockStatus
- type Consensus
- type DomainBlock
- type DomainCoinbaseData
- type DomainHash
- func CloneHashes(hashes []*DomainHash) []*DomainHash
- func NewDomainHashFromByteArray(hashBytes *[DomainHashSize]byte) *DomainHash
- func NewDomainHashFromByteSlice(hashBytes []byte) (*DomainHash, error)
- func NewDomainHashFromString(hashString string) (*DomainHash, error)
- func NewZeroHash() *DomainHash
- func (hash *DomainHash) ByteArray() *[DomainHashSize]byte
- func (hash *DomainHash) ByteSlice() []byte
- func (hash *DomainHash) Equal(other *DomainHash) bool
- func (hash *DomainHash) Less(other *DomainHash) bool
- func (hash *DomainHash) LessOrEqual(other *DomainHash) bool
- func (hash DomainHash) String() string
- type DomainOutpoint
- type DomainSubnetworkID
- type DomainTransaction
- type DomainTransactionID
- func (id *DomainTransactionID) ByteArray() *[DomainHashSize]byte
- func (id *DomainTransactionID) ByteSlice() []byte
- func (id *DomainTransactionID) Clone() *DomainTransactionID
- func (id *DomainTransactionID) Equal(other *DomainTransactionID) bool
- func (id *DomainTransactionID) Less(other *DomainTransactionID) bool
- func (id *DomainTransactionID) LessOrEqual(other *DomainTransactionID) bool
- func (id DomainTransactionID) String() string
- type DomainTransactionInput
- type DomainTransactionOutput
- type MutableBlockHeader
- type MutableUTXODiff
- type OutpointAndUTXOEntryPair
- type ReadOnlyUTXOSetIterator
- type ScriptPublicKey
- type SelectedChainPath
- type SyncInfo
- type TransactionAcceptanceData
- type UTXOCollection
- type UTXODiff
- type UTXOEntry
- type VirtualInfo
Constants ¶
const DomainHashSize = 32
DomainHashSize of array used to store hashes.
const DomainSubnetworkIDSize = 20
DomainSubnetworkIDSize is the size of the array used to store subnetwork IDs.
Variables ¶
This section is empty.
Functions ¶
func HashesEqual ¶
func HashesEqual(a, b []*DomainHash) bool
HashesEqual returns whether the given hash slices are equal.
Types ¶
type AcceptanceData ¶
type AcceptanceData []*BlockAcceptanceData
AcceptanceData stores data about which transactions were accepted by a block. It's ordered in the same way as the block merge set blues.
func (AcceptanceData) Clone ¶
func (ad AcceptanceData) Clone() AcceptanceData
Clone clones the AcceptanceData
func (AcceptanceData) Equal ¶
func (ad AcceptanceData) Equal(other AcceptanceData) bool
Equal returns whether ad equals to other
type BaseBlockHeader ¶
type BaseBlockHeader interface { Version() uint16 ParentHashes() []*DomainHash HashMerkleRoot() *DomainHash AcceptedIDMerkleRoot() *DomainHash UTXOCommitment() *DomainHash TimeInMilliseconds() int64 Bits() uint32 Nonce() uint64 Equal(other BaseBlockHeader) bool }
BaseBlockHeader represents the header part of a Kaspa block
type BlockAcceptanceData ¶
type BlockAcceptanceData struct { BlockHash *DomainHash TransactionAcceptanceData []*TransactionAcceptanceData }
BlockAcceptanceData stores all transactions in a block with an indication if they were accepted or not by some other block
func (*BlockAcceptanceData) Clone ¶
func (bad *BlockAcceptanceData) Clone() *BlockAcceptanceData
Clone returns a clone of BlockAcceptanceData
func (*BlockAcceptanceData) Equal ¶
func (bad *BlockAcceptanceData) Equal(other *BlockAcceptanceData) bool
Equal returns whether bad equals to other
type BlockHeader ¶
type BlockHeader interface { BaseBlockHeader ToMutable() MutableBlockHeader }
BlockHeader represents an immutable block header.
type BlockInfo ¶
type BlockInfo struct { Exists bool BlockStatus BlockStatus BlueScore uint64 }
BlockInfo contains various information about a specific block
type BlockInsertionResult ¶
type BlockInsertionResult struct { VirtualSelectedParentChainChanges *SelectedChainPath VirtualUTXODiff UTXODiff VirtualParents []*DomainHash }
BlockInsertionResult is auxiliary data returned from ValidateAndInsertBlock
type BlockLocator ¶
type BlockLocator []*DomainHash
BlockLocator is used to help locate a specific block. The algorithm for building the block locator is to add block hashes in reverse order on the block's selected parent chain until the desired stop block is reached. In order to keep the list of locator hashes to a reasonable number of entries, the step between each entry is doubled each loop iteration to exponentially decrease the number of hashes as a function of the distance from the block being located.
For example, assume a selected parent chain with IDs as depicted below, and the stop block is genesis:
genesis -> 1 -> 2 -> ... -> 15 -> 16 -> 17 -> 18
The block locator for block 17 would be the hashes of blocks:
[17 16 14 11 7 2 genesis]
func (BlockLocator) Clone ¶
func (locator BlockLocator) Clone() BlockLocator
Clone returns a clone of BlockLocator
type BlockStatus ¶
type BlockStatus byte
BlockStatus represents the validation state of the block.
const ( // StatusInvalid indicates that the block is invalid. StatusInvalid BlockStatus = iota // StatusUTXOValid indicates the block is valid from any UTXO related aspects and has passed all the other validations as well. StatusUTXOValid // StatusUTXOPendingVerification indicates that the block is pending verification against its past UTXO-Set, either // because it was not yet verified since the block was never in the selected parent chain, or if the // block violates finality. StatusUTXOPendingVerification // StatusDisqualifiedFromChain indicates that the block is not eligible to be a selected parent. StatusDisqualifiedFromChain // StatusHeaderOnly indicates that the block transactions are not held (pruned or wasn't added yet) StatusHeaderOnly )
func (BlockStatus) Clone ¶
func (bs BlockStatus) Clone() BlockStatus
Clone returns a clone of BlockStatus
func (BlockStatus) Equal ¶
func (bs BlockStatus) Equal(other BlockStatus) bool
Equal returns whether bs equals to other
func (BlockStatus) String ¶
func (bs BlockStatus) String() string
type Consensus ¶
type Consensus interface { BuildBlock(coinbaseData *DomainCoinbaseData, transactions []*DomainTransaction) (*DomainBlock, error) ValidateAndInsertBlock(block *DomainBlock) (*BlockInsertionResult, error) ValidateTransactionAndPopulateWithConsensusData(transaction *DomainTransaction) error GetBlock(blockHash *DomainHash) (*DomainBlock, error) GetBlockHeader(blockHash *DomainHash) (BlockHeader, error) GetBlockInfo(blockHash *DomainHash) (*BlockInfo, error) GetBlockChildren(blockHash *DomainHash) ([]*DomainHash, error) GetBlockAcceptanceData(blockHash *DomainHash) (AcceptanceData, error) GetHashesBetween(lowHash, highHash *DomainHash, maxBlueScoreDifference uint64) (hashes []*DomainHash, actualHighHash *DomainHash, err error) GetMissingBlockBodyHashes(highHash *DomainHash) ([]*DomainHash, error) GetPruningPointUTXOs(expectedPruningPointHash *DomainHash, fromOutpoint *DomainOutpoint, limit int) ([]*OutpointAndUTXOEntryPair, error) GetVirtualUTXOs(expectedVirtualParents []*DomainHash, fromOutpoint *DomainOutpoint, limit int) ([]*OutpointAndUTXOEntryPair, error) PruningPoint() (*DomainHash, error) ClearImportedPruningPointData() error AppendImportedPruningPointUTXOs(outpointAndUTXOEntryPairs []*OutpointAndUTXOEntryPair) error ValidateAndInsertImportedPruningPoint(newPruningPoint *DomainBlock) error GetVirtualSelectedParent() (*DomainHash, error) CreateBlockLocator(lowHash, highHash *DomainHash, limit uint32) (BlockLocator, error) CreateHeadersSelectedChainBlockLocator(lowHash, highHash *DomainHash) (BlockLocator, error) CreateFullHeadersSelectedChainBlockLocator() (BlockLocator, error) GetSyncInfo() (*SyncInfo, error) Tips() ([]*DomainHash, error) GetVirtualInfo() (*VirtualInfo, error) IsValidPruningPoint(blockHash *DomainHash) (bool, error) GetVirtualSelectedParentChainFromBlock(blockHash *DomainHash) (*SelectedChainPath, error) IsInSelectedParentChainOf(blockHashA *DomainHash, blockHashB *DomainHash) (bool, error) GetHeadersSelectedTip() (*DomainHash, error) Anticone(blockHash *DomainHash) ([]*DomainHash, error) }
Consensus maintains the current core state of the node
type DomainBlock ¶
type DomainBlock struct { Header BlockHeader Transactions []*DomainTransaction }
DomainBlock represents a Kaspa block
func (*DomainBlock) Clone ¶
func (block *DomainBlock) Clone() *DomainBlock
Clone returns a clone of DomainBlock
func (*DomainBlock) Equal ¶
func (block *DomainBlock) Equal(other *DomainBlock) bool
Equal returns whether block equals to other
type DomainCoinbaseData ¶
type DomainCoinbaseData struct { ScriptPublicKey *ScriptPublicKey ExtraData []byte }
DomainCoinbaseData contains data by which a coinbase transaction is built
func (*DomainCoinbaseData) Clone ¶
func (dcd *DomainCoinbaseData) Clone() *DomainCoinbaseData
Clone returns a clone of DomainCoinbaseData
type DomainHash ¶
type DomainHash struct {
// contains filtered or unexported fields
}
DomainHash is the domain representation of a Hash
func CloneHashes ¶
func CloneHashes(hashes []*DomainHash) []*DomainHash
CloneHashes returns a clone of the given hashes slice. Note: since DomainHash is a read-only type, the clone is shallow
func NewDomainHashFromByteArray ¶
func NewDomainHashFromByteArray(hashBytes *[DomainHashSize]byte) *DomainHash
NewDomainHashFromByteArray constructs a new DomainHash out of a byte array
func NewDomainHashFromByteSlice ¶
func NewDomainHashFromByteSlice(hashBytes []byte) (*DomainHash, error)
NewDomainHashFromByteSlice constructs a new DomainHash out of a byte slice. Returns an error if the length of the byte slice is not exactly `DomainHashSize`
func NewDomainHashFromString ¶
func NewDomainHashFromString(hashString string) (*DomainHash, error)
NewDomainHashFromString constructs a new DomainHash out of a hex-encoded string. Returns an error if the length of the string is not exactly `DomainHashSize * 2`
func NewZeroHash ¶ added in v0.10.0
func NewZeroHash() *DomainHash
NewZeroHash returns a DomainHash that represents the zero value (0x000000...000)
func (*DomainHash) ByteArray ¶
func (hash *DomainHash) ByteArray() *[DomainHashSize]byte
ByteArray returns the bytes in this hash represented as a byte array. The hash bytes are cloned, therefore it is safe to modify the resulting array.
func (*DomainHash) ByteSlice ¶
func (hash *DomainHash) ByteSlice() []byte
ByteSlice returns the bytes in this hash represented as a byte slice. The hash bytes are cloned, therefore it is safe to modify the resulting slice.
func (*DomainHash) Equal ¶
func (hash *DomainHash) Equal(other *DomainHash) bool
Equal returns whether hash equals to other
func (*DomainHash) Less ¶
func (hash *DomainHash) Less(other *DomainHash) bool
Less returns true if hash is less than other
func (*DomainHash) LessOrEqual ¶
func (hash *DomainHash) LessOrEqual(other *DomainHash) bool
LessOrEqual returns true if hash is smaller or equal to other
func (DomainHash) String ¶
func (hash DomainHash) String() string
String returns the Hash as the hexadecimal string of the hash.
type DomainOutpoint ¶
type DomainOutpoint struct { TransactionID DomainTransactionID Index uint32 }
DomainOutpoint represents a Kaspa transaction outpoint
func NewDomainOutpoint ¶
func NewDomainOutpoint(id *DomainTransactionID, index uint32) *DomainOutpoint
NewDomainOutpoint instantiates a new DomainOutpoint with the given id and index
func (*DomainOutpoint) Clone ¶
func (op *DomainOutpoint) Clone() *DomainOutpoint
Clone returns a clone of DomainOutpoint
func (*DomainOutpoint) Equal ¶
func (op *DomainOutpoint) Equal(other *DomainOutpoint) bool
Equal returns whether op equals to other
func (DomainOutpoint) String ¶
func (op DomainOutpoint) String() string
String stringifies an outpoint.
type DomainSubnetworkID ¶
type DomainSubnetworkID [DomainSubnetworkIDSize]byte
DomainSubnetworkID is the domain representation of a Subnetwork ID
func (*DomainSubnetworkID) Clone ¶
func (id *DomainSubnetworkID) Clone() *DomainSubnetworkID
Clone returns a clone of DomainSubnetworkID
func (*DomainSubnetworkID) Equal ¶
func (id *DomainSubnetworkID) Equal(other *DomainSubnetworkID) bool
Equal returns whether id equals to other
func (DomainSubnetworkID) String ¶
func (id DomainSubnetworkID) String() string
String stringifies a subnetwork ID.
type DomainTransaction ¶
type DomainTransaction struct { Version uint16 Inputs []*DomainTransactionInput Outputs []*DomainTransactionOutput LockTime uint64 SubnetworkID DomainSubnetworkID Gas uint64 Payload []byte Fee uint64 Mass uint64 // ID is a field that is used to cache the transaction ID. // Always use consensushashing.TransactionID instead of accessing this field directly ID *DomainTransactionID }
DomainTransaction represents a Kaspa transaction
func (*DomainTransaction) Clone ¶
func (tx *DomainTransaction) Clone() *DomainTransaction
Clone returns a clone of DomainTransaction
func (*DomainTransaction) Equal ¶
func (tx *DomainTransaction) Equal(other *DomainTransaction) bool
Equal returns whether tx equals to other
type DomainTransactionID ¶
type DomainTransactionID DomainHash
DomainTransactionID represents the ID of a Kaspa transaction
func NewDomainTransactionIDFromByteArray ¶
func NewDomainTransactionIDFromByteArray(transactionIDBytes *[DomainHashSize]byte) *DomainTransactionID
NewDomainTransactionIDFromByteArray constructs a new TransactionID out of a byte array
func NewDomainTransactionIDFromByteSlice ¶
func NewDomainTransactionIDFromByteSlice(transactionIDBytes []byte) (*DomainTransactionID, error)
NewDomainTransactionIDFromByteSlice constructs a new TransactionID out of a byte slice Returns an error if the length of the byte slice is not exactly `DomainHashSize`
func NewDomainTransactionIDFromString ¶
func NewDomainTransactionIDFromString(transactionIDString string) (*DomainTransactionID, error)
NewDomainTransactionIDFromString constructs a new TransactionID out of a string Returns an error if the length of the string is not exactly `DomainHashSize * 2`
func (*DomainTransactionID) ByteArray ¶
func (id *DomainTransactionID) ByteArray() *[DomainHashSize]byte
ByteArray returns the bytes in this transactionID represented as a byte array. The transactionID bytes are cloned, therefore it is safe to modify the resulting array.
func (*DomainTransactionID) ByteSlice ¶
func (id *DomainTransactionID) ByteSlice() []byte
ByteSlice returns the bytes in this transactionID represented as a byte slice. The transactionID bytes are cloned, therefore it is safe to modify the resulting slice.
func (*DomainTransactionID) Clone ¶
func (id *DomainTransactionID) Clone() *DomainTransactionID
Clone returns a clone of DomainTransactionID
func (*DomainTransactionID) Equal ¶
func (id *DomainTransactionID) Equal(other *DomainTransactionID) bool
Equal returns whether id equals to other
func (*DomainTransactionID) Less ¶
func (id *DomainTransactionID) Less(other *DomainTransactionID) bool
Less returns true if id is less than other
func (*DomainTransactionID) LessOrEqual ¶
func (id *DomainTransactionID) LessOrEqual(other *DomainTransactionID) bool
LessOrEqual returns true if id is smaller or equal to other
func (DomainTransactionID) String ¶
func (id DomainTransactionID) String() string
String stringifies a transaction ID.
type DomainTransactionInput ¶
type DomainTransactionInput struct { PreviousOutpoint DomainOutpoint SignatureScript []byte Sequence uint64 UTXOEntry UTXOEntry }
DomainTransactionInput represents a Kaspa transaction input
func (*DomainTransactionInput) Clone ¶
func (input *DomainTransactionInput) Clone() *DomainTransactionInput
Clone returns a clone of DomainTransactionInput
func (*DomainTransactionInput) Equal ¶
func (input *DomainTransactionInput) Equal(other *DomainTransactionInput) bool
Equal returns whether input equals to other
type DomainTransactionOutput ¶
type DomainTransactionOutput struct { Value uint64 ScriptPublicKey *ScriptPublicKey }
DomainTransactionOutput represents a Kaspad transaction output
func (*DomainTransactionOutput) Clone ¶
func (output *DomainTransactionOutput) Clone() *DomainTransactionOutput
Clone returns a clone of DomainTransactionOutput
func (*DomainTransactionOutput) Equal ¶
func (output *DomainTransactionOutput) Equal(other *DomainTransactionOutput) bool
Equal returns whether output equals to other
type MutableBlockHeader ¶
type MutableBlockHeader interface { BaseBlockHeader ToImmutable() BlockHeader SetNonce(nonce uint64) SetTimeInMilliseconds(timeInMilliseconds int64) }
MutableBlockHeader represents a block header that can be mutated, but only the fields that are relevant to mining (Nonce and TimeInMilliseconds).
type MutableUTXODiff ¶ added in v0.8.10
type MutableUTXODiff interface { ToImmutable() UTXODiff WithDiff(other UTXODiff) (UTXODiff, error) DiffFrom(other UTXODiff) (UTXODiff, error) ToAdd() UTXOCollection ToRemove() UTXOCollection WithDiffInPlace(other UTXODiff) error AddTransaction(transaction *DomainTransaction, blockDAAScore uint64) error }
MutableUTXODiff represents a UTXO-Diff that can be mutated
type OutpointAndUTXOEntryPair ¶
type OutpointAndUTXOEntryPair struct { Outpoint *DomainOutpoint UTXOEntry UTXOEntry }
OutpointAndUTXOEntryPair is an outpoint along with its respective UTXO entry
type ReadOnlyUTXOSetIterator ¶ added in v0.8.10
type ReadOnlyUTXOSetIterator interface { First() bool Next() bool Get() (outpoint *DomainOutpoint, utxoEntry UTXOEntry, err error) Close() error }
ReadOnlyUTXOSetIterator is an iterator over all entries in a ReadOnlyUTXOSet
type ScriptPublicKey ¶
ScriptPublicKey represents a Kaspad ScriptPublicKey
type SelectedChainPath ¶
type SelectedChainPath struct { Added []*DomainHash Removed []*DomainHash }
SelectedChainPath is a path the of the selected chains between two blocks.
type TransactionAcceptanceData ¶
type TransactionAcceptanceData struct { Transaction *DomainTransaction Fee uint64 IsAccepted bool TransactionInputUTXOEntries []UTXOEntry }
TransactionAcceptanceData stores a transaction together with an indication if it was accepted or not by some block
func (*TransactionAcceptanceData) Clone ¶
func (tad *TransactionAcceptanceData) Clone() *TransactionAcceptanceData
Clone returns a clone of TransactionAcceptanceData
func (*TransactionAcceptanceData) Equal ¶
func (tad *TransactionAcceptanceData) Equal(other *TransactionAcceptanceData) bool
Equal returns whether tad equals to other
type UTXOCollection ¶ added in v0.8.10
type UTXOCollection interface { Iterator() ReadOnlyUTXOSetIterator Get(outpoint *DomainOutpoint) (UTXOEntry, bool) Contains(outpoint *DomainOutpoint) bool Len() int }
UTXOCollection represents a collection of UTXO entries, indexed by their outpoint
type UTXODiff ¶ added in v0.8.10
type UTXODiff interface { ToAdd() UTXOCollection ToRemove() UTXOCollection WithDiff(other UTXODiff) (UTXODiff, error) DiffFrom(other UTXODiff) (UTXODiff, error) CloneMutable() MutableUTXODiff }
UTXODiff represents the diff between two UTXO sets
type UTXOEntry ¶
type UTXOEntry interface { Amount() uint64 ScriptPublicKey() *ScriptPublicKey // The public key script for the output. BlockDAAScore() uint64 // Blue score of the block accepting the tx. IsCoinbase() bool Equal(other UTXOEntry) bool }
UTXOEntry houses details about an individual transaction output in a utxo set such as whether or not it was contained in a coinbase tx, the blue score of the block that accepts the tx, its public key script, and how much it pays.
type VirtualInfo ¶
type VirtualInfo struct { ParentHashes []*DomainHash Bits uint32 PastMedianTime int64 BlueScore uint64 }
VirtualInfo represents information about the virtual block needed by external components