openethereum/json/src/spec/authority_round.rs

110 lines
3.9 KiB
Rust
Raw Normal View History

// Copyright 2015-2018 Parity Technologies (UK) Ltd.
2016-09-08 12:28:59 +02:00
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Authority params deserialization.
use ethereum_types::Address;
2016-09-08 12:28:59 +02:00
use uint::Uint;
use super::ValidatorSet;
2016-09-08 12:28:59 +02:00
/// Authority params deserialization.
#[derive(Debug, PartialEq, Deserialize)]
pub struct AuthorityRoundParams {
/// Block duration, in seconds.
2016-09-08 12:28:59 +02:00
#[serde(rename="stepDuration")]
pub step_duration: Uint,
/// Valid authorities
pub validators: ValidatorSet,
2016-12-06 19:23:15 +01:00
/// Starting step. Determined automatically if not specified.
/// To be used for testing only.
#[serde(rename="startStep")]
pub start_step: Option<Uint>,
/// Block at which score validation should start.
#[serde(rename="validateScoreTransition")]
pub validate_score_transition: Option<Uint>,
/// Block from which monotonic steps start.
#[serde(rename="validateStepTransition")]
pub validate_step_transition: Option<Uint>,
/// Whether transitions should be immediate.
#[serde(rename="immediateTransitions")]
pub immediate_transitions: Option<bool>,
/// Reward per block in wei.
#[serde(rename="blockReward")]
pub block_reward: Option<Uint>,
/// Block at which the block reward contract should start being used.
#[serde(rename="blockRewardContractTransition")]
pub block_reward_contract_transition: Option<Uint>,
/// Block reward contract address (setting the block reward contract
/// overrides the static block reward definition).
#[serde(rename="blockRewardContractAddress")]
pub block_reward_contract_address: Option<Address>,
/// Block at which maximum uncle count should be considered.
#[serde(rename="maximumUncleCountTransition")]
pub maximum_uncle_count_transition: Option<Uint>,
/// Maximum number of accepted uncles.
2017-11-10 00:56:02 +01:00
#[serde(rename="maximumUncleCount")]
pub maximum_uncle_count: Option<Uint>,
Aura: Broadcast empty step messages instead of creating empty blocks (#7605) * aura: broadcast empty step message instead of sealing empty block * aura: add empty_step messages to seal * aura: include parent_hash in empty step message * aura: verify received empty step messages * aura: verify empty step messages in block * aura: fix dead lock on empty_steps * aura: fix EmptyStep Encodable * aura: take number of empty steps into account in chain score * aura: use empty step signers for finality * aura: add empty "empty step" messages to seal when reading from spec * aura: fix EmptyStep rlp encoding * aura: use Vec<u8> instead of Bytes * aura: fix block empty step verification * Update .gitlab-ci.yml fix lint * aura: fix accumulation of empty step signatures for finality * aura: include empty steps in seal signature * aura: configurable max number of empty steps * engine: pass block header to seal_fields method This is necessary to make the number of seal fields dynamic, e.g. activating a transition on a certain block number that changes the seal. * aura: add transition to enable empty step messages * aura: clear old empty step messages on verify_block_external * aura: ignore empty step messages from the future * aura: report skipped primaries when empty steps are not enabled * aura: fix tests * aura: report misbehavior * aura: add tests for rolling finality with multiple signatures * engine: fix validator set test In this test the block validation wasn't failing because the block was in the future (expected failure) but was instead failing because the author of the block isn't the expected authority. Since we added reporting of blocks produced by the wrong authority this test started failing. * aura: reward all the authors of empty step messages * aura: fix reward attribution for new blocks * aura: add tests for empty steps broadcasting and inclusion in blocks * aura: reduce size of empty step messages in seal * aura: add test for empty step inclusion in blocks * aura: add test for rewarding of empty steps * aura: add test for empty steps validation * aura: fix rlp encoding of sealed empty step * aura: fix grumbles
2018-02-15 01:39:29 +01:00
/// Block at which empty step messages should start.
#[serde(rename="emptyStepsTransition")]
pub empty_steps_transition: Option<Uint>,
/// Maximum number of accepted empty steps.
#[serde(rename="maximumEmptySteps")]
pub maximum_empty_steps: Option<Uint>,
2016-09-08 12:28:59 +02:00
}
/// Authority engine deserialization.
#[derive(Debug, PartialEq, Deserialize)]
pub struct AuthorityRound {
/// Ethash params.
pub params: AuthorityRoundParams,
}
#[cfg(test)]
mod tests {
use ethereum_types::{U256, H160};
use uint::Uint;
2016-09-08 12:28:59 +02:00
use serde_json;
use hash::Address;
use spec::validator_set::ValidatorSet;
2016-09-08 16:27:54 +02:00
use spec::authority_round::AuthorityRound;
2016-09-08 12:28:59 +02:00
#[test]
fn authority_round_deserialization() {
2016-09-08 12:28:59 +02:00
let s = r#"{
"params": {
"stepDuration": "0x02",
"validators": {
"list" : ["0xc6d9d2cd449a754c494264e1809c50e34d64562b"]
},
"startStep" : 24,
"validateStepTransition": 150,
"blockReward": 5000000,
"maximumUncleCountTransition": 10000000,
"maximumUncleCount": 5
2016-09-08 12:28:59 +02:00
}
}"#;
let deserialized: AuthorityRound = serde_json::from_str(s).unwrap();
assert_eq!(deserialized.params.step_duration, Uint(U256::from(0x02)));
assert_eq!(deserialized.params.validators, ValidatorSet::List(vec![Address(H160::from("0xc6d9d2cd449a754c494264e1809c50e34d64562b"))]));
assert_eq!(deserialized.params.start_step, Some(Uint(U256::from(24))));
assert_eq!(deserialized.params.immediate_transitions, None);
assert_eq!(deserialized.params.maximum_uncle_count_transition, Some(Uint(10_000_000.into())));
assert_eq!(deserialized.params.maximum_uncle_count, Some(Uint(5.into())));
2016-09-08 12:28:59 +02:00
}
}