Skip to content

Commit

Permalink
wip: adding consensus data to blocks to be verified
Browse files Browse the repository at this point in the history
  • Loading branch information
abi87 committed Oct 23, 2024
1 parent 69efa86 commit 8b87b65
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
9 changes: 8 additions & 1 deletion mod/consensus/pkg/cometbft/service/middleware/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

"github.com/berachain/beacon-kit/mod/consensus/pkg/cometbft/service/encoding"
"github.com/berachain/beacon-kit/mod/consensus/pkg/types"
"github.com/berachain/beacon-kit/mod/errors"
"github.com/berachain/beacon-kit/mod/primitives/pkg/async"
"github.com/berachain/beacon-kit/mod/primitives/pkg/encoding/json"
Expand Down Expand Up @@ -220,7 +221,13 @@ func (h *ABCIMiddleware[
}

// notify that the beacon block has been received.
blkEvent := async.NewEvent(ctx, async.BeaconBlockReceived, blk)
var enrichedBlk *types.ConsensusBlock[BeaconBlockT]
enrichedBlk = enrichedBlk.New(
blk,
ctx.BlockTime(),
ctx.BlockHeader().ProposerAddress,
)
blkEvent := async.NewEvent(ctx, async.BeaconBlockReceived, enrichedBlk)
if err = h.dispatcher.Publish(blkEvent); err != nil {
return h.createProcessProposalResponse(errors.WrapNonFatal(err))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,53 +22,43 @@ package types

import (
"time"

"github.com/berachain/beacon-kit/mod/primitives/pkg/math"
)

type ConsensusEnrichedBlock[BeaconBlockT any] struct {
type ConsensusBlock[BeaconBlockT any] struct {
blk BeaconBlockT

// blkTime assigned by CometBFT to the beacon block
blkTime time.Time
blkTime math.U64

// block proposer address assigned by CometBFT to the beacon block
blkProposerAddress []byte
}

// New creates a new SlotData instance.
func (b *ConsensusEnrichedBlock[BeaconBlockT]) New(
func (b *ConsensusBlock[BeaconBlockT]) New(
beaconBlock BeaconBlockT,
blkTime time.Time,
blkProposerAddress []byte,
) *ConsensusEnrichedBlock[BeaconBlockT] {
b = &ConsensusEnrichedBlock[BeaconBlockT]{
) *ConsensusBlock[BeaconBlockT] {
b = &ConsensusBlock[BeaconBlockT]{
blk: beaconBlock,
blkTime: blkTime,
blkTime: math.U64(blkTime.Unix()),
blkProposerAddress: blkProposerAddress,
}
return b
}

func NewBlockFromConsensus[BeaconBlockT any](
beaconBlock BeaconBlockT,
blkTime time.Time,
blkProposerAddress []byte,
) *ConsensusEnrichedBlock[BeaconBlockT] {
return &ConsensusEnrichedBlock[BeaconBlockT]{
blk: beaconBlock,
blkTime: blkTime,
blkProposerAddress: blkProposerAddress,
}
}

func (b *ConsensusEnrichedBlock[BeaconBlockT]) GetBeaconBlock() BeaconBlockT {
func (b *ConsensusBlock[BeaconBlockT]) GetBeaconBlock() BeaconBlockT {
return b.blk
}

func (b *ConsensusEnrichedBlock[_]) GetConsensusBlockTime() time.Time {
func (b *ConsensusBlock[_]) GetConsensusBlockTime() math.U64 {
return b.blkTime
}

// TODO: harden the return type
func (b *ConsensusEnrichedBlock[_]) GetConsensusProposerAddress() []byte {
func (b *ConsensusBlock[_]) GetConsensusProposerAddress() []byte {
return b.blkProposerAddress
}

0 comments on commit 8b87b65

Please sign in to comment.