unit test and code comments

This commit is contained in:
Andrew Jackson (Ajax) 2023-11-15 10:04:04 -06:00
parent f80a5bcebf
commit ac2306beef
4 changed files with 20 additions and 15 deletions

View File

@ -69,7 +69,6 @@ It will not send any messages to the chain. Since it can compute any deadline, o
if err != nil { if err != nil {
return err return err
} }
defer deps.fullCloser()
wdPostTask, wdPoStSubmitTask, derlareRecoverTask, err := provider.WindowPostScheduler(ctx, deps.cfg.Fees, deps.cfg.Proving, deps.full, deps.verif, deps.lw, wdPostTask, wdPoStSubmitTask, derlareRecoverTask, err := provider.WindowPostScheduler(ctx, deps.cfg.Fees, deps.cfg.Proving, deps.full, deps.verif, deps.lw,
deps.as, deps.maddrs, deps.db, deps.stor, deps.si, deps.cfg.Subsystems.WindowPostMaxTasks) deps.as, deps.maddrs, deps.db, deps.stor, deps.si, deps.cfg.Subsystems.WindowPostMaxTasks)

View File

@ -23,7 +23,6 @@ import (
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-jsonrpc"
"github.com/filecoin-project/go-jsonrpc/auth" "github.com/filecoin-project/go-jsonrpc/auth"
"github.com/filecoin-project/go-statestore" "github.com/filecoin-project/go-statestore"
@ -116,6 +115,12 @@ var runCmd = &cli.Command{
tag.Insert(metrics.Commit, build.CurrentCommit), tag.Insert(metrics.Commit, build.CurrentCommit),
tag.Insert(metrics.NodeType, "provider"), tag.Insert(metrics.NodeType, "provider"),
) )
shutdownChan := make(chan struct{})
ctx, ctxclose := context.WithCancel(ctx)
go func() {
<-shutdownChan
ctxclose()
}()
// Register all metric views // Register all metric views
/* /*
if err := view.Register( if err := view.Register(
@ -133,14 +138,12 @@ var runCmd = &cli.Command{
} }
} }
shutdownChan := make(chan struct{})
deps, err := getDeps(ctx, cctx) deps, err := getDeps(ctx, cctx)
if err != nil { if err != nil {
return err return err
} }
cfg, db, full, verif, lw, as, maddrs, stor, si, localStore := deps.cfg, deps.db, deps.full, deps.verif, deps.lw, deps.as, deps.maddrs, deps.stor, deps.si, deps.localStore cfg, db, full, verif, lw, as, maddrs, stor, si, localStore := deps.cfg, deps.db, deps.full, deps.verif, deps.lw, deps.as, deps.maddrs, deps.stor, deps.si, deps.localStore
defer deps.fullCloser()
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
///// Task Selection ///// Task Selection
@ -206,7 +209,6 @@ var runCmd = &cli.Command{
//node.ShutdownHandler{Component: "provider", StopFunc: stop}, //node.ShutdownHandler{Component: "provider", StopFunc: stop},
<-finishCh <-finishCh
return nil return nil
}, },
} }
@ -256,7 +258,6 @@ type Deps struct {
cfg *config.LotusProviderConfig cfg *config.LotusProviderConfig
db *harmonydb.DB db *harmonydb.DB
full api.FullNode full api.FullNode
fullCloser jsonrpc.ClientCloser
verif storiface.Verifier verif storiface.Verifier
lw *sealer.LocalWorker lw *sealer.LocalWorker
as *ctladdr.AddressSelector as *ctladdr.AddressSelector
@ -319,14 +320,19 @@ func getDeps(ctx context.Context, cctx *cli.Context) (*Deps, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer func() { _ = j.Close() }()
full, fullCloser, err := cliutil.GetFullNodeAPIV1LotusProvider(cctx, cfg.Apis.ChainApiInfo) full, fullCloser, err := cliutil.GetFullNodeAPIV1LotusProvider(cctx, cfg.Apis.ChainApiInfo)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer fullCloser()
go func() {
select {
case <-ctx.Done():
fullCloser()
_ = j.Close()
}
}()
sa, err := StorageAuth(cfg.Apis.StorageRPCSecret) sa, err := StorageAuth(cfg.Apis.StorageRPCSecret)
if err != nil { if err != nil {
return nil, xerrors.Errorf(`'%w' while parsing the config toml's return nil, xerrors.Errorf(`'%w' while parsing the config toml's
@ -380,7 +386,6 @@ Get it with: jq .PrivateKey ~/.lotus-miner/keystore/MF2XI2BNNJ3XILLQOJUXMYLUMU`,
cfg, cfg,
db, db,
full, full,
fullCloser,
verif, verif,
lw, lw,
as, as,

View File

@ -3,6 +3,7 @@ package resources
import ( import (
"bytes" "bytes"
"context" "context"
"fmt"
"os/exec" "os/exec"
"regexp" "regexp"
"runtime" "runtime"
@ -94,8 +95,8 @@ func Register(db *harmonydb.DB, hostnameAndPort string) (*Reg, error) {
func CleanupMachines(ctx context.Context, db *harmonydb.DB) int { func CleanupMachines(ctx context.Context, db *harmonydb.DB) int {
ct, err := db.Exec(ctx, ct, err := db.Exec(ctx,
`DELETE FROM harmony_machines WHERE last_contact < CURRENT_TIMESTAMP - INTERVAL $1 MILLISECONDS`, `DELETE FROM harmony_machines WHERE last_contact < CURRENT_TIMESTAMP - INTERVAL $1 `,
LOOKS_DEAD_TIMEOUT.Milliseconds()) // ms enables unit testing to change timeout. fmt.Sprintf("%d MILLISECOND", LOOKS_DEAD_TIMEOUT.Milliseconds())) // ms enables unit testing to change timeout.
if err != nil { if err != nil {
logger.Warn("unable to delete old machines: ", err) logger.Warn("unable to delete old machines: ", err)
} }

View File

@ -74,10 +74,10 @@ type WdPostTask struct {
} }
type wdTaskIdentity struct { type wdTaskIdentity struct {
SpID uint64 SpID uint64 `db:"sp_id"`
ProvingPeriodStart abi.ChainEpoch ProvingPeriodStart abi.ChainEpoch `db:"proving_period_start"`
DeadlineIndex uint64 DeadlineIndex uint64 `db:"deadline_index"`
PartitionIndex uint64 PartitionIndex uint64 `db:"partition_index"`
} }
func NewWdPostTask(db *harmonydb.DB, func NewWdPostTask(db *harmonydb.DB,