internal/ethapi: don't attach empty sidecar when signing blob tx without blobs

This commit is contained in:
Vicky 2026-03-18 02:32:40 +08:00
parent ab357151da
commit 746d691d66
2 changed files with 7 additions and 2 deletions

View file

@ -1865,7 +1865,7 @@ func (api *TransactionAPI) SignTransaction(ctx context.Context, args Transaction
// If the transaction-to-sign was a blob transaction, then the signed one
// no longer retains the blobs, only the blob hashes. In this step, we need
// to put back the blob(s).
if args.IsEIP4844() {
if args.Blobs != nil {
signed = signed.WithBlobTxSidecar(types.NewBlobTxSidecar(sidecarVersion, args.Blobs, args.Commitments, args.Proofs))
}
data, err := signed.MarshalBinary()

View file

@ -2698,10 +2698,15 @@ func TestSignBlobTransaction(t *testing.T) {
t.Fatalf("failed to fill tx defaults: %v\n", err)
}
_, err = api.SignTransaction(context.Background(), argsFromTransaction(res.Tx, b.acc.Address))
result, err := api.SignTransaction(context.Background(), argsFromTransaction(res.Tx, b.acc.Address))
if err != nil {
t.Fatalf("should not fail on blob transaction")
}
// When no blobs are provided (only blob hashes), the signed transaction
// should not have an empty sidecar attached.
if result.Tx.BlobTxSidecar() != nil {
t.Fatal("signed transaction should not have a sidecar when no blobs were provided")
}
}
func TestSendBlobTransaction(t *testing.T) {