[NOD-1532] Remove consensus rule that requires blocks are sorted by hash

This commit is contained in:
Mike Zak 2020-11-15 13:12:42 +02:00 committed by Svarog
parent fc5e39f6cc
commit f52cddc25c
2 changed files with 0 additions and 29 deletions

View File

@ -1,13 +1,10 @@
package blockvalidator
import (
"sort"
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
"github.com/kaspanet/kaspad/domain/consensus/ruleerrors"
"github.com/kaspanet/kaspad/domain/consensus/utils/consensusserialization"
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
"github.com/kaspanet/kaspad/domain/consensus/utils/hashes"
"github.com/pkg/errors"
)
@ -24,11 +21,6 @@ func (v *blockValidator) ValidateHeaderInIsolation(blockHash *externalapi.Domain
return err
}
err = checkBlockParentsOrder(header)
if err != nil {
return err
}
return nil
}
@ -44,21 +36,3 @@ func (v *blockValidator) checkParentsLimit(header *externalapi.DomainBlockHeader
}
return nil
}
//checkBlockParentsOrder ensures that the block's parents are ordered by hash
func checkBlockParentsOrder(header *externalapi.DomainBlockHeader) error {
sortedHashes := make([]*externalapi.DomainHash, len(header.ParentHashes))
for i, hash := range header.ParentHashes {
sortedHashes[i] = hash
}
isSorted := sort.SliceIsSorted(sortedHashes, func(i, j int) bool {
return hashes.Less(sortedHashes[i], sortedHashes[j])
})
if !isSorted {
return errors.Wrapf(ruleerrors.ErrWrongParentsOrder, "block parents are not ordered by hash")
}
return nil
}

View File

@ -34,9 +34,6 @@ var (
// ErrNoParents indicates that the block is missing parents
ErrNoParents = newRuleError("ErrNoParents")
// ErrWrongParentsOrder indicates that the block's parents are not ordered by hash, as expected
ErrWrongParentsOrder = newRuleError("ErrWrongParentsOrder")
// ErrDifficultyTooLow indicates the difficulty for the block is lower
// than the difficulty required.
ErrDifficultyTooLow = newRuleError("ErrDifficultyTooLow")