Skip to content

Commit

Permalink
miner, wemix: work logging before registering mined block
Browse files Browse the repository at this point in the history
  • Loading branch information
sadoci committed Oct 25, 2022
1 parent 827963f commit 896b8ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
11 changes: 5 additions & 6 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,11 @@ func (w *worker) commitEx(env *environment, interval func(), update bool, start
}
logs = append(logs, receipt.Logs...)
}
if !wemixminer.IsPoW() {
if err = wemixminer.ReleaseMiningToken(sealedBlock.Number(), sealedBlock.Hash(), sealedBlock.ParentHash()); err != nil {
return err
}
}
// Commit block and state to database.
_, err := w.chain.WriteBlockAndSetHead(sealedBlock, receipts, logs, env.state, true)
if err != nil {
Expand All @@ -1767,12 +1772,6 @@ func (w *worker) commitEx(env *environment, interval func(), update bool, start
log.Info("Successfully sealed new block", "number", sealedBlock.Number(), "sealhash", sealhash, "hash", hash,
"elapsed", common.PrettyDuration(time.Since(createdAt)))

if !wemixminer.IsPoW() {
if err = wemixminer.ReleaseMiningToken(sealedBlock.Number(), sealedBlock.Hash(), sealedBlock.ParentHash()); err != nil {
return err
}
}

// Broadcast the block and announce chain insertion event
w.mux.Post(core.NewMinedBlockEvent{Block: sealedBlock})

Expand Down
15 changes: 11 additions & 4 deletions wemix/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,17 @@ func releaseMiningToken(height *big.Int, hash, parentHash common.Hash) error {
if lck == nil || lck.ttl() < 0 {
return wemixminer.ErrNotInitialized
}
ctx, cancel := context.WithTimeout(context.Background(),
admin.etcd.Server.Cfg.ReqTimeout())
defer cancel()
err := lck.releaseTokenSync(ctx, height, hash, parentHash)
var err error
for range []int{1, 2} {
// retry in case it fails to release due to leader changes, etc.
ctx, cancel := context.WithTimeout(context.Background(),
admin.etcd.Server.Cfg.ReqTimeout())
err = lck.releaseTokenSync(ctx, height, hash, parentHash)
cancel()
if err == nil {
break
}
}

// invalidate the saved token
miningToken.Store(&WemixToken{})
Expand Down

0 comments on commit 896b8ef

Please sign in to comment.