Skip to content
This repository has been archived by the owner on Nov 24, 2020. It is now read-only.

Query utxos from local database #25

Merged
merged 4 commits into from
Apr 29, 2020
Merged

Query utxos from local database #25

merged 4 commits into from
Apr 29, 2020

Conversation

tiero
Copy link
Contributor

@tiero tiero commented Apr 29, 2020

Before this PR, we would have to query the external explorer on-demand (most of the time via the public internet) to get utxos and balances, thus making the response time slower.

To solve this we introduce an abstraction Unspent and new collections Unspents that takes care of having a local cache. The services now query from the datastore, with a failover to explorer network call only in case of an error on reading.

The crawler has been refactored to always fetching the utxos and updating the local datastore using a new event of type BALANCE. If the daemon stops and restart, the crawlers will be started again against both the fee account and all the registered markets.

When a tradePropose is executed as the last thing we flag the consumed utxos with spent boolean and we reference those with the ID of the SwapAccept message, so in case of failure in tradeComplete step (basically no actual swap executed on-chain), we unlock those utxos so we can use it again.

Minor changes:

  • An abstraction called Market has been added to consume the type DEPOSIT events.
  • The config.json now has explorer: { liquid: ..., regtest:``} so the operator can change the explorer endpoint
  • Refactored the reducer util for grouping the utxos by assets

This closes #22

@tiero tiero merged commit 05d2205 into master Apr 29, 2020
@tiero
Copy link
Contributor Author

tiero commented Apr 29, 2020

@altafan
This is very important to be seen, even if merged already because it's a substantial change and increase the overall complexity, but it prepares for a smooth transition to support both a better fee management #17 and most importantly it helps to reason in preparation for concurrent swap requests #15

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use local cache for fethcing utxos
1 participant