Skip to content
This repository was archived by the owner on Feb 26, 2021. It is now read-only.

Commit 4d66349

Browse files
committed
quit promoting tails that remain unconfirmed
1 parent ace5df1 commit 4d66349

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

ui/js/ui.history.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,23 @@ var UI = (function(UI, $, undefined) {
2121
return (Date.now() - parseInt(tx.attachmentTimestamp)) < (11 * 60 * 1000)
2222
}
2323

24+
const TTL = 30 * 60 * 1000
25+
26+
function hasTimeToLive (origin) {
27+
if (!origin) {
28+
return false
29+
}
30+
if (origin.attachmentTimestamp > Date.now()) {
31+
return false
32+
}
33+
return (Date.now() - origin.attachmentTimestamp) < TTL
34+
}
35+
2436
UI.handleHistory = function() {
2537
var modal;
2638

2739
const bundlesToTailsMap = new Map()
40+
const bundlesToOriginsMap = new Map()
2841
const promotableTailsMap = new Map()
2942
const inconsistentTails = new Set()
3043

@@ -78,7 +91,7 @@ var UI = (function(UI, $, undefined) {
7891
$modal.find(".contents").html(html);
7992
$modal.find(".hash").html("<strong><span data-i18n='hash'>" + UI.t("hash") + "</span>:</strong> " + UI.formatForClipboard(hash));
8093

81-
$modal.find(".persistence").html("<span data-i18n='persistence'>" + UI.t("persistence") + "</span>: " + (persistence ? "<span data-i18n='" + status + "'>" + UI.t(status) + "</span>" : "<span data-i18n='pending'>" + UI.t("pending") + "</span>")).show();
94+
$modal.find(".persistence").html("<span data-i18n='persistence'>" + UI.t("persistence") + "</span>: <span data-i18n='" + status + "'>" + UI.t(status) + "</span>").show();
8295
$modal.find(".btn").data("hash", hash);
8396
$modal.find(".btn").data("bundle", bundleHash)
8497

@@ -152,8 +165,9 @@ var UI = (function(UI, $, undefined) {
152165
renderBundleModal(persistence, false, false, status)
153166
} else if (consistentTail &&
154167
!inconsistentTails.has(consistentTail.hash) &&
155-
isAboveMaxDepth(consistentTail)) {
156-
renderBundleModal(false, true, false)
168+
isAboveMaxDepth(consistentTail) &&
169+
hasTimeToLive(bundlesToOriginsMap.get(bundleHash))) {
170+
renderBundleModal(false, true, false, 'pending')
157171
} else {
158172
promotableTails = promotableTails.filter(tx => !inconsistentTails.has(tx.hash) && isAboveMaxDepth(tx))
159173

@@ -162,12 +176,16 @@ var UI = (function(UI, $, undefined) {
162176
if (consistentTail) {
163177
bundlesToTailsMap.set(bundleHash, consistentTail)
164178

165-
renderBundleModal(persistence, true, false)
179+
if (!bundlesToOriginsMap.has(bundleHash)) {
180+
bundlesToOriginsMap.set(consistentTail)
181+
}
182+
183+
renderBundleModal(false, true, false, 'pending')
166184
} else {
167185
bundlesToTailsMap.delete(bundleHash)
168186
promotableTails = []
169187

170-
renderBundleModal(persistence, false, true)
188+
renderBundleModal(false, false, true, 'pending')
171189
}
172190
}).catch(() => {
173191
_isRenderingModal = false
@@ -267,7 +285,7 @@ var UI = (function(UI, $, undefined) {
267285

268286
return getFirstConsistentTail(promotableTails, 0, inconsistentTails)
269287
.then(newConsistentTail => {
270-
if (newConsistentTail) {
288+
if (newConsistentTail && hasTimeToLive(bundlesToOriginsMap.get(bundleHash))) {
271289
bundlesToTailsMap.set(bundleHash, newConsistentTail)
272290

273291
setTimeout(() => _promote(newConsistentTail), 0)
@@ -300,7 +318,7 @@ var UI = (function(UI, $, undefined) {
300318

301319
getFirstConsistentTail(promotableTails, 0, inconsistentTails)
302320
.then(newConsistentTail => {
303-
if (newConsistentTail) {
321+
if (newConsistentTail && hasTimeToLive(bundlesToOriginsMap.get(bundleHash))) {
304322
bundlesToTailsMap.set(bundleHash, newConsistentTail)
305323

306324
setTimeout(() => _promote(newConsistentTail), 0)
@@ -353,6 +371,7 @@ var UI = (function(UI, $, undefined) {
353371

354372
bundlesToTailsMap.set(bundle[0].bundle, bundle[0])
355373
promotableTails.push(bundle[0])
374+
bundlesToOriginsMap.set(bundle[0].bundle, bundle[0])
356375
}
357376

358377
UI.isLocked = false;

0 commit comments

Comments
 (0)