Skip to content

Commit a0c1f9e

Browse files
authored
Merge pull request #3589 from stacks-network/fix/3588
fix/3588
2 parents 07e7a61 + 8043038 commit a0c1f9e

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to the versioning scheme outlined in the [README.md](README.md).
77

8+
## [2.1.0.0.1]
9+
10+
### Fixed
11+
12+
- Handle the case where a bitcoin node returns zero headers (#3588)
13+
814
## [2.1]
915

1016
This is a **consensus-breaking** release that introduces a _lot_ of new

src/burnchains/bitcoin/spv.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,11 @@ impl SpvClient {
831831
assert!(self.readwrite, "SPV header DB is open read-only");
832832

833833
let num_headers = block_headers.len();
834+
if num_headers == 0 {
835+
// nothing to do
836+
return Ok(());
837+
}
838+
834839
let first_header_hash = block_headers[0].header.bitcoin_hash();
835840
let last_header_hash = block_headers[block_headers.len() - 1].header.bitcoin_hash();
836841
let total_work_before = self.update_chain_work()?;
@@ -1827,4 +1832,24 @@ mod test {
18271832

18281833
let deserialized: Vec<Vec<u8>> = deserialize(&encoded_tx).unwrap();
18291834
}
1835+
1836+
#[test]
1837+
fn test_handle_headers_empty() {
1838+
let headers_path = "/tmp/test-spv-handle_headers_empty.dat";
1839+
if fs::metadata(headers_path).is_ok() {
1840+
fs::remove_file(headers_path).unwrap();
1841+
}
1842+
1843+
let mut spv_client = SpvClient::new(
1844+
headers_path,
1845+
0,
1846+
None,
1847+
BitcoinNetworkType::Regtest,
1848+
true,
1849+
false,
1850+
)
1851+
.unwrap();
1852+
1853+
spv_client.handle_headers(1, vec![]).unwrap();
1854+
}
18301855
}

0 commit comments

Comments
 (0)