Remove version fields from GetBlocks, GetHeaders.

These are instead set by the negotiated version.
This commit is contained in:
Henry de Valence 2020-02-08 13:48:42 -08:00 committed by Deirdre Connolly
parent 44b299d15c
commit 47cafc630f
2 changed files with 18 additions and 20 deletions

View File

@ -205,20 +205,18 @@ impl Codec {
GetAddr => { /* Empty payload -- no-op */ } GetAddr => { /* Empty payload -- no-op */ }
Block(ref block) => block.zcash_serialize(&mut writer)?, Block(ref block) => block.zcash_serialize(&mut writer)?,
GetBlocks { GetBlocks {
ref version,
ref block_locator_hashes, ref block_locator_hashes,
ref hash_stop, ref hash_stop,
} => { } => {
writer.write_u32::<LittleEndian>(version.0)?; writer.write_u32::<LittleEndian>(self.builder.version.0)?;
block_locator_hashes.zcash_serialize(&mut writer)?; block_locator_hashes.zcash_serialize(&mut writer)?;
hash_stop.zcash_serialize(&mut writer)?; hash_stop.zcash_serialize(&mut writer)?;
} }
GetHeaders { GetHeaders {
ref version,
ref block_locator_hashes, ref block_locator_hashes,
ref hash_stop, ref hash_stop,
} => { } => {
writer.write_u32::<LittleEndian>(version.0)?; writer.write_u32::<LittleEndian>(self.builder.version.0)?;
block_locator_hashes.zcash_serialize(&mut writer)?; block_locator_hashes.zcash_serialize(&mut writer)?;
hash_stop.zcash_serialize(&mut writer)?; hash_stop.zcash_serialize(&mut writer)?;
} }
@ -457,11 +455,14 @@ impl Codec {
} }
fn read_getblocks<R: Read>(&self, mut reader: R) -> Result<Message, Error> { fn read_getblocks<R: Read>(&self, mut reader: R) -> Result<Message, Error> {
Ok(Message::GetBlocks { if self.builder.version == Version(reader.read_u32::<LittleEndian>()?) {
version: Version(reader.read_u32::<LittleEndian>()?), Ok(Message::GetBlocks {
block_locator_hashes: Vec::zcash_deserialize(&mut reader)?, block_locator_hashes: Vec::zcash_deserialize(&mut reader)?,
hash_stop: BlockHeaderHash::zcash_deserialize(&mut reader)?, hash_stop: BlockHeaderHash::zcash_deserialize(&mut reader)?,
}) })
} else {
Err(Error::Parse("getblocks version did not match negotiation"))
}
} }
/// Deserialize a `headers` message. /// Deserialize a `headers` message.
@ -474,11 +475,14 @@ impl Codec {
} }
fn read_getheaders<R: Read>(&self, mut reader: R) -> Result<Message, Error> { fn read_getheaders<R: Read>(&self, mut reader: R) -> Result<Message, Error> {
Ok(Message::GetHeaders { if self.builder.version == Version(reader.read_u32::<LittleEndian>()?) {
version: Version(reader.read_u32::<LittleEndian>()?), Ok(Message::GetHeaders {
block_locator_hashes: Vec::zcash_deserialize(&mut reader)?, block_locator_hashes: Vec::zcash_deserialize(&mut reader)?,
hash_stop: BlockHeaderHash::zcash_deserialize(&mut reader)?, hash_stop: BlockHeaderHash::zcash_deserialize(&mut reader)?,
}) })
} else {
Err(Error::Parse("getblocks version did not match negotiation"))
}
} }
fn read_inv<R: Read>(&self, reader: R) -> Result<Message, Error> { fn read_inv<R: Read>(&self, reader: R) -> Result<Message, Error> {

View File

@ -160,9 +160,6 @@ pub enum Message {
// restriction, or if they don't, what happens if we send them too // restriction, or if they don't, what happens if we send them too
// many results. // many results.
GetBlocks { GetBlocks {
/// The protocol version.
version: Version,
/// Block locators, from newest back to genesis block. /// Block locators, from newest back to genesis block.
block_locator_hashes: Vec<BlockHeaderHash>, block_locator_hashes: Vec<BlockHeaderHash>,
@ -203,9 +200,6 @@ pub enum Message {
// restriction, or if they don't, what happens if we send them too // restriction, or if they don't, what happens if we send them too
// many results. // many results.
GetHeaders { GetHeaders {
/// The protocol version.
version: Version,
/// Block locators, from newest back to genesis block. /// Block locators, from newest back to genesis block.
block_locator_hashes: Vec<BlockHeaderHash>, block_locator_hashes: Vec<BlockHeaderHash>,