WIP: ldk improvements

This commit is contained in:
Overtorment 2021-10-29 12:12:14 +01:00
parent 87862ab5e7
commit ca7930c59e
No known key found for this signature in database
GPG key ID: AB15F43F78CCBC06
2 changed files with 16 additions and 9 deletions

View file

@ -177,7 +177,7 @@ export class LightningLdkWallet extends LightningCustodianWallet {
async lookupNodeConnectionDetailsByPubkey(pubkey: string) {
// first, trying cache:
if (this._nodeConnectionDetailsCache[pubkey] && +new Date() - this._nodeConnectionDetailsCache[pubkey].ts < 2 * 14 * 24 * 3600 * 1000) {
if (this._nodeConnectionDetailsCache[pubkey] && +new Date() - this._nodeConnectionDetailsCache[pubkey].ts < 4 * 7 * 24 * 3600 * 1000) {
// cache hit
return this._nodeConnectionDetailsCache[pubkey];
}
@ -307,6 +307,7 @@ export class LightningLdkWallet extends LightningCustodianWallet {
// ok, it was sent. now, waiting for an event that it was _actually_ paid:
for (let c = 0; c < 60; c++) {
await new Promise(resolve => setTimeout(resolve, 500)); // sleep
for (const sentPayment of RnLdk.sentPayments || []) {
const paidHash = LightningLdkWallet.preimage2hash(sentPayment.payment_preimage);
if (paidHash === decoded.payment_hash) {
@ -323,11 +324,10 @@ export class LightningLdkWallet extends LightningCustodianWallet {
return;
}
}
}
// timeout. maybe it failed? lets lookup in a list of failed payments:
for (const failedPayment of RnLdk.failedPayments) {
if (failedPayment.payment_hash === decoded.payment_hash) throw new Error(JSON.stringify(failedPayment));
for (const failedPayment of RnLdk.failedPayments || []) {
if (failedPayment.payment_hash === decoded.payment_hash) throw new Error(JSON.stringify(failedPayment));
}
}
// no? lets just throw timeout error
@ -481,16 +481,19 @@ export class LightningLdkWallet extends LightningCustodianWallet {
try {
// exception might be in case of incompletely-started LDK
this._listChannels = await RnLdk.listChannels();
this._execInBackground(this.checkBlockchain);
await this.checkBlockchain();
// ^^^ will be executed if above didnt throw exceptions, which means ldk fully started.
// we need this for a case when app returns from background if it was in bg for a really long time.
// ldk needs to update it's blockchain data, and this is practically the only place where it can
// do that (except on cold start)
await this.reconnectPeersWithPendingChannels();
} catch (_) {}
}
try {
await this.reconnectPeersWithPendingChannels();
} finally {
}
await this.getUserInvoices(); // it internally updates paid user invoices
}

View file

@ -133,11 +133,15 @@ const LdkInfo = () => {
allChannelsAmount.current = channelsAvailable;
}, [channels, pendingChannels, inactiveChannels]);
// do we even need periodic sync when user stares at this screen..?
useEffect(() => {
refetchData().then(() => {
refreshDataInterval.current = setInterval(() => {
refetchData(false);
if (wallet.timeToCheckBlockchain()) wallet.checkBlockchain();
if (wallet.timeToCheckBlockchain()) {
wallet.checkBlockchain();
wallet.reconnectPeersWithPendingChannels();
}
}, 2000);
});
return () => {