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:
Svarog 2020-12-22 14:05:21 +02:00 committed by GitHub
parent 5632bee49d
commit e7edfaceb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 73 deletions

View File

@ -52,7 +52,7 @@ func (v *blockValidator) checkBlockTimestampInIsolation(header *externalapi.Doma
maxCurrentTime := now + int64(v.timestampDeviationTolerance)*v.targetTimePerBlock.Milliseconds()
if blockTimestamp > maxCurrentTime {
return errors.Wrapf(
ruleerrors.ErrBlockIsTooMuchInTheFuture, "The block timestamp is in the future.")
ruleerrors.ErrTimeTooMuchInTheFuture, "The block timestamp is in the future.")
}
return nil
}

View File

@ -136,7 +136,7 @@ func (v *transactionValidator) checkTransactionOutputAmounts(tx *externalapi.Dom
totalSompiOut := uint64(0)
// Calculate the total output amount for this transaction. It is safe
// 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 {
totalSompiOut += output.Value
}

View File

@ -45,7 +45,7 @@ func (v *transactionValidator) ValidateTransactionInIsolation(tx *externalapi.Do
return err
}
// TODO: fill it with the right subnetwork id.
// TODO: fill it with the node's subnetwork id.
err = v.checkTransactionSubnetwork(tx, nil)
if err != nil {
return err
@ -167,7 +167,7 @@ func (v *transactionValidator) checkNativeTransactionPayload(tx *externalapi.Dom
}
func (v *transactionValidator) checkTransactionSubnetwork(tx *externalapi.DomainTransaction,
subnetworkID *externalapi.DomainSubnetworkID) error {
localNodeSubnetworkID *externalapi.DomainSubnetworkID) error {
if !v.enableNonNativeSubnetworks && tx.SubnetworkID != subnetworks.SubnetworkIDNative &&
tx.SubnetworkID != subnetworks.SubnetworkIDCoinbase {
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
// or our own subnetwork may have a payload
isLocalNodeFull := subnetworkID == nil
shouldTxBeFull := subnetworks.IsBuiltIn(tx.SubnetworkID) || subnetworks.IsEqual(&tx.SubnetworkID, subnetworkID)
isLocalNodeFull := localNodeSubnetworkID == nil
shouldTxBeFull := subnetworks.IsBuiltIn(tx.SubnetworkID) || subnetworks.IsEqual(&tx.SubnetworkID, localNodeSubnetworkID)
if !isLocalNodeFull && !shouldTxBeFull && len(tx.Payload) > 0 {
return errors.Wrapf(ruleerrors.ErrInvalidPayload,
"transaction that was expected to be partial has a payload "+

View File

@ -14,10 +14,6 @@ var (
// exists.
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
// no longer accepted since the majority of the network has upgraded
// to a newer version.
@ -27,9 +23,8 @@ var (
// the last several blocks per the DAG consensus rules.
ErrTimeTooOld = newRuleError("ErrTimeTooOld")
// ErrTimeTooNew indicates the time is too far in the future as compared
// the current time.
ErrTimeTooNew = newRuleError("ErrTimeTooNew")
//ErrTimeTooMuchInTheFuture indicates that the block timestamp is too much in the future.
ErrTimeTooMuchInTheFuture = newRuleError("ErrTimeTooMuchInTheFuture")
// ErrNoParents indicates that the block is missing parents
ErrNoParents = newRuleError("ErrNoParents")
@ -47,10 +42,6 @@ var (
// ErrInvalidPoW indicates that the block proof-of-work is invalid.
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
// the expected value.
ErrBadMerkleRoot = newRuleError("ErrBadMerkleRoot")
@ -59,9 +50,6 @@ var (
// the expected value.
ErrBadUTXOCommitment = newRuleError("ErrBadUTXOCommitment")
// ErrInvalidSubnetwork indicates the subnetwork is not allowed.
ErrInvalidSubnetwork = newRuleError("ErrInvalidSubnetwork")
// ErrFinalityPointTimeTooOld indicates a block has a timestamp before the
// last finality point.
ErrFinalityPointTimeTooOld = newRuleError("ErrFinalityPointTimeTooOld")
@ -75,10 +63,6 @@ var (
// valid transaction must have at least one input.
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
// invalid in some way such as being out of range.
ErrBadTxOutValue = newRuleError("ErrBadTxOutValue")
@ -87,11 +71,6 @@ var (
// input more than once.
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
// that spends an output that was already spent by another
// transaction in the same block.
@ -106,11 +85,6 @@ var (
// valid block may only contain unique transactions.
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
// coinbase that has not yet reached the required maturity.
ErrImmatureSpend = newRuleError("ErrImmatureSpend")
@ -119,14 +93,6 @@ var (
// value than the sum of all of its inputs.
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
// is not a coinbase transaction.
ErrFirstTxNotCoinbase = newRuleError("ErrFirstTxNotCoinbase")
@ -153,24 +119,10 @@ var (
// the stack.
ErrScriptValidation = newRuleError("ErrScriptValidation")
// ErrParentBlockUnknown indicates that the parent block is not known.
ErrParentBlockUnknown = newRuleError("ErrParentBlockUnknown")
// ErrInvalidAncestorBlock indicates that an ancestor of this block has
// already failed validation.
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
// sorted by subnetwork
ErrTransactionsNotSorted = newRuleError("ErrTransactionsNotSorted")
@ -197,14 +149,6 @@ var (
// ErrTooManyParents indicates that a block points to more then `MaxNumParentBlocks` parents
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
// its own point of view
ErrViolatingBoundedMergeDepth = newRuleError("ErrViolatingBoundedMergeDepth")
@ -216,16 +160,10 @@ var (
// In the same block
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
// allowed limits.
ErrBlockSizeTooHigh = newRuleError("ErrBlockSizeTooHigh")
// ErrBuiltInTransactionHasGas indicates that a transaction with built in subnetwork ID has a non zero gas.
ErrBuiltInTransactionHasGas = newRuleError("ErrBuiltInTransactionHasGas")
ErrKnownInvalid = newRuleError("ErrKnownInvalid")
ErrSubnetworksDisabled = newRuleError("ErrSubnetworksDisabled")
@ -238,9 +176,6 @@ var (
//ErrPruningPointViolation indicates that the pruning point isn't in the block past.
ErrPruningPointViolation = newRuleError("ErrPruningPointViolation")
//ErrBlockIsTooMuchInTheFuture indicates that the block timestamp is too much in the future.
ErrBlockIsTooMuchInTheFuture = newRuleError("ErrBlockIsTooMuchInTheFuture")
ErrUnexpectedPruningPoint = newRuleError("ErrUnexpectedPruningPoint")
)