-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Conversation
util/network-devp2p/src/ip_utils.rs
Outdated
addr[5], | ||
addr[6], | ||
addr[7])), | ||
((addr[1] as u16) << 8) | (addr[0] as u16), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addr
is actually a [u8; 16] so no need to transmute it but requires some shifting to merge two bytes into a word (two bytes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -236,16 +236,15 @@ mod getinterfaces { | |||
let sa: *const sockaddr_in6 = sa as *const sockaddr_in6; | |||
let sa = & unsafe { *sa }; | |||
let (addr, port) = (sa.sin6_addr.s6_addr, sa.sin6_port); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the type of addr
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is u32 but I saw that this was actually from std::net
and it actually implements the from trait
for our types so I changed it! Sorry for changing after reviewing byt it makes the code more readable IMO!
b2a2cf8
to
c88c831
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some grumbles.
ethash/src/compute.rs
Outdated
@@ -137,11 +137,11 @@ fn hash_compute(light: &Light, full_size: usize, header_hash: &H256, nonce: u64) | |||
($n:expr, $value:expr) => {{ | |||
// We use explicit lifetimes to ensure that val's borrow is invalidated until the | |||
// transmuted val dies. | |||
unsafe fn make_const_array<'a, T, U>(val: &'a mut [T]) -> &'a mut [U; $n] { | |||
unsafe fn make_const_array<'a, T, U>(val: &mut [T]) -> &mut [U; $n] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop unsafe
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&mut *(val.as_mut_ptr() as *mut [U; $n])
is also unsafe because deref
of raw pointer so I would like to keep the function as unsafe
! Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah won't compile without unsafe
ignore my comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like the explicit lifetimes have been dropped here. should be &'a mut [T] -> &'a mut [U; $n]
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rphmeier Explicit lifetimes
here are not needed here, so I removed them but forgot a
in the signature!
I can revert this if you want explicit lifetime annotations!
ethash/src/compute.rs
Outdated
@@ -268,10 +268,10 @@ fn hash_compute(light: &Light, full_size: usize, header_hash: &H256, nonce: u64) | |||
|
|||
let value: H256 = unsafe { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop unsafe
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, keccak_256::unchecked
is unsafe.
util/network-devp2p/src/ip_utils.rs
Outdated
((addr & 0x00FF_0000) >> 16) as u8, | ||
((addr & 0xFF00_0000) >> 24) as u8)), | ||
port) | ||
(IpAddr::V4(Ipv4Addr::from(addr)), port) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we're encoding the octets in reverse order compared to std
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will check but I assumed the tests actually tested this?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are right, I will revert this!
c88c831
to
7090737
Compare
* Make unsafe block smaller * Use different byte-order than `std`, read words as big endian instead of little endian!
7090737
to
2199be7
Compare
* Use `from_be` to work both for big and little endian * Ipv6 addresses were incorrectly `transmuted`
2199be7
to
4a3f7d3
Compare
port) | ||
let ip_addr = Ipv6Addr::from(addr); | ||
debug_assert!(addr == ip_addr.octets()); | ||
(IpAddr::V6(ip_addr), port) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty convinced that this was a bug because
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] // ::1
was parsed as [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]
Also with u8, endianness "shouldn´t"
matter
So, I suspect casting/transmute it to u16 [0x1 0x2]
will be:
- Little endian: -> [0x2 0x1]
- Big endian: -> [0x1 0x2]
Needs a 2nd review. cc @andresilva |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…rp_sync_on_light_client * 'master' of https://github.com/paritytech/parity: deps: bump fs-swap (openethereum#8953) Eliminate some more `transmute()` (openethereum#8879) Restrict vault.json permssion to owner and using random suffix for temp vault.json file (openethereum#8932) print SS.self_public when starting SS node (openethereum#8949) scripts: minor improvements (openethereum#8930) rpc: cap gas limit of local calls (openethereum#8943) docs: update changelogs (openethereum#8931) ethcore: fix compilation when using slow-blocks or evm-debug features (openethereum#8936) fixed blooms dir creation (openethereum#8941) Update hardcoded headers (openethereum#8925)
No description provided.