Skip to content

Commit

Permalink
miner: fix BlobSidecar.BlockHash for double signed blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanBSC committed Aug 14, 2024
1 parent 164fcc3 commit 4e6b257
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
9 changes: 9 additions & 0 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package types

import (
"encoding/binary"
"encoding/json"
"fmt"
"io"
"math/big"
Expand Down Expand Up @@ -551,6 +552,14 @@ func (b *Block) WithSidecars(sidecars BlobSidecars) *Block {
return block
}

func (b *Block) DeepCopySidecars(sidecars BlobSidecars) {
b.sidecars = make(BlobSidecars, len(sidecars))
if len(sidecars) != 0 {
buffer, _ := json.Marshal(sidecars)
json.Unmarshal(buffer, &b.sidecars)
}
}

// Hash returns the keccak256 hash of b's header.
// The hash is computed on the first call and cached thereafter.
func (b *Block) Hash() common.Hash {
Expand Down
2 changes: 1 addition & 1 deletion core/vote/vote_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func newTestBackend() *testBackend {
return &testBackend{eventMux: new(event.TypeMux)}
}
func (b *testBackend) IsMining() bool { return true }
func (b *testBackend) VoteEnabled() bool { return true }
func (b *testBackend) VoteEnabled() bool { return true }
func (b *testBackend) EventMux() *event.TypeMux { return b.eventMux }

func (p *mockPOSA) GetJustifiedNumberAndHash(chain consensus.ChainHeaderReader, headers []*types.Header) (uint64, common.Hash, error) {
Expand Down
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ func (s *Ethereum) StopMining() {
}

func (s *Ethereum) IsMining() bool { return s.miner.Mining() }
func (s *Ethereum) VoteEnabled() bool { return s.miner.VoteEnabled() }
func (s *Ethereum) VoteEnabled() bool { return s.miner.VoteEnabled() }
func (s *Ethereum) Miner() *miner.Miner { return s.miner }

func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager }
Expand Down
10 changes: 7 additions & 3 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,14 +691,18 @@ func (w *worker) resultLoop() {
shadowHeader := block.Header()
shadowHeader.Extra[0] = 'd'
shadowHeader.Extra[1] = 's'
shadowBlock := types.NewBlockWithHeader(shadowHeader).WithBody(block.Transactions(), block.Uncles()).WithWithdrawals(block.Withdrawals()).WithSidecars(block.Sidecars())
shadowBlock := types.NewBlockWithHeader(shadowHeader).WithBody(block.Transactions(), block.Uncles()).WithWithdrawals(block.Withdrawals())
shadowBlock.DeepCopySidecars(block.Sidecars())
shadowBlock, err := p.AssembleSignature(shadowBlock)
if err == nil {
w.postBlock(shadowBlock, inturn)
sealhash := w.engine.SealHash(shadowBlock.Header())
hash := shadowBlock.Hash()
log.Info("Successfully sealed new block", "number", shadowBlock.Number(), "sealhash", sealhash, "hash", hash,
"elapsed", common.PrettyDuration(time.Since(task.createdAt)))
if len(block.Sidecars()) != 0 {
log.Debug("show sidecars", "block.Sidecars()[0].BlockHash", block.Sidecars()[0].BlockHash, "shadowBlock.Sidecars()[0].BlockHash", shadowBlock.Sidecars()[0].BlockHash)
}
} else {
log.Info("Failed to AssembleSignature", "err", err)
}
Expand Down Expand Up @@ -1329,8 +1333,8 @@ LOOP:
workList = append(workList, work)

delay := w.engine.Delay(w.chain, work.header, &w.config.DelayLeftOver)
if w.config.MB.LastBlockMiningTime > w.chainConfig.Parlia.Period*1000/2 {
if p, ok := w.engine.(*parlia.Parlia); ok {
if p, ok := w.engine.(*parlia.Parlia); ok {
if w.config.MB.LastBlockMiningTime > w.chainConfig.Parlia.Period*1000/2 {
service := p.APIs(w.chain)[0].Service
latestBlockNumber := rpc.LatestBlockNumber
currentTurnLength, err := service.(*parlia.API).GetTurnLength(&latestBlockNumber)
Expand Down

0 comments on commit 4e6b257

Please sign in to comment.