mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 06:06:49 +00:00
[NOD-493] Make GetBlock return an appropriate error if the hash is known to be of an invalid block. (#520)
This commit is contained in:
parent
9adb105e37
commit
11e936d109
@ -192,6 +192,18 @@ func (dag *BlockDAG) IsKnownOrphan(hash *daghash.Hash) bool {
|
||||
return exists
|
||||
}
|
||||
|
||||
// IsKnownInvalid returns whether the passed hash is known to be an invalid block.
|
||||
// Note that if the block is not found this method will return false.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (dag *BlockDAG) IsKnownInvalid(hash *daghash.Hash) bool {
|
||||
node := dag.index.LookupNode(hash)
|
||||
if node == nil {
|
||||
return false
|
||||
}
|
||||
return dag.index.NodeStatus(node).KnownInvalid()
|
||||
}
|
||||
|
||||
// GetOrphanMissingAncestorHashes returns all of the missing parents in the orphan's sub-DAG
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
|
@ -66,6 +66,7 @@ const (
|
||||
ErrRPCRawTxString RPCErrorCode = -32602
|
||||
ErrRPCDecodeHexString RPCErrorCode = -22
|
||||
ErrRPCOrphanBlock RPCErrorCode = -6
|
||||
ErrRPCBlockInvalid RPCErrorCode = -5
|
||||
)
|
||||
|
||||
// Errors that are specific to btcd.
|
||||
|
@ -23,6 +23,14 @@ func handleGetBlock(s *Server, cmd interface{}, closeChan <-chan struct{}) (inte
|
||||
return nil, rpcDecodeHexError(c.Hash)
|
||||
}
|
||||
|
||||
// Return an appropriate error if the block is known to be invalid
|
||||
if s.cfg.DAG.IsKnownInvalid(hash) {
|
||||
return nil, &btcjson.RPCError{
|
||||
Code: btcjson.ErrRPCBlockInvalid,
|
||||
Message: "Block is known to be invalid",
|
||||
}
|
||||
}
|
||||
|
||||
// Return an appropriate error if the block is an orphan
|
||||
if s.cfg.DAG.IsKnownOrphan(hash) {
|
||||
return nil, &btcjson.RPCError{
|
||||
|
Loading…
x
Reference in New Issue
Block a user