@@ -24,6 +24,7 @@ import (
2424 "fmt"
2525
2626 ctypes "github.com/berachain/beacon-kit/consensus-types/types"
27+ "github.com/berachain/beacon-kit/consensus/cometbft/service/blobreactor"
2728 datypes "github.com/berachain/beacon-kit/da/types"
2829 "github.com/berachain/beacon-kit/primitives/common"
2930 "github.com/berachain/beacon-kit/primitives/encoding/ssz"
@@ -66,34 +67,33 @@ func UnmarshalBeaconBlockFromABCIRequest(
6667}
6768
6869// UnmarshalBlobSidecarsFromABCIRequest extracts blob sidecars from an ABCI FinalizeBlockRequest based on blob consensus parameters.
69- func UnmarshalBlobSidecarsFromABCIRequest (req * cmtabci.FinalizeBlockRequest , blobEnableHeight int64 ) (datypes.BlobSidecars , error ) {
70+ func UnmarshalBlobSidecarsFromABCIRequest (req * cmtabci.FinalizeBlockRequest , cfg blobreactor. ConfigGetter ) (datypes.BlobSidecars , error ) {
7071 if req == nil {
7172 return nil , ErrNilABCIRequest
7273 }
7374
74- // Before or at BlobEnableHeight: blobs are in Txs[1] if present
75- if blobEnableHeight <= 0 || req .Height < blobEnableHeight {
76- txs := req .GetTxs ()
77- if len (txs ) <= 1 {
78- // No sidecars in this block
79- return datypes.BlobSidecars {}, nil
80- }
75+ // If we are at or after BlobEnableHeight, then blobs must be retrieved from cache or via blobreactor p2p
76+ if cfg .IsBlobConsensusEnabledAtHeight (req .Height ) {
77+ return datypes.BlobSidecars {}, nil
78+ }
8179
82- sidecarBz := txs [1 ]
83- if len (sidecarBz ) == 0 {
84- return datypes.BlobSidecars {}, nil
85- }
80+ // Otherwise, blobs are in Txs[1] if present in this block
81+ txs := req .GetTxs ()
82+ if len (txs ) <= 1 {
83+ return datypes.BlobSidecars {}, nil
84+ }
8685
87- var sidecars datypes. BlobSidecars
88- if err := ssz . Unmarshal (sidecarBz , & sidecars ); err != nil {
89- return nil , fmt . Errorf ( "failed to unmarshal blobs from Txs[1]: %w" , err )
90- }
86+ sidecarBz := txs [ 1 ]
87+ if len (sidecarBz ) == 0 {
88+ return datypes. BlobSidecars {}, nil
89+ }
9190
92- return sidecars , nil
91+ var sidecars datypes.BlobSidecars
92+ if err := ssz .Unmarshal (sidecarBz , & sidecars ); err != nil {
93+ return nil , fmt .Errorf ("failed to unmarshal blobs from Txs[1]: %w" , err )
9394 }
9495
95- // After BlobEnableHeight: blobs are distributed via BlobReactor and must be retrieved from cache or storage
96- return datypes.BlobSidecars {}, nil
96+ return sidecars , nil
9797}
9898
9999// ExtractBlobSidecarsFromRequest is a generic helper that extracts blob sidecars from either
@@ -103,36 +103,35 @@ func ExtractBlobSidecarsFromRequest(
103103 txs [][]byte ,
104104 blobData []byte ,
105105 height int64 ,
106- blobEnableHeight int64 ,
106+ cfg blobreactor. ConfigGetter ,
107107) (datypes.BlobSidecars , error ) {
108- // Before BlobEnableHeight: blobs are in Txs[1]
109- if blobEnableHeight <= 0 || height < blobEnableHeight {
110- if len (txs ) <= 1 {
111- // No sidecars in this block
112- return datypes.BlobSidecars {}, nil
113- }
114-
115- sidecarBz := txs [1 ]
116- if len (sidecarBz ) == 0 {
108+ // If we are at or after BlobEnableHeight, then we use blobData for blobs if present
109+ if cfg .IsBlobConsensusEnabledAtHeight (height ) {
110+ if len (blobData ) == 0 {
117111 return datypes.BlobSidecars {}, nil
118112 }
119113
120114 var sidecars datypes.BlobSidecars
121- if err := ssz .Unmarshal (sidecarBz , & sidecars ); err != nil {
122- return nil , fmt .Errorf ("failed to unmarshal blobs from Txs[1] at height %d: %w" , height , err )
115+ if err := ssz .Unmarshal (blobData , & sidecars ); err != nil {
116+ return nil , fmt .Errorf ("failed to unmarshal blobs from Blob field at height %d: %w" , height , err )
123117 }
124118
125119 return sidecars , nil
126120 }
127121
128- // After BlobEnableHeight: blobs are in the Blob field
129- if len (blobData ) == 0 {
122+ // Otherwise, blobs are in Txs[1] if present
123+ if len (txs ) <= 1 {
124+ return datypes.BlobSidecars {}, nil
125+ }
126+
127+ sidecarBz := txs [1 ]
128+ if len (sidecarBz ) == 0 {
130129 return datypes.BlobSidecars {}, nil
131130 }
132131
133132 var sidecars datypes.BlobSidecars
134- if err := ssz .Unmarshal (blobData , & sidecars ); err != nil {
135- return nil , fmt .Errorf ("failed to unmarshal blobs from Blob field at height %d: %w" , height , err )
133+ if err := ssz .Unmarshal (sidecarBz , & sidecars ); err != nil {
134+ return nil , fmt .Errorf ("failed to unmarshal blobs from Txs[1] at height %d: %w" , height , err )
136135 }
137136
138137 return sidecars , nil
0 commit comments