mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-07 14:46:44 +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
|
package blockvalidator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/ruleerrors"
|
"github.com/kaspanet/kaspad/domain/consensus/ruleerrors"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/consensusserialization"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/consensusserialization"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/hashes"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -24,11 +21,6 @@ func (v *blockValidator) ValidateHeaderInIsolation(blockHash *externalapi.Domain
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = checkBlockParentsOrder(header)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,21 +36,3 @@ func (v *blockValidator) checkParentsLimit(header *externalapi.DomainBlockHeader
|
|||||||
}
|
}
|
||||||
return nil
|
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 indicates that the block is missing parents
|
||||||
ErrNoParents = newRuleError("ErrNoParents")
|
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
|
// ErrDifficultyTooLow indicates the difficulty for the block is lower
|
||||||
// than the difficulty required.
|
// than the difficulty required.
|
||||||
ErrDifficultyTooLow = newRuleError("ErrDifficultyTooLow")
|
ErrDifficultyTooLow = newRuleError("ErrDifficultyTooLow")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user