Skip to content

Commit

Permalink
Merge pull request #234 from ipfs-force-community/feat/warning-for-a-…
Browse files Browse the repository at this point in the history
…too-big-PropagationDelaySecs

feat: add warning for PropagationDelaySecs
  • Loading branch information
simlecode authored Nov 9, 2023
2 parents 3d6c7c6 + d8c2508 commit d1500b7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
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

0 comments on commit d1500b7

Please sign in to comment.