`prefer_current_channel` overflows `u64 * 110` during invoice route-hint selection (panic in debug, wrong channel in release)
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 83/100
Direção de pesquisa
Comece em lightning/src/ln/invoice_utils.rs, em prefer_current_channel, por volta das linhas 583–585, e depois leia os chamadores durante a criação de invoices. Execute o reprodutor fornecido, repro_prefer_current_channel_overflow, para confirmar o overflow. O trabalho estará concluído quando a comparação tratar os valores altos indicados sem overflow e escolher o maior canal elegível; execute o reprodutor novamente em debug e release.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Summary
In lightning/src/ln/invoice_utils.rs:583-585, prefer_current_channel multiplies u64 msat values by 110 and 100 without widening:
let scaled_min_inbound = min_inbound_capacity_msat.unwrap() * 110;
let current_sufficient = current_channel * 100 >= scaled_min_inbound;
let candidate_sufficient = candidate_channel * 100 >= scaled_min_inbound;
Valid BOLT 11 amounts are accepted up to MAX_VALUE_MSAT = 2_100_000_000_000_000_000 (21M BTC), yet u64::MAX / 110 = 167_697_673_397_359_560 msat (~1.677M BTC) and u64::MAX / 100 = 184_467_440_737_095_516 msat (~1.845M BTC).
When a node has 2+ eligible private channels with the same counterparty and creates a BOLT 11 invoice via ChannelManager::create_bolt11_invoice (or invoice_utils::create_phantom_invoice) with amount_msats > u64::MAX / 110:
- Debug builds (
overflow-checks = true): panics atlightning/src/ln/invoice_utils.rs:583(attempt to multiply with overflow). - Release builds:
scaled_min_inboundsilently wraps modulo2^64(e.g.,(u64::MAX / 110 + 1).wrapping_mul(110) == 94), so both channels compare as sufficient and LDK selects the smallest channel instead of the largest channel, inverting the documented fallback rule.
Minimal Reproducer (commit 103b762b4f7842320874d4127abec854c101caba)
Add to mod test in lightning/src/ln/invoice_utils.rs:
#[test]
fn repro_prefer_current_channel_overflow() {
let chanmon_cfgs = create_chanmon_cfgs(2);
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 100_000, 10_000);
create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 500_000, 10_000);
let largest = nodes[1].node.list_usable_channels().into_iter()
.max_by_key(|c| c.inbound_capacity_msat).unwrap();
let params = Bolt11InvoiceParameters {
amount_msats: Some(u64::MAX / 110 + 1),
..Default::default()
};
let inv = nodes[1].node.create_bolt11_invoice(params).unwrap();
assert_eq!(inv.route_hints()[0].0[0].short_channel_id, largest.inbound_scid_alias.unwrap());
}
cargo test -p lightning --lib repro_prefer_current_channel_overflowpanics withattempt to multiply with overflowatinvoice_utils.rs:583:30.cargo test --release -p lightning --lib repro_prefer_current_channel_overflowfails the assertion because LDK selects the ~98.3M msat channel over the ~494.3M msat channel.
Suggested Fix
Widen the three operands to u128:
let scaled_min_inbound = u128::from(min_inbound_capacity_msat.unwrap()) * 110;
let current_sufficient = u128::from(current_channel) * 100 >= scaled_min_inbound;
let candidate_sufficient = u128::from(candidate_channel) * 100 >= scaled_min_inbound;
- Linguagem predominante
- Rust
- Estrelas
- 1.4k
- Forks
- 482
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de lightningdevkit/rust-lightning
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 65/100
lightningdevkit/rust-lightning#1849 ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 22/100
lightningdevkit/rust-lightning#4764 · 3 comentários ·
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 22/100
lightningdevkit/rust-lightning#4757 · 1 comentário ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 28/100
lightningdevkit/rust-lightning#4739 ·
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 28/100
lightningdevkit/rust-lightning#4738 · 3 comentários ·
Todas as issues de lightningdevkit/rust-lightning
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 2 dias
-
autofixer: follow-up
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
tursodatabase/turso#12531 ·
Mantenedores costumam responder em até 1 dia
-
bug help wanted ui
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
userFRM/egui-charts#4292 ·
Mantenedores costumam responder em até 1 dia
-
CHANGELOG.md out of dateAbertaIssue-Bug Need-Review
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 85/100
PowerShell/DSC#1832 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
Tripstack-Corp/spyc#1352 ·
Mantenedores costumam responder em até 1 dia