mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
core/types: fix rlp decoding
This commit is contained in:
parent
d3c184d7ec
commit
f31ad09c57
3 changed files with 30 additions and 10 deletions
|
|
@ -173,6 +173,9 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateBlobSidecar(hashes []common.Hash, sidecar *types.BlobTxSidecar) error {
|
func validateBlobSidecar(hashes []common.Hash, sidecar *types.BlobTxSidecar) error {
|
||||||
|
if sidecar.Version != 0 {
|
||||||
|
return fmt.Errorf("invalid sidecar version pre-osaka: %v", sidecar.Version)
|
||||||
|
}
|
||||||
if len(sidecar.Blobs) != len(hashes) {
|
if len(sidecar.Blobs) != len(hashes) {
|
||||||
return fmt.Errorf("invalid number of %d blobs compared to %d blob hashes", len(sidecar.Blobs), len(hashes))
|
return fmt.Errorf("invalid number of %d blobs compared to %d blob hashes", len(sidecar.Blobs), len(hashes))
|
||||||
}
|
}
|
||||||
|
|
@ -193,6 +196,9 @@ func validateBlobSidecar(hashes []common.Hash, sidecar *types.BlobTxSidecar) err
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateBlobSidecarOsaka(hashes []common.Hash, sidecar *types.BlobTxSidecar) error {
|
func validateBlobSidecarOsaka(hashes []common.Hash, sidecar *types.BlobTxSidecar) error {
|
||||||
|
if sidecar.Version != 1 {
|
||||||
|
return fmt.Errorf("invalid sidecar version post-osaka: %v", sidecar.Version)
|
||||||
|
}
|
||||||
if len(sidecar.Blobs) != len(hashes) {
|
if len(sidecar.Blobs) != len(hashes) {
|
||||||
return fmt.Errorf("invalid number of %d blobs compared to %d blob hashes", len(sidecar.Blobs), len(hashes))
|
return fmt.Errorf("invalid number of %d blobs compared to %d blob hashes", len(sidecar.Blobs), len(hashes))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ type BlobTx struct {
|
||||||
|
|
||||||
// BlobTxSidecar contains the blobs of a blob transaction.
|
// BlobTxSidecar contains the blobs of a blob transaction.
|
||||||
type BlobTxSidecar struct {
|
type BlobTxSidecar struct {
|
||||||
|
Version byte // Version
|
||||||
Blobs []kzg4844.Blob // Blobs needed by the blob pool
|
Blobs []kzg4844.Blob // Blobs needed by the blob pool
|
||||||
Commitments []kzg4844.Commitment // Commitments needed by the blob pool
|
Commitments []kzg4844.Commitment // Commitments needed by the blob pool
|
||||||
Proofs []kzg4844.Proof // Proofs needed by the blob pool
|
Proofs []kzg4844.Proof // Proofs needed by the blob pool
|
||||||
|
|
@ -125,8 +126,8 @@ type blobTxWithBlobs struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type versionedBlobTxWithBlobs struct {
|
type versionedBlobTxWithBlobs struct {
|
||||||
Version byte
|
|
||||||
BlobTx *BlobTx
|
BlobTx *BlobTx
|
||||||
|
Version byte
|
||||||
Blobs []kzg4844.Blob
|
Blobs []kzg4844.Blob
|
||||||
Commitments []kzg4844.Commitment
|
Commitments []kzg4844.Commitment
|
||||||
Proofs []kzg4844.Proof
|
Proofs []kzg4844.Proof
|
||||||
|
|
@ -240,6 +241,17 @@ func (tx *BlobTx) encode(b *bytes.Buffer) error {
|
||||||
if tx.Sidecar == nil {
|
if tx.Sidecar == nil {
|
||||||
return rlp.Encode(b, tx)
|
return rlp.Encode(b, tx)
|
||||||
}
|
}
|
||||||
|
// Encode a cell proof transaction
|
||||||
|
if tx.Sidecar.Version != 0 {
|
||||||
|
inner := &versionedBlobTxWithBlobs{
|
||||||
|
BlobTx: tx,
|
||||||
|
Version: tx.Sidecar.Version,
|
||||||
|
Blobs: tx.Sidecar.Blobs,
|
||||||
|
Commitments: tx.Sidecar.Commitments,
|
||||||
|
Proofs: tx.Sidecar.Proofs,
|
||||||
|
}
|
||||||
|
return rlp.Encode(b, inner)
|
||||||
|
}
|
||||||
inner := &blobTxWithBlobs{
|
inner := &blobTxWithBlobs{
|
||||||
BlobTx: tx,
|
BlobTx: tx,
|
||||||
Blobs: tx.Sidecar.Blobs,
|
Blobs: tx.Sidecar.Blobs,
|
||||||
|
|
@ -269,20 +281,22 @@ func (tx *BlobTx) decode(input []byte) error {
|
||||||
return rlp.DecodeBytes(input, tx)
|
return rlp.DecodeBytes(input, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// It's a tx with blobs.
|
// It's a tx with blobs. Try to decode it as version 0.
|
||||||
var inner blobTxWithBlobs
|
var inner versionedBlobTxWithBlobs
|
||||||
if err := rlp.DecodeBytes(input, &inner); err != nil {
|
if err := rlp.DecodeBytes(input, &inner); err != nil {
|
||||||
var innerWithVersion versionedBlobTxWithBlobs
|
var innerV0 blobTxWithBlobs
|
||||||
if err := rlp.DecodeBytes(input, &innerWithVersion); err != nil {
|
if err := rlp.DecodeBytes(input, &innerV0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
inner.BlobTx = innerWithVersion.BlobTx
|
inner.BlobTx = innerV0.BlobTx
|
||||||
inner.Blobs = innerWithVersion.Blobs
|
inner.Version = 0
|
||||||
inner.Commitments = innerWithVersion.Commitments
|
inner.Blobs = innerV0.Blobs
|
||||||
inner.Proofs = innerWithVersion.Proofs
|
inner.Commitments = innerV0.Commitments
|
||||||
|
inner.Proofs = innerV0.Proofs
|
||||||
}
|
}
|
||||||
*tx = *inner.BlobTx
|
*tx = *inner.BlobTx
|
||||||
tx.Sidecar = &BlobTxSidecar{
|
tx.Sidecar = &BlobTxSidecar{
|
||||||
|
Version: inner.Version,
|
||||||
Blobs: inner.Blobs,
|
Blobs: inner.Blobs,
|
||||||
Commitments: inner.Commitments,
|
Commitments: inner.Commitments,
|
||||||
Proofs: inner.Proofs,
|
Proofs: inner.Proofs,
|
||||||
|
|
|
||||||
|
|
@ -571,7 +571,7 @@ func (api *ConsensusAPI) GetBlobsV1(hashes []common.Hash) ([]*engine.BlobAndProo
|
||||||
index[hash] = i
|
index[hash] = i
|
||||||
}
|
}
|
||||||
for i, sidecar := range sidecars {
|
for i, sidecar := range sidecars {
|
||||||
if res[i] != nil {
|
if res[i] != nil && sidecar == nil {
|
||||||
// already filled
|
// already filled
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue