Skip to content

Commit 45f6630

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 e277d8d commit 45f6630

File tree

16 files changed

+977
-406
lines changed

16 files changed

+977
-406
lines changed

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
ChainSource, Event, ExtraConfig, LoggerType, Mnemonic, PaymentInfo, Seed, SparkWalletConfig,
@@ -198,6 +199,21 @@ impl WalletState {
198199
fee_msat
199200
);
200201
},
202+
Event::RebalanceFailed {
203+
trigger_payment_id,
204+
trusted_rebalance_payment_id,
205+
amount_msat,
206+
reason,
207+
} => {
208+
println!(
209+
"{} Rebalance failed: {} msat, trigger_payment_id: {}, trusted_rebalance_payment_id: {:?}, reason: {}",
210+
"❌".bright_red(),
211+
amount_msat,
212+
trigger_payment_id,
213+
trusted_rebalance_payment_id.map(|id| id.to_lower_hex_string()),
214+
reason
215+
);
216+
},
201217
Event::SplicePending { new_funding_txo, .. } => {
202218
println!(
203219
"{} 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"] }

0 commit comments

Comments
 (0)