Skip to content

Commit

Permalink
fix(fip0081): minor updates from review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Oct 2, 2024
1 parent 54116a7 commit 9cc9458
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 46 deletions.
4 changes: 2 additions & 2 deletions build/buildconstants/params_calibnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ const UpgradeTuktukHeight = 999999999999999
// UpgradeTuktukPowerRampDurationEpochs ends up in the power actor state after
// Tuktuk migration. along with a RampStartEpoch matching the upgrade height.
//
// For calibrationnet, we set this to 7 days so we can observe and confirm the
// For calibrationnet, we set this to 3 days so we can observe and confirm the
// ramp behavior before mainnet upgrade.
var UpgradeTuktukPowerRampDurationEpochs = uint64(builtin.EpochsInDay * 7)
var UpgradeTuktukPowerRampDurationEpochs = uint64(builtin.EpochsInDay * 3)

var SupportedProofTypes = []abi.RegisteredSealProof{
abi.RegisteredSealProof_StackedDrg32GiBV1,
Expand Down
42 changes: 28 additions & 14 deletions chain/consensus/filcns/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2600,6 +2600,11 @@ func upgradeActorsV14Common(
return newRoot, nil
}

// PreUpgradeActorsV15 runs the premigration for v15 actors. Note that this migration contains no
// cached migrators, so the only purpose of running a premigration is to prime the blockstore with
// IPLD blocks that would be created during the migration, to reduce the amount of work that needs
// to be done during the actual migration since block Puts become simple Has operations. But the
// same amount of migration work will need to be done otherwise.
func PreUpgradeActorsV15(ctx context.Context, sm *stmgr.StateManager, cache stmgr.MigrationCache, root cid.Cid, epoch abi.ChainEpoch, ts *types.TipSet) error {
// Use half the CPUs for pre-migration, but leave at least 3.
workerCount := MigrationMaxWorkerCount
Expand All @@ -2615,10 +2620,8 @@ func PreUpgradeActorsV15(ctx context.Context, sm *stmgr.StateManager, cache stmg
}

config := migration.Config{
MaxWorkers: uint(workerCount),
ProgressLogPeriod: time.Minute * 5,
PowerRampStartEpoch: int64(buildconstants.UpgradeTuktukHeight),
PowerRampDurationEpochs: buildconstants.UpgradeTuktukPowerRampDurationEpochs,
MaxWorkers: uint(workerCount),
ProgressLogPeriod: time.Minute * 5,
}

_, err = upgradeActorsV15Common(ctx, sm, cache, lbRoot, epoch, config)
Expand All @@ -2640,12 +2643,10 @@ func UpgradeActorsV15(
workerCount = 1
}
config := migration.Config{
MaxWorkers: uint(workerCount),
JobQueueSize: 1000,
ResultQueueSize: 100,
ProgressLogPeriod: 10 * time.Second,
PowerRampStartEpoch: int64(epoch),
PowerRampDurationEpochs: buildconstants.UpgradeTuktukPowerRampDurationEpochs,
MaxWorkers: uint(workerCount),
JobQueueSize: 1000,
ResultQueueSize: 100,
ProgressLogPeriod: 10 * time.Second,
}
newRoot, err := upgradeActorsV15Common(ctx, sm, cache, root, epoch, config)
if err != nil {
Expand All @@ -2658,7 +2659,8 @@ func upgradeActorsV15Common(
ctx context.Context,
sm *stmgr.StateManager,
cache stmgr.MigrationCache,
root cid.Cid, epoch abi.ChainEpoch,
root cid.Cid,
epoch abi.ChainEpoch,
config migration.Config,
) (cid.Cid, error) {
writeStore := blockstore.NewAutobatch(ctx, sm.ChainStore().StateBlockstore(), units.GiB/4)
Expand Down Expand Up @@ -2687,9 +2689,21 @@ func upgradeActorsV15Common(
}

// Perform the migration
newHamtRoot, err := nv24.MigrateStateTree(ctx, adtStore, manifest, stateRoot.Actors, epoch, config, migrationLogger{}, cache)
if err != nil {
return cid.Undef, xerrors.Errorf("upgrading to actors vXX+1: %w", err)
newHamtRoot, err := nv24.MigrateStateTree(
ctx,
adtStore,
manifest,
stateRoot.Actors,
epoch,
// two FIP-0081 constants for this migration only
int64(buildconstants.UpgradeTuktukHeight), // powerRampStartEpoch
buildconstants.UpgradeTuktukPowerRampDurationEpochs, // powerRampDurationEpochs
config,
migrationLogger{},
cache,
)
if err != nil {
return cid.Undef, xerrors.Errorf("upgrading to actors v15: %w", err)
}

// Persist the result.
Expand Down
20 changes: 3 additions & 17 deletions chain/gen/genesis/miners.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,29 +481,15 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal

pcd := miner15.PreCommitDepositForPower(smoothing15.FilterEstimate(rewardSmoothed), qaps, miner15.QAPowerMax(m.SectorSize))

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

powerState, err := power.Load(adt.WrapStore(ctx, cst), powerActor)
if err != nil {
return cid.Undef, xerrors.Errorf("loading power actor state: %w", err)
}

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

pledge := miner15.InitialPledgeForPower(
sectorWeight,
baselinePower,
smoothing15.FilterEstimate(rewardSmoothed),
qaps,
big.Zero(),
epochsSinceRampStart,
powerState.RampDurationEpochs(),
// epochsSinceRampStart and rampDurationEpochs: InternalSectorSetupForPreseal uses 0,0 for
// these parameters, regardless of what the power actor state says.
0, 0,
)

pledge = big.Add(pcd, pledge)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ require (
github.com/filecoin-project/go-jsonrpc v0.6.0
github.com/filecoin-project/go-padreader v0.0.1
github.com/filecoin-project/go-paramfetch v0.0.4
github.com/filecoin-project/go-state-types v0.15.0-dev.0.20240930040600-f1e9746dbeaa
github.com/filecoin-project/go-state-types v0.15.0-dev.0.20241002035125-d8aa0706403b
github.com/filecoin-project/go-statemachine v1.0.3
github.com/filecoin-project/go-statestore v0.2.0
github.com/filecoin-project/go-storedcounter v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ github.com/filecoin-project/go-state-types v0.0.0-20200928172055-2df22083d8ab/go
github.com/filecoin-project/go-state-types v0.0.0-20201102161440-c8033295a1fc/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g=
github.com/filecoin-project/go-state-types v0.1.0/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g=
github.com/filecoin-project/go-state-types v0.1.6/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.15.0-dev.0.20240930040600-f1e9746dbeaa h1:bFoshr5ETGO0UWCeBD4LLwkk/BVCvwLO5gpgOojB268=
github.com/filecoin-project/go-state-types v0.15.0-dev.0.20240930040600-f1e9746dbeaa/go.mod h1:YcWoJE/24XGEL6w9FjUoMBu7+eHEkgwKnkGZkTBX9TE=
github.com/filecoin-project/go-state-types v0.15.0-dev.0.20241002035125-d8aa0706403b h1:aMD8mc99JKwLu30ceihaCUcpwcpi4W+sd9zrna1J28I=
github.com/filecoin-project/go-state-types v0.15.0-dev.0.20241002035125-d8aa0706403b/go.mod h1:YcWoJE/24XGEL6w9FjUoMBu7+eHEkgwKnkGZkTBX9TE=
github.com/filecoin-project/go-statemachine v1.0.3 h1:N07o6alys+V1tNoSTi4WuuoeNC4erS/6jE74+NsgQuk=
github.com/filecoin-project/go-statemachine v1.0.3/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54=
github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI=
Expand Down
34 changes: 24 additions & 10 deletions itests/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,8 +915,10 @@ func TestMigrationNV24(t *testing.T) {
blockTime = 10 * time.Millisecond
)
buildconstants.UpgradeTuktukPowerRampDurationEpochs = powerRampDurationEpochs
buildconstants.UpgradeTuktukHeight = nv24epoch

// InitialPledgeMaxPerByte is a little too low for an itest environment so gets in the way of testing the underlying calculation
// InitialPledgeMaxPerByte is a little too low for an itest environment so gets in the way of
// testing the underlying calculation, so we bump it up here so it doesn't interfere.
miner14.InitialPledgeMaxPerByte = big.Mul(miner14.InitialPledgeMaxPerByte, big.NewInt(10)) // pre migration
miner15.InitialPledgeMaxPerByte = big.Mul(miner15.InitialPledgeMaxPerByte, big.NewInt(10)) // post migration

Expand All @@ -931,14 +933,23 @@ func TestMigrationNV24(t *testing.T) {
testClient, _, ens := kit.EnsembleMinimal(
t,
kit.MockProofs(),
kit.UpgradeSchedule(stmgr.Upgrade{
Network: network.Version23,
Height: -1,
}, stmgr.Upgrade{
Network: network.Version24,
Height: nv24epoch,
Migration: filcns.UpgradeActorsV15,
},
kit.UpgradeSchedule(
stmgr.Upgrade{
Network: network.Version23,
Height: -1,
},
stmgr.Upgrade{
Network: network.Version24,
Height: nv24epoch,
Migration: filcns.UpgradeActorsV15,
PreMigrations: []stmgr.PreMigration{{ // should have no effect on measurements
PreMigration: filcns.PreUpgradeActorsV15,
StartWithin: nv24epoch / 2,
DontStartWithin: 2,
StopWithin: 2,
}},
Expensive: true,
},
))

ens.InterconnectAll().BeginMining(blockTime)
Expand Down Expand Up @@ -975,8 +986,11 @@ func TestMigrationNV24(t *testing.T) {
relativeChange := float64(pledge.Uint64()-preFip0081Pledge.Uint64()) / float64(preFip0081Pledge.Uint64())
if i > 0 {
if head.Height() > nv24epoch {
// We want to see an increasing distance between the pre-fip-0081 pledge and original pledge
// We want to see an increasing distance between the pre-FIP-0081 pledge and original pledge
// calculation, so the relative change should be increasing from the migration onward.
// This test depends on network power being below baseline, once we are above baseline
// then the FIP-0081 70/30 split (including ramp) should not differ from the pre-FIP-0081
// pledge calculation.
if relativeChange < lastRelativeChange {
t.Errorf("relative change decreased: %f -> %f @%d", lastRelativeChange, relativeChange, head.Height())
break
Expand Down

0 comments on commit 9cc9458

Please sign in to comment.