-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: caching of recently used coins #1105
Conversation
…nto feature/utxo_caching
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only have some minor remarks
I thought about it but decided against it because it works only partially, i.e. when they use send_and_await. I imagine using send_and_await is more likely in local tests then out in the wild or if it is used on a live network, I think it's unlikely they will encounter the problem of using the same inputs since they wait for completion anyways. On the other hand, we could probably benefit from invalidating at places where we call submit_and_await internally like contract calls. So maybe it's worth it. |
Update I've adjusted it to invalidate on failed txs during Do we still want to shorten the TTL and is there a way to retrieve the block-time from the network? @Voxelot |
I agree it would make it cleaner, but I'd rather we do that in a separate PR since updating this with the master branch is getting cumbersome. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a first pass, and it's looking solid. I'll do another pass once the CI is green (I believe this is test-related so it shouldn't change much).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good, a non-blocking question on naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Checklist
Adds a cache to the
Provider
for recently used coins. The cache is behind an optional feature flag coin-cache.The cache holds a map with entries of
(Bech32Address, AssetId)
->HashSet<CoinTypeId>
whereCoinTypeId
is either a utxo or a nonce andBech32Address
is the address of the account that owns the coins.Whenever a tx is submitted, every
CoinTypeId
is added to the cache entry corresponding to it's owner and asset.When an account requests spendable_coins of a specific asset, the node is queried with recently used coins from the cache as a filtering condition.
The cache specifies a TTL for the items, once it expires the corresponding entries will be ignored and evicted the next time active entries are retrieved.
CoinCacheItem
is a wrapper for aCoinTypeId
that is stored in the cache. It includes the creation time so it can be verified against the TTL. It implements the Hash and PartialEq traits so that inserting them into the Set only compares against the id and not the creation time. This means that if a coin somehow is used again before it was evicted, the corresponding entry will just be updated with a new timestamp.Tests make use of tokio::time to advance time manually instead of using sleep().
Other changes:
The strategy for adding fee coins is changed from completly recomputing the
base asset input set to just adding an amount of base asset that will cover the fee.
While this might lead to a bit more dust it gives us more flexibility and we can allow the user to specify base asset inputs at will.