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

Ensure Block Processing Failures Return an Error #2325

Merged
merged 8 commits into from
Apr 21, 2019
Merged
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
1 change: 1 addition & 0 deletions beacon-chain/blockchain/block_processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (c *ChainService) ReceiveBlock(ctx context.Context, block *pb.BeaconBlock)
if err := c.beaconDB.DeleteBlock(block); err != nil {
return nil, fmt.Errorf("could not delete bad block from db: %v", err)
}
return beaconState, err
default:
return beaconState, fmt.Errorf("could not apply block state transition: %v", err)
}
Expand Down
15 changes: 13 additions & 2 deletions beacon-chain/blockchain/block_processing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/internal"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
Expand Down Expand Up @@ -220,6 +221,9 @@ func TestReceiveBlock_UsesParentBlockState(t *testing.T) {
}

func TestReceiveBlock_DeletesBadBlock(t *testing.T) {
featureconfig.InitFeatureConfig(&featureconfig.FeatureFlagConfig{
EnableCheckBlockStateRoot: false,
})
db := internal.SetupDB(t)
defer internal.TeardownDB(t, db)
ctx := context.Background()
Expand Down Expand Up @@ -274,8 +278,12 @@ func TestReceiveBlock_DeletesBadBlock(t *testing.T) {
t.Fatal(err)
}

if _, err := chainService.ReceiveBlock(context.Background(), block); err == nil {
t.Error("Expected block to fail processing, received nil")
_, err = chainService.ReceiveBlock(context.Background(), block)
switch err.(type) {
case *BlockFailedProcessingErr:
t.Log("Block failed processing as expected")
default:
t.Errorf("Unexpected block processing error: %v", err)
}

savedBlock, err := db.Block(blockRoot)
Expand All @@ -289,6 +297,9 @@ func TestReceiveBlock_DeletesBadBlock(t *testing.T) {
if !db.IsEvilBlockHash(blockRoot) {
t.Error("Expected block root to have been blacklisted")
}
featureconfig.InitFeatureConfig(&featureconfig.FeatureFlagConfig{
EnableCheckBlockStateRoot: true,
})
}

func TestReceiveBlock_CheckBlockStateRoot_GoodState(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions beacon-chain/sync/initial-sync/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func (s *InitialSync) exitInitialSync(ctx context.Context, block *pb.BeaconBlock
if err := s.db.DeleteBlock(block); err != nil {
return fmt.Errorf("could not delete bad block from db: %v", err)
}
return fmt.Errorf("could not apply block state transition: %v", err)
default:
return fmt.Errorf("could not apply block state transition: %v", err)
}
Expand Down