Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
[json-spec] make blake2 pricing spec more readable (#11034)
Browse files Browse the repository at this point in the history
* [json-spec] make blake2 pricing spec more readable

* [ethcore] fix compilation
  • Loading branch information
ordian authored Sep 10, 2019
1 parent d8d7abc commit feb87c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions ethcore/builtin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ impl Builtin {
impl From<ethjson::spec::Builtin> for Builtin {
fn from(b: ethjson::spec::Builtin) -> Self {
let pricer: Box<dyn Pricer> = match b.pricing {
ethjson::spec::Pricing::Blake2F(cost_per_round) => {
Box::new(cost_per_round)
ethjson::spec::Pricing::Blake2F { gas_per_round } => {
Box::new(gas_per_round)
},
ethjson::spec::Pricing::Linear(linear) => {
Box::new(Linear {
Expand Down
11 changes: 6 additions & 5 deletions json/src/spec/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

use uint::Uint;

/// Price per round of Blake2 compression.
pub type Blake2F = u64;

/// Linear pricing.
#[derive(Debug, PartialEq, Deserialize, Clone)]
Expand Down Expand Up @@ -69,7 +67,10 @@ pub struct AltBn128Pairing {
#[serde(rename_all = "snake_case")]
pub enum Pricing {
/// Pricing for Blake2 compression function: each call costs the same amount per round.
Blake2F(Blake2F),
Blake2F {
/// Price per round of Blake2 compression function.
gas_per_round: u64,
},
/// Linear pricing.
Linear(Linear),
/// Pricing for modular exponentiation.
Expand Down Expand Up @@ -117,11 +118,11 @@ mod tests {
let s = r#"{
"name": "blake2_f",
"activate_at": "0xffffff",
"pricing": { "blake2_f": 123 }
"pricing": { "blake2_f": { "gas_per_round": 123 } }
}"#;
let deserialized: Builtin = serde_json::from_str(s).unwrap();
assert_eq!(deserialized.name, "blake2_f");
assert_eq!(deserialized.pricing, Pricing::Blake2F(123));
assert_eq!(deserialized.pricing, Pricing::Blake2F { gas_per_round: 123 });
assert!(deserialized.activate_at.is_some());
}

Expand Down

0 comments on commit feb87c9

Please sign in to comment.