From cc92ae79984c94d4646058152d9d595182d8fa6a Mon Sep 17 00:00:00 2001
From: SChernykh <sergey.v.chernykh@gmail.com>
Date: Wed, 2 Nov 2022 11:30:49 +0100
Subject: [PATCH] Retry get_block_headers_range RPC call if it fails

---
 src/p2pool.cpp | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/p2pool.cpp b/src/p2pool.cpp
index 53ea3dc..b3cd226 100644
--- a/src/p2pool.cpp
+++ b/src/p2pool.cpp
@@ -677,14 +677,14 @@ void p2pool::download_block_headers(uint64_t current_height)
 					}
 				}
 				else {
-					LOGERR(1, "fatal error: couldn't download block header for height " << height);
+					LOGERR(1, "fatal error: couldn't download block header for seed height " << height);
 					panic();
 				}
 			},
 			[height](const char* data, size_t size)
 			{
 				if (size > 0) {
-					LOGERR(1, "fatal error: couldn't download block header for height " << height << ", error " << log::const_buf(data, size));
+					LOGERR(1, "fatal error: couldn't download block header for seed height " << height << ", error " << log::const_buf(data, size));
 					panic();
 				}
 			});
@@ -720,15 +720,15 @@ void p2pool::download_block_headers(uint64_t current_height)
 				}
 			}
 			else {
-				LOGERR(1, "fatal error: couldn't download block headers for heights " << start_height << " - " << current_height - 1);
-				panic();
+				LOGERR(1, "Couldn't download block headers for heights " << start_height << " - " << current_height - 1);
+				download_block_headers(current_height);
 			}
 		},
-		[start_height, current_height](const char* data, size_t size)
+		[this, start_height, current_height](const char* data, size_t size)
 		{
 			if (size > 0) {
-				LOGERR(1, "fatal error: couldn't download block headers for heights " << start_height << " - " << current_height - 1 << ", error " << log::const_buf(data, size));
-				panic();
+				LOGERR(1, "Couldn't download block headers for heights " << start_height << " - " << current_height - 1 << ", error " << log::const_buf(data, size));
+				download_block_headers(current_height);
 			}
 		});
 }