mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
Return early from ReceiveBlock if already sycned (#13089)
* Return early from ReceiveBlock if already sycned * Fix bad setup test
This commit is contained in:
@@ -3,6 +3,7 @@ package blockchain
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -58,6 +59,11 @@ type SlashingReceiver interface {
|
||||
func (s *Service) ReceiveBlock(ctx context.Context, block interfaces.ReadOnlySignedBeaconBlock, blockRoot [32]byte) error {
|
||||
ctx, span := trace.StartSpan(ctx, "blockChain.ReceiveBlock")
|
||||
defer span.End()
|
||||
// Return early if the block has been synced
|
||||
if s.InForkchoice(blockRoot) {
|
||||
log.WithField("blockRoot", fmt.Sprintf("%#x", blockRoot)).Debug("Ignoring already synced block")
|
||||
return nil
|
||||
}
|
||||
receivedTime := time.Now()
|
||||
s.blockBeingSynced.set(blockRoot)
|
||||
defer s.blockBeingSynced.unset(blockRoot)
|
||||
|
||||
@@ -26,6 +26,9 @@ func TestBuilderInvalidBlock(t *testing.T) {
|
||||
blk, err := blocks.NewSignedBeaconBlock(util.NewBeaconBlock())
|
||||
require.NoError(t, err)
|
||||
builder := NewBuilder(t, st, blk)
|
||||
blk, err = blocks.NewSignedBeaconBlock(util.NewBeaconBlock())
|
||||
blk.SetSlot(2)
|
||||
require.NoError(t, err)
|
||||
builder.InvalidBlock(t, blk)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user