-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Private packets verification and queue refactoring #8715
Changes from all commits
843b2ba
fbdf3de
a4778e3
fc113ba
e5feccd
6436745
800aa19
55eef9e
c8898cd
12873cf
59ddce1
7e15ebb
a11c5e5
32e558c
3735cf4
6f85030
eb2ec3f
2778d4e
af28236
f6338eb
62131e0
064d814
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,15 +25,41 @@ use transaction::signature::{add_chain_replay_protection, check_replay_protectio | |
#[derive(Default, Debug, Clone, PartialEq, RlpEncodable, RlpDecodable, Eq)] | ||
pub struct PrivateTransaction { | ||
/// Encrypted data | ||
pub encrypted: Bytes, | ||
encrypted: Bytes, | ||
/// Address of the contract | ||
pub contract: Address, | ||
contract: Address, | ||
/// Hash | ||
hash: H256, | ||
} | ||
|
||
impl PrivateTransaction { | ||
/// Compute hash on private transaction | ||
/// Constructor | ||
pub fn new(encrypted: Bytes, contract: Address) -> Self { | ||
PrivateTransaction { | ||
encrypted, | ||
contract, | ||
hash: 0.into(), | ||
}.compute_hash() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please get rid of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO such optimization in order to calculate hash only once is justified. I've reworked it in order to provide access to the fields via getters |
||
} | ||
|
||
fn compute_hash(mut self) -> PrivateTransaction { | ||
self.hash = keccak(&*self.rlp_bytes()); | ||
self | ||
} | ||
|
||
/// Hash of the private transaction | ||
pub fn hash(&self) -> H256 { | ||
keccak(&*self.rlp_bytes()) | ||
self.hash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe just |
||
} | ||
|
||
/// Address of the contract | ||
pub fn contract(&self) -> Address { | ||
self.contract | ||
} | ||
|
||
/// Encrypted data | ||
pub fn encrypted(&self) -> Bytes { | ||
self.encrypted.clone() | ||
} | ||
} | ||
|
||
|
@@ -49,6 +75,8 @@ pub struct SignedPrivateTransaction { | |
r: U256, | ||
/// The S field of the signature | ||
s: U256, | ||
/// Hash | ||
hash: H256, | ||
} | ||
|
||
impl SignedPrivateTransaction { | ||
|
@@ -59,7 +87,13 @@ impl SignedPrivateTransaction { | |
r: sig.r().into(), | ||
s: sig.s().into(), | ||
v: add_chain_replay_protection(sig.v() as u64, chain_id), | ||
} | ||
hash: 0.into(), | ||
}.compute_hash() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please get rid of the |
||
} | ||
|
||
fn compute_hash(mut self) -> SignedPrivateTransaction { | ||
self.hash = keccak(&*self.rlp_bytes()); | ||
self | ||
} | ||
|
||
pub fn standard_v(&self) -> u8 { check_replay_protection(self.v) } | ||
|
@@ -73,4 +107,9 @@ impl SignedPrivateTransaction { | |
pub fn private_transaction_hash(&self) -> H256 { | ||
self.private_transaction_hash | ||
} | ||
|
||
/// Own hash | ||
pub fn hash(&self) -> H256 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't understand this comment :-( |
||
self.hash | ||
} | ||
} |
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.
That's not really a good choice for an API. Both
encrypted
andcontract
arepub
so you can easily change parameters while the hash will stay cached and will be just pure wrong. It's going to be really error prone.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 actually like the idea that hash is cached in this way. We just need to make sure that this structure is never
mut
. Unfortunately rust does not allow us to enforce immutability of struct instances.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 agree with @tomusdrw Hashing was incorrectly added into API.
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.
Reworked