mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-07-08 22:02:34 +00:00
Remove redundant rule errors (#1256)
* Remove ErrTimeTooNew and rename ErrBlockIsTooMuchInTheFuture to ErrTimeTooMuchInTheFuture * Remove ErrBlockMassTooHigh * Remove ErrHighHash * Remove ErrInvalidSubnetwork + some cleanup around subnetwork validation * Remove ErrTxMassTooHigh * Remove ErrBadTxInput * Remove ErrOverwriteTx * Remove ErrTooManySigOps * Remove ErrParentBlockUnknown * Remove ErrParentBlockIsNotCurrentTips * Remove ErrWithDiff * Remove ErrFinality * Remove ErrDelayedBlockIsNotAllowed + ErrOrphanBlockIsNotAllowed * Remove ErrSelectedParentDisqualifiedFromChain * Remove ErrBuildInTransactionHasGas * Remove ErrBadFees
This commit is contained in:
parent
5632bee49d
commit
e7edfaceb7
@ -52,7 +52,7 @@ func (v *blockValidator) checkBlockTimestampInIsolation(header *externalapi.Doma
|
|||||||
maxCurrentTime := now + int64(v.timestampDeviationTolerance)*v.targetTimePerBlock.Milliseconds()
|
maxCurrentTime := now + int64(v.timestampDeviationTolerance)*v.targetTimePerBlock.Milliseconds()
|
||||||
if blockTimestamp > maxCurrentTime {
|
if blockTimestamp > maxCurrentTime {
|
||||||
return errors.Wrapf(
|
return errors.Wrapf(
|
||||||
ruleerrors.ErrBlockIsTooMuchInTheFuture, "The block timestamp is in the future.")
|
ruleerrors.ErrTimeTooMuchInTheFuture, "The block timestamp is in the future.")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ func (v *transactionValidator) checkTransactionOutputAmounts(tx *externalapi.Dom
|
|||||||
totalSompiOut := uint64(0)
|
totalSompiOut := uint64(0)
|
||||||
// Calculate the total output amount for this transaction. It is safe
|
// Calculate the total output amount for this transaction. It is safe
|
||||||
// to ignore overflow and out of range errors here because those error
|
// to ignore overflow and out of range errors here because those error
|
||||||
// conditions would have already been caught by checkTransactionSanity.
|
// conditions would have already been caught by checkTransactionAmountRanges.
|
||||||
for _, output := range tx.Outputs {
|
for _, output := range tx.Outputs {
|
||||||
totalSompiOut += output.Value
|
totalSompiOut += output.Value
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ func (v *transactionValidator) ValidateTransactionInIsolation(tx *externalapi.Do
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: fill it with the right subnetwork id.
|
// TODO: fill it with the node's subnetwork id.
|
||||||
err = v.checkTransactionSubnetwork(tx, nil)
|
err = v.checkTransactionSubnetwork(tx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -167,7 +167,7 @@ func (v *transactionValidator) checkNativeTransactionPayload(tx *externalapi.Dom
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *transactionValidator) checkTransactionSubnetwork(tx *externalapi.DomainTransaction,
|
func (v *transactionValidator) checkTransactionSubnetwork(tx *externalapi.DomainTransaction,
|
||||||
subnetworkID *externalapi.DomainSubnetworkID) error {
|
localNodeSubnetworkID *externalapi.DomainSubnetworkID) error {
|
||||||
if !v.enableNonNativeSubnetworks && tx.SubnetworkID != subnetworks.SubnetworkIDNative &&
|
if !v.enableNonNativeSubnetworks && tx.SubnetworkID != subnetworks.SubnetworkIDNative &&
|
||||||
tx.SubnetworkID != subnetworks.SubnetworkIDCoinbase {
|
tx.SubnetworkID != subnetworks.SubnetworkIDCoinbase {
|
||||||
return errors.Wrapf(ruleerrors.ErrSubnetworksDisabled, "transaction has non native or coinbase "+
|
return errors.Wrapf(ruleerrors.ErrSubnetworksDisabled, "transaction has non native or coinbase "+
|
||||||
@ -176,8 +176,8 @@ func (v *transactionValidator) checkTransactionSubnetwork(tx *externalapi.Domain
|
|||||||
|
|
||||||
// If we are a partial node, only transactions on built in subnetworks
|
// If we are a partial node, only transactions on built in subnetworks
|
||||||
// or our own subnetwork may have a payload
|
// or our own subnetwork may have a payload
|
||||||
isLocalNodeFull := subnetworkID == nil
|
isLocalNodeFull := localNodeSubnetworkID == nil
|
||||||
shouldTxBeFull := subnetworks.IsBuiltIn(tx.SubnetworkID) || subnetworks.IsEqual(&tx.SubnetworkID, subnetworkID)
|
shouldTxBeFull := subnetworks.IsBuiltIn(tx.SubnetworkID) || subnetworks.IsEqual(&tx.SubnetworkID, localNodeSubnetworkID)
|
||||||
if !isLocalNodeFull && !shouldTxBeFull && len(tx.Payload) > 0 {
|
if !isLocalNodeFull && !shouldTxBeFull && len(tx.Payload) > 0 {
|
||||||
return errors.Wrapf(ruleerrors.ErrInvalidPayload,
|
return errors.Wrapf(ruleerrors.ErrInvalidPayload,
|
||||||
"transaction that was expected to be partial has a payload "+
|
"transaction that was expected to be partial has a payload "+
|
||||||
|
@ -14,10 +14,6 @@ var (
|
|||||||
// exists.
|
// exists.
|
||||||
ErrDuplicateBlock = newRuleError("ErrDuplicateBlock")
|
ErrDuplicateBlock = newRuleError("ErrDuplicateBlock")
|
||||||
|
|
||||||
// ErrBlockMassTooHigh indicates the mass of a block exceeds the maximum
|
|
||||||
// allowed limits.
|
|
||||||
ErrBlockMassTooHigh = newRuleError("ErrBlockMassTooHigh")
|
|
||||||
|
|
||||||
// ErrBlockVersionTooOld indicates the block version is too old and is
|
// ErrBlockVersionTooOld indicates the block version is too old and is
|
||||||
// no longer accepted since the majority of the network has upgraded
|
// no longer accepted since the majority of the network has upgraded
|
||||||
// to a newer version.
|
// to a newer version.
|
||||||
@ -27,9 +23,8 @@ var (
|
|||||||
// the last several blocks per the DAG consensus rules.
|
// the last several blocks per the DAG consensus rules.
|
||||||
ErrTimeTooOld = newRuleError("ErrTimeTooOld")
|
ErrTimeTooOld = newRuleError("ErrTimeTooOld")
|
||||||
|
|
||||||
// ErrTimeTooNew indicates the time is too far in the future as compared
|
//ErrTimeTooMuchInTheFuture indicates that the block timestamp is too much in the future.
|
||||||
// the current time.
|
ErrTimeTooMuchInTheFuture = newRuleError("ErrTimeTooMuchInTheFuture")
|
||||||
ErrTimeTooNew = newRuleError("ErrTimeTooNew")
|
|
||||||
|
|
||||||
// ErrNoParents indicates that the block is missing parents
|
// ErrNoParents indicates that the block is missing parents
|
||||||
ErrNoParents = newRuleError("ErrNoParents")
|
ErrNoParents = newRuleError("ErrNoParents")
|
||||||
@ -47,10 +42,6 @@ var (
|
|||||||
// ErrInvalidPoW indicates that the block proof-of-work is invalid.
|
// ErrInvalidPoW indicates that the block proof-of-work is invalid.
|
||||||
ErrInvalidPoW = newRuleError("ErrInvalidPoW")
|
ErrInvalidPoW = newRuleError("ErrInvalidPoW")
|
||||||
|
|
||||||
// ErrHighHash indicates the block does not hash to a value which is
|
|
||||||
// lower than the required target difficultly.
|
|
||||||
ErrHighHash = newRuleError("ErrHighHash")
|
|
||||||
|
|
||||||
// ErrBadMerkleRoot indicates the calculated merkle root does not match
|
// ErrBadMerkleRoot indicates the calculated merkle root does not match
|
||||||
// the expected value.
|
// the expected value.
|
||||||
ErrBadMerkleRoot = newRuleError("ErrBadMerkleRoot")
|
ErrBadMerkleRoot = newRuleError("ErrBadMerkleRoot")
|
||||||
@ -59,9 +50,6 @@ var (
|
|||||||
// the expected value.
|
// the expected value.
|
||||||
ErrBadUTXOCommitment = newRuleError("ErrBadUTXOCommitment")
|
ErrBadUTXOCommitment = newRuleError("ErrBadUTXOCommitment")
|
||||||
|
|
||||||
// ErrInvalidSubnetwork indicates the subnetwork is not allowed.
|
|
||||||
ErrInvalidSubnetwork = newRuleError("ErrInvalidSubnetwork")
|
|
||||||
|
|
||||||
// ErrFinalityPointTimeTooOld indicates a block has a timestamp before the
|
// ErrFinalityPointTimeTooOld indicates a block has a timestamp before the
|
||||||
// last finality point.
|
// last finality point.
|
||||||
ErrFinalityPointTimeTooOld = newRuleError("ErrFinalityPointTimeTooOld")
|
ErrFinalityPointTimeTooOld = newRuleError("ErrFinalityPointTimeTooOld")
|
||||||
@ -75,10 +63,6 @@ var (
|
|||||||
// valid transaction must have at least one input.
|
// valid transaction must have at least one input.
|
||||||
ErrNoTxInputs = newRuleError("ErrNoTxInputs")
|
ErrNoTxInputs = newRuleError("ErrNoTxInputs")
|
||||||
|
|
||||||
// ErrTxMassTooHigh indicates the mass of a transaction exceeds the maximum
|
|
||||||
// allowed limits.
|
|
||||||
ErrTxMassTooHigh = newRuleError("ErrTxMassTooHigh")
|
|
||||||
|
|
||||||
// ErrBadTxOutValue indicates an output value for a transaction is
|
// ErrBadTxOutValue indicates an output value for a transaction is
|
||||||
// invalid in some way such as being out of range.
|
// invalid in some way such as being out of range.
|
||||||
ErrBadTxOutValue = newRuleError("ErrBadTxOutValue")
|
ErrBadTxOutValue = newRuleError("ErrBadTxOutValue")
|
||||||
@ -87,11 +71,6 @@ var (
|
|||||||
// input more than once.
|
// input more than once.
|
||||||
ErrDuplicateTxInputs = newRuleError("ErrDuplicateTxInputs")
|
ErrDuplicateTxInputs = newRuleError("ErrDuplicateTxInputs")
|
||||||
|
|
||||||
// ErrBadTxInput indicates a transaction input is invalid in some way
|
|
||||||
// such as referencing a previous transaction outpoint which is out of
|
|
||||||
// range or not referencing one at all.
|
|
||||||
ErrBadTxInput = newRuleError("ErrBadTxInput")
|
|
||||||
|
|
||||||
// ErrDoubleSpendInSameBlock indicates a transaction
|
// ErrDoubleSpendInSameBlock indicates a transaction
|
||||||
// that spends an output that was already spent by another
|
// that spends an output that was already spent by another
|
||||||
// transaction in the same block.
|
// transaction in the same block.
|
||||||
@ -106,11 +85,6 @@ var (
|
|||||||
// valid block may only contain unique transactions.
|
// valid block may only contain unique transactions.
|
||||||
ErrDuplicateTx = newRuleError("ErrDuplicateTx")
|
ErrDuplicateTx = newRuleError("ErrDuplicateTx")
|
||||||
|
|
||||||
// ErrOverwriteTx indicates a block contains a transaction that has
|
|
||||||
// the same hash as a previous transaction which has not been fully
|
|
||||||
// spent.
|
|
||||||
ErrOverwriteTx = newRuleError("ErrOverwriteTx")
|
|
||||||
|
|
||||||
// ErrImmatureSpend indicates a transaction is attempting to spend a
|
// ErrImmatureSpend indicates a transaction is attempting to spend a
|
||||||
// coinbase that has not yet reached the required maturity.
|
// coinbase that has not yet reached the required maturity.
|
||||||
ErrImmatureSpend = newRuleError("ErrImmatureSpend")
|
ErrImmatureSpend = newRuleError("ErrImmatureSpend")
|
||||||
@ -119,14 +93,6 @@ var (
|
|||||||
// value than the sum of all of its inputs.
|
// value than the sum of all of its inputs.
|
||||||
ErrSpendTooHigh = newRuleError("ErrSpendTooHigh")
|
ErrSpendTooHigh = newRuleError("ErrSpendTooHigh")
|
||||||
|
|
||||||
// ErrBadFees indicates the total fees for a block are invalid due to
|
|
||||||
// exceeding the maximum possible value.
|
|
||||||
ErrBadFees = newRuleError("ErrBadFees")
|
|
||||||
|
|
||||||
// ErrTooManySigOps indicates the total number of signature operations
|
|
||||||
// for a transaction or block exceed the maximum allowed limits.
|
|
||||||
ErrTooManySigOps = newRuleError("ErrTooManySigOps")
|
|
||||||
|
|
||||||
// ErrFirstTxNotCoinbase indicates the first transaction in a block
|
// ErrFirstTxNotCoinbase indicates the first transaction in a block
|
||||||
// is not a coinbase transaction.
|
// is not a coinbase transaction.
|
||||||
ErrFirstTxNotCoinbase = newRuleError("ErrFirstTxNotCoinbase")
|
ErrFirstTxNotCoinbase = newRuleError("ErrFirstTxNotCoinbase")
|
||||||
@ -153,24 +119,10 @@ var (
|
|||||||
// the stack.
|
// the stack.
|
||||||
ErrScriptValidation = newRuleError("ErrScriptValidation")
|
ErrScriptValidation = newRuleError("ErrScriptValidation")
|
||||||
|
|
||||||
// ErrParentBlockUnknown indicates that the parent block is not known.
|
|
||||||
ErrParentBlockUnknown = newRuleError("ErrParentBlockUnknown")
|
|
||||||
|
|
||||||
// ErrInvalidAncestorBlock indicates that an ancestor of this block has
|
// ErrInvalidAncestorBlock indicates that an ancestor of this block has
|
||||||
// already failed validation.
|
// already failed validation.
|
||||||
ErrInvalidAncestorBlock = newRuleError("ErrInvalidAncestorBlock")
|
ErrInvalidAncestorBlock = newRuleError("ErrInvalidAncestorBlock")
|
||||||
|
|
||||||
// ErrParentBlockNotCurrentTips indicates that the block's parents are not the
|
|
||||||
// current tips. This is not a block validation rule, but is required
|
|
||||||
// for block proposals submitted via getblocktemplate RPC.
|
|
||||||
ErrParentBlockNotCurrentTips = newRuleError("ErrParentBlockNotCurrentTips")
|
|
||||||
|
|
||||||
// ErrWithDiff indicates that there was an error with UTXOSet.WithDiff
|
|
||||||
ErrWithDiff = newRuleError("ErrWithDiff")
|
|
||||||
|
|
||||||
// ErrFinality indicates that a block doesn't adhere to the finality rules
|
|
||||||
ErrFinality = newRuleError("ErrFinality")
|
|
||||||
|
|
||||||
// ErrTransactionsNotSorted indicates that transactions in block are not
|
// ErrTransactionsNotSorted indicates that transactions in block are not
|
||||||
// sorted by subnetwork
|
// sorted by subnetwork
|
||||||
ErrTransactionsNotSorted = newRuleError("ErrTransactionsNotSorted")
|
ErrTransactionsNotSorted = newRuleError("ErrTransactionsNotSorted")
|
||||||
@ -197,14 +149,6 @@ var (
|
|||||||
// ErrTooManyParents indicates that a block points to more then `MaxNumParentBlocks` parents
|
// ErrTooManyParents indicates that a block points to more then `MaxNumParentBlocks` parents
|
||||||
ErrTooManyParents = newRuleError("ErrTooManyParents")
|
ErrTooManyParents = newRuleError("ErrTooManyParents")
|
||||||
|
|
||||||
// ErrDelayedBlockIsNotAllowed indicates that a block with a delayed timestamp was
|
|
||||||
// submitted with BFDisallowDelay flag raised.
|
|
||||||
ErrDelayedBlockIsNotAllowed = newRuleError("ErrDelayedBlockIsNotAllowed")
|
|
||||||
|
|
||||||
// ErrOrphanBlockIsNotAllowed indicates that an orphan block was submitted with
|
|
||||||
// BFDisallowOrphans flag raised.
|
|
||||||
ErrOrphanBlockIsNotAllowed = newRuleError("ErrOrphanBlockIsNotAllowed")
|
|
||||||
|
|
||||||
// ErrViolatingBoundedMergeDepth indicates that a block is violating finality from
|
// ErrViolatingBoundedMergeDepth indicates that a block is violating finality from
|
||||||
// its own point of view
|
// its own point of view
|
||||||
ErrViolatingBoundedMergeDepth = newRuleError("ErrViolatingBoundedMergeDepth")
|
ErrViolatingBoundedMergeDepth = newRuleError("ErrViolatingBoundedMergeDepth")
|
||||||
@ -216,16 +160,10 @@ var (
|
|||||||
// In the same block
|
// In the same block
|
||||||
ErrChainedTransactions = newRuleError("ErrChainedTransactions")
|
ErrChainedTransactions = newRuleError("ErrChainedTransactions")
|
||||||
|
|
||||||
// ErrSelectedParentDisqualifiedFromChain indicates that a block's selectedParent has the status DisqualifiedFromChain
|
|
||||||
ErrSelectedParentDisqualifiedFromChain = newRuleError("ErrSelectedParentDisqualifiedFromChain")
|
|
||||||
|
|
||||||
// ErrBlockSizeTooHigh indicates the size of a block exceeds the maximum
|
// ErrBlockSizeTooHigh indicates the size of a block exceeds the maximum
|
||||||
// allowed limits.
|
// allowed limits.
|
||||||
ErrBlockSizeTooHigh = newRuleError("ErrBlockSizeTooHigh")
|
ErrBlockSizeTooHigh = newRuleError("ErrBlockSizeTooHigh")
|
||||||
|
|
||||||
// ErrBuiltInTransactionHasGas indicates that a transaction with built in subnetwork ID has a non zero gas.
|
|
||||||
ErrBuiltInTransactionHasGas = newRuleError("ErrBuiltInTransactionHasGas")
|
|
||||||
|
|
||||||
ErrKnownInvalid = newRuleError("ErrKnownInvalid")
|
ErrKnownInvalid = newRuleError("ErrKnownInvalid")
|
||||||
|
|
||||||
ErrSubnetworksDisabled = newRuleError("ErrSubnetworksDisabled")
|
ErrSubnetworksDisabled = newRuleError("ErrSubnetworksDisabled")
|
||||||
@ -238,9 +176,6 @@ var (
|
|||||||
//ErrPruningPointViolation indicates that the pruning point isn't in the block past.
|
//ErrPruningPointViolation indicates that the pruning point isn't in the block past.
|
||||||
ErrPruningPointViolation = newRuleError("ErrPruningPointViolation")
|
ErrPruningPointViolation = newRuleError("ErrPruningPointViolation")
|
||||||
|
|
||||||
//ErrBlockIsTooMuchInTheFuture indicates that the block timestamp is too much in the future.
|
|
||||||
ErrBlockIsTooMuchInTheFuture = newRuleError("ErrBlockIsTooMuchInTheFuture")
|
|
||||||
|
|
||||||
ErrUnexpectedPruningPoint = newRuleError("ErrUnexpectedPruningPoint")
|
ErrUnexpectedPruningPoint = newRuleError("ErrUnexpectedPruningPoint")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user