From 0a9617e1693265a3a9891abd21cf5f58ff477bef Mon Sep 17 00:00:00 2001 From: clemahieu Date: Mon, 18 Apr 2016 21:14:42 -0500 Subject: [PATCH] Fix deadlock when upgrading while importing. --- rai/node/wallet.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/rai/node/wallet.cpp b/rai/node/wallet.cpp index 1fa8917e..208d69a2 100644 --- a/rai/node/wallet.cpp +++ b/rai/node/wallet.cpp @@ -899,20 +899,25 @@ bool rai::wallet::exists (rai::public_key const & account_a) bool rai::wallet::import (std::string const & json_a, std::string const & password_a) { - rai::transaction transaction (store.environment, nullptr, true); - rai::uint256_union id; - random_pool.GenerateBlock (id.bytes.data (), id.bytes.size ()); auto error (false); - rai::wallet_store temp (error, node.wallets.kdf, transaction, 0, 1, id.to_string (), json_a); + std::unique_ptr temp; + { + rai::transaction transaction (store.environment, nullptr, true); + rai::uint256_union id; + random_pool.GenerateBlock (id.bytes.data (), id.bytes.size ()); + temp.reset (new rai::wallet_store (error, node.wallets.kdf, transaction, 0, 1, id.to_string (), json_a)); + } if (!error) { - error = temp.attempt_password (transaction, password_a); - if (!error) - { - error = store.import (transaction, temp); - } + rai::transaction transaction (store.environment, nullptr, false); + error = temp->attempt_password (transaction, password_a); } - temp.destroy (transaction); + rai::transaction transaction (store.environment, nullptr, true); + if (!error) + { + error = store.import (transaction, *temp); + } + temp->destroy (transaction); return error; }