From b6746f043a17373ac2061ecabd714663dcee545e Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Fri, 31 Aug 2018 15:12:27 -0400 Subject: [PATCH] remove old transactions to lighten the memory --- lib/modules/transactionTracker/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/modules/transactionTracker/index.js b/lib/modules/transactionTracker/index.js index 6bff5294..2fc3f41a 100644 --- a/lib/modules/transactionTracker/index.js +++ b/lib/modules/transactionTracker/index.js @@ -4,6 +4,7 @@ class TransactionTracker { this.events = embark.events; this.transactions = {}; this.embark = embark; + this.startTimestamp = Date.now() / 1000; embark.events.on("block:pending:transaction", this.onPendingTransaction.bind(this)); embark.events.on("block:header", this.onBlockHeader.bind(this)); @@ -31,6 +32,19 @@ class TransactionTracker { } }); this.events.emit('blockchain:gas:oracle:new'); + this.cullOldTransactions(); + }); + } + + cullOldTransactions() { + const timeLimit = (Date.now() / 1000) - 600; // Transactions old of 10 minutes are not to be counted anymore + if (this.startTimestamp > timeLimit) { + return; + } + Object.keys(this.transactions).forEach(transactionHash => { + if (this.transactions[transactionHash].startTimestamp < timeLimit) { + delete this.transactions[transactionHash]; + } }); }