From 4815d86cbbc7923f544c2ab6fb5675a50c25e804 Mon Sep 17 00:00:00 2001 From: Anthony Potdevin <31413433+apotdevin@users.noreply.github.com> Date: Sun, 31 Oct 2021 12:56:10 +0100 Subject: [PATCH] fix: duplicate transactions (#356) --- server/schema/transactions/helpers.ts | 26 +++++++++++++++++-------- server/schema/transactions/resolvers.ts | 2 -- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/server/schema/transactions/helpers.ts b/server/schema/transactions/helpers.ts index b40dc52f..ac25649c 100644 --- a/server/schema/transactions/helpers.ts +++ b/server/schema/transactions/helpers.ts @@ -11,6 +11,10 @@ import { LndObject, } from 'server/types/ln-service.types'; +// Limit the amount of transactions that are fetched +const FETCH_LIMIT = 50000; +const BATCH_SIZE = 250; + export const getNodeFromChannel = async ( lnd: {}, channelId: string, @@ -94,17 +98,15 @@ export const getPaymentsBetweenDates = async ({ lnd, from, until, - batch = 25, }: { lnd: LndObject | null; from?: string; until?: string; - batch?: number; }) => { const paymentList = await to( getPayments({ lnd, - limit: batch, + limit: BATCH_SIZE, }) ); @@ -129,7 +131,7 @@ export const getPaymentsBetweenDates = async ({ return last && first; }; - if (isOutOf) { + if (isOutOf || paymentList.payments.length < BATCH_SIZE) { return paymentList.payments.filter(filterArray); } @@ -139,6 +141,11 @@ export const getPaymentsBetweenDates = async ({ let finished = false; while (!finished) { + if (completePayments.length >= FETCH_LIMIT) { + finished = true; + break; + } + const newPayments = await to( getPayments({ lnd, @@ -175,17 +182,15 @@ export const getInvoicesBetweenDates = async ({ lnd, from, until, - batch = 25, }: { lnd: LndObject | null; from?: string; until?: string; - batch?: number; }) => { const invoiceList = await to( getInvoices({ lnd, - limit: batch, + limit: BATCH_SIZE, }) ); @@ -210,7 +215,7 @@ export const getInvoicesBetweenDates = async ({ return last && first; }; - if (isOutOf) { + if (isOutOf || invoiceList.invoices.length < BATCH_SIZE) { return invoiceList.invoices.filter(filterArray); } @@ -220,6 +225,11 @@ export const getInvoicesBetweenDates = async ({ let finished = false; while (!finished) { + if (completeInvoices.length >= FETCH_LIMIT) { + finished = true; + break; + } + const newInvoices = await to( getInvoices({ lnd, diff --git a/server/schema/transactions/resolvers.ts b/server/schema/transactions/resolvers.ts index c46b3f62..cbb38b66 100644 --- a/server/schema/transactions/resolvers.ts +++ b/server/schema/transactions/resolvers.ts @@ -31,7 +31,6 @@ export const transactionResolvers = { lnd, from: startDate, until: endDate, - batch: 25, }); const mappedPayments = payments.map(payment => ({ @@ -47,7 +46,6 @@ export const transactionResolvers = { lnd, from: startDate, until: endDate, - batch: 25, }); const mappedInvoices = invoices.map(invoice => ({