1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2019-2024 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::{
    shim::{econ::TokenAmount, sector::RegisteredSealProof},
    state_migration::common::{TypeMigration, TypeMigrator},
};
use fil_actor_miner_state::{
    v11::SectorOnChainInfo as SectorOnChainInfoV11,
    v12::{SectorOnChainInfo as SectorOnChainInfoV12, SectorOnChainInfoFlags},
};
use fvm_ipld_blockstore::Blockstore;

impl TypeMigration<&SectorOnChainInfoV11, SectorOnChainInfoV12> for TypeMigrator {
    fn migrate_type(
        from: &SectorOnChainInfoV11,
        _: &impl Blockstore,
    ) -> anyhow::Result<SectorOnChainInfoV12> {
        let power_base_epoch = from.activation;

        let activation = if from.sector_key_cid.is_some() {
            from.activation - from.replaced_sector_age
        } else {
            from.activation
        };

        let flags = if from.simple_qa_power {
            SectorOnChainInfoFlags::SIMPLE_QA_POWER
        } else {
            SectorOnChainInfoFlags::default()
        };

        let out_info = SectorOnChainInfoV12 {
            sector_number: from.sector_number,
            seal_proof: RegisteredSealProof::from(from.seal_proof).into(),
            sealed_cid: from.sealed_cid,
            deal_ids: from.deal_ids.clone(),
            activation,
            expiration: from.expiration,
            deal_weight: from.deal_weight.clone(),
            verified_deal_weight: from.verified_deal_weight.clone(),
            initial_pledge: TokenAmount::from(&from.initial_pledge).into(),
            expected_day_reward: TokenAmount::from(&from.expected_day_reward).into(),
            expected_storage_pledge: TokenAmount::from(&from.expected_storage_pledge).into(),
            power_base_epoch,
            replaced_day_reward: TokenAmount::from(&from.replaced_day_reward).into(),
            sector_key_cid: from.sector_key_cid,
            flags,
        };

        Ok(out_info)
    }
}