mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-13 11:36:37 +00:00
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 <csaba.kiraly@gmail.com>
This commit is contained in:
parent
965ffff9ac
commit
89158aa64e
1 changed files with 31 additions and 41 deletions
|
|
@ -1640,11 +1640,11 @@ func (p *BlobPool) AvailableBlobs(vhashes []common.Hash) int {
|
||||||
return available
|
return available
|
||||||
}
|
}
|
||||||
|
|
||||||
// preCheck performs the static validation upon the provided txs and converts
|
// preCheck performs the static validation upon the provided tx and converts
|
||||||
// the legacy sidecars if Osaka fork has been activated with a short time window.
|
// the legacy sidecars if Osaka fork has been activated with a short time window.
|
||||||
//
|
//
|
||||||
// This function is pure static and lock free.
|
// This function is pure static and lock free.
|
||||||
func (p *BlobPool) preCheck(txs []*types.Transaction) ([]*types.Transaction, []error) {
|
func (p *BlobPool) preCheck(tx *types.Transaction) error {
|
||||||
var (
|
var (
|
||||||
head = p.head.Load()
|
head = p.head.Load()
|
||||||
isOsaka = p.chain.Config().IsOsaka(head.Number, head.Time)
|
isOsaka = p.chain.Config().IsOsaka(head.Number, head.Time)
|
||||||
|
|
@ -1653,56 +1653,46 @@ func (p *BlobPool) preCheck(txs []*types.Transaction) ([]*types.Transaction, []e
|
||||||
if isOsaka {
|
if isOsaka {
|
||||||
deadline = time.Unix(int64(*p.chain.Config().OsakaTime), 0).Add(conversionTimeWindow)
|
deadline = time.Unix(int64(*p.chain.Config().OsakaTime), 0).Add(conversionTimeWindow)
|
||||||
}
|
}
|
||||||
var errs []error
|
// Validate the transaction statically at first to avoid unnecessary
|
||||||
for _, tx := range txs {
|
// conversion. This step doesn't require lock protection.
|
||||||
// Validate the transaction statically at first to avoid unnecessary
|
if err := p.ValidateTxBasics(tx); err != nil {
|
||||||
// conversion. This step doesn't require lock protection.
|
return err
|
||||||
if err := p.ValidateTxBasics(tx); err != nil {
|
|
||||||
errs = append(errs, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Before the Osaka fork, reject the blob txs with cell proofs
|
|
||||||
if !isOsaka {
|
|
||||||
if tx.BlobTxSidecar().Version == types.BlobSidecarVersion0 {
|
|
||||||
errs = append(errs, nil)
|
|
||||||
} else {
|
|
||||||
errs = append(errs, errors.New("cell proof is not supported yet"))
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// After the Osaka fork, reject the legacy blob txs if the conversion
|
|
||||||
// time window is passed.
|
|
||||||
if tx.BlobTxSidecar().Version == types.BlobSidecarVersion1 {
|
|
||||||
errs = append(errs, nil)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if head.Time > uint64(deadline.Unix()) {
|
|
||||||
errs = append(errs, errors.New("legacy blob tx is not supported"))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Convert the legacy sidecar after Osaka fork. This could be a long
|
|
||||||
// procedure which takes a few seconds, even minutes if there is a long
|
|
||||||
// queue. Fortunately it will only block the routine of the source peer
|
|
||||||
// announcing the tx, without affecting other parts.
|
|
||||||
errs = append(errs, p.cQueue.convert(tx))
|
|
||||||
}
|
}
|
||||||
return txs, errs
|
// Before the Osaka fork, reject the blob txs with cell proofs
|
||||||
|
if !isOsaka {
|
||||||
|
if tx.BlobTxSidecar().Version == types.BlobSidecarVersion0 {
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return errors.New("cell proof is not supported yet")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// After the Osaka fork, reject the legacy blob txs if the conversion
|
||||||
|
// time window is passed.
|
||||||
|
if tx.BlobTxSidecar().Version == types.BlobSidecarVersion1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if head.Time > uint64(deadline.Unix()) {
|
||||||
|
return errors.New("legacy blob tx is not supported")
|
||||||
|
}
|
||||||
|
// Convert the legacy sidecar after Osaka fork. This could be a long
|
||||||
|
// procedure which takes a few seconds, even minutes if there is a long
|
||||||
|
// queue. Fortunately it will only block the routine of the source peer
|
||||||
|
// announcing the tx, without affecting other parts.
|
||||||
|
return p.cQueue.convert(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add inserts a set of blob transactions into the pool if they pass validation (both
|
// Add inserts a set of blob transactions into the pool if they pass validation (both
|
||||||
// consensus validity and pool restrictions).
|
// consensus validity and pool restrictions).
|
||||||
func (p *BlobPool) Add(txs []*types.Transaction, sync bool) []error {
|
func (p *BlobPool) Add(txs []*types.Transaction, sync bool) []error {
|
||||||
var (
|
var (
|
||||||
errs []error
|
errs []error = make([]error, len(txs))
|
||||||
adds = make([]*types.Transaction, 0, len(txs))
|
adds = make([]*types.Transaction, 0, len(txs))
|
||||||
)
|
)
|
||||||
txs, errs = p.preCheck(txs)
|
|
||||||
for i, tx := range txs {
|
for i, tx := range txs {
|
||||||
if errs[i] != nil {
|
if errs[i] = p.preCheck(tx); errs[i] != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
errs[i] = p.add(tx)
|
if errs[i] = p.add(tx); errs[i] == nil {
|
||||||
if errs[i] == nil {
|
|
||||||
adds = append(adds, tx.WithoutBlobTxSidecar())
|
adds = append(adds, tx.WithoutBlobTxSidecar())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue