mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 20:37:17 +00:00
9edba29f64
* slashing simulator * add in necessary items for slasher sim * sim item * fix up * fixed build * rev * slasher sim in testing * testonly * gaz * gaz * fix viz Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: prestonvanloon <preston@prysmaticlabs.com>
49 lines
1.6 KiB
Go
49 lines
1.6 KiB
Go
package simulator
|
|
|
|
import (
|
|
"testing"
|
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
|
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
|
dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
|
|
"github.com/prysmaticlabs/prysm/crypto/bls"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
"github.com/prysmaticlabs/prysm/testing/util"
|
|
)
|
|
|
|
func setupService(t *testing.T, params *Parameters) *Simulator {
|
|
slasherDB := dbtest.SetupSlasherDB(t)
|
|
beaconState, err := util.NewBeaconState()
|
|
require.NoError(t, err)
|
|
|
|
// We setup validators in the beacon state along with their
|
|
// private keys used to generate valid signatures in generated objects.
|
|
validators := make([]*ethpb.Validator, params.NumValidators)
|
|
privKeys := make(map[types.ValidatorIndex]bls.SecretKey)
|
|
for valIdx := range validators {
|
|
privKey, err := bls.RandKey()
|
|
require.NoError(t, err)
|
|
privKeys[types.ValidatorIndex(valIdx)] = privKey
|
|
validators[valIdx] = ðpb.Validator{
|
|
PublicKey: privKey.PublicKey().Marshal(),
|
|
WithdrawalCredentials: make([]byte, 32),
|
|
}
|
|
}
|
|
err = beaconState.SetValidators(validators)
|
|
require.NoError(t, err)
|
|
|
|
gen := stategen.NewMockService()
|
|
gen.AddStateForRoot(beaconState, [32]byte{})
|
|
return &Simulator{
|
|
srvConfig: &ServiceConfig{
|
|
Params: params,
|
|
Database: slasherDB,
|
|
AttestationStateFetcher: &mock.ChainService{State: beaconState},
|
|
PrivateKeysByValidatorIndex: privKeys,
|
|
StateGen: gen,
|
|
},
|
|
}
|
|
}
|