diff --git a/btcjson/jsonrpcerr.go b/btcjson/jsonrpcerr.go index 59345bb95..20533dc33 100644 --- a/btcjson/jsonrpcerr.go +++ b/btcjson/jsonrpcerr.go @@ -65,6 +65,7 @@ const ( ErrRPCSubnetworkNotFound RPCErrorCode = -5 ErrRPCRawTxString RPCErrorCode = -32602 ErrRPCDecodeHexString RPCErrorCode = -22 + ErrRPCOrphanBlock RPCErrorCode = -6 ) // Errors that are specific to btcd. diff --git a/server/rpc/handle_get_block.go b/server/rpc/handle_get_block.go index 59a210420..783f4f4dd 100644 --- a/server/rpc/handle_get_block.go +++ b/server/rpc/handle_get_block.go @@ -22,6 +22,15 @@ func handleGetBlock(s *Server, cmd interface{}, closeChan <-chan struct{}) (inte if err != nil { return nil, rpcDecodeHexError(c.Hash) } + + // Return an appropriate error if the block is an orphan + if s.cfg.DAG.IsKnownOrphan(hash) { + return nil, &btcjson.RPCError{ + Code: btcjson.ErrRPCOrphanBlock, + Message: "Block is an orphan", + } + } + var blkBytes []byte err = s.cfg.DB.View(func(dbTx database.Tx) error { var err error