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: Critical: Item market entry remains in market storage node upon succesful buyItem call #53

Closed
2 of 4 tasks
carlos-kryha opened this issue Oct 13, 2023 · 2 comments
Closed
2 of 4 tasks
Assignees
Labels
bug Something isn't working

Comments

@carlos-kryha
Copy link
Contributor

carlos-kryha commented Oct 13, 2023

Description

We encountered this issue when purchasing a legendary hair item, the buy flow worked as expected (item was moved to buyers wallet, displayed in inventory, and can be equipped/unequipped). The market entry however, remains in the market path on the storageNode despite having been sold. This results in a "ghost" entry that can never be bought since the item is no longer on contract.

To be clear: this bug does not compromise offer safety nor does it allow unwanted behavior in regards to token transfers. It simply polutes the market list with entries that are no longer available.

Repro steps

The cause of the bug is unclear and there's currently no way to reproduce it consistently
That being said, I can verify the following market entry has been correctly fulfilled, and remains in the storageNode

Acceptance criteria

  • understand what causes the bug
  • implement fix
  • test fix on emerynet
  • determine effort to find and remove affected entries
@carlos-kryha carlos-kryha added the bug Something isn't working label Oct 13, 2023
@carlos-kryha carlos-kryha self-assigned this Oct 13, 2023
@carlos-kryha carlos-kryha changed the title Item market entry remains in market storage node upon succesful buyItem call Bug: Critical. Item market entry remains in market storage node upon succesful buyItem call Oct 13, 2023
@carlos-kryha carlos-kryha changed the title Bug: Critical. Item market entry remains in market storage node upon succesful buyItem call Bug: Critical: Item market entry remains in market storage node upon succesful buyItem call Oct 13, 2023
carlos-kryha added a commit that referenced this issue Oct 18, 2023
This enebles us to exclude certain category/rarity combinations from the
item shop. Currently excluding legendary hair items due to #53
- [x] cleaned up item-shop data 
- [x] added const for filtering out by `[[Category, Rarity[]]]`
- [x] implemented filters in item-shop
- [x] update view

---------

Co-authored-by: Xabier Almazor <[email protected]>
Co-authored-by: Xabier Almazor <[email protected]>
Co-authored-by: Wietze <[email protected]>
Co-authored-by: Xabier Almazor Telek <[email protected]>
Co-authored-by: Pandelis Symeonidis <[email protected]>
Co-authored-by: Axel Verheul <[email protected]>
Co-authored-by: Pandelis Symeonidis <[email protected]>
@carlos-kryha
Copy link
Contributor Author

Code from #61 is called in the buyFirstSaleItem flow after the reallocation is completed and before the removal of the market entry. We suspect #61 is causing the buy call to error out, preventing the code that removes the entry from the market from running.
https://github.com/Kryha/KREAd/blob/develop/agoric/contract/src/kreadKit.js#L1357

@carlos-kryha
Copy link
Contributor Author

@Pandelissym was able to reproduce this locally. After validating the offers and reallocating the assets, the buyItem fn runs the following code:

          // Update metrics
          marketFacet.updateMetrics('item', {
            marketplaceAverageLevel: {
              type: 'remove',
              value: sellRecord.asset.level,
            },
          });

          // Remove market entry
          market.itemEntries.delete(sellRecord.id);
          void marketFacet.deleteNode(
            sellRecord.recorderKit.recorder.getStorageNode(),
          );

#61 can cause marketFacet.updateMetrics() to result in a negative marketplaceAverageLevel. This is then rejected by the following guard:

          marketplaceAverageLevel: M.splitRecord({
                type: M.or('add', 'remove'),
                value: M.gte(0),
          }),

Since marketFacet.updateMetrics() fails, the code responsible for removing the market entry is never executed

@Pandelissym Pandelissym linked a pull request Oct 20, 2023 that will close this issue
@Pandelissym Pandelissym self-assigned this Oct 20, 2023
Pandelissym added a commit that referenced this issue Oct 20, 2023
Fixed marketplaceAverageLevel metric. For items, this metric was being
calculated incorrectly. This lead to specific cases where the metric
might become a negative value after updating. This would violate the
typeguard of the metric which expects it to be greater or equal than 0
and an error would be thrown. This means the buy item flow would not
complete hence why the item would still remain in the market state.

Fixes 2 bugs:
1. #61 
2. #53

Co-authored-by: Pandelis Symeonidis <[email protected]>
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

3 participants