Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Identity fix #10128

Merged
merged 8 commits into from
Jan 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions ethcore/sync/src/chain/propagator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ 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";

let splitted = if client_id.starts_with(LEGACY_CLIENT_ID_PREFIX) {
client_id[LEGACY_CLIENT_ID_PREFIX.len()..].split('.')
} else if client_id.starts_with(PARITY_CLIENT_ID_PREFIX) {
client_id[PARITY_CLIENT_ID_PREFIX.len()..].split('.')
const LEGACY_CLIENT_ID_PREFIX: &'static str = "Parity/";
const PARITY_CLIENT_ID_PREFIX: &'static str = "Parity-Ethereum/";
const VERSION_PREFIX: &'static str = "/v";

let idx = client_id.rfind(VERSION_PREFIX).map(|idx| idx + VERSION_PREFIX.len()).unwrap_or(client_id.len());
Copy link
Collaborator

@sorpaas sorpaas Jan 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this break if a client's identity starts with v?

Edit: no it won't break. rfind finds the right-most match.

let splitted = if client_id.starts_with(LEGACY_CLIENT_ID_PREFIX) || client_id.starts_with(PARITY_CLIENT_ID_PREFIX) {
client_id[idx..].split('.')
} else {
return false;
};
Expand Down Expand Up @@ -599,7 +599,7 @@ mod tests {
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());
io.peers_info.insert(4, "Parity-Ethereum/ABCDEFGH/v2.7.3".to_owned());

// and new service transaction is propagated to peers
SyncPropagator::propagate_new_transactions(&mut sync, &mut io, || true);
Expand Down