File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.0.0/ ) ,
66and 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
1016This is a ** consensus-breaking** release that introduces a _ lot_ of new
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments