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

fix(nft): fix notes for 1.0.6-beta #1914

Merged
merged 9 commits into from Jul 17, 2023
Merged

fix(nft): fix notes for 1.0.6-beta #1914

merged 9 commits into from Jul 17, 2023

Conversation

laruh
Copy link
Member

@laruh laruh commented Jul 12, 2023

@laruh laruh added in progress Changes will be made from the author 1.0.6-beta labels Jul 12, 2023
@laruh laruh added under review and removed in progress Changes will be made from the author labels Jul 13, 2023
@laruh laruh requested a review from shamardy July 13, 2023 08:15
@laruh laruh added in progress Changes will be made from the author and removed under review labels Jul 13, 2023
@laruh laruh added under review and removed in progress Changes will be made from the author labels Jul 14, 2023
@laruh
Copy link
Member Author

laruh commented Jul 14, 2023

@Alrighttt @ozkanonur please review Address type for nft addresses and prepared stmt.

@shamardy shamardy added the P1 label Jul 14, 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.

Thank you for the fixes! First review iteration!

mm2src/coins/eth.rs Outdated Show resolved Hide resolved
@@ -455,3 +459,17 @@ impl From<Nft> for TxMeta {
}
}
}

pub(crate) struct NftCtx {
pub(crate) guard: Arc<AsyncMutex<()>>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think instead of a guard you should have the nft_cache_db in the Nft context

nft_cache_db: ConstructibleDb::new(ctx).into_shared(),

then it can be initialized only once when from_ctx first called and then retrieved on subsequent calls and this is done using from_ctx
like how it's used in CoinsContext
Ok(try_s!(from_ctx(&ctx.coins_ctx, move || {

This is not a blocker since guard works right now, but it's better code structure since now we have CoinsContext and NftCtx and nft_cache_db is in CoinsContext. I think you can remove the need to build storage in every nft function also following from the above.

Copy link
Member Author

@laruh laruh Jul 16, 2023

Choose a reason for hiding this comment

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

I think instead of a guard you should have the nft_cache_db in the Nft context

without mutex guard, we will have the same mm2 problem due to race condition.

{"mmrpc":"2.0","error":"DB error ErrorSaving(\"Error uploading an item: \\\"DomException { obj: Object { obj: JsValue(ConstraintError: Unable to add key to index 'chain_tx_hash_index': at least one key does not satisfy the uniqueness requirements.\\\\nundefined) } }\\\"\")","error_path":"nft.wasm_storage.object_store","error_trace":"nft:115] wasm_storage:362] object_store:42]","error_type":"DbError","error_data":"ErrorSaving(\"Error uploading an item: \\\"DomException { obj: Object { obj: JsValue(ConstraintError: Unable to add key to index 'chain_tx_hash_index': at least one key does not satisfy the uniqueness requirements.\\\\nundefined) } }\\\"\")","id":null}

PS: I also caught this problem in native target. Sql propagates the error that you are trying to add item with identical primary key.

I mean if we just move nft_cache_db to NftCtx, we will have the same situation. Instead of CoinsContext::from_ctx(ctx) we will just have NftCtx::from_ctx(&ctx) here
image
Also dont forget, that nft_cache_db is for wasm target, for native we use sqlite_connection from mmctx.

We need to lock the whole function before using storage and sending the moralis request. So I believe it doesn't mater, where we have nft_cache_db or build storage, we need to prevent the access to storage and sending identical moralis request before previous RPC is done.

But yeah, it is a good idea, bcz nft_cache_db should be a part of context of related feature. I didnt notice it.

I think you can remove the need to build storage in every nft function also following from the above.

yep, I have it in my plans. Actually I was trying to move the process of NftBuilder creation and NftStorage building to NftCtx as in this example, but I faced with problem during creating of Box with type impl NftListStorageOps + NftTxHistoryStorageOps. Moreover traits have type Error: NftStorageError. So I postponed this idea until the next refactoring.

Copy link
Member Author

Choose a reason for hiding this comment

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

moved nft_cache_db field to struct NftCtx

mm2src/coins/nft.rs Outdated Show resolved Hide resolved
Copy link
Member

@Alrighttt Alrighttt left a comment

Choose a reason for hiding this comment

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

LGTM

@smk762 smk762 self-requested a review July 17, 2023 19:34
Copy link

@smk762 smk762 left a comment

Choose a reason for hiding this comment

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

Testing NFT database successful:

On first load, nft list and history empty until update_nft called.
Ddid some transfers, from external and to self, and each time no change to list/history, until update called. No errors encountered.
On self send, saw block number go up in list as expected. No errors encountered.
After logging out and then in again, previous stored list/history was visible without needing to call update.

@shamardy shamardy merged commit 1e0cf5b into dev Jul 17, 2023
23 of 30 checks passed
@shamardy shamardy deleted the nft_fix_for_1.0.6 branch July 17, 2023 23:26
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.

None yet

4 participants