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

Linkdrop locust workload #11782

Merged
merged 5 commits into from
Jul 17, 2024

Conversation

jaswinder6991
Copy link
Contributor

I created a linkdrop workload as a part of statelessnet traffic generation program.

The load deploys a keypom contract and then try to create and claim linkdrop on it.

@jaswinder6991 jaswinder6991 requested a review from a team as a code owner July 13, 2024 05:30
@jaswinder6991
Copy link
Contributor Author

While I try to run this I came across this error below:

[2024-07-13 10:50:15,406] 192/WARNING/root: marking an error Link Error: "function types incompatible: expected func of type `(i64) -> ()`, found func of type `(i32, i32, i32) -> (i32)`", id=FkAajDBZqe33dhiKbBMARxQz3WNk6dwYZAftiFYu8YHm {'executor_id': 'uizajn_linkdrop.node0', 'gas_burnt': 1511604825652, 'logs': [], 'metadata': {'gas_profile': [{'cost': 'CONTRACT_LOADING_BASE', 'cost_category': 'WASM_HOST_COST', 'gas_used': '35445963'}, {'cost': 'CONTRACT_LOADING_BYTES', 'cost_category': 'WASM_HOST_COST', 'gas_used': '623228152005'}], 'version': 3}, 'receipt_ids': ['8jKbxRHU653rAyonevFfRs7dVTfWThuXj8rqbVevRR5F'], 'status': {'Failure': {'ActionError': {'index': 0, 'kind': {'FunctionCallError': {'ExecutionError': 'Link Error: "function types incompatible: expected func of type `(i64) -> ()`, found func of type `(i32, i32, i32) -> (i32)`"'}}}}}, 'tokens_burnt': '151160482565200000000'}

This happens in InitLinkdrop while deploying the contract. I thought it was a problem with my code but then I tried to run the ft load and saw the same problem.

Copy link

codecov bot commented Jul 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.77%. Comparing base (3ed0062) to head (8ab27b2).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #11782   +/-   ##
=======================================
  Coverage   71.77%   71.77%           
=======================================
  Files         796      796           
  Lines      162939   162939           
  Branches   162939   162939           
=======================================
+ Hits       116951   116953    +2     
  Misses      40934    40934           
+ Partials     5054     5052    -2     
Flag Coverage Δ
backward-compatibility 0.23% <ø> (ø)
db-migration 0.23% <ø> (ø)
genesis-check 1.35% <ø> (ø)
integration-tests 37.93% <ø> (+0.01%) ⬆️
linux 71.29% <ø> (+0.01%) ⬆️
linux-nightly 71.37% <ø> (+<0.01%) ⬆️
macos 54.56% <ø> (-0.01%) ⬇️
pytests 1.58% <ø> (ø)
sanity-checks 1.38% <ø> (ø)
unittests 66.21% <ø> (-0.02%) ⬇️
upgradability 0.28% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jancionear jancionear requested review from aborg-dev and telezhnaya and removed request for wacban July 13, 2024 23:16
@jaswinder6991 jaswinder6991 force-pushed the jass/performance-tests-linkdrop branch from be00fa3 to 3fa4b31 Compare July 15, 2024 07:21
return transaction.sign_function_call_transaction(
self.sender.key, self.receiver_id, self.method,
json.dumps(self.args()).encode('utf-8'), 100 * TGAS, self.balance,
self.sender.get_nonce_for_pk(self.node, self.sender.key.account_id,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason why you can't use self.sender.use_nonce() here instead of get_nonce_for_pk?
It is supposed to be a simpler and more scalable way because it caches the nonce betweek calls.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, if we find a way to use the standard use_nonce() here, we'll be able to use FunctionCall as a base class, removing a lot of boilerplate.

Copy link
Contributor Author

@jaswinder6991 jaswinder6991 Jul 15, 2024

Choose a reason for hiding this comment

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

The way the linkdrop contract works is that it exposes an add_key function which lets drop creator call it and add a new access key to the contract.
The drop claimer then calls the contract function claim using this limited access key. So the contract is calling itself now basically.

use_nonce gave you the nonce for the full key for the smart contract currently in the runner. I needed nonce for the newly added access key which is limited and can only call claim function.

For every claim, you use a new access key hence caching old nonce won't work.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, In this case I suggest inlining the call to mocknet_helpers.get_nonce_for_pk here directly and removing the method Account::get_nonce_for_pk(self, ...), as the self is not used in that method.

self.node = node

#Create a new key pair, which would be a full access key to your account
private_key, public_key = ed25519.create_keypair()
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a helper class for this in pytest/lib/key.py:Key.
You should be able to do something like:

key = Key.implicit_account()
# Use `key.sk` and `key.pk` as before.


from configured_logger import new_logger
from locust import constant_throughput, task
#from common.base import NearUser
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Remove commented out line

@task
def create_and_claim_drop(self):
# Generate a random key pair
private_key, public_key = ed25519.create_keypair()
Copy link
Contributor

Choose a reason for hiding this comment

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

Same observation as above about using Key class to get sk and pk instead



@events.init.add_listener
def on_locust_init(environment, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency, can you please move on_locust_init and a parser method below into "common/linkdrop.py"?
This is how we do it for other workloads and it makes it easier to reuse multiple different workloads in a single locustfile.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add instructions on how to download this file into https://github.com/near/nearcore/blob/master/pytest/tests/loadtest/locust/download_contracts.sh?

This will help us to refresh it in the future if it ever changes.

Copy link
Contributor

@aborg-dev aborg-dev 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 contributing a new Locust workload! I've left some comments, but I think it should be good to go very soon.

@jaswinder6991
Copy link
Contributor Author

Thanks for contributing a new Locust workload! I've left some comments, but I think it should be good to go very soon.

Thanks @Akashin for the review. I will work on all the comments immediately.
I am not able to run it locally because of this issue I mentioned.

#11782 (comment)

Do you have any ideas why this is happening?
It happens for current FT load too for me. My hunch is that is it could be an Apple Silicon M1 issue.

@aborg-dev
Copy link
Contributor

aborg-dev commented Jul 15, 2024

While I try to run this I came across this error below:

[2024-07-13 10:50:15,406] 192/WARNING/root: marking an error Link Error: "function types incompatible: expected func of type `(i64) -> ()`, found func of type `(i32, i32, i32) -> (i32)`", id=FkAajDBZqe33dhiKbBMARxQz3WNk6dwYZAftiFYu8YHm {'executor_id': 'uizajn_linkdrop.node0', 'gas_burnt': 1511604825652, 'logs': [], 'metadata': {'gas_profile': [{'cost': 'CONTRACT_LOADING_BASE', 'cost_category': 'WASM_HOST_COST', 'gas_used': '35445963'}, {'cost': 'CONTRACT_LOADING_BYTES', 'cost_category': 'WASM_HOST_COST', 'gas_used': '623228152005'}], 'version': 3}, 'receipt_ids': ['8jKbxRHU653rAyonevFfRs7dVTfWThuXj8rqbVevRR5F'], 'status': {'Failure': {'ActionError': {'index': 0, 'kind': {'FunctionCallError': {'ExecutionError': 'Link Error: "function types incompatible: expected func of type `(i64) -> ()`, found func of type `(i32, i32, i32) -> (i32)`"'}}}}}, 'tokens_burnt': '151160482565200000000'}

This happens in InitLinkdrop while deploying the contract. I thought it was a problem with my code but then I tried to run the ft load and saw the same problem.

This indicates that something is wrong with the deployed WASM for this smart contract.
There are a few place in our code that reference this:

But I agree that the error is quite cryptic. Maybe @Ekleog or @nagisa know how to debug this further?

The FT smart contract is definitely well-formed, so I would double-check that you are testing this with the latest version of neard binary.

The Apple M1 can definitely be the issue here, I'm not entirely sure about the status of support for this hardware. A few ways around this would be either running the workload in a VM or use Docker.

@wacban
Copy link
Contributor

wacban commented Jul 15, 2024

re link error - not sure if this helps but I got the same error when specifying wrong function signature in the near test contracts. For me it was when I used u32 instead of u64 but it seems like you have a larger mismatch:
(i64) -> ()`, found func of type `(i32, i32, i32) -> (i32).

It would be cool to provide some extra info in the error, most notably the method name.

@jaswinder6991
Copy link
Contributor Author

re link error - not sure if this helps but I got the same error when specifying wrong function signature in the near test contracts. For me it was when I used u32 instead of u64 but it seems like you have a larger mismatch: (i64) -> ()`, found func of type `(i32, i32, i32) -> (i32).

It would be cool to provide some extra info in the error, most notably the method name.

For me it seems like it occurs while calling the init function after deploying the contract.
See here.
I have seen this for fungible_token load too. So init function for it as well.

@nagisa
Copy link
Collaborator

nagisa commented Jul 15, 2024

Maybe @Ekleog or @nagisa know how to debug this further?

The answer to this is a debugger attached to neard (ideally rr) or modify the validator with print statements in various locations where the error might originate from.

Due to the protocol requirements and such, having a quality insight into what's going wrong was not really a major goal for a long time and a project of building up a contract developer dev tool which would have helped with this never materialized.

@jaswinder6991
Copy link
Contributor Author

While I try to run this I came across this error below:

[2024-07-13 10:50:15,406] 192/WARNING/root: marking an error Link Error: "function types incompatible: expected func of type `(i64) -> ()`, found func of type `(i32, i32, i32) -> (i32)`", id=FkAajDBZqe33dhiKbBMARxQz3WNk6dwYZAftiFYu8YHm {'executor_id': 'uizajn_linkdrop.node0', 'gas_burnt': 1511604825652, 'logs': [], 'metadata': {'gas_profile': [{'cost': 'CONTRACT_LOADING_BASE', 'cost_category': 'WASM_HOST_COST', 'gas_used': '35445963'}, {'cost': 'CONTRACT_LOADING_BYTES', 'cost_category': 'WASM_HOST_COST', 'gas_used': '623228152005'}], 'version': 3}, 'receipt_ids': ['8jKbxRHU653rAyonevFfRs7dVTfWThuXj8rqbVevRR5F'], 'status': {'Failure': {'ActionError': {'index': 0, 'kind': {'FunctionCallError': {'ExecutionError': 'Link Error: "function types incompatible: expected func of type `(i64) -> ()`, found func of type `(i32, i32, i32) -> (i32)`"'}}}}}, 'tokens_burnt': '151160482565200000000'}

This happens in InitLinkdrop while deploying the contract. I thought it was a problem with my code but then I tried to run the ft load and saw the same problem.

This indicates that something is wrong with the deployed WASM for this smart contract. There are a few place in our code that reference this:

But I agree that the error is quite cryptic. Maybe @Ekleog or @nagisa know how to debug this further?

The FT smart contract is definitely well-formed, so I would double-check that you are testing this with the latest version of neard binary.

The Apple M1 can definitely be the issue here, I'm not entirely sure about the status of support for this hardware. A few ways around this would be either running the workload in a VM or use Docker.

An update on this. I tried to run the workload on the statelessnet instead of localnet and everything worked smoothly like before.
My take is that it is either an Apple Silicon issue or my local issue. I will try to test this with another Apple Silicon system.

def create_and_claim_drop(self):
# Generate a random key pair
keypair = key.Key.implicit_account()
public_keys = []
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: can just define this as public_keys = [keypair.pk]

Copy link
Contributor

@aborg-dev aborg-dev Jul 16, 2024

Choose a reason for hiding this comment

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

Or even inlining it in AddKey constructor, as this variable it not used anywhere else.

@telezhnaya telezhnaya added this pull request to the merge queue Jul 17, 2024
Merged via the queue into near:master with commit 1786401 Jul 17, 2024
29 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants