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

Broadcast of multiple destination tx fails #151

Open
1 task done
riccardorispoli opened this issue Oct 26, 2023 · 5 comments
Open
1 task done

Broadcast of multiple destination tx fails #151

riccardorispoli opened this issue Oct 26, 2023 · 5 comments

Comments

@riccardorispoli
Copy link

Description

On stagenet, I'm not able to broadcast (using LWS) transactions with multiple destinations crafted with @mymonero/mymonero-monero-client. Destination addresses are not integrated addresses and I have not specified a paymentId (following what's written here). I can also confirm that I have enough unlocked balance for the transaction.

  • Can you reproduce the issue?

Steps to reproduce

Run this code snippet replacing placeholders with your wallet keys and primary address.

const axios = require("axios")
const LWSClient = require("@mymonero/mymonero-lws-client")

const httpClient = axios.create({ baseURL: PRIVATE_LWS_URL })
const options = {
  httpClient,
  appName: "MyMonero",
  appVersion: "1.1.25",
  apiKey: PRIVATE_VIEW_KEY
}

const lwsClient = new LWSClient(options)

// Check account
lwsClient.login(PRIVATE_VIEW_KEY, PRIMARY_ADDRESS, false)

const WABridge = await require("@mymonero/mymonero-monero-client")({})

const unspentOuts = await lwsClient.unspentOutputs(PRIVATE_VIEW_KEY, PRIMARY_ADDRESS)

const txOptions = {
  priority: 1,
  address: PRIMARY_ADDRESS,
  privateViewKey: PRIVATE_VIEW_KEY,
  publicSpendKey: PUBLIC_SPEND_KEY,
  privateSpendKey: PRIVATE_SPEND_KEY,
  shouldSweep: false,
  paymentId: "",
  nettype: "STAGENET",
  unspentOuts,
  async randomOutsCb(numberOfOuts) {
    return await lwsClient.randomOutputs(numberOfOuts)
  }
}

const singleDestinationTx = await WABridge.createTransaction({
  ...txOptions,
  destinations: [
    {
      send_amount: "0.1",
      to_address: "53QvrbYs8eQ1aDZDjZ1FPhaffgBvNEBewF3nk4A6KKbYcPLGddfvU5SAG1BgDtx5RYhm8uCwZHVcfHbo9TbooE5TD3ufe3G"
    }
  ]
})

const doubleDestinationTx = await WABridge.createTransaction({
  ...txOptions,
  destinations: [
    {
      send_amount: "0.1",
      to_address: "53QvrbYs8eQ1aDZDjZ1FPhaffgBvNEBewF3nk4A6KKbYcPLGddfvU5SAG1BgDtx5RYhm8uCwZHVcfHbo9TbooE5TD3ufe3G"
    },
    {
      send_amount: "0.2",
      to_address: "79iUszJcoNW2LcHmdCrgbGbq6unuzH9RkdmsGi29TrFL4VHfbz5SrBLJLEXYmPMqc3JQEqqg8h8WVc7aBMXCa2uRTMWjjuC"
    }
  ]
})

const result1 = await lwsClient.submitRawTx(singleDestinationTx.serialized_signed_tx)
console.log(result1) // Working properly

const result2 = await lwsClient.submitRawTx(doubleDestinationTx.serialized_signed_tx)
console.log(result2) // Not working, 500 error, tx seems invalid

Expected behavior:

Both transactions working properly.

Actual behavior:

Transaction with multiple destinations fails to broadcast.

Versions

  • @mymonero/mymonero-lws-client: ^3.0.0
  • @mymonero/mymonero-monero-client: ^3.0.0
  • axios: ^1.5.1
@devinpearson
Copy link
Collaborator

Hi @riccardorispoli can you confirm if you are running the script as it is written?

The issue you would face, is around input selection, the creation of the two transactions, the singe and double will use the same inputs and so will create fine but the second will fail when broadcast.

I would try the double destination on its own or you may need to do improved input selection.

If you still dont come right with the single broadcast, we can look a bit deeper with you.

@riccardorispoli
Copy link
Author

riccardorispoli commented Oct 26, 2023

@devinpearson I can confirm that I'm running the script I wrote down. I tried also crafting and broadcasting the double destination only, but it still fails. Single transaction though works fine, as stated in my first message. Note that I'm using the same unspentOuts for both transactions.

It seems that the problem doesn't concern broadcasting, but rather transaction crafting. Crafting a transaction with monero-ts library, for example (although it's a different flow and not suitable with my use case since in my project I will have to rely on lws outputs only) and using submitRawTx from @mymonero/mymonero-lws-client is working fine.

@riccardorispoli
Copy link
Author

riccardorispoli commented Oct 26, 2023

@devinpearson I have more insights about the error. This is the error output from LWS when I try to broadcast the multiple destination transaction:

2023-10-26 11:41:31.659 E Server returned RPC error: fee too low with code 1 called from rest_server.cpp:648

It seems that the createTransaction method, for transactions with more than one destination, is calculating a fee amount lower than needed. In fact, if I set priority to 2, I am able to successfully broadcast the tx.

@devinpearson
Copy link
Collaborator

@riccardorispoli take a look here for an example of upping the fee. its not the best way of doing it but it will get you over the line. i think currently the fees are coming in low and only considering one input.

unspentOuts.per_byte_fee = 30000

@riccardorispoli
Copy link
Author

@devinpearson So are you implying that the problem is on LWS side (and thus the /unspentOuts endpoint is returning a lower per_byte_fee than it should) and not due to a @mymonero/mymonero-monero-client wrong fee calculation (based on tx size during createTransaction)?

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

2 participants