Skip to content

feat(f3): prefetch the power table of every parent tipset #13107

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions chain/lf3/ec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/filecoin-project/go-f3/gpbft"
"github.com/filecoin-project/go-state-types/abi"

"github.com/filecoin-project/lotus/build/buildconstants"
"github.com/filecoin-project/lotus/chain"
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/actors/builtin/power"
Expand Down Expand Up @@ -95,6 +96,29 @@ func (ts *f3TipSet) Timestamp() time.Time {
return time.Time{}
}

func (ec *ecWrapper) runPrefetcher(ctx context.Context) {
// We have a loop here because we'll be automatically unsubscribed if we're too slow.
for {
headChanges := ec.chainStore.SubHeadChanges(ctx)
for changes := range headChanges {
for _, head := range changes {
if head.Type == store.HCRevert {
continue
}
// We do one job at a time because we're just pre-fetching here. If,
// e.g., we end up in "catch up" mode, we'll be unsubscribed (too
// slow) then we'll try again after we wait for one block.
_, _ = ec.getPowerTableLotusTSK(ctx, head.Val.Parents())
}
}
select {
case <-time.After(time.Duration(buildconstants.BlockDelaySecs) * time.Second):
case <-ctx.Done():
return
}
}
}

// GetTipsetByEpoch should return a tipset before the one requested if the requested
// tipset does not exist due to null epochs
func (ec *ecWrapper) GetTipsetByEpoch(ctx context.Context, epoch int64) (ec.TipSet, error) {
Expand Down
26 changes: 22 additions & 4 deletions chain/lf3/f3.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,38 @@ func New(mctx helpers.MetricsCtx, lc fx.Lifecycle, params F3Params) (*F3, error)
OnStop: fff.inner.Stop,
})

// Start signing F3 messages.
lCtx, cancel := context.WithCancel(mctx)
doneCh := make(chan struct{})

// start EC wrapper power-table prefetch logic.
donePrefetchingCh := make(chan struct{})
lc.Append(fx.Hook{
OnStart: func(context.Context) error {
go func() {
defer close(donePrefetchingCh)
ec.runPrefetcher(lCtx)
}()
return nil
},
OnStop: func(context.Context) error {
cancel()
<-donePrefetchingCh
return nil
},
})

// Start signing F3 messages.
doneSigningCh := make(chan struct{})
lc.Append(fx.Hook{
OnStart: func(context.Context) error {
go func() {
defer close(doneCh)
defer close(doneSigningCh)
fff.runSigningLoop(lCtx)
}()
return nil
},
OnStop: func(context.Context) error {
cancel()
<-doneCh
<-doneSigningCh
return nil
},
})
Expand Down
Loading