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

Error when I relay a transaction with walletRpc #36

Closed
ianniculescu opened this issue Apr 15, 2022 · 4 comments
Closed

Error when I relay a transaction with walletRpc #36

ianniculescu opened this issue Apr 15, 2022 · 4 comments

Comments

@ianniculescu
Copy link

Sending an unique transaction is fine, but if i try to send a few in a row, if i don't put a TimeUnit.SECONDS.sleep(10) before and after the relay function I get this error: Exception in thread "main" -4: Failed to commit tx. RPC request: 'relay_tx' with params: {"hex":"the transaction hex"}.
in the command prompt i get this multiple lines with this: "2022-04-15 06:56:19.730 E daemon_send_resp.status != CORE_RPC_STATUS_OK. THROW EXCEPTION: error::tx_rejected
2022-04-15 06:56:19.741 E !boost::string_ref{sig_str}.starts_with(header_v1) && !boost::string_ref{sig_str}.starts_with(header_v2). THROW EXCEPTION: error::wallet_internal_error
"

Even with the delay, sometimes randomly the transaction fails and i get this error, it is very random. How should i fix it ?
I also check the fee before relaying the Tx, and to send multiple transactions on Stagenet I also have multiple funded wallets that i switch after there are no more unlocked funds. I use walletRpc.openWallet() and walletRpc.close()

MoneroTxWallet createdTx = walletRpc.createTx(new MoneroTxConfig()
.setAccountIndex(0)
.setAddress("some_address")
.setAmount("some_amount").setRelay(false));

TimeUnit.SECONDS.sleep(10);
walletRpc.relayTx(createdTx);
TimeUnit.SECONDS.sleep(10);

@woodser
Copy link
Owner

woodser commented Apr 15, 2022

From the daemon terminal, this error is expected: "!boost::string_ref{sig_str}.starts_with(header_v1) && !boost::string_ref{sig_str}.starts_with(header_v2). THROW EXCEPTION: error::wallet_internal_error" (see related issue).

However, the "tx_rejected" from means the submitted tx was invalid and rejected by the daemon.

I tested locally and was able to create then relay 50 txs in a row without any problem, so I'm not able to reproduce the issue.

Is your code multithreaded at all? createTx() only creates the tx without reserving its funds, so if another thread also calls createTx() before the previous was committed and relayed, both txs can spend the same funds so one becomes invalid after the other.

@ianniculescu
Copy link
Author

How did you create 50 txs and relay them without bumping into the 10 block lock time after the first transaction?
the way i imagined it was having 10 wallets with 1 big UTXO each and switching wallets after 1 transaction so I can send 10 transactions in a row before i have to wait 20 min.

I know you can send up to 16 outputs from an input but for now i just want to be able to send 10 Tx without an error.
Do i run multithreaded code ? I'm sorry even reading about it on the internet i have no clue what it means. So here is a short example of the code i run that gives me an error.

MoneroWalletRpc walletRpc = new MoneroWalletRpc("http://localhost:38083", "rpc_user", "abc123");

   walletRpc.openWallet("Wallet1","password");
   
	MoneroTxWallet createdTx1 = walletRpc.createTx(new MoneroTxConfig()
	        .setAccountIndex(0)
	        .setAddress("address")
	        .setAmount("100000000"));
	
	walletRpc.relayTx(createdTx1);
	System.out.println("Transaction1 "+createdTx1.getHash()+" relayed");
   
	walletRpc.close(true);
	
	 walletRpc.openWallet("wallet2","password");
       
		MoneroTxWallet createdTx2 = walletRpc.createTx(new MoneroTxConfig()
		        .setAccountIndex(0)
		        .setAddress("address")
		        .setAmount("100000000"));
		
		walletRpc.relayTx(createdTx2);
		System.out.println("Transaction2 "+createdTx2.getHash()+" relayed");
       
		walletRpc.close(true);

and this is what i get in return :

Transaction1 b1c5ab4bc0827a608e607f039b47722d404c9fd2085e8817f6038ac30fb0b540 relayed
Exception in thread "main" -4: Failed to commit tx.
RPC request: 'relay_tx' with params: {"hex":"Transaction hex"}
at monero.common.MoneroRpcConnection.validateRpcResponse(MoneroRpcConnection.java:489)
at monero.common.MoneroRpcConnection.sendJsonRequest(MoneroRpcConnection.java:295)
at monero.common.MoneroRpcConnection.sendJsonRequest(MoneroRpcConnection.java:252)
at monero.wallet.MoneroWalletRpc.relayTxs(MoneroWalletRpc.java:1352)
at monero.wallet.MoneroWalletDefault.relayTx(MoneroWalletDefault.java:313)
at monero.wallet.MoneroWalletRpc.relayTx(MoneroWalletRpc.java:92)
at monero.wallet.MoneroWalletDefault.relayTx(MoneroWalletDefault.java:318)
at monero.wallet.MoneroWalletRpc.relayTx(MoneroWalletRpc.java:92)
at Program.test.main(test.java:48)

the first transaction goes without a problem but after i change to another wallet and want to broadcast the second transaction it doesn't work. What should i do ?

@woodser
Copy link
Owner

woodser commented Apr 24, 2022

How did you create 50 txs and relay them without bumping into the 10 block lock time after the first transaction?

I had a test wallet with >50 unspent outputs, so they could all be sent in rapid succession.

I'm still not able to reproduce the error. Please enable logging in the daemon with set_log 1 and report the error in the daemon's console for why the tx fails.

@woodser
Copy link
Owner

woodser commented Mar 26, 2024

Closing as stale.

@woodser woodser closed this as completed Mar 26, 2024
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