Skip to content

Commit

Permalink
replace SimpleQaPower with flags
Browse files Browse the repository at this point in the history
  • Loading branch information
LesnyRumcajs committed Sep 1, 2023
1 parent a154da5 commit bbd32e3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
25 changes: 16 additions & 9 deletions builtin/v12/migration/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,21 +372,28 @@ func (m minerMigrator) migrateDeadlines(ctx context.Context, store adt11.Store,
}

func migrateSectorInfo(sectorInfo miner11.SectorOnChainInfo) *miner12.SectorOnChainInfo {
// For a sector that has not been updated: the Activation is correct and ReplacedSectorAge is zero.
// For a sector that has been updated through SnapDeals: Activation is the epoch at which it was upgraded, and ReplacedSectorAge is delta since the true activation.
// For a sector that has been updated through the old CC path: Activation is correct
// Thus, we want to set:
//
// PowerBaseEpoch := Activation (in all cases)
// Activation := Activation (for non-upgraded sectors and sectors upgraded through old CC path)
// Activation := OldActivation - ReplacedSectorAge (for sectors updated through SnapDeals)
// For a sector that has not been updated: the Activation is correct and ReplacedSectorAge is zero.
// For a sector that has been updated through SnapDeals: Activation is the epoch at which it was upgraded, and ReplacedSectorAge is delta since the true activation.
// For a sector that has been updated through the old CC path: Activation is correct
// Thus, we want to set:
//
// PowerBaseEpoch := Activation (in all cases)
// Activation := Activation (for non-upgraded sectors and sectors upgraded through old CC path)
// Activation := OldActivation - ReplacedSectorAge (for sectors updated through SnapDeals)
//
// SimpleQAPower field got replaced by flags field. We set the flag SIMPLE_QA_POWER if the sector had the field set to true.

powerBaseEpoch := sectorInfo.Activation
activationEpoch := sectorInfo.Activation
if sectorInfo.SectorKeyCID != nil {
activationEpoch = sectorInfo.Activation - sectorInfo.ReplacedSectorAge
}

flags := miner12.SectorOnChainInfoFlags(0)
if sectorInfo.SimpleQAPower {
flags = flags | miner12.SIMPLE_QA_POWER
}

return &miner12.SectorOnChainInfo{
SectorNumber: sectorInfo.SectorNumber,
SealProof: sectorInfo.SealProof,
Expand All @@ -402,6 +409,6 @@ func migrateSectorInfo(sectorInfo miner11.SectorOnChainInfo) *miner12.SectorOnCh
PowerBaseEpoch: powerBaseEpoch,
ReplacedDayReward: sectorInfo.ReplacedDayReward,
SectorKeyCID: sectorInfo.SectorKeyCID,
SimpleQAPower: sectorInfo.SimpleQAPower,
Flags: flags,
}
}
29 changes: 18 additions & 11 deletions builtin/v12/miner/miner_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,30 @@ type SectorPreCommitOnChainInfo struct {
PreCommitEpoch abi.ChainEpoch
}

type SectorOnChainInfoFlags uint32

const (
SIMPLE_QA_POWER SectorOnChainInfoFlags = 1 << iota // QA power mechanism introduced in FIP-0045
)


// Information stored on-chain for a proven sector.
type SectorOnChainInfo struct {
SectorNumber abi.SectorNumber
SealProof abi.RegisteredSealProof // The seal proof type implies the PoSt proof/s
SealedCID cid.Cid // CommR
DealIDs []abi.DealID
Activation abi.ChainEpoch // Epoch during which the sector proof was accepted
Expiration abi.ChainEpoch // Epoch during which the sector expires
DealWeight abi.DealWeight // Integral of active deals over sector lifetime
VerifiedDealWeight abi.DealWeight // Integral of active verified deals over sector lifetime
InitialPledge abi.TokenAmount // Pledge collected to commit this sector
ExpectedDayReward abi.TokenAmount // Expected one day projection of reward for sector computed at activation time
ExpectedStoragePledge abi.TokenAmount // Expected twenty day projection of reward for sector computed at activation time
PowerBaseEpoch abi.ChainEpoch // Epoch at which this sector's power was most recently updated
ReplacedDayReward abi.TokenAmount // Day reward of this sector before its power was most recently updated
SectorKeyCID *cid.Cid // The original SealedSectorCID, only gets set on the first ReplicaUpdate
SimpleQAPower bool // Flag for QA power mechanism introduced in FIP-0045
Activation abi.ChainEpoch // Epoch during which the sector proof was accepted
Expiration abi.ChainEpoch // Epoch during which the sector expires
DealWeight abi.DealWeight // Integral of active deals over sector lifetime
VerifiedDealWeight abi.DealWeight // Integral of active verified deals over sector lifetime
InitialPledge abi.TokenAmount // Pledge collected to commit this sector
ExpectedDayReward abi.TokenAmount // Expected one day projection of reward for sector computed at activation time
ExpectedStoragePledge abi.TokenAmount // Expected twenty day projection of reward for sector computed at activation time
PowerBaseEpoch abi.ChainEpoch // Epoch at which this sector's power was most recently updated
ReplacedDayReward abi.TokenAmount // Day reward of this sector before its power was most recently updated
SectorKeyCID *cid.Cid // The original SealedSectorCID, only gets set on the first ReplicaUpdate
Flags SectorOnChainInfoFlags // Additional flags
}

func (st *State) GetInfo(store adt.Store) (*MinerInfo, error) {
Expand Down

0 comments on commit bbd32e3

Please sign in to comment.