remove old transactions to lighten the memory

This commit is contained in:
Jonathan Rainville 2018-08-31 15:12:27 -04:00
parent bad6eb3e04
commit b6746f043a

View File

@ -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];
}
});
}