Skip to content

Commit

Permalink
[Chore] Update MinerInfo (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruseinov authored Nov 28, 2023
1 parent 82095e2 commit e8fe46c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
61 changes: 61 additions & 0 deletions fil_actor_interface/src/builtin/miner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::convert::*;
use crate::Policy;
use anyhow::Context;
use cid::Cid;
use fil_actor_miner_state::v12::{BeneficiaryTerm, PendingBeneficiaryChange};
use fvm_ipld_bitfield::BitField;
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::{serde_bytes, BytesDe};
Expand Down Expand Up @@ -305,6 +306,10 @@ pub struct MinerInfo {
pub sector_size: SectorSize,
pub window_post_partition_sectors: u64,
pub consensus_fault_elapsed: ChainEpoch,
pub pending_owner_address: Option<Address>,
pub beneficiary: Address,
pub beneficiary_term: BeneficiaryTerm,
pub pending_beneficiary_term: Option<PendingBeneficiaryChange>,
}

impl From<fil_actor_miner_state::v8::MinerInfo> for MinerInfo {
Expand All @@ -328,6 +333,10 @@ impl From<fil_actor_miner_state::v8::MinerInfo> for MinerInfo {
sector_size: info.sector_size,
window_post_partition_sectors: info.window_post_partition_sectors,
consensus_fault_elapsed: info.consensus_fault_elapsed,
pending_owner_address: info.pending_owner_address,
beneficiary: info.owner,
beneficiary_term: BeneficiaryTerm::default(),
pending_beneficiary_term: None,
}
}
}
Expand All @@ -353,6 +362,22 @@ impl From<fil_actor_miner_state::v9::MinerInfo> for MinerInfo {
sector_size: info.sector_size,
window_post_partition_sectors: info.window_post_partition_sectors,
consensus_fault_elapsed: info.consensus_fault_elapsed,
pending_owner_address: info.pending_owner_address,
beneficiary: info.beneficiary,
beneficiary_term: BeneficiaryTerm {
expiration: info.beneficiary_term.expiration,
quota: from_token_v2_to_v4(info.beneficiary_term.quota),
used_quota: from_token_v2_to_v4(info.beneficiary_term.used_quota),
},
pending_beneficiary_term: info.pending_beneficiary_term.map(|term| {
PendingBeneficiaryChange {
new_beneficiary: from_address_v2_to_v4(term.new_beneficiary),
new_quota: from_token_v2_to_v4(term.new_quota),
new_expiration: term.new_expiration,
approved_by_beneficiary: term.approved_by_beneficiary,
approved_by_nominee: term.approved_by_nominee,
}
}),
}
}
}
Expand Down Expand Up @@ -381,6 +406,22 @@ impl From<fil_actor_miner_state::v10::MinerInfo> for MinerInfo {
sector_size: from_sector_size_v3_to_v2(info.sector_size),
window_post_partition_sectors: info.window_post_partition_sectors,
consensus_fault_elapsed: info.consensus_fault_elapsed,
pending_owner_address: info.pending_owner_address.map(from_address_v3_to_v2),
beneficiary: from_address_v3_to_v2(info.beneficiary),
beneficiary_term: BeneficiaryTerm {
quota: from_token_v3_to_v4(info.beneficiary_term.quota),
used_quota: from_token_v3_to_v4(info.beneficiary_term.used_quota),
expiration: info.beneficiary_term.expiration,
},
pending_beneficiary_term: info.pending_beneficiary_term.map(|term| {
PendingBeneficiaryChange {
new_beneficiary: from_address_v3_to_v4(term.new_beneficiary),
new_quota: from_token_v3_to_v4(term.new_quota),
new_expiration: term.new_expiration,
approved_by_beneficiary: term.approved_by_beneficiary,
approved_by_nominee: term.approved_by_nominee,
}
}),
}
}
}
Expand Down Expand Up @@ -409,6 +450,22 @@ impl From<fil_actor_miner_state::v11::MinerInfo> for MinerInfo {
sector_size: from_sector_size_v3_to_v2(info.sector_size),
window_post_partition_sectors: info.window_post_partition_sectors,
consensus_fault_elapsed: info.consensus_fault_elapsed,
pending_owner_address: info.pending_owner_address.map(from_address_v3_to_v2),
beneficiary: from_address_v3_to_v2(info.beneficiary),
beneficiary_term: BeneficiaryTerm {
quota: from_token_v3_to_v4(info.beneficiary_term.quota),
used_quota: from_token_v3_to_v4(info.beneficiary_term.used_quota),
expiration: info.beneficiary_term.expiration,
},
pending_beneficiary_term: info.pending_beneficiary_term.map(|change| {
PendingBeneficiaryChange {
new_beneficiary: from_address_v3_to_v4(change.new_beneficiary),
new_quota: from_token_v3_to_v4(change.new_quota),
new_expiration: change.new_expiration,
approved_by_beneficiary: change.approved_by_beneficiary,
approved_by_nominee: change.approved_by_nominee,
}
}),
}
}
}
Expand Down Expand Up @@ -437,6 +494,10 @@ impl From<fil_actor_miner_state::v12::MinerInfo> for MinerInfo {
sector_size: from_sector_size_v4_to_v2(info.sector_size),
window_post_partition_sectors: info.window_post_partition_sectors,
consensus_fault_elapsed: info.consensus_fault_elapsed,
pending_owner_address: info.pending_owner_address.map(from_address_v4_to_v2),
beneficiary: from_address_v4_to_v2(info.beneficiary),
beneficiary_term: info.beneficiary_term,
pending_beneficiary_term: info.pending_beneficiary_term,
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions fil_actor_interface/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,28 @@ pub fn from_address_v2_to_v4(addr: AddressV2) -> AddressV4 {
.expect("Couldn't convert between FVM2 and FVM4 addresses.")
}

pub fn from_address_v3_to_v4(addr: AddressV3) -> AddressV4 {
AddressV4::from_bytes(&addr.to_bytes())
.expect("Couldn't convert between FVM3 and FVM4 addresses.")
}

pub fn from_address_v4_to_v2(addr: AddressV4) -> AddressV2 {
AddressV2::from_bytes(&addr.to_bytes())
.expect("Couldn't convert between FVM4 and FVM2 addresses.")
}

pub fn from_token_v2_to_v4(token: TokenAmountV2) -> TokenAmountV4 {
TokenAmountV4::from_atto(token.atto().clone())
}

pub fn from_token_v3_to_v2(token: TokenAmountV3) -> TokenAmountV2 {
TokenAmountV2::from_atto(token.atto().clone())
}

pub fn from_token_v3_to_v4(token: TokenAmountV3) -> TokenAmountV4 {
TokenAmountV4::from_atto(token.atto().clone())
}

pub fn from_token_v4_to_v2(token: TokenAmountV4) -> TokenAmountV2 {
TokenAmountV2::from_atto(token.atto().clone())
}
Expand Down

0 comments on commit e8fe46c

Please sign in to comment.