Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions consensus/cometbft/service/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ package cometbft

import (
"time"

cmttypes "github.com/cometbft/cometbft/types"
)

// TelemetrySink is an interface for sending metrics to a telemetry backend.
Expand All @@ -31,3 +33,8 @@ type TelemetrySink interface {
// MeasureSince measures the time since the given time.
MeasureSince(key string, start time.Time, args ...string)
}

// PrivValidatorConsumer consumes a CometBFT PrivValidator reference.
type PrivValidatorConsumer interface {
SetPrivValidator(cmttypes.PrivValidator)
}
7 changes: 7 additions & 0 deletions consensus/cometbft/service/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ func SetInterBlockCache(cache storetypes.MultiStorePersistentCache) func(*Servic
}
}

// SetPrivValidatorConsumer configures the Service to share its PrivValidator.
func SetPrivValidatorConsumer(consumer PrivValidatorConsumer) func(*Service) {
return func(s *Service) {
s.privValConsumer = consumer
}
}

// SetChainID sets the chain ID in cometbft.
func SetChainID(chainID string) func(*Service) {
return func(s *Service) { s.chainID = chainID }
Expand Down
8 changes: 7 additions & 1 deletion consensus/cometbft/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ type Service struct {
cmtCfg *cmtcfg.Config

telemetrySink TelemetrySink
// privValConsumer consumes the PrivValidator created during Start.
privValConsumer PrivValidatorConsumer

logger *phuslu.Logger
sm *statem.Manager
Expand Down Expand Up @@ -203,7 +205,6 @@ func (s *Service) Start(
if err != nil {
return err
}

s.ResetAppCtx(ctx)
s.node, err = node.NewNode(
ctx,
Expand All @@ -220,6 +221,11 @@ func (s *Service) Start(
return err
}

// The privval has been started, we can now swap the FilePV
if s.privValConsumer != nil {
s.privValConsumer.SetPrivValidator(s.node.PrivValidator())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be helpful to log here when we swap the PrivValidator

}

pubKey, errPk := s.node.PrivValidator().GetPubKey()
if errPk != nil {
return fmt.Errorf("failed retrieving pub key: %w", err)
Expand Down
9 changes: 8 additions & 1 deletion node-core/components/cometbft_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/berachain/beacon-kit/log/phuslu"
"github.com/berachain/beacon-kit/node-core/builder"
"github.com/berachain/beacon-kit/node-core/components/metrics"
"github.com/berachain/beacon-kit/primitives/crypto"
cmtcfg "github.com/cometbft/cometbft/config"
dbm "github.com/cosmos/cosmos-db"
)
Expand All @@ -43,7 +44,13 @@ func ProvideCometBFTService(
cmtCfg *cmtcfg.Config,
appOpts config.AppOptions,
telemetrySink *metrics.TelemetrySink,
blsSigner crypto.BLSSigner,
) *cometbft.Service {
options := builder.DefaultServiceOptions(appOpts)
if consumer, ok := blsSigner.(cometbft.PrivValidatorConsumer); ok {
options = append(options, cometbft.SetPrivValidatorConsumer(consumer))
}

return cometbft.NewService(
logger,
db,
Expand All @@ -52,6 +59,6 @@ func ProvideCometBFTService(
cs,
cmtCfg,
telemetrySink,
builder.DefaultServiceOptions(appOpts)...,
options...,
)
}
5 changes: 5 additions & 0 deletions node-core/components/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ type BLSSigner struct {
types.PrivValidator
}

// SetPrivValidator swaps the underlying PrivValidator the signer delegates to.
func (f *BLSSigner) SetPrivValidator(pv types.PrivValidator) {
f.PrivValidator = pv
}

// NewBLSSigner creates a new BLSSigner instance using the provided key and
// state
// file paths.
Expand Down
Loading