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): exclude spam and phishing, refactored db #1959

Merged
merged 50 commits into from
Nov 6, 2023
Merged

Conversation

laruh
Copy link
Member

@laruh laruh commented Sep 4, 2023

In this PR exclude_spam and exclude_phishing params were added for get_nft_list and get_nft_transfers RPCs.

Db in native target was refactored. It doesnt use details_json with all rust struct fields anymore. To get nft and transfers from db, there is need to fetch all fields from the table. However update process some specific fields from became easier.

If exclude_spam is true, then all nfts or transfers where possible_spam is true will be excluded from response.
If exclude_phishing is true, then all nfts or transfers where possible_phishing is true will be excluded from response.

Link to antispam API docs.

Second sprint iteration from commit 410330a

  • send req to camo proxy to get UriMeta from json. It protects from phishing and solves cors problem.
  • impl update of possible_phishing (add requests to /api/blocklist/domain/scan endpoint).
  • use contains_disallowed_url check for possible spam urls during update process, so we will have already checked nfts in db, which can be excluded.
  • ignore error from moralis Get NFT metadata response. If we get the error, then return Nft with empty metadata and possible_spam:true.
  • use cross tests.
  • impl async wrapper for sql Connection (future sprint).

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! Some notes from first review iteration:

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
Comment on lines 382 to 383
let nfts: Vec<Nft> = self.get_nfts_by_token_address(chain, token_address.clone()).await?;
let locked_db = self.lock_db().await?;
Copy link
Member

Choose a reason for hiding this comment

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

You should lock the db before reading nfts

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Member Author

@laruh laruh Sep 6, 2023

Choose a reason for hiding this comment

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

UPD if we move lock_db before other db methods which access db it breaks it. well bcz another storage method tries to lock db while it already was locked.

Copy link
Member

Choose a reason for hiding this comment

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

Oooh, I see. Hmm, that shouldn't be that way but let's not deal with this issue in this PR. You can revert it to previous state.

Copy link
Member Author

@laruh laruh Sep 6, 2023

Choose a reason for hiding this comment

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

You can revert it to previous state.

Already did it.

I noticed that something is wrong bcz couldn't see the rest of tests.
Didnt notice the related error message, they are almost the same as usual.

Will compare errors tomorrow, just to be sure

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 Outdated Show resolved Hide resolved
mm2src/coins/nft/storage/sql_storage.rs Show resolved Hide resolved
mm2src/coins/nft/storage/sql_storage.rs 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
@laruh laruh added in progress Changes will be made from the author and removed under review labels Sep 6, 2023
@laruh laruh added under review in progress Changes will be made from the author and removed in progress Changes will be made from the author under review labels Sep 6, 2023
@laruh laruh added under review and removed in progress Changes will be made from the author labels Sep 6, 2023
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.

These are my last notes on this PR. Thank you for patience on fixing the previous ones.

As an extra note, if this PR doesn't need to be rushed, I would highly suggest testing and re-designing the usage of db locks if necessary. Right now as far as I understand, almost every function starts with locking, so if caller and callee locks the db, there is very high chance if being end up with deadlocks. Like it happened #1959 (comment) here.

mm2src/coins/nft/nft_tests.rs Outdated Show resolved Hide resolved
mm2src/coins/nft/storage/mod.rs Outdated Show resolved Hide resolved
mm2src/coins/nft.rs Outdated 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.

Some notes starting from 6f33a11

mm2src/coins/nft.rs Outdated Show resolved Hide resolved
mm2src/coins/nft/nft_tests.rs Outdated 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.

Minor notes:

mm2src/mm2_db/src/indexed_db/indexed_db.rs Outdated Show resolved Hide resolved
mm2src/mm2_db/src/indexed_db/indexed_db.rs Outdated Show resolved Hide resolved
onur-ozkan
onur-ozkan previously approved these changes Oct 9, 2023
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.

thank you for the fixes!

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.

First review iteration from my side! I will review the rest of the code in the next and last review iteration!

Comment on lines +484 to +486
storage
.update_transfer_spam_by_token_address(chain, address_hex, true)
.await?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This call is not needed if possible_spam was true before, also can possible_spam change from true to false? meaning that an NFT that was flagged as possible spam passes some criteria and gets reconsidered as not being a spam.

Copy link
Member Author

@laruh laruh Oct 12, 2023

Choose a reason for hiding this comment

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

This call is not needed if possible_spam was true before,

oh, yeah agree in refresh_possible_spam there is no need to send spam request again if possible spam is already true bcz of nft_db.common.possible_spam = moralis_meta.common.possible_spam;

also can possible_spam change from true to false

Well we dont know how moralis marks their nft spam or not spam.
But yeah it could be a situation that they changed possible_spam from true to false
But since we use separate db with spamy addresses I suggest to mark nft as spam if contact address has true in our db.

Another but :D I got your idea. lets check in refresh_possible_spam function whether the spam value for contract address has changed in our database or not. If moralis returns false and our spam api returns false for contract in refresh functionality then lets leave this as false.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But yeah it could be a situation that they changed possible_spam from true to false

But since we use separate db with spamy addresses I suggest to mark nft as spam if contact address has true in our db.

I consider this an edge case, but NFT collections can gain traction after sometime and some of the false positive possible spam NFTs due to the criteria used to identify spams can become popular in the future. I see that we don't change true to false anywhere, we can keep it this way for now until we get real cases from users feedback.

mm2src/coins/nft.rs Show resolved Hide resolved
if let Ok(token_uri_meta) = serde_json::from_value(response_meta) {
uri_meta = token_uri_meta;
}
if let Some(url) = construct_camo_url_with_token(token_uri, url_antispam) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am interested to know how camo will be used for image_url/animation_url/etc.. , will the url be constructed from the GUI side? or will it not be used at all?

Copy link
Member Author

@laruh laruh Oct 12, 2023

Choose a reason for hiding this comment

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

@smk did /url/decode/{url_hex} endpoint capable to return you json object or if link returns image type content you will download picture, if request was successful of course(camo doesnt allow redirections). So yeah, GUI also should use camo to download pictures

Copy link
Collaborator

Choose a reason for hiding this comment

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

So yeah, GUI also should use camo to download pictures

Should we provide them the constructed camo url or will they construct it from their side? It can be an option in NftMetadataReq, if requested, we would then convert the urls after we retrieve them from database to camo format.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should we provide them the constructed camo url or will they construct it from their side?

GUI needs to convert image_url string to hex format and send get req to /url/decode/{url_hex}. There is no need to build the whole complex camo url, proxy does it on its side. All you need is to provide hex format. I think GUI can do it on their side.

It can be an option in NftMetadataReq, if requested, we would then convert the urls after we retrieve them from database to camo format.

As far as I know they send get nft list req with max flag to see all nft info and then try to send req to image_url to download picture for all items. But of course we can speak about it and if they want we can add ready hex format.

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.

🔥

@shamardy
Copy link
Collaborator

@laruh please provide @KomodoPlatform/qa team examples of changes in this PR for docs and testing if needed.

@laruh
Copy link
Member Author

laruh commented Oct 14, 2023

@laruh please provide @KomodoPlatform/qa team examples of changes in this PR for docs and testing if needed.

Sure. Actually we already in the process of adding up to date changes in the current doc PR

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

@shamardy
Copy link
Collaborator

shamardy commented Nov 6, 2023

@laruh @KomodoPlatform/qa can this PR be merged or are there still some work to be done on the QA/docs side?

@laruh
Copy link
Member Author

laruh commented Nov 6, 2023

@laruh @KomodoPlatform/qa can this PR be merged or are there still some work to be done on the QA/docs side?

Hi, I think we can merge it. Docs will be updated to match this PR, if we missed something from the current PR we also can add it.
I don't know if qa tested this pull request, but they can test the next one with async wrapper and tx fees & confirmations and also re check exclude spam/phishing.

@shamardy shamardy merged commit 30c5869 into dev Nov 6, 2023
30 of 32 checks passed
@smk762 smk762 removed the docs label Nov 1, 2024
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.

6 participants