Skip to content

Commit c07a0cd

Browse files
committed
Rework GraduatedRebalancer to work across restarts
Previously, we would await payment successes before doing a rebalance successful event. This would cause issues if the app was closed during a rebalance. This adds handling so the GraduatedRebalancer is now event based and persists its state. We also now have better handling for failed rebalances to go along with it.
1 parent 8e10b63 commit c07a0cd

16 files changed

Lines changed: 1210 additions & 401 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ panic = 'abort' # Abort on panic
1919
bitcoin-payment-instructions = { version = "0.6.0" }
2020
lightning = { version = "0.2.0" }
2121
lightning-invoice = { version = "0.34.0" }
22+
lightning-macros = "0.2.0"
2223

2324
[profile.release]
2425
panic = "abort"

examples/cli/src/main.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use colored::Colorize;
44
use rustyline::DefaultEditor;
55
use rustyline::error::ReadlineError;
66

7+
use orange_sdk::bitcoin::hex::DisplayHex;
78
use orange_sdk::bitcoin_payment_instructions::amount::Amount;
89
use orange_sdk::{
910
CashuConfig, ChainSource, CurrencyUnit, Event, ExtraConfig, LoggerType, Mnemonic, PaymentInfo,
@@ -224,6 +225,21 @@ impl WalletState {
224225
fee_msat
225226
);
226227
},
228+
Event::RebalanceFailed {
229+
trigger_payment_id,
230+
trusted_rebalance_payment_id,
231+
amount_msat,
232+
reason,
233+
} => {
234+
println!(
235+
"{} Rebalance failed: {} msat, trigger_payment_id: {}, trusted_rebalance_payment_id: {:?}, reason: {}",
236+
"❌".bright_red(),
237+
amount_msat,
238+
trigger_payment_id,
239+
trusted_rebalance_payment_id.map(|id| id.to_lower_hex_string()),
240+
reason
241+
);
242+
},
227243
Event::SplicePending { new_funding_txo, .. } => {
228244
println!(
229245
"{} Splice pending: {}",

graduated-rebalancer/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ license = "MIT OR Apache-2.0"
1010
bitcoin-payment-instructions = { workspace = true }
1111
lightning = { workspace = true }
1212
lightning-invoice = { workspace = true }
13-
tokio = { version = "1", default-features = false }
13+
lightning-macros = { workspace = true }
14+
tokio = { version = "1", default-features = false, features = ["sync", "macros"] }

0 commit comments

Comments
 (0)