From 71f9b66e0818905b5e96fb1afc5643c338b659c8 Mon Sep 17 00:00:00 2001 From: DragonMural Date: Sat, 1 Aug 2020 00:19:29 -0400 Subject: [PATCH 01/15] Initial Import --- Cargo.lock | 18 ++++++ Cargo.toml | 2 + utils/math/Cargo.toml | 11 ++++ utils/math/src/lib.rs | 43 +++++++++++++ utils/smoothing/Cargo.toml | 15 +++++ utils/smoothing/src/alpha_beta_filter.rs | 67 ++++++++++++++++++++ utils/smoothing/src/constants.rs | 69 +++++++++++++++++++++ utils/smoothing/src/lib.rs | 79 ++++++++++++++++++++++++ 8 files changed, 304 insertions(+) create mode 100644 utils/math/Cargo.toml create mode 100644 utils/math/src/lib.rs create mode 100644 utils/smoothing/Cargo.toml create mode 100644 utils/smoothing/src/alpha_beta_filter.rs create mode 100644 utils/smoothing/src/constants.rs create mode 100644 utils/smoothing/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index b1a0520a4c17..d775b3d77a00 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2525,6 +2525,13 @@ dependencies = [ "utils", ] +[[package]] +name = "forest_math" +version = "0.1.0" +dependencies = [ + "forest_bigint", +] + [[package]] name = "forest_message" version = "0.3.0" @@ -2543,6 +2550,17 @@ dependencies = [ "serde_json", ] +[[package]] +name = "forest_smoothing" +version = "0.1.0" +dependencies = [ + "clock", + "forest_bigint", + "forest_math", + "lazy_static", + "num-traits 0.2.12", +] + [[package]] name = "forest_vm" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 905b5acd9776..44b125df8b5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,8 @@ members = [ "utils/test_utils", "utils/commcid", "utils/json_utils", + "utils/smoothing", + "utils/math", "types", "key_management", ] diff --git a/utils/math/Cargo.toml b/utils/math/Cargo.toml new file mode 100644 index 000000000000..f13d6daa5390 --- /dev/null +++ b/utils/math/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "forest_math" +version = "0.1.0" +authors = ["ChainSafe Systems "] +edition = "2018" + +[dependencies] +num-bigint = { path = "../../utils/bigint", package = "forest_bigint" } + + +[dev-dependencies] diff --git a/utils/math/src/lib.rs b/utils/math/src/lib.rs new file mode 100644 index 000000000000..f376ede3f333 --- /dev/null +++ b/utils/math/src/lib.rs @@ -0,0 +1,43 @@ + +use std::error:: Error; + + + + + +use num_bigint::{ + biguint_ser::{BigUintDe, BigUintSer}, + BigInt, BigUint, +}; + +pub const PRECISION : u64 = 128; + +pub fn poly_val(poly : &[BigInt], x : &BigInt ) -> BigInt { + + let mut res = BigInt::default(); + + for coeff in poly { + let temp = &res * x; + res = (temp >> PRECISION) + coeff; + } + res +} + + +pub fn parse(coefs : &[&str]) -> Result, ()> { + + println!("Num elements is {}", coefs.len()); + + let mut out : Vec = Vec::with_capacity(coefs.len() as usize); + + for (i, coef) in coefs.iter().enumerate() { + let c = BigInt::parse_bytes(coef.as_bytes() , 10).ok_or(())? ; + out.push(c); + } + Ok(out) +} + + + + + diff --git a/utils/smoothing/Cargo.toml b/utils/smoothing/Cargo.toml new file mode 100644 index 000000000000..c9962a4693c8 --- /dev/null +++ b/utils/smoothing/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "forest_smoothing" +version = "0.1.0" +authors = ["ChainSafe Systems "] +edition = "2018" + +[dependencies] +num-bigint = { path = "../../utils/bigint", package = "forest_bigint" } +clock = { path = "../../node/clock" } +forest_math = {path = "../math"} +lazy_static = "1.4" +num-traits = "0.2" + + +[dev-dependencies] diff --git a/utils/smoothing/src/alpha_beta_filter.rs b/utils/smoothing/src/alpha_beta_filter.rs new file mode 100644 index 000000000000..dc9ab7e6582a --- /dev/null +++ b/utils/smoothing/src/alpha_beta_filter.rs @@ -0,0 +1,67 @@ + +use num_bigint::{ + biguint_ser::{BigUintDe, BigUintSer}, + BigInt, BigUint, +}; +use clock::ChainEpoch; +use forest_math::PRECISION; + + + +#[derive(Default)] +pub struct FilterEstimate { + pub pos : BigInt, + pub velo : BigInt, +} + + + +impl FilterEstimate{ + + pub fn new(pos : BigInt, velo : BigInt) -> Self{ + FilterEstimate{ + pos : pos << PRECISION, + velo : velo << PRECISION, + } + } + + pub fn estimate(&self) -> BigInt { + &self.pos >> PRECISION + } +} + +#[derive(Default)] +pub struct AlphaBetaFilter { + alpha : BigInt, + beta : BigInt, + prev_est : FilterEstimate +} + +impl AlphaBetaFilter { + pub fn load_filter(prev_est : FilterEstimate, alpha : BigInt, beta : BigInt) -> Self{ + AlphaBetaFilter{ + alpha, + beta, + prev_est + } + } + + pub fn next_estimate(&self, obs : BigInt, epoch_delta : ChainEpoch) -> FilterEstimate{ + let delta_t = BigInt::from(epoch_delta) << PRECISION; + let delta_x = (&delta_t * &self.prev_est.velo) >> PRECISION; + let mut pos = delta_x + &self.prev_est.pos; + + let obs = obs << PRECISION; + let residual = obs - &pos; + let revision_x = (&self.alpha * &residual) >> PRECISION; + pos += &revision_x; + + let revision_v = (residual * &self.beta) / delta_t; + let velo = revision_v + &self.prev_est.velo; + FilterEstimate{ + pos, + velo + } + } +} + diff --git a/utils/smoothing/src/constants.rs b/utils/smoothing/src/constants.rs new file mode 100644 index 000000000000..86f8971b13f4 --- /dev/null +++ b/utils/smoothing/src/constants.rs @@ -0,0 +1,69 @@ + +use num_bigint::{ + biguint_ser::{BigUintDe, BigUintSer}, + BigInt, BigUint, +}; +use forest_math::{parse}; + +lazy_static! { + pub static ref NUM: [&'static str ; 7] = [ + "261417938209272870992496419296200268025", + "7266615505142943436908456158054846846897", + "32458783941900493142649393804518050491988", + "17078670566130897220338060387082146864806", + "-35150353308172866634071793531642638290419", + "-20351202052858059355702509232125230498980", + "-1563932590352680681114104005183375350999", + ]; + + pub static ref DENOM: [&'static str ; 7] = [ + "49928077726659937662124949977867279384", + "2508163877009111928787629628566491583994", + "21757751789594546643737445330202599887121", + "53400635271583923415775576342898617051826", + "41248834748603606604000911015235164348839", + "9015227820322455780436733526367238305537", + "340282366920938463463374607431768211456", + ]; + + pub static ref CONST_STRS: [&'static str ; 4] = [ + "314760000000000000000000000000000000", // DefaultAlpha + "96640100000000000000000000000000", // DefaultBeta + "302231454903657293676544", // Epsilon + "235865763225513294137944142764154484399", // ln(2) + ]; + +} + +const DEFAULT_ALPHA : usize = 0; +const DEFAULT_BETA : usize = 1; +const EXTRAPOLATED_CUM_SUM_RATIO_EPSILON : usize = 2; +const LN_2 : usize = 3; + +pub fn get_ln_num_coef() -> Vec { + parse(&NUM[..]).unwrap() +} + +pub fn get_ln_denom_coef() -> Vec { + parse(&DENOM[..]).unwrap() +} + +pub fn get_const_bigs() -> Vec { + parse(&CONST_STRS[..]).unwrap() +} + +pub fn get_ln2() -> BigInt { + BigInt::parse_bytes(CONST_STRS[LN_2].as_bytes(), 10).unwrap() +} + +pub fn get_cum_sum_ratio_epsilon() -> BigInt { + BigInt::parse_bytes(CONST_STRS[EXTRAPOLATED_CUM_SUM_RATIO_EPSILON].as_bytes(), 10).unwrap() +} + +#[test]fn parse_check () { + let _ = get_ln_num_coef(); + let _ = get_ln_denom_coef(); + let _ = get_const_bigs(); + +} + diff --git a/utils/smoothing/src/lib.rs b/utils/smoothing/src/lib.rs new file mode 100644 index 000000000000..7315e43a1648 --- /dev/null +++ b/utils/smoothing/src/lib.rs @@ -0,0 +1,79 @@ +#[macro_use] +extern crate lazy_static; + +use num_bigint::{ + biguint_ser::{BigUintDe, BigUintSer}, + BigInt, BigUint, +}; + +mod alpha_beta_filter; +mod constants; +pub use alpha_beta_filter::*; +use forest_math::{PRECISION, poly_val}; +use num_traits::sign::Signed; +use constants::*; +use clock::ChainEpoch; + + +fn get_bit_len(z : &BigInt)-> usize { + z.abs().to_radix_le(2).1.len() +} + + +fn extrapolated_cum_sum_of_ratio(delta : ChainEpoch, relative_start : ChainEpoch, est_num : FilterEstimate, est_denom : FilterEstimate) -> BigInt{ + + let delta_t = BigInt::from(delta) << PRECISION; + let t0 = BigInt::from(relative_start) << PRECISION; + + let pos_1 = est_num.pos; + let pos_2 = est_denom.pos; + let velo_1 = est_num.velo; + let velo_2 = est_denom.velo; + + let squared_velo_2 = ( &velo_2 * &velo_2) >> PRECISION; + + if squared_velo_2 >= get_cum_sum_ratio_epsilon() { + let mut x2a = ((&velo_2 * t0) >> PRECISION) + &pos_2; + let mut x2b = ((&velo_2 * &delta_t) >> PRECISION) + &x2a; + x2a = ln(&x2a); + x2b = ln(&x2b); + + let m1 = ((&x2b - &x2a) * pos_1 * &velo_2) >> PRECISION; + + let m2_l = (&x2a - &x2b) * &pos_2; + let m2_r = velo_2 * &delta_t; + let m2 = ((m2_l + m2_r) * velo_1) >> PRECISION; + + return (m2 + m1) / squared_velo_2; + } + + let half_delta = &delta_t >> 1; + let mut x1m = velo_1 * (t0 + half_delta); + x1m = (x1m >> PRECISION) + pos_1; + + (x1m * delta_t) / pos_2 +} + + + + + +fn ln (z : &BigInt) -> BigInt { + let k : i64 = get_bit_len(z) as i64 - 1 - PRECISION as i64; + + let x : BigInt = if k > 0 { + z >> k + }else { + z << -1*k + }; + + BigInt::from(k) * get_ln2() + ln_between_one_and_two(x) +} + +fn ln_between_one_and_two(x : BigInt) -> BigInt { + let num = poly_val( &get_ln_num_coef() , &x) << PRECISION; + let denom = poly_val( &get_ln_denom_coef() , &x); + num / denom +} + + From 55514a7bda4987d2a44b2c77d41a962b8660c5e9 Mon Sep 17 00:00:00 2001 From: DragonMural Date: Sun, 2 Aug 2020 13:30:41 -0400 Subject: [PATCH 02/15] Added tests and CBOR --- Cargo.lock | 4 ++ utils/math/src/lib.rs | 35 ++++------- utils/smoothing/Cargo.toml | 4 ++ utils/smoothing/src/alpha_beta_filter.rs | 64 ++++++++++---------- utils/smoothing/src/constants.rs | 65 ++++++++++---------- utils/smoothing/src/lib.rs | 76 ++++++++++++------------ vm/actor/src/builtin/mod.rs | 1 + 7 files changed, 121 insertions(+), 128 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d775b3d77a00..55eed86a5d84 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2554,11 +2554,15 @@ dependencies = [ name = "forest_smoothing" version = "0.1.0" dependencies = [ + "actor", "clock", + "fil_types", "forest_bigint", + "forest_encoding", "forest_math", "lazy_static", "num-traits 0.2.12", + "serde", ] [[package]] diff --git a/utils/math/src/lib.rs b/utils/math/src/lib.rs index f376ede3f333..aec41926bd7d 100644 --- a/utils/math/src/lib.rs +++ b/utils/math/src/lib.rs @@ -1,43 +1,28 @@ +// Copyright 2020 ChainSafe Systems +// SPDX-License-Identifier: Apache-2.0, MIT -use std::error:: Error; +use num_bigint::BigInt; +pub const PRECISION: u64 = 128; - - - -use num_bigint::{ - biguint_ser::{BigUintDe, BigUintSer}, - BigInt, BigUint, -}; - -pub const PRECISION : u64 = 128; - -pub fn poly_val(poly : &[BigInt], x : &BigInt ) -> BigInt { - +pub fn poly_val(poly: &[BigInt], x: &BigInt) -> BigInt { let mut res = BigInt::default(); for coeff in poly { - let temp = &res * x; + let temp = &res * x; res = (temp >> PRECISION) + coeff; } res } - -pub fn parse(coefs : &[&str]) -> Result, ()> { - +pub fn parse(coefs: &[&str]) -> Result, ()> { println!("Num elements is {}", coefs.len()); - let mut out : Vec = Vec::with_capacity(coefs.len() as usize); + let mut out: Vec = Vec::with_capacity(coefs.len() as usize); - for (i, coef) in coefs.iter().enumerate() { - let c = BigInt::parse_bytes(coef.as_bytes() , 10).ok_or(())? ; + for coef in coefs { + let c = BigInt::parse_bytes(coef.as_bytes(), 10).ok_or(())?; out.push(c); } Ok(out) } - - - - - diff --git a/utils/smoothing/Cargo.toml b/utils/smoothing/Cargo.toml index c9962a4693c8..21a3443f5aca 100644 --- a/utils/smoothing/Cargo.toml +++ b/utils/smoothing/Cargo.toml @@ -10,6 +10,10 @@ clock = { path = "../../node/clock" } forest_math = {path = "../math"} lazy_static = "1.4" num-traits = "0.2" +actor = {path = "../../vm/actor", package = "actor"} +fil_types = { path = "../../types" } +encoding = { package = "forest_encoding", path = "../../encoding" } +serde = { version = "1.0", features = ["derive"] } [dev-dependencies] diff --git a/utils/smoothing/src/alpha_beta_filter.rs b/utils/smoothing/src/alpha_beta_filter.rs index dc9ab7e6582a..9c8d2157249a 100644 --- a/utils/smoothing/src/alpha_beta_filter.rs +++ b/utils/smoothing/src/alpha_beta_filter.rs @@ -1,67 +1,69 @@ +// Copyright 2020 ChainSafe Systems +// SPDX-License-Identifier: Apache-2.0, MIT -use num_bigint::{ - biguint_ser::{BigUintDe, BigUintSer}, - BigInt, BigUint, -}; use clock::ChainEpoch; +use encoding::Cbor; use forest_math::PRECISION; +use num_bigint::{bigint_ser, BigInt}; +use serde::{Deserialize, Serialize}; - - -#[derive(Default)] +#[derive(Default, Serialize, Deserialize)] pub struct FilterEstimate { - pub pos : BigInt, - pub velo : BigInt, + #[serde(with = "bigint_ser")] + pub pos: BigInt, + #[serde(with = "bigint_ser")] + pub velo: BigInt, } - - -impl FilterEstimate{ - - pub fn new(pos : BigInt, velo : BigInt) -> Self{ - FilterEstimate{ - pos : pos << PRECISION, - velo : velo << PRECISION, +impl FilterEstimate { + pub fn new(pos: BigInt, velo: BigInt) -> Self { + FilterEstimate { + pos: pos << PRECISION, + velo: velo << PRECISION, } } pub fn estimate(&self) -> BigInt { &self.pos >> PRECISION } + + pub fn extrapolate(&self, delta: ChainEpoch) -> BigInt { + let delta_t = BigInt::from(delta) << PRECISION; + let pos = &self.pos << PRECISION; + (&self.velo * delta_t) + pos + } } +impl Cbor for FilterEstimate {} + #[derive(Default)] pub struct AlphaBetaFilter { - alpha : BigInt, - beta : BigInt, - prev_est : FilterEstimate + alpha: BigInt, + beta: BigInt, + prev_est: FilterEstimate, } impl AlphaBetaFilter { - pub fn load_filter(prev_est : FilterEstimate, alpha : BigInt, beta : BigInt) -> Self{ - AlphaBetaFilter{ + pub fn load_filter(prev_est: FilterEstimate, alpha: BigInt, beta: BigInt) -> Self { + AlphaBetaFilter { alpha, beta, - prev_est + prev_est, } } - pub fn next_estimate(&self, obs : BigInt, epoch_delta : ChainEpoch) -> FilterEstimate{ + pub fn next_estimate(&self, obs: BigInt, epoch_delta: ChainEpoch) -> FilterEstimate { let delta_t = BigInt::from(epoch_delta) << PRECISION; let delta_x = (&delta_t * &self.prev_est.velo) >> PRECISION; let mut pos = delta_x + &self.prev_est.pos; - let obs = obs << PRECISION; + let obs = obs << PRECISION; let residual = obs - &pos; let revision_x = (&self.alpha * &residual) >> PRECISION; - pos += &revision_x; + pos += &revision_x; let revision_v = (residual * &self.beta) / delta_t; let velo = revision_v + &self.prev_est.velo; - FilterEstimate{ - pos, - velo - } + FilterEstimate { pos, velo } } } - diff --git a/utils/smoothing/src/constants.rs b/utils/smoothing/src/constants.rs index 86f8971b13f4..967c4d64ba1d 100644 --- a/utils/smoothing/src/constants.rs +++ b/utils/smoothing/src/constants.rs @@ -1,44 +1,41 @@ +// Copyright 2020 ChainSafe Systems +// SPDX-License-Identifier: Apache-2.0, MIT -use num_bigint::{ - biguint_ser::{BigUintDe, BigUintSer}, - BigInt, BigUint, -}; -use forest_math::{parse}; +use forest_math::parse; +use num_bigint::BigInt; lazy_static! { pub static ref NUM: [&'static str ; 7] = [ "261417938209272870992496419296200268025", - "7266615505142943436908456158054846846897", - "32458783941900493142649393804518050491988", - "17078670566130897220338060387082146864806", - "-35150353308172866634071793531642638290419", - "-20351202052858059355702509232125230498980", - "-1563932590352680681114104005183375350999", + "7266615505142943436908456158054846846897", + "32458783941900493142649393804518050491988", + "17078670566130897220338060387082146864806", + "-35150353308172866634071793531642638290419", + "-20351202052858059355702509232125230498980", + "-1563932590352680681114104005183375350999", ]; pub static ref DENOM: [&'static str ; 7] = [ - "49928077726659937662124949977867279384", - "2508163877009111928787629628566491583994", - "21757751789594546643737445330202599887121", - "53400635271583923415775576342898617051826", - "41248834748603606604000911015235164348839", - "9015227820322455780436733526367238305537", - "340282366920938463463374607431768211456", + "49928077726659937662124949977867279384", + "2508163877009111928787629628566491583994", + "21757751789594546643737445330202599887121", + "53400635271583923415775576342898617051826", + "41248834748603606604000911015235164348839", + "9015227820322455780436733526367238305537", + "340282366920938463463374607431768211456", ]; pub static ref CONST_STRS: [&'static str ; 4] = [ - "314760000000000000000000000000000000", // DefaultAlpha - "96640100000000000000000000000000", // DefaultBeta - "302231454903657293676544", // Epsilon - "235865763225513294137944142764154484399", // ln(2) + "314760000000000000000000000000000000", // DefaultAlpha + "96640100000000000000000000000000", // DefaultBeta + "302231454903657293676544", // Epsilon + "235865763225513294137944142764154484399", // ln(2) ]; } -const DEFAULT_ALPHA : usize = 0; -const DEFAULT_BETA : usize = 1; -const EXTRAPOLATED_CUM_SUM_RATIO_EPSILON : usize = 2; -const LN_2 : usize = 3; +const EXTRAPOLATED_CUM_SUM_RATIO_EPSILON: usize = 2; +const LN_2: usize = 3; pub fn get_ln_num_coef() -> Vec { parse(&NUM[..]).unwrap() @@ -48,22 +45,20 @@ pub fn get_ln_denom_coef() -> Vec { parse(&DENOM[..]).unwrap() } -pub fn get_const_bigs() -> Vec { - parse(&CONST_STRS[..]).unwrap() -} - pub fn get_ln2() -> BigInt { BigInt::parse_bytes(CONST_STRS[LN_2].as_bytes(), 10).unwrap() } pub fn get_cum_sum_ratio_epsilon() -> BigInt { - BigInt::parse_bytes(CONST_STRS[EXTRAPOLATED_CUM_SUM_RATIO_EPSILON].as_bytes(), 10).unwrap() + BigInt::parse_bytes( + CONST_STRS[EXTRAPOLATED_CUM_SUM_RATIO_EPSILON].as_bytes(), + 10, + ) + .unwrap() } -#[test]fn parse_check () { +#[test] +fn parse_check() { let _ = get_ln_num_coef(); let _ = get_ln_denom_coef(); - let _ = get_const_bigs(); - } - diff --git a/utils/smoothing/src/lib.rs b/utils/smoothing/src/lib.rs index 7315e43a1648..aca71e7e197d 100644 --- a/utils/smoothing/src/lib.rs +++ b/utils/smoothing/src/lib.rs @@ -1,79 +1,81 @@ +// Copyright 2020 ChainSafe Systems +// SPDX-License-Identifier: Apache-2.0, MIT + #[macro_use] extern crate lazy_static; -use num_bigint::{ - biguint_ser::{BigUintDe, BigUintSer}, - BigInt, BigUint, -}; +use num_bigint::BigInt; mod alpha_beta_filter; mod constants; pub use alpha_beta_filter::*; -use forest_math::{PRECISION, poly_val}; -use num_traits::sign::Signed; -use constants::*; use clock::ChainEpoch; +use constants::*; +use forest_math::{poly_val, PRECISION}; +use num_traits::sign::Signed; - -fn get_bit_len(z : &BigInt)-> usize { +fn get_bit_len(z: &BigInt) -> usize { z.abs().to_radix_le(2).1.len() } - -fn extrapolated_cum_sum_of_ratio(delta : ChainEpoch, relative_start : ChainEpoch, est_num : FilterEstimate, est_denom : FilterEstimate) -> BigInt{ - +pub fn extrapolated_cum_sum_of_ratio( + delta: ChainEpoch, + relative_start: ChainEpoch, + est_num: &FilterEstimate, + est_denom: &FilterEstimate, +) -> BigInt { let delta_t = BigInt::from(delta) << PRECISION; let t0 = BigInt::from(relative_start) << PRECISION; - let pos_1 = est_num.pos; - let pos_2 = est_denom.pos; - let velo_1 = est_num.velo; - let velo_2 = est_denom.velo; + let pos_1 = &est_num.pos; + let pos_2 = &est_denom.pos; + let velo_1 = &est_num.velo; + let velo_2 = &est_denom.velo; - let squared_velo_2 = ( &velo_2 * &velo_2) >> PRECISION; + let squared_velo_2 = (velo_2 * velo_2) >> PRECISION; if squared_velo_2 >= get_cum_sum_ratio_epsilon() { - let mut x2a = ((&velo_2 * t0) >> PRECISION) + &pos_2; - let mut x2b = ((&velo_2 * &delta_t) >> PRECISION) + &x2a; + let mut x2a = ((velo_2 * t0) >> PRECISION) + pos_2; + let mut x2b = ((velo_2 * &delta_t) >> PRECISION) + &x2a; x2a = ln(&x2a); x2b = ln(&x2b); - let m1 = ((&x2b - &x2a) * pos_1 * &velo_2) >> PRECISION; + let m1 = ((&x2b - &x2a) * pos_1 * velo_2) >> PRECISION; - let m2_l = (&x2a - &x2b) * &pos_2; + let m2_l = (&x2a - &x2b) * pos_2; let m2_r = velo_2 * &delta_t; let m2 = ((m2_l + m2_r) * velo_1) >> PRECISION; return (m2 + m1) / squared_velo_2; } - let half_delta = &delta_t >> 1; + let half_delta = &delta_t >> 1; let mut x1m = velo_1 * (t0 + half_delta); x1m = (x1m >> PRECISION) + pos_1; (x1m * delta_t) / pos_2 } +pub fn ln(z: &BigInt) -> BigInt { + let k: i64 = get_bit_len(z) as i64 - 1 - PRECISION as i64; + let x: BigInt = if k > 0 { z >> k } else { z << k.abs() }; - - -fn ln (z : &BigInt) -> BigInt { - let k : i64 = get_bit_len(z) as i64 - 1 - PRECISION as i64; - - let x : BigInt = if k > 0 { - z >> k - }else { - z << -1*k - }; - - BigInt::from(k) * get_ln2() + ln_between_one_and_two(x) + BigInt::from(k) * get_ln2() + ln_between_one_and_two(x) } -fn ln_between_one_and_two(x : BigInt) -> BigInt { - let num = poly_val( &get_ln_num_coef() , &x) << PRECISION; - let denom = poly_val( &get_ln_denom_coef() , &x); +fn ln_between_one_and_two(x: BigInt) -> BigInt { + let num = poly_val(&get_ln_num_coef(), &x) << PRECISION; + let denom = poly_val(&get_ln_denom_coef(), &x); num / denom } +// Returns an estimate with position val and velocity 0 +pub fn testing_constant_estimate(val: BigInt) -> FilterEstimate { + FilterEstimate::new(val, BigInt::from(0u8)) +} +// Returns and estimate with postion x and velocity v +pub fn testing_estimate(x: BigInt, v: BigInt) -> FilterEstimate { + FilterEstimate::new(x, v) +} diff --git a/vm/actor/src/builtin/mod.rs b/vm/actor/src/builtin/mod.rs index 501c69e51a48..8bf26c8a5546 100644 --- a/vm/actor/src/builtin/mod.rs +++ b/vm/actor/src/builtin/mod.rs @@ -20,3 +20,4 @@ pub mod verifreg; pub use self::codes::*; pub(crate) use self::shared::*; pub use self::singletons::*; +pub use network::*; From 841035b595db330ff6f7f8a2fef911fc8f4eb8be Mon Sep 17 00:00:00 2001 From: DragonMural Date: Mon, 3 Aug 2020 10:54:58 -0400 Subject: [PATCH 03/15] Adding test --- .../smoothing/tests/alpha_beta_filter_test.rs | 203 ++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 utils/smoothing/tests/alpha_beta_filter_test.rs diff --git a/utils/smoothing/tests/alpha_beta_filter_test.rs b/utils/smoothing/tests/alpha_beta_filter_test.rs new file mode 100644 index 000000000000..522042bd00fd --- /dev/null +++ b/utils/smoothing/tests/alpha_beta_filter_test.rs @@ -0,0 +1,203 @@ +// Copyright 2020 ChainSafe Systems +// SPDX-License-Identifier: Apache-2.0, MIT + +use forest_math::{parse, PRECISION}; +use forest_smoothing::extrapolated_cum_sum_of_ratio as ecsor; +use forest_smoothing::*; + +use num_bigint::BigInt; + +use actor::EPOCHS_IN_DAY; +use clock::ChainEpoch; +use fil_types::StoragePower; +use num_traits::sign::Signed; + +const ERR_BOUND: u64 = 350; + +// Millionths of difference between val1 and val2 +// (val1 - val2) / val1 * 1e6 +// all inputs Q.128, output Q.0 +fn per_million_error(val_1: &BigInt, val_2: &BigInt) -> BigInt { + let diff = (val_1 - val_2) << PRECISION; + + let ratio = diff / val_1; + let million = BigInt::from(1_000_000) << PRECISION; + + let diff_per_million = (ratio * million).abs(); + + diff_per_million >> 2 * PRECISION +} + +fn iterative_cum_sum_of_ratio( + num: &filterEstimate, + denom: &filterEstimate, + t0: ChainEpoch, + delta: ChainEpoch, +) -> BigInt { + let mut ratio = BigInt::from(0u8); + + for i in 0..delta { + let num_epsilon = num.extrapolate(t0 + i); // Q.256 + let denom_epsilon = denom.extrapolate(t0 + i) >> PRECISION; // Q.256 + let mut epsilon = num_epsilon / denom_epsilon; // Q.256 / Q.128 => Q.128 + + if i != 0 && i != delta - 1 { + epsilon *= 2; // Q.128 * Q.0 => Q.128 + } + ratio += epsilon; + } + + ratio / 2 +} + +fn assert_err_bound( + num: &filterEstimate, + denom: &filterEstimate, + delta: ChainEpoch, + t0: ChainEpoch, + err_bound: BigInt, +) { + let analytic = ecsor(delta, t0, num, denom); + let iterative = iterative_cum_sum_of_ratio(num, denom, t0, delta); + let actual_err = per_million_error(&analytic, &iterative); + assert!( + actual_err < err_bound, + "Values are {} and {}", + actual_err, + err_bound + ); +} + +#[test] +fn test_natural_log() { + let ln_inputs: Vec = parse(&[ + "340282366920938463463374607431768211456", // Q.128 format of 1 + "924990000000000000000000000000000000000", // Q.128 format of e (rounded up in 5th decimal place to handle truncation) + "34028236692093846346337460743176821145600000000000000000000", // Q.128 format of 100e18 + "6805647338418769269267492148635364229120000000000000000000000", // Q.128 format of 2e22 + "204169000000000000000000000000000000", // Q.128 format of 0.0006 + "34028236692093846346337460743", // Q.128 format of 1e-10 + ]) + .unwrap(); + + let expected_ln_outputs: Vec = parse(&[ + "0", // Q.128 format of 0 = ln(1) + "340282366920938463463374607431768211456", // Q.128 format of 1 = ln(e) + "15670582109617661336106769654068947397831", // Q.128 format of 46.051... = ln(100e18) + "17473506083804940763855390762239996622013", // Q.128 format of 51.35... = ln(2e22) + "-2524410000000000000000000000000000000000", // Q.128 format of -7.41.. = ln(0.0006) + "-7835291054808830668053384827034473698915", // Q.128 format of -23.02.. = ln(1e-10) + ]) + .unwrap(); + + assert_eq!(ln_inputs.len(), expected_ln_outputs.len()); + let num_inputs = ln_inputs.len(); + + for i in 0..num_inputs { + let z = &ln_inputs[i]; + let ln_of_z = ln(z); + let expected_z = &expected_ln_outputs[i]; + assert_eq!(expected_z >> PRECISION, ln_of_z >> PRECISION); + } +} + +#[test] +fn constant_estimate() { + let num_estimate = testing_constant_estimate(BigInt::from(4_000_000)); + let denom_estimate = testing_constant_estimate(BigInt::from(1)); + + // 4e6/1 over 1000 epochs should give us 4e9 + let csr_1 = ecsor(1000, 0, &num_estimate, &denom_estimate) >> PRECISION; + assert_eq!(BigInt::from(4 * 10_i64.pow(9)), csr_1); + + // if we change t0 nothing should change because velocity is 0 + let csr_2 = ecsor(1000, 10_i64.pow(15), &num_estimate, &denom_estimate) >> PRECISION; + + assert_eq!(csr_1, csr_2); + + // 1e12 / 200e12 for 100 epochs should give ratio of 1/2 + let num_estimate = testing_constant_estimate(BigInt::from(10_i64.pow(12))); + let denom_estimate = testing_constant_estimate(BigInt::from(200 * 10_i64.pow(12))); + let csr_frac = ecsor(100, 0, &num_estimate, &denom_estimate); + + // If we didn't return Q.128 we'd just get zero + assert_eq!(BigInt::from(0u8), &csr_frac >> PRECISION); + + // multiply by 10k and we'll get 5k + // note: this is a bit sensative to input, lots of numbers approach from below + // (...99999) and so truncating division takes us off by one + let product = csr_frac * (BigInt::from(10_000) << PRECISION); // Q.256 + assert_eq!(BigInt::from(5000), product >> 2 * PRECISION); +} + +#[test] +fn both_positive_velocity() { + let num_estimate = testing_estimate(BigInt::from(111), BigInt::from(12)); + let denom_estimate = testing_estimate(BigInt::from(3456), BigInt::from(8)); + assert_err_bound( + &num_estimate, + &denom_estimate, + 10_000, + 0, + BigInt::from(ERR_BOUND), + ); +} + +#[test] +fn flipped_signs() { + let num_estimate = testing_estimate(BigInt::from(1_000_000), BigInt::from(-100)); + let denom_estimate = testing_estimate(BigInt::from(70_000), BigInt::from(1000)); + assert_err_bound( + &num_estimate, + &denom_estimate, + 100_000, + 0, + BigInt::from(ERR_BOUND), + ); +} + +#[test] +fn values_in_range() { + let tens_Of_fil = BigInt::from(50 * 10_i128.pow(18)); + let one_fil_per_sec = BigInt::from(25); + let four_fil_per_second = BigInt::from(100); + + let slow_money = testing_estimate(tens_Of_fil.clone(), one_fil_per_sec); + let fast_money = testing_estimate(tens_Of_fil.clone(), four_fil_per_second); + + let tens_of_ei_bs = StoragePower::from(10_i128.pow(19)); + let thousands_of_ei_bs = StoragePower::from(2 * 10_i128.pow(22)); + + let one_byte_per_epoch_velocity = BigInt::from(1); + let ten_pi_bs_per_day_velocity = + BigInt::from(10 * 2_i128.pow(50)) / BigInt::from(EPOCHS_IN_DAY); + let one_ei_bs_per_day_velocity = BigInt::from(2_i128.pow(60)) / BigInt::from(EPOCHS_IN_DAY); + + let delta = EPOCHS_IN_DAY; + let t0 = 0; + let err_bound = BigInt::from(ERR_BOUND); + + let test_cases: Vec<(StoragePower, BigInt)> = vec![ + (tens_of_ei_bs.clone(), one_byte_per_epoch_velocity.clone()), + (tens_of_ei_bs.clone(), ten_pi_bs_per_day_velocity.clone()), + (tens_of_ei_bs.clone(), one_ei_bs_per_day_velocity.clone()), + ( + thousands_of_ei_bs.clone(), + one_byte_per_epoch_velocity.clone(), + ), + ( + thousands_of_ei_bs.clone(), + ten_pi_bs_per_day_velocity.clone(), + ), + ( + thousands_of_ei_bs.clone(), + one_ei_bs_per_day_velocity.clone(), + ), + ]; + + for test_case in test_cases { + let power = testing_estimate(test_case.0, test_case.1); + assert_err_bound(&slow_money, &power, delta, t0, err_bound.clone()); + assert_err_bound(&fast_money, &power, delta, t0, err_bound.clone()); + } +} From 236f222aee3a3975244a377bff650849f743733a Mon Sep 17 00:00:00 2001 From: DragonMural Date: Mon, 3 Aug 2020 12:11:09 -0400 Subject: [PATCH 04/15] Fioxing test issue --- utils/smoothing/tests/alpha_beta_filter_test.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/smoothing/tests/alpha_beta_filter_test.rs b/utils/smoothing/tests/alpha_beta_filter_test.rs index 522042bd00fd..57cd15d74f7c 100644 --- a/utils/smoothing/tests/alpha_beta_filter_test.rs +++ b/utils/smoothing/tests/alpha_beta_filter_test.rs @@ -29,8 +29,8 @@ fn per_million_error(val_1: &BigInt, val_2: &BigInt) -> BigInt { } fn iterative_cum_sum_of_ratio( - num: &filterEstimate, - denom: &filterEstimate, + num: &FilterEstimate, + denom: &FilterEstimate, t0: ChainEpoch, delta: ChainEpoch, ) -> BigInt { @@ -51,8 +51,8 @@ fn iterative_cum_sum_of_ratio( } fn assert_err_bound( - num: &filterEstimate, - denom: &filterEstimate, + num: &FilterEstimate, + denom: &FilterEstimate, delta: ChainEpoch, t0: ChainEpoch, err_bound: BigInt, From 9b15b8aca686aea4b5bd8983d7361ab774a83957 Mon Sep 17 00:00:00 2001 From: nannick Date: Tue, 4 Aug 2020 09:18:31 -0400 Subject: [PATCH 05/15] Update utils/math/src/lib.rs Co-authored-by: Austin Abell --- utils/math/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/math/src/lib.rs b/utils/math/src/lib.rs index aec41926bd7d..4552b62f8f46 100644 --- a/utils/math/src/lib.rs +++ b/utils/math/src/lib.rs @@ -9,8 +9,7 @@ pub fn poly_val(poly: &[BigInt], x: &BigInt) -> BigInt { let mut res = BigInt::default(); for coeff in poly { - let temp = &res * x; - res = (temp >> PRECISION) + coeff; + res = ((res * x) >> PRECISION) + coeff; } res } From bb0cbaf201695697bd8eddef022e870e46d5783c Mon Sep 17 00:00:00 2001 From: nannick Date: Tue, 4 Aug 2020 09:18:46 -0400 Subject: [PATCH 06/15] Update utils/math/src/lib.rs Co-authored-by: Austin Abell --- utils/math/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/math/src/lib.rs b/utils/math/src/lib.rs index 4552b62f8f46..269070f155c8 100644 --- a/utils/math/src/lib.rs +++ b/utils/math/src/lib.rs @@ -15,7 +15,6 @@ pub fn poly_val(poly: &[BigInt], x: &BigInt) -> BigInt { } pub fn parse(coefs: &[&str]) -> Result, ()> { - println!("Num elements is {}", coefs.len()); let mut out: Vec = Vec::with_capacity(coefs.len() as usize); From 3b3592dbcec2b5cc8a9f15266f87fe27fcb1aaeb Mon Sep 17 00:00:00 2001 From: nannick Date: Tue, 4 Aug 2020 09:19:00 -0400 Subject: [PATCH 07/15] Update utils/smoothing/Cargo.toml Co-authored-by: Austin Abell --- utils/smoothing/Cargo.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/utils/smoothing/Cargo.toml b/utils/smoothing/Cargo.toml index 21a3443f5aca..ef6426a85ec7 100644 --- a/utils/smoothing/Cargo.toml +++ b/utils/smoothing/Cargo.toml @@ -14,6 +14,3 @@ actor = {path = "../../vm/actor", package = "actor"} fil_types = { path = "../../types" } encoding = { package = "forest_encoding", path = "../../encoding" } serde = { version = "1.0", features = ["derive"] } - - -[dev-dependencies] From d14b2dbc37c73f7fad6eb72af6f29d4a25c4105f Mon Sep 17 00:00:00 2001 From: DragonMural Date: Wed, 5 Aug 2020 16:44:24 -0400 Subject: [PATCH 08/15] Adding some requested changes --- utils/math/Cargo.toml | 5 +--- utils/math/src/lib.rs | 16 ++++------ utils/smoothing/src/constants.rs | 50 +++++--------------------------- utils/smoothing/src/lib.rs | 8 ++--- 4 files changed, 19 insertions(+), 60 deletions(-) diff --git a/utils/math/Cargo.toml b/utils/math/Cargo.toml index f13d6daa5390..200185d4b4cb 100644 --- a/utils/math/Cargo.toml +++ b/utils/math/Cargo.toml @@ -5,7 +5,4 @@ authors = ["ChainSafe Systems "] edition = "2018" [dependencies] -num-bigint = { path = "../../utils/bigint", package = "forest_bigint" } - - -[dev-dependencies] +num-bigint = { path = "../../utils/bigint", package = "forest_bigint" } \ No newline at end of file diff --git a/utils/math/src/lib.rs b/utils/math/src/lib.rs index 269070f155c8..0738f6968a41 100644 --- a/utils/math/src/lib.rs +++ b/utils/math/src/lib.rs @@ -1,10 +1,13 @@ // Copyright 2020 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -use num_bigint::BigInt; +use num_bigint::{BigInt, ParseBigIntError}; pub const PRECISION: u64 = 128; +/// polyval evaluates a polynomial given by coefficients `p` in Q.128 format +/// at point `x` in Q.128 format. Output is in Q.128. +/// Coefficients should be ordered from the highest order coefficient to the lowest. pub fn poly_val(poly: &[BigInt], x: &BigInt) -> BigInt { let mut res = BigInt::default(); @@ -14,13 +17,6 @@ pub fn poly_val(poly: &[BigInt], x: &BigInt) -> BigInt { res } -pub fn parse(coefs: &[&str]) -> Result, ()> { - - let mut out: Vec = Vec::with_capacity(coefs.len() as usize); - - for coef in coefs { - let c = BigInt::parse_bytes(coef.as_bytes(), 10).ok_or(())?; - out.push(c); - } - Ok(out) +pub fn parse(coefs: &[&str]) -> Result, ParseBigIntError> { + coefs.iter().map(|c| c.parse()).collect() } diff --git a/utils/smoothing/src/constants.rs b/utils/smoothing/src/constants.rs index 967c4d64ba1d..badd3ffd85eb 100644 --- a/utils/smoothing/src/constants.rs +++ b/utils/smoothing/src/constants.rs @@ -5,7 +5,7 @@ use forest_math::parse; use num_bigint::BigInt; lazy_static! { - pub static ref NUM: [&'static str ; 7] = [ + pub static ref NUM: Vec = parse(&[ "261417938209272870992496419296200268025", "7266615505142943436908456158054846846897", "32458783941900493142649393804518050491988", @@ -13,9 +13,9 @@ lazy_static! { "-35150353308172866634071793531642638290419", "-20351202052858059355702509232125230498980", "-1563932590352680681114104005183375350999", - ]; - - pub static ref DENOM: [&'static str ; 7] = [ + ]) + .unwrap(); + pub static ref DENOM: Vec = parse(&[ "49928077726659937662124949977867279384", "2508163877009111928787629628566491583994", "21757751789594546643737445330202599887121", @@ -23,42 +23,8 @@ lazy_static! { "41248834748603606604000911015235164348839", "9015227820322455780436733526367238305537", "340282366920938463463374607431768211456", - ]; - - pub static ref CONST_STRS: [&'static str ; 4] = [ - "314760000000000000000000000000000000", // DefaultAlpha - "96640100000000000000000000000000", // DefaultBeta - "302231454903657293676544", // Epsilon - "235865763225513294137944142764154484399", // ln(2) - ]; - -} - -const EXTRAPOLATED_CUM_SUM_RATIO_EPSILON: usize = 2; -const LN_2: usize = 3; - -pub fn get_ln_num_coef() -> Vec { - parse(&NUM[..]).unwrap() -} - -pub fn get_ln_denom_coef() -> Vec { - parse(&DENOM[..]).unwrap() -} - -pub fn get_ln2() -> BigInt { - BigInt::parse_bytes(CONST_STRS[LN_2].as_bytes(), 10).unwrap() -} - -pub fn get_cum_sum_ratio_epsilon() -> BigInt { - BigInt::parse_bytes( - CONST_STRS[EXTRAPOLATED_CUM_SUM_RATIO_EPSILON].as_bytes(), - 10, - ) - .unwrap() -} - -#[test] -fn parse_check() { - let _ = get_ln_num_coef(); - let _ = get_ln_denom_coef(); + ]) + .unwrap(); + pub static ref LN_2: BigInt = "235865763225513294137944142764154484399".parse().unwrap(); + pub static ref EPSILON: BigInt = "302231454903657293676544".parse().unwrap(); } diff --git a/utils/smoothing/src/lib.rs b/utils/smoothing/src/lib.rs index aca71e7e197d..cb99b78b63a9 100644 --- a/utils/smoothing/src/lib.rs +++ b/utils/smoothing/src/lib.rs @@ -34,7 +34,7 @@ pub fn extrapolated_cum_sum_of_ratio( let squared_velo_2 = (velo_2 * velo_2) >> PRECISION; - if squared_velo_2 >= get_cum_sum_ratio_epsilon() { + if squared_velo_2 >= EPSILON.clone() { let mut x2a = ((velo_2 * t0) >> PRECISION) + pos_2; let mut x2b = ((velo_2 * &delta_t) >> PRECISION) + &x2a; x2a = ln(&x2a); @@ -61,12 +61,12 @@ pub fn ln(z: &BigInt) -> BigInt { let x: BigInt = if k > 0 { z >> k } else { z << k.abs() }; - BigInt::from(k) * get_ln2() + ln_between_one_and_two(x) + BigInt::from(k) * LN_2.clone() + ln_between_one_and_two(x) } fn ln_between_one_and_two(x: BigInt) -> BigInt { - let num = poly_val(&get_ln_num_coef(), &x) << PRECISION; - let denom = poly_val(&get_ln_denom_coef(), &x); + let num = poly_val(&NUM, &x) << PRECISION; + let denom = poly_val(&DENOM, &x); num / denom } From b853fbdc2b662bf584c59277f3b2773ee210f49f Mon Sep 17 00:00:00 2001 From: DragonMural Date: Wed, 5 Aug 2020 17:06:43 -0400 Subject: [PATCH 09/15] Remove clone --- utils/smoothing/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/smoothing/src/lib.rs b/utils/smoothing/src/lib.rs index cb99b78b63a9..d1fca300ce8e 100644 --- a/utils/smoothing/src/lib.rs +++ b/utils/smoothing/src/lib.rs @@ -34,7 +34,7 @@ pub fn extrapolated_cum_sum_of_ratio( let squared_velo_2 = (velo_2 * velo_2) >> PRECISION; - if squared_velo_2 >= EPSILON.clone() { + if squared_velo_2 >= *EPSILON { let mut x2a = ((velo_2 * t0) >> PRECISION) + pos_2; let mut x2b = ((velo_2 * &delta_t) >> PRECISION) + &x2a; x2a = ln(&x2a); @@ -61,7 +61,7 @@ pub fn ln(z: &BigInt) -> BigInt { let x: BigInt = if k > 0 { z >> k } else { z << k.abs() }; - BigInt::from(k) * LN_2.clone() + ln_between_one_and_two(x) + BigInt::from(k) * &*LN_2 + ln_between_one_and_two(x) } fn ln_between_one_and_two(x: BigInt) -> BigInt { From fe0c686e3197efa5bfcbe6061e35341c84f1a7a7 Mon Sep 17 00:00:00 2001 From: DragonMural Date: Wed, 5 Aug 2020 20:36:46 -0400 Subject: [PATCH 10/15] Move to vm/actor/util --- Cargo.lock | 22 ------------ Cargo.toml | 2 -- utils/math/Cargo.toml | 8 ----- utils/smoothing/Cargo.toml | 16 --------- utils/smoothing/src/constants.rs | 30 ---------------- .../actor/src/util}/alpha_beta_filter.rs | 4 ++- .../src/lib.rs => vm/actor/src/util/math.rs | 0 vm/actor/src/util/mod.rs | 5 +++ .../src/lib.rs => vm/actor/src/util/smooth.rs | 36 ++++++++++++++----- .../actor}/tests/alpha_beta_filter_test.rs | 6 ++-- 10 files changed, 39 insertions(+), 90 deletions(-) delete mode 100644 utils/math/Cargo.toml delete mode 100644 utils/smoothing/Cargo.toml delete mode 100644 utils/smoothing/src/constants.rs rename {utils/smoothing/src => vm/actor/src/util}/alpha_beta_filter.rs (97%) rename utils/math/src/lib.rs => vm/actor/src/util/math.rs (100%) rename utils/smoothing/src/lib.rs => vm/actor/src/util/smooth.rs (63%) rename {utils/smoothing => vm/actor}/tests/alpha_beta_filter_test.rs (98%) diff --git a/Cargo.lock b/Cargo.lock index 55eed86a5d84..b1a0520a4c17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2525,13 +2525,6 @@ dependencies = [ "utils", ] -[[package]] -name = "forest_math" -version = "0.1.0" -dependencies = [ - "forest_bigint", -] - [[package]] name = "forest_message" version = "0.3.0" @@ -2550,21 +2543,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "forest_smoothing" -version = "0.1.0" -dependencies = [ - "actor", - "clock", - "fil_types", - "forest_bigint", - "forest_encoding", - "forest_math", - "lazy_static", - "num-traits 0.2.12", - "serde", -] - [[package]] name = "forest_vm" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 44b125df8b5c..905b5acd9776 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,8 +33,6 @@ members = [ "utils/test_utils", "utils/commcid", "utils/json_utils", - "utils/smoothing", - "utils/math", "types", "key_management", ] diff --git a/utils/math/Cargo.toml b/utils/math/Cargo.toml deleted file mode 100644 index 200185d4b4cb..000000000000 --- a/utils/math/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "forest_math" -version = "0.1.0" -authors = ["ChainSafe Systems "] -edition = "2018" - -[dependencies] -num-bigint = { path = "../../utils/bigint", package = "forest_bigint" } \ No newline at end of file diff --git a/utils/smoothing/Cargo.toml b/utils/smoothing/Cargo.toml deleted file mode 100644 index ef6426a85ec7..000000000000 --- a/utils/smoothing/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "forest_smoothing" -version = "0.1.0" -authors = ["ChainSafe Systems "] -edition = "2018" - -[dependencies] -num-bigint = { path = "../../utils/bigint", package = "forest_bigint" } -clock = { path = "../../node/clock" } -forest_math = {path = "../math"} -lazy_static = "1.4" -num-traits = "0.2" -actor = {path = "../../vm/actor", package = "actor"} -fil_types = { path = "../../types" } -encoding = { package = "forest_encoding", path = "../../encoding" } -serde = { version = "1.0", features = ["derive"] } diff --git a/utils/smoothing/src/constants.rs b/utils/smoothing/src/constants.rs deleted file mode 100644 index badd3ffd85eb..000000000000 --- a/utils/smoothing/src/constants.rs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2020 ChainSafe Systems -// SPDX-License-Identifier: Apache-2.0, MIT - -use forest_math::parse; -use num_bigint::BigInt; - -lazy_static! { - pub static ref NUM: Vec = parse(&[ - "261417938209272870992496419296200268025", - "7266615505142943436908456158054846846897", - "32458783941900493142649393804518050491988", - "17078670566130897220338060387082146864806", - "-35150353308172866634071793531642638290419", - "-20351202052858059355702509232125230498980", - "-1563932590352680681114104005183375350999", - ]) - .unwrap(); - pub static ref DENOM: Vec = parse(&[ - "49928077726659937662124949977867279384", - "2508163877009111928787629628566491583994", - "21757751789594546643737445330202599887121", - "53400635271583923415775576342898617051826", - "41248834748603606604000911015235164348839", - "9015227820322455780436733526367238305537", - "340282366920938463463374607431768211456", - ]) - .unwrap(); - pub static ref LN_2: BigInt = "235865763225513294137944142764154484399".parse().unwrap(); - pub static ref EPSILON: BigInt = "302231454903657293676544".parse().unwrap(); -} diff --git a/utils/smoothing/src/alpha_beta_filter.rs b/vm/actor/src/util/alpha_beta_filter.rs similarity index 97% rename from utils/smoothing/src/alpha_beta_filter.rs rename to vm/actor/src/util/alpha_beta_filter.rs index 9c8d2157249a..3ccaf90081c9 100644 --- a/utils/smoothing/src/alpha_beta_filter.rs +++ b/vm/actor/src/util/alpha_beta_filter.rs @@ -1,9 +1,11 @@ // Copyright 2020 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT +#![allow(dead_code)] +use super::math::PRECISION; + use clock::ChainEpoch; use encoding::Cbor; -use forest_math::PRECISION; use num_bigint::{bigint_ser, BigInt}; use serde::{Deserialize, Serialize}; diff --git a/utils/math/src/lib.rs b/vm/actor/src/util/math.rs similarity index 100% rename from utils/math/src/lib.rs rename to vm/actor/src/util/math.rs diff --git a/vm/actor/src/util/mod.rs b/vm/actor/src/util/mod.rs index d4e74e6fedce..19b8bc5b61ef 100644 --- a/vm/actor/src/util/mod.rs +++ b/vm/actor/src/util/mod.rs @@ -1,12 +1,17 @@ // Copyright 2020 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT +mod alpha_beta_filter; mod balance_table; +pub mod math; mod multimap; mod set; mod set_multimap; +pub mod smooth; pub use self::balance_table::BalanceTable; pub use self::multimap::*; pub use self::set::Set; pub use self::set_multimap::SetMultimap; +pub use math::*; +pub use smooth::*; \ No newline at end of file diff --git a/utils/smoothing/src/lib.rs b/vm/actor/src/util/smooth.rs similarity index 63% rename from utils/smoothing/src/lib.rs rename to vm/actor/src/util/smooth.rs index d1fca300ce8e..6251e97060c1 100644 --- a/utils/smoothing/src/lib.rs +++ b/vm/actor/src/util/smooth.rs @@ -1,19 +1,39 @@ // Copyright 2020 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -#[macro_use] -extern crate lazy_static; - use num_bigint::BigInt; -mod alpha_beta_filter; -mod constants; -pub use alpha_beta_filter::*; +use super::alpha_beta_filter::*; + +use crate::math::{parse, poly_val, PRECISION}; use clock::ChainEpoch; -use constants::*; -use forest_math::{poly_val, PRECISION}; use num_traits::sign::Signed; +lazy_static! { + pub static ref NUM: Vec = parse(&[ + "261417938209272870992496419296200268025", + "7266615505142943436908456158054846846897", + "32458783941900493142649393804518050491988", + "17078670566130897220338060387082146864806", + "-35150353308172866634071793531642638290419", + "-20351202052858059355702509232125230498980", + "-1563932590352680681114104005183375350999", + ]) + .unwrap(); + pub static ref DENOM: Vec = parse(&[ + "49928077726659937662124949977867279384", + "2508163877009111928787629628566491583994", + "21757751789594546643737445330202599887121", + "53400635271583923415775576342898617051826", + "41248834748603606604000911015235164348839", + "9015227820322455780436733526367238305537", + "340282366920938463463374607431768211456", + ]) + .unwrap(); + pub static ref LN_2: BigInt = "235865763225513294137944142764154484399".parse().unwrap(); + pub static ref EPSILON: BigInt = "302231454903657293676544".parse().unwrap(); +} + fn get_bit_len(z: &BigInt) -> usize { z.abs().to_radix_le(2).1.len() } diff --git a/utils/smoothing/tests/alpha_beta_filter_test.rs b/vm/actor/tests/alpha_beta_filter_test.rs similarity index 98% rename from utils/smoothing/tests/alpha_beta_filter_test.rs rename to vm/actor/tests/alpha_beta_filter_test.rs index 57cd15d74f7c..d36c29f39058 100644 --- a/utils/smoothing/tests/alpha_beta_filter_test.rs +++ b/vm/actor/tests/alpha_beta_filter_test.rs @@ -1,9 +1,9 @@ // Copyright 2020 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -use forest_math::{parse, PRECISION}; -use forest_smoothing::extrapolated_cum_sum_of_ratio as ecsor; -use forest_smoothing::*; +use actor::math::{parse, PRECISION}; +use actor::smooth::extrapolated_cum_sum_of_ratio as ecsor; +use actor::smooth::*; use num_bigint::BigInt; From 82602356b9e14310ebb4fa4f7cde58f3f25c308d Mon Sep 17 00:00:00 2001 From: DragonMural Date: Wed, 5 Aug 2020 20:51:33 -0400 Subject: [PATCH 11/15] Test updates --- vm/actor/src/util/mod.rs | 6 ++---- vm/actor/tests/alpha_beta_filter_test.rs | 7 ++++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/vm/actor/src/util/mod.rs b/vm/actor/src/util/mod.rs index 19b8bc5b61ef..93085a64fa3d 100644 --- a/vm/actor/src/util/mod.rs +++ b/vm/actor/src/util/mod.rs @@ -1,7 +1,7 @@ // Copyright 2020 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -mod alpha_beta_filter; +pub mod alpha_beta_filter; mod balance_table; pub mod math; mod multimap; @@ -12,6 +12,4 @@ pub mod smooth; pub use self::balance_table::BalanceTable; pub use self::multimap::*; pub use self::set::Set; -pub use self::set_multimap::SetMultimap; -pub use math::*; -pub use smooth::*; \ No newline at end of file +pub use self::set_multimap::SetMultimap; \ No newline at end of file diff --git a/vm/actor/tests/alpha_beta_filter_test.rs b/vm/actor/tests/alpha_beta_filter_test.rs index d36c29f39058..e10f06397c35 100644 --- a/vm/actor/tests/alpha_beta_filter_test.rs +++ b/vm/actor/tests/alpha_beta_filter_test.rs @@ -4,6 +4,7 @@ use actor::math::{parse, PRECISION}; use actor::smooth::extrapolated_cum_sum_of_ratio as ecsor; use actor::smooth::*; +use actor::alpha_beta_filter::FilterEstimate; use num_bigint::BigInt; @@ -158,12 +159,12 @@ fn flipped_signs() { #[test] fn values_in_range() { - let tens_Of_fil = BigInt::from(50 * 10_i128.pow(18)); + let tens_of_fil = BigInt::from(50 * 10_i128.pow(18)); let one_fil_per_sec = BigInt::from(25); let four_fil_per_second = BigInt::from(100); - let slow_money = testing_estimate(tens_Of_fil.clone(), one_fil_per_sec); - let fast_money = testing_estimate(tens_Of_fil.clone(), four_fil_per_second); + let slow_money = testing_estimate(tens_of_fil.clone(), one_fil_per_sec); + let fast_money = testing_estimate(tens_of_fil.clone(), four_fil_per_second); let tens_of_ei_bs = StoragePower::from(10_i128.pow(19)); let thousands_of_ei_bs = StoragePower::from(2 * 10_i128.pow(22)); From aa2fe1aab9ddb46c30866e7cd689863e19abc48a Mon Sep 17 00:00:00 2001 From: DragonMural Date: Wed, 5 Aug 2020 20:54:18 -0400 Subject: [PATCH 12/15] Lint fix --- vm/actor/src/util/mod.rs | 2 +- vm/actor/tests/alpha_beta_filter_test.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vm/actor/src/util/mod.rs b/vm/actor/src/util/mod.rs index 93085a64fa3d..daa9fa7d892c 100644 --- a/vm/actor/src/util/mod.rs +++ b/vm/actor/src/util/mod.rs @@ -12,4 +12,4 @@ pub mod smooth; pub use self::balance_table::BalanceTable; pub use self::multimap::*; pub use self::set::Set; -pub use self::set_multimap::SetMultimap; \ No newline at end of file +pub use self::set_multimap::SetMultimap; diff --git a/vm/actor/tests/alpha_beta_filter_test.rs b/vm/actor/tests/alpha_beta_filter_test.rs index e10f06397c35..fa9e1b1725a5 100644 --- a/vm/actor/tests/alpha_beta_filter_test.rs +++ b/vm/actor/tests/alpha_beta_filter_test.rs @@ -1,10 +1,10 @@ // Copyright 2020 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT +use actor::alpha_beta_filter::FilterEstimate; use actor::math::{parse, PRECISION}; use actor::smooth::extrapolated_cum_sum_of_ratio as ecsor; use actor::smooth::*; -use actor::alpha_beta_filter::FilterEstimate; use num_bigint::BigInt; From 44f05a4d5a78cf444bf7ee4697105b7b134af96d Mon Sep 17 00:00:00 2001 From: DragonMural Date: Thu, 6 Aug 2020 10:42:50 -0400 Subject: [PATCH 13/15] Serialize_tuple --- vm/actor/src/util/alpha_beta_filter.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vm/actor/src/util/alpha_beta_filter.rs b/vm/actor/src/util/alpha_beta_filter.rs index 3ccaf90081c9..8e6be9b57031 100644 --- a/vm/actor/src/util/alpha_beta_filter.rs +++ b/vm/actor/src/util/alpha_beta_filter.rs @@ -5,11 +5,11 @@ use super::math::PRECISION; use clock::ChainEpoch; +use encoding::tuple::*; use encoding::Cbor; use num_bigint::{bigint_ser, BigInt}; -use serde::{Deserialize, Serialize}; -#[derive(Default, Serialize, Deserialize)] +#[derive(Default, Serialize_tuple, Deserialize_tuple)] pub struct FilterEstimate { #[serde(with = "bigint_ser")] pub pos: BigInt, From 09661c67ada7e1f552217c88eb6f0448f7d7f0d3 Mon Sep 17 00:00:00 2001 From: DragonMural Date: Fri, 7 Aug 2020 14:44:43 -0400 Subject: [PATCH 14/15] Update --- vm/actor/src/util/math.rs | 2 +- vm/actor/src/util/mod.rs | 1 - .../util/{ => smooth}/alpha_beta_filter.rs | 35 +++++++++------- vm/actor/src/util/smooth/mod.rs | 8 ++++ .../util/{smooth.rs => smooth/smooth_func.rs} | 42 ++++++++----------- vm/actor/tests/alpha_beta_filter_test.rs | 21 ++++++---- 6 files changed, 59 insertions(+), 50 deletions(-) rename vm/actor/src/util/{ => smooth}/alpha_beta_filter.rs (57%) create mode 100644 vm/actor/src/util/smooth/mod.rs rename vm/actor/src/util/{smooth.rs => smooth/smooth_func.rs} (74%) diff --git a/vm/actor/src/util/math.rs b/vm/actor/src/util/math.rs index 0738f6968a41..44ff0ce393ed 100644 --- a/vm/actor/src/util/math.rs +++ b/vm/actor/src/util/math.rs @@ -17,6 +17,6 @@ pub fn poly_val(poly: &[BigInt], x: &BigInt) -> BigInt { res } -pub fn parse(coefs: &[&str]) -> Result, ParseBigIntError> { +pub fn poly_parse(coefs: &[&str]) -> Result, ParseBigIntError> { coefs.iter().map(|c| c.parse()).collect() } diff --git a/vm/actor/src/util/mod.rs b/vm/actor/src/util/mod.rs index daa9fa7d892c..c7cfb37c4f15 100644 --- a/vm/actor/src/util/mod.rs +++ b/vm/actor/src/util/mod.rs @@ -1,7 +1,6 @@ // Copyright 2020 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -pub mod alpha_beta_filter; mod balance_table; pub mod math; mod multimap; diff --git a/vm/actor/src/util/alpha_beta_filter.rs b/vm/actor/src/util/smooth/alpha_beta_filter.rs similarity index 57% rename from vm/actor/src/util/alpha_beta_filter.rs rename to vm/actor/src/util/smooth/alpha_beta_filter.rs index 8e6be9b57031..aba792d3bfde 100644 --- a/vm/actor/src/util/alpha_beta_filter.rs +++ b/vm/actor/src/util/smooth/alpha_beta_filter.rs @@ -1,9 +1,9 @@ // Copyright 2020 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT +//TODO Remove Allow dead code when AlphaBetaFilter is used #![allow(dead_code)] -use super::math::PRECISION; - +use crate::util::math::PRECISION; use clock::ChainEpoch; use encoding::tuple::*; use encoding::Cbor; @@ -12,27 +12,30 @@ use num_bigint::{bigint_ser, BigInt}; #[derive(Default, Serialize_tuple, Deserialize_tuple)] pub struct FilterEstimate { #[serde(with = "bigint_ser")] - pub pos: BigInt, + pub position: BigInt, #[serde(with = "bigint_ser")] - pub velo: BigInt, + pub velocity: BigInt, } impl FilterEstimate { - pub fn new(pos: BigInt, velo: BigInt) -> Self { + /// Create a new filter estimate given two Q.0 format ints. + pub fn new(position: BigInt, velocity: BigInt) -> Self { FilterEstimate { - pos: pos << PRECISION, - velo: velo << PRECISION, + position: position << PRECISION, + velocity: velocity << PRECISION, } } + /// Returns the Q.0 position estimate of the filter pub fn estimate(&self) -> BigInt { - &self.pos >> PRECISION + &self.position >> PRECISION } + /// Extrapolate filter "position" delta epochs in the future. pub fn extrapolate(&self, delta: ChainEpoch) -> BigInt { let delta_t = BigInt::from(delta) << PRECISION; - let pos = &self.pos << PRECISION; - (&self.velo * delta_t) + pos + let position = &self.position << PRECISION; + (&self.velocity * delta_t) + position } } @@ -56,16 +59,16 @@ impl AlphaBetaFilter { pub fn next_estimate(&self, obs: BigInt, epoch_delta: ChainEpoch) -> FilterEstimate { let delta_t = BigInt::from(epoch_delta) << PRECISION; - let delta_x = (&delta_t * &self.prev_est.velo) >> PRECISION; - let mut pos = delta_x + &self.prev_est.pos; + let delta_x = (&delta_t * &self.prev_est.velocity) >> PRECISION; + let mut position = delta_x + &self.prev_est.position; let obs = obs << PRECISION; - let residual = obs - &pos; + let residual = obs - &position; let revision_x = (&self.alpha * &residual) >> PRECISION; - pos += &revision_x; + position += &revision_x; let revision_v = (residual * &self.beta) / delta_t; - let velo = revision_v + &self.prev_est.velo; - FilterEstimate { pos, velo } + let velocity = revision_v + &self.prev_est.velocity; + FilterEstimate { position, velocity } } } diff --git a/vm/actor/src/util/smooth/mod.rs b/vm/actor/src/util/smooth/mod.rs new file mode 100644 index 000000000000..92f8182307e4 --- /dev/null +++ b/vm/actor/src/util/smooth/mod.rs @@ -0,0 +1,8 @@ +// Copyright 2020 ChainSafe Systems +// SPDX-License-Identifier: Apache-2.0, MIT + +mod alpha_beta_filter; +mod smooth_func; + +pub use alpha_beta_filter::*; +pub use smooth_func::*; diff --git a/vm/actor/src/util/smooth.rs b/vm/actor/src/util/smooth/smooth_func.rs similarity index 74% rename from vm/actor/src/util/smooth.rs rename to vm/actor/src/util/smooth/smooth_func.rs index 6251e97060c1..aee2df354dac 100644 --- a/vm/actor/src/util/smooth.rs +++ b/vm/actor/src/util/smooth/smooth_func.rs @@ -1,16 +1,13 @@ // Copyright 2020 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -use num_bigint::BigInt; - use super::alpha_beta_filter::*; - -use crate::math::{parse, poly_val, PRECISION}; +use crate::math::{poly_parse, poly_val, PRECISION}; use clock::ChainEpoch; -use num_traits::sign::Signed; +use num_bigint::BigInt; lazy_static! { - pub static ref NUM: Vec = parse(&[ + pub static ref NUM: Vec = poly_parse(&[ "261417938209272870992496419296200268025", "7266615505142943436908456158054846846897", "32458783941900493142649393804518050491988", @@ -20,7 +17,7 @@ lazy_static! { "-1563932590352680681114104005183375350999", ]) .unwrap(); - pub static ref DENOM: Vec = parse(&[ + pub static ref DENOM: Vec = poly_parse(&[ "49928077726659937662124949977867279384", "2508163877009111928787629628566491583994", "21757751789594546643737445330202599887121", @@ -34,10 +31,11 @@ lazy_static! { pub static ref EPSILON: BigInt = "302231454903657293676544".parse().unwrap(); } -fn get_bit_len(z: &BigInt) -> usize { - z.abs().to_radix_le(2).1.len() +fn get_bit_len(z: &BigInt) -> u64 { + z.bits() } +/// Extrapolate the CumSumRatio given two filters. pub fn extrapolated_cum_sum_of_ratio( delta: ChainEpoch, relative_start: ChainEpoch, @@ -47,14 +45,14 @@ pub fn extrapolated_cum_sum_of_ratio( let delta_t = BigInt::from(delta) << PRECISION; let t0 = BigInt::from(relative_start) << PRECISION; - let pos_1 = &est_num.pos; - let pos_2 = &est_denom.pos; - let velo_1 = &est_num.velo; - let velo_2 = &est_denom.velo; + let pos_1 = &est_num.position; + let pos_2 = &est_denom.position; + let velo_1 = &est_num.velocity; + let velo_2 = &est_denom.velocity; let squared_velo_2 = (velo_2 * velo_2) >> PRECISION; - if squared_velo_2 >= *EPSILON { + if squared_velo_2 > *EPSILON { let mut x2a = ((velo_2 * t0) >> PRECISION) + pos_2; let mut x2b = ((velo_2 * &delta_t) >> PRECISION) + &x2a; x2a = ln(&x2a); @@ -76,26 +74,20 @@ pub fn extrapolated_cum_sum_of_ratio( (x1m * delta_t) / pos_2 } +/// The natural log of Q.128 x. pub fn ln(z: &BigInt) -> BigInt { let k: i64 = get_bit_len(z) as i64 - 1 - PRECISION as i64; let x: BigInt = if k > 0 { z >> k } else { z << k.abs() }; - BigInt::from(k) * &*LN_2 + ln_between_one_and_two(x) + (BigInt::from(k) * &*LN_2) + ln_between_one_and_two(x) } +/// The natural log of x, specified in Q.128 format +/// Should only use with 1 <= x <= 2 +/// Output is in Q.128 format. fn ln_between_one_and_two(x: BigInt) -> BigInt { let num = poly_val(&NUM, &x) << PRECISION; let denom = poly_val(&DENOM, &x); num / denom } - -// Returns an estimate with position val and velocity 0 -pub fn testing_constant_estimate(val: BigInt) -> FilterEstimate { - FilterEstimate::new(val, BigInt::from(0u8)) -} - -// Returns and estimate with postion x and velocity v -pub fn testing_estimate(x: BigInt, v: BigInt) -> FilterEstimate { - FilterEstimate::new(x, v) -} diff --git a/vm/actor/tests/alpha_beta_filter_test.rs b/vm/actor/tests/alpha_beta_filter_test.rs index fa9e1b1725a5..7b130fd7fdce 100644 --- a/vm/actor/tests/alpha_beta_filter_test.rs +++ b/vm/actor/tests/alpha_beta_filter_test.rs @@ -1,16 +1,13 @@ // Copyright 2020 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -use actor::alpha_beta_filter::FilterEstimate; -use actor::math::{parse, PRECISION}; +use actor::math::{poly_parse, PRECISION}; use actor::smooth::extrapolated_cum_sum_of_ratio as ecsor; use actor::smooth::*; - -use num_bigint::BigInt; - use actor::EPOCHS_IN_DAY; use clock::ChainEpoch; use fil_types::StoragePower; +use num_bigint::BigInt; use num_traits::sign::Signed; const ERR_BOUND: u64 = 350; @@ -69,9 +66,19 @@ fn assert_err_bound( ); } +// Returns an estimate with position val and velocity 0 +pub fn testing_constant_estimate(val: BigInt) -> FilterEstimate { + FilterEstimate::new(val, BigInt::from(0u8)) +} + +// Returns and estimate with postion x and velocity v +pub fn testing_estimate(x: BigInt, v: BigInt) -> FilterEstimate { + FilterEstimate::new(x, v) +} + #[test] fn test_natural_log() { - let ln_inputs: Vec = parse(&[ + let ln_inputs: Vec = poly_parse(&[ "340282366920938463463374607431768211456", // Q.128 format of 1 "924990000000000000000000000000000000000", // Q.128 format of e (rounded up in 5th decimal place to handle truncation) "34028236692093846346337460743176821145600000000000000000000", // Q.128 format of 100e18 @@ -81,7 +88,7 @@ fn test_natural_log() { ]) .unwrap(); - let expected_ln_outputs: Vec = parse(&[ + let expected_ln_outputs: Vec = poly_parse(&[ "0", // Q.128 format of 0 = ln(1) "340282366920938463463374607431768211456", // Q.128 format of 1 = ln(e) "15670582109617661336106769654068947397831", // Q.128 format of 46.051... = ln(100e18) From 8d9c1e7c15e871e1e6d15dcd11e19af554e4fc3d Mon Sep 17 00:00:00 2001 From: DragonMural Date: Fri, 7 Aug 2020 14:55:09 -0400 Subject: [PATCH 15/15] Removing warn statement --- vm/actor/src/util/smooth/alpha_beta_filter.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/vm/actor/src/util/smooth/alpha_beta_filter.rs b/vm/actor/src/util/smooth/alpha_beta_filter.rs index aba792d3bfde..82bf97cfcabb 100644 --- a/vm/actor/src/util/smooth/alpha_beta_filter.rs +++ b/vm/actor/src/util/smooth/alpha_beta_filter.rs @@ -1,8 +1,6 @@ // Copyright 2020 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -//TODO Remove Allow dead code when AlphaBetaFilter is used -#![allow(dead_code)] use crate::util::math::PRECISION; use clock::ChainEpoch; use encoding::tuple::*;