Greatly reduce load onto the Electrum backend

We achieve our optimizations in three ways:

1. Batching calls instead of making them individually.

To get access to the batch calls, we replace all our
calls to the HTTP interface with RPC calls.

2. Never directly make network calls based on function
calls on the wallet.

Instead, inquiring about the status of a script always
just returns information based on local data. With every
call, we check when we last refreshed the local data and
do so if the data is considered to be too old. This
interval is configurable.

3. Use electrum's notification feature to get updated
with the latest blockheight.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Rishab Sharma <rishflab@hotmail.com>
This commit is contained in:
rishflab 2021-03-11 18:16:00 +11:00 committed by Thomas Eizinger
parent e17cbadccb
commit e5c0158597
No known key found for this signature in database
GPG key ID: 651AC83A6C6C8B96
16 changed files with 628 additions and 378 deletions

View file

@ -40,8 +40,11 @@ pub enum Command {
#[structopt(flatten)]
connect_params: AliceConnectParams,
#[structopt(flatten)]
bitcoin_params: BitcoinParams,
#[structopt(long = "electrum-rpc",
help = "Provide the Bitcoin Electrum RPC URL",
default_value = DEFAULT_ELECTRUM_RPC_URL
)]
electrum_rpc_url: Url,
#[structopt(flatten)]
monero_params: MoneroParams,
@ -59,8 +62,11 @@ pub enum Command {
#[structopt(flatten)]
connect_params: AliceConnectParams,
#[structopt(flatten)]
bitcoin_params: BitcoinParams,
#[structopt(long = "electrum-rpc",
help = "Provide the Bitcoin Electrum RPC URL",
default_value = DEFAULT_ELECTRUM_RPC_URL
)]
electrum_rpc_url: Url,
#[structopt(flatten)]
monero_params: MoneroParams,
@ -76,8 +82,11 @@ pub enum Command {
#[structopt(short, long)]
force: bool,
#[structopt(flatten)]
bitcoin_params: BitcoinParams,
#[structopt(long = "electrum-rpc",
help = "Provide the Bitcoin Electrum RPC URL",
default_value = DEFAULT_ELECTRUM_RPC_URL
)]
electrum_rpc_url: Url,
},
/// Try to cancel a swap and refund my BTC (expert users only)
Refund {
@ -90,8 +99,11 @@ pub enum Command {
#[structopt(short, long)]
force: bool,
#[structopt(flatten)]
bitcoin_params: BitcoinParams,
#[structopt(long = "electrum-rpc",
help = "Provide the Bitcoin Electrum RPC URL",
default_value = DEFAULT_ELECTRUM_RPC_URL
)]
electrum_rpc_url: Url,
},
}
@ -128,21 +140,6 @@ pub struct MoneroParams {
pub monero_daemon_host: String,
}
#[derive(structopt::StructOpt, Debug)]
pub struct BitcoinParams {
#[structopt(long = "electrum-http",
help = "Provide the Bitcoin Electrum HTTP URL",
default_value = DEFAULT_ELECTRUM_HTTP_URL
)]
pub electrum_http_url: Url,
#[structopt(long = "electrum-rpc",
help = "Provide the Bitcoin Electrum RPC URL",
default_value = DEFAULT_ELECTRUM_RPC_URL
)]
pub electrum_rpc_url: Url,
}
#[derive(Clone, Debug)]
pub struct Data(pub PathBuf);