mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
test_lightningd.py: helper to sync blockheight.
We need this to avoid spurious errors in the next patch. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
8016dbbc91
commit
aa01b7d120
@@ -549,6 +549,27 @@ void json_dev_broadcast(struct command *cmd,
|
||||
command_success(cmd, null_response(cmd));
|
||||
}
|
||||
|
||||
static void json_dev_blockheight(struct command *cmd,
|
||||
const char *buffer, const jsmntok_t *params)
|
||||
{
|
||||
struct chain_topology *topo = cmd->dstate->topology;
|
||||
struct json_result *response;
|
||||
|
||||
response = new_json_result(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_add_num(response, "blockheight", get_block_height(topo));
|
||||
json_object_end(response);
|
||||
command_success(cmd, response);
|
||||
}
|
||||
|
||||
static const struct json_command dev_blockheight = {
|
||||
"dev-blockheight",
|
||||
json_dev_blockheight,
|
||||
"Find out what block height we have",
|
||||
"Returns { blockheight: u32 } on success"
|
||||
};
|
||||
AUTODATA(json_command, &dev_blockheight);
|
||||
|
||||
/* On shutdown, peers get deleted last. That frees from our list, so
|
||||
* do it now instead. */
|
||||
static void destroy_outgoing_txs(struct chain_topology *topo)
|
||||
|
||||
@@ -37,6 +37,19 @@ def setupBitcoind():
|
||||
logging.debug("Insufficient balance, generating 1 block")
|
||||
bitcoind.rpc.generate(1)
|
||||
|
||||
def sync_blockheight(*args):
|
||||
while True:
|
||||
target = bitcoind.rpc.getblockcount()
|
||||
all_up_to_date = True
|
||||
for l in args:
|
||||
if l.rpc.dev_blockheight()['blockheight'] != target:
|
||||
all_up_to_date = False
|
||||
|
||||
if all_up_to_date:
|
||||
return
|
||||
|
||||
# Sleep before spinning.
|
||||
time.sleep(0.1)
|
||||
|
||||
def tearDownBitcoind():
|
||||
global bitcoind
|
||||
|
||||
Reference in New Issue
Block a user