Skip to content

Commit

Permalink
blobtx mining pass
Browse files Browse the repository at this point in the history
  • Loading branch information
buddh0 committed Mar 13, 2024
1 parent 8c8eac0 commit f764722
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 29 deletions.
2 changes: 1 addition & 1 deletion consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@ func (p *Parlia) Seal(chain consensus.ChainHeaderReader, block *types.Block, res
}

select {
case results <- block.WithSeal(header):
case results <- block.WithSeal(header).WithBlobs(block.Blobs()):
default:
log.Warn("Sealing result is not read by miner", "sealhash", types.SealHash(header, p.chainConfig.ChainID))
}
Expand Down
2 changes: 1 addition & 1 deletion core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
},
func() error {
// Withdrawals are present after the Shanghai fork.
if header.WithdrawalsHash != nil {
if (header.WithdrawalsHash != nil && *header.WithdrawalsHash != common.Hash{}) {
// Withdrawals list must be present in body after Shanghai.
if block.Withdrawals() == nil {
return errors.New("missing withdrawals in block body")
Expand Down
3 changes: 1 addition & 2 deletions core/data_availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package core

import (
"crypto/sha256"
"errors"
"fmt"
"sync"

Expand Down Expand Up @@ -74,7 +73,7 @@ func IsDataAvailable(chain consensus.ChainHeaderReader, block *types.Block) (err
}
blobs := block.Blobs()
if len(versionedHashes) != len(blobs) {
return errors.New("blobs do not match the versionedHashes length")
return fmt.Errorf("blob info mismatch: blobs %d, versionedHashes:%d", len(blobs), len(versionedHashes))
}

// check blob amount
Expand Down
14 changes: 5 additions & 9 deletions core/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package core

import (
"math/big"
"reflect"

"github.com/ethereum/go-ethereum/params"

Expand Down Expand Up @@ -62,7 +61,11 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common
baseFee = new(big.Int).Set(header.BaseFee)
}
if header.ExcessBlobGas != nil {
blobBaseFee = eip4844.CalcBlobFee(*header.ExcessBlobGas, getChainConfig(chain))
var config *params.ChainConfig
if chain != nil {
config = chain.Config()
}
blobBaseFee = eip4844.CalcBlobFee(*header.ExcessBlobGas, config)
}
if header.Difficulty.Cmp(common.Big0) == 0 {
random = &header.MixDigest
Expand Down Expand Up @@ -145,10 +148,3 @@ func Transfer(db vm.StateDB, sender, recipient common.Address, amount *uint256.I
db.SubBalance(sender, amount)
db.AddBalance(recipient, amount)
}

func getChainConfig(bc ChainContext) *params.ChainConfig {
if bc == nil || reflect.ValueOf(bc).IsNil() {
return nil
}
return bc.Config()
}
11 changes: 3 additions & 8 deletions eth/protocols/eth/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ const (
// blockPropagation is a block propagation event, waiting for its turn in the
// broadcast queue.
type blockPropagation struct {
block *types.Block
td *big.Int
sidecars types.BlobTxSidecars `rlp:"optional"`
block *types.Block
td *big.Int
}

// broadcastBlocks is a write loop that multiplexes blocks and block announcements
Expand All @@ -48,11 +47,7 @@ func (p *Peer) broadcastBlocks() {
if err := p.SendNewBlock(prop.block, prop.td); err != nil {
return
}
if len(prop.sidecars) > 0 {
p.Log().Trace("Propagated block", "number", prop.block.Number(), "hash", prop.block.Hash(), "td", prop.td, "sidecars", prop.sidecars.Len())
} else {
p.Log().Trace("Propagated block", "number", prop.block.Number(), "hash", prop.block.Hash(), "td", prop.td)
}
p.Log().Trace("Propagated block", "number", prop.block.Number(), "hash", prop.block.Hash(), "td", prop.td, "sidecars", len(prop.block.Blobs()))

case block := <-p.queuedBlockAnns:
if err := p.SendNewBlockHashes([]common.Hash{block.Hash()}, []uint64{block.NumberU64()}); err != nil {
Expand Down
5 changes: 2 additions & 3 deletions eth/protocols/eth/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,8 @@ func (p *Peer) SendNewBlock(block *types.Block, td *big.Int) error {
// the peer's broadcast queue is full, the event is silently dropped.
func (p *Peer) AsyncSendNewBlock(block *types.Block, td *big.Int) {
bp := &blockPropagation{
block: block,
td: td,
sidecars: block.Blobs(),
block: block,
td: td,
}

select {
Expand Down
11 changes: 6 additions & 5 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,12 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) {
header.GasLimit = core.CalcGasLimit(parentGasLimit, w.config.GasCeil)
}
}
// Run the consensus preparation with the default or customized consensus engine.
// Note that the `header.Time` may be changed.
if err := w.engine.Prepare(w.chain, header); err != nil {
log.Error("Failed to prepare header for sealing", "err", err)
return nil, err
}
// Apply EIP-4844, EIP-4788.
if w.chainConfig.IsCancun(header.Number, header.Time) {
var excessBlobGas uint64
Expand All @@ -1011,11 +1017,6 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) {
header.ParentBeaconRoot = genParams.beaconRoot
}
}
// Run the consensus preparation with the default or customized consensus engine.
if err := w.engine.Prepare(w.chain, header); err != nil {
log.Error("Failed to prepare header for sealing", "err", err)
return nil, err
}
// Could potentially happen if starting to mine in an odd state.
// Note genParams.coinbase can be different with header.Coinbase
// since clique algorithm can modify the coinbase field in header.
Expand Down

0 comments on commit f764722

Please sign in to comment.