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

[Bug] Spent Coins in Wallet When Offers Taken by Combined Offer #16461

Closed
erniesc opened this issue Sep 29, 2023 · 5 comments
Closed

[Bug] Spent Coins in Wallet When Offers Taken by Combined Offer #16461

erniesc opened this issue Sep 29, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@erniesc
Copy link

erniesc commented Sep 29, 2023

What happened?

The Chia wallet gets in a bad state after I post multiple offers on Dexie then the offers are taken all at once using the combined offer feature of Dexie. The wallet then acts like some of the spent coins remain available and offers completed on-chain still have PENDING_ACCEPT status in my wallet. The debug.log error "Trade for this offer already exists" is raised when the problem happens. The problem still occurs running the Chia 2.0.1 release and looking back in the log I suspect the problem happened running 1.7.x and 1.8.x too. Previously I cleared the problem by deleting the wallet db file and re-syncing because the balance didn't make sense.

I can reproduce the problem myself with the steps below using the CLI. Two wallets (different keys of course) are needed. The maker wallet creates offers and the taker wallet accepts the combined offer created on Dexie.

  • Using the maker wallet:
    Wallet ID 4 is DBX asset ID db1a9020d48d9d4ad22631b66ab4b9ebd3637ef7758ad38881348c5d24c38f20
  1. Create two or more offers to exchange XCH for a CAT such as DBX. The problem will also occur if the CAT is offered and XCH is requested.

    chia wallet make_offer -o 1:0.008 --request 4:4.0 -p buydbx_27Sep_1.txt
    chia wallet make_offer -o 1:0.004 --request 4:2.0 -p buydbx_27Sep_2.txt

  2. Post the offers on Dexie. The now complete offers on Dexie are visible at the links below.

    https://dexie.space/offers/6e2DdZgu4HBNLqjmqTAFMg68MYVaFoqxEaTrvR6N4Ysp
    https://dexie.space/offers/2kcvVAbUHzqic3GbfYnoyHD9gTVH5mUfZm8RdEbtNcm3

  3. On Dexie select the posted offers from the maker wallet to create a single combined offer. Dexie will not allow offers in the "Your Offers" list to be selected for combination. Open Dexie in a private window or hide the offers to be combined on the "Your Offers" page.

  • Using the taker wallet:
  1. Download the combined offer from Dexie.

  2. Take the combined offer.
    chia wallet take_offer 0.012XCH_x_6.06DBX.offer

  3. After the combined offer is confirmed verify the new XCH and DBX balances are as expected on the taker wallet.

  • Using the maker wallet:
  1. Check offer status (chia wallet get_offers -s ) and see only one of the offers from step 1 is now confirmed. The other offers remain with status PENDING_ACCEPT in the wallet but now show Completed status on the Dexie site.

  2. Maker wallet XCH balance is only changed by the amount of the confirmed offer but the DBX balance has increased by the total amount of the offers from step 1. The remaining PENDING_ACCEPT offers will be stuck PENDING_CANCEL or FAILED if canceled with an on-chain transaction but can be canceled using the --insecure option to chia wallet cancel_offer.

  3. New offer files offering XCH can be created but some will be invalid presumably because they include coins are already spent. The invalid offers immediately show Cancelled status if uploaded to Dexie.

  4. The maker wallet can be restored to a good working state with the expected balances by stopping, deleting the wallet db file, then restarting and letting the wallet re-sync.

  5. The Relevant log output contains the error traceback found in the debug.log file.

Version

2.0.1

What platform are you using?

Linux

What ui mode are you using?

CLI

Relevant log output

2023-09-27T22:26:11.428 wallet chia.wallet.wallet_state_manager: ERROR    Failed to add coin_state: CoinState { coin: Coin { parent_coin_info: ca640c01bbc42f12be71b6108f4e224d247d0a8a097b54d27681b4d20db272ee, puzzle_hash: 4e632f927766acde8316b334bacb02c7a8cebef9eb79fc3bdcdc5dbb576c947d, amount: 4000000000 }, spent_height: Some(4292383), created_height: Some(4292313) }, error: Trade for this offer already exists.
Traceback (most recent call last):
  File "/data/chia/chia-blockchain/chia/wallet/wallet_state_manager.py", line 1301, in _add_coin_states
    await self.trade_manager.coins_of_interest_farmed(coin_state, fork_height, peer)
  File "/data/chia/chia-blockchain/chia/wallet/trade_manager.py", line 162, in coins_of_interest_farmed
    await self.trade_store.set_status(trade.trade_id, TradeStatus.CONFIRMED, height)
  File "/data/chia/chia-blockchain/chia/wallet/trading/trade_store.py", line 221, in set_status
    await self.add_trade_record(tx, offer_name)
  File "/data/chia/chia-blockchain/chia/wallet/trading/trade_store.py", line 164, in add_trade_record
    raise ValueError("Trade for this offer already exists.")
ValueError: Trade for this offer already exists.
@erniesc erniesc added the bug Something isn't working label Sep 29, 2023
@emlowe
Copy link
Contributor

emlowe commented Oct 4, 2023

Thanks for the detailed and complete bug report!

@Quexington
Copy link
Contributor

@erniesc See the PR linked above to see if that has better behavior for you.

@erniesc
Copy link
Author

erniesc commented Oct 17, 2023

Thank you! I'll give it a try as soon as possible.

@erniesc
Copy link
Author

erniesc commented Oct 17, 2023

@Quexington The fix in PR #16636 solved the problem for me when applied on top of release v2.1.1. The balances in the maker wallet are now correct after offers are taken by a combined offer and all the completed offers have CONFIRMED status as expected.

@wjblanke
Copy link
Contributor

Closing as fixed. Please file another issue if u have problems

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants