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: add warning for PropagationDelaySecs #234

Merged
merged 2 commits into from
Nov 9, 2023
Merged
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
20 changes: 18 additions & 2 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ var initCmd = &cli.Command{
return err
}

if err := storageMinerInit(cctx, r, &fullnode); err != nil {
networkParams, err := fullNodeAPI.StateGetNetworkParams(ctx)
if err != nil {
return err
}

if err := storageMinerInit(cctx, r, &fullnode, networkParams.BlockDelaySecs); err != nil {
log.Errorf("Failed to initialize sophon-miner: %+v", err)
path, err := homedir.Expand(repoPath)
if err != nil {
Expand All @@ -133,7 +138,7 @@ var initCmd = &cli.Command{
},
}

func storageMinerInit(cctx *cli.Context, r repo.Repo, fn *config.APIInfo) error {
func storageMinerInit(cctx *cli.Context, r repo.Repo, fn *config.APIInfo, blockDelay uint64) error {
lr, err := r.Lock()
if err != nil {
return err
Expand Down Expand Up @@ -180,6 +185,17 @@ func storageMinerInit(cctx *cli.Context, r repo.Repo, fn *config.APIInfo) error
cfg.API.ListenAddress = ma.String()
cfg.SlashFilter.Type = sfType
cfg.SlashFilter.MySQL.Conn = cctx.String("mysql-conn")

// set the default value of PropagationDelaySecs based on experience.
switch blockDelay {
case 30:
cfg.PropagationDelaySecs = 12
case 4:
cfg.PropagationDelaySecs = 1
default:
cfg.PropagationDelaySecs = blockDelay / 2
}

}); err != nil {
return fmt.Errorf("modify config failed: %w", err)
}
Expand Down
19 changes: 16 additions & 3 deletions miner/multiminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,16 +595,29 @@ func (m *Miner) getLatestBase(ctx context.Context) (*MiningBase, time.Duration,
var onDone func(bool, abi.ChainEpoch, error)
var injectNulls abi.ChainEpoch

// overlapCount is used to avoid getting stuck in an endless loop
overlapCount := 0

for {
prebase, err := m.GetBestMiningCandidate(ctx)
if err != nil {
return nil, time.Second * 5, fmt.Errorf("get best mining candidate: %w", err)
}

if base != nil && base.TipSet.Height() == prebase.TipSet.Height() && base.NullRounds == prebase.NullRounds {
base = prebase
break
if base != nil {
if base.TipSet.Height() == prebase.TipSet.Height() && base.NullRounds == prebase.NullRounds {
base = prebase
break
} else {
if overlapCount >= 5 {
log.Warnf("wait to long (about %d epochs) to get mining base, please check your config of PropagationDelaySecs and network", base.TipSet.Height()+base.NullRounds-prebase.TipSet.Height()+prebase.NullRounds)
overlapCount = 0
} else {
overlapCount++
}
}
}

if base != nil {
onDone(false, 0, nil)
}
Expand Down
Loading