monero-ts
monero-ts copied to clipboard
Cannot open_wallet if the same wallet is opened by `monero-wallet-rpc`
If a wallet is opened by monero-wallet-rpc
, attempting to re-open it via daemon.openWallet()
throws exception error with appropriate message on RPC console:
E !is_keys_file_locked(). THROW EXCEPTION: error::wallet_internal_error
That is inconvenient if you need to restart your node application and still work with the same wallet -> you have to restart monero-wallet-rpc
as well, or manually close the wallet (method which also is not supported by library)
Working on a PR to fix it.
If a wallet is opened by monero-wallet-rpc, attempting to re-open it via daemon.openWallet() throws exception error with appropriate message on RPC console:
You must mean walletRpc.openWallet()
since the daemon (monero-daemon-rpc) cannot open a wallet.
If the wallet is already open by monero-wallet-rpc, attempting to re-open the same wallet with the same instance of monero-wallet-rpc will succeed, so there is no need to close the wallet first. Opening the same wallet in a separate instance of monero-wallet-rpc will expectedly fail, however.
or manually close the wallet (method which also is not supported by library)
You can use wallet.close(save)
to close and optionally save the wallet.
If the wallet is already open by monero-wallet-rpc, attempting to re-open the same wallet with the same instance of monero-wallet-rpc will succeed
It doesn't succeed. Test the following code:
const {connectToWalletRpc, LibraryUtils, MoneroWallet, MoneroWalletListener, createWalletFull} = require('monero-javascript');
(async ()=>{
const WALLET_DIR = '/home/user/monero'
const WALLET_NAME = 'test-wallet'
const WALLET_PASSWORD = 'test-wallet-password'
// start a monero-wallet-rpc instance:
/*
monero-wallet-rpc --daemon-host testnet.community.xmr.to \
--testnet --trusted-daemon \
--rpc-bind-port 8885 --rpc-login admin:admin \
--wallet-dir "WALLET_DIR"
*/
// create wallet
console.log('creating wallet..')
await createWalletFull({
path: WALLET_DIR+'/'+WALLET_NAME,
password: WALLET_PASSWORD,
networkType: 'testnet',
});
// connect to wallet RPC instance
console.log('connect to RPC..')
const WalletRPC = await connectToWalletRpc(
'http://127.0.0.1:8885',
'admin',
'admin'
);
// open wallet once
console.log('open wallet once..')
await WalletRPC.openWallet(
WALLET_NAME,
WALLET_PASSWORD
);
// open wallet twice.
// here it fails
console.log('open wallet twice..')
await WalletRPC.openWallet(
WALLET_NAME,
WALLET_PASSWORD
);
})();
I'm using "Monero 'Oxygen Orion' (v0.17.2.0-release)"
I think monero-wallet-rpc
attempts to access the same wallet before closing it thus not having access to the keys file? I don't know why it occurs. But manually closing the wallet before accessing it solves the problem.
You can use wallet.close(save) to close and optionally save the wallet.
Good to know, but I think it's clumsy to close the wallet from it's own instance because only one wallet can be opened by monero-wallet-rpc
at a time..
It is not supposed to be a multi-user wallet. As long as the first connection is alive, the second connect must fail.
Try to run one instance of your client, and once connected, CTRL-C or crash out of that one, without closing the connection first and launch a new instance.
It is not supposed to be a multi-user wallet. As long as the first connection is alive, the second connect must fail.
Misspelled 'wallet' with 'daemon', I might've confused you.
It was never meant to be. This issue is about opening a wallet using monero-wallet-rpc
, via a MoneroWalletRPC
instance, even if the same wallet is already opened by monero-wallet-rpc
Try to run one instance of your client, and once connected, CTRL-C or crash out of that one, without closing the connection first and launch a new instance
Yes it works like that, but doesn't make more sense to close the wallet via MoneroWalletRPC
instead of manually stopping monero-wallet-rpc
process? That implies each time your nodejs app crashes, you must crash monero-wallet-rpc
as well; each time you start the nodejs app you must start monero-wallet-rpc
as well.. Because in current situation, if monero-wallet-rpc
has the working wallet opened, MoneroWalletRPC
is not able to open it again, which is the issue I'm talking about..
It doesn't succeed. Test the following code.
I tested the code. It succeeds as long as the first wallet (created with createWalletFull()
) is closed before attempting to open the wallet with monero-wallet-rpc. Otherwise monero-wallet-rpc correctly fails since the wallet is already open elsewhere.
The second call to open the wallet with monero-wallet-rpc succeeds as expected, because there is no issue re-opening the same wallet on the same instance of monero-wallet-rpc.
I think monero-daemon-rpc attempts to access the same wallet
Again, you must mean monero-wallet-rpc because monero-daemon-rpc does not access wallets, it just provides data for wallets.
Good to know, but I think it's clumsy to close the wallet from it's own instance
The wallet instance represents a handle to a "wallet service". One can close the currently open wallet on that service and open another one. Do you have other recommendations for how this should be done?
monero-wallet-rpc will create wallets in its same directory by default. I assumed when testing the code that you were creating the full wallet in the same directory as monero-wallet-rpc's wallet directory. If you aren't using the same directory for both, perhaps there is a wallet in monero-wallet-rpc's wallet directory which you're unintentionally opening?
The second call to open the wallet with monero-wallet-rpc succeeds as expected, because there is no issue re-opening the same wallet on the same instance of monero-wallet-rpc.
That fails on my side on the latest monero release. What OS are you using for testing?
The wallet instance represents a handle to a "wallet service". One can close the currently open wallet on that service and open another one. Do you have other recommendations for how this should be done?
I think closing it directly from MoneroWalletRPC
instance makes sense, because you can't have simultaneous wallets opened per MoneroWalletRPC
instance
monero-wallet-rpc will create wallets in its same directory by default. I assumed when testing the code that you were creating the full wallet in the same directory as monero-wallet-rpc's wallet directory. If you aren't using the same directory for both, perhaps there is a wallet in monero-wallet-rpc's wallet directory which you're unintentionally opening?
Directory configurations are the same for monero-wallet-rpc
and "createWalletFull()". Quadruple tested them..
What OS are you using for testing?
Mac OS.
I think closing it directly from MoneroWalletRPC instance makes sense, because you can't have simultaneous wallets opened per MoneroWalletRPC instance
That's how it is now.
Mac OS.
I think it occurs only on Windows platforms for some reason. Possibly wallet-rpc code bug? Will dig deeper into it the following days
That's how it is now.
I didn't see the 'close' method at first. My mistake
I think it occurs only on Windows platforms for some reason. Possibly wallet-rpc code bug? Will dig deeper into it the following days
If the issue only occurs with monero-wallet-rpc on Windows, an issue should be filed with monero-project to fix.