@@ -1631,6 +1631,31 @@ static struct command_result *param_string_array(struct command *cmd, const char
16311631 return NULL ;
16321632}
16331633
1634+ static struct command_result * getchaininfo_success (struct command * cmd ,
1635+ const char * method ,
1636+ const char * buffer ,
1637+ const jsmntok_t * toks ,
1638+ struct payment * payment )
1639+ {
1640+ struct xpay * xpay = xpay_of (cmd -> plugin );
1641+ u32 headercount ;
1642+ const char * err ;
1643+
1644+ err = json_scan (tmpctx , buffer , toks , "{headercount:%}" ,
1645+ JSON_SCAN (json_to_u32 , & headercount ));
1646+ if (err )
1647+ plugin_err (cmd -> plugin , "Bad getchaininfo response: %s" , err );
1648+
1649+ if (headercount > xpay -> blockheight ) {
1650+ plugin_log (cmd -> plugin , LOG_DBG ,
1651+ "Updating payment blockheight from %d (blocks "
1652+ "synced) to %d (headercount)" ,
1653+ (int )xpay -> blockheight , (int )headercount );
1654+ xpay -> blockheight = headercount ;
1655+ }
1656+ return populate_private_layer (cmd , payment );
1657+ }
1658+
16341659static struct command_result *
16351660preapproveinvoice_succeed (struct command * cmd ,
16361661 const char * method ,
@@ -1639,6 +1664,7 @@ preapproveinvoice_succeed(struct command *cmd,
16391664 struct payment * payment )
16401665{
16411666 struct xpay * xpay = xpay_of (cmd -> plugin );
1667+ struct out_req * req ;
16421668
16431669 /* Now we can conclude `check` command */
16441670 if (command_check_only (cmd )) {
@@ -1653,7 +1679,11 @@ preapproveinvoice_succeed(struct command *cmd,
16531679 if (payment -> disable_mpp )
16541680 payment_log (payment , LOG_INFORM , "No MPP support: this is going to be hard to pay" );
16551681
1656- return populate_private_layer (cmd , payment );
1682+ /* Fetch the header height for we might be out-of-sync. */
1683+ req = jsonrpc_request_start (cmd , "getchaininfo" , & getchaininfo_success ,
1684+ forward_error , payment );
1685+ json_add_u32 (req -> js , "last_height" , 0 );
1686+ return send_outreq (req );
16571687}
16581688
16591689static struct command_result * check_offer_payable (struct command * cmd ,
0 commit comments