feat(lotus-sim): use current power instead of lookback

I'd _really_ like to use lookback, but don't have that when starting
from a snapshot.
This commit is contained in:
Steven Allen 2021-06-22 14:35:30 -07:00
parent 0b06de2bd3
commit 87c306fd47
2 changed files with 9 additions and 52 deletions

View File

@ -16,7 +16,6 @@ import (
"github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/aerrors" "github.com/filecoin-project/lotus/chain/actors/aerrors"
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/actors/builtin/power" "github.com/filecoin-project/lotus/chain/actors/builtin/power"
"github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/lotus/chain/actors/policy"
@ -26,9 +25,8 @@ import (
) )
const ( const (
minPreCommitBatchSize = 1 minPreCommitBatchSize = 1
maxPreCommitBatchSize = miner5.PreCommitSectorBatchMaxSize maxPreCommitBatchSize = miner5.PreCommitSectorBatchMaxSize
onboardingProjectionLookback = 2 * 7 * builtin.EpochsInDay // lookback two weeks
) )
type PreCommitStage struct { type PreCommitStage struct {
@ -276,11 +274,6 @@ func (stage *PreCommitStage) load(ctx context.Context, bb *blockbuilder.BlockBui
"rest", stage.rest.len(), "rest", stage.rest.len(),
) )
}() }()
lookbackEpoch := bb.Height() - onboardingProjectionLookback
lookbackPowerTable, err := loadClaims(ctx, bb, lookbackEpoch)
if err != nil {
return xerrors.Errorf("failed to load claims from lookback epoch %d: %w", lookbackEpoch, err)
}
store := bb.ActorStore() store := bb.ActorStore()
st := bb.ParentStateTree() st := bb.ParentStateTree()
@ -290,10 +283,10 @@ func (stage *PreCommitStage) load(ctx context.Context, bb *blockbuilder.BlockBui
} }
type onboardingInfo struct { type onboardingInfo struct {
addr address.Address addr address.Address
onboardingRate uint64 sectorCount uint64
} }
sealList := make([]onboardingInfo, 0, len(lookbackPowerTable)) var sealList []onboardingInfo
err = powerState.ForEachClaim(func(addr address.Address, claim power.Claim) error { err = powerState.ForEachClaim(func(addr address.Address, claim power.Claim) error {
if claim.RawBytePower.IsZero() { if claim.RawBytePower.IsZero() {
return nil return nil
@ -308,16 +301,10 @@ func (stage *PreCommitStage) load(ctx context.Context, bb *blockbuilder.BlockBui
return err return err
} }
sectorsAdded := sectorsFromClaim(info.SectorSize, claim) sectorCount := sectorsFromClaim(info.SectorSize, claim)
if lookbackClaim, ok := lookbackPowerTable[addr]; !ok {
sectorsAdded -= sectorsFromClaim(info.SectorSize, lookbackClaim)
}
// NOTE: power _could_ have been lost, but that's too much of a pain to care if sectorCount > 0 {
// about. We _could_ look for faulty power by iterating through all sealList = append(sealList, onboardingInfo{addr, uint64(sectorCount)})
// deadlines, but I'd rather not.
if sectorsAdded > 0 {
sealList = append(sealList, onboardingInfo{addr, uint64(sectorsAdded)})
} }
return nil return nil
}) })
@ -331,7 +318,7 @@ func (stage *PreCommitStage) load(ctx context.Context, bb *blockbuilder.BlockBui
// Now that we have a list of sealing miners, sort them into percentiles. // Now that we have a list of sealing miners, sort them into percentiles.
sort.Slice(sealList, func(i, j int) bool { sort.Slice(sealList, func(i, j int) bool {
return sealList[i].onboardingRate < sealList[j].onboardingRate return sealList[i].sectorCount < sealList[j].sectorCount
}) })
// reset, just in case. // reset, just in case.

View File

@ -43,36 +43,6 @@ func sectorsFromClaim(sectorSize abi.SectorSize, c power.Claim) int64 {
return sectorCount.Int64() return sectorCount.Int64()
} }
// loadClaims will load all non-zero claims at the given epoch.
func loadClaims(
ctx context.Context, bb *blockbuilder.BlockBuilder, height abi.ChainEpoch,
) (map[address.Address]power.Claim, error) {
powerTable := make(map[address.Address]power.Claim)
st, err := bb.StateTreeByHeight(height)
if err != nil {
return nil, err
}
powerState, err := loadPower(bb.ActorStore(), st)
if err != nil {
return nil, err
}
err = powerState.ForEachClaim(func(miner address.Address, claim power.Claim) error {
// skip miners without power
if claim.RawBytePower.IsZero() {
return nil
}
powerTable[miner] = claim
return nil
})
if err != nil {
return nil, err
}
return powerTable, nil
}
func postChainCommitInfo(ctx context.Context, bb *blockbuilder.BlockBuilder, epoch abi.ChainEpoch) (abi.Randomness, error) { func postChainCommitInfo(ctx context.Context, bb *blockbuilder.BlockBuilder, epoch abi.ChainEpoch) (abi.Randomness, error) {
cs := bb.StateManager().ChainStore() cs := bb.StateManager().ChainStore()
ts := bb.ParentTipSet() ts := bb.ParentTipSet()