Skip to content

Commit

Permalink
processing ConsensusSidecars in blob-processors
Browse files Browse the repository at this point in the history
  • Loading branch information
abi87 committed Oct 28, 2024
1 parent 6c36d22 commit 16540c0
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 21 deletions.
2 changes: 1 addition & 1 deletion beacond/cmd/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func DefaultComponents() []any {
components.ProvideBlsSigner,
components.ProvideBlobProcessor[
*AvailabilityStore, *BeaconBlockBody, *BeaconBlockHeader,
*BlobSidecar, *BlobSidecars, *Logger,
*ConsensusSidecars, *BlobSidecar, *BlobSidecars, *Logger,
],
components.ProvideBlobProofVerifier,
components.ProvideBlobVerifier[
Expand Down
1 change: 1 addition & 0 deletions beacond/cmd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type (
*AvailabilityStore,
*BeaconBlockBody,
*BeaconBlockHeader,
*ConsensusSidecars,
*BlobSidecar,
*BlobSidecars,
]
Expand Down
19 changes: 13 additions & 6 deletions mod/da/pkg/blob/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Processor[
],
BeaconBlockBodyT any,
BeaconBlockHeaderT BeaconBlockHeader,
ConsensusSidecarsT ConsensusSidecars[BlobSidecarsT, BeaconBlockHeaderT],
BlobSidecarT Sidecar[BeaconBlockHeaderT],
BlobSidecarsT Sidecars[BlobSidecarT],
] struct {
Expand All @@ -59,6 +60,7 @@ func NewProcessor[
],
BeaconBlockBodyT any,
BeaconBlockHeaderT BeaconBlockHeader,
ConsensusSidecarsT ConsensusSidecars[BlobSidecarsT, BeaconBlockHeaderT],
BlobSidecarT Sidecar[BeaconBlockHeaderT],
BlobSidecarsT Sidecars[BlobSidecarT],
](
Expand All @@ -69,11 +71,11 @@ func NewProcessor[
telemetrySink TelemetrySink,
) *Processor[
AvailabilityStoreT, BeaconBlockBodyT, BeaconBlockHeaderT,
BlobSidecarT, BlobSidecarsT,
ConsensusSidecarsT, BlobSidecarT, BlobSidecarsT,
] {
return &Processor[
AvailabilityStoreT, BeaconBlockBodyT, BeaconBlockHeaderT,
BlobSidecarT, BlobSidecarsT,
ConsensusSidecarsT, BlobSidecarT, BlobSidecarsT,
]{
logger: logger,
chainSpec: chainSpec,
Expand All @@ -84,10 +86,15 @@ func NewProcessor[
}

// VerifySidecars verifies the blobs and ensures they match the local state.
func (sp *Processor[AvailabilityStoreT, _, _, _, BlobSidecarsT]) VerifySidecars(
sidecars BlobSidecarsT,
func (sp *Processor[
AvailabilityStoreT, _, _, ConsensusSidecarsT, _, _,
]) VerifySidecars(
cs ConsensusSidecarsT,
) error {
startTime := time.Now()
var (
startTime = time.Now()
sidecars = cs.GetSidecars()
)
defer sp.metrics.measureVerifySidecarsDuration(
startTime, math.U64(sidecars.Len()),
)
Expand All @@ -109,7 +116,7 @@ func (sp *Processor[AvailabilityStoreT, _, _, _, BlobSidecarsT]) VerifySidecars(

// slot := processes the blobs and ensures they match the local state.
func (sp *Processor[
AvailabilityStoreT, _, _, _, BlobSidecarsT,
AvailabilityStoreT, _, _, _, _, BlobSidecarsT,
]) ProcessSidecars(
avs AvailabilityStoreT,
sidecars BlobSidecarsT,
Expand Down
5 changes: 5 additions & 0 deletions mod/da/pkg/blob/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ type BlobVerifier[BlobSidecarsT any] interface {
VerifySidecars(sidecars BlobSidecarsT, kzgOffset uint64) error
}

type ConsensusSidecars[BlobSidecarsT any, BeaconBlockHeaderT any] interface {
GetSidecars() BlobSidecarsT
GetHeader() BeaconBlockHeaderT
}

type Sidecar[BeaconBlockHeaderT any] interface {
GetBeaconBlockHeader() BeaconBlockHeaderT
GetBlob() eip4844.Blob
Expand Down
9 changes: 5 additions & 4 deletions mod/da/pkg/da/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Service[
avs AvailabilityStoreT
bp BlobProcessor[
AvailabilityStoreT,
BlobSidecarsT,
ConsensusSidecarsT, BlobSidecarsT,
]
dispatcher asynctypes.EventDispatcher
logger log.Logger
Expand All @@ -60,7 +60,8 @@ func NewService[
](
avs AvailabilityStoreT,
bp BlobProcessor[
AvailabilityStoreT, BlobSidecarsT,
AvailabilityStoreT,
ConsensusSidecarsT, BlobSidecarsT,
],
dispatcher asynctypes.EventDispatcher,
logger log.Logger,
Expand Down Expand Up @@ -191,15 +192,15 @@ func (s *Service[_, ConsensusSidecarsT, _, _]) verifySidecars(
cs ConsensusSidecarsT,
) error {
sidecars := cs.GetSidecars()
// If there are no blobs to verify, return early.
if sidecars.IsNil() || sidecars.Len() == 0 {
// nothing to verify
return nil
}

s.logger.Info("Received incoming blob sidecars")

// Verify the blobs and ensure they match the local state.
if err := s.bp.VerifySidecars(sidecars); err != nil {
if err := s.bp.VerifySidecars(cs); err != nil {
s.logger.Error(
"rejecting incoming blob sidecars",
"reason", err,
Expand Down
9 changes: 5 additions & 4 deletions mod/da/pkg/da/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@
package da

// BlobProcessor is the interface for the blobs processor.
type BlobProcessor[AvailabilityStoreT any, BlobSidecarsT any] interface {
type BlobProcessor[
AvailabilityStoreT,
ConsensusSidecarsT, BlobSidecarsT any,
] interface {
// ProcessSidecars processes the blobs and ensures they match the local
// state.
ProcessSidecars(
avs AvailabilityStoreT,
sidecars BlobSidecarsT,
) error
// VerifySidecars verifies the blobs and ensures they match the local state.
VerifySidecars(
sidecars BlobSidecarsT,
) error
VerifySidecars(sidecars ConsensusSidecarsT) error
}

type ConsensusSidecars[BlobSidecarsT any, BeaconBlockHeaderT any] interface {
Expand Down
10 changes: 6 additions & 4 deletions mod/node-core/pkg/components/blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,21 @@ func ProvideBlobProcessor[
AvailabilityStoreT AvailabilityStore[BeaconBlockBodyT, BlobSidecarsT],
BeaconBlockBodyT any,
BeaconBlockHeaderT BeaconBlockHeader[BeaconBlockHeaderT],
ConsensusSidecarsT ConsensusSidecars[BlobSidecarsT, BeaconBlockHeaderT],
BlobSidecarT BlobSidecar[BeaconBlockHeaderT],
BlobSidecarsT BlobSidecars[BlobSidecarsT, BlobSidecarT],
LoggerT log.AdvancedLogger[LoggerT],
](
in BlobProcessorIn[BlobSidecarsT, LoggerT],
) *dablob.Processor[
AvailabilityStoreT, BeaconBlockBodyT, BeaconBlockHeaderT,
BlobSidecarT, BlobSidecarsT,
ConsensusSidecarsT, BlobSidecarT, BlobSidecarsT,
] {
return dablob.NewProcessor[
AvailabilityStoreT,
BeaconBlockBodyT,
BeaconBlockHeaderT,
ConsensusSidecarsT,
BlobSidecarT,
BlobSidecarsT,
](
Expand All @@ -123,15 +125,15 @@ func ProvideBlobProcessor[
// DAServiceIn is the input for the BlobService.
type DAServiceIn[
AvailabilityStoreT any,
BeaconBlockBodyT any,
ConsensusSidecarsT any,
BlobSidecarsT any,
LoggerT any,
] struct {
depinject.In

AvailabilityStore AvailabilityStoreT
BlobProcessor BlobProcessor[
AvailabilityStoreT, BeaconBlockBodyT, BlobSidecarsT,
AvailabilityStoreT, ConsensusSidecarsT, BlobSidecarsT,
]
Dispatcher Dispatcher
Logger LoggerT
Expand All @@ -149,7 +151,7 @@ func ProvideDAService[
LoggerT log.AdvancedLogger[LoggerT],
](
in DAServiceIn[
AvailabilityStoreT, BeaconBlockBodyT, BlobSidecarsT, LoggerT,
AvailabilityStoreT, ConsensusSidecarsT, BlobSidecarsT, LoggerT,
],
) *da.Service[
AvailabilityStoreT,
Expand Down
4 changes: 2 additions & 2 deletions mod/node-core/pkg/components/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ type (
// BlobProcessor is the interface for the blobs processor.
BlobProcessor[
AvailabilityStoreT any,
BeaconBlockBodyT any,
ConsensusSidecarsT any,
BlobSidecarsT any,
] interface {
// ProcessSidecars processes the blobs and ensures they match the local
Expand All @@ -239,7 +239,7 @@ type (
// VerifySidecars verifies the blobs and ensures they match the local
// state.
VerifySidecars(
sidecars BlobSidecarsT,
sidecars ConsensusSidecarsT,
) error
}

Expand Down

0 comments on commit 16540c0

Please sign in to comment.