Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement lotus-sim #6406

Merged
merged 94 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from 85 commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
e2f5c49
feat: implement lotus-sim
Stebalien May 19, 2021
8000dec
feat(lotus-sim): add command to list pending upgrades
Stebalien Jun 7, 2021
be9e30e
fix(lotus-sim): rename step to run
Stebalien Jun 7, 2021
b7bfc06
feat(lotus-sim): add an info command
Stebalien Jun 7, 2021
2f7d7ae
feat(lotus-sim): refactor and document
Stebalien Jun 8, 2021
7925b69
doc(lotus-sim): document block generation logic
Stebalien Jun 8, 2021
0ccf716
fix(lotus-sim): refactor miner state loading
Stebalien Jun 8, 2021
2e4f526
fix(lotus-sim): skip (and log) missing/expired pre-commits
Stebalien Jun 8, 2021
82019ce
fix(lotus-sim): correctly merge forward commit queue.
Stebalien Jun 8, 2021
5b31ae3
fix: test commit queue
Stebalien Jun 8, 2021
dfdafa3
fix(lotus-sim): pretend all messages are BLS
Stebalien Jun 8, 2021
0725019
feat(lotus-sim): completely pack block
Stebalien Jun 8, 2021
f9ebe30
test(lotus-sim): test commit-queue rollover
Stebalien Jun 8, 2021
a57c509
fix(lotus-sim): cleanup and document pre-commit filtering
Stebalien Jun 8, 2021
0faacbe
feat(lotus-sim): store start tipset
Stebalien Jun 8, 2021
5f6733f
feat(lotus-sim): expose StateManager from Simulation
Stebalien Jun 8, 2021
ccdd660
feat(lotus-sim): more stats
Stebalien Jun 8, 2021
c5dc67c
feat(lotus-sim): add a walk function
Stebalien Jun 8, 2021
8410b0f
feat(lotus-sim): add a feature to copy/rename simulation.
Stebalien Jun 8, 2021
4f0b9ee
fix(lotus-sim): check for slash in names on copy
Stebalien Jun 8, 2021
bb4753f
feat(lotus-sim): add commands to rename and copy
Stebalien Jun 8, 2021
77f0fee
chore(lotus-sim): fix comment about simulation block miner
Stebalien Jun 8, 2021
4578e0d
chore(lotus-sim): remove dead code
Stebalien Jun 8, 2021
e097ba8
feat(lotus-sim): wire up signal handler
Stebalien Jun 8, 2021
ba65a1b
chore(lotus-sim): rename stat to info
Stebalien Jun 8, 2021
747b3d3
fix(lotus-sim): skip miners without power when loading
Stebalien Jun 8, 2021
88af350
fix(lotus-sim): use global base-fee value
Stebalien Jun 9, 2021
0075abe
fix(vm): always specify an ActorErr when ApplyMessage fails.
Stebalien Jun 9, 2021
86e459f
feat(lotus-sim): return receipt
Stebalien Jun 9, 2021
e7b1e09
feat(multisig): expose ApproveReturn
Stebalien Jun 9, 2021
2b4f865
feat(lotus-sim): fund from a funding account
Stebalien Jun 9, 2021
868231a
fix(lotus-sim): don't take from the fund account when funding
Stebalien Jun 10, 2021
1802ae3
feat(lotus-sim): record timing information for pre/prove-commit packing
Stebalien Jun 10, 2021
2b77c17
chore(lotus-sim): fix import grouping
Stebalien Jun 10, 2021
dcdb0ab
feat(lotus-sim): profile on SIGUSR2
Stebalien Jun 10, 2021
936659d
feat(lotus-sim): print info on SIGUSR1
Stebalien Jun 10, 2021
4a80c83
fix(lotus-sim): fix spelling
Stebalien Jun 10, 2021
5766002
fix(lotus-sim): guard info with dashes
Stebalien Jun 10, 2021
a3f64e0
fix(lotus-sim): profile signal handling
Stebalien Jun 10, 2021
7a8bfd8
doc(lotus-sim): document signals
Stebalien Jun 10, 2021
977bf1c
fix(lotus-sim): write pprof profiles to a directory
Stebalien Jun 10, 2021
c18ca60
fix(lotus-sim): specify ErrWriter
Stebalien Jun 10, 2021
be713ec
fix(lotus-sim): we always fill the block with pre-commits
Stebalien Jun 10, 2021
783dc5a
fix(lotus-sim): fund multiple times
Stebalien Jun 10, 2021
8d734d8
fix(lotus-sim): log failed pre-commits and continue
Stebalien Jun 10, 2021
1644900
fix(lotus-sim): fix funding error check
Stebalien Jun 10, 2021
ca9eadd
Add gas info command
Jun 10, 2021
68593ce
fix(lotus-sim): obey context in walk
Stebalien Jun 10, 2021
3d3c26f
Add lookback limit
Jun 10, 2021
ab59474
fix(lotus-sim): count single prove-commits when computing efficiency
Stebalien Jun 10, 2021
500fae6
fix(lotus-sim): less indentation in info
Stebalien Jun 10, 2021
fbaffe8
fix(lotus-sim): return error from walk
Stebalien Jun 10, 2021
1df5445
feat(lotus-sim): make walk parallel
Stebalien Jun 10, 2021
d551f2b
feat(lotus-sim): print duration info in days
Stebalien Jun 10, 2021
707b3bf
fix(lotus-sim): refuse to start simulation with no miners
Stebalien Jun 10, 2021
985994c
feat(lotus-sim): add command for analyzing post stats over time
Stebalien Jun 10, 2021
2721279
fix(lotus-sim): describe info commands
Stebalien Jun 10, 2021
7dd58ef
Add quantiles and histogram
Jun 11, 2021
8a215df
fix(statetree): make StateTree.ForEach take layers into account
Stebalien Jun 11, 2021
52261fb
refactor(lotus-sim): enterprise grade
Stebalien Jun 12, 2021
f6043a0
feat(lotus-sim): measure daily power growth
Stebalien Jun 12, 2021
ec3f969
feat(lotus-sim): allow walking back past the start
Stebalien Jun 12, 2021
f9d2a23
fix(lotus-sim): correctly handle cancellation in walk
Stebalien Jun 12, 2021
0af7dcd
fix(lotus-sim): rename power to capacity
Stebalien Jun 12, 2021
63178ce
feat(lotus-sim): daily capacity growth
Stebalien Jun 12, 2021
8fffaa5
fix(lotus-sim): average over 2 days
Stebalien Jun 12, 2021
95cf577
fix(lotus-sim): really cancel walk immediately
Stebalien Jun 12, 2021
5d7b7ce
feat(lotus-sim): allow profile info
Stebalien Jun 12, 2021
22267eb
feat(lotus-sim): split info command file
Stebalien Jun 14, 2021
73ae192
feat(lotus-sim): state size command
Stebalien Jun 15, 2021
885062f
fix(lotus-sim): fix info state imports
Stebalien Jun 16, 2021
af33d69
fix(lotus-sim): don't close node on list
Stebalien Jun 16, 2021
e41f084
fix(lotus-sim): load prove-commits
Stebalien Jun 16, 2021
ec5fab0
feat(lotus-sim): log failing proofs
Stebalien Jun 16, 2021
28e6fa5
fix(lotus-sim): remove duplicate error handling
Stebalien Jun 16, 2021
ce29a0a
fix(lotus-sim): initialize commit queue
Stebalien Jun 16, 2021
f0d0b40
fix(lotus-sim): debug log mock
Stebalien Jun 16, 2021
a26cd5a
fix(lotus-sim): mark provecommit stage initialized
Stebalien Jun 16, 2021
bc2698a
fix(lotus-sim): simulate using realistic gas numbers
Stebalien Jun 16, 2021
2aedd82
fix(lotus-sim): correct window post batch sizes
Stebalien Jun 17, 2021
eb2b706
chore: fix lint errors in simulation
Stebalien Jun 18, 2021
b30b5dd
fix: move actors changes to template files
Stebalien Jun 18, 2021
eb0a15f
fix(genesis): set initial balances to 0
Stebalien Jun 18, 2021
2fdf49e
Add histogram and quantiles for message sizes
Jun 17, 2021
69a8a6b
fix(lotus-sim): lint
Stebalien Jun 18, 2021
d6abcff
fix(lotus-sim): apply code review from magik6k
Stebalien Jun 21, 2021
ffb63a9
fix(lotus-sim): make 'fund' easier to understand
Stebalien Jun 21, 2021
b5f9148
build(lotus-sim): add a makefile target
Stebalien Jun 21, 2021
80eba10
feat(lotus-sim): NewNode to construct a node without a repo
Stebalien Jun 21, 2021
c532b1b
fix(lotus-sim): remove unused field and function
Stebalien Jun 21, 2021
b7c36bc
fix(lotus-sim): make NewNode take a repo
Stebalien Jun 21, 2021
0b06de2
fix(lotus-sim): unembed Node from Simulation
Stebalien Jun 21, 2021
87c306f
feat(lotus-sim): use current power instead of lookback
Stebalien Jun 22, 2021
63e2caa
lint(lotus-sim): handle error
Stebalien Jun 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions chain/actors/builtin/miner/actor.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner"
miner3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner"
miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner"
{{range .versions}}
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
{{end}}
Expand Down Expand Up @@ -97,9 +98,13 @@ type State interface {
FindSector(abi.SectorNumber) (*SectorLocation, error)
GetSectorExpiration(abi.SectorNumber) (*SectorExpiration, error)
GetPrecommittedSector(abi.SectorNumber) (*SectorPreCommitOnChainInfo, error)
ForEachPrecommittedSector(func(SectorPreCommitOnChainInfo) error) error
LoadSectors(sectorNos *bitfield.BitField) ([]*SectorOnChainInfo, error)
NumLiveSectors() (uint64, error)
IsAllocated(abi.SectorNumber) (bool, error)
// UnallocatedSectorNumbers returns up to count unallocated sector numbers (or less than
// count if there aren't enough).
UnallocatedSectorNumbers(count int) ([]abi.SectorNumber, error)

// Note that ProvingPeriodStart is deprecated and will be renamed / removed in a future version of actors
GetProvingPeriodStart() (abi.ChainEpoch, error)
Expand Down Expand Up @@ -176,6 +181,7 @@ type DeclareFaultsRecoveredParams = miner0.DeclareFaultsRecoveredParams
type SubmitWindowedPoStParams = miner0.SubmitWindowedPoStParams
type ProveCommitSectorParams = miner0.ProveCommitSectorParams
type DisputeWindowedPoStParams = miner3.DisputeWindowedPoStParams
type ProveCommitAggregateParams = miner5.ProveCommitAggregateParams

func PreferredSealProofTypeFromWindowPoStType(nver network.Version, proof abi.RegisteredPoStProof) (abi.RegisteredSealProof, error) {
// We added support for the new proofs in network version 7, and removed support for the old
Expand Down
6 changes: 6 additions & 0 deletions chain/actors/builtin/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner"
miner3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner"
miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner"

builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"

Expand Down Expand Up @@ -156,9 +157,13 @@ type State interface {
FindSector(abi.SectorNumber) (*SectorLocation, error)
GetSectorExpiration(abi.SectorNumber) (*SectorExpiration, error)
GetPrecommittedSector(abi.SectorNumber) (*SectorPreCommitOnChainInfo, error)
ForEachPrecommittedSector(func(SectorPreCommitOnChainInfo) error) error
LoadSectors(sectorNos *bitfield.BitField) ([]*SectorOnChainInfo, error)
NumLiveSectors() (uint64, error)
IsAllocated(abi.SectorNumber) (bool, error)
// UnallocatedSectorNumbers returns up to count unallocated sector numbers (or less than
// count if there aren't enough).
UnallocatedSectorNumbers(count int) ([]abi.SectorNumber, error)

// Note that ProvingPeriodStart is deprecated and will be renamed / removed in a future version of actors
GetProvingPeriodStart() (abi.ChainEpoch, error)
Expand Down Expand Up @@ -235,6 +240,7 @@ type DeclareFaultsRecoveredParams = miner0.DeclareFaultsRecoveredParams
type SubmitWindowedPoStParams = miner0.SubmitWindowedPoStParams
type ProveCommitSectorParams = miner0.ProveCommitSectorParams
type DisputeWindowedPoStParams = miner3.DisputeWindowedPoStParams
type ProveCommitAggregateParams = miner5.ProveCommitAggregateParams

func PreferredSealProofTypeFromWindowPoStType(nver network.Version, proof abi.RegisteredPoStProof) (abi.RegisteredSealProof, error) {
// We added support for the new proofs in network version 7, and removed support for the old
Expand Down
67 changes: 65 additions & 2 deletions chain/actors/builtin/miner/state.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
{{end}}
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-bitfield"
rle "github.com/filecoin-project/go-bitfield/rle"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/dline"
"github.com/ipfs/go-cid"
Expand Down Expand Up @@ -209,6 +210,26 @@ func (s *state{{.v}}) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCom
return &ret, nil
}

func (s *state{{.v}}) ForEachPrecommittedSector(cb func(SectorPreCommitOnChainInfo) error) error {
{{if (ge .v 3) -}}
precommitted, err := adt{{.v}}.AsMap(s.store, s.State.PreCommittedSectors, builtin{{.v}}.DefaultHamtBitwidth)
{{- else -}}
precommitted, err := adt{{.v}}.AsMap(s.store, s.State.PreCommittedSectors)
{{- end}}
if err != nil {
return err
}

var info miner{{.v}}.SectorPreCommitOnChainInfo
if err := precommitted.ForEach(&info, func(_ string) error {
return cb(fromV{{.v}}SectorPreCommitOnChainInfo(info))
}); err != nil {
return err
}

return nil
}

func (s *state{{.v}}) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, error) {
sectors, err := miner{{.v}}.LoadSectors(s.store, s.State.Sectors)
if err != nil {
Expand Down Expand Up @@ -242,9 +263,15 @@ func (s *state{{.v}}) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo
return infos, nil
}

func (s *state{{.v}}) IsAllocated(num abi.SectorNumber) (bool, error) {
func (s *state{{.v}}) loadAllocatedSectorNumbers() (bitfield.BitField, error) {
var allocatedSectors bitfield.BitField
if err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors); err != nil {
err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors)
return allocatedSectors, err
}

func (s *state{{.v}}) IsAllocated(num abi.SectorNumber) (bool, error) {
allocatedSectors, err := s.loadAllocatedSectorNumbers()
if err != nil {
return false, err
}

Expand All @@ -255,6 +282,42 @@ func (s *state{{.v}}) GetProvingPeriodStart() (abi.ChainEpoch, error) {
return s.State.ProvingPeriodStart, nil
}

func (s *state{{.v}}) UnallocatedSectorNumbers(count int) ([]abi.SectorNumber, error) {
allocatedSectors, err := s.loadAllocatedSectorNumbers()
if err != nil {
return nil, err
}

allocatedRuns, err := allocatedSectors.RunIterator()
if err != nil {
return nil, err
}

unallocatedRuns, err := rle.Subtract(
&rle.RunSliceIterator{Runs: []rle.Run{ {Val: true, Len: abi.MaxSectorNumber} }},
allocatedRuns,
)
if err != nil {
return nil, err
}

iter, err := rle.BitsFromRuns(unallocatedRuns)
if err != nil {
return nil, err
}

sectors := make([]abi.SectorNumber, 0, count)
for iter.HasNext() && len(sectors) < count {
nextNo, err := iter.Next()
if err != nil {
return nil, err
}
sectors = append(sectors, abi.SectorNumber(nextNo))
}
magik6k marked this conversation as resolved.
Show resolved Hide resolved

return sectors, nil
}

func (s *state{{.v}}) LoadDeadline(idx uint64) (Deadline, error) {
dls, err := s.State.LoadDeadlines(s.store)
if err != nil {
Expand Down
63 changes: 61 additions & 2 deletions chain/actors/builtin/miner/v0.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-bitfield"
rle "github.com/filecoin-project/go-bitfield/rle"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/dline"
"github.com/ipfs/go-cid"
Expand Down Expand Up @@ -206,6 +207,22 @@ func (s *state0) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOn
return &ret, nil
}

func (s *state0) ForEachPrecommittedSector(cb func(SectorPreCommitOnChainInfo) error) error {
precommitted, err := adt0.AsMap(s.store, s.State.PreCommittedSectors)
if err != nil {
return err
}

var info miner0.SectorPreCommitOnChainInfo
if err := precommitted.ForEach(&info, func(_ string) error {
return cb(fromV0SectorPreCommitOnChainInfo(info))
}); err != nil {
return err
}

return nil
}

func (s *state0) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, error) {
sectors, err := miner0.LoadSectors(s.store, s.State.Sectors)
if err != nil {
Expand Down Expand Up @@ -239,9 +256,15 @@ func (s *state0) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, err
return infos, nil
}

func (s *state0) IsAllocated(num abi.SectorNumber) (bool, error) {
func (s *state0) loadAllocatedSectorNumbers() (bitfield.BitField, error) {
var allocatedSectors bitfield.BitField
if err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors); err != nil {
err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors)
return allocatedSectors, err
}

func (s *state0) IsAllocated(num abi.SectorNumber) (bool, error) {
allocatedSectors, err := s.loadAllocatedSectorNumbers()
if err != nil {
return false, err
}

Expand All @@ -252,6 +275,42 @@ func (s *state0) GetProvingPeriodStart() (abi.ChainEpoch, error) {
return s.State.ProvingPeriodStart, nil
}

func (s *state0) UnallocatedSectorNumbers(count int) ([]abi.SectorNumber, error) {
allocatedSectors, err := s.loadAllocatedSectorNumbers()
if err != nil {
return nil, err
}

allocatedRuns, err := allocatedSectors.RunIterator()
if err != nil {
return nil, err
}

unallocatedRuns, err := rle.Subtract(
&rle.RunSliceIterator{Runs: []rle.Run{{Val: true, Len: abi.MaxSectorNumber}}},
allocatedRuns,
)
if err != nil {
return nil, err
}

iter, err := rle.BitsFromRuns(unallocatedRuns)
if err != nil {
return nil, err
}

sectors := make([]abi.SectorNumber, 0, count)
for iter.HasNext() && len(sectors) < count {
nextNo, err := iter.Next()
if err != nil {
return nil, err
}
sectors = append(sectors, abi.SectorNumber(nextNo))
}

return sectors, nil
}

func (s *state0) LoadDeadline(idx uint64) (Deadline, error) {
dls, err := s.State.LoadDeadlines(s.store)
if err != nil {
Expand Down
63 changes: 61 additions & 2 deletions chain/actors/builtin/miner/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-bitfield"
rle "github.com/filecoin-project/go-bitfield/rle"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/dline"
"github.com/ipfs/go-cid"
Expand Down Expand Up @@ -204,6 +205,22 @@ func (s *state2) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOn
return &ret, nil
}

func (s *state2) ForEachPrecommittedSector(cb func(SectorPreCommitOnChainInfo) error) error {
precommitted, err := adt2.AsMap(s.store, s.State.PreCommittedSectors)
if err != nil {
return err
}

var info miner2.SectorPreCommitOnChainInfo
if err := precommitted.ForEach(&info, func(_ string) error {
return cb(fromV2SectorPreCommitOnChainInfo(info))
}); err != nil {
return err
}

return nil
}

func (s *state2) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, error) {
sectors, err := miner2.LoadSectors(s.store, s.State.Sectors)
if err != nil {
Expand Down Expand Up @@ -237,9 +254,15 @@ func (s *state2) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, err
return infos, nil
}

func (s *state2) IsAllocated(num abi.SectorNumber) (bool, error) {
func (s *state2) loadAllocatedSectorNumbers() (bitfield.BitField, error) {
var allocatedSectors bitfield.BitField
if err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors); err != nil {
err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors)
return allocatedSectors, err
}

func (s *state2) IsAllocated(num abi.SectorNumber) (bool, error) {
allocatedSectors, err := s.loadAllocatedSectorNumbers()
if err != nil {
return false, err
}

Expand All @@ -250,6 +273,42 @@ func (s *state2) GetProvingPeriodStart() (abi.ChainEpoch, error) {
return s.State.ProvingPeriodStart, nil
}

func (s *state2) UnallocatedSectorNumbers(count int) ([]abi.SectorNumber, error) {
allocatedSectors, err := s.loadAllocatedSectorNumbers()
if err != nil {
return nil, err
}

allocatedRuns, err := allocatedSectors.RunIterator()
if err != nil {
return nil, err
}

unallocatedRuns, err := rle.Subtract(
&rle.RunSliceIterator{Runs: []rle.Run{{Val: true, Len: abi.MaxSectorNumber}}},
allocatedRuns,
)
if err != nil {
return nil, err
}

iter, err := rle.BitsFromRuns(unallocatedRuns)
if err != nil {
return nil, err
}

sectors := make([]abi.SectorNumber, 0, count)
for iter.HasNext() && len(sectors) < count {
nextNo, err := iter.Next()
if err != nil {
return nil, err
}
sectors = append(sectors, abi.SectorNumber(nextNo))
}

return sectors, nil
}

func (s *state2) LoadDeadline(idx uint64) (Deadline, error) {
dls, err := s.State.LoadDeadlines(s.store)
if err != nil {
Expand Down
Loading