Skip to content

Commit

Permalink
feat(fip0081): minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Oct 1, 2024
1 parent 67a5c73 commit 0bba2ea
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 74 deletions.
63 changes: 32 additions & 31 deletions build/buildconstants/params_testground.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,37 +76,38 @@ var (
UpgradeBreezeHeight abi.ChainEpoch = -1
BreezeGasTampingDuration abi.ChainEpoch = 0

UpgradeSmokeHeight abi.ChainEpoch = -1
UpgradeIgnitionHeight abi.ChainEpoch = -2
UpgradeRefuelHeight abi.ChainEpoch = -3
UpgradeTapeHeight abi.ChainEpoch = -4
UpgradeAssemblyHeight abi.ChainEpoch = 10
UpgradeLiftoffHeight abi.ChainEpoch = -5
UpgradeKumquatHeight abi.ChainEpoch = -6
UpgradeCalicoHeight abi.ChainEpoch = -8
UpgradePersianHeight abi.ChainEpoch = -9
UpgradeOrangeHeight abi.ChainEpoch = -10
UpgradeClausHeight abi.ChainEpoch = -11
UpgradeTrustHeight abi.ChainEpoch = -12
UpgradeNorwegianHeight abi.ChainEpoch = -13
UpgradeTurboHeight abi.ChainEpoch = -14
UpgradeHyperdriveHeight abi.ChainEpoch = -15
UpgradeChocolateHeight abi.ChainEpoch = -16
UpgradeOhSnapHeight abi.ChainEpoch = -17
UpgradeSkyrHeight abi.ChainEpoch = -18
UpgradeSharkHeight abi.ChainEpoch = -19
UpgradeHyggeHeight abi.ChainEpoch = -20
UpgradeLightningHeight abi.ChainEpoch = -21
UpgradeThunderHeight abi.ChainEpoch = -22
UpgradeWatermelonHeight abi.ChainEpoch = -23
UpgradeWatermelonFixHeight abi.ChainEpoch = -24
UpgradeWatermelonFix2Height abi.ChainEpoch = -25
UpgradeDragonHeight abi.ChainEpoch = -26
UpgradePhoenixHeight abi.ChainEpoch = -27
UpgradeCalibrationDragonFixHeight abi.ChainEpoch = -28
UpgradeWaffleHeight abi.ChainEpoch = -29
UpgradeTuktukHeight abi.ChainEpoch = -30
UpgradeTuktukPowerRampDurationEpochs uint64 = 0
UpgradeSmokeHeight abi.ChainEpoch = -1
UpgradeIgnitionHeight abi.ChainEpoch = -2
UpgradeRefuelHeight abi.ChainEpoch = -3
UpgradeTapeHeight abi.ChainEpoch = -4
UpgradeAssemblyHeight abi.ChainEpoch = 10
UpgradeLiftoffHeight abi.ChainEpoch = -5
UpgradeKumquatHeight abi.ChainEpoch = -6
UpgradeCalicoHeight abi.ChainEpoch = -8
UpgradePersianHeight abi.ChainEpoch = -9
UpgradeOrangeHeight abi.ChainEpoch = -10
UpgradeClausHeight abi.ChainEpoch = -11
UpgradeTrustHeight abi.ChainEpoch = -12
UpgradeNorwegianHeight abi.ChainEpoch = -13
UpgradeTurboHeight abi.ChainEpoch = -14
UpgradeHyperdriveHeight abi.ChainEpoch = -15
UpgradeChocolateHeight abi.ChainEpoch = -16
UpgradeOhSnapHeight abi.ChainEpoch = -17
UpgradeSkyrHeight abi.ChainEpoch = -18
UpgradeSharkHeight abi.ChainEpoch = -19
UpgradeHyggeHeight abi.ChainEpoch = -20
UpgradeLightningHeight abi.ChainEpoch = -21
UpgradeThunderHeight abi.ChainEpoch = -22
UpgradeWatermelonHeight abi.ChainEpoch = -23
UpgradeWatermelonFixHeight abi.ChainEpoch = -24
UpgradeWatermelonFix2Height abi.ChainEpoch = -25
UpgradeDragonHeight abi.ChainEpoch = -26
UpgradePhoenixHeight abi.ChainEpoch = -27
UpgradeCalibrationDragonFixHeight abi.ChainEpoch = -28
UpgradeWaffleHeight abi.ChainEpoch = -29
UpgradeTuktukHeight abi.ChainEpoch = -30

UpgradeTuktukPowerRampDurationEpochs uint64 = 0

DrandSchedule = map[abi.ChainEpoch]DrandEnum{
0: DrandMainnet,
Expand Down
30 changes: 13 additions & 17 deletions cmd/lotus-shed/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,31 +774,27 @@ var chainPledgeCmd = &cli.Command{
circ.FilCirculating = big.Zero()
}

var epochsSinceRampStart int64
var rampDurationEpochs uint64

if powerActor, err := state.GetActor(power.Address); err != nil {
return xerrors.Errorf("loading power actor: %w", err)
} else if powerState, err := power.Load(store, powerActor); err != nil {
return xerrors.Errorf("loading power actor state: %w", err)
} else if powerState.RampStartEpoch() > 0 {
epochsSinceRampStart = epoch - powerState.RampStartEpoch()
rampDurationEpochs = powerState.RampDurationEpochs()
}

rewardActor, err := state.GetActor(reward.Address)
if err != nil {
return xerrors.Errorf("loading miner actor: %w", err)
}

rewardState, err := reward.Load(store, rewardActor)
if err != nil {
return xerrors.Errorf("loading reward actor state: %w", err)
}

powerActor, err := state.GetActor(power.Address)
if err != nil {
return xerrors.Errorf("loading power actor: %w", err)
}

powerState, err := power.Load(store, powerActor)
if err != nil {
return xerrors.Errorf("loading power actor state: %w", err)
}

var epochsSinceRampStart int64
if powerState.RampStartEpoch() > 0 {
epochsSinceRampStart = epoch - powerState.RampStartEpoch()
}

fmt.Println("FilVested", types.FIL(circ.FilVested))
fmt.Println("FilMined", types.FIL(circ.FilMined))
fmt.Println("FilBurnt", types.FIL(circ.FilBurnt))
Expand All @@ -817,7 +813,7 @@ var chainPledgeCmd = &cli.Command{
&powerSmoothed,
circ.FilCirculating,
epochsSinceRampStart,
powerState.RampDurationEpochs(),
rampDurationEpochs,
)
if err != nil {
return xerrors.Errorf("calculating initial pledge: %w", err)
Expand Down
44 changes: 18 additions & 26 deletions node/impl/full/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1558,19 +1558,9 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr
return types.EmptyInt, xerrors.Errorf("getting circulating supply: %w", err)
}

powerActor, err := state.GetActor(power.Address)
epochsSinceRampStart, rampDurationEpochs, err := a.getPledgeRampParams(ctx, ts.Height(), state)
if err != nil {
return types.EmptyInt, xerrors.Errorf("loading power actor: %w", err)
}

powerState, err := power.Load(a.Chain.ActorStore(ctx), powerActor)
if err != nil {
return types.EmptyInt, xerrors.Errorf("loading power actor state: %w", err)
}

var epochsSinceRampStart int64
if powerState.RampStartEpoch() > 0 {
epochsSinceRampStart = int64(ts.Height()) - powerState.RampStartEpoch()
return types.EmptyInt, xerrors.Errorf("getting pledge ramp params: %w", err)
}

initialPledge, err := rewardState.InitialPledgeForPower(
Expand All @@ -1579,7 +1569,7 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr
powerSmoothed,
circSupply.FilCirculating,
epochsSinceRampStart,
powerState.RampDurationEpochs(),
rampDurationEpochs,
)
if err != nil {
return types.EmptyInt, xerrors.Errorf("calculating initial pledge: %w", err)
Expand All @@ -1588,6 +1578,18 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr
return types.BigDiv(types.BigMul(initialPledge, initialPledgeNum), initialPledgeDen), nil
}

// getPledgeRampParams returns epochsSinceRampStart, rampDurationEpochs, or 0, 0 if the pledge ramp is not active.
func (a *StateAPI) getPledgeRampParams(ctx context.Context, height abi.ChainEpoch, state *state.StateTree) (int64, uint64, error) {
if powerActor, err := state.GetActor(power.Address); err != nil {
return 0, 0, xerrors.Errorf("loading power actor: %w", err)
} else if powerState, err := power.Load(a.Chain.ActorStore(ctx), powerActor); err != nil {
return 0, 0, xerrors.Errorf("loading power actor state: %w", err)
} else if powerState.RampStartEpoch() > 0 {
return int64(height) - powerState.RampStartEpoch(), powerState.RampDurationEpochs(), nil
}
return 0, 0, nil
}

func (a *StateAPI) StateMinerInitialPledgeForSector(ctx context.Context, sectorDuration abi.ChainEpoch, sectorSize abi.SectorSize, verifiedSize uint64, tsk types.TipSetKey) (types.BigInt, error) {
if sectorDuration <= 0 {
return types.EmptyInt, xerrors.Errorf("sector duration must greater than 0")
Expand Down Expand Up @@ -1632,19 +1634,9 @@ func (a *StateAPI) StateMinerInitialPledgeForSector(ctx context.Context, sectorD
verifiedWeight := big.Mul(big.NewIntUnsigned(verifiedSize), big.NewInt(int64(sectorDuration)))
sectorWeight := builtin.QAPowerForWeight(sectorSize, sectorDuration, big.Zero(), verifiedWeight)

powerActor, err := state.GetActor(power.Address)
if err != nil {
return types.EmptyInt, xerrors.Errorf("loading power actor: %w", err)
}

powerState, err := power.Load(a.Chain.ActorStore(ctx), powerActor)
epochsSinceRampStart, rampDurationEpochs, err := a.getPledgeRampParams(ctx, ts.Height(), state)
if err != nil {
return types.EmptyInt, xerrors.Errorf("loading power actor state: %w", err)
}

var epochsSinceRampStart int64
if powerState.RampStartEpoch() > 0 {
epochsSinceRampStart = int64(ts.Height()) - powerState.RampStartEpoch()
return types.EmptyInt, xerrors.Errorf("getting pledge ramp params: %w", err)
}

initialPledge, err := rewardState.InitialPledgeForPower(
Expand All @@ -1653,7 +1645,7 @@ func (a *StateAPI) StateMinerInitialPledgeForSector(ctx context.Context, sectorD
powerSmoothed,
circSupply.FilCirculating,
epochsSinceRampStart,
powerState.RampDurationEpochs(),
rampDurationEpochs,
)
if err != nil {
return types.EmptyInt, xerrors.Errorf("calculating initial pledge: %w", err)
Expand Down

0 comments on commit 0bba2ea

Please sign in to comment.