Skip to content

Commit

Permalink
re-use FilterEstimate
Browse files Browse the repository at this point in the history
  • Loading branch information
LesnyRumcajs committed Mar 24, 2022
1 parent ed58241 commit 3770200
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 67 deletions.
62 changes: 1 addition & 61 deletions vm/actor_interface/src/builtin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ pub mod system;
use crate::ActorVersion;

use cid::Cid;
use num_bigint::BigInt;

pub use fvm_shared::clock::EPOCH_DURATION_SECONDS;
pub use fvm_shared::smooth::FilterEstimate;
pub const EPOCHS_IN_DAY: clock::ChainEpoch = actorv0::EPOCHS_IN_DAY;

// Aliases for common addresses
Expand Down Expand Up @@ -83,63 +83,3 @@ pub fn actor_version(code: &Cid) -> Option<ActorVersion> {
None
}
}

#[derive(Default, Clone, Debug, PartialEq)]
pub struct FilterEstimate {
pub position: BigInt,
pub velocity: BigInt,
}

impl From<actorv0::util::smooth::FilterEstimate> for FilterEstimate {
fn from(filter_est: actorv0::util::smooth::FilterEstimate) -> Self {
Self {
position: filter_est.position,
velocity: filter_est.velocity,
}
}
}

impl From<actorv2::util::smooth::FilterEstimate> for FilterEstimate {
fn from(filter_est: actorv2::util::smooth::FilterEstimate) -> Self {
Self {
position: filter_est.position,
velocity: filter_est.velocity,
}
}
}

impl From<actorv3::util::smooth::FilterEstimate> for FilterEstimate {
fn from(filter_est: actorv3::util::smooth::FilterEstimate) -> Self {
Self {
position: filter_est.position,
velocity: filter_est.velocity,
}
}
}

impl From<actorv4::util::smooth::FilterEstimate> for FilterEstimate {
fn from(filter_est: actorv4::util::smooth::FilterEstimate) -> Self {
Self {
position: filter_est.position,
velocity: filter_est.velocity,
}
}
}

impl From<actorv5::util::smooth::FilterEstimate> for FilterEstimate {
fn from(filter_est: actorv5::util::smooth::FilterEstimate) -> Self {
Self {
position: filter_est.position,
velocity: filter_est.velocity,
}
}
}

impl From<actorv6::util::smooth::FilterEstimate> for FilterEstimate {
fn from(filter_est: actorv6::util::smooth::FilterEstimate) -> Self {
Self {
position: filter_est.position,
velocity: filter_est.velocity,
}
}
}
22 changes: 16 additions & 6 deletions vm/actor_interface/src/builtin/power/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ pub enum State {
V6(actorv6::power::State),
}

/// Converts any `FilterEstimate`, e.g. `actorv0::util::smooth::FilterEstimate` type into
/// generalized one `crate::FilterEstimate`.
macro_rules! convert_filter_estimate {
($from:expr) => {
FilterEstimate {
position: $from.position.clone(),
velocity: $from.velocity.clone(),
}
};
}
impl State {
pub fn load<BS>(store: &BS, actor: &ActorState) -> Result<State, Box<dyn Error>>
where
Expand Down Expand Up @@ -225,12 +235,12 @@ impl State {
/// Returns this_epoch_qa_power_smoothed from the state.
pub fn total_power_smoothed(&self) -> FilterEstimate {
match self {
State::V0(st) => st.this_epoch_qa_power_smoothed.clone().into(),
State::V2(st) => st.this_epoch_qa_power_smoothed.clone().into(),
State::V3(st) => st.this_epoch_qa_power_smoothed.clone().into(),
State::V4(st) => st.this_epoch_qa_power_smoothed.clone().into(),
State::V5(st) => st.this_epoch_qa_power_smoothed.clone().into(),
State::V6(st) => st.this_epoch_qa_power_smoothed.clone().into(),
State::V0(st) => convert_filter_estimate!(st.this_epoch_qa_power_smoothed),
State::V2(st) => convert_filter_estimate!(st.this_epoch_qa_power_smoothed),
State::V3(st) => convert_filter_estimate!(st.this_epoch_qa_power_smoothed),
State::V4(st) => convert_filter_estimate!(st.this_epoch_qa_power_smoothed),
State::V5(st) => convert_filter_estimate!(st.this_epoch_qa_power_smoothed),
State::V6(st) => convert_filter_estimate!(st.this_epoch_qa_power_smoothed),
}
}

Expand Down

0 comments on commit 3770200

Please sign in to comment.