Skip to content

Commit

Permalink
Sidecar fetching changes for 4844 (#2283)
Browse files Browse the repository at this point in the history
* ci: temp enable blobtx branch ci run;

* Switch ON blobpool & ensure Cancun hardfork can occur (#2223)

pool: switch ON blobpool+no reannotx

* feat: support blob storage & miscs; (#2229)

* chainconfig: use cancun fork for BSC;
feat: fill WithdrawalsHash when BSC enable cancun fork;

* rawdb: support to CRUD blobs;
freezer: support to freeze block blobs;

* freezer: support to freeze block blobs;

* blockchain: add blob cache & blob query helper;

* blockchain: add blob cache & blob query helper;

* freezer: refactor addition table logic, add uts;

* blobexpiry: add more extra expiry time, and logs;

* ci: fix UT fails;

* fix: fix some PR review comments;

* parlia: implement IsDataAvailable function;

* blob: refactor blob transfer logic;

* blob: support config blob extra reserve;

* blockchian: support to import block with blob & blobGasFee; (#2260)

* blob: implement min&max gas price logic;
blob: change some key parameters;

* blockchian: support import side chain;

* blobpool: reject the banned address;

* blockchain: add chasing head for DA check;

* params: update blob related config;

* blockchain: opt data available checking performance;
dataavailability: add more UTs;

* blockchain: opt data available checking performance;
dataavailability: add more UTs;

* ci: fix failed UTs;

* ci: fix failed UTs;

* params: modify blob related params;

* gasprice: support BEP-336 blob gas price calculate;

* ci: fix some broken UTs;

* fix failed check for WithdrawalsHash (#2276)

* eth: include sidecars in fitering of body

* core: refactor sidecars name

* eth: sidecars type refactor

* core: remove extra from bad merge

* eth: fix handlenewblock test after merge

---------

Co-authored-by: GalaIO <[email protected]>
Co-authored-by: buddho <[email protected]>
  • Loading branch information
3 people committed Mar 21, 2024
1 parent 8063efd commit e29c386
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 30 deletions.
10 changes: 5 additions & 5 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ type Block struct {
ReceivedAt time.Time
ReceivedFrom interface{}

// blobs provides DA check
blobs BlobTxSidecars
// sidecars provides DA check
sidecars BlobTxSidecars
}

// "external" block encoding. used for eth protocol, etc.
Expand Down Expand Up @@ -455,7 +455,7 @@ func (b *Block) SanityCheck() error {
}

func (b *Block) Blobs() BlobTxSidecars {
return b.blobs
return b.sidecars
}

type writeCounter uint64
Expand Down Expand Up @@ -520,12 +520,12 @@ func (b *Block) WithWithdrawals(withdrawals []*Withdrawal) *Block {
}

// WithBlobs returns a block containing the given blobs.
func (b *Block) WithBlobs(blobs BlobTxSidecars) *Block {
func (b *Block) WithBlobs(sidecars BlobTxSidecars) *Block {
block := &Block{
header: b.header,
transactions: b.transactions,
uncles: b.uncles,
blobs: blobs,
sidecars: sidecars,
}
return block
}
Expand Down
34 changes: 18 additions & 16 deletions eth/fetcher/block_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@ type headerFilterTask struct {
time time.Time // Arrival time of the headers
}

// bodyFilterTask represents a batch of block bodies (transactions and uncles)
// bodyFilterTask represents a batch of block bodies (transactions, sidecars and uncles)
// needing fetcher filtering.
type bodyFilterTask struct {
peer string // The source peer of block bodies
transactions [][]*types.Transaction // Collection of transactions per block bodies
uncles [][]*types.Header // Collection of uncles per block bodies
time time.Time // Arrival time of the blocks' contents
peer string // The source peer of block bodies
transactions [][]*types.Transaction // Collection of transactions per block bodies
uncles [][]*types.Header // Collection of uncles per block bodies
sidecars [][]*types.BlobTxSidecar // Collection of sidecars per block bodies
time time.Time // Arrival time of the blocks' contents
}

// blockOrHeaderInject represents a schedules import operation.
Expand Down Expand Up @@ -314,29 +315,29 @@ func (f *BlockFetcher) FilterHeaders(peer string, headers []*types.Header, time

// FilterBodies extracts all the block bodies that were explicitly requested by
// the fetcher, returning those that should be handled differently.
func (f *BlockFetcher) FilterBodies(peer string, transactions [][]*types.Transaction, uncles [][]*types.Header, time time.Time) ([][]*types.Transaction, [][]*types.Header) {
log.Trace("Filtering bodies", "peer", peer, "txs", len(transactions), "uncles", len(uncles))
func (f *BlockFetcher) FilterBodies(peer string, transactions [][]*types.Transaction, uncles [][]*types.Header, sidecars [][]*types.BlobTxSidecar, time time.Time) ([][]*types.Transaction, [][]*types.Header, [][]*types.BlobTxSidecar) {
log.Trace("Filtering bodies", "peer", peer, "txs", len(transactions), "uncles", len(uncles), "sidecars", len(sidecars))

// Send the filter channel to the fetcher
filter := make(chan *bodyFilterTask)

select {
case f.bodyFilter <- filter:
case <-f.quit:
return nil, nil
return nil, nil, nil
}
// Request the filtering of the body list
select {
case filter <- &bodyFilterTask{peer: peer, transactions: transactions, uncles: uncles, time: time}:
case filter <- &bodyFilterTask{peer: peer, transactions: transactions, uncles: uncles, sidecars: sidecars, time: time}:
case <-f.quit:
return nil, nil
return nil, nil, nil
}
// Retrieve the bodies remaining after filtering
select {
case task := <-filter:
return task.transactions, task.uncles
return task.transactions, task.uncles, task.sidecars
case <-f.quit:
return nil, nil
return nil, nil, nil
}
}

Expand Down Expand Up @@ -576,9 +577,8 @@ func (f *BlockFetcher) loop() {
case res := <-resCh:
res.Done <- nil
// Ignoring withdrawals here, since the block fetcher is not used post-merge.
// todo 4844 is it ok to ignore sidecars here too?
txs, uncles, _, _ := res.Res.(*eth.BlockBodiesResponse).Unpack()
f.FilterBodies(peer, txs, uncles, time.Now())
txs, uncles, _, sidecars := res.Res.(*eth.BlockBodiesResponse).Unpack()
f.FilterBodies(peer, txs, uncles, sidecars, time.Now())

case <-timeout.C:
// The peer didn't respond in time. The request
Expand Down Expand Up @@ -696,7 +696,7 @@ func (f *BlockFetcher) loop() {
blocks := []*types.Block{}
// abort early if there's nothing explicitly requested
if len(f.completing) > 0 {
for i := 0; i < len(task.transactions) && i < len(task.uncles); i++ {
for i := 0; i < len(task.transactions) && i < len(task.uncles) && i < len(task.sidecars); i++ {
// Match up a body to any possible completion request
var (
matched = false
Expand All @@ -723,6 +723,7 @@ func (f *BlockFetcher) loop() {
matched = true
if f.getBlock(hash) == nil {
block := types.NewBlockWithHeader(announce.header).WithBody(task.transactions[i], task.uncles[i])
block = block.WithBlobs(task.sidecars[i])
block.ReceivedAt = task.time
blocks = append(blocks, block)
} else {
Expand All @@ -732,6 +733,7 @@ func (f *BlockFetcher) loop() {
if matched {
task.transactions = append(task.transactions[:i], task.transactions[i+1:]...)
task.uncles = append(task.uncles[:i], task.uncles[i+1:]...)
task.sidecars = append(task.sidecars[:i], task.sidecars[i+1:]...)
i--
continue
}
Expand Down
8 changes: 0 additions & 8 deletions eth/protocols/eth/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,6 @@ func TestHandleNewBlock(t *testing.T) {
}

protos := []p2p.Protocol{
{
Name: "eth",
Version: ETH67,
},
{
Name: "eth",
Version: ETH68,
Expand All @@ -604,10 +600,6 @@ func TestHandleNewBlock(t *testing.T) {
},
}
caps := []p2p.Cap{
{
Name: "eth",
Version: ETH67,
},
{
Name: "eth",
Version: ETH68,
Expand Down
2 changes: 1 addition & 1 deletion eth/protocols/eth/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ type BlockHeadersRLPPacket struct {
type NewBlockPacket struct {
Block *types.Block
TD *big.Int
Sidecars []*types.BlobTxSidecar `rlp:"optional"`
Sidecars types.BlobTxSidecars `rlp:"optional"`
}

// sanityCheck verifies that the values are reasonable, as a DoS protection
Expand Down

0 comments on commit e29c386

Please sign in to comment.