mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 14:16:43 +00:00
Don't mark block that got rejected because of ruleerrors.ErrPrunedBlock as invalid (#1529)
* Don't mark block that got rejected because of ruleerrors.ErrPrunedBlock as invalid * Update comment
This commit is contained in:
parent
2a31074fc4
commit
e78cdff3d0
@ -53,12 +53,19 @@ func (bp *blockProcessor) validateBlock(block *externalapi.DomainBlock, isPrunin
|
||||
err = bp.validatePostProofOfWork(block, isPruningPoint)
|
||||
if err != nil {
|
||||
if errors.As(err, &ruleerrors.RuleError{}) {
|
||||
// If we got ErrMissingParents the block shouldn't be considered as invalid
|
||||
// because it could be added later on when its parents are present, and if
|
||||
// we get ErrBadMerkleRoot we shouldn't mark the block as invalid because
|
||||
// later on we can get the block with transactions that fits the merkle
|
||||
// root.
|
||||
if !errors.As(err, &ruleerrors.ErrMissingParents{}) && !errors.Is(err, ruleerrors.ErrBadMerkleRoot) {
|
||||
// We mark invalid blocks with status externalapi.StatusInvalid except in the
|
||||
// case of the following errors:
|
||||
// ErrMissingParents - If we got ErrMissingParents the block shouldn't be
|
||||
// considered as invalid because it could be added later on when its
|
||||
// parents are present.
|
||||
// ErrBadMerkleRoot - if we get ErrBadMerkleRoot we shouldn't mark the
|
||||
// block as invalid because later on we can get the block with
|
||||
// transactions that fits the merkle root.
|
||||
// ErrPrunedBlock - ErrPrunedBlock is an error that rejects a block body and
|
||||
// not the block as a whole, so we shouldn't mark it as invalid.
|
||||
if !errors.As(err, &ruleerrors.ErrMissingParents{}) &&
|
||||
!errors.Is(err, ruleerrors.ErrBadMerkleRoot) &&
|
||||
!errors.Is(err, ruleerrors.ErrPrunedBlock) {
|
||||
// Discard all changes so we save only the block status
|
||||
bp.discardAllChanges()
|
||||
hash := consensushashing.BlockHash(block)
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"github.com/kaspanet/kaspad/domain/consensus/model"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/ruleerrors"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/utils/testutils"
|
||||
"github.com/kaspanet/kaspad/domain/dagconfig"
|
||||
@ -58,6 +59,17 @@ func TestCheckBlockIsNotPruned(t *testing.T) {
|
||||
if !errors.Is(err, ruleerrors.ErrPrunedBlock) {
|
||||
t.Fatalf("Unexpected error: %+v", err)
|
||||
}
|
||||
|
||||
beforePruningBlockBlockStatus, err := tc.BlockStatusStore().Get(tc.DatabaseContext(),
|
||||
consensushashing.BlockHash(beforePruningBlock))
|
||||
if err != nil {
|
||||
t.Fatalf("BlockStatusStore().Get: %+v", err)
|
||||
}
|
||||
|
||||
// Check that the block still has header only status although it got rejected.
|
||||
if beforePruningBlockBlockStatus != externalapi.StatusHeaderOnly {
|
||||
t.Fatalf("Unexpected status %s", beforePruningBlockBlockStatus)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user