Skip to content

Commit

Permalink
fix(power15): apply adjustments from review
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Oct 3, 2024
1 parent ca7f9a4 commit 52bfd13
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
38 changes: 27 additions & 11 deletions builtin/v15/migration/top.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,37 @@ import (
"golang.org/x/xerrors"
)

// MigrateStateTree Migrates the filecoin state tree starting from the global state tree and upgrading all actor state.
// MigrateStateTree migrates the Filecoin state tree starting from the global state tree and upgrading all actor states.
// The store must support concurrent writes (even if the configured worker count is 1).
func MigrateStateTree(ctx context.Context, store cbor.IpldStore, newManifestCID cid.Cid, actorsRootIn cid.Cid, priorEpoch abi.ChainEpoch, cfg migration.Config, log migration.Logger, cache migration.MigrationCache) (cid.Cid, error) {
//
// FIP-0081 constants for the power actor state for pledge calculations that apply only to this migration:
//
// - powerRampStartEpoch: Epoch at which the new pledge calculation starts.
// - powerRampDurationEpochs: Number of epochs over which the new pledge calculation is ramped up.
func MigrateStateTree(
ctx context.Context,
store cbor.IpldStore,
newManifestCID cid.Cid,
actorsRootIn cid.Cid,
priorEpoch abi.ChainEpoch,
powerRampStartEpoch int64,
powerRampDurationEpochs uint64,
cfg migration.Config,
log migration.Logger,
cache migration.MigrationCache,
) (cid.Cid, error) {
if cfg.MaxWorkers <= 0 {
return cid.Undef, xerrors.Errorf("invalid migration config with %d workers", cfg.MaxWorkers)
}

if cfg.PowerRampStartEpoch == 0 {
return cid.Undef, xerrors.Errorf("PowerRampStartEpoch must be set")
if powerRampStartEpoch == 0 {
return cid.Undef, xerrors.Errorf("powerRampStartEpoch must be non-zero")
}
if cfg.PowerRampStartEpoch < 0 {
return cid.Undef, xerrors.Errorf("PowerRampStartEpoch must be non-negative")
if powerRampStartEpoch < 0 {
return cid.Undef, xerrors.Errorf("powerRampStartEpoch must be non-negative")
}
if cfg.PowerRampDurationEpochs == 0 {
return cid.Undef, xerrors.Errorf("PowerRampDurationEpochs must be set")
if powerRampDurationEpochs == 0 {
return cid.Undef, xerrors.Errorf("powerRampDurationEpochs must be non-zero")
}

adtStore := adt15.WrapStore(ctx, store)
Expand Down Expand Up @@ -88,7 +104,7 @@ func MigrateStateTree(ctx context.Context, store cbor.IpldStore, newManifestCID
if !ok {
return cid.Undef, xerrors.Errorf("code cid for %s actor not found in new manifest", oldEntry.Name)
}
migrations[oldEntry.Code] = migration.CachedMigration(cache, migration.CodeMigrator{OutCodeCID: newCodeCID})
migrations[oldEntry.Code] = migration.CodeMigrator{OutCodeCID: newCodeCID}
}

// migrations that migrate both code and state, override entries in `migrations`
Expand All @@ -111,11 +127,11 @@ func MigrateStateTree(ctx context.Context, store cbor.IpldStore, newManifestCID
return cid.Undef, xerrors.Errorf("code cid for power actor not found in new manifest")
}

pm, err := newPowerMigrator(cfg.PowerRampStartEpoch, cfg.PowerRampDurationEpochs, power15Cid)
pm, err := newPowerMigrator(powerRampStartEpoch, powerRampDurationEpochs, power15Cid)
if err != nil {
return cid.Undef, xerrors.Errorf("failed to create miner migrator: %w", err)
}
migrations[power14Cid] = migration.CachedMigration(cache, *pm)
migrations[power14Cid] = *pm

if len(migrations)+len(deferredCodeIDs) != len(oldManifestData.Entries) {
return cid.Undef, xerrors.Errorf("incomplete migration specification with %d code CIDs, need %d", len(migrations)+len(deferredCodeIDs), len(oldManifestData.Entries))
Expand Down
5 changes: 3 additions & 2 deletions builtin/v15/miner/monies.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ func PreCommitDepositForPower(rewardEstimate, networkQAPowerEstimate smoothing.F
return ExpectedRewardForPowerClampedAtAttoFIL(rewardEstimate, networkQAPowerEstimate, qaSectorPower, PreCommitDepositProjectionPeriod)
}

// Computes the pledge requirement for committing new quality-adjusted power to the network, given
// the current network total and baseline power, per-epoch reward, and circulating token supply.
// InitialPledgeForPower computes the pledge requirement for committing new quality-adjusted power
// to the network, given the current network total and baseline power, per-epoch reward, and
// circulating token supply.
// The pledge comprises two parts:
// - storage pledge, aka IP base: a multiple of the reward expected to be earned by newly-committed power
// - consensus pledge, aka additional IP: a pro-rata fraction of the circulating money supply
Expand Down
4 changes: 0 additions & 4 deletions migration/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ type Config struct {
ProgressLogPeriod time.Duration
// The epoch at which the upgrade will run.
UpgradeEpoch abi.ChainEpoch

// FIP-0081 constants for the power actor state for pledge calculations.
PowerRampStartEpoch int64 // Epoch at which the new pledge calculation starts.
PowerRampDurationEpochs uint64 // Number of epochs over which the new pledge calculation is ramped up.
}

type Logger interface {
Expand Down

0 comments on commit 52bfd13

Please sign in to comment.