Skip to content

Commit fbfe758

Browse files
authored
Merge pull request #253 from ipfs-force-community/fix/last-work
fix: ignore lastWork when selecting the best mining candidate
2 parents f577ce5 + 1907484 commit fbfe758

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

miner/multiminer.go

+8-25
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func (m *Miner) mine(ctx context.Context) {
344344
if err := m.sf.PutBlock(ctx, &sharedTypes.BlockHeader{
345345
Height: base.TipSet.Height() + base.NullRounds + 1,
346346
Miner: res.addr,
347-
}, base.TipSet.Height()+base.NullRounds, time.Time{}, types.ChainForked); err != nil {
347+
}, base.TipSet.Height(), time.Time{}, types.ChainForked); err != nil {
348348
log.Errorf("failed to record chain forked: %s", err)
349349
}
350350

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

470-
go m.tryGetBeacon(ctx, *base)
471-
472470
// Wait until the next epoch, plus the propagation delay, so a new tipset
473471
// has enough time to form.
474472
m.untilNextEpoch(base)
475473

476474
if len(winPoSts) == 0 {
477475
base.NullRounds++
478476
}
477+
478+
go m.tryGetBeacon(ctx, *base)
479479
}
480480
}
481481

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

494-
round := head.Height() + 1
494+
round := head.Height() + base.NullRounds + 1
495495
nodes := m.submitNodes
496496

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

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

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

785-
if m.lastWork != nil {
786-
if m.lastWork.TipSet.Equals(bts) {
787-
return m.lastWork, nil
788-
}
789-
790-
btsw, err := m.api.ChainTipSetWeight(ctx, bts.Key())
791-
if err != nil {
792-
return nil, err
793-
}
794-
ltsw, err := m.api.ChainTipSetWeight(ctx, m.lastWork.TipSet.Key())
795-
if err != nil {
796-
m.lastWork = nil
797-
return nil, err
798-
}
799-
800-
if sharedTypes.BigCmp(btsw, ltsw) <= 0 {
801-
return m.lastWork, nil
802-
}
785+
if m.lastWork == nil || !m.lastWork.TipSet.Equals(bts) {
786+
m.lastWork = &MiningBase{TipSet: bts}
803787
}
804788

805-
m.lastWork = &MiningBase{TipSet: bts}
806789
return m.lastWork, nil
807790
}
808791

0 commit comments

Comments
 (0)