Skip to content

Better retry system #898

@Einliterflasche

Description

@Einliterflasche

At least in the swap state machine we have retries sprinkled all over the place. They require a lot of boilerplate.

We should find a way to hoist the retries into fn run_until. It should be possible to use a thin warapper around anyhow::Error which can be easily converted back and forth but carries retry information. Maybe only persistent vs transient error. Maybe we can extend it to include retry configs (timeout, backoff, ...). Error returned by fn next_state would be (by default) treated as transient with sensible defaults, with the option to easily override this using syntax something like this:

// -- snip --
// transaction missing won't change with retries
let tx = fetch_transaction(&bitcoin_wallet, txid).await.context("Couldn't fetch transaction").permanent_err()?;
// -- snip --

Currently the small retry blocks used in many places of the state machinery add a LOT of boilerplate. Not just moving the code into a closure and specifying (mostly the same) retry config and mapping errors (.map_err(backoff::Error::transient)). We also have to clone a handful of variables each time (bitcoin wallet, state, ...). This makes the whole state machine much more verbose than it'd need to be and harder to parse / spot issues.

Metadata

Metadata

Labels

AliceRelated to the maker state machineBobRelated to the taker state machinerefactoringRelated to refactorings. No new features are added.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions