From 04dad4a140df636481f4c33d75237e19dbbf1168 Mon Sep 17 00:00:00 2001 From: 5chdn <5chdn@users.noreply.github.com> Date: Thu, 5 Jul 2018 22:41:21 +0200 Subject: [PATCH] ethcore-sync: accept service transactions from parity and parity-ethereum --- ethcore/sync/src/chain/propagator.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ethcore/sync/src/chain/propagator.rs b/ethcore/sync/src/chain/propagator.rs index 9cd3981b6..fd6f2c0c4 100644 --- a/ethcore/sync/src/chain/propagator.rs +++ b/ethcore/sync/src/chain/propagator.rs @@ -48,16 +48,24 @@ fn accepts_service_transaction(client_id: &str) -> bool { // Parity versions starting from this will accept service-transactions const SERVICE_TRANSACTIONS_VERSION: (u32, u32) = (1u32, 6u32); // Parity client string prefix + const LEGACY_CLIENT_ID_PREFIX: &'static str = "Parity/v"; const PARITY_CLIENT_ID_PREFIX: &'static str = "Parity-Ethereum/v"; - if !client_id.starts_with(PARITY_CLIENT_ID_PREFIX) { - return false; - } + if client_id.starts_with(LEGACY_CLIENT_ID_PREFIX) { + let ver: Vec = client_id[LEGACY_CLIENT_ID_PREFIX.len()..].split('.') + .take(2) + .filter_map(|s| s.parse().ok()) + .collect(); + ver.len() == 2 && (ver[0] > SERVICE_TRANSACTIONS_VERSION.0 || (ver[0] == SERVICE_TRANSACTIONS_VERSION.0 && ver[1] >= SERVICE_TRANSACTIONS_VERSION.1)) + } else if client_id.starts_with(PARITY_CLIENT_ID_PREFIX) { let ver: Vec = client_id[PARITY_CLIENT_ID_PREFIX.len()..].split('.') .take(2) .filter_map(|s| s.parse().ok()) .collect(); - ver.len() == 2 && (ver[0] > SERVICE_TRANSACTIONS_VERSION.0 || (ver[0] == SERVICE_TRANSACTIONS_VERSION.0 && ver[1] >= SERVICE_TRANSACTIONS_VERSION.1)) + ver.len() == 2 && (ver[0] > SERVICE_TRANSACTIONS_VERSION.0 || (ver[0] == SERVICE_TRANSACTIONS_VERSION.0 && ver[1] >= SERVICE_TRANSACTIONS_VERSION.1)) + } else { + return false; + } } /// The Chain Sync Propagator: propagates data to peers @@ -580,7 +588,7 @@ mod tests { io.peers_info.insert(2, "Parity-Ethereum/v2.6".to_owned()); // and peer#3 is Parity, discarding service transactions insert_dummy_peer(&mut sync, 3, block_hash); - io.peers_info.insert(3, "Parity-Ethereum/v2.5".to_owned()); + io.peers_info.insert(3, "Parity/v1.5".to_owned()); // and peer#4 is Parity, accepting service transactions insert_dummy_peer(&mut sync, 4, block_hash); io.peers_info.insert(4, "Parity-Ethereum/v2.7.3-ABCDEFGH".to_owned());