Repository: kaspanet/kaspad
Pull request #2165 (2022-11-08 11:32:45)

Add found to GetBlock

codecov[bot]: # [Codecov](https://codecov.io/gh/kaspanet/kaspad/pull/2165?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet) Report
Base: **58.93**% // Head: **58.88**% // Decreases project coverage by **`-0.05%`** :warning:
> Coverage data is based on head [(`7c521c3`)](https://codecov.io/gh/kaspanet/kaspad/pull/2165?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet) compared to base [(`6c774c9`)](https://codecov.io/gh/kaspanet/kaspad/commit/6c774c966bf28ec9a660737c443ab602de128a77?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet).
> Patch coverage: 27.27% of modified lines in pull request are covered.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##              dev    #2165      +/-   ##
==========================================
- Coverage   58.93%   58.88%   -0.06%     
==========================================
  Files         679      679              
  Lines       33063    33065       +2     
==========================================
- Hits        19486    19469      -17     
- Misses      10740    10757      +17     
- Partials     2837     2839       +2     
```


| [Impacted Files](https://codecov.io/gh/kaspanet/kaspad/pull/2165?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet) | Coverage Δ | |
|---|---|---|
| [domain/migrate.go](https://codecov.io/gh/kaspanet/kaspad/pull/2165/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet#diff-ZG9tYWluL21pZ3JhdGUuZ28=) | `0.00% <0.00%> (ø)` | |
| [version/version.go](https://codecov.io/gh/kaspanet/kaspad/pull/2165/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet#diff-dmVyc2lvbi92ZXJzaW9uLmdv) | `41.66% <ø> (ø)` | |
| [...l/flows/v5/blockrelay/handle\_ibd\_block\_requests.go](https://codecov.io/gh/kaspanet/kaspad/pull/2165/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet#diff-YXBwL3Byb3RvY29sL2Zsb3dzL3Y1L2Jsb2NrcmVsYXkvaGFuZGxlX2liZF9ibG9ja19yZXF1ZXN0cy5nbw==) | `68.42% <33.33%> (+4.78%)` | :arrow_up: |
| [.../handle\_pruning\_point\_and\_its\_anticone\_requests.go](https://codecov.io/gh/kaspanet/kaspad/pull/2165/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet#diff-YXBwL3Byb3RvY29sL2Zsb3dzL3Y1L2Jsb2NrcmVsYXkvaGFuZGxlX3BydW5pbmdfcG9pbnRfYW5kX2l0c19hbnRpY29uZV9yZXF1ZXN0cy5nbw==) | `62.06% <33.33%> (-1.47%)` | :arrow_down: |
| [...flows/v5/blockrelay/handle\_relay\_block\_requests.go](https://codecov.io/gh/kaspanet/kaspad/pull/2165/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet#diff-YXBwL3Byb3RvY29sL2Zsb3dzL3Y1L2Jsb2NrcmVsYXkvaGFuZGxlX3JlbGF5X2Jsb2NrX3JlcXVlc3RzLmdv) | `64.70% <33.33%> (+4.70%)` | :arrow_up: |
| [.../protocol/flows/v5/blockrelay/handle\_relay\_invs.go](https://codecov.io/gh/kaspanet/kaspad/pull/2165/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet#diff-YXBwL3Byb3RvY29sL2Zsb3dzL3Y1L2Jsb2NrcmVsYXkvaGFuZGxlX3JlbGF5X2ludnMuZ28=) | `52.61% <33.33%> (-0.43%)` | :arrow_down: |
| [domain/consensus/consensus.go](https://codecov.io/gh/kaspanet/kaspad/pull/2165/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet#diff-ZG9tYWluL2NvbnNlbnN1cy9jb25zZW5zdXMuZ28=) | `67.39% <50.00%> (ø)` | |
| [domain/consensus/model/externalapi/blockinfo.go](https://codecov.io/gh/kaspanet/kaspad/pull/2165/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet#diff-ZG9tYWluL2NvbnNlbnN1cy9tb2RlbC9leHRlcm5hbGFwaS9ibG9ja2luZm8uZ28=) | `84.61% <0.00%> (-15.39%)` | :arrow_down: |
| [...ructure/network/rpcclient/grpcclient/grpcclient.go](https://codecov.io/gh/kaspanet/kaspad/pull/2165/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet#diff-aW5mcmFzdHJ1Y3R1cmUvbmV0d29yay9ycGNjbGllbnQvZ3JwY2NsaWVudC9ncnBjY2xpZW50Lmdv) | `71.21% <0.00%> (-10.61%)` | :arrow_down: |
| [domain/utxoindex/store.go](https://codecov.io/gh/kaspanet/kaspad/pull/2165/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet#diff-ZG9tYWluL3V0eG9pbmRleC9zdG9yZS5nbw==) | `62.35% <0.00%> (-1.97%)` | :arrow_down: |
| ... and [2 more](https://codecov.io/gh/kaspanet/kaspad/pull/2165/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet) | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/kaspanet/kaspad/pull/2165?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet).


Patch:
diff --git a/app/protocol/flows/v5/blockrelay/handle_ibd_block_requests.go b/app/protocol/flows/v5/blockrelay/handle_ibd_block_requests.go
index aa69b82a..45ccc6c4 100644
--- a/app/protocol/flows/v5/blockrelay/handle_ibd_block_requests.go
+++ b/app/protocol/flows/v5/blockrelay/handle_ibd_block_requests.go
@@ -27,18 +27,15 @@ func HandleIBDBlockRequests(context HandleIBDBlockRequestsContext, incomingRoute
 		log.Debugf("Got request for %d ibd blocks", len(msgRequestIBDBlocks.Hashes))
 		for i, hash := range msgRequestIBDBlocks.Hashes {
 			// Fetch the block from the database.
-			blockInfo, err := context.Domain().Consensus().GetBlockInfo(hash)
-			if err != nil {
-				return err
-			}
-			if !blockInfo.HasBody() {
-				return protocolerrors.Errorf(true, "block %s not found (v5)", hash)
-			}
-			block, err := context.Domain().Consensus().GetBlock(hash)
+			block, found, err := context.Domain().Consensus().GetBlock(hash)
 			if err != nil {
 				return errors.Wrapf(err, "unable to fetch requested block hash %s", hash)
 			}
 
+			if !found {
+				return protocolerrors.Errorf(false, "IBD block %s not found", hash)
+			}
+
 			// TODO (Partial nodes): Convert block to partial block if needed
 
 			blockMessage := appmessage.DomainBlockToMsgBlock(block)
diff --git a/app/protocol/flows/v5/blockrelay/handle_pruning_point_and_its_anticone_requests.go b/app/protocol/flows/v5/blockrelay/handle_pruning_point_and_its_anticone_requests.go
index cecfc93a..4c0a1120 100644
--- a/app/protocol/flows/v5/blockrelay/handle_pruning_point_and_its_anticone_requests.go
+++ b/app/protocol/flows/v5/blockrelay/handle_pruning_point_and_its_anticone_requests.go
@@ -119,11 +119,15 @@ func HandlePruningPointAndItsAnticoneRequests(context PruningPointAndItsAnticone
 			}
 
 			for i, blockHash := range pointAndItsAnticone {
-				block, err := context.Domain().Consensus().GetBlock(blockHash)
+				block, found, err := context.Domain().Consensus().GetBlock(blockHash)
 				if err != nil {
 					return err
 				}
 
+				if !found {
+					return protocolerrors.Errorf(false, "pruning point anticone block %s not found", blockHash)
+				}
+
 				err = outgoingRoute.Enqueue(appmessage.DomainBlockWithTrustedDataToBlockWithTrustedDataV4(block, trustedDataDAABlockIndexes[*blockHash], trustedDataGHOSTDAGDataIndexes[*blockHash]))
 				if err != nil {
 					return err
diff --git a/app/protocol/flows/v5/blockrelay/handle_relay_block_requests.go b/app/protocol/flows/v5/blockrelay/handle_relay_block_requests.go
index 552f5f10..f82fd43f 100644
--- a/app/protocol/flows/v5/blockrelay/handle_relay_block_requests.go
+++ b/app/protocol/flows/v5/blockrelay/handle_relay_block_requests.go
@@ -28,18 +28,15 @@ func HandleRelayBlockRequests(context RelayBlockRequestsContext, incomingRoute *
 		log.Debugf("Got request for relay blocks with hashes %s", getRelayBlocksMessage.Hashes)
 		for _, hash := range getRelayBlocksMessage.Hashes {
 			// Fetch the block from the database.
-			blockInfo, err := context.Domain().Consensus().GetBlockInfo(hash)
-			if err != nil {
-				return err
-			}
-			if !blockInfo.HasBody() {
-				return protocolerrors.Errorf(true, "block %s not found", hash)
-			}
-			block, err := context.Domain().Consensus().GetBlock(hash)
+			block, found, err := context.Domain().Consensus().GetBlock(hash)
 			if err != nil {
 				return errors.Wrapf(err, "unable to fetch requested block hash %s", hash)
 			}
 
+			if !found {
+				return protocolerrors.Errorf(false, "Relay block %s not found", hash)
+			}
+
 			// TODO (Partial nodes): Convert block to partial block if needed
 
 			err = outgoingRoute.Enqueue(appmessage.DomainBlockToMsgBlock(block))
diff --git a/app/protocol/flows/v5/blockrelay/handle_relay_invs.go b/app/protocol/flows/v5/blockrelay/handle_relay_invs.go
index 72736689..5a037720 100644
--- a/app/protocol/flows/v5/blockrelay/handle_relay_invs.go
+++ b/app/protocol/flows/v5/blockrelay/handle_relay_invs.go
@@ -211,10 +211,14 @@ func (flow *handleRelayInvsFlow) start() error {
 				continue
 			}
 			virtualHasNewParents = true
-			block, err := flow.Domain().Consensus().GetBlock(parent)
+			block, found, err := flow.Domain().Consensus().GetBlock(parent)
 			if err != nil {
 				return err
 			}
+
+			if !found {
+				return protocolerrors.Errorf(false, "Virtual parent %s not found", parent)
+			}
 			blockHash := consensushashing.BlockHash(block)
 			log.Debugf("Relaying block %s", blockHash)
 			err = flow.relayBlock(block)
diff --git a/domain/consensus/consensus.go b/domain/consensus/consensus.go
index 518d7d60..f21cfaaa 100644
--- a/domain/consensus/consensus.go
+++ b/domain/consensus/consensus.go
@@ -357,7 +357,7 @@ func (s *consensus) ValidateTransactionAndPopulateWithConsensusData(transaction
 		stagingArea, transaction, model.VirtualBlockHash)
 }
 
-func (s *consensus) GetBlock(blockHash *externalapi.DomainHash) (*externalapi.DomainBlock, error) {
+func (s *consensus) GetBlock(blockHash *externalapi.DomainHash) (*externalapi.DomainBlock, bool, error) {
 	s.lock.Lock()
 	defer s.lock.Unlock()
 
@@ -366,11 +366,11 @@ func (s *consensus) GetBlock(blockHash *externalapi.DomainHash) (*externalapi.Do
 	block, err := s.blockStore.Block(s.databaseContext, stagingArea, blockHash)
 	if err != nil {
 		if errors.Is(err, database.ErrNotFound) {
-			return nil, errors.Wrapf(err, "block %s does not exist", blockHash)
+			return nil, false, nil
 		}
-		return nil, err
+		return nil, false, err
 	}
-	return block, nil
+	return block, true, nil
 }
 
 func (s *consensus) GetBlockEvenIfHeaderOnly(blockHash *externalapi.DomainHash) (*externalapi.DomainBlock, error) {
diff --git a/domain/consensus/model/externalapi/consensus.go b/domain/consensus/model/externalapi/consensus.go
index d7aadc20..da065adb 100644
--- a/domain/consensus/model/externalapi/consensus.go
+++ b/domain/consensus/model/externalapi/consensus.go
@@ -13,7 +13,7 @@ type Consensus interface {
 	ValidatePruningPointProof(pruningPointProof *PruningPointProof) error
 	ApplyPruningPointProof(pruningPointProof *PruningPointProof) error
 
-	GetBlock(blockHash *DomainHash) (*DomainBlock, error)
+	GetBlock(blockHash *DomainHash) (*DomainBlock, bool, error)
 	GetBlockEvenIfHeaderOnly(blockHash *DomainHash) (*DomainBlock, error)
 	GetBlockHeader(blockHash *DomainHash) (BlockHeader, error)
 	GetBlockInfo(blockHash *DomainHash) (*BlockInfo, error)
diff --git a/domain/migrate.go b/domain/migrate.go
index ef75a045..ffb43acb 100644
--- a/domain/migrate.go
+++ b/domain/migrate.go
@@ -2,6 +2,7 @@ package domain
 
 import (
 	"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
+	"github.com/pkg/errors"
 	"math"
 )
 
@@ -66,11 +67,15 @@ func syncConsensuses(syncer, syncee externalapi.Consensus) error {
 	}
 
 	for _, blockHash := range pruningPointAndItsAnticone {
-		block, err := syncer.GetBlock(blockHash)
+		block, found, err := syncer.GetBlock(blockHash)
 		if err != nil {
 			return err
 		}
 
+		if !found {
+			return errors.Errorf("block %s is missing", blockHash)
+		}
+
 		blockDAAWindowHashes, err := syncer.BlockDAAWindowHashes(blockHash)
 		if err != nil {
 			return err
@@ -156,11 +161,14 @@ func syncConsensuses(syncer, syncee externalapi.Consensus) error {
 			continue
 		}
 
-		block, err := syncer.GetBlock(blocksHash)
+		block, found, err := syncer.GetBlock(blocksHash)
 		if err != nil {
 			return err
 		}
 
+		if !found {
+			return errors.Errorf("block %s is missing", blocksHash)
+		}
 		err = syncee.ValidateAndInsertBlock(block, false)
 		if err != nil {
 			return err


Test patch:
diff --git a/cmd/kaspawallet/daemon/server/split_transaction_test.go b/cmd/kaspawallet/daemon/server/split_transaction_test.go
index 0f521bb6..6d87470d 100644
--- a/cmd/kaspawallet/daemon/server/split_transaction_test.go
+++ b/cmd/kaspawallet/daemon/server/split_transaction_test.go
@@ -121,7 +121,7 @@ func testEstimateMassIncreaseForSignaturesSetUp(t *testing.T, consensusConfig *c
 		t.Fatalf("AddBlock: %+v", err)
 	}
 
-	block1, err := tc.GetBlock(block1Hash)
+	block1, _, err := tc.GetBlock(block1Hash)
 	if err != nil {
 		t.Fatalf("GetBlock: %+v", err)
 	}
diff --git a/cmd/kaspawallet/libkaspawallet/transaction_test.go b/cmd/kaspawallet/libkaspawallet/transaction_test.go
index 1d183080..39a46999 100644
--- a/cmd/kaspawallet/libkaspawallet/transaction_test.go
+++ b/cmd/kaspawallet/libkaspawallet/transaction_test.go
@@ -84,7 +84,7 @@ func TestMultisig(t *testing.T) {
 				t.Fatalf("AddBlock: %+v", err)
 			}
 
-			block1, err := tc.GetBlock(block1Hash)
+			block1, _, err := tc.GetBlock(block1Hash)
 			if err != nil {
 				t.Fatalf("GetBlock: %+v", err)
 			}
@@ -245,7 +245,7 @@ func TestP2PK(t *testing.T) {
 				t.Fatalf("AddBlock: %+v", err)
 			}
 
-			block1, err := tc.GetBlock(block1Hash)
+			block1, _, err := tc.GetBlock(block1Hash)
 			if err != nil {
 				t.Fatalf("GetBlock: %+v", err)
 			}
@@ -377,17 +377,17 @@ func TestMaxSompi(t *testing.T) {
 			t.Fatalf("AddBlock: %+v", err)
 		}
 
-		fundingBlock2, err := tc.GetBlock(fundingBlock2Hash)
+		fundingBlock2, _, err := tc.GetBlock(fundingBlock2Hash)
 		if err != nil {
 			t.Fatalf("GetBlock: %+v", err)
 		}
 
-		fundingBlock3, err := tc.GetBlock(fundingBlock3Hash)
+		fundingBlock3, _, err := tc.GetBlock(fundingBlock3Hash)
 		if err != nil {
 			t.Fatalf("GetBlock: %+v", err)
 		}
 
-		fundingBlock4, err := tc.GetBlock(fundingBlock4Hash)
+		fundingBlock4, _, err := tc.GetBlock(fundingBlock4Hash)
 		if err != nil {
 			t.Fatalf("GetBlock: %+v", err)
 		}
@@ -397,7 +397,7 @@ func TestMaxSompi(t *testing.T) {
 			t.Fatalf("AddBlock: %+v", err)
 		}
 
-		block1, err := tc.GetBlock(block1Hash)
+		block1, _, err := tc.GetBlock(block1Hash)
 		if err != nil {
 			t.Fatalf("GetBlock: %+v", err)
 		}
diff --git a/domain/consensus/finality_test.go b/domain/consensus/finality_test.go
index cf764428..6ac93f8f 100644
--- a/domain/consensus/finality_test.go
+++ b/domain/consensus/finality_test.go
@@ -263,7 +263,7 @@ func TestBoundedMergeDepth(t *testing.T) {
 					continue
 				}
 
-				block, err := tcSyncer.GetBlock(blocksHash)
+				block, _, err := tcSyncer.GetBlock(blocksHash)
 				if err != nil {
 					t.Fatalf("GetBlockHeader: %+v", err)
 				}
diff --git a/domain/consensus/processes/blockprocessor/validate_and_insert_imported_pruning_point_test.go b/domain/consensus/processes/blockprocessor/validate_and_insert_imported_pruning_point_test.go
index f86112ba..0ecd36b1 100644
--- a/domain/consensus/processes/blockprocessor/validate_and_insert_imported_pruning_point_test.go
+++ b/domain/consensus/processes/blockprocessor/validate_and_insert_imported_pruning_point_test.go
@@ -93,7 +93,7 @@ func TestValidateAndInsertImportedPruningPoint(t *testing.T) {
 			}
 
 			for _, blockHash := range pruningPointAndItsAnticone {
-				block, err := tcSyncer.GetBlock(blockHash)
+				block, _, err := tcSyncer.GetBlock(blockHash)
 				if err != nil {
 					t.Fatalf("GetBlock: %+v", err)
 				}
@@ -268,7 +268,7 @@ func TestValidateAndInsertImportedPruningPoint(t *testing.T) {
 			}
 
 			for _, blocksHash := range missingBlockHashes {
-				block, err := tcSyncer.GetBlock(blocksHash)
+				block, _, err := tcSyncer.GetBlock(blocksHash)
 				if err != nil {
 					t.Fatalf("GetBlock: %+v", err)
 				}
@@ -294,7 +294,7 @@ func TestValidateAndInsertImportedPruningPoint(t *testing.T) {
 			}
 
 			tipHash := addBlock(tcSyncer, syncerTips, t)
-			tip, err := tcSyncer.GetBlock(tipHash)
+			tip, _, err := tcSyncer.GetBlock(tipHash)
 			if err != nil {
 				t.Fatalf("GetBlock: %+v", err)
 			}
@@ -341,7 +341,7 @@ func TestValidateAndInsertImportedPruningPoint(t *testing.T) {
 		tipHash := consensusConfig.GenesisHash
 		for i := 0; i < numSharedBlocks; i++ {
 			tipHash = addBlock(tcSyncer, []*externalapi.DomainHash{tipHash}, t)
-			block, err := tcSyncer.GetBlock(tipHash)
+			block, _, err := tcSyncer.GetBlock(tipHash)
 			if err != nil {
 				t.Fatalf("GetBlock: %+v", err)
 			}
diff --git a/domain/consensus/processes/blockvalidator/block_body_in_context_test.go b/domain/consensus/processes/blockvalidator/block_body_in_context_test.go
index ff8c71bb..ac93c895 100644
--- a/domain/consensus/processes/blockvalidator/block_body_in_context_test.go
+++ b/domain/consensus/processes/blockvalidator/block_body_in_context_test.go
@@ -41,7 +41,7 @@ func TestCheckBlockIsNotPruned(t *testing.T) {
 			t.Fatalf("AddBlock: %+v", err)
 		}
 
-		beforePruningBlock, err := tc.GetBlock(tipHash)
+		beforePruningBlock, _, err := tc.GetBlock(tipHash)
 		if err != nil {
 			t.Fatalf("beforePruningBlock: %+v", err)
 		}
@@ -199,7 +199,7 @@ func TestIsFinalizedTransaction(t *testing.T) {
 			t.Fatalf("Error getting block DAA score : %+v", err)
 		}
 		blockParents := block.Header.DirectParents()
-		parentToSpend, err := tc.GetBlock(blockParents[0])
+		parentToSpend, _, err := tc.GetBlock(blockParents[0])
 		if err != nil {
 			t.Fatalf("Error getting block1: %+v", err)
 		}
diff --git a/domain/consensus/processes/blockvalidator/block_body_in_isolation_test.go b/domain/consensus/processes/blockvalidator/block_body_in_isolation_test.go
index 15d60206..0d3062f5 100644
--- a/domain/consensus/processes/blockvalidator/block_body_in_isolation_test.go
+++ b/domain/consensus/processes/blockvalidator/block_body_in_isolation_test.go
@@ -70,7 +70,7 @@ func TestChainedTransactions(t *testing.T) {
 			t.Fatalf("AddBlock: %+v", err)
 		}
 
-		block1, err := tc.GetBlock(block1Hash)
+		block1, _, err := tc.GetBlock(block1Hash)
 		if err != nil {
 			t.Fatalf("Error getting block1: %+v", err)
 		}
@@ -97,7 +97,7 @@ func TestChainedTransactions(t *testing.T) {
 			t.Fatalf("unexpected error %+v", err)
 		}
 
-		block2, err := tc.GetBlock(block2Hash)
+		block2, _, err := tc.GetBlock(block2Hash)
 		if err != nil {
 			t.Fatalf("Error getting block2: %+v", err)
 		}
diff --git a/domain/consensus/processes/consensusstatemanager/calculate_past_utxo_test.go b/domain/consensus/processes/consensusstatemanager/calculate_past_utxo_test.go
index d8690767..a734fc28 100644
--- a/domain/consensus/processes/consensusstatemanager/calculate_past_utxo_test.go
+++ b/domain/consensus/processes/consensusstatemanager/calculate_past_utxo_test.go
@@ -40,7 +40,7 @@ func TestUTXOCommitment(t *testing.T) {
 		if err != nil {
 			t.Fatalf("Error creating block B: %+v", err)
 		}
-		blockB, err := consensus.GetBlock(blockBHash)
+		blockB, _, err := consensus.GetBlock(blockBHash)
 		if err != nil {
 			t.Fatalf("Error getting block B: %+v", err)
 		}
@@ -73,7 +73,7 @@ func TestUTXOCommitment(t *testing.T) {
 }
 
 func checkBlockUTXOCommitment(t *testing.T, consensus testapi.TestConsensus, blockHash *externalapi.DomainHash, blockName string) {
-	block, err := consensus.GetBlock(blockHash)
+	block, _, err := consensus.GetBlock(blockHash)
 	if err != nil {
 		t.Fatalf("Error getting block %s: %+v", blockName, err)
 	}
diff --git a/domain/consensus/processes/consensusstatemanager/resolve_block_status_test.go b/domain/consensus/processes/consensusstatemanager/resolve_block_status_test.go
index 1614ff49..cacfa195 100644
--- a/domain/consensus/processes/consensusstatemanager/resolve_block_status_test.go
+++ b/domain/consensus/processes/consensusstatemanager/resolve_block_status_test.go
@@ -40,7 +40,7 @@ func TestDoubleSpends(t *testing.T) {
 		if err != nil {
 			t.Fatalf("Error creating fundingBlock: %+v", err)
 		}
-		fundingBlock, err := consensus.GetBlock(fundingBlockHash)
+		fundingBlock, _, err := consensus.GetBlock(fundingBlockHash)
 		if err != nil {
 			t.Fatalf("Error getting fundingBlock: %+v", err)
 		}
@@ -195,7 +195,7 @@ func TestTransactionAcceptance(t *testing.T) {
 			}
 		}
 		lastBlockInChain := chainTipHash
-		blockC, err := testConsensus.GetBlock(blockHashC)
+		blockC, _, err := testConsensus.GetBlock(blockHashC)
 		if err != nil {
 			t.Fatalf("Error getting blockC: %+v", err)
 		}
@@ -269,22 +269,27 @@ func TestTransactionAcceptance(t *testing.T) {
 		if err != nil {
 			t.Fatalf("Error getting acceptance data: %+v", err)
 		}
-		blueChildOfRedBlock, err := testConsensus.GetBlock(hashBlueChildOfRedBlock)
+		blueChildOfRedBlock, _, err := testConsensus.GetBlock(hashBlueChildOfRedBlock)
 		if err != nil {
 			t.Fatalf("Error getting blueChildOfRedBlock: %+v", err)
 		}
-		blockE, err := testConsensus.GetBlock(blockHashF)
+		blockE, _, err := testConsensus.GetBlock(blockHashF)
 		if err != nil {
 			t.Fatalf("Error getting blockE: %+v", err)
 		}
-		redBlock, err := testConsensus.GetBlock(redHash)
+		redBlock, _, err := testConsensus.GetBlock(redHash)
 		if err != nil {
 			t.Fatalf("Error getting redBlock: %+v", err)
 		}
-		_, err = testConsensus.GetBlock(blockHashG)
+		_, found, err := testConsensus.GetBlock(blockHashG)
 		if err != nil {
-			t.Fatalf("Error getting blockF: %+v", err)
+			t.Fatalf("Error getting blockG: %+v", err)
 		}
+
+		if !found {
+			t.Fatalf("block G is missing")
+		}
+
 		updatedDAAScoreVirtualBlock := consensusConfig.GenesisBlock.Header.DAAScore() + 26
 		//We expect the second transaction in the "blue block" (blueChildOfRedBlock) to be accepted because the merge set is ordered topologically
 		//and the red block is ordered topologically before the "blue block" so the input is known in the UTXOSet.
diff --git a/domain/consensus/processes/transactionvalidator/transactionvalidator_test.go b/domain/consensus/processes/transactionvalidator/transactionvalidator_test.go
index f9cdbdbc..447b1934 100644
--- a/domain/consensus/processes/transactionvalidator/transactionvalidator_test.go
+++ b/domain/consensus/processes/transactionvalidator/transactionvalidator_test.go
@@ -318,12 +318,12 @@ func TestSigningTwoInputs(t *testing.T) {
 			t.Fatalf("AddBlock: %+v", err)
 		}
 
-		block2, err := tc.GetBlock(block2Hash)
+		block2, _, err := tc.GetBlock(block2Hash)
 		if err != nil {
 			t.Fatalf("Error getting block2: %+v", err)
 		}
 
-		block3, err := tc.GetBlock(block3Hash)
+		block3, _, err := tc.GetBlock(block3Hash)
 		if err != nil {
 			t.Fatalf("Error getting block3: %+v", err)
 		}
@@ -444,12 +444,12 @@ func TestSigningTwoInputsECDSA(t *testing.T) {
 			t.Fatalf("AddBlock: %+v", err)
 		}
 
-		block2, err := tc.GetBlock(block2Hash)
+		block2, _, err := tc.GetBlock(block2Hash)
 		if err != nil {
 			t.Fatalf("Error getting block2: %+v", err)
 		}
 
-		block3, err := tc.GetBlock(block3Hash)
+		block3, _, err := tc.GetBlock(block3Hash)
 		if err != nil {
 			t.Fatalf("Error getting block3: %+v", err)
 		}
diff --git a/domain/consensus/timelock_CLTV_test.go b/domain/consensus/timelock_CLTV_test.go
index 21544239..ce7a5122 100644
--- a/domain/consensus/timelock_CLTV_test.go
+++ b/domain/consensus/timelock_CLTV_test.go
@@ -43,7 +43,7 @@ func TestCheckLockTimeVerifyConditionedByDAAScore(t *testing.T) {
 		if err != nil {
 			t.Fatalf("Error creating blockD: %v", err)
 		}
-		blockD, err := testConsensus.GetBlock(blockDHash)
+		blockD, _, err := testConsensus.GetBlock(blockDHash)
 		if err != nil {
 			t.Fatalf("Failed getting blockD: %v", err)
 		}
@@ -150,7 +150,7 @@ func TestCheckLockTimeVerifyConditionedByDAAScoreWithWrongLockTime(t *testing.T)
 		if err != nil {
 			t.Fatalf("Error creating blockD: %v", err)
 		}
-		blockD, err := testConsensus.GetBlock(blockDHash)
+		blockD, _, err := testConsensus.GetBlock(blockDHash)
 		if err != nil {
 			t.Fatalf("Failed getting blockD: %v", err)
 		}
@@ -252,7 +252,7 @@ func TestCheckLockTimeVerifyConditionedByAbsoluteTime(t *testing.T) {
 		if err != nil {
 			t.Fatalf("Error creating blockD: %v", err)
 		}
-		blockD, err := testConsensus.GetBlock(blockDHash)
+		blockD, _, err := testConsensus.GetBlock(blockDHash)
 		if err != nil {
 			t.Fatalf("Failed getting blockD: %v", err)
 		}
@@ -283,7 +283,7 @@ func TestCheckLockTimeVerifyConditionedByAbsoluteTime(t *testing.T) {
 		if err != nil {
 			t.Fatalf("Error creating blockE: %v", err)
 		}
-		blockE, err := testConsensus.GetBlock(blockEHash)
+		blockE, _, err := testConsensus.GetBlock(blockEHash)
 		if err != nil {
 			t.Fatalf("Failed getting blockE: %v", err)
 		}
@@ -380,7 +380,7 @@ func TestCheckLockTimeVerifyConditionedByAbsoluteTimeWithWrongLockTime(t *testin
 		if err != nil {
 			t.Fatalf("Error creating blockD: %v", err)
 		}
-		blockD, err := testConsensus.GetBlock(blockDHash)
+		blockD, _, err := testConsensus.GetBlock(blockDHash)
 		if err != nil {
 			t.Fatalf("Failed getting blockD: %v", err)
 		}
@@ -411,7 +411,7 @@ func TestCheckLockTimeVerifyConditionedByAbsoluteTimeWithWrongLockTime(t *testin
 		if err != nil {
 			t.Fatalf("Error creating blockE: %v", err)
 		}
-		blockE, err := testConsensus.GetBlock(blockEHash)
+		blockE, _, err := testConsensus.GetBlock(blockEHash)
 		if err != nil {
 			t.Fatalf("Failed getting blockE: %v", err)
 		}
diff --git a/domain/miningmanager/miningmanager_test.go b/domain/miningmanager/miningmanager_test.go
index d98950b1..d1b1b8e2 100644
--- a/domain/miningmanager/miningmanager_test.go
+++ b/domain/miningmanager/miningmanager_test.go
@@ -339,7 +339,7 @@ func TestOrphanTransactions(t *testing.T) {
 			t.Fatalf("AddBlock: %v", err)
 		}
 
-		blockParentsTransactions, err := tc.GetBlock(blockParentsTransactionsHash)
+		blockParentsTransactions, _, err := tc.GetBlock(blockParentsTransactionsHash)
 		if err != nil {
 			t.Fatalf("GetBlock: %v", err)
 		}
@@ -648,7 +648,7 @@ func TestModifyBlockTemplate(t *testing.T) {
 			t.Fatalf("AddBlock: %v", err)
 		}
 
-		blockParentsTransactions, err := tc.GetBlock(blockParentsTransactionsHash)
+		blockParentsTransactions, _, err := tc.GetBlock(blockParentsTransactionsHash)
 		if err != nil {
 			t.Fatalf("GetBlock: %v", err)
 		}
@@ -924,7 +924,7 @@ func createParentAndChildrenTransactions(tc testapi.TestConsensus) (txParent *ex
 	if err != nil {
 		return nil, nil, errors.Wrap(err, "AddBlock: ")
 	}
-	fundingBlockForParent, err := tc.GetBlock(fundingBlockHashForParent)
+	fundingBlockForParent, _, err := tc.GetBlock(fundingBlockHashForParent)
 	if err != nil {
 		return nil, nil, errors.Wrap(err, "GetBlock: ")
 	}
@@ -949,7 +949,7 @@ func createChildAndParentTxsAndAddParentToConsensus(tc testapi.TestConsensus) (*
 	if err != nil {
 		return nil, errors.Wrap(err, "AddBlock: ")
 	}
-	ParentBlock, err := tc.GetBlock(ParentBlockHash)
+	ParentBlock, _, err := tc.GetBlock(ParentBlockHash)
 	if err != nil {
 		return nil, errors.Wrap(err, "GetBlock: ")
 	}
diff --git a/stability-tests/common/mine/mine.go b/stability-tests/common/mine/mine.go
index bcc65b20..78200980 100644
--- a/stability-tests/common/mine/mine.go
+++ b/stability-tests/common/mine/mine.go
@@ -105,7 +105,16 @@ func mineBlocks(consensusConfig *consensus.Config, rpcClient *rpc.Client, blockC
 func mineOrFetchBlock(blockData JSONBlock, mdb *miningDB, testConsensus testapi.TestConsensus) (*externalapi.DomainBlock, error) {
 	hash := mdb.hashByID(blockData.ID)
 	if mdb.hashByID(blockData.ID) != nil {
-		return testConsensus.GetBlock(hash)
+		block, found, err := testConsensus.GetBlock(hash)
+		if err != nil {
+			return nil, err
+		}
+
+		if !found {
+			return nil, errors.Errorf("block %s is missing", hash)
+		}
+
+		return block, nil
 	}
 
 	parentHashes := make([]*externalapi.DomainHash, len(blockData.Parents))
diff --git a/stability-tests/netsync/fast-pruning-ibd-test/generate_test.go b/stability-tests/netsync/fast-pruning-ibd-test/generate_test.go
index 58e6a2e7..2c631f5b 100644
--- a/stability-tests/netsync/fast-pruning-ibd-test/generate_test.go
+++ b/stability-tests/netsync/fast-pruning-ibd-test/generate_test.go
@@ -44,7 +44,7 @@ func TestGenerateFastPruningIBDTest(t *testing.T) {
 			}
 		}
 
-		tip, err := tc.GetBlock(tipHash)
+		tip, _, err := tc.GetBlock(tipHash)
 		if err != nil {
 			t.Fatal(err)
 		}