Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can only send one transfer at the same time #15

Open
michielbdejong opened this issue Aug 31, 2017 · 2 comments
Open

Can only send one transfer at the same time #15

michielbdejong opened this issue Aug 31, 2017 · 2 comments

Comments

@michielbdejong
Copy link
Contributor

michielbdejong commented Aug 31, 2017

Try the following script:

const crypto = require('crypto')
const Packet = require('ilp-packet')
const uuid = require('uuid/v4')
const Plugin = require('ilp-plugin-xrp-escrow')

const config = require('../config/xrp')
const sender = new Plugin(config[1])
const receiver = new Plugin(config[2])
const numTrans = 2

function sha256(fulfillment) {
  return crypto.createHash('sha256').update(fulfillment).digest()
}

Promise.all([sender.connect(), receiver.connect()]).then(() => {
  console.log('connected', sender.getAccount(), receiver.getAccount())
  const fulfillment = crypto.randomBytes(32)
  const condition = sha256(fulfillment)

  let arriveds = 0
  let submitteds = 0
  receiver.on('incoming_prepare', (transfer) => {
    console.log('transfer arrived', ++arriveds, transfer)
    receiver.fulfillCondition(transfer.id, fulfillment.toString('base64')).then(() => {
      console.log('submitted', ++submitteds)
    }, err => {
      console.error('submit failed!', err)
    })
  })
  let successes = 0
  sender.on('outgoing_fulfill', (transfer, fulfillment) => { console.log('test success!', ++successes) })
  sender.on('outgoing_reject', (transfer, reason) => { console.log('test failed by receiver!', transfer, reason) })
  sender.on('outgoing_cancel', (transfer, reason) => { console.log('test failed by ledger!', transfer, reason) })
  let sents = 0
  function send() {
    sender.sendTransfer({
      id: uuid(),
      ledger: sender.getInfo().prefix,
      from: sender.getAccount(),
      to: receiver.getAccount(),
      amount: '10',
      expiresAt: new Date(new Date().getTime() + 100000).toISOString(),
      executionCondition: condition.toString('base64'),
      ilp: Packet.serializeIlpPayment({ amount: '1', account: receiver.getAccount() }).toString('base64'),
      noteToSelf: {}
    }).then(() => {
      console.log('transfer sent', ++sents)
    }, err => {
      console.err('transfer failed', err)
    })
  }
  setTimeout(function() {
    console.log('first timeout fired')
    send()
  }, 5000)
  setTimeout(function() {
    console.log('second timeout fired')
    send()
  }, 15000)
})

This succeeds (you see test success! 1 and test success! 2 in the output). But now lower the second timeout from 15000 to 6000, so that the two transfers are in flight at the same time. Then, only one of them succeeds (you only still see test success! 1). It seems incoming_prepare is not fired in the receiver for the second transfer, if the first transfer has not been fulfilled yet.

@michielbdejong
Copy link
Contributor Author

It actually seems to be a bit intermittent; maybe it's due to rate limiting.

@michielbdejong
Copy link
Contributor Author

It's because of how handleTransactionResult works in src/submitter. Will fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant