Merge pull request #3822 from mempool/nymkappa/fix-possible-crash
fix possible backend crash
This commit is contained in:
		
						commit
						d009edbbf3
					
				| @ -472,11 +472,11 @@ class Mining { | |||||||
|     } |     } | ||||||
|     this.blocksPriceIndexingRunning = true; |     this.blocksPriceIndexingRunning = true; | ||||||
| 
 | 
 | ||||||
|  |     let totalInserted = 0; | ||||||
|     try { |     try { | ||||||
|       const prices: any[] = await PricesRepository.$getPricesTimesAndId();     |       const prices: any[] = await PricesRepository.$getPricesTimesAndId();     | ||||||
|       const blocksWithoutPrices: any[] = await BlocksRepository.$getBlocksWithoutPrice(); |       const blocksWithoutPrices: any[] = await BlocksRepository.$getBlocksWithoutPrice(); | ||||||
| 
 | 
 | ||||||
|       let totalInserted = 0; |  | ||||||
|       const blocksPrices: BlockPrice[] = []; |       const blocksPrices: BlockPrice[] = []; | ||||||
| 
 | 
 | ||||||
|       for (const block of blocksWithoutPrices) { |       for (const block of blocksWithoutPrices) { | ||||||
| @ -521,7 +521,13 @@ class Mining { | |||||||
|       } |       } | ||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       this.blocksPriceIndexingRunning = false; |       this.blocksPriceIndexingRunning = false; | ||||||
|       throw e; |       logger.err(`Cannot index block prices. ${e}`); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if (totalInserted > 0) { | ||||||
|  |       logger.info(`Indexing blocks prices completed. Indexed ${totalInserted}`, logger.tags.mining); | ||||||
|  |     } else { | ||||||
|  |       logger.debug(`Indexing blocks prices completed. Indexed 0.`, logger.tags.mining); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     this.blocksPriceIndexingRunning = false; |     this.blocksPriceIndexingRunning = false; | ||||||
|  | |||||||
| @ -577,19 +577,6 @@ class BlocksRepository { | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /** |  | ||||||
|    * Return blocks height |  | ||||||
|    */ |  | ||||||
|    public async $getBlocksHeightsAndTimestamp(): Promise<object[]> { |  | ||||||
|     try { |  | ||||||
|       const [rows]: any[] = await DB.query(`SELECT height, blockTimestamp as timestamp FROM blocks`); |  | ||||||
|       return rows; |  | ||||||
|     } catch (e) { |  | ||||||
|       logger.err('Cannot get blocks height and timestamp from the db. Reason: ' + (e instanceof Error ? e.message : e)); |  | ||||||
|       throw e; |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   /** |   /** | ||||||
|    * Get general block stats |    * Get general block stats | ||||||
|    */ |    */ | ||||||
| @ -889,7 +876,7 @@ class BlocksRepository { | |||||||
|       return rows; |       return rows; | ||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       logger.err('Cannot get blocks height and timestamp from the db. Reason: ' + (e instanceof Error ? e.message : e)); |       logger.err('Cannot get blocks height and timestamp from the db. Reason: ' + (e instanceof Error ? e.message : e)); | ||||||
|       throw e; |       return []; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| @ -909,7 +896,6 @@ class BlocksRepository { | |||||||
|         logger.debug(`Cannot save blocks prices for blocks [${blockPrices[0].height} to ${blockPrices[blockPrices.length - 1].height}] because it has already been indexed, ignoring`); |         logger.debug(`Cannot save blocks prices for blocks [${blockPrices[0].height} to ${blockPrices[blockPrices.length - 1].height}] because it has already been indexed, ignoring`); | ||||||
|       } else { |       } else { | ||||||
|         logger.err(`Cannot save blocks prices for blocks [${blockPrices[0].height} to ${blockPrices[blockPrices.length - 1].height}] into db. Reason: ` + (e instanceof Error ? e.message : e)); |         logger.err(`Cannot save blocks prices for blocks [${blockPrices[0].height} to ${blockPrices[blockPrices.length - 1].height}] into db. Reason: ` + (e instanceof Error ? e.message : e)); | ||||||
|         throw e; |  | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| @ -928,7 +914,7 @@ class BlocksRepository { | |||||||
|       return blocks; |       return blocks; | ||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       logger.err(`Cannot get blocks with missing coinstatsindex. Reason: ` + (e instanceof Error ? e.message : e)); |       logger.err(`Cannot get blocks with missing coinstatsindex. Reason: ` + (e instanceof Error ? e.message : e)); | ||||||
|       throw e; |       return []; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user