Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Broadcast Slashing on equivocation #14693

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
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
25 changes: 25 additions & 0 deletions beacon-chain/blockchain/process_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ func (s *Service) postBlockProcess(cfg *postBlockProcessConfig) error {
defer reportProcessingTime(startTime)
defer reportAttestationInclusion(cfg.roblock.Block())

// Check for equivocation before inserting into fork choice
slashing, slashingErr := s.detectEquivocatingBlock(cfg.ctx, cfg.roblock)
if slashingErr != nil {
return errors.Wrap(slashingErr, "could not detect equivocating block")

Choose a reason for hiding this comment

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

this should probably log instead of returning and preventing FCU? could not check for block equivocation seems more accurate

}

if slashing != nil {
if err := s.broadcastProposerSlashing(cfg.ctx, slashing); err != nil {
log.WithError(err).Error("Could not broadcast proposer slashing")
}

// Also insert into slashing pool
if err := s.cfg.SlashingPool.InsertProposerSlashing(cfg.ctx, cfg.postState, slashing); err != nil {
log.WithError(err).Error("Could not insert proposer slashing into pool")
}
}

err := s.cfg.ForkChoiceStore.InsertNode(ctx, cfg.postState, cfg.roblock)
if err != nil {
// Do not use parent context in the event it deadlined
Expand Down Expand Up @@ -706,3 +723,11 @@ func (s *Service) rollbackBlock(ctx context.Context, blockRoot [32]byte) {
log.WithError(err).Errorf("Could not delete block with block root %#x", blockRoot)
}
}

func (s *Service) broadcastProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) error {
if features.Get().DisableBroadcastSlashings {
return nil
}

return s.cfg.P2p.Broadcast(ctx, slashing)
}
47 changes: 47 additions & 0 deletions beacon-chain/blockchain/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,3 +580,50 @@
}
go slots.CountdownToGenesis(ctx, genesisTime, uint64(gState.NumValidators()), gRoot)
}

func (s *Service) detectEquivocatingBlock(ctx context.Context, block interfaces.ReadOnlySignedBeaconBlock) (*ethpb.ProposerSlashing, error) {
// Get the incoming block's header
header1, err := block.Header()
if err != nil {
return nil, errors.Wrap(err, "could not get header from incoming block")
}

s.headLock.RLock()
headBlock, err := s.headBlock()
if err != nil {
s.headLock.RUnlock()
return nil, errors.Wrap(err, "could not get head block")
}
s.headLock.RUnlock()

// Get the head block's header
header2, err := headBlock.Header()
if err != nil {
return nil, errors.Wrap(err, "could not get header from head block")
}

// Check for equivocation:
if header1.Header.Slot == header2.Header.Slot &&
header1.Header.ProposerIndex == header2.Header.ProposerIndex {

Check failure on line 607 in beacon-chain/blockchain/service.go

View workflow job for this annotation

GitHub Actions / Lint

unnecessary leading newline (whitespace)

header1Root, err := header1.Header.HashTreeRoot()
if err != nil {
return nil, errors.Wrap(err, "could not hash header 1")
}

header2Root, err := header2.Header.HashTreeRoot()
if err != nil {
return nil, errors.Wrap(err, "could not hash header 2")
}

// Different header roots means equivocation
if header1Root != header2Root {
return &ethpb.ProposerSlashing{
Header_1: header1,
Header_2: header2,
}, nil
}
}

return nil, nil
}
Loading