Skip to content

Commit 1dc8cc7

Browse files
committed
various fixes
1 parent dd244e9 commit 1dc8cc7

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

faucet.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ip_src = "ConnectInfo"
44
seed_file = "faucet.seed"
55
sqlite_file = "faucet.sqlite"
66
network = "signet"
7-
esplora = "https://esploraapi.devnet-annapurna.stratabtc.org"
8-
l2_http_endpoint = "https://stratareth.devnet-annapurna.stratabtc.org"
7+
esplora = "https://esploraapi53d3659b.devnet-annapurna.stratabtc.org"
8+
l2_http_endpoint = "https://stratareth3666f0713.devnet-annapurna.stratabtc.org"
99
sats_per_claim = 1_002_000_000
1010
pow_difficulty = 19

src/batcher.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub struct BatcherNotAvailable(SendError);
4040
pub struct BatcherConfig {
4141
pub period: Duration,
4242
pub max_per_tx: usize,
43+
pub max_in_flight: usize,
4344
}
4445

4546
impl Batcher {
@@ -65,6 +66,9 @@ impl Batcher {
6566
select! {
6667
biased;
6768
instant = batch_interval.tick() => {
69+
if l1_payout_queue.is_empty() {
70+
continue
71+
}
6872
let span = info_span!("batch processing", batch = ?instant);
6973
let _guard = span.enter();
7074

@@ -78,7 +82,13 @@ impl Batcher {
7882
psbt.add_recipient(req.address.script_pubkey(), req.amount);
7983
total_sent += req.amount;
8084
}
81-
let mut psbt = psbt.finish().expect("valid tx");
85+
let mut psbt = match psbt.finish() {
86+
Ok(psbt) => psbt,
87+
Err(e) => {
88+
error!("failed finalizing tx: {e:?}");
89+
continue;
90+
}
91+
};
8292

8393
let l1w = RwLockWriteGuard::downgrade(l1w);
8494

@@ -105,7 +115,9 @@ impl Batcher {
105115
}
106116
req = rx.recv() => match req {
107117
Ok(req) => match req {
108-
PayoutRequest::L1(req) => l1_payout_queue.push_back(req)
118+
PayoutRequest::L1(req) => if l1_payout_queue.len() < cfg.max_in_flight {
119+
l1_payout_queue.push_back(req)
120+
}
109121
},
110122
Err(e) => error!("error receiving PayoutRequest: {e:?}")
111123
}

src/main.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::{
1414
env,
1515
net::{IpAddr, SocketAddr},
1616
sync::{Arc, LazyLock},
17-
time::Duration,
1817
};
1918

2019
use alloy::{
@@ -30,7 +29,7 @@ use axum::{
3029
Json, Router,
3130
};
3231
use axum_client_ip::SecureClientIp;
33-
use batcher::{Batcher, BatcherConfig, L1PayoutRequest, PayoutRequest};
32+
use batcher::{Batcher, L1PayoutRequest, PayoutRequest};
3433
use bdk_wallet::{
3534
bitcoin::{address::NetworkUnchecked, Address as L1Address},
3635
KeychainKind,
@@ -82,12 +81,9 @@ async fn main() {
8281

8382
let l2_wallet = L2Wallet::new(&seed).expect("l2 wallet creation to succeed");
8483
let l1_wallet = Arc::new(RwLock::new(l1_wallet));
85-
let mut batcher = Batcher::new(BatcherConfig {
86-
period: Duration::from_secs(30),
87-
max_per_tx: 250,
88-
});
89-
84+
let mut batcher = Batcher::new(SETTINGS.batcher.clone());
9085
batcher.start(l1_wallet.clone());
86+
9187
L1Wallet::spawn_syncer(l1_wallet.clone());
9288

9389
let state = Arc::new(AppState {

src/settings.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ use std::{
33
path::PathBuf,
44
str::FromStr,
55
sync::LazyLock,
6+
time::Duration,
67
};
78

89
use axum_client_ip::SecureClientIpSource;
910
use bdk_wallet::bitcoin::{Amount, Network};
1011
use config::Config;
1112
use serde::{Deserialize, Serialize};
1213

13-
use crate::CRATE_NAME;
14+
use crate::{batcher::BatcherConfig, CRATE_NAME};
1415

1516
pub static SETTINGS: LazyLock<Settings> = LazyLock::new(|| {
1617
let args = std::env::args().collect::<Vec<_>>();
@@ -49,9 +50,12 @@ pub struct InternalSettings {
4950
pub l2_http_endpoint: String,
5051
pub sats_per_claim: Amount,
5152
pub pow_difficulty: u8,
53+
pub batcher_period: Option<u64>,
54+
pub batcher_max_per_batch: Option<usize>,
55+
pub batcher_max_in_flight: Option<usize>,
5256
}
5357

54-
#[derive(Serialize, Deserialize, Debug)]
58+
#[derive(Debug)]
5559
/// Settings struct filled with either config values or
5660
/// opinionated defaults
5761
pub struct Settings {
@@ -65,6 +69,7 @@ pub struct Settings {
6569
pub l2_http_endpoint: String,
6670
pub sats_per_claim: Amount,
6771
pub pow_difficulty: u8,
72+
pub batcher: BatcherConfig,
6873
}
6974

7075
// on L2, we represent 1 btc as 1 "eth" on the rollup
@@ -93,6 +98,11 @@ impl TryFrom<InternalSettings> for Settings {
9398
l2_http_endpoint: internal.l2_http_endpoint,
9499
sats_per_claim: internal.sats_per_claim,
95100
pow_difficulty: internal.pow_difficulty,
101+
batcher: BatcherConfig {
102+
period: Duration::from_secs(internal.batcher_period.unwrap_or(30)),
103+
max_per_tx: internal.batcher_max_per_batch.unwrap_or(250),
104+
max_in_flight: internal.batcher_max_in_flight.unwrap_or(2500),
105+
},
96106
})
97107
}
98108
}

0 commit comments

Comments
 (0)