Skip to content

Commit

Permalink
test: genesis actors version
Browse files Browse the repository at this point in the history
Properly handle genesis in actors tests. Fast-forward upgrading to
actors v13 doesn't work because there needs to be at least a day between
v0 genesis and v13 (due to differences in miner cron).
  • Loading branch information
Stebalien committed Aug 11, 2021
1 parent 5ee73d9 commit faf893e
Show file tree
Hide file tree
Showing 19 changed files with 132 additions and 171 deletions.
1 change: 0 additions & 1 deletion build/params_shared_vals.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const UnixfsLinksPerLevel = 1024

const AllowableClockDriftSecs = uint64(1)
const NewestNetworkVersion = network.Version13
const ActorUpgradeNetworkVersion = network.Version4

// Epochs
const ForkLengthThreshold = Finality
Expand Down
5 changes: 1 addition & 4 deletions cmd/lotus-miner/actor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"testing"
"time"

"github.com/filecoin-project/go-state-types/network"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"

Expand All @@ -34,9 +33,7 @@ func TestWorkerKeyChange(t *testing.T) {
kit.QuietMiningLogs()

blocktime := 1 * time.Millisecond
client1, client2, miner, ens := kit.EnsembleTwoOne(t, kit.MockProofs(),
kit.ConstructorOpts(kit.InstantaneousNetworkVersion(network.Version13)),
)
client1, client2, miner, ens := kit.EnsembleTwoOne(t, kit.MockProofs())
ens.InterconnectAll().BeginMining(blocktime)

output := bytes.NewBuffer(nil)
Expand Down
2 changes: 1 addition & 1 deletion itests/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (ts *apiSuite) testNonGenesisMiner(t *testing.T) {
var newMiner kit.TestMiner
ens.Miner(&newMiner, full,
kit.OwnerAddr(full.DefaultKey),
kit.ProofType(abi.RegisteredSealProof_StackedDrg2KiBV1), // we're using v0 actors with old proofs.
kit.ProofType(abi.RegisteredSealProof_StackedDrg2KiBV1_1),
kit.WithAllSubsystems(),
).Start().InterconnectAll()

Expand Down
10 changes: 4 additions & 6 deletions itests/ccupgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ func TestCCUpgrade(t *testing.T) {
kit.QuietMiningLogs()

for _, height := range []abi.ChainEpoch{
-1, // before
162, // while sealing
530, // after upgrade deal
5000, // after
-1, // before
162, // while sealing
560, // after upgrade deal
} {
height := height // make linters happy by copying
t.Run(fmt.Sprintf("upgrade-%d", height), func(t *testing.T) {
Expand All @@ -33,8 +32,7 @@ func runTestCCUpgrade(t *testing.T, upgradeHeight abi.ChainEpoch) {
ctx := context.Background()
blockTime := 5 * time.Millisecond

opts := kit.ConstructorOpts(kit.LatestActorsAt(upgradeHeight))
client, miner, ens := kit.EnsembleMinimal(t, kit.MockProofs(), opts)
client, miner, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.LatestActorsAt(upgradeHeight))
ens.InterconnectAll().BeginMining(blockTime)

maddr, err := miner.ActorAddress(ctx)
Expand Down
5 changes: 2 additions & 3 deletions itests/deadlines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ func TestDeadlineToggling(t *testing.T) {
minerD kit.TestMiner
minerE kit.TestMiner
)
opts := []kit.NodeOpt{kit.ConstructorOpts(kit.NetworkUpgradeAt(network.Version12, upgradeH))}
opts = append(opts, kit.WithAllSubsystems())
ens := kit.NewEnsemble(t, kit.MockProofs()).
opts := []kit.NodeOpt{kit.WithAllSubsystems()}
ens := kit.NewEnsemble(t, kit.MockProofs(), kit.TurboUpgradeAt(upgradeH)).
FullNode(&client, opts...).
Miner(&minerA, &client, opts...).
Start().
Expand Down
1 change: 1 addition & 0 deletions itests/deals_concurrent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestDealWithMarketAndMinerNode(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}

t.Skip("skipping due to flakiness: see #6956")

kit.QuietMiningLogs()
Expand Down
1 change: 0 additions & 1 deletion itests/deals_publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func TestPublishDealsBatching(t *testing.T) {
DisableOwnerFallback: true,
DisableWorkerFallback: true,
})),
kit.LatestActorsAt(-1),
)

client, miner, ens := kit.EnsembleMinimal(t, kit.Account(publisherKey, types.FromFil(10)), kit.MockProofs(), kit.ConstructorOpts(opts))
Expand Down
34 changes: 26 additions & 8 deletions itests/kit/ensemble.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/filecoin-project/lotus/chain/gen"
genesis2 "github.com/filecoin-project/lotus/chain/gen/genesis"
"github.com/filecoin-project/lotus/chain/messagepool"
"github.com/filecoin-project/lotus/chain/stmgr"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/wallet"
"github.com/filecoin-project/lotus/cmd/lotus-seed/seed"
Expand Down Expand Up @@ -114,6 +115,7 @@ type Ensemble struct {
bms map[*TestMiner]*BlockMiner
}
genesis struct {
version network.Version
miners []genesis.Miner
accounts []genesis.Actor
}
Expand All @@ -130,6 +132,12 @@ func NewEnsemble(t *testing.T, opts ...EnsembleOpt) *Ensemble {
n := &Ensemble{t: t, options: &options}
n.active.bms = make(map[*TestMiner]*BlockMiner)

for _, up := range options.upgradeSchedule {
if up.Height < 0 {
n.genesis.version = up.Network
}
}

// add accounts from ensemble options to genesis.
for _, acc := range options.accounts {
n.genesis.accounts = append(n.genesis.accounts, genesis.Actor{
Expand Down Expand Up @@ -173,7 +181,7 @@ func (n *Ensemble) FullNode(full *TestFullNode, opts ...NodeOpt) *Ensemble {

// Miner enrolls a new miner, using the provided full node for chain
// interactions.
func (n *Ensemble) Miner(miner *TestMiner, full *TestFullNode, opts ...NodeOpt) *Ensemble {
func (n *Ensemble) Miner(minerNode *TestMiner, full *TestFullNode, opts ...NodeOpt) *Ensemble {
require.NotNil(n.t, full, "full node required when instantiating miner")

options := DefaultNodeOpts
Expand Down Expand Up @@ -208,11 +216,15 @@ func (n *Ensemble) Miner(miner *TestMiner, full *TestFullNode, opts ...NodeOpt)
genm *genesis.Miner
)

// Default 2KiB sector for the network version
proofType, err := miner.SealProofTypeFromSectorSize(2<<10, n.genesis.version)
require.NoError(n.t, err)

// create the preseal commitment.
if n.options.mockProofs {
genm, k, err = mockstorage.PreSeal(abi.RegisteredSealProof_StackedDrg2KiBV1, actorAddr, sectors)
genm, k, err = mockstorage.PreSeal(proofType, actorAddr, sectors)
} else {
genm, k, err = seed.PreSeal(actorAddr, abi.RegisteredSealProof_StackedDrg2KiBV1, 0, sectors, tdir, []byte("make genesis mem random"), nil, true)
genm, k, err = seed.PreSeal(actorAddr, proofType, 0, sectors, tdir, []byte("make genesis mem random"), nil, true)
}
require.NoError(n.t, err)

Expand All @@ -237,7 +249,7 @@ func (n *Ensemble) Miner(miner *TestMiner, full *TestFullNode, opts ...NodeOpt)
rl, err := net.Listen("tcp", "127.0.0.1:")
require.NoError(n.t, err)

*miner = TestMiner{
*minerNode = TestMiner{
t: n.t,
ActorAddr: actorAddr,
OwnerKey: ownerKey,
Expand All @@ -247,10 +259,10 @@ func (n *Ensemble) Miner(miner *TestMiner, full *TestFullNode, opts ...NodeOpt)
RemoteListener: rl,
}

miner.Libp2p.PeerID = peerId
miner.Libp2p.PrivKey = privkey
minerNode.Libp2p.PeerID = peerId
minerNode.Libp2p.PrivKey = privkey

n.inactive.miners = append(n.inactive.miners, miner)
n.inactive.miners = append(n.inactive.miners, minerNode)

return n
}
Expand Down Expand Up @@ -283,6 +295,9 @@ func (n *Ensemble) Start() *Ensemble {

// so that we subscribe to pubsub topics immediately
node.Override(new(dtypes.Bootstrapper), dtypes.Bootstrapper(true)),

// upgrades
node.Override(new(stmgr.UpgradeSchedule), n.options.upgradeSchedule),
}

// append any node builder options.
Expand Down Expand Up @@ -510,6 +525,9 @@ func (n *Ensemble) Start() *Ensemble {
scfg.Storage.ResourceFiltering = sectorstorage.ResourceFilteringDisabled
return scfg.Storage
}),

// upgrades
node.Override(new(stmgr.UpgradeSchedule), n.options.upgradeSchedule),
}

// append any node builder options.
Expand Down Expand Up @@ -693,7 +711,7 @@ func (n *Ensemble) generateGenesis() *genesis.Template {
}

templ := &genesis.Template{
NetworkVersion: network.Version0,
NetworkVersion: n.genesis.version,
Accounts: n.genesis.accounts,
Miners: n.genesis.miners,
NetworkName: "test",
Expand Down
8 changes: 8 additions & 0 deletions itests/kit/ensemble_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"time"

"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/stmgr"
"github.com/filecoin-project/lotus/chain/wallet"
)

Expand All @@ -19,10 +21,16 @@ type ensembleOpts struct {
verifiedRoot genesisAccount
accounts []genesisAccount
mockProofs bool

upgradeSchedule stmgr.UpgradeSchedule
}

var DefaultEnsembleOpts = ensembleOpts{
pastOffset: 10000000 * time.Second, // time sufficiently in the past to trigger catch-up mining.
upgradeSchedule: stmgr.UpgradeSchedule{{
Height: -1,
Network: build.NewestNetworkVersion,
}},
}

// MockProofs activates mock proofs for the entire ensemble.
Expand Down
58 changes: 58 additions & 0 deletions itests/kit/ensemble_opts_nv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package kit

import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/lotus/chain/stmgr"
)

func UpgradeSchedule(upgrades ...stmgr.Upgrade) EnsembleOpt {
return func(opts *ensembleOpts) error {
opts.upgradeSchedule = upgrades
return opts.upgradeSchedule.Validate()
}
}

// GenesisNetworkVersion sets the network version of genesis.
func GenesisNetworkVersion(nv network.Version) EnsembleOpt {
return UpgradeSchedule(stmgr.Upgrade{
Network: nv,
Height: -1,
})
}

func SDRUpgradeAt(calico, persian abi.ChainEpoch) EnsembleOpt {
return UpgradeSchedule(stmgr.Upgrade{
Network: network.Version6,
Height: -1,
}, stmgr.Upgrade{
Network: network.Version7,
Height: calico,
Migration: stmgr.UpgradeCalico,
}, stmgr.Upgrade{
Network: network.Version8,
Height: persian,
})
}

func LatestActorsAt(upgradeHeight abi.ChainEpoch) EnsembleOpt {
return UpgradeSchedule(stmgr.Upgrade{
Network: network.Version12,
Height: -1,
}, stmgr.Upgrade{
Network: network.Version13,
Height: upgradeHeight,
Migration: stmgr.UpgradeActorsV5,
})
}

func TurboUpgradeAt(upgradeHeight abi.ChainEpoch) EnsembleOpt {
return UpgradeSchedule(stmgr.Upgrade{
Network: network.Version11,
Height: -1,
}, stmgr.Upgrade{
Network: network.Version12,
Height: upgradeHeight,
Migration: stmgr.UpgradeActorsV4,
})
}
90 changes: 0 additions & 90 deletions itests/kit/node_opts_nv.go

This file was deleted.

6 changes: 4 additions & 2 deletions itests/sdr_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ func TestSDRUpgrade(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

opts := kit.ConstructorOpts(kit.SDRUpgradeAt(500, 1000))
client, miner, ens := kit.EnsembleMinimal(t, kit.MockProofs(), opts)
client, miner, ens := kit.EnsembleMinimal(t,
kit.MockProofs(),
kit.SDRUpgradeAt(500, 1000),
)
ens.InterconnectAll()

build.Clock.Sleep(time.Second)
Expand Down
Loading

0 comments on commit faf893e

Please sign in to comment.