mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-05 13:46:42 +00:00
[NOD-1532] Remove consensus rule that requires blocks are sorted by hash
This commit is contained in:
parent
fc5e39f6cc
commit
f52cddc25c
@ -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
|
||||
}
|
||||
|
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user