Skip to content

Commit

Permalink
Merge pull request #253 from ipfs-force-community/fix/last-work
Browse files Browse the repository at this point in the history
fix: ignore lastWork when selecting the best mining candidate
  • Loading branch information
Vladmair authored Dec 12, 2024
2 parents f577ce5 + 1907484 commit fbfe758
Showing 1 changed file with 8 additions and 25 deletions.
33 changes: 8 additions & 25 deletions miner/multiminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func (m *Miner) mine(ctx context.Context) {
if err := m.sf.PutBlock(ctx, &sharedTypes.BlockHeader{
Height: base.TipSet.Height() + base.NullRounds + 1,
Miner: res.addr,
}, base.TipSet.Height()+base.NullRounds, time.Time{}, types.ChainForked); err != nil {
}, base.TipSet.Height(), time.Time{}, types.ChainForked); err != nil {
log.Errorf("failed to record chain forked: %s", err)
}

Expand Down Expand Up @@ -467,15 +467,15 @@ func (m *Miner) mine(ctx context.Context) {
log.Info("no block and increase nullround")
}

go m.tryGetBeacon(ctx, *base)

// Wait until the next epoch, plus the propagation delay, so a new tipset
// has enough time to form.
m.untilNextEpoch(base)

if len(winPoSts) == 0 {
base.NullRounds++
}

go m.tryGetBeacon(ctx, *base)
}
}

Expand All @@ -491,7 +491,7 @@ func (m *Miner) tryGetBeacon(ctx context.Context, base MiningBase) {
return
}

round := head.Height() + 1
round := head.Height() + base.NullRounds + 1
nodes := m.submitNodes

log.Infof("try get beacon at: %d", round)
Expand Down Expand Up @@ -547,9 +547,9 @@ func (m *Miner) broadCastBlock(ctx context.Context, base MiningBase, bm *sharedT
return
}

if err := m.sf.MinedBlock(ctx, bm.Header, base.TipSet.Height()+base.NullRounds); err != nil {
if err := m.sf.MinedBlock(ctx, bm.Header, base.TipSet.Height()); err != nil {
log.Errorf("<!!> SLASH FILTER ERROR: %s", err)
if err = m.sf.PutBlock(ctx, bm.Header, base.TipSet.Height()+base.NullRounds, time.Time{}, types.Error); err != nil {
if err = m.sf.PutBlock(ctx, bm.Header, base.TipSet.Height(), time.Time{}, types.Error); err != nil {
log.Errorf("failed to put block: %s", err)
}

Expand Down Expand Up @@ -782,27 +782,10 @@ func (m *Miner) GetBestMiningCandidate(ctx context.Context) (*MiningBase, error)
return nil, err
}

if m.lastWork != nil {
if m.lastWork.TipSet.Equals(bts) {
return m.lastWork, nil
}

btsw, err := m.api.ChainTipSetWeight(ctx, bts.Key())
if err != nil {
return nil, err
}
ltsw, err := m.api.ChainTipSetWeight(ctx, m.lastWork.TipSet.Key())
if err != nil {
m.lastWork = nil
return nil, err
}

if sharedTypes.BigCmp(btsw, ltsw) <= 0 {
return m.lastWork, nil
}
if m.lastWork == nil || !m.lastWork.TipSet.Equals(bts) {
m.lastWork = &MiningBase{TipSet: bts}
}

m.lastWork = &MiningBase{TipSet: bts}
return m.lastWork, nil
}

Expand Down

0 comments on commit fbfe758

Please sign in to comment.