Update api.go

This commit is contained in:
Doryu 2025-11-21 01:16:09 +01:00 committed by GitHub
parent f4817b7a53
commit a4c0578680
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1644,6 +1644,19 @@ func (api *TransactionAPI) currentBlobSidecarVersion() byte {
return types.BlobSidecarVersion0 return types.BlobSidecarVersion0
} }
// convertLegacyBlobSidecar upgrades the legacy blob sidecar if required.
// TODO: remove in go-ethereum v1.17.x
func convertLegacyBlobSidecar(tx *types.Transaction, expected byte) (*types.Transaction, error) {
sc := tx.BlobTxSidecar()
if sc == nil || sc.Version != types.BlobSidecarVersion0 || expected != types.BlobSidecarVersion1 {
return tx, nil
}
if err := sc.ToV1(); err != nil {
return nil, fmt.Errorf("blob sidecar conversion failed: %v", err)
}
return tx.WithBlobTxSidecar(sc), nil
}
// SendRawTransaction will add the signed transaction to the transaction pool. // SendRawTransaction will add the signed transaction to the transaction pool.
// The sender is responsible for signing the transaction and using the correct nonce. // The sender is responsible for signing the transaction and using the correct nonce.
func (api *TransactionAPI) SendRawTransaction(ctx context.Context, input hexutil.Bytes) (common.Hash, error) { func (api *TransactionAPI) SendRawTransaction(ctx context.Context, input hexutil.Bytes) (common.Hash, error) {
@ -1653,15 +1666,10 @@ func (api *TransactionAPI) SendRawTransaction(ctx context.Context, input hexutil
} }
// Convert legacy blob transaction proofs. // Convert legacy blob transaction proofs.
// TODO: remove in go-ethereum v1.17.x var err error
if sc := tx.BlobTxSidecar(); sc != nil { tx, err = convertLegacyBlobSidecar(tx, api.currentBlobSidecarVersion())
exp := api.currentBlobSidecarVersion() if err != nil {
if sc.Version == types.BlobSidecarVersion0 && exp == types.BlobSidecarVersion1 { return common.Hash{}, err
if err := sc.ToV1(); err != nil {
return common.Hash{}, fmt.Errorf("blob sidecar conversion failed: %v", err)
}
tx = tx.WithBlobTxSidecar(sc)
}
} }
return SubmitTransaction(ctx, api.b, tx) return SubmitTransaction(ctx, api.b, tx)
@ -1676,15 +1684,10 @@ func (api *TransactionAPI) SendRawTransactionSync(ctx context.Context, input hex
} }
// Convert legacy blob transaction proofs. // Convert legacy blob transaction proofs.
// TODO: remove in go-ethereum v1.17.x var err error
if sc := tx.BlobTxSidecar(); sc != nil { tx, err = convertLegacyBlobSidecar(tx, api.currentBlobSidecarVersion())
exp := api.currentBlobSidecarVersion() if err != nil {
if sc.Version == types.BlobSidecarVersion0 && exp == types.BlobSidecarVersion1 { return nil, err
if err := sc.ToV1(); err != nil {
return nil, fmt.Errorf("blob sidecar conversion failed: %v", err)
}
tx = tx.WithBlobTxSidecar(sc)
}
} }
ch := make(chan core.ChainEvent, 128) ch := make(chan core.ChainEvent, 128)