Browse Source

Replace wallet DB with in-memory DB

BDK's database only acts as a cache and can always be fully restored
by deleting it. With an Electrum backend, syncing is very quick meaning
the local cache basically does not serve any purpose. We've been having
troubles with BDK's database being broken due to internal inconsistency
problems. Switching to an in-memory database should fix these because
a restart of the application essentially wipes the database.

Resolves #465.
chore/bump-maia
Thomas Eizinger 3 years ago
parent
commit
e42a85ebcf
No known key found for this signature in database GPG Key ID: 651AC83A6C6C8B96
  1. 2
      daemon/Cargo.toml
  2. 6
      daemon/src/maker.rs
  3. 6
      daemon/src/taker.rs
  4. 6
      daemon/src/wallet.rs

2
daemon/Cargo.toml

@ -7,7 +7,7 @@ edition = "2021"
anyhow = "1"
async-trait = "0.1.51"
atty = "0.2"
bdk = { version = "0.14", default-features = false, features = ["sqlite", "electrum"] }
bdk = { version = "0.14", default-features = false, features = ["electrum"] }
bytes = "1"
chrono = { version = "0.4", features = ["serde"] }
clap = "3.0.0-beta.5"

6
daemon/src/maker.rs

@ -159,11 +159,7 @@ async fn main() -> Result<()> {
let mut tasks = Tasks::default();
let (wallet, wallet_feed_receiver) = wallet::Actor::new(
opts.network.electrum(),
&data_dir.join("maker_wallet.sqlite"),
ext_priv_key,
)?;
let (wallet, wallet_feed_receiver) = wallet::Actor::new(opts.network.electrum(), ext_priv_key)?;
let (wallet, wallet_fut) = wallet.create(None).run();
tasks.add(wallet_fut);

6
daemon/src/taker.rs

@ -170,11 +170,7 @@ async fn main() -> Result<()> {
let mut tasks = Tasks::default();
let (wallet, wallet_feed_receiver) = wallet::Actor::new(
opts.network.electrum(),
&data_dir.join("taker_wallet.sqlite"),
ext_priv_key,
)?;
let (wallet, wallet_feed_receiver) = wallet::Actor::new(opts.network.electrum(), ext_priv_key)?;
let (wallet, wallet_fut) = wallet.create(None).run();
tasks.add(wallet_fut);

6
daemon/src/wallet.rs

@ -14,7 +14,6 @@ use bdk::{electrum_client, FeeRate, KeychainKind, SignOptions};
use maia::{PartyParams, TxBuilderExt};
use rocket::serde::json::Value;
use std::collections::HashSet;
use std::path::Path;
use std::time::Duration;
use tokio::sync::watch;
use xtra_productivity::xtra_productivity;
@ -22,7 +21,7 @@ use xtra_productivity::xtra_productivity;
const DUST_AMOUNT: u64 = 546;
pub struct Actor {
wallet: bdk::Wallet<ElectrumBlockchain, bdk::database::SqliteDatabase>,
wallet: bdk::Wallet<ElectrumBlockchain, bdk::database::MemoryDatabase>,
used_utxos: HashSet<OutPoint>,
tasks: Tasks,
sender: watch::Sender<Option<WalletInfo>>,
@ -35,13 +34,12 @@ pub struct TransactionAlreadyInBlockchain;
impl Actor {
pub fn new(
electrum_rpc_url: &str,
wallet_dir: &Path,
ext_priv_key: ExtendedPrivKey,
) -> Result<(Self, watch::Receiver<Option<WalletInfo>>)> {
let client = bdk::electrum_client::Client::new(electrum_rpc_url)
.context("Failed to initialize Electrum RPC client")?;
let db = bdk::database::SqliteDatabase::new(wallet_dir.display().to_string());
let db = bdk::database::MemoryDatabase::new();
let wallet = bdk::Wallet::new(
bdk::template::Bip84(ext_priv_key, KeychainKind::External),

Loading…
Cancel
Save