Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Proof.block_hash serde rename as proposal_hash #1618

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions devtools/axon-tools/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ pub fn verify_proof(
}
.rlp_bytes();

if keccak_256(&raw_proposal) != proof.block_hash.0 {
if keccak_256(&raw_proposal) != proof.proposal_hash.0 {
return Err(Error::InvalidProofBlockHash);
}

let vote = Vote {
height: proof.number,
round: proof.round,
vote_type: 2u8,
block_hash: Bytes::from(proof.block_hash.0.to_vec()),
height: proof.number,
round: proof.round,
vote_type: 2u8,
proposal_hash: Bytes::from(proof.proposal_hash.0.to_vec()),
};

let hash_vote = keccak_256(rlp::encode(&vote).as_ref());
Expand Down
2 changes: 1 addition & 1 deletion devtools/axon-tools/src/rlp_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Encodable for Vote {
.append(&self.height)
.append(&self.round)
.append(&vote_type)
.append(&self.block_hash.to_vec());
.append(&self.proposal_hash.to_vec());
}
}

Expand Down
2 changes: 1 addition & 1 deletion devtools/axon-tools/src/tests/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"proof": {
"number": "0xe7c2",
"round": "0x0",
"block_hash": "0x734f6e28a7caf9df326c21d8c57b89034ed02f782a11d04d18284b7aa4de43f0",
"proposal_hash": "0x734f6e28a7caf9df326c21d8c57b89034ed02f782a11d04d18284b7aa4de43f0",
"signature": "0x933be0cd674477473bd68a55a53511a652fbcecfa4cafaa244d0b55ca3f6a7f296d50a2744337365fd6407d737cc389f054b70b3c82ee27a1669a43cc344ba7ad42a7cc663faa63190a739dc1c6a1a5d80d45f5903f42d118fc5e4d695cc4815",
"bitmap": "0xb0"
},
Expand Down
2 changes: 1 addition & 1 deletion devtools/axon-tools/src/tests/proof.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"number": "0xe7c3",
"round": "0x0",
"block_hash": "0x6e48fa2d2002453abd9b51e4ac0342abb1f027b8272d6e27ce79a630b3f26673",
"proposal_hash": "0x6e48fa2d2002453abd9b51e4ac0342abb1f027b8272d6e27ce79a630b3f26673",
"signature": "0xb3e8e27db04baec18c04bc0b8ffe7fdbf2b5f7d6ef243c8be02bfd75defee32f1c0ff73a9fa67fee24630d2da5aa70f111ba41c0212be5d91b95f3bb84e5c0406b4742cca8c8f8362c07024fd8081d16875b01f43c6aa11c60b196af8c671a9b",
"bitmap": "0x70"
}
10 changes: 5 additions & 5 deletions devtools/axon-tools/src/tests/verify_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ fn test_proposal() {
extra_data: Vec::new(),
base_fee_per_gas: U256::from(7),
proof: Proof {
number: 0,
round: 1,
block_hash: H256::from([1u8; 32]),
signature: Bytes::from("1234"),
bitmap: Bytes::from("abcd"),
number: 0,
round: 1,
proposal_hash: H256::from([1u8; 32]),
signature: Bytes::from("1234"),
bitmap: Bytes::from("abcd"),
},
chain_id: 1000,
call_system_script_count: 1,
Expand Down
53 changes: 32 additions & 21 deletions devtools/axon-tools/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,32 +301,36 @@ pub struct Proof {
deserialize_with = "decode::deserialize_hex_u64"
)
)]
pub number: u64,
pub number: u64,

#[cfg_attr(
all(feature = "impl-serde", feature = "std"),
serde(
serialize_with = "encode::serialize_uint",
deserialize_with = "decode::deserialize_hex_u64"
)
)]
pub round: u64,
pub block_hash: Hash,
pub round: u64,

pub proposal_hash: Hash,

#[cfg_attr(
all(feature = "impl-serde", feature = "std"),
serde(
serialize_with = "faster_hex::withpfx_lowercase::serialize",
deserialize_with = "faster_hex::withpfx_lowercase::deserialize"
)
)]
pub signature: Bytes,
pub signature: Bytes,

#[cfg_attr(
all(feature = "impl-serde", feature = "std"),
serde(
serialize_with = "faster_hex::withpfx_lowercase::serialize",
deserialize_with = "faster_hex::withpfx_lowercase::deserialize"
)
)]
pub bitmap: Bytes,
pub bitmap: Bytes,
}

#[cfg(feature = "proof")]
Expand Down Expand Up @@ -360,21 +364,21 @@ impl core::cmp::Ord for Validator {
#[cfg_attr(doc_cfg, doc(cfg(feature = "proof")))]
#[cfg_attr(feature = "impl-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Vote {
pub height: u64,
pub round: u64,
pub vote_type: u8,
pub block_hash: Bytes,
pub height: u64,
pub round: u64,
pub vote_type: u8,
pub proposal_hash: Bytes,
}

#[cfg(test)]
#[cfg(feature = "proof")]
impl Vote {
fn random() -> Self {
Self {
height: rand::random(),
round: rand::random(),
vote_type: 2,
block_hash: tests::random_bytes(32),
height: rand::random(),
round: rand::random(),
vote_type: 2,
proposal_hash: tests::random_bytes(32),
}
}
}
Expand Down Expand Up @@ -445,42 +449,49 @@ pub struct ConsensusConfig {
all(feature = "impl-serde", feature = "std"),
serde(deserialize_with = "decode::deserialize_hex_u64")
)]
pub gas_limit: u64,
pub gas_limit: u64,

#[cfg_attr(
all(feature = "impl-serde", feature = "std"),
serde(deserialize_with = "decode::deserialize_hex_u64")
)]
pub interval: u64,
pub interval: u64,

#[cfg_attr(
all(feature = "impl-serde", feature = "std"),
serde(deserialize_with = "decode::deserialize_hex_u64")
)]
pub propose_ratio: u64,
pub propose_ratio: u64,

#[cfg_attr(
all(feature = "impl-serde", feature = "std"),
serde(deserialize_with = "decode::deserialize_hex_u64")
)]
pub prevote_ratio: u64,
pub prevote_ratio: u64,

#[cfg_attr(
all(feature = "impl-serde", feature = "std"),
serde(deserialize_with = "decode::deserialize_hex_u64")
)]
pub precommit_ratio: u64,

#[cfg_attr(
all(feature = "impl-serde", feature = "std"),
serde(deserialize_with = "decode::deserialize_hex_u64")
)]
pub brake_ratio: u64,
pub brake_ratio: u64,

#[cfg_attr(
all(feature = "impl-serde", feature = "std"),
serde(deserialize_with = "decode::deserialize_hex_u64")
)]
pub tx_num_limit: u64,
pub tx_num_limit: u64,

#[cfg_attr(
all(feature = "impl-serde", feature = "std"),
serde(deserialize_with = "decode::deserialize_hex_u64")
)]
pub max_tx_size: u64,
pub max_tx_size: u64,
}

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -733,6 +744,6 @@ mod tests {
let decoded: overlord::types::Vote = rlp::decode(&raw).unwrap();
assert_eq!(vote.height, decoded.height);
assert_eq!(vote.round, decoded.round);
assert_eq!(vote.block_hash, decoded.block_hash);
assert_eq!(vote.proposal_hash, decoded.block_hash);
}
}
1 change: 1 addition & 0 deletions protocol/src/types/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ pub struct Proof {
pub number: u64,
#[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_uint"))]
pub round: u64,
#[serde(rename = "proposal_hash")]
pub block_hash: Hash,
#[cfg_attr(
feature = "hex-serialize",
Expand Down