mirror of
https://github.com/kaspanet/kaspad.git
synced 2026-03-22 08:03:34 +00:00
* [NOD-1190] Move non-processBlock stuff out of process.go. * [NOD-1190] Move everything out of accept.go. * [NOD-1190] Move all processBlock functions to process.go. * [NOD-1190] Move orphan stuff to orphan.go. * [NOD-1190] Remove thresholdstate stuff. * [NOD-1190] Move isSynced to sync_rate.go. * [NOD-1190] Move delayed block stuff to delayed_blocks.go. * [NOD-1190] Rename orphans.go to orphaned_blocks.go. * [NOD-1190] Move non-BlockDAG structs out of dag.go. * [NOD-1190] Remove unused fields. * [NOD-1190] Fixup BlockDAG.New a bit. * [NOD-1190] Move sequence lock stuff to sequence_lock.go * [NOD-1190] Move some multiset stuff out of dag.go. * [NOD-1190] Move finality stuff out of dag.go. * [NOD-1190] Move blocklocator stuff out of dag.go. * [NOD-1190] Move confirmation stuff out of dag.go. * [NOD-1190] Move utxo and selected parent chain stuff out of dag.go. * [NOD-1190] Move BlockDAG lock functions to the beginning of dag.go. * [NOD-1190] Move verifyAndBuildUTXO out of process.go. * [NOD-1190] Extract handleProcessBlockError to a function. * [NOD-1190] Remove daglock unlock in notifyBlockAccepted. * [NOD-1190] Extract checkDuplicateBlock to a method. * [NOD-1190] Fix merge errors. * [NOD-1190] Remove unused parameter from CalcSequenceLock. * [NOD-1190] Extract processBlock contents into functions. * [NOD-1190] Fix parent delayed blocks not marking their children as delayed * [NOD-1190] Fix TestProcessDelayedBlocks. * [NOD-1190] Extract stuff in maybeAcceptBlock to separate functions. * [NOD-1190] Rename handleProcessBlockError to handleConnectBlockError. * [NOD-1190] Remove some comments. * [NOD-1190] Use lowercase in error messages. * [NOD-1190] Rename createNewBlockNode to createBlockNodeFromBlock. * [NOD-1190] Rename orphaned_blocks.go to orpan_blocks.go. * [NOD-1190] Extract validateUTXOCommitment to a separate function. * [NOD-1190] Fix a bug in validateUTXOCommitment. * [NOD-1190] Rename checkBlockTxsFinalized to checkBlockTransactionsFinalized. * [NOD-1190] Add a comment over createBlockNodeFromBlock. * [NOD-1190] Fold validateAllTxsFinalized into checkBlockTransactionsFinalized. * [NOD-1190] Return parents from checkBlockParents. * [NOD-1190] Remove the processBlock prefix from the functions that had it. * [NOD-1190] Begin extracting functions out of checkTransactionSanity. * [NOD-1190] Finish extracting functions out of checkTransactionSanity. * [NOD-1190] Remove an unused parameter. * [NOD-1190] Fix merge errors. * [NOD-1190] Added an explanation as to why we change the nonce in TestProcessDelayedBlocks. * [NOD-1190] Fix a comment. * [NOD-1190] Fix a comment. * [NOD-1190] Fix a typo. * [NOD-1190] Replace checkBlockParents with handleLookupParentNodesError.
85 lines
2.3 KiB
Go
85 lines
2.3 KiB
Go
package blockdag
|
|
|
|
import (
|
|
"github.com/kaspanet/go-secp256k1"
|
|
"github.com/kaspanet/kaspad/domainmessage"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// calcMultiset returns the multiset of the past UTXO of the given block.
|
|
func (node *blockNode) calcMultiset(dag *BlockDAG, acceptanceData MultiBlockTxsAcceptanceData,
|
|
selectedParentPastUTXO UTXOSet) (*secp256k1.MultiSet, error) {
|
|
|
|
return node.pastUTXOMultiSet(dag, acceptanceData, selectedParentPastUTXO)
|
|
}
|
|
|
|
func (node *blockNode) pastUTXOMultiSet(dag *BlockDAG, acceptanceData MultiBlockTxsAcceptanceData,
|
|
selectedParentPastUTXO UTXOSet) (*secp256k1.MultiSet, error) {
|
|
|
|
ms, err := node.selectedParentMultiset(dag)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for _, blockAcceptanceData := range acceptanceData {
|
|
for _, txAcceptanceData := range blockAcceptanceData.TxAcceptanceData {
|
|
if !txAcceptanceData.IsAccepted {
|
|
continue
|
|
}
|
|
|
|
tx := txAcceptanceData.Tx.MsgTx()
|
|
|
|
var err error
|
|
ms, err = addTxToMultiset(ms, tx, selectedParentPastUTXO, node.blueScore)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
}
|
|
return ms, nil
|
|
}
|
|
|
|
// selectedParentMultiset returns the multiset of the node's selected
|
|
// parent. If the node is the genesis blockNode then it does not have
|
|
// a selected parent, in which case return a new, empty multiset.
|
|
func (node *blockNode) selectedParentMultiset(dag *BlockDAG) (*secp256k1.MultiSet, error) {
|
|
if node.isGenesis() {
|
|
return secp256k1.NewMultiset(), nil
|
|
}
|
|
|
|
ms, err := dag.multisetStore.multisetByBlockNode(node.selectedParent)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return ms, nil
|
|
}
|
|
|
|
func addTxToMultiset(ms *secp256k1.MultiSet, tx *domainmessage.MsgTx, pastUTXO UTXOSet, blockBlueScore uint64) (*secp256k1.MultiSet, error) {
|
|
for _, txIn := range tx.TxIn {
|
|
entry, ok := pastUTXO.Get(txIn.PreviousOutpoint)
|
|
if !ok {
|
|
return nil, errors.Errorf("Couldn't find entry for outpoint %s", txIn.PreviousOutpoint)
|
|
}
|
|
|
|
var err error
|
|
ms, err = removeUTXOFromMultiset(ms, entry, &txIn.PreviousOutpoint)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
isCoinbase := tx.IsCoinBase()
|
|
for i, txOut := range tx.TxOut {
|
|
outpoint := *domainmessage.NewOutpoint(tx.TxID(), uint32(i))
|
|
entry := NewUTXOEntry(txOut, isCoinbase, blockBlueScore)
|
|
|
|
var err error
|
|
ms, err = addUTXOToMultiset(ms, entry, &outpoint)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return ms, nil
|
|
}
|