From 1d6d395688fc44212c871916e26dbe5b4ef3ceb3 Mon Sep 17 00:00:00 2001 From: Luca Vaccaro Date: Tue, 13 Feb 2018 16:08:10 +0100 Subject: [PATCH 1/2] Add option --from-blockheight --- lightningd/lightningd.c | 5 +++++ lightningd/lightningd.h | 3 +++ lightningd/options.c | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 1a84d961ed59..2cfa094c6edc 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -325,6 +325,11 @@ int main(int argc, char *argv[]) peer_first_blocknum = wallet_channels_first_blocknum(ld->wallet); + if (ld->config.from_blockheight > -1){ + // Get_init_blockhash() go back of 100 blocks + peer_first_blocknum = ld->config.from_blockheight + 100; + } + db_commit_transaction(ld->wallet->db); /* Initialize block topology (does its own transaction) */ diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index d6d7d5275b1e..e29fe561ac16 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -26,6 +26,9 @@ struct config { /* How long do we let them lock up our funds? (blocks) */ u32 locktime_max; + /* Add block from blockheight (-1 to use default chaintopology strategy). */ + s32 from_blockheight; + /* How many blocks before we expect to see anchor?. */ u32 anchor_onchain_wait; diff --git a/lightningd/options.c b/lightningd/options.c index d26b46156382..98748cea8198 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -220,6 +220,9 @@ static void config_register_opts(struct lightningd *ld) opt_register_arg("--max-locktime-blocks", opt_set_u32, opt_show_u32, &ld->config.locktime_max, "Maximum blocks a peer can lock up our funds"); + opt_register_arg("--from-blockheight", opt_set_s32, opt_show_s32, + &ld->config.from_blockheight, + "Add blocks from blockchain height"); opt_register_arg("--anchor-onchain", opt_set_u32, opt_show_u32, &ld->config.anchor_onchain_wait, "Blocks before we give up on pending anchor transaction"); @@ -320,6 +323,9 @@ static const struct config testnet_config = { /* They can have up to 3 days. */ .locktime_max = 3 * 6 * 24, + /* Default -1 to use default chaintopology strategy. */ + .from_blockheight = -1, + /* Testnet can have long runs of empty blocks. */ .anchor_onchain_wait = 100, @@ -373,6 +379,9 @@ static const struct config mainnet_config = { /* They can have up to 3 days. */ .locktime_max = 3 * 6 * 24, + /* Default -1 to use default chaintopology strategy. */ + .from_blockheight = -1, + /* You should get in within 10 blocks. */ .anchor_onchain_wait = 10, From 1baa378ce4e7e86c22bc38adde38557947895a28 Mon Sep 17 00:00:00 2001 From: Luca Vaccaro Date: Tue, 13 Feb 2018 16:10:34 +0100 Subject: [PATCH 2/2] Fix whitespaces --- lightningd/options.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lightningd/options.c b/lightningd/options.c index 98748cea8198..54f1f8d3f18e 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -323,8 +323,8 @@ static const struct config testnet_config = { /* They can have up to 3 days. */ .locktime_max = 3 * 6 * 24, - /* Default -1 to use default chaintopology strategy. */ - .from_blockheight = -1, + /* Default -1 to use default chaintopology strategy. */ + .from_blockheight = -1, /* Testnet can have long runs of empty blocks. */ .anchor_onchain_wait = 100, @@ -379,8 +379,8 @@ static const struct config mainnet_config = { /* They can have up to 3 days. */ .locktime_max = 3 * 6 * 24, - /* Default -1 to use default chaintopology strategy. */ - .from_blockheight = -1, + /* Default -1 to use default chaintopology strategy. */ + .from_blockheight = -1, /* You should get in within 10 blocks. */ .anchor_onchain_wait = 10,