Closed tiero closed 4 years ago
@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
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 collectionsUnspents
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 withspent
boolean and we reference those with the ID of the SwapAccept message, so in case of failure intradeComplete
step (basically no actual swap executed on-chain), we unlock those utxos so we can use it again.Minor changes:
Market
has been added to consume the typeDEPOSIT
events.config.json
now hasexplorer: { liquid:
..., regtest:``}
so the operator can change the explorer endpointThis closes #22