Fix AddBlock not returning validation failure errors (#1268)

* Fix AddBlock not returning validation failure errors.

* Elevate a log from Info to Warning.

* Elevate a log from Info to Warning.
This commit is contained in:
stasatdaglabs
2020-12-23 15:08:02 +02:00
committed by GitHub
parent 273c271771
commit 6ef8eaf133
3 changed files with 7 additions and 3 deletions

View File

@@ -101,8 +101,7 @@ func (f *FlowContext) AddBlock(block *externalapi.DomainBlock) error {
blockInsertionResult, err := f.Domain().Consensus().ValidateAndInsertBlock(block)
if err != nil {
if errors.As(err, &ruleerrors.RuleError{}) {
log.Infof("Validation failed for block %s: %s", consensushashing.BlockHash(block), err)
return nil
log.Warnf("Validation failed for block %s: %s", consensushashing.BlockHash(block), err)
}
return err
}

View File

@@ -149,7 +149,7 @@ func (f *FlowContext) unorphanBlock(orphanHash externalapi.DomainHash) (*externa
blockInsertionResult, err := f.domain.Consensus().ValidateAndInsertBlock(orphanBlock)
if err != nil {
if errors.As(err, &ruleerrors.RuleError{}) {
log.Infof("Validation failed for orphan block %s: %s", orphanHash, err)
log.Warnf("Validation failed for orphan block %s: %s", orphanHash, err)
return nil, nil
}
return nil, err

View File

@@ -3,8 +3,10 @@ package rpchandlers
import (
"github.com/kaspanet/kaspad/app/appmessage"
"github.com/kaspanet/kaspad/app/rpc/rpccontext"
"github.com/kaspanet/kaspad/domain/consensus/ruleerrors"
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
"github.com/pkg/errors"
)
// HandleSubmitBlock handles the respectively named RPC command
@@ -16,6 +18,9 @@ func HandleSubmitBlock(context *rpccontext.Context, _ *router.Router, request ap
err := context.ProtocolManager.AddBlock(domainBlock)
if err != nil {
if !errors.As(err, &ruleerrors.RuleError{}) {
return nil, err
}
errorMessage := &appmessage.SubmitBlockResponseMessage{}
errorMessage.Error = appmessage.RPCErrorf("Block rejected. Reason: %s", err)
return errorMessage, nil