From 716da21f85d9c7548c02c351ab52f3324ad9e0f3 Mon Sep 17 00:00:00 2001
From: Rusty Russell <rusty@rustcorp.com.au>
Date: Thu, 10 Nov 2016 23:53:48 +1030
Subject: [PATCH] chaintopology: reduce how far back we start on testnet.

When initially reading the blockchain, we start 100 back from the
current block, or at the first block with a funding transaction,
whichever is earlier.

This slows testing slightly, so use whatever the "forever" value is
(10 on testnet, still 100 on mainnet).

make check -j12 times:
	Before:	7m52.005s
	After:  6m31.896s

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 daemon/chaintopology.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/daemon/chaintopology.c b/daemon/chaintopology.c
index 681269777..ee1fe9753 100644
--- a/daemon/chaintopology.c
+++ b/daemon/chaintopology.c
@@ -483,10 +483,11 @@ static void get_init_blockhash(struct lightningd_state *dstate, u32 blockcount,
 	u32 start;
 	struct peer *peer;
 
-	if (blockcount < 100)
+	/* Start back before any reasonable forks. */
+	if (blockcount < dstate->config.forever_confirms)
 		start = 0;
 	else
-		start = blockcount - 100;
+		start = blockcount - dstate->config.forever_confirms;
 
 	/* If loaded from database, go back to earliest possible peer anchor. */
 	list_for_each(&dstate->peers, peer, list) {