Skip to content

Commit 13c253f

Browse files
committed
miner: fix BlobSidecar.BlockHash for double signed blocks
1 parent 1ecd0e0 commit 13c253f

4 files changed

Lines changed: 18 additions & 5 deletions

File tree

core/types/block.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package types
1919

2020
import (
2121
"encoding/binary"
22+
"encoding/json"
2223
"fmt"
2324
"io"
2425
"math/big"
@@ -551,6 +552,14 @@ func (b *Block) WithSidecars(sidecars BlobSidecars) *Block {
551552
return block
552553
}
553554

555+
func (b *Block) DeepCopySidecars(sidecars BlobSidecars) {
556+
b.sidecars = make(BlobSidecars, len(sidecars))
557+
if len(sidecars) != 0 {
558+
buffer, _ := json.Marshal(sidecars)
559+
json.Unmarshal(buffer, &b.sidecars)
560+
}
561+
}
562+
554563
// Hash returns the keccak256 hash of b's header.
555564
// The hash is computed on the first call and cached thereafter.
556565
func (b *Block) Hash() common.Hash {

core/vote/vote_pool_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func newTestBackend() *testBackend {
7777
return &testBackend{eventMux: new(event.TypeMux)}
7878
}
7979
func (b *testBackend) IsMining() bool { return true }
80-
func (b *testBackend) VoteEnabled() bool { return true }
80+
func (b *testBackend) VoteEnabled() bool { return true }
8181
func (b *testBackend) EventMux() *event.TypeMux { return b.eventMux }
8282

8383
func (p *mockPOSA) GetJustifiedNumberAndHash(chain consensus.ChainHeaderReader, headers []*types.Header) (uint64, common.Hash, error) {

eth/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ func (s *Ethereum) StopMining() {
621621
}
622622

623623
func (s *Ethereum) IsMining() bool { return s.miner.Mining() }
624-
func (s *Ethereum) VoteEnabled() bool { return s.miner.VoteEnabled() }
624+
func (s *Ethereum) VoteEnabled() bool { return s.miner.VoteEnabled() }
625625
func (s *Ethereum) Miner() *miner.Miner { return s.miner }
626626

627627
func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager }

miner/worker.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,14 +691,18 @@ func (w *worker) resultLoop() {
691691
shadowHeader := block.Header()
692692
shadowHeader.Extra[0] = 'd'
693693
shadowHeader.Extra[1] = 's'
694-
shadowBlock := types.NewBlockWithHeader(shadowHeader).WithBody(block.Transactions(), block.Uncles()).WithWithdrawals(block.Withdrawals()).WithSidecars(block.Sidecars())
694+
shadowBlock := types.NewBlockWithHeader(shadowHeader).WithBody(block.Transactions(), block.Uncles()).WithWithdrawals(block.Withdrawals())
695+
shadowBlock.DeepCopySidecars(block.Sidecars())
695696
shadowBlock, err := p.AssembleSignature(shadowBlock)
696697
if err == nil {
697698
w.postBlock(shadowBlock, inturn)
698699
sealhash := w.engine.SealHash(shadowBlock.Header())
699700
hash := shadowBlock.Hash()
700701
log.Info("Successfully sealed new block", "number", shadowBlock.Number(), "sealhash", sealhash, "hash", hash,
701702
"elapsed", common.PrettyDuration(time.Since(task.createdAt)))
703+
if len(block.Sidecars()) != 0 {
704+
log.Debug("show sidecars", "block.Sidecars()[0].BlockHash", block.Sidecars()[0].BlockHash, "shadowBlock.Sidecars()[0].BlockHash", shadowBlock.Sidecars()[0].BlockHash)
705+
}
702706
} else {
703707
log.Info("Failed to AssembleSignature", "err", err)
704708
}
@@ -1329,8 +1333,8 @@ LOOP:
13291333
workList = append(workList, work)
13301334

13311335
delay := w.engine.Delay(w.chain, work.header, &w.config.DelayLeftOver)
1332-
if w.config.MB.LastBlockMiningTime > w.chainConfig.Parlia.Period*1000/2 {
1333-
if p, ok := w.engine.(*parlia.Parlia); ok {
1336+
if p, ok := w.engine.(*parlia.Parlia); ok {
1337+
if w.config.MB.LastBlockMiningTime > w.chainConfig.Parlia.Period*1000/2 {
13341338
service := p.APIs(w.chain)[0].Service
13351339
latestBlockNumber := rpc.LatestBlockNumber
13361340
currentTurnLength, err := service.(*parlia.API).GetTurnLength(&latestBlockNumber)

0 commit comments

Comments
 (0)