2020-03-26 18:31:20 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-08-04 19:50:23 +00:00
|
|
|
"fmt"
|
|
|
|
"sync"
|
2020-03-26 18:31:20 +00:00
|
|
|
"testing"
|
|
|
|
|
2020-05-05 05:15:32 +00:00
|
|
|
"github.com/golang/mock/gomock"
|
2020-03-26 18:31:20 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
2020-05-05 05:15:32 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
2020-08-04 19:50:23 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/state"
|
2020-05-05 05:15:32 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/bls"
|
2020-05-08 05:51:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
2020-05-05 05:15:32 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/mock"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/p2putils"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
2020-08-18 12:41:25 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
2020-05-05 05:15:32 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/slasher/beaconclient"
|
2020-03-26 18:31:20 +00:00
|
|
|
testDB "github.com/prysmaticlabs/prysm/slasher/db/testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/slasher/detection"
|
|
|
|
)
|
|
|
|
|
2020-05-08 05:51:56 +00:00
|
|
|
func TestServer_IsSlashableAttestation(t *testing.T) {
|
2020-03-26 18:31:20 +00:00
|
|
|
db := testDB.SetupSlasherDB(t, false)
|
2020-05-05 05:15:32 +00:00
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
defer ctrl.Finish()
|
|
|
|
bClient := mock.NewMockBeaconChainClient(ctrl)
|
|
|
|
nClient := mock.NewMockNodeClient(ctrl)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
_, keys, err := testutil.DeterministicDepositsAndKeys(4)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err)
|
2020-05-05 05:15:32 +00:00
|
|
|
wantedValidators1 := ðpb.Validators{
|
|
|
|
ValidatorList: []*ethpb.Validators_ValidatorContainer{
|
|
|
|
{
|
|
|
|
Index: 3, Validator: ðpb.Validator{PublicKey: keys[3].PublicKey().Marshal()},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-03-26 18:31:20 +00:00
|
|
|
|
2020-05-05 05:15:32 +00:00
|
|
|
wantedGenesis := ðpb.Genesis{
|
2020-08-27 18:13:32 +00:00
|
|
|
GenesisValidatorsRoot: bytesutil.PadTo([]byte("I am genesis"), 32),
|
2020-05-05 05:15:32 +00:00
|
|
|
}
|
2020-08-04 19:50:23 +00:00
|
|
|
|
2020-03-26 18:31:20 +00:00
|
|
|
savedAttestation := ðpb.IndexedAttestation{
|
|
|
|
AttestingIndices: []uint64{3},
|
|
|
|
Data: ðpb.AttestationData{
|
2020-08-27 18:13:32 +00:00
|
|
|
Source: ðpb.Checkpoint{Epoch: 3, Root: make([]byte, 32)},
|
|
|
|
Target: ðpb.Checkpoint{Epoch: 4, Root: make([]byte, 32)},
|
|
|
|
BeaconBlockRoot: make([]byte, 32),
|
2020-03-26 18:31:20 +00:00
|
|
|
},
|
2020-08-27 18:13:32 +00:00
|
|
|
Signature: make([]byte, 96),
|
2020-03-26 18:31:20 +00:00
|
|
|
}
|
2020-08-04 19:50:23 +00:00
|
|
|
|
2020-03-26 18:31:20 +00:00
|
|
|
cfg := &detection.Config{
|
|
|
|
SlasherDB: db,
|
|
|
|
}
|
2020-08-04 19:50:23 +00:00
|
|
|
fork, err := p2putils.Fork(savedAttestation.Data.Target.Epoch)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err)
|
2020-05-05 05:15:32 +00:00
|
|
|
|
|
|
|
bcCfg := &beaconclient.Config{BeaconClient: bClient, NodeClient: nClient, SlasherDB: db}
|
2020-09-23 08:59:49 +00:00
|
|
|
bs, err := beaconclient.NewService(ctx, bcCfg)
|
2020-10-01 18:53:36 +00:00
|
|
|
require.NoError(t, err)
|
2020-09-23 08:59:49 +00:00
|
|
|
ds := detection.NewService(ctx, cfg)
|
2020-05-05 05:15:32 +00:00
|
|
|
server := Server{ctx: ctx, detector: ds, slasherDB: db, beaconClient: bs}
|
2020-08-04 19:50:23 +00:00
|
|
|
nClient.EXPECT().GetGenesis(gomock.Any(), gomock.Any()).Return(wantedGenesis, nil).AnyTimes()
|
2020-05-05 05:15:32 +00:00
|
|
|
bClient.EXPECT().ListValidators(
|
|
|
|
gomock.Any(),
|
|
|
|
gomock.Any(),
|
2020-08-04 19:50:23 +00:00
|
|
|
).Return(wantedValidators1, nil).AnyTimes()
|
|
|
|
domain, err := helpers.Domain(fork, savedAttestation.Data.Target.Epoch, params.BeaconConfig().DomainBeaconAttester, wantedGenesis.GenesisValidatorsRoot)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err)
|
2020-08-04 19:50:23 +00:00
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
wg.Add(100)
|
|
|
|
var wentThrough bool
|
|
|
|
for i := uint64(0); i < 100; i++ {
|
|
|
|
go func(j uint64) {
|
|
|
|
defer wg.Done()
|
|
|
|
iatt := state.CopyIndexedAttestation(savedAttestation)
|
|
|
|
iatt.Data.Slot += j
|
|
|
|
root, err := helpers.ComputeSigningRoot(iatt.Data, domain)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err)
|
2020-10-12 16:12:00 +00:00
|
|
|
validatorSig := keys[iatt.AttestingIndices[0]].Sign(root[:])
|
2020-08-04 19:50:23 +00:00
|
|
|
marshalledSig := validatorSig.Marshal()
|
|
|
|
iatt.Signature = marshalledSig
|
|
|
|
slashings, err := server.IsSlashableAttestation(ctx, iatt)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err, "Got error while trying to detect slashing")
|
2020-08-04 19:50:23 +00:00
|
|
|
|
|
|
|
if len(slashings.AttesterSlashing) == 0 && !wentThrough {
|
|
|
|
wentThrough = true
|
|
|
|
} else if len(slashings.AttesterSlashing) == 0 && wentThrough {
|
|
|
|
t.Fatalf("Only one attestation should go through without slashing: %v", iatt)
|
|
|
|
}
|
|
|
|
}(i)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
2020-03-26 18:31:20 +00:00
|
|
|
}
|
2020-05-08 05:51:56 +00:00
|
|
|
|
2020-06-11 18:50:12 +00:00
|
|
|
func TestServer_IsSlashableAttestationNoUpdate(t *testing.T) {
|
|
|
|
db := testDB.SetupSlasherDB(t, false)
|
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
defer ctrl.Finish()
|
|
|
|
bClient := mock.NewMockBeaconChainClient(ctrl)
|
|
|
|
nClient := mock.NewMockNodeClient(ctrl)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
_, keys, err := testutil.DeterministicDepositsAndKeys(4)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err)
|
2020-06-11 18:50:12 +00:00
|
|
|
wantedValidators1 := ðpb.Validators{
|
|
|
|
ValidatorList: []*ethpb.Validators_ValidatorContainer{
|
|
|
|
{
|
|
|
|
Index: 3, Validator: ðpb.Validator{PublicKey: keys[3].PublicKey().Marshal()},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
bClient.EXPECT().ListValidators(
|
|
|
|
gomock.Any(),
|
|
|
|
gomock.Any(),
|
|
|
|
).Return(wantedValidators1, nil)
|
|
|
|
|
|
|
|
wantedGenesis := ðpb.Genesis{
|
2020-08-27 18:13:32 +00:00
|
|
|
GenesisValidatorsRoot: bytesutil.PadTo([]byte("I am genesis"), 32),
|
2020-06-11 18:50:12 +00:00
|
|
|
}
|
|
|
|
nClient.EXPECT().GetGenesis(gomock.Any(), gomock.Any()).Return(wantedGenesis, nil)
|
|
|
|
savedAttestation := ðpb.IndexedAttestation{
|
|
|
|
AttestingIndices: []uint64{3},
|
|
|
|
Data: ðpb.AttestationData{
|
2020-08-27 18:13:32 +00:00
|
|
|
Source: ðpb.Checkpoint{Epoch: 3, Root: make([]byte, 32)},
|
|
|
|
Target: ðpb.Checkpoint{Epoch: 4, Root: make([]byte, 32)},
|
|
|
|
BeaconBlockRoot: make([]byte, 32),
|
2020-06-11 18:50:12 +00:00
|
|
|
},
|
2020-08-27 18:13:32 +00:00
|
|
|
Signature: make([]byte, 96),
|
2020-06-11 18:50:12 +00:00
|
|
|
}
|
|
|
|
incomingAtt := ðpb.IndexedAttestation{
|
|
|
|
AttestingIndices: []uint64{1, 3},
|
|
|
|
Data: ðpb.AttestationData{
|
2020-08-27 18:13:32 +00:00
|
|
|
Source: ðpb.Checkpoint{Epoch: 2, Root: make([]byte, 32)},
|
|
|
|
Target: ðpb.Checkpoint{Epoch: 4, Root: make([]byte, 32)},
|
|
|
|
BeaconBlockRoot: make([]byte, 32),
|
2020-06-11 18:50:12 +00:00
|
|
|
},
|
2020-08-27 18:13:32 +00:00
|
|
|
Signature: make([]byte, 96),
|
2020-06-11 18:50:12 +00:00
|
|
|
}
|
|
|
|
cfg := &detection.Config{
|
|
|
|
SlasherDB: db,
|
|
|
|
}
|
|
|
|
fork, err := p2putils.Fork(savedAttestation.Data.Target.Epoch)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err)
|
2020-06-11 18:50:12 +00:00
|
|
|
domain, err := helpers.Domain(fork, savedAttestation.Data.Target.Epoch, params.BeaconConfig().DomainBeaconAttester, wantedGenesis.GenesisValidatorsRoot)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err)
|
2020-06-11 18:50:12 +00:00
|
|
|
root, err := helpers.ComputeSigningRoot(savedAttestation.Data, domain)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err)
|
2020-10-12 08:11:05 +00:00
|
|
|
var sig []bls.Signature
|
2020-06-11 18:50:12 +00:00
|
|
|
for _, idx := range savedAttestation.AttestingIndices {
|
|
|
|
validatorSig := keys[idx].Sign(root[:])
|
|
|
|
sig = append(sig, validatorSig)
|
|
|
|
}
|
|
|
|
aggSig := bls.AggregateSignatures(sig)
|
|
|
|
marshalledSig := aggSig.Marshal()
|
|
|
|
|
|
|
|
savedAttestation.Signature = marshalledSig
|
|
|
|
|
|
|
|
bcCfg := &beaconclient.Config{BeaconClient: bClient, NodeClient: nClient, SlasherDB: db}
|
2020-09-23 08:59:49 +00:00
|
|
|
bs, err := beaconclient.NewService(ctx, bcCfg)
|
2020-10-01 18:53:36 +00:00
|
|
|
require.NoError(t, err)
|
2020-09-23 08:59:49 +00:00
|
|
|
ds := detection.NewService(ctx, cfg)
|
2020-06-11 18:50:12 +00:00
|
|
|
server := Server{ctx: ctx, detector: ds, slasherDB: db, beaconClient: bs}
|
|
|
|
slashings, err := server.IsSlashableAttestation(ctx, savedAttestation)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err, "Got error while trying to detect slashing")
|
|
|
|
require.Equal(t, 0, len(slashings.AttesterSlashing), "Found slashings while no slashing should have been found on first attestation")
|
2020-06-11 18:50:12 +00:00
|
|
|
sl, err := server.IsSlashableAttestationNoUpdate(ctx, incomingAtt)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err, "Got error while trying to detect slashing")
|
|
|
|
require.Equal(t, true, sl.Slashable, "Attestation should be found to be slashable")
|
2020-06-11 18:50:12 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 05:51:56 +00:00
|
|
|
func TestServer_IsSlashableBlock(t *testing.T) {
|
|
|
|
db := testDB.SetupSlasherDB(t, false)
|
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
defer ctrl.Finish()
|
|
|
|
bClient := mock.NewMockBeaconChainClient(ctrl)
|
|
|
|
nClient := mock.NewMockNodeClient(ctrl)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
_, keys, err := testutil.DeterministicDepositsAndKeys(4)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err)
|
2020-05-08 05:51:56 +00:00
|
|
|
wantedValidators := ðpb.Validators{
|
|
|
|
ValidatorList: []*ethpb.Validators_ValidatorContainer{
|
|
|
|
{
|
|
|
|
Index: 1, Validator: ðpb.Validator{PublicKey: keys[1].PublicKey().Marshal()},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
bClient.EXPECT().ListValidators(
|
|
|
|
gomock.Any(),
|
|
|
|
gomock.Any(),
|
2020-08-04 19:50:23 +00:00
|
|
|
).Return(wantedValidators, nil).AnyTimes()
|
2020-05-08 05:51:56 +00:00
|
|
|
|
|
|
|
wantedGenesis := ðpb.Genesis{
|
2020-08-27 18:13:32 +00:00
|
|
|
GenesisValidatorsRoot: bytesutil.PadTo([]byte("I am genesis"), 32),
|
2020-05-08 05:51:56 +00:00
|
|
|
}
|
2020-08-04 19:50:23 +00:00
|
|
|
nClient.EXPECT().GetGenesis(gomock.Any(), gomock.Any()).Return(wantedGenesis, nil).AnyTimes()
|
2020-05-08 05:51:56 +00:00
|
|
|
savedBlock := ðpb.SignedBeaconBlockHeader{
|
|
|
|
Header: ðpb.BeaconBlockHeader{
|
|
|
|
Slot: 1,
|
|
|
|
ProposerIndex: 1,
|
|
|
|
BodyRoot: bytesutil.PadTo([]byte("body root"), 32),
|
2020-08-27 18:13:32 +00:00
|
|
|
StateRoot: make([]byte, 32),
|
|
|
|
ParentRoot: make([]byte, 32),
|
2020-05-08 05:51:56 +00:00
|
|
|
},
|
2020-08-27 18:13:32 +00:00
|
|
|
Signature: make([]byte, 96),
|
2020-05-08 05:51:56 +00:00
|
|
|
}
|
2020-08-04 19:50:23 +00:00
|
|
|
|
2020-05-08 05:51:56 +00:00
|
|
|
cfg := &detection.Config{
|
|
|
|
SlasherDB: db,
|
|
|
|
}
|
2020-08-04 19:50:23 +00:00
|
|
|
savedBlockEpoch := helpers.SlotToEpoch(savedBlock.Header.Slot)
|
|
|
|
fork, err := p2putils.Fork(savedBlockEpoch)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err)
|
2020-08-04 19:50:23 +00:00
|
|
|
domain, err := helpers.Domain(fork, savedBlockEpoch, params.BeaconConfig().DomainBeaconProposer, wantedGenesis.GenesisValidatorsRoot)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err)
|
2020-05-08 05:51:56 +00:00
|
|
|
|
|
|
|
bcCfg := &beaconclient.Config{BeaconClient: bClient, NodeClient: nClient, SlasherDB: db}
|
2020-09-23 08:59:49 +00:00
|
|
|
bs, err := beaconclient.NewService(ctx, bcCfg)
|
2020-10-01 18:53:36 +00:00
|
|
|
require.NoError(t, err)
|
2020-09-23 08:59:49 +00:00
|
|
|
ds := detection.NewService(ctx, cfg)
|
2020-05-08 05:51:56 +00:00
|
|
|
server := Server{ctx: ctx, detector: ds, slasherDB: db, beaconClient: bs}
|
2020-08-04 19:50:23 +00:00
|
|
|
|
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
wg.Add(100)
|
|
|
|
var wentThrough bool
|
|
|
|
for i := uint64(0); i < 100; i++ {
|
|
|
|
go func(j uint64) {
|
|
|
|
defer wg.Done()
|
|
|
|
sbbh := state.CopySignedBeaconBlockHeader(savedBlock)
|
|
|
|
sbbh.Header.BodyRoot = bytesutil.PadTo([]byte(fmt.Sprintf("%d", j)), 32)
|
2020-08-27 18:13:32 +00:00
|
|
|
bhr, err := sbbh.Header.HashTreeRoot()
|
2020-08-18 12:41:25 +00:00
|
|
|
assert.NoError(t, err)
|
2020-08-04 19:50:23 +00:00
|
|
|
root, err := helpers.ComputeSigningRoot(bhr, domain)
|
2020-08-18 12:41:25 +00:00
|
|
|
assert.NoError(t, err)
|
2020-08-04 19:50:23 +00:00
|
|
|
sbbh.Signature = keys[sbbh.Header.ProposerIndex].Sign(root[:]).Marshal()
|
|
|
|
slashings, err := server.IsSlashableBlock(ctx, sbbh)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err, "Got error while trying to detect slashing")
|
2020-08-04 19:50:23 +00:00
|
|
|
if len(slashings.ProposerSlashing) == 0 && !wentThrough {
|
|
|
|
wentThrough = true
|
|
|
|
} else if len(slashings.ProposerSlashing) == 0 && wentThrough {
|
|
|
|
t.Fatalf("Only one block should go through without slashing: %v", sbbh)
|
|
|
|
}
|
|
|
|
}(i)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
2020-05-08 05:51:56 +00:00
|
|
|
}
|
2020-06-11 18:50:12 +00:00
|
|
|
|
|
|
|
func TestServer_IsSlashableBlockNoUpdate(t *testing.T) {
|
|
|
|
db := testDB.SetupSlasherDB(t, false)
|
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
defer ctrl.Finish()
|
|
|
|
bClient := mock.NewMockBeaconChainClient(ctrl)
|
|
|
|
nClient := mock.NewMockNodeClient(ctrl)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
_, keys, err := testutil.DeterministicDepositsAndKeys(4)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err)
|
2020-06-11 18:50:12 +00:00
|
|
|
wantedValidators := ðpb.Validators{
|
|
|
|
ValidatorList: []*ethpb.Validators_ValidatorContainer{
|
|
|
|
{
|
|
|
|
Index: 1, Validator: ðpb.Validator{PublicKey: keys[1].PublicKey().Marshal()},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
bClient.EXPECT().ListValidators(
|
|
|
|
gomock.Any(),
|
|
|
|
gomock.Any(),
|
|
|
|
).Return(wantedValidators, nil)
|
|
|
|
|
|
|
|
wantedGenesis := ðpb.Genesis{
|
2020-08-27 18:13:32 +00:00
|
|
|
GenesisValidatorsRoot: bytesutil.PadTo([]byte("I am genesis"), 32),
|
2020-06-11 18:50:12 +00:00
|
|
|
}
|
|
|
|
nClient.EXPECT().GetGenesis(gomock.Any(), gomock.Any()).Return(wantedGenesis, nil)
|
|
|
|
savedBlock := ðpb.SignedBeaconBlockHeader{
|
|
|
|
Header: ðpb.BeaconBlockHeader{
|
|
|
|
Slot: 1,
|
|
|
|
ProposerIndex: 1,
|
|
|
|
BodyRoot: bytesutil.PadTo([]byte("body root"), 32),
|
2020-08-27 18:13:32 +00:00
|
|
|
StateRoot: bytesutil.PadTo([]byte("state root"), 32),
|
|
|
|
ParentRoot: bytesutil.PadTo([]byte("parent root"), 32),
|
2020-06-11 18:50:12 +00:00
|
|
|
},
|
2020-08-27 18:13:32 +00:00
|
|
|
Signature: make([]byte, 96),
|
2020-06-11 18:50:12 +00:00
|
|
|
}
|
|
|
|
incomingBlock := ðpb.BeaconBlockHeader{
|
|
|
|
Slot: 1,
|
|
|
|
ProposerIndex: 1,
|
|
|
|
BodyRoot: bytesutil.PadTo([]byte("body root2"), 32),
|
2020-08-27 18:13:32 +00:00
|
|
|
StateRoot: bytesutil.PadTo([]byte("state root2"), 32),
|
|
|
|
ParentRoot: bytesutil.PadTo([]byte("parent root2"), 32),
|
2020-06-11 18:50:12 +00:00
|
|
|
}
|
|
|
|
cfg := &detection.Config{
|
|
|
|
SlasherDB: db,
|
|
|
|
}
|
|
|
|
savedBlockEpoch := helpers.SlotToEpoch(savedBlock.Header.Slot)
|
|
|
|
fork, err := p2putils.Fork(savedBlockEpoch)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err)
|
2020-06-11 18:50:12 +00:00
|
|
|
domain, err := helpers.Domain(fork, savedBlockEpoch, params.BeaconConfig().DomainBeaconProposer, wantedGenesis.GenesisValidatorsRoot)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err)
|
2020-08-27 18:13:32 +00:00
|
|
|
bhr, err := savedBlock.Header.HashTreeRoot()
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err)
|
2020-06-11 18:50:12 +00:00
|
|
|
root, err := helpers.ComputeSigningRoot(bhr, domain)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err)
|
2020-06-11 18:50:12 +00:00
|
|
|
blockSig := keys[savedBlock.Header.ProposerIndex].Sign(root[:])
|
|
|
|
marshalledSig := blockSig.Marshal()
|
|
|
|
savedBlock.Signature = marshalledSig
|
|
|
|
bcCfg := &beaconclient.Config{BeaconClient: bClient, NodeClient: nClient, SlasherDB: db}
|
2020-09-23 08:59:49 +00:00
|
|
|
bs, err := beaconclient.NewService(ctx, bcCfg)
|
2020-10-01 18:53:36 +00:00
|
|
|
require.NoError(t, err)
|
2020-09-23 08:59:49 +00:00
|
|
|
ds := detection.NewService(ctx, cfg)
|
2020-06-11 18:50:12 +00:00
|
|
|
server := Server{ctx: ctx, detector: ds, slasherDB: db, beaconClient: bs}
|
|
|
|
slashings, err := server.IsSlashableBlock(ctx, savedBlock)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err, "Got error while trying to detect slashing")
|
|
|
|
require.Equal(t, 0, len(slashings.ProposerSlashing), "Found slashings while no slashing should have been found on first block")
|
2020-06-11 18:50:12 +00:00
|
|
|
sl, err := server.IsSlashableBlockNoUpdate(ctx, incomingBlock)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err, "Got error while trying to detect slashing")
|
|
|
|
require.Equal(t, true, sl.Slashable, "Block should be found to be slashable")
|
2020-06-11 18:50:12 +00:00
|
|
|
}
|