diff --git a/chia/rpc/wallet_rpc_api.py b/chia/rpc/wallet_rpc_api.py index 372f3edb2668..007c1c4a6c70 100644 --- a/chia/rpc/wallet_rpc_api.py +++ b/chia/rpc/wallet_rpc_api.py @@ -542,9 +542,9 @@ async def send_transaction(self, request): fee = uint64(request["fee"]) else: fee = uint64(0) - tx: TransactionRecord = await wallet.generate_signed_transaction(amount, puzzle_hash, fee) - - await wallet.push_transaction(tx) + async with self.service.wallet_state_manager.tx_lock: + tx: TransactionRecord = await wallet.generate_signed_transaction(amount, puzzle_hash, fee) + await wallet.push_transaction(tx) # Transaction may not have been included in the mempool yet. Use get_transaction to check. return { @@ -594,9 +594,9 @@ async def cc_spend(self, request): fee = uint64(request["fee"]) else: fee = uint64(0) - - tx: TransactionRecord = await wallet.generate_signed_transaction([amount], [puzzle_hash], fee) - await wallet.wallet_state_manager.add_pending_transaction(tx) + async with self.service.wallet_state_manager.tx_lock: + tx: TransactionRecord = await wallet.generate_signed_transaction([amount], [puzzle_hash], fee) + await wallet.push_transaction(tx) return { "transaction": tx, @@ -873,8 +873,9 @@ async def send_clawback_transaction(self, request): wallet: RLWallet = self.service.wallet_state_manager.wallets[wallet_id] fee = int(request["fee"]) - tx = await wallet.clawback_rl_coin_transaction(fee) - await wallet.push_transaction(tx) + async with self.service.wallet_state_manager.tx_lock: + tx = await wallet.clawback_rl_coin_transaction(fee) + await wallet.push_transaction(tx) # Transaction may not have been included in the mempool yet. Use get_transaction to check. return { diff --git a/chia/wallet/wallet_state_manager.py b/chia/wallet/wallet_state_manager.py index c94783548886..372b0e0297df 100644 --- a/chia/wallet/wallet_state_manager.py +++ b/chia/wallet/wallet_state_manager.py @@ -72,6 +72,8 @@ class WalletStateManager: # Makes sure only one asyncio thread is changing the blockchain state at one time lock: asyncio.Lock + tx_lock: asyncio.Lock + log: logging.Logger # TODO Don't allow user to send tx until wallet is synced @@ -119,6 +121,7 @@ async def create( else: self.log = logging.getLogger(__name__) self.lock = asyncio.Lock() + self.tx_lock = asyncio.Lock() self.log.debug(f"Starting in db path: {db_path}") self.db_connection = await aiosqlite.connect(db_path)