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

feat(nft): move db lock, add tx fee and confirmations #1989

Merged
merged 20 commits into from
Dec 11, 2023
Merged

Conversation

laruh
Copy link
Member

@laruh laruh commented Oct 11, 2023

continuation of this PR.
solves comment and issue.

  • nft_cache_db was added in NftCtx for non wasm target.
  • Changelog of Async sqlite wrapper gist
  • AsyncConnection structure was created in mm2src/db_common/src/async_sql_conn.rs. It can be used as async wrapper for sqlite connection.
  • async_sqlite_connection field was added in MmCtx.

note:

According to this transaction_receipt(hash) can return None for "old" transactions.
transaction_receipt should work fine for swaps, as we need info about the recently broadcasted transaction.

deps added

mm2src/db_common/Cargo.toml
tokio = { version = "1.20", default-features = false, features = ["macros"] }
crossbeam-channel = "0.5.1"
futures = "0.3.1"

@laruh laruh added the in progress Changes will be made from the author label Oct 11, 2023
@laruh laruh changed the title feat(nft): move db lock feat(nft): move db lock, add tx fee and confirmations Oct 25, 2023
@laruh laruh added under review and removed in progress Changes will be made from the author labels Oct 29, 2023
@artemii235 artemii235 self-requested a review October 30, 2023 04:42
Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I have few minor notes and one question.

mm2src/coins/nft.rs Outdated Show resolved Hide resolved
mm2src/coins/nft.rs Outdated Show resolved Hide resolved
mm2src/coins/nft.rs Outdated Show resolved Hide resolved
@@ -492,19 +447,18 @@ impl NftTransferHistoryStorageOps for IndexedDbNftStorage {
.await?
.into_iter()
.map(|(_item_id, transfer)| transfer);
let filtered = Self::filter_transfers(transfer_tables, filters)?;
let filtered = filter_transfers(transfer_tables, filters)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand, we fetch all transfers from IndexedDB and apply filters thereafter. Can cursor be used instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can build and open cursor and then use while let Some((_item_id, item)) = cursor.next() to get next item and apply filters. But seems like cursor.next() doesnt work properly.
I did such impl previously in wasm storage method to filter transfers only with empty metadata. However, GUI got runtime error mm2lib.js:1731 Uncaught Error: closure invoked recursively or after being dropped. I will send you full logs in dm.
PR where I started to use cursor collect method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you look for a way to fix the issue with next? Using collect or requesting all items from the table will cause excessive memory usage. Also, cursor is used in Zcoin WASM implementation, so we have a possible problem with it too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use spawn_local_abortable function instead of spawn_local, but to be honest I dont remember where. Didnt work, I think bcz my idea was wrong. As we needed to do hotfix asap we decided to come back to this issue later.

ps: as I can see now collect method utilizes next and collect works fine.

Copy link
Member

@artemii235 artemii235 Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to apply the following plan:

  1. Use next instead of collect where applicable.
  2. Check if Uncaught Error: closure invoked recursively or after being dropped happens again.
  3. If yes, create an issue in the DeFi framework repo.
  4. Troubleshoot and fix the problem.

cc @shamardy

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it can be done in the next iteration 🙂

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed plan @artemii235 , I totally agree with it :)

@laruh laruh added in progress Changes will be made from the author under review and removed under review in progress Changes will be made from the author labels Nov 2, 2023
@shamardy shamardy changed the base branch from spam-nft-refactor-db to dev November 6, 2023 10:25
@shamardy shamardy changed the base branch from dev to spam-nft-refactor-db November 6, 2023 10:25
@shamardy
Copy link
Collaborator

shamardy commented Nov 6, 2023

@laruh please rebase this PR to dev and then we need to change the base branch in this page.

Edit: After discussions with @laruh, there is no need to rebase now to continue the review process without interrupting it with force pushing.

Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next iteration 🙂

mm2src/coins/nft.rs Outdated Show resolved Hide resolved
mm2src/coins/nft/nft_structs.rs Outdated Show resolved Hide resolved
mm2src/coins/nft/nft_structs.rs Outdated Show resolved Hide resolved
mm2src/coins/nft/nft_structs.rs Outdated Show resolved Hide resolved
mm2src/coins/nft/storage/sql_storage.rs Outdated Show resolved Hide resolved
mm2src/coins/nft/storage/sql_storage.rs Outdated Show resolved Hide resolved
mm2src/coins/nft/storage/sql_storage.rs Show resolved Hide resolved
mm2src/db_common/Cargo.toml Outdated Show resolved Hide resolved
@laruh laruh added in progress Changes will be made from the author and removed under review labels Nov 7, 2023
Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor notes and question 🙂

mm2src/coins/nft/storage/wasm/wasm_storage.rs Outdated Show resolved Hide resolved
mm2src/coins/nft/storage/wasm/wasm_storage.rs Outdated Show resolved Hide resolved
mm2src/coins/nft/storage/wasm/wasm_storage.rs Show resolved Hide resolved
Copy link
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR! First review iteration with only small comments at this stage of the review.

mm2src/coins/nft.rs Outdated Show resolved Hide resolved
mm2src/mm2_core/src/mm_ctx.rs Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this code ported? In the future it would be good to follow these guidelines for ported code #1861 (review) #1861 (comment) so that we can track the changes in the commit history, and it will also be easy for reviewers to check the changes to the original code. It's not required for this PR though as it will be hard to do that.

Copy link
Member Author

@laruh laruh Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, Yes, its ported from https://github.com/programatik29/tokio-rusqlite/blob/master/src/lib.rs

In PR description I can provide gist with the info about changes in ported files and in deps for this lib.
Also I will provide the list of commits where I added async con first time and then changed it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

artemii235
artemii235 previously approved these changes Nov 8, 2023
Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more notes from my side 🙂

@laruh laruh added under review and removed in progress Changes will be made from the author labels Nov 8, 2023
Copy link
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next Review Iteration :)

mm2src/coins/nft/nft_errors.rs Outdated Show resolved Hide resolved
mm2src/mm2_core/src/mm_ctx.rs Outdated Show resolved Hide resolved
mm2src/mm2_core/src/mm_ctx.rs Show resolved Hide resolved
Copy link
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one last comment!

mm2src/db_common/src/async_sql_conn.rs Show resolved Hide resolved
Copy link
Member

@onur-ozkan onur-ozkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Can we have different PRs for per scope next time? It was quite hard to review (e.g., trying to understand which changes relate each other) for me as the changes contain changes on different logics/scopes.

Some notes from my side:

mm2src/coins/nft.rs Outdated Show resolved Hide resolved
mm2src/coins/nft/nft_structs.rs Outdated Show resolved Hide resolved
mm2src/mm2_core/src/mm_ctx.rs Outdated Show resolved Hide resolved
mm2src/db_common/src/async_sql_conn.rs Outdated Show resolved Hide resolved
mm2src/db_common/src/async_sql_conn.rs Outdated Show resolved Hide resolved
@laruh
Copy link
Member Author

laruh commented Nov 10, 2023

Can we have different PRs for per scope next time? It was quite hard to review (e.g., trying to understand which changes relate each other) for me as the changes contain changes on different logics/scopes.

yeah, sorry for this. Lets try this strategy in next sprint(s). we can create a chain of pull requests, where the base branch of subsequent RP is the feature branch from prev PR.

onur-ozkan
onur-ozkan previously approved these changes Nov 10, 2023
@laruh laruh added in progress Changes will be made from the author and removed under review labels Nov 12, 2023
@laruh laruh removed the in progress Changes will be made from the author label Nov 20, 2023
@laruh laruh changed the base branch from spam-nft-refactor-db to dev November 21, 2023 03:49
@laruh laruh dismissed stale reviews from shamardy, onur-ozkan, and artemii235 November 21, 2023 03:49

The base branch was changed.

@laruh
Copy link
Member Author

laruh commented Nov 21, 2023

@laruh now you need to change the base branch to dev as discussed on DM some time ago

Done!

shamardy
shamardy previously approved these changes Nov 21, 2023
@shamardy
Copy link
Collaborator

@laruh if there are any changes to docs for @KomodoPlatform/qa please provide these changes.

@smk762
Copy link

smk762 commented Nov 27, 2023

Docs r2r at KomodoPlatform/komodo-docs-mdx#42

@laruh
Copy link
Member Author

laruh commented Dec 11, 2023

@smk762 @shamardy added commit 4ba539f which fixes redundant moralis reqs during update_nft call.

@smk762
Copy link

smk762 commented Dec 11, 2023

@smk762 @shamardy added commit 4ba539f which fixes redundant moralis reqs during update_nft call.

tested in isolation and confirmed working

@Alrighttt
Copy link
Member

Alrighttt commented Dec 11, 2023

@laruh please provide a brief justification for each dependency added.

edit: Never mind, all the "deps added" are already used within the project.

@shamardy shamardy merged commit 52dab22 into dev Dec 11, 2023
24 of 31 checks passed
@shamardy shamardy deleted the nft-move-db-lock branch December 11, 2023 18:08
Copy link

@ca333 ca333 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

secure code reviewed

dimxy added a commit to dimxy/komodo-defi-framework that referenced this pull request Dec 21, 2023
* dev: (22 commits)
  chore(config): remove vscode launchjson (KomodoPlatform#2040)
  feat(trading-proto-upgrade): wasm DB, kickstart, refund states, v2 RPCs (KomodoPlatform#2015)
  feat(UTXO): balance event streaming for Electrum clients (KomodoPlatform#2013)
  feat(tx): add new sign_raw_transaction rpc for UTXO and EVM coins (KomodoPlatform#1930)
  fix(p2p): handle encode_and_sign errors (KomodoPlatform#2038)
  chore(release): add changelog entries for v2.0.0-beta (KomodoPlatform#2037)
  chore(network): write network information to stdout (KomodoPlatform#2034)
  fix(price_endpoints): add cached url (KomodoPlatform#2032)
  deps(network): sync with upstream yamux (KomodoPlatform#2030)
  fix(config): accept a string as rpcport value (KomodoPlatform#2026)
  feat(nft): move db lock, add tx fee and confirmations (KomodoPlatform#1989)
  chore(network): update seednodes for netid 8762 (KomodoPlatform#2024)
  chore(network): add todo on peer storage behaviour (KomodoPlatform#2025)
  chore(network): exclude `168.119.236.249` from the seednode list (KomodoPlatform#2021)
  feat(network): deprecate 7777 network (KomodoPlatform#2020)
  chore(release): bump mm2 version to 2.0.0-beta (KomodoPlatform#2018)
  feat(UTXO swaps): kmd burn plan impl (KomodoPlatform#2006)
  chore(docs): fix the link to simple market maker in README.md (KomodoPlatform#2011)
  refactor(cli): cli dependency updates and warn on bad config perm (KomodoPlatform#1956)
  chore(containers and docs): update docs and container images (KomodoPlatform#2003)
  ...

# Conflicts:
#	mm2src/mm2_main/tests/mm2_tests/mm2_tests_inner.rs
#	mm2src/mm2_test_helpers/src/for_tests.rs
dimxy added a commit to dimxy/komodo-defi-framework that referenced this pull request Jan 23, 2024
* dev: (24 commits)
  chore(release): bump mm2 version to 2.1.0-beta (KomodoPlatform#2044)
  feat(trezor): add segwit support for withdraw with trezor (KomodoPlatform#1984)
  chore(config): remove vscode launchjson (KomodoPlatform#2040)
  feat(trading-proto-upgrade): wasm DB, kickstart, refund states, v2 RPCs (KomodoPlatform#2015)
  feat(UTXO): balance event streaming for Electrum clients (KomodoPlatform#2013)
  feat(tx): add new sign_raw_transaction rpc for UTXO and EVM coins (KomodoPlatform#1930)
  fix(p2p): handle encode_and_sign errors (KomodoPlatform#2038)
  chore(release): add changelog entries for v2.0.0-beta (KomodoPlatform#2037)
  chore(network): write network information to stdout (KomodoPlatform#2034)
  fix(price_endpoints): add cached url (KomodoPlatform#2032)
  deps(network): sync with upstream yamux (KomodoPlatform#2030)
  fix(config): accept a string as rpcport value (KomodoPlatform#2026)
  feat(nft): move db lock, add tx fee and confirmations (KomodoPlatform#1989)
  chore(network): update seednodes for netid 8762 (KomodoPlatform#2024)
  chore(network): add todo on peer storage behaviour (KomodoPlatform#2025)
  chore(network): exclude `168.119.236.249` from the seednode list (KomodoPlatform#2021)
  feat(network): deprecate 7777 network (KomodoPlatform#2020)
  chore(release): bump mm2 version to 2.0.0-beta (KomodoPlatform#2018)
  feat(UTXO swaps): kmd burn plan impl (KomodoPlatform#2006)
  chore(docs): fix the link to simple market maker in README.md (KomodoPlatform#2011)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants