Skip to content

Commit

Permalink
feat: limit number of forwarded by entries
Browse files Browse the repository at this point in the history
  • Loading branch information
justmoon committed Nov 7, 2017
1 parent 2c3b0f9 commit a307c2f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/models/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const validator = require('../lib/validate')
const ilpErrors = require('../lib/ilp-errors')
const IncomingTransferError = require('../errors/incoming-transfer-error')

// Maximum number of entries in the forwarded_by field for ILP errors
const FORWARDED_BY_MAX = 6

function * validateExpiry (sourceTransfer, destinationTransfer, config) {
// TODO tie the maxHoldTime to the fx rate
// TODO bring all these loops into one to speed this up
Expand Down Expand Up @@ -94,12 +97,19 @@ function * rejectSourceTransfer (destinationTransfer, rejectionMessage, ledgers)
validator.validate('IlpAddress', sourceTransferLedger)
validator.validate('Uuid', sourceTransferId)

// Add ourselves to the front of the forwarded list and cut off after
// FORWARDED_BY_MAX.
const forwardedBy = [ledgers.getPlugin(sourceTransferLedger).getAccount()]
.concat(rejectionMessage.forwarded_by || [])
.slice(0, FORWARDED_BY_MAX)

yield ledgers.getPlugin(sourceTransferLedger)
.rejectIncomingTransfer(sourceTransferId, Object.assign(rejectionMessage, {
forwarded_by: ledgers.getPlugin(sourceTransferLedger).getAccount()
forwarded_by: forwardedBy
}))
.catch(() => {
.catch(err => {
log.warn('Attempted to reject source transfer but it was unsucessful')
log.debug((typeof err === 'object' && err.stack) ? err.stack : String(err))
})
}

Expand Down
4 changes: 2 additions & 2 deletions test/paymentsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ describe('Payments', function () {
name: 'Error 1',
message: 'error 1',
triggered_by: 'foo',
forwarded_by: 'mock.test2.bob',
forwarded_by: ['mock.test2.bob'],
additional_info: {}
})
})
Expand Down Expand Up @@ -544,7 +544,7 @@ describe('Payments', function () {
name: 'Error 1',
message: 'error 1',
triggered_by: 'foo',
forwarded_by: 'mock.test2.bob',
forwarded_by: ['mock.test2.bob'],
additional_info: {}
})
})
Expand Down

0 comments on commit a307c2f

Please sign in to comment.