akorchyn / near-api

3 stars 1 forks source link

Concurrent transactions #2

Closed frol closed 1 month ago

frol commented 3 months ago

Let's also ensure we test the API usability when app developers need to make concurrent transactions (function calls).

There are several challenges there:

As part of this issue, I want us to doublecheck that it is possible to use near-api-rs in such situation and if not having a nice solution, at least have the option to have a helper wrapper with a pool of access keys.

akorchyn commented 2 months ago

The nonce caching and key pooling are implemented on the Signer level.

As long as the user keeps using the same Signer instance (that is wrapped into Arc). It should be fine.

The nonce issue could happen if the number of keys is less than the amount of TXs per sending period. Also, there is a potential issue that several instances of the same key are running concurrently. They may mess with each other, but it's up to the developer to provide unique keys.

akorchyn commented 1 month ago

Example how to use it: https://github.com/akorchyn/near-api/blob/main/examples/account_key_pooling.rs