Skip to content

Commit

Permalink
first working version with ACKS and PARTS from the spec file
Browse files Browse the repository at this point in the history
  • Loading branch information
SurfingNerd committed Feb 7, 2024
1 parent 8c84383 commit 2698fb7
Showing 1 changed file with 61 additions and 7 deletions.
68 changes: 61 additions & 7 deletions crates/ethjson/src/spec/hbbft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//! Hbbft parameter deserialization.
use ethereum_types::Address;
use serde_with::serde_as;

/// Skip block reward parameter.
/// Defines one (potential open) range about skips
Expand All @@ -32,21 +33,23 @@ pub struct HbbftParamsSkipBlockReward {
pub to_block: Option<u64>,
}

#[serde_as]
#[derive(Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub struct HbbftNetworkForks {


}

pub struct HbbftNetworkFork {
/// Block number at which the fork starts.
pub block_number_start: u64,
/// Validator set at the fork.
pub validator_set: Vec<Address>,
pub validators: Vec<Address>,
#[serde_as(as = "serde_with::hex::Hex")]
pub parts: Vec<u8>,
#[serde_as(as = "serde_with::hex::Hex")]
pub acks: Vec<u8>,
}


/// Hbbft parameters.
#[derive(Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
Expand Down Expand Up @@ -74,7 +77,8 @@ pub struct HbbftParams {
/// This validator set is becomming pending so it can write it's PARTs and ACKS.
/// From beginning of the fork trigger block until the finality of the key gen transactions,
/// no block verifications are done.
pub forks: HbbftNetworkForks,
#[serde(default)]
pub forks: Vec<HbbftNetworkFork>,
}

/// Hbbft engine config.
Expand Down Expand Up @@ -113,6 +117,56 @@ mod tests {
use ethereum_types::Address;
use std::str::FromStr;

#[test]
fn hbbft_deserialization_forks() {
// let s = r#"{
// "params": {
// "forks": {
// {
// "blockNumberStart" : 777,
// "validators": [
// "0xfe163fc225f3863cef09f1f68ead173f30300d13"
// ],
// "parts": [
// "0x19585436b7d97298a751e2a6020c30677497772013001420c0a6aea5790347bdf5531c1387be685a232b01ec614913b18da0a6cbcd1074f1733f902a7eb656e9"
// ],
// "acks": [
// "0x19585436b7d97298a751e2a6020c30677497772013001420c0a6aea5790347bdf5531c1387be685a232b01ec614913b18da0a6cbcd1074f1733f902a7eb656e9"
// ]
// }
// }
// }
// }"#;

let s = r#"{
"params": {
"minimumBlockTime": 0,
"maximumBlockTime": 600,
"transactionQueueSizeTrigger": 1,
"isUnitTest": true,
"blockRewardContractAddress": "0x2000000000000000000000000000000000000002",
"forks": [
{
"blockNumberStart" : 777,
"validators": [
"0xfe163fc225f3863cef09f1f68ead173f30300d13"
],
"parts": "19585436b7d97298a751e2a6020c30677497772013001420c0a6aea5790347bdf5531c1387be685a232b01ec614913b18da0a6cbcd1074f1733f902a7eb656e9",
"acks": "19585436b7d97298a751e2a6020c30677497772013001420c0a6aea5790347bdf5531c1387be685a232b01ec614913b18da0a6cbcd1074f1733f902a7eb656e9"
}
]
}
}"#;

let deserialized: Hbbft = serde_json::from_str(s).unwrap();
assert_eq!(deserialized.params.forks.len() , 1);
assert_eq!(deserialized.params.forks.get(0).expect("").block_number_start , 777);
assert_eq!(deserialized.params.forks.get(0).expect("").parts.len() , 64);
assert_eq!(deserialized.params.forks.get(0).expect("").acks.len() , 64);


}

#[test]
fn hbbft_deserialization() {
let s = r#"{
Expand Down

0 comments on commit 2698fb7

Please sign in to comment.