Skip to content
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

Config: expose swap finality parameters #800

Merged
merged 19 commits into from
Dec 13, 2022

Conversation

h4sh3d
Copy link
Member

@h4sh3d h4sh3d commented Dec 2, 2022

This PR introduce a new section[swap...] in the config file farcasterd.toml. The swap section, for now, contains finality and safety parameters per chain per network. A chain can accept arbitrating parameters or accordant parameters, currently we only support btc and xmr:

#[derive(Deserialize, Serialize, Debug, Clone)]
#[serde(crate = "serde_crate")]
pub struct SwapConfig {
/// Swap parameters for the Bitcoin blockchain per network
pub bitcoin: Networked<Option<ArbConfig>>,
/// Swap parameters for the Monero blockchain per network
pub monero: Networked<Option<AccConfig>>,
}

The configuration can then return a parsed swap configuration for a given network, arb chain, and acc chain

/// Returns the swap config for the specified network and arbitrating/accordant blockchains
pub fn get_swap_config(
&self,
arb: ArbitratingBlockchain,
acc: AccordantBlockchain,
network: Network,
) -> Result<ParsedSwapConfig, config::ConfigError> {

We have default values for mainnent and testnet for Bitcoin and Monero, if no config is found in the file we return those default value (backward compatibility), otherwise an error is returned. The configuration translate the real chain (Btc, Xmr) into its interface (Arb, Acc) as the swap is started with the offer that contains the chains used.

Launching a swap now takes the parsed swap config to

let child = launch(
"swapd",
&[
"--arb-finality".to_string(),
swap_config.arbitrating.finality.to_string(),
"--arb-safety".to_string(),
swap_config.arbitrating.safety.to_string(),
"--acc-finality".to_string(),
swap_config.accordant.finality.to_string(),
"--id".to_string(),
swap_id.to_hex(),
"--public-offer".to_string(),
public_offer.to_string(),
"--trade-role".to_string(),
local_trade_role.to_string(),
],
)?;

Cli arguments of swapd have been reworked to accept the new arguments. (Breaking change with other bins that use swapd directly)

The new chains.rs file contains enums for listing support arb/acc chains in our node (e.g. btc as acc is in theory possible but probably not supported in the current architecture, but that would be a nice test to see where the current design falls apart). These structs can be reused later elsewhere (e.g. make cli args) to ensure we accept only valid params.

@h4sh3d h4sh3d linked an issue Dec 6, 2022 that may be closed by this pull request
@h4sh3d h4sh3d force-pushed the feat/config-swap-finality branch from ba4d741 to 4e90e98 Compare December 6, 2022 16:48
@h4sh3d
Copy link
Member Author

h4sh3d commented Dec 6, 2022

@Lederstrumpf @TheCharlatan do we want to expose different finality and safety margin per network? (And are those names good?)

@TheCharlatan
Copy link
Member

TheCharlatan commented Dec 6, 2022

Makes sense to expose per network and names lgtm

farcasterd.toml Outdated Show resolved Hide resolved
@Lederstrumpf
Copy link
Member

@Lederstrumpf @TheCharlatan do we want to expose different finality and safety margin per network? (And are those names good?)

agree it makes sense to have different finality thresholds per network. for safety, it would be more consistent to call this safety_threshold rather than safety_margin, but it works in the opposite direction (upper vs lower bound) to finality, so having distinct names may avoid someone misinterpreting the direction.
I'll also put suggestions of finality_min and safety_max on the table to be absolutely clear on direction since they require less thinking / a lower command of English to be understood unambiguously.

@h4sh3d h4sh3d force-pushed the feat/config-swap-finality branch from 4e90e98 to 94956af Compare December 7, 2022 13:27
@h4sh3d h4sh3d marked this pull request as ready for review December 7, 2022 16:48
@h4sh3d h4sh3d added this to the v0.7.0 milestone Dec 7, 2022
Copy link
Member

@TheCharlatan TheCharlatan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 981c0d1

Really nice work! Would like @Lederstrumpf to ACK this as well, since it touches configuration.

Copy link
Member

@Lederstrumpf Lederstrumpf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK @ bda0705
and I look forward to chains.rs spreading its claws through the node to make it chain generic 🔪 :D!

pub type BlockHeight = u32;

/// Represent a block length or a block number
pub type BlockSpan = u32;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -226,25 +384,44 @@ pub struct SyncerServers {
pub monero_wallet_dir: Option<String>,
}

#[derive(Deserialize, Serialize, Default, Debug, Clone)]
#[serde(crate = "serde_crate")]
pub struct Networked<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I both hate & love this struct naming xD
I'm guessing you wanted to avoid Network because this here is limited to config? Then might go for NetworkConfig? Anyway, keen to get your rationale for this one on Monday.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) yes network is to generic, just wanted to express that it’s a wrapper to “network” a type. NetworkConfig would be fine (if we don’t introduce some [network..] section later) or PerNetwork maybe.

@Lederstrumpf
Copy link
Member

(I'm holding off on merge to get #789 in first since they conflict slightly)

@Lederstrumpf
Copy link
Member

This PR introduce a new section[swap...] in the config file farcasterd.toml. The swap section, for now, contains finality and safety parameters per chain per network. A chain can accept arbitrating parameters or accordant parameters, currently we only support btc and xmr:

...

ok - merging :). And nice new PR docs, @h4sh3d!

@Lederstrumpf Lederstrumpf merged commit 9499015 into farcaster-project:main Dec 13, 2022
h4sh3d added a commit to h4sh3d/farcaster-node that referenced this pull request Dec 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

expose finality threshold externally
3 participants