diff options
author | Determinant <[email protected]> | 2019-09-26 16:16:56 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2019-09-26 16:16:56 -0400 |
commit | a96fc7a942fb6f0a9da5b5bf9c84a98af42a24dc (patch) | |
tree | 8cb685aa6df55f15758e93ffe24b6c5d075859a5 /miner/worker.go | |
parent | 2e0b38c332a3ab4e11b97a38ff6d8427a3d96215 (diff) |
remove 1s limit from block generation; more API
Diffstat (limited to 'miner/worker.go')
-rw-r--r-- | miner/worker.go | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/miner/worker.go b/miner/worker.go index 8dd2aff..11f3f71 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -26,7 +26,6 @@ import ( "sync" "sync/atomic" "time" - //"fmt" "github.com/ava-labs/go-ethereum/common" "github.com/ava-labs/go-ethereum/consensus" @@ -124,7 +123,9 @@ type intervalAdjust struct { } type MinerCallbacks struct { - OnSeal func(*types.Block) error + OnSealFinish func(*types.Block) error + OnSealDrop func(*types.Block) + OnHeaderNew func(*types.Header) } // worker is the main object which takes care of submitting new work to consensus engine @@ -558,6 +559,10 @@ func (w *worker) taskLoop() { // Reject duplicate sealing work due to resubmitting. sealHash := w.engine.SealHash(task.block.Header()) if sealHash == prev { + log.Warn("Reject duplicate sealing work due to resubmitting.") + if w.minerCallbacks.OnSealDrop != nil { + w.minerCallbacks.OnSealDrop(task.block) + } continue } // Interrupt previous sealing operation @@ -565,6 +570,9 @@ func (w *worker) taskLoop() { stopCh, prev = make(chan struct{}), sealHash if w.skipSealHook != nil && w.skipSealHook(task) { + if w.minerCallbacks.OnSealDrop != nil { + w.minerCallbacks.OnSealDrop(task.block) + } continue } w.pendingMu.Lock() @@ -636,8 +644,8 @@ func (w *worker) resultLoop() { } log.Info("Successfully sealed new block", "number", block.Number(), "sealhash", sealhash, "hash", hash, "elapsed", common.PrettyDuration(time.Since(task.createdAt))) - if w.minerCallbacks.OnSeal != nil { - w.minerCallbacks.OnSeal(block) + if w.minerCallbacks.OnSealFinish != nil { + w.minerCallbacks.OnSealFinish(block) } // Broadcast the block and announce chain insertion event @@ -883,7 +891,8 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64) parent := w.chain.CurrentBlock() if parent.Time() >= uint64(timestamp) { - timestamp = int64(parent.Time() + 1) + //timestamp = int64(parent.Time() + 1) + timestamp = int64(parent.Time()) } // this will ensure we're not going off too far in the future if now := time.Now().Unix(); timestamp > now+1 { @@ -925,6 +934,9 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64) } } } + if w.minerCallbacks.OnHeaderNew != nil { + w.minerCallbacks.OnHeaderNew(header) + } // Could potentially happen if starting to mine in an odd state. err := w.makeCurrent(parent, header) if err != nil { |