ethcore-sync: accept service transactions from parity and parity-ethereum

This commit is contained in:
5chdn 2018-07-05 22:41:21 +02:00
parent 338e56907f
commit 04dad4a140
No known key found for this signature in database
GPG Key ID: 1A40871B597F5F80

View File

@ -48,16 +48,24 @@ fn accepts_service_transaction(client_id: &str) -> bool {
// Parity versions starting from this will accept service-transactions // Parity versions starting from this will accept service-transactions
const SERVICE_TRANSACTIONS_VERSION: (u32, u32) = (1u32, 6u32); const SERVICE_TRANSACTIONS_VERSION: (u32, u32) = (1u32, 6u32);
// Parity client string prefix // Parity client string prefix
const LEGACY_CLIENT_ID_PREFIX: &'static str = "Parity/v";
const PARITY_CLIENT_ID_PREFIX: &'static str = "Parity-Ethereum/v"; const PARITY_CLIENT_ID_PREFIX: &'static str = "Parity-Ethereum/v";
if !client_id.starts_with(PARITY_CLIENT_ID_PREFIX) { if client_id.starts_with(LEGACY_CLIENT_ID_PREFIX) {
return false; let ver: Vec<u32> = 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<u32> = client_id[PARITY_CLIENT_ID_PREFIX.len()..].split('.') let ver: Vec<u32> = client_id[PARITY_CLIENT_ID_PREFIX.len()..].split('.')
.take(2) .take(2)
.filter_map(|s| s.parse().ok()) .filter_map(|s| s.parse().ok())
.collect(); .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 /// 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()); io.peers_info.insert(2, "Parity-Ethereum/v2.6".to_owned());
// and peer#3 is Parity, discarding service transactions // and peer#3 is Parity, discarding service transactions
insert_dummy_peer(&mut sync, 3, block_hash); 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 // and peer#4 is Parity, accepting service transactions
insert_dummy_peer(&mut sync, 4, block_hash); insert_dummy_peer(&mut sync, 4, block_hash);
io.peers_info.insert(4, "Parity-Ethereum/v2.7.3-ABCDEFGH".to_owned()); io.peers_info.insert(4, "Parity-Ethereum/v2.7.3-ABCDEFGH".to_owned());