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

* '' * '' * '' * Changes genesis block version to 0. * a * a * All tests are done. * All tests passed for changed block version from int32 to uint16 * Adds validation of rejecting blocks with unknown versions. * Changes txn version from int32 to uint16. * . * Adds comments to exported functions. * Change functions name from ConvertFromRpcScriptPubKeyToRPCScriptPubKey to ConvertFromAppMsgRPCScriptPubKeyToRPCScriptPubKey and from ConvertFromRPCScriptPubKeyToRpcScriptPubKey to ConvertFromRPCScriptPubKeyToAppMsgRPCScriptPubKey * change comment to "ScriptPublicKey represents a Kaspad ScriptPublicKey" * delete part (tx.Version < 0) that cannot be exist on the if statement. * Revert protobuf version. * Fix a comment. * Fix a comment. * Rename a variable. * Rename a variable. * Remove a const. * Rename a type. * Rename a field. * Rename a field. * Remove commented-out code. * Remove dangerous nil case in DomainTransactionOutput.Clone(). * Remove a constant. * Fix a string. * Fix wrong totalScriptPubKeySize in transactionMassStandalonePart. * Remove a constant. * Remove an unused error. * Fix a serialization error. * Specify version types to be uint16 explicitly. * Use constants.ScriptPublicKeyVersion. * Fix a bad test. * Remove some whitespace. * Add a case to utxoEntry.Equal(). * Rename scriptPubKey to scriptPublicKey. * Remove a TODO. * Rename constants. * Rename a variable. * Add version to parseShortForm. Co-authored-by: tal <tal@daglabs.com> Co-authored-by: stasatdaglabs <stas@daglabs.com>
49 lines
1.7 KiB
Go
49 lines
1.7 KiB
Go
package transactionvalidator
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
"github.com/kaspanet/kaspad/domain/consensus/ruleerrors"
|
|
"github.com/kaspanet/kaspad/domain/consensus/utils/estimatedsize"
|
|
"github.com/kaspanet/kaspad/domain/consensus/utils/transactionhelper"
|
|
"github.com/kaspanet/kaspad/domain/consensus/utils/txscript"
|
|
)
|
|
|
|
func (v *transactionValidator) transactionMassStandalonePart(tx *externalapi.DomainTransaction) uint64 {
|
|
size := estimatedsize.TransactionEstimatedSerializedSize(tx)
|
|
|
|
totalScriptPubKeySize := uint64(0)
|
|
for _, output := range tx.Outputs {
|
|
totalScriptPubKeySize += 2 //output.ScriptPublicKey.Version (uint16)
|
|
totalScriptPubKeySize += uint64(len(output.ScriptPublicKey.Script))
|
|
}
|
|
|
|
return size*v.massPerTxByte + totalScriptPubKeySize*v.massPerScriptPubKeyByte
|
|
}
|
|
|
|
func (v *transactionValidator) transactionMass(tx *externalapi.DomainTransaction) (uint64, error) {
|
|
if transactionhelper.IsCoinBase(tx) {
|
|
return 0, nil
|
|
}
|
|
|
|
standaloneMass := v.transactionMassStandalonePart(tx)
|
|
sigOpsCount := uint64(0)
|
|
var missingOutpoints []*externalapi.DomainOutpoint
|
|
for _, input := range tx.Inputs {
|
|
utxoEntry := input.UTXOEntry
|
|
if utxoEntry == nil {
|
|
missingOutpoints = append(missingOutpoints, &input.PreviousOutpoint)
|
|
continue
|
|
}
|
|
// Count the precise number of signature operations in the
|
|
// referenced public key script.
|
|
sigScript := input.SignatureScript
|
|
isP2SH := txscript.IsPayToScriptHash(utxoEntry.ScriptPublicKey())
|
|
sigOpsCount += uint64(txscript.GetPreciseSigOpCount(sigScript, utxoEntry.ScriptPublicKey(), isP2SH))
|
|
}
|
|
if len(missingOutpoints) > 0 {
|
|
return 0, ruleerrors.NewErrMissingTxOut(missingOutpoints)
|
|
}
|
|
|
|
return standaloneMass + sigOpsCount*v.massPerSigOp, nil
|
|
}
|