From 9603597da79ebcac99d4e018c960ce6c511c9880 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 15 Jun 2016 21:31:19 +0200 Subject: [PATCH 1/2] Fix read-ahead bug. Re-ahead 8 bytes rather than 3 to ensure large blocks import fine. --- parity/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/parity/main.rs b/parity/main.rs index 1467eaa50..e1890ff0f 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -398,7 +398,7 @@ fn execute_import(conf: Configuration) { Box::new(::std::io::stdin()) }; - let mut first_bytes: Bytes = vec![0; 3]; + let mut first_bytes: Bytes = vec![0; 8]; let mut first_read = 0; let format = match conf.args.flag_format { @@ -438,13 +438,13 @@ fn execute_import(conf: Configuration) { match format { DataFormat::Binary => { loop { - let mut bytes: Bytes = if first_read > 0 {first_bytes.clone()} else {vec![0; 3]}; + let mut bytes: Bytes = if first_read > 0 {first_bytes.clone()} else {vec![0; 8]}; let n = if first_read > 0 {first_read} else {instream.read(&mut(bytes[..])).unwrap_or_else(|_| die!("Error reading from the file/stream."))}; if n == 0 { break; } first_read = 0; let s = PayloadInfo::from(&(bytes[..])).unwrap_or_else(|e| die!("Invalid RLP in the file/stream: {:?}", e)).total(); bytes.resize(s, 0); - instream.read_exact(&mut(bytes[3..])).unwrap_or_else(|_| die!("Error reading from the file/stream.")); + instream.read_exact(&mut(bytes[8..])).unwrap_or_else(|_| die!("Error reading from the file/stream.")); do_import(bytes); } } From 80e56cb8d7c48bf6aa9236c1f48ba00c9896e82b Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 15 Jun 2016 23:12:43 +0200 Subject: [PATCH 2/2] Refactor to use a const. --- parity/main.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/parity/main.rs b/parity/main.rs index e1890ff0f..8b99f463b 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -398,7 +398,9 @@ fn execute_import(conf: Configuration) { Box::new(::std::io::stdin()) }; - let mut first_bytes: Bytes = vec![0; 8]; + const READAHEAD_BYTES: usize = 8; + + let mut first_bytes: Bytes = vec![0; READAHEAD_BYTES]; let mut first_read = 0; let format = match conf.args.flag_format { @@ -438,13 +440,13 @@ fn execute_import(conf: Configuration) { match format { DataFormat::Binary => { loop { - let mut bytes: Bytes = if first_read > 0 {first_bytes.clone()} else {vec![0; 8]}; + let mut bytes: Bytes = if first_read > 0 {first_bytes.clone()} else {vec![0; READAHEAD_BYTES]}; let n = if first_read > 0 {first_read} else {instream.read(&mut(bytes[..])).unwrap_or_else(|_| die!("Error reading from the file/stream."))}; if n == 0 { break; } first_read = 0; let s = PayloadInfo::from(&(bytes[..])).unwrap_or_else(|e| die!("Invalid RLP in the file/stream: {:?}", e)).total(); bytes.resize(s, 0); - instream.read_exact(&mut(bytes[8..])).unwrap_or_else(|_| die!("Error reading from the file/stream.")); + instream.read_exact(&mut(bytes[READAHEAD_BYTES..])).unwrap_or_else(|_| die!("Error reading from the file/stream.")); do_import(bytes); } }