Panic on my server (attempt to subtract with overflow)
🐛 Bug Report
Logs:
2021-12-09T12:10:08.758989Z INFO Ledger successfully advanced to block 24433 (ab1xqkmfag68kuzpnl4wnkxlup2cvwf0dmxe7vxu9rrs8k30acmyczsjjy6sp)
2021-12-09T12:10:12.591517Z INFO Ledger successfully advanced to block 24434 (ab1gkjy5nsf7me9la7yaflfdgkgy0ted6k49j7m5g4g7zfusl8guc9qh9xk2r)
2021-12-09T12:10:18.041998Z INFO Ledger successfully advanced to block 24435 (ab1fp36u0eukug0s2g5tch93rt06zvvd2d7pymp57pav9fnamy3kyxqsxhka3)
2021-12-09T12:10:18.167638Z INFO Ledger successfully advanced to block 24436 (ab1v24ewezdz3xyhhd78e0g9qcxfgthv674z64fwa882gf2453r4sqqaxjt7u)
thread 'tokio-runtime-worker' panicked at 'attempt to subtract with overflow', /aleo/snarkOS/src/network/ledger.rs:954:58
stack backtrace:
0: rust_begin_unwind
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/panicking.rs:517:5
1: core::panicking::panic_fmt
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:100:14
2: core::panicking::panic
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:50:5
3: snarkos::network::ledger::Ledger<N,E>::update_block_requests::{{closure}}
at ./src/network/ledger.rs:954:58
4: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/future/mod.rs:80:19
5: snarkos::network::ledger::Ledger<N,E>::update::{{closure}}
at ./src/network/ledger.rs:295:17
6: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/future/mod.rs:80:19
7: snarkos::network::ledger::Ledger<N,E>::open::{{closure}}::{{closure}}
at ./src/network/ledger.rs:200:21
8: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/future/mod.rs:80:19
...
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
2021-12-09T12:10:44.342685Z WARN [UnconfirmedBlock] channel closed
2021-12-09T12:10:45.142860Z WARN [UnconfirmedBlock] channel closed
2021-12-09T12:10:47.222083Z ERROR Failed to send heartbeat to ledger: channel closed
2021-12-09T12:10:50.706777Z WARN [Pong] channel closed
2021-12-09T12:10:50.706905Z WARN [Pong] channel closed
2021-12-09T12:10:50.707119Z WARN [Pong] channel closed
2021-12-09T12:10:51.759396Z WARN [Pong] channel closed
2021-12-09T12:10:51.761376Z WARN [Pong] channel closed
Steps to Reproduce
Run by snarkos --trial --verbosity 0 --miner aleoxxxx
Your Environment
- testnet2 at 464586779a095a45158fb565a3c39627bb74956f
- rustc 1.57.0 (f1edd0429 2021-11-29)
- Ubuntu 18.04
While it's in line 955 (and not 954) in current testnet2 branch, I'm suspecting that it's the following operation:
let number_of_block_requests = std::cmp::min(maximum_block_height - latest_common_ancestor, E::MAXIMUM_BLOCK_REQUEST);
Upon closer inspection it seems that it's due to the current logic assuming that a greater combined weight means that the corresponding height is guaranteed to be greater.
While it's in line 955 (and not 954) in current
testnet2branch, I'm suspecting that it's the following operation:let number_of_block_requests = std::cmp::min(maximum_block_height - latest_common_ancestor, E::MAXIMUM_BLOCK_REQUEST);
You are right! I'm looking at the code, maybe with add comment.
"Duct-taping" this with a saturating_sub is an option, but it would only conceal the underlying issue; there's a related TODO by @howardwu there, Ccing him so he can comment on this when he's available.
I don't think it applies to testnet3 anymore, so closing.