mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-09-13 13:00:10 +00:00

* [NOD-1223] Delete unused files/packages. * [NOD-1223] Move signal and limits to the os package. * [NOD-1223] Put database and dbaccess into the db package. * [NOD-1223] Fold the logs package into the logger package. * [NOD-1223] Rename domainmessage to appmessage. * [NOD-1223] Rename to/from DomainMessage to AppMessage. * [NOD-1223] Move appmessage to the app packge. * [NOD-1223] Move protocol to the app packge. * [NOD-1223] Move the network package to the infrastructure packge. * [NOD-1223] Rename cmd to executables. * [NOD-1223] Fix go.doc in the logger package.
85 lines
2.3 KiB
Go
85 lines
2.3 KiB
Go
package blockdag
|
|
|
|
import (
|
|
"github.com/kaspanet/go-secp256k1"
|
|
"github.com/kaspanet/kaspad/app/appmessage"
|
|
"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 *appmessage.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 := *appmessage.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
|
|
}
|