Skip to content

Commit 89158aa

Browse files
authored
core/txpool/blobpool: convert and add one-by-one (#32718)
This is a small improvement on #32656 in case Add was called with multiple type 3 transactions, adding transactions to the pool one-by-one as they are converted. Announcement to peers is still done in a batch. Signed-off-by: Csaba Kiraly <[email protected]>
1 parent 965ffff commit 89158aa

File tree

1 file changed

+30
-40
lines changed

1 file changed

+30
-40
lines changed

core/txpool/blobpool/blobpool.go

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,11 +1640,11 @@ func (p *BlobPool) AvailableBlobs(vhashes []common.Hash) int {
16401640
return available
16411641
}
16421642

1643-
// preCheck performs the static validation upon the provided txs and converts
1643+
// preCheck performs the static validation upon the provided tx and converts
16441644
// the legacy sidecars if Osaka fork has been activated with a short time window.
16451645
//
16461646
// This function is pure static and lock free.
1647-
func (p *BlobPool) preCheck(txs []*types.Transaction) ([]*types.Transaction, []error) {
1647+
func (p *BlobPool) preCheck(tx *types.Transaction) error {
16481648
var (
16491649
head = p.head.Load()
16501650
isOsaka = p.chain.Config().IsOsaka(head.Number, head.Time)
@@ -1653,56 +1653,46 @@ func (p *BlobPool) preCheck(txs []*types.Transaction) ([]*types.Transaction, []e
16531653
if isOsaka {
16541654
deadline = time.Unix(int64(*p.chain.Config().OsakaTime), 0).Add(conversionTimeWindow)
16551655
}
1656-
var errs []error
1657-
for _, tx := range txs {
1658-
// Validate the transaction statically at first to avoid unnecessary
1659-
// conversion. This step doesn't require lock protection.
1660-
if err := p.ValidateTxBasics(tx); err != nil {
1661-
errs = append(errs, err)
1662-
continue
1663-
}
1664-
// Before the Osaka fork, reject the blob txs with cell proofs
1665-
if !isOsaka {
1666-
if tx.BlobTxSidecar().Version == types.BlobSidecarVersion0 {
1667-
errs = append(errs, nil)
1668-
} else {
1669-
errs = append(errs, errors.New("cell proof is not supported yet"))
1670-
}
1671-
continue
1672-
}
1673-
// After the Osaka fork, reject the legacy blob txs if the conversion
1674-
// time window is passed.
1675-
if tx.BlobTxSidecar().Version == types.BlobSidecarVersion1 {
1676-
errs = append(errs, nil)
1677-
continue
1678-
}
1679-
if head.Time > uint64(deadline.Unix()) {
1680-
errs = append(errs, errors.New("legacy blob tx is not supported"))
1681-
continue
1656+
// Validate the transaction statically at first to avoid unnecessary
1657+
// conversion. This step doesn't require lock protection.
1658+
if err := p.ValidateTxBasics(tx); err != nil {
1659+
return err
1660+
}
1661+
// Before the Osaka fork, reject the blob txs with cell proofs
1662+
if !isOsaka {
1663+
if tx.BlobTxSidecar().Version == types.BlobSidecarVersion0 {
1664+
return nil
1665+
} else {
1666+
return errors.New("cell proof is not supported yet")
16821667
}
1683-
// Convert the legacy sidecar after Osaka fork. This could be a long
1684-
// procedure which takes a few seconds, even minutes if there is a long
1685-
// queue. Fortunately it will only block the routine of the source peer
1686-
// announcing the tx, without affecting other parts.
1687-
errs = append(errs, p.cQueue.convert(tx))
16881668
}
1689-
return txs, errs
1669+
// After the Osaka fork, reject the legacy blob txs if the conversion
1670+
// time window is passed.
1671+
if tx.BlobTxSidecar().Version == types.BlobSidecarVersion1 {
1672+
return nil
1673+
}
1674+
if head.Time > uint64(deadline.Unix()) {
1675+
return errors.New("legacy blob tx is not supported")
1676+
}
1677+
// Convert the legacy sidecar after Osaka fork. This could be a long
1678+
// procedure which takes a few seconds, even minutes if there is a long
1679+
// queue. Fortunately it will only block the routine of the source peer
1680+
// announcing the tx, without affecting other parts.
1681+
return p.cQueue.convert(tx)
16901682
}
16911683

16921684
// Add inserts a set of blob transactions into the pool if they pass validation (both
16931685
// consensus validity and pool restrictions).
16941686
func (p *BlobPool) Add(txs []*types.Transaction, sync bool) []error {
16951687
var (
1696-
errs []error
1697-
adds = make([]*types.Transaction, 0, len(txs))
1688+
errs []error = make([]error, len(txs))
1689+
adds = make([]*types.Transaction, 0, len(txs))
16981690
)
1699-
txs, errs = p.preCheck(txs)
17001691
for i, tx := range txs {
1701-
if errs[i] != nil {
1692+
if errs[i] = p.preCheck(tx); errs[i] != nil {
17021693
continue
17031694
}
1704-
errs[i] = p.add(tx)
1705-
if errs[i] == nil {
1695+
if errs[i] = p.add(tx); errs[i] == nil {
17061696
adds = append(adds, tx.WithoutBlobTxSidecar())
17071697
}
17081698
}

0 commit comments

Comments
 (0)