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

Commit e2a8077

Browse files
authored
Check inclusion states before promoting (#831)
1 parent 96e95f2 commit e2a8077

File tree

3 files changed

+105
-94
lines changed

3 files changed

+105
-94
lines changed

locales/en/translation.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,6 @@
345345
"cannot_close_whilst_recovering": "Cannot close whilst recovering",
346346
"recovery_new_seed_prompt": "Enter your new seed below. The address at key index 0 should be unused it is where you will receive your tokens into during the reveal phase.",
347347
"recovery_reattach_prompt": "Please wait for the confirmation of the proof transaction and make use of the promote/reattach button if it is pending for too long. A proof is only accepted once it's confirmed.",
348-
"reattach_not_required": "Wait a few seconds before reattaching",
349-
"promote_not_required": "Wait a few seconds before promoting",
350348
"recovery_proof_transaction_pending": "Proof transaction is pending",
351349
"recovery_proof_transaction_confirmed": "Proof transaction confirmed",
352350
"recovery_reveal_transaction_pending": "Reveal transaction is pending",

ui/js/ui.history.js

Lines changed: 62 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ var UI = (function(UI, $, undefined) {
219219
});
220220
} else if (isPromote) {
221221
function _resetUI (err, success, desktopNotification) {
222+
$('#promote-btn .progress').hide()
223+
222224
if (err) {
223225
$('#promote-btn').loadingError(err)
224226
} else {
@@ -238,67 +240,82 @@ var UI = (function(UI, $, undefined) {
238240
}
239241

240242
function _promote (tail, count, i, skipCheck) {
241-
console.log(tail)
242-
UI.isDoingPOW = true
243+
iota.api.getLatestInclusion([tail.hash], (err, states) => {
244+
if (err) {
245+
_resetUI(err.message)
246+
return
247+
}
243248

244-
const spamTransfer = [{address: '9'.repeat(81), value: 0, message: '', tag: ''}]
249+
if (states[0]) {
250+
$('#bundle-modal').find('.btn').hide()
251+
$('#bundle-modal').find(".persistence").html("<span data-i18n='persistence'>" + UI.t("persistence") + "</span>: <span data-i18n='confirmed'>" + UI.t('confirmed') + "</span>").show()
245252

246-
if (!skipCheck && !isAboveMaxDepth(tail)) {
247-
_resetUI('promote_bellow_max_depth_error')
253+
UI.updateState(1000)
248254

249-
bundlesToTailsMap.delete(bundleHash)
255+
_resetUI(null, 'promote_completed', 'transaction_promoted_successfully')
256+
return
257+
}
250258

251-
$('#reattach-btn').show()
252-
$('#promote-btn').loadingReset('promote')
253-
$('#promote-btn').hide()
254-
}
259+
const spamTransfer = [{address: '9'.repeat(81), value: 0, message: '', tag: ''}]
255260

256-
$('#promote-btn').loadingReset()
261+
if (!skipCheck && !isAboveMaxDepth(tail)) {
262+
_resetUI('promote_bellow_max_depth_error')
257263

258-
var $bar = $('<span class="progress" style="display:block"><div class="slider"><div class="line"></div><div class="break dot1"></div><div class="break dot2"></div><div class="break dot3"></div></div></span>')
264+
bundlesToTailsMap.delete(bundleHash)
259265

260-
if (i === 1) {
261-
$('#promote-btn').append($bar)
262-
}
263-
$('#promote-btn .progress').show()
266+
$('#reattach-btn').show()
267+
$('#promote-btn').loadingReset('promote')
268+
$('#promote-btn').hide()
269+
return
270+
}
264271

265-
$('#promote-btn').loadingUpdate(UI.t('promoting') + ' ' + i + '/' + count)
272+
$('#promote-btn').loadingReset()
266273

267-
iota.api.promoteTransaction(
268-
tail.hash,
269-
connection.depth,
270-
connection.minWeightMagnitude,
271-
spamTransfer,
272-
{interrupt: false, delay: 0},
273-
(err, res) => {
274-
UI.isDoingPOW = false
274+
var $bar = $('<span class="progress" style="display:block"><div class="slider"><div class="line"></div><div class="break dot1"></div><div class="break dot2"></div><div class="break dot3"></div></div></span>')
275275

276-
if (err) {
277-
if (err.message.indexOf('Inconsistent subtangle') > -1) {
278-
_resetUI('promote_inconsistent_subtangle_error')
276+
if (i === 1) {
277+
$('#promote-btn').append($bar)
278+
}
279+
$('#promote-btn .progress').show()
279280

280-
bundlesToTailsMap.delete(bundleHash)
281+
$('#promote-btn').loadingUpdate(UI.t('promoting') + ' ' + i + '/' + count)
281282

282-
$('#promote-btn').hide()
283-
$('#promote-btn').loadingReset('promote')
284-
$('#reattach-btn').show()
285-
} else {
286-
_resetUI(err.message)
287-
}
288-
} else {
289-
if (i < count) {
290-
setTimeout(() => _promote(tail, count, ++i, true), 1000)
291-
return
292-
}
283+
UI.isDoingPOW = true
284+
285+
iota.api.promoteTransaction(
286+
tail.hash,
287+
connection.depth,
288+
connection.minWeightMagnitude,
289+
spamTransfer,
290+
{interrupt: false, delay: 0},
291+
(err, res) => {
292+
UI.isDoingPOW = false
293293

294-
$('#promote-btn .progress').hide()
294+
if (err) {
295+
if (err.message.indexOf('Inconsistent subtangle') > -1) {
296+
_resetUI('promote_inconsistent_subtangle_error')
295297

296-
UI.updateState(1000)
298+
bundlesToTailsMap.delete(bundleHash)
297299

298-
_resetUI(null, 'promote_completed', 'transaction_promoted_successfully')
300+
$('#promote-btn').hide()
301+
$('#promote-btn').loadingReset('promote')
302+
$('#reattach-btn').show()
303+
} else {
304+
_resetUI(err.message)
305+
}
306+
} else {
307+
if (i < count) {
308+
setTimeout(() => _promote(tail, count, ++i, true), 1000)
309+
return
310+
}
311+
312+
UI.updateState(1000)
313+
314+
_resetUI(null, 'promote_completed', 'transaction_promoted_successfully')
315+
}
299316
}
300-
}
301-
)
317+
)
318+
})
302319
}
303320
_promote(bundlesToTailsMap.get(bundleHash), 5, 1, false)
304321
} else {

ui/js/ui.recover.js

Lines changed: 43 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
4444
var _bundlesToTailsMap = new Map()
4545
var _proofTx = null
4646
var _revealTx = null
47+
var _proofTails = []
48+
var _revealTails = []
4749
var _proofTxConfirmed = false
4850
var _revealTxConfirmed = false
4951
var _proofAddress = ''
@@ -146,6 +148,7 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
146148
recoveryNextBtn.loadingReset('recovery_next')
147149
return
148150
}
151+
_proofTails = tails
149152
_proofTx = [txs.filter(tx => tx.lastIndex === 0).sort((a, b) => a.timestamp - b.timestamp)[0]]
150153
_step++
151154
$('#recovery-step-1').hide()
@@ -205,12 +208,13 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
205208
$('#recovery-transaction-hash-clipboard').html(UI.formatForClipboard(tx[0].hash))
206209
_bundlesToTailsMap.set(tx[0].bundle, tx[0])
207210
_step++
211+
_proofTx = tx
208212
checkInclusionStates(tx, CONFIRMATION_CHECK_TIMEOUT, false, (err, confirmed, tails) => {
209213
if (err) {
210214
UI.formError('recover', err.message, {initial: 'recovery_next'})
211215
return
212216
}
213-
_proofTx = tx
217+
_proofTails = tails
214218
if (confirmed) {
215219
_proofTxConfirmed = true
216220
UI.formSuccess('recover', 'recovery_proof_transaction_confirmed')
@@ -266,12 +270,6 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
266270
e.preventDefault()
267271
e.stopPropagation()
268272
})
269-
if (!_proofTx) {
270-
UI.formError('recover', 'reattach_not_required', {initial: 'reattach'})
271-
reattachBtn.loadingReset('reattach')
272-
$('.remodal-close').off('click')
273-
return
274-
}
275273
reattach(_proofTx[0].hash).then(res => {
276274
reattachBtn.loadingReset('reattach')
277275
UI.formSuccess('recover', 'reattach_completed', {initial: 'reattach'})
@@ -294,14 +292,8 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
294292
e.preventDefault()
295293
e.stopPropagation()
296294
})
297-
if (!_proofTx) {
298-
UI.formError('recover', 'promote_not_required', {initial: 'promote'})
299-
promoteBtn.loadingReset('promote')
300-
$('.remodal-close').off('click')
301-
return
302-
}
303295
const tail = _bundlesToTailsMap.get(_proofTx[0].bundle) || _proofTx[0]
304-
promote(tail, _bundlesToTailsMap, 5, 1, (err, res) => {
296+
promote(tail, _proofTails, _bundlesToTailsMap, 5, 1, (err, res) => {
305297
if (err) {
306298
if (err.message.indexOf('Inconsistent subtangle') > -1) {
307299
UI.formError('recover', 'promote_inconsistent_subtangle_error')
@@ -325,14 +317,8 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
325317
e.preventDefault()
326318
e.stopPropagation()
327319
})
328-
if (!_revealTx) {
329-
UI.formError('recover', 'promote_not_required', {initial: 'promote'})
330-
recoverySubmitSeedPromoteBtn.loadingReset('promote')
331-
$('.remodal-close').off('click')
332-
return
333-
}
334320
const tail = _bundlesToTailsMap.get(_revealTx[0].bundle) || _revealTx[0]
335-
promote(tail, _bundlesToTailsMap, 5, 1, (err, res) => {
321+
promote(tail, _revealTails, _bundlesToTailsMap, 5, 1, (err, res) => {
336322
if (err) {
337323
if (err.message.indexOf('Inconsistent subtangle') > -1) {
338324
UI.formError('recover', 'promote_inconsistent_subtangle_error')
@@ -357,12 +343,6 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
357343
e.preventDefault()
358344
e.stopPropagation()
359345
})
360-
if (!_revealTx) {
361-
UI.formError('recover', 'reattach_not_required', {initial: 'reattach'})
362-
recoverySubmitSeedReattachBtn.loadingReset('reattach')
363-
$('.remodal-close').off('click')
364-
return
365-
}
366346
reattach(_revealTx[0].hash).then(res => {
367347
recoverySubmitSeedReattachBtn.loadingReset('reattach')
368348
_pauseConfCheck = false
@@ -415,12 +395,13 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
415395
$('#recovery-proof-confirmed-status').hide()
416396
$('#recovery-reveal-confirmed-status').fadeIn()
417397
$('#recovery-transaction-hash-clipboard').html(UI.formatForClipboard(txs[0].hash))
398+
_revealTx = txs
418399
checkInclusionStates(txs, CONFIRMATION_CHECK_TIMEOUT, false, (err, confirmed, tails) => {
419400
if (err) {
420401
UI.formError('recover', err.message, {initial: 'recovery_next'})
421402
return
422403
}
423-
_revealTx = txs
404+
_revealTails = tails
424405
if (confirmed) {
425406
UI.formSuccess('recover', 'recovery_completed', {initial: 'recovery_submit_seed'})
426407
$('.remodal-close').off('click')
@@ -493,6 +474,8 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
493474
_bundlesToTailsMap = new Map()
494475
_proofTx = null
495476
_revealTx = null
477+
_proofTails = []
478+
_revealTails = []
496479
_proofTxConfirmed = false
497480
_revealTxConfirmed = false
498481
_proofAddress = ''
@@ -590,27 +573,40 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
590573
)
591574
}
592575

593-
function promote (tail, bundlesToTailsMap, count, i, cb) {
594-
iota.api.promoteTransaction(
595-
tail.hash,
596-
connection.depth,
597-
connection.minWeightMagnitude,
598-
[{ address: '9'.repeat(81), value: 0, message: '', tag: '' }],
599-
{ interrupt: false, delay: 0 },
600-
(err, res) => {
601-
if (err) {
602-
if (err.message.indexOf('Inconsistent subtangle') > -1) {
603-
bundlesToTailsMap.delete(tail.bundle)
576+
function promote (tail, tails, bundlesToTailsMap, count, i, cb) {
577+
if (!tails || !tails.length) {
578+
tails = [tail]
579+
}
580+
iota.api.getLatestInclusion(tails.map(tx => tx.hash), (err, states) => {
581+
if (err) {
582+
return cb(err)
583+
}
584+
585+
if (states.some(state => state)) {
586+
return cb(null, true)
587+
}
588+
589+
iota.api.promoteTransaction(
590+
tail.hash,
591+
connection.depth,
592+
connection.minWeightMagnitude,
593+
[{ address: '9'.repeat(81), value: 0, message: '', tag: '' }],
594+
{ interrupt: false, delay: 0 },
595+
(err, res) => {
596+
if (err) {
597+
if (err.message.indexOf('Inconsistent subtangle') > -1) {
598+
bundlesToTailsMap.delete(tail.bundle)
599+
}
600+
return cb(err)
601+
}
602+
if (i < count) {
603+
setTimeout(() => promote(tail, tails, bundlesToTailsMap, count, ++i, cb), 1000)
604+
} else {
605+
cb(null, res)
604606
}
605-
return cb(err)
606-
}
607-
if (i < count) {
608-
setTimeout(() => promote(tail, bundlesToTailsMap, count, ++i, cb))
609-
} else {
610-
cb(null, res)
611607
}
612-
}
613-
)
608+
)
609+
})
614610
}
615611

616612
function generateProofBundle (address, pepperAndProof, tag) {

0 commit comments

Comments
 (0)