aboutsummaryrefslogtreecommitdiff
path: root/miner
diff options
context:
space:
mode:
Diffstat (limited to 'miner')
-rw-r--r--miner/miner.go5
-rw-r--r--miner/worker.go22
2 files changed, 20 insertions, 7 deletions
diff --git a/miner/miner.go b/miner/miner.go
index 60a5d39..583e458 100644
--- a/miner/miner.go
+++ b/miner/miner.go
@@ -22,6 +22,7 @@ import (
"math/big"
"time"
+ myparams "github.com/ava-labs/coreth/params"
"github.com/ava-labs/go-ethereum/common"
"github.com/ava-labs/go-ethereum/common/hexutil"
"github.com/ava-labs/go-ethereum/consensus"
@@ -80,8 +81,8 @@ func (self *Miner) HashRate() uint64 {
}
func (self *Miner) SetExtra(extra []byte) error {
- if uint64(len(extra)) > params.MaximumExtraDataSize {
- return fmt.Errorf("Extra exceeds max length. %d > %v", len(extra), params.MaximumExtraDataSize)
+ if uint64(len(extra)) > myparams.MaximumExtraDataSize {
+ return fmt.Errorf("Extra exceeds max length. %d > %v", len(extra), myparams.MaximumExtraDataSize)
}
self.w.setExtra(extra)
return nil
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 {