mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Eliminate Custody Logic for Phase 0 (#1408)
This commit is contained in:
@@ -333,7 +333,7 @@ func TestRunningChainService(t *testing.T) {
|
||||
for i := uint64(0); i < params.BeaconConfig().EpochLength*2; i++ {
|
||||
ShardCommittees = append(ShardCommittees, &pb.ShardCommitteeArray{
|
||||
ArrayShardCommittee: []*pb.ShardCommittee{
|
||||
{Committee: []uint32{9, 8, 311, 12, 92, 1, 23, 17}},
|
||||
{Committee: []uint64{9, 8, 311, 12, 92, 1, 23, 17}},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ test_cases:
|
||||
proposal_2_slot: 15
|
||||
proposal_2_root: !!binary |
|
||||
LkmqmqoodLKAslkjdkajsdljasdkajlksjdasldjasdd
|
||||
casper_slashings:
|
||||
- slot: 59 # At slot 59, we trigger a casper slashing
|
||||
attester_slashings:
|
||||
- slot: 59 # At slot 59, we trigger a attester slashing
|
||||
slashable_vote_data_1_slot: 55
|
||||
slashable_vote_data_2_slot: 55
|
||||
slashable_vote_data_1_justified_slot: 0
|
||||
@@ -110,7 +110,7 @@ The following configuration options are available for state transition tests:
|
||||
- **num_slots**: `int` the number of times we run a state transition in the test
|
||||
- **deposits**: `[Deposit Config]` trigger a new validator deposit into the beacon state based on configuration options
|
||||
- **proposer_slashings**: `[Proposer Slashing Config]` trigger a proposer slashing at a certain slot for a certain proposer index
|
||||
- **casper_slashings**: `[Casper Slashing Config]` trigger a casper slashing at a certain slot
|
||||
- **attester_slashings**: `[Casper Slashing Config]` trigger a attester slashing at a certain slot
|
||||
- **validator_exits**: `[Validator Exit Config]` trigger a voluntary validator exit at a certain slot for a validator index
|
||||
|
||||
**Deposit Config**
|
||||
@@ -133,7 +133,7 @@ The following configuration options are available for state transition tests:
|
||||
|
||||
**Casper Slashing Config**
|
||||
|
||||
- **slot**: `int` a slot in which to trigger a casper slashing during a state transition test
|
||||
- **slot**: `int` a slot in which to trigger a attester slashing during a state transition test
|
||||
- **slashable_vote_data_1_slot**: `int` the slot of the attestation data of slashableVoteData1
|
||||
- **slashable_vote_data_2_slot**: `int` the slot of the attestation data of slashableVoteData2
|
||||
- **slashable_vote_data_1_justified_slot**: `int` the justified slot of the attestation data of slashableVoteData1
|
||||
|
||||
@@ -24,7 +24,7 @@ func generateSimulatedBlock(
|
||||
simulatedDeposit *StateTestDeposit,
|
||||
depositsTrie *trie.DepositTrie,
|
||||
simulatedProposerSlashing *StateTestProposerSlashing,
|
||||
simulatedCasperSlashing *StateTestCasperSlashing,
|
||||
simulatedAttesterSlashing *StateTestAttesterSlashing,
|
||||
simulatedExit *StateTestValidatorExit,
|
||||
) (*pb.BeaconBlock, [32]byte, error) {
|
||||
encodedState, err := proto.Marshal(beaconState)
|
||||
@@ -39,7 +39,7 @@ func generateSimulatedBlock(
|
||||
StateRootHash32: stateRoot[:],
|
||||
Body: &pb.BeaconBlockBody{
|
||||
ProposerSlashings: []*pb.ProposerSlashing{},
|
||||
CasperSlashings: []*pb.CasperSlashing{},
|
||||
AttesterSlashings: []*pb.AttesterSlashing{},
|
||||
Attestations: []*pb.Attestation{},
|
||||
Deposits: []*pb.Deposit{},
|
||||
Exits: []*pb.Exit{},
|
||||
@@ -85,23 +85,23 @@ func generateSimulatedBlock(
|
||||
},
|
||||
})
|
||||
}
|
||||
if simulatedCasperSlashing != nil {
|
||||
block.Body.CasperSlashings = append(block.Body.CasperSlashings, &pb.CasperSlashing{
|
||||
SlashableVoteData_1: &pb.SlashableVoteData{
|
||||
if simulatedAttesterSlashing != nil {
|
||||
block.Body.AttesterSlashings = append(block.Body.AttesterSlashings, &pb.AttesterSlashing{
|
||||
SlashableVote_1: &pb.SlashableVote{
|
||||
Data: &pb.AttestationData{
|
||||
Slot: simulatedCasperSlashing.SlashableVoteData1Slot,
|
||||
JustifiedSlot: simulatedCasperSlashing.SlashableVoteData1JustifiedSlot,
|
||||
Slot: simulatedAttesterSlashing.SlashableVote1Slot,
|
||||
JustifiedSlot: simulatedAttesterSlashing.SlashableVote1JustifiedSlot,
|
||||
},
|
||||
CustodyBit_0Indices: simulatedCasperSlashing.SlashableVoteData1CustodyBit0Indices,
|
||||
CustodyBit_1Indices: simulatedCasperSlashing.SlashableVoteData1CustodyBit1Indices,
|
||||
CustodyBitfield: []byte(simulatedAttesterSlashing.SlashableVote1CustodyBitField),
|
||||
ValidatorIndices: simulatedAttesterSlashing.SlashableVote1ValidatorIndices,
|
||||
},
|
||||
SlashableVoteData_2: &pb.SlashableVoteData{
|
||||
SlashableVote_2: &pb.SlashableVote{
|
||||
Data: &pb.AttestationData{
|
||||
Slot: simulatedCasperSlashing.SlashableVoteData2Slot,
|
||||
JustifiedSlot: simulatedCasperSlashing.SlashableVoteData2JustifiedSlot,
|
||||
Slot: simulatedAttesterSlashing.SlashableVote2Slot,
|
||||
JustifiedSlot: simulatedAttesterSlashing.SlashableVote2JustifiedSlot,
|
||||
},
|
||||
CustodyBit_0Indices: simulatedCasperSlashing.SlashableVoteData2CustodyBit0Indices,
|
||||
CustodyBit_1Indices: simulatedCasperSlashing.SlashableVoteData2CustodyBit1Indices,
|
||||
CustodyBitfield: []byte(simulatedAttesterSlashing.SlashableVote2CustodyBitField),
|
||||
ValidatorIndices: simulatedAttesterSlashing.SlashableVote2ValidatorIndices,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ type ShuffleTest struct {
|
||||
|
||||
// ShuffleTestCase --
|
||||
type ShuffleTestCase struct {
|
||||
Input []uint32 `yaml:"input,flow"`
|
||||
Output []uint32 `yaml:"output,flow"`
|
||||
Input []uint64 `yaml:"input,flow"`
|
||||
Output []uint64 `yaml:"output,flow"`
|
||||
Seed string
|
||||
}
|
||||
|
||||
@@ -151,9 +151,9 @@ func (sb *SimulatedBackend) RunStateTransitionTest(testCase *StateTestCase) erro
|
||||
prevBlockRoots := [][32]byte{genesisBlockRoot}
|
||||
|
||||
// We keep track of the randao layers peeled for each proposer index in a map.
|
||||
layersPeeledForProposer := make(map[uint32]int, len(beaconState.ValidatorRegistry))
|
||||
layersPeeledForProposer := make(map[uint64]int, len(beaconState.ValidatorRegistry))
|
||||
for idx := range beaconState.ValidatorRegistry {
|
||||
layersPeeledForProposer[uint32(idx)] = 0
|
||||
layersPeeledForProposer[uint64(idx)] = 0
|
||||
}
|
||||
|
||||
depositsTrie := trie.NewDepositTrie()
|
||||
@@ -195,10 +195,10 @@ func (sb *SimulatedBackend) RunStateTransitionTest(testCase *StateTestCase) erro
|
||||
break
|
||||
}
|
||||
}
|
||||
var simulatedCasperSlashing *StateTestCasperSlashing
|
||||
for _, cSlashing := range testCase.Config.CasperSlashings {
|
||||
var simulatedAttesterSlashing *StateTestAttesterSlashing
|
||||
for _, cSlashing := range testCase.Config.AttesterSlashings {
|
||||
if cSlashing.Slot == i {
|
||||
simulatedCasperSlashing = cSlashing
|
||||
simulatedAttesterSlashing = cSlashing
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -222,7 +222,7 @@ func (sb *SimulatedBackend) RunStateTransitionTest(testCase *StateTestCase) erro
|
||||
simulatedDeposit,
|
||||
depositsTrie,
|
||||
simulatedProposerSlashing,
|
||||
simulatedCasperSlashing,
|
||||
simulatedAttesterSlashing,
|
||||
simulatedValidatorExit,
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@@ -22,7 +22,7 @@ type StateTestConfig struct {
|
||||
DepositSlots []uint64 `yaml:"deposit_slots"`
|
||||
Deposits []*StateTestDeposit `yaml:"deposits"`
|
||||
ProposerSlashings []*StateTestProposerSlashing `yaml:"proposer_slashings"`
|
||||
CasperSlashings []*StateTestCasperSlashing `yaml:"casper_slashings"`
|
||||
AttesterSlashings []*StateTestAttesterSlashing `yaml:"attester_slashings"`
|
||||
ValidatorExits []*StateTestValidatorExit `yaml:"validator_exits"`
|
||||
EpochLength uint64 `yaml:"epoch_length"`
|
||||
ShardCount uint64 `yaml:"shard_count"`
|
||||
@@ -41,7 +41,7 @@ type StateTestDeposit struct {
|
||||
// StateTestProposerSlashing --
|
||||
type StateTestProposerSlashing struct {
|
||||
Slot uint64 `yaml:"slot"`
|
||||
ProposerIndex uint32 `yaml:"proposer_index"`
|
||||
ProposerIndex uint64 `yaml:"proposer_index"`
|
||||
Proposal1Shard uint64 `yaml:"proposal_1_shard"`
|
||||
Proposal2Shard uint64 `yaml:"proposal_2_shard"`
|
||||
Proposal1Slot uint64 `yaml:"proposal_1_slot"`
|
||||
@@ -50,29 +50,29 @@ type StateTestProposerSlashing struct {
|
||||
Proposal2Root string `yaml:"proposal_2_root"`
|
||||
}
|
||||
|
||||
// StateTestCasperSlashing --
|
||||
type StateTestCasperSlashing struct {
|
||||
Slot uint64 `yaml:"slot"`
|
||||
SlashableVoteData1Slot uint64 `yaml:"slashable_vote_data_1_slot"`
|
||||
SlashableVoteData1JustifiedSlot uint64 `yaml:"slashable_vote_data_1_justified_slot"`
|
||||
SlashableVoteData1CustodyBit0Indices []uint32 `yaml:"slashable_vote_data_1_custody_0_indices"`
|
||||
SlashableVoteData1CustodyBit1Indices []uint32 `yaml:"slashable_vote_data_1_custody_1_indices"`
|
||||
SlashableVoteData2Slot uint64 `yaml:"slashable_vote_data_2_slot"`
|
||||
SlashableVoteData2JustifiedSlot uint64 `yaml:"slashable_vote_data_2_justified_slot"`
|
||||
SlashableVoteData2CustodyBit0Indices []uint32 `yaml:"slashable_vote_data_2_custody_0_indices"`
|
||||
SlashableVoteData2CustodyBit1Indices []uint32 `yaml:"slashable_vote_data_2_custody_1_indices"`
|
||||
// StateTestAttesterSlashing --
|
||||
type StateTestAttesterSlashing struct {
|
||||
Slot uint64 `yaml:"slot"`
|
||||
SlashableVote1Slot uint64 `yaml:"slashable_vote_1_slot"`
|
||||
SlashableVote1JustifiedSlot uint64 `yaml:"slashable_vote_1_justified_slot"`
|
||||
SlashableVote1ValidatorIndices []uint64 `yaml:"slashable_vote_1_validator_indices"`
|
||||
SlashableVote1CustodyBitField string `yaml:"slashable_vote_1_custody_bitfield"`
|
||||
SlashableVote2Slot uint64 `yaml:"slashable_vote_2_slot"`
|
||||
SlashableVote2JustifiedSlot uint64 `yaml:"slashable_vote_2_justified_slot"`
|
||||
SlashableVote2ValidatorIndices []uint64 `yaml:"slashable_vote_2_validator_indices"`
|
||||
SlashableVote2CustodyBitField string `yaml:"slashable_vote_2_custody_bitfield"`
|
||||
}
|
||||
|
||||
// StateTestValidatorExit --
|
||||
type StateTestValidatorExit struct {
|
||||
Slot uint64 `yaml:"slot"`
|
||||
ValidatorIndex uint32 `yaml:"validator_index"`
|
||||
ValidatorIndex uint64 `yaml:"validator_index"`
|
||||
}
|
||||
|
||||
// StateTestResults --
|
||||
type StateTestResults struct {
|
||||
Slot uint64
|
||||
NumValidators int `yaml:"num_validators"`
|
||||
PenalizedValidators []uint32 `yaml:"penalized_validators"`
|
||||
ExitedValidators []uint32 `yaml:"exited_validators"`
|
||||
PenalizedValidators []uint64 `yaml:"penalized_validators"`
|
||||
ExitedValidators []uint64 `yaml:"exited_validators"`
|
||||
}
|
||||
|
||||
@@ -22,19 +22,19 @@ func readTestsFromYaml(yamlDir string) ([]interface{}, error) {
|
||||
|
||||
dirs, err := ioutil.ReadDir(yamlDir)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not read yaml tests directory: %v", err)
|
||||
return nil, fmt.Errorf("could not read YAML tests directory: %v", err)
|
||||
}
|
||||
for _, dir := range dirs {
|
||||
files, err := ioutil.ReadDir(path.Join(yamlDir, dir.Name()))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not read yaml tests directory: %v", err)
|
||||
return nil, fmt.Errorf("could not read YAML tests directory: %v", err)
|
||||
}
|
||||
for _, file := range files {
|
||||
filePath := path.Join(yamlDir, dir.Name(), file.Name())
|
||||
// #nosec G304
|
||||
data, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not read yaml file: %v", err)
|
||||
return nil, fmt.Errorf("could not read YAML file: %v", err)
|
||||
}
|
||||
switch dir.Name() {
|
||||
case forkChoiceTestsFolderName:
|
||||
|
||||
@@ -42,16 +42,16 @@ test_cases:
|
||||
proposal_2_slot: 15
|
||||
proposal_2_root: !!binary |
|
||||
LkmqmqoodLKAslkjdkajsdljasdkajlksjdasldjasdd
|
||||
casper_slashings:
|
||||
- slot: 59 # At slot 59, we trigger a casper slashing
|
||||
slashable_vote_data_1_slot: 55
|
||||
slashable_vote_data_2_slot: 55
|
||||
slashable_vote_data_1_justified_slot: 0
|
||||
slashable_vote_data_2_justified_slot: 1
|
||||
slashable_vote_data_1_custody_0_indices: [16386]
|
||||
slashable_vote_data_1_custody_1_indices: []
|
||||
slashable_vote_data_2_custody_0_indices: []
|
||||
slashable_vote_data_2_custody_1_indices: [16386]
|
||||
attester_slashings:
|
||||
- slot: 59 # At slot 59, we trigger a attester slashing
|
||||
slashable_vote_1_slot: 55
|
||||
slashable_vote_2_slot: 55
|
||||
slashable_vote_1_justified_slot: 0
|
||||
slashable_vote_2_justified_slot: 1
|
||||
slashable_vote_1_custody_bitfield: !binary "F"
|
||||
slashable_vote_1_validator_indices: [16386]
|
||||
slashable_vote_2_custody_bitfield: !binary "F"
|
||||
slashable_vote_2_validator_indices: [16386]
|
||||
validator_exits:
|
||||
- slot: 60
|
||||
validator_index: 100 # At slot 60, validator at index 100 triggers a voluntary exit
|
||||
|
||||
@@ -31,7 +31,7 @@ var config = params.BeaconConfig()
|
||||
// loses base_reward(state, index).
|
||||
func ExpectedFFGSource(
|
||||
state *pb.BeaconState,
|
||||
justifiedAttesterIndices []uint32,
|
||||
justifiedAttesterIndices []uint64,
|
||||
justifiedAttestingBalance uint64,
|
||||
totalBalance uint64) *pb.BeaconState {
|
||||
|
||||
@@ -68,7 +68,7 @@ func ExpectedFFGSource(
|
||||
// base_reward(state, index).
|
||||
func ExpectedFFGTarget(
|
||||
state *pb.BeaconState,
|
||||
boundaryAttesterIndices []uint32,
|
||||
boundaryAttesterIndices []uint64,
|
||||
boundaryAttestingBalance uint64,
|
||||
totalBalance uint64) *pb.BeaconState {
|
||||
|
||||
@@ -105,7 +105,7 @@ func ExpectedFFGTarget(
|
||||
// base_reward(state, index).
|
||||
func ExpectedBeaconChainHead(
|
||||
state *pb.BeaconState,
|
||||
headAttesterIndices []uint32,
|
||||
headAttesterIndices []uint64,
|
||||
headAttestingBalance uint64,
|
||||
totalBalance uint64) *pb.BeaconState {
|
||||
|
||||
@@ -138,7 +138,7 @@ func ExpectedBeaconChainHead(
|
||||
// inclusion_distance(state, index)
|
||||
func InclusionDistance(
|
||||
state *pb.BeaconState,
|
||||
attesterIndices []uint32,
|
||||
attesterIndices []uint64,
|
||||
totalBalance uint64) (*pb.BeaconState, error) {
|
||||
|
||||
baseRewardQuotient := baseRewardQuotient(totalBalance)
|
||||
@@ -165,7 +165,7 @@ func InclusionDistance(
|
||||
// loses inactivity_penalty(state, index, epochs_since_finality)
|
||||
func InactivityFFGSource(
|
||||
state *pb.BeaconState,
|
||||
justifiedAttesterIndices []uint32,
|
||||
justifiedAttesterIndices []uint64,
|
||||
totalBalance uint64,
|
||||
epochsSinceFinality uint64) *pb.BeaconState {
|
||||
|
||||
@@ -189,7 +189,7 @@ func InactivityFFGSource(
|
||||
// loses inactivity_penalty(state, index, epochs_since_finality)
|
||||
func InactivityFFGTarget(
|
||||
state *pb.BeaconState,
|
||||
boundaryAttesterIndices []uint32,
|
||||
boundaryAttesterIndices []uint64,
|
||||
totalBalance uint64,
|
||||
epochsSinceFinality uint64) *pb.BeaconState {
|
||||
|
||||
@@ -213,7 +213,7 @@ func InactivityFFGTarget(
|
||||
// loses base_reward(state, index)
|
||||
func InactivityChainHead(
|
||||
state *pb.BeaconState,
|
||||
headAttesterIndices []uint32,
|
||||
headAttesterIndices []uint64,
|
||||
totalBalance uint64) *pb.BeaconState {
|
||||
|
||||
baseRewardQuotient := baseRewardQuotient(totalBalance)
|
||||
@@ -261,7 +261,7 @@ func InactivityExitedPenalties(
|
||||
// MIN_ATTESTATION_INCLUSION_DELAY // inclusion_distance(state, index)
|
||||
func InactivityInclusionDistance(
|
||||
state *pb.BeaconState,
|
||||
attesterIndices []uint32,
|
||||
attesterIndices []uint64,
|
||||
totalBalance uint64) (*pb.BeaconState, error) {
|
||||
|
||||
baseRewardQuotient := baseRewardQuotient(totalBalance)
|
||||
@@ -291,7 +291,7 @@ func InactivityInclusionDistance(
|
||||
func AttestationInclusion(
|
||||
state *pb.BeaconState,
|
||||
totalBalance uint64,
|
||||
prevEpochAttesterIndices []uint32) (*pb.BeaconState, error) {
|
||||
prevEpochAttesterIndices []uint64) (*pb.BeaconState, error) {
|
||||
|
||||
baseRewardQuotient := baseRewardQuotient(totalBalance)
|
||||
for _, index := range prevEpochAttesterIndices {
|
||||
@@ -400,7 +400,7 @@ func baseRewardQuotient(totalBalance uint64) uint64 {
|
||||
// get_effective_balance(state, index) // base_reward_quotient // 5
|
||||
func baseReward(
|
||||
state *pb.BeaconState,
|
||||
validatorIndex uint32,
|
||||
validatorIndex uint64,
|
||||
baseRewardQuotient uint64) uint64 {
|
||||
|
||||
validatorBalance := validators.EffectiveBalance(state, validatorIndex)
|
||||
@@ -416,7 +416,7 @@ func baseReward(
|
||||
// * epochs_since_finality // INACTIVITY_PENALTY_QUOTIENT // 2
|
||||
func inactivityPenalty(
|
||||
state *pb.BeaconState,
|
||||
validatorIndex uint32,
|
||||
validatorIndex uint64,
|
||||
baseRewardQuotient uint64,
|
||||
epochsSinceFinality uint64) uint64 {
|
||||
|
||||
|
||||
@@ -83,15 +83,15 @@ func TestInactivityPenalty(t *testing.T) {
|
||||
|
||||
func TestFFGSrcRewardsPenalties(t *testing.T) {
|
||||
tests := []struct {
|
||||
voted []uint32
|
||||
voted []uint64
|
||||
balanceAfterSrcRewardPenalties []uint64
|
||||
}{
|
||||
// voted represents the validator indices that voted for FFG source,
|
||||
// balanceAfterSrcRewardPenalties represents their final balances,
|
||||
// validators who voted should get an increase, who didn't should get a decrease.
|
||||
{[]uint32{}, []uint64{31999427550, 31999427550, 31999427550, 31999427550}},
|
||||
{[]uint32{0, 1}, []uint64{32000286225, 32000286225, 31999427550, 31999427550}},
|
||||
{[]uint32{0, 1, 2, 3}, []uint64{32000572450, 32000572450, 32000572450, 32000572450}},
|
||||
{[]uint64{}, []uint64{31999427550, 31999427550, 31999427550, 31999427550}},
|
||||
{[]uint64{0, 1}, []uint64{32000286225, 32000286225, 31999427550, 31999427550}},
|
||||
{[]uint64{0, 1, 2, 3}, []uint64{32000572450, 32000572450, 32000572450, 32000572450}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
validatorBalances := make([]uint64, 4)
|
||||
@@ -122,15 +122,15 @@ func TestFFGSrcRewardsPenalties(t *testing.T) {
|
||||
|
||||
func TestFFGTargetRewardsPenalties(t *testing.T) {
|
||||
tests := []struct {
|
||||
voted []uint32
|
||||
voted []uint64
|
||||
balanceAfterTgtRewardPenalties []uint64
|
||||
}{
|
||||
// voted represents the validator indices that voted for FFG target,
|
||||
// balanceAfterTgtRewardPenalties represents their final balances,
|
||||
// validators who voted should get an increase, who didn't should get a decrease.
|
||||
{[]uint32{}, []uint64{31999427550, 31999427550, 31999427550, 31999427550}},
|
||||
{[]uint32{0, 1}, []uint64{32000286225, 32000286225, 31999427550, 31999427550}},
|
||||
{[]uint32{0, 1, 2, 3}, []uint64{32000572450, 32000572450, 32000572450, 32000572450}},
|
||||
{[]uint64{}, []uint64{31999427550, 31999427550, 31999427550, 31999427550}},
|
||||
{[]uint64{0, 1}, []uint64{32000286225, 32000286225, 31999427550, 31999427550}},
|
||||
{[]uint64{0, 1, 2, 3}, []uint64{32000572450, 32000572450, 32000572450, 32000572450}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
validatorBalances := make([]uint64, 4)
|
||||
@@ -161,15 +161,15 @@ func TestFFGTargetRewardsPenalties(t *testing.T) {
|
||||
|
||||
func TestChainHeadRewardsPenalties(t *testing.T) {
|
||||
tests := []struct {
|
||||
voted []uint32
|
||||
voted []uint64
|
||||
balanceAfterHeadRewardPenalties []uint64
|
||||
}{
|
||||
// voted represents the validator indices that voted for canonical chain,
|
||||
// balanceAfterHeadRewardPenalties represents their final balances,
|
||||
// validators who voted should get an increase, who didn't should get a decrease.
|
||||
{[]uint32{}, []uint64{31999427550, 31999427550, 31999427550, 31999427550}},
|
||||
{[]uint32{0, 1}, []uint64{32000286225, 32000286225, 31999427550, 31999427550}},
|
||||
{[]uint32{0, 1, 2, 3}, []uint64{32000572450, 32000572450, 32000572450, 32000572450}},
|
||||
{[]uint64{}, []uint64{31999427550, 31999427550, 31999427550, 31999427550}},
|
||||
{[]uint64{0, 1}, []uint64{32000286225, 32000286225, 31999427550, 31999427550}},
|
||||
{[]uint64{0, 1, 2, 3}, []uint64{32000572450, 32000572450, 32000572450, 32000572450}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
validatorBalances := make([]uint64, 4)
|
||||
@@ -213,11 +213,11 @@ func TestInclusionDistRewards_Ok(t *testing.T) {
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
voted []uint32
|
||||
voted []uint64
|
||||
}{
|
||||
{[]uint32{}},
|
||||
{[]uint32{237, 224}},
|
||||
{[]uint32{237, 224, 2, 242}},
|
||||
{[]uint64{}},
|
||||
{[]uint64{237, 224}},
|
||||
{[]uint64{237, 224, 2, 242}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
validatorBalances := make([]uint64, config.EpochLength*4)
|
||||
@@ -262,10 +262,10 @@ func TestInclusionDistRewards_NotOk(t *testing.T) {
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
voted []uint32
|
||||
voted []uint64
|
||||
balanceAfterInclusionRewards []uint64
|
||||
}{
|
||||
{[]uint32{0, 1, 2, 3}, []uint64{}},
|
||||
{[]uint64{0, 1, 2, 3}, []uint64{}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
state := &pb.BeaconState{
|
||||
@@ -281,15 +281,15 @@ func TestInclusionDistRewards_NotOk(t *testing.T) {
|
||||
|
||||
func TestInactivityFFGSrcPenalty(t *testing.T) {
|
||||
tests := []struct {
|
||||
voted []uint32
|
||||
voted []uint64
|
||||
balanceAfterFFGSrcPenalty []uint64
|
||||
epochsSinceFinality uint64
|
||||
}{
|
||||
// The higher the epochs since finality, the more penalties applied.
|
||||
{[]uint32{0, 1}, []uint64{32000000000, 32000000000, 31999422782, 31999422782}, 5},
|
||||
{[]uint32{}, []uint64{31999422782, 31999422782, 31999422782, 31999422782}, 5},
|
||||
{[]uint32{}, []uint64{31999418014, 31999418014, 31999418014, 31999418014}, 10},
|
||||
{[]uint32{}, []uint64{31999408477, 31999408477, 31999408477, 31999408477}, 20},
|
||||
{[]uint64{0, 1}, []uint64{32000000000, 32000000000, 31999422782, 31999422782}, 5},
|
||||
{[]uint64{}, []uint64{31999422782, 31999422782, 31999422782, 31999422782}, 5},
|
||||
{[]uint64{}, []uint64{31999418014, 31999418014, 31999418014, 31999418014}, 10},
|
||||
{[]uint64{}, []uint64{31999408477, 31999408477, 31999408477, 31999408477}, 20},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
validatorBalances := make([]uint64, 4)
|
||||
@@ -320,15 +320,15 @@ func TestInactivityFFGSrcPenalty(t *testing.T) {
|
||||
|
||||
func TestInactivityFFGTargetPenalty(t *testing.T) {
|
||||
tests := []struct {
|
||||
voted []uint32
|
||||
voted []uint64
|
||||
balanceAfterFFGTargetPenalty []uint64
|
||||
epochsSinceFinality uint64
|
||||
}{
|
||||
// The higher the epochs since finality, the more penalties applied.
|
||||
{[]uint32{0, 1}, []uint64{32000000000, 32000000000, 31999422782, 31999422782}, 5},
|
||||
{[]uint32{}, []uint64{31999422782, 31999422782, 31999422782, 31999422782}, 5},
|
||||
{[]uint32{}, []uint64{31999418014, 31999418014, 31999418014, 31999418014}, 10},
|
||||
{[]uint32{}, []uint64{31999408477, 31999408477, 31999408477, 31999408477}, 20},
|
||||
{[]uint64{0, 1}, []uint64{32000000000, 32000000000, 31999422782, 31999422782}, 5},
|
||||
{[]uint64{}, []uint64{31999422782, 31999422782, 31999422782, 31999422782}, 5},
|
||||
{[]uint64{}, []uint64{31999418014, 31999418014, 31999418014, 31999418014}, 10},
|
||||
{[]uint64{}, []uint64{31999408477, 31999408477, 31999408477, 31999408477}, 20},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
validatorBalances := make([]uint64, 4)
|
||||
@@ -359,12 +359,12 @@ func TestInactivityFFGTargetPenalty(t *testing.T) {
|
||||
|
||||
func TestInactivityHeadPenalty(t *testing.T) {
|
||||
tests := []struct {
|
||||
voted []uint32
|
||||
voted []uint64
|
||||
balanceAfterInactivityHeadPenalty []uint64
|
||||
}{
|
||||
{[]uint32{}, []uint64{31999427550, 31999427550, 31999427550, 31999427550}},
|
||||
{[]uint32{0, 1}, []uint64{32000000000, 32000000000, 31999427550, 31999427550}},
|
||||
{[]uint32{0, 1, 2, 3}, []uint64{32000000000, 32000000000, 32000000000, 32000000000}},
|
||||
{[]uint64{}, []uint64{31999427550, 31999427550, 31999427550, 31999427550}},
|
||||
{[]uint64{0, 1}, []uint64{32000000000, 32000000000, 31999427550, 31999427550}},
|
||||
{[]uint64{0, 1, 2, 3}, []uint64{32000000000, 32000000000, 32000000000, 32000000000}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
validatorBalances := make([]uint64, 4)
|
||||
@@ -441,11 +441,11 @@ func TestInactivityInclusionPenalty_Ok(t *testing.T) {
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
voted []uint32
|
||||
voted []uint64
|
||||
}{
|
||||
{[]uint32{}},
|
||||
{[]uint32{237, 224}},
|
||||
{[]uint32{237, 224, 2, 242}},
|
||||
{[]uint64{}},
|
||||
{[]uint64{237, 224}},
|
||||
{[]uint64{237, 224, 2, 242}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
validatorBalances := make([]uint64, config.EpochLength*4)
|
||||
@@ -489,10 +489,10 @@ func TestInactivityInclusionPenalty_NotOk(t *testing.T) {
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
voted []uint32
|
||||
voted []uint64
|
||||
balanceAfterInclusionRewards []uint64
|
||||
}{
|
||||
{[]uint32{0, 1, 2, 3}, []uint64{}},
|
||||
{[]uint64{0, 1, 2, 3}, []uint64{}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
state := &pb.BeaconState{
|
||||
@@ -521,10 +521,10 @@ func TestAttestationInclusionRewards(t *testing.T) {
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
voted []uint32
|
||||
voted []uint64
|
||||
}{
|
||||
{[]uint32{}},
|
||||
{[]uint32{237}},
|
||||
{[]uint64{}},
|
||||
{[]uint64{237}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
validatorBalances := make([]uint64, config.EpochLength*4)
|
||||
@@ -564,10 +564,10 @@ func TestAttestationInclusionRewards_NoInclusionSlot(t *testing.T) {
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
voted []uint32
|
||||
voted []uint64
|
||||
balanceAfterAttestationInclusion []uint64
|
||||
}{
|
||||
{[]uint32{0, 1, 2, 3}, []uint64{32000000000, 32000000000, 32000000000, 32000000000}},
|
||||
{[]uint64{0, 1, 2, 3}, []uint64{32000000000, 32000000000, 32000000000, 32000000000}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
validatorBalances := make([]uint64, 4)
|
||||
@@ -598,10 +598,10 @@ func TestAttestationInclusionRewards_NoProposerIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
voted []uint32
|
||||
voted []uint64
|
||||
balanceAfterAttestationInclusion []uint64
|
||||
}{
|
||||
{[]uint32{0}, []uint64{32000071022, 32000000000, 32000000000, 32000000000}},
|
||||
{[]uint64{0}, []uint64{32000071022, 32000000000, 32000000000, 32000000000}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
validatorBalances := make([]uint64, 4)
|
||||
|
||||
@@ -16,6 +16,7 @@ go_library(
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//shared/bytes:go_default_library",
|
||||
"//shared/hashutil:go_default_library",
|
||||
"//shared/mathutil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/slices:go_default_library",
|
||||
"//shared/ssz:go_default_library",
|
||||
|
||||
@@ -31,7 +31,7 @@ func NewGenesisBlock(stateRoot []byte) *pb.BeaconBlock {
|
||||
Signature: config.EmptySignature,
|
||||
Body: &pb.BeaconBlockBody{
|
||||
ProposerSlashings: []*pb.ProposerSlashing{},
|
||||
CasperSlashings: []*pb.CasperSlashing{},
|
||||
AttesterSlashings: []*pb.AttesterSlashing{},
|
||||
Attestations: []*pb.Attestation{},
|
||||
Deposits: []*pb.Deposit{},
|
||||
Exits: []*pb.Exit{},
|
||||
|
||||
@@ -6,6 +6,7 @@ package blocks
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
@@ -14,6 +15,7 @@ import (
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
bytesutil "github.com/prysmaticlabs/prysm/shared/bytes"
|
||||
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/mathutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/slices"
|
||||
"github.com/prysmaticlabs/prysm/shared/trie"
|
||||
@@ -181,54 +183,54 @@ func verifyProposerSlashing(
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProcessCasperSlashings is one of the operations performed
|
||||
// ProcessAttesterSlashings is one of the operations performed
|
||||
// on each processed beacon block to penalize validators based on
|
||||
// Casper FFG slashing conditions if any slashable events occurred.
|
||||
//
|
||||
// Official spec definition for casper slashings:
|
||||
// Official spec definition for attester slashings:
|
||||
//
|
||||
// Verify that len(block.body.casper_slashings) <= MAX_CASPER_SLASHINGS.
|
||||
// For each casper_slashing in block.body.casper_slashings:
|
||||
// Verify that len(block.body.attester_slashings) <= MAX_CASPER_SLASHINGS.
|
||||
// For each attester_slashing in block.body.attester_slashings:
|
||||
//
|
||||
// Verify that verify_casper_votes(state, casper_slashing.votes_1).
|
||||
// Verify that verify_casper_votes(state, casper_slashing.votes_2).
|
||||
// Verify that casper_slashing.votes_1.data != casper_slashing.votes_2.data.
|
||||
// Verify that verify_attester_votes(state, attester_slashing.votes_1).
|
||||
// Verify that verify_attester_votes(state, attester_slashing.votes_2).
|
||||
// Verify that attester_slashing.votes_1.data != attester_slashing.votes_2.data.
|
||||
// Let indices(vote) = vote.aggregate_signature_poc_0_indices +
|
||||
// vote.aggregate_signature_poc_1_indices.
|
||||
// Let intersection = [x for x in indices(casper_slashing.votes_1)
|
||||
// if x in indices(casper_slashing.votes_2)].
|
||||
// Let intersection = [x for x in indices(attester_slashing.votes_1)
|
||||
// if x in indices(attester_slashing.votes_2)].
|
||||
// Verify that len(intersection) >= 1.
|
||||
// Verify the following about the casper votes:
|
||||
// Verify the following about the attester votes:
|
||||
// (vote1.justified_slot < vote2.justified_slot) &&
|
||||
// (vote2.justified_slot + 1 == vote2.slot) &&
|
||||
// (vote2.slot < vote1.slot)
|
||||
// OR
|
||||
// vote1.slot == vote.slot
|
||||
// Verify that casper_slashing.votes_1.data.justified_slot + 1 <
|
||||
// casper_slashing.votes_2.data.justified_slot + 1 ==
|
||||
// casper_slashing.votes_2.data.slot < casper_slashing.votes_1.data.slot
|
||||
// or casper_slashing.votes_1.data.slot == casper_slashing.votes_2.data.slot.
|
||||
// Verify that attester_slashing.votes_1.data.justified_slot + 1 <
|
||||
// attester_slashing.votes_2.data.justified_slot + 1 ==
|
||||
// attester_slashing.votes_2.data.slot < attester_slashing.votes_1.data.slot
|
||||
// or attester_slashing.votes_1.data.slot == attester_slashing.votes_2.data.slot.
|
||||
// For each validator index i in intersection,
|
||||
// if state.validator_registry[i].penalized_slot > state.slot, then
|
||||
// run penalize_validator(state, i)
|
||||
func ProcessCasperSlashings(
|
||||
func ProcessAttesterSlashings(
|
||||
beaconState *pb.BeaconState,
|
||||
block *pb.BeaconBlock,
|
||||
) (*pb.BeaconState, error) {
|
||||
body := block.Body
|
||||
registry := beaconState.ValidatorRegistry
|
||||
if uint64(len(body.CasperSlashings)) > params.BeaconConfig().MaxCasperSlashings {
|
||||
if uint64(len(body.AttesterSlashings)) > params.BeaconConfig().MaxAttesterSlashings {
|
||||
return nil, fmt.Errorf(
|
||||
"number of casper slashings (%d) exceeds allowed threshold of %d",
|
||||
len(body.CasperSlashings),
|
||||
params.BeaconConfig().MaxCasperSlashings,
|
||||
"number of attester slashings (%d) exceeds allowed threshold of %d",
|
||||
len(body.AttesterSlashings),
|
||||
params.BeaconConfig().MaxAttesterSlashings,
|
||||
)
|
||||
}
|
||||
for idx, slashing := range body.CasperSlashings {
|
||||
if err := verifyCasperSlashing(slashing); err != nil {
|
||||
return nil, fmt.Errorf("could not verify casper slashing #%d: %v", idx, err)
|
||||
for idx, slashing := range body.AttesterSlashings {
|
||||
if err := verifyAttesterSlashing(slashing); err != nil {
|
||||
return nil, fmt.Errorf("could not verify attester slashing #%d: %v", idx, err)
|
||||
}
|
||||
validatorIndices, err := casperSlashingPenalizedIndices(slashing)
|
||||
validatorIndices, err := attesterSlashingPenalizedIndices(slashing)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not determine validator indices to penalize: %v", err)
|
||||
}
|
||||
@@ -246,17 +248,17 @@ func ProcessCasperSlashings(
|
||||
return beaconState, nil
|
||||
}
|
||||
|
||||
func verifyCasperSlashing(slashing *pb.CasperSlashing) error {
|
||||
slashableVoteData1 := slashing.SlashableVoteData_1
|
||||
slashableVoteData2 := slashing.SlashableVoteData_2
|
||||
slashableVoteData1Attestation := slashableVoteData1.Data
|
||||
slashableVoteData2Attestation := slashableVoteData2.Data
|
||||
func verifyAttesterSlashing(slashing *pb.AttesterSlashing) error {
|
||||
slashableVote1 := slashing.SlashableVote_1
|
||||
slashableVote2 := slashing.SlashableVote_2
|
||||
slashableVoteData1Attestation := slashableVote1.Data
|
||||
slashableVoteData2Attestation := slashableVote2.Data
|
||||
|
||||
if err := verifySlashableVoteData(slashableVoteData1); err != nil {
|
||||
return fmt.Errorf("could not verify casper slashable vote data 1: %v", err)
|
||||
if err := verifySlashableVote(slashableVote1); err != nil {
|
||||
return fmt.Errorf("could not verify attester slashable vote data 1: %v", err)
|
||||
}
|
||||
if err := verifySlashableVoteData(slashableVoteData2); err != nil {
|
||||
return fmt.Errorf("could not verify casper slashable vote data 2: %v", err)
|
||||
if err := verifySlashableVote(slashableVote2); err != nil {
|
||||
return fmt.Errorf("could not verify attester slashable vote data 2: %v", err)
|
||||
}
|
||||
|
||||
// Inner attestation data structures for the votes should not be equal,
|
||||
@@ -264,7 +266,7 @@ func verifyCasperSlashing(slashing *pb.CasperSlashing) error {
|
||||
// should occur.
|
||||
if reflect.DeepEqual(slashableVoteData1Attestation, slashableVoteData2Attestation) {
|
||||
return fmt.Errorf(
|
||||
"casper slashing inner slashable vote data attestation should not match: %v, %v",
|
||||
"attester slashing inner slashable vote data attestation should not match: %v, %v",
|
||||
slashableVoteData1Attestation,
|
||||
slashableVoteData2Attestation,
|
||||
)
|
||||
@@ -308,18 +310,10 @@ func verifyCasperSlashing(slashing *pb.CasperSlashing) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func casperSlashingPenalizedIndices(slashing *pb.CasperSlashing) ([]uint32, error) {
|
||||
slashableVoteData1 := slashing.SlashableVoteData_1
|
||||
slashableVoteData2 := slashing.SlashableVoteData_2
|
||||
slashableVoteData1Indices := append(
|
||||
slashableVoteData1.CustodyBit_0Indices,
|
||||
slashableVoteData1.CustodyBit_1Indices...,
|
||||
)
|
||||
slashableVoteData2Indices := append(
|
||||
slashableVoteData2.CustodyBit_0Indices,
|
||||
slashableVoteData2.CustodyBit_1Indices...,
|
||||
)
|
||||
indicesIntersection := slices.Intersection(slashableVoteData1Indices, slashableVoteData2Indices)
|
||||
func attesterSlashingPenalizedIndices(slashing *pb.AttesterSlashing) ([]uint64, error) {
|
||||
indicesIntersection := slices.Intersection(
|
||||
slashing.SlashableVote_1.ValidatorIndices,
|
||||
slashing.SlashableVote_2.ValidatorIndices)
|
||||
if len(indicesIntersection) < 1 {
|
||||
return nil, fmt.Errorf(
|
||||
"expected intersection of vote indices to be non-empty: %v",
|
||||
@@ -329,16 +323,29 @@ func casperSlashingPenalizedIndices(slashing *pb.CasperSlashing) ([]uint32, erro
|
||||
return indicesIntersection, nil
|
||||
}
|
||||
|
||||
func verifySlashableVoteData(votes *pb.SlashableVoteData) error {
|
||||
totalCustody := len(votes.CustodyBit_0Indices) +
|
||||
len(votes.CustodyBit_1Indices)
|
||||
if uint64(totalCustody) > params.BeaconConfig().MaxCasperVotes {
|
||||
return fmt.Errorf(
|
||||
"exceeded allowed casper votes (%d), received %d",
|
||||
params.BeaconConfig().MaxCasperVotes,
|
||||
totalCustody,
|
||||
)
|
||||
func verifySlashableVote(votes *pb.SlashableVote) error {
|
||||
emptyCustody := make([]byte, len(votes.CustodyBitfield))
|
||||
if bytes.Equal(votes.CustodyBitfield, emptyCustody) {
|
||||
return errors.New("custody bit field can't all be 0s")
|
||||
}
|
||||
if len(votes.ValidatorIndices) == 0 {
|
||||
return errors.New("empty validator indices")
|
||||
}
|
||||
for i := 0; i < len(votes.ValidatorIndices)-1; i++ {
|
||||
if votes.ValidatorIndices[i] >= votes.ValidatorIndices[i+1] {
|
||||
return fmt.Errorf("validator indices not in descending order: %v",
|
||||
votes.ValidatorIndices)
|
||||
}
|
||||
}
|
||||
if len(votes.CustodyBitfield) != mathutil.CeilDiv8(len(votes.ValidatorIndices)) {
|
||||
return fmt.Errorf("custody bit field length (%d) don't match indices length (%d)",
|
||||
len(votes.CustodyBitfield), mathutil.CeilDiv8(len(votes.ValidatorIndices)))
|
||||
}
|
||||
if uint64(len(votes.ValidatorIndices)) > config.MaxIndicesPerSlashableVote {
|
||||
return fmt.Errorf("validator indices length (%d) exceeded max indices per slashable vote(%d)",
|
||||
len(votes.ValidatorIndices), config.MaxIndicesPerSlashableVote)
|
||||
}
|
||||
|
||||
// TODO(#258): Implement BLS verify multiple.
|
||||
// pubs = aggregate_pubkeys for each validator in registry for poc0 and poc1
|
||||
// indices
|
||||
@@ -579,7 +586,6 @@ func ProcessValidatorDeposits(
|
||||
depositInput.ProofOfPossession,
|
||||
depositInput.WithdrawalCredentialsHash32,
|
||||
depositInput.RandaoCommitmentHash32,
|
||||
depositInput.CustodyCommitmentHash32,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not process deposit into beacon state: %v", err)
|
||||
|
||||
@@ -332,8 +332,8 @@ func TestProcessProposerSlashings_AppliesCorrectStatus(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessCasperSlashings_ThresholdReached(t *testing.T) {
|
||||
slashings := make([]*pb.CasperSlashing, config.MaxCasperSlashings+1)
|
||||
func TestProcessAttesterSlashings_ThresholdReached(t *testing.T) {
|
||||
slashings := make([]*pb.AttesterSlashing, config.MaxAttesterSlashings+1)
|
||||
registry := []*pb.ValidatorRecord{}
|
||||
currentSlot := uint64(0)
|
||||
|
||||
@@ -343,16 +343,16 @@ func TestProcessCasperSlashings_ThresholdReached(t *testing.T) {
|
||||
}
|
||||
block := &pb.BeaconBlock{
|
||||
Body: &pb.BeaconBlockBody{
|
||||
CasperSlashings: slashings,
|
||||
AttesterSlashings: slashings,
|
||||
},
|
||||
}
|
||||
want := fmt.Sprintf(
|
||||
"number of casper slashings (%d) exceeds allowed threshold of %d",
|
||||
config.MaxCasperSlashings+1,
|
||||
config.MaxCasperSlashings,
|
||||
"number of attester slashings (%d) exceeds allowed threshold of %d",
|
||||
config.MaxAttesterSlashings+1,
|
||||
config.MaxAttesterSlashings,
|
||||
)
|
||||
|
||||
if _, err := ProcessCasperSlashings(
|
||||
if _, err := ProcessAttesterSlashings(
|
||||
beaconState,
|
||||
block,
|
||||
); !strings.Contains(err.Error(), want) {
|
||||
@@ -360,27 +360,19 @@ func TestProcessCasperSlashings_ThresholdReached(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessCasperSlashings_VoteThresholdReached(t *testing.T) {
|
||||
slashings := []*pb.CasperSlashing{
|
||||
func TestProcessAttesterSlashings_EmptyCustodyFields(t *testing.T) {
|
||||
slashings := []*pb.AttesterSlashing{
|
||||
{
|
||||
SlashableVoteData_1: &pb.SlashableVoteData{
|
||||
CustodyBit_0Indices: make(
|
||||
[]uint32,
|
||||
config.MaxCasperVotes,
|
||||
),
|
||||
CustodyBit_1Indices: make(
|
||||
[]uint32,
|
||||
config.MaxCasperVotes,
|
||||
SlashableVote_1: &pb.SlashableVote{
|
||||
ValidatorIndices: make(
|
||||
[]uint64,
|
||||
config.MaxIndicesPerSlashableVote,
|
||||
),
|
||||
},
|
||||
SlashableVoteData_2: &pb.SlashableVoteData{
|
||||
CustodyBit_0Indices: make(
|
||||
[]uint32,
|
||||
config.MaxCasperVotes,
|
||||
),
|
||||
CustodyBit_1Indices: make(
|
||||
[]uint32,
|
||||
config.MaxCasperVotes,
|
||||
SlashableVote_2: &pb.SlashableVote{
|
||||
ValidatorIndices: make(
|
||||
[]uint64,
|
||||
config.MaxIndicesPerSlashableVote,
|
||||
),
|
||||
},
|
||||
},
|
||||
@@ -394,16 +386,12 @@ func TestProcessCasperSlashings_VoteThresholdReached(t *testing.T) {
|
||||
}
|
||||
block := &pb.BeaconBlock{
|
||||
Body: &pb.BeaconBlockBody{
|
||||
CasperSlashings: slashings,
|
||||
AttesterSlashings: slashings,
|
||||
},
|
||||
}
|
||||
want := fmt.Sprintf(
|
||||
"exceeded allowed casper votes (%d), received %d",
|
||||
config.MaxCasperVotes,
|
||||
config.MaxCasperVotes*2,
|
||||
)
|
||||
want := fmt.Sprint("custody bit field can't all be 0")
|
||||
|
||||
if _, err := ProcessCasperSlashings(
|
||||
if _, err := ProcessAttesterSlashings(
|
||||
beaconState,
|
||||
block,
|
||||
); !strings.Contains(err.Error(), want) {
|
||||
@@ -411,26 +399,18 @@ func TestProcessCasperSlashings_VoteThresholdReached(t *testing.T) {
|
||||
}
|
||||
|
||||
// Perform the same check for SlashableVoteData_2.
|
||||
slashings = []*pb.CasperSlashing{
|
||||
slashings = []*pb.AttesterSlashing{
|
||||
{
|
||||
SlashableVoteData_1: &pb.SlashableVoteData{
|
||||
CustodyBit_0Indices: make(
|
||||
[]uint32,
|
||||
config.MaxCasperVotes,
|
||||
),
|
||||
CustodyBit_1Indices: make(
|
||||
[]uint32,
|
||||
config.MaxCasperVotes,
|
||||
SlashableVote_1: &pb.SlashableVote{
|
||||
ValidatorIndices: make(
|
||||
[]uint64,
|
||||
config.MaxIndicesPerSlashableVote,
|
||||
),
|
||||
},
|
||||
SlashableVoteData_2: &pb.SlashableVoteData{
|
||||
CustodyBit_0Indices: make(
|
||||
[]uint32,
|
||||
config.MaxCasperVotes,
|
||||
),
|
||||
CustodyBit_1Indices: make(
|
||||
[]uint32,
|
||||
config.MaxCasperVotes,
|
||||
SlashableVote_2: &pb.SlashableVote{
|
||||
ValidatorIndices: make(
|
||||
[]uint64,
|
||||
config.MaxIndicesPerSlashableVote,
|
||||
),
|
||||
},
|
||||
},
|
||||
@@ -441,10 +421,10 @@ func TestProcessCasperSlashings_VoteThresholdReached(t *testing.T) {
|
||||
}
|
||||
block = &pb.BeaconBlock{
|
||||
Body: &pb.BeaconBlockBody{
|
||||
CasperSlashings: slashings,
|
||||
AttesterSlashings: slashings,
|
||||
},
|
||||
}
|
||||
if _, err := ProcessCasperSlashings(
|
||||
if _, err := ProcessAttesterSlashings(
|
||||
beaconState,
|
||||
block,
|
||||
); !strings.Contains(err.Error(), want) {
|
||||
@@ -452,17 +432,21 @@ func TestProcessCasperSlashings_VoteThresholdReached(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessCasperSlashings_UnmatchedAttestations(t *testing.T) {
|
||||
func TestProcessAttesterSlashings_UnmatchedAttestations(t *testing.T) {
|
||||
att1 := &pb.AttestationData{
|
||||
Slot: 5,
|
||||
}
|
||||
slashings := []*pb.CasperSlashing{
|
||||
slashings := []*pb.AttesterSlashing{
|
||||
{
|
||||
SlashableVoteData_1: &pb.SlashableVoteData{
|
||||
Data: att1,
|
||||
SlashableVote_1: &pb.SlashableVote{
|
||||
Data: att1,
|
||||
ValidatorIndices: []uint64{1},
|
||||
CustodyBitfield: []byte{0xFF},
|
||||
},
|
||||
SlashableVoteData_2: &pb.SlashableVoteData{
|
||||
Data: att1,
|
||||
SlashableVote_2: &pb.SlashableVote{
|
||||
Data: att1,
|
||||
ValidatorIndices: []uint64{2},
|
||||
CustodyBitfield: []byte{0xFF},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -475,16 +459,16 @@ func TestProcessCasperSlashings_UnmatchedAttestations(t *testing.T) {
|
||||
}
|
||||
block := &pb.BeaconBlock{
|
||||
Body: &pb.BeaconBlockBody{
|
||||
CasperSlashings: slashings,
|
||||
AttesterSlashings: slashings,
|
||||
},
|
||||
}
|
||||
want := fmt.Sprintf(
|
||||
"casper slashing inner slashable vote data attestation should not match: %v, %v",
|
||||
"attester slashing inner slashable vote data attestation should not match: %v, %v",
|
||||
att1,
|
||||
att1,
|
||||
)
|
||||
|
||||
if _, err := ProcessCasperSlashings(
|
||||
if _, err := ProcessAttesterSlashings(
|
||||
beaconState,
|
||||
block,
|
||||
); !strings.Contains(err.Error(), want) {
|
||||
@@ -492,7 +476,7 @@ func TestProcessCasperSlashings_UnmatchedAttestations(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessCasperSlashings_SlotsInequalities(t *testing.T) {
|
||||
func TestProcessAttesterSlashings_SlotsInequalities(t *testing.T) {
|
||||
testCases := []struct {
|
||||
att1 *pb.AttestationData
|
||||
att2 *pb.AttestationData
|
||||
@@ -541,13 +525,17 @@ func TestProcessCasperSlashings_SlotsInequalities(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
slashings := []*pb.CasperSlashing{
|
||||
slashings := []*pb.AttesterSlashing{
|
||||
{
|
||||
SlashableVoteData_1: &pb.SlashableVoteData{
|
||||
Data: tt.att1,
|
||||
SlashableVote_1: &pb.SlashableVote{
|
||||
Data: tt.att1,
|
||||
ValidatorIndices: []uint64{1},
|
||||
CustodyBitfield: []byte{0xFF},
|
||||
},
|
||||
SlashableVoteData_2: &pb.SlashableVoteData{
|
||||
Data: tt.att2,
|
||||
SlashableVote_2: &pb.SlashableVote{
|
||||
Data: tt.att2,
|
||||
ValidatorIndices: []uint64{2},
|
||||
CustodyBitfield: []byte{0xFF},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -560,7 +548,7 @@ func TestProcessCasperSlashings_SlotsInequalities(t *testing.T) {
|
||||
}
|
||||
block := &pb.BeaconBlock{
|
||||
Body: &pb.BeaconBlockBody{
|
||||
CasperSlashings: slashings,
|
||||
AttesterSlashings: slashings,
|
||||
},
|
||||
}
|
||||
want := fmt.Sprintf(
|
||||
@@ -584,7 +572,7 @@ func TestProcessCasperSlashings_SlotsInequalities(t *testing.T) {
|
||||
tt.att2.Slot,
|
||||
)
|
||||
|
||||
if _, err := ProcessCasperSlashings(
|
||||
if _, err := ProcessAttesterSlashings(
|
||||
beaconState,
|
||||
block,
|
||||
); !strings.Contains(err.Error(), want) {
|
||||
@@ -593,7 +581,7 @@ func TestProcessCasperSlashings_SlotsInequalities(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessCasperSlashings_EmptyVoteIndexIntersection(t *testing.T) {
|
||||
func TestProcessAttesterSlashings_EmptyVoteIndexIntersection(t *testing.T) {
|
||||
att1 := &pb.AttestationData{
|
||||
Slot: 5,
|
||||
JustifiedSlot: 5,
|
||||
@@ -602,17 +590,17 @@ func TestProcessCasperSlashings_EmptyVoteIndexIntersection(t *testing.T) {
|
||||
Slot: 5,
|
||||
JustifiedSlot: 4,
|
||||
}
|
||||
slashings := []*pb.CasperSlashing{
|
||||
slashings := []*pb.AttesterSlashing{
|
||||
{
|
||||
SlashableVoteData_1: &pb.SlashableVoteData{
|
||||
Data: att1,
|
||||
CustodyBit_0Indices: []uint32{1, 2},
|
||||
CustodyBit_1Indices: []uint32{3, 4},
|
||||
SlashableVote_1: &pb.SlashableVote{
|
||||
Data: att1,
|
||||
ValidatorIndices: []uint64{1},
|
||||
CustodyBitfield: []byte{0xFF},
|
||||
},
|
||||
SlashableVoteData_2: &pb.SlashableVoteData{
|
||||
Data: att2,
|
||||
CustodyBit_0Indices: []uint32{5, 6},
|
||||
CustodyBit_1Indices: []uint32{7, 8},
|
||||
SlashableVote_2: &pb.SlashableVote{
|
||||
Data: att2,
|
||||
ValidatorIndices: []uint64{2},
|
||||
CustodyBitfield: []byte{0xFF},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -625,11 +613,11 @@ func TestProcessCasperSlashings_EmptyVoteIndexIntersection(t *testing.T) {
|
||||
}
|
||||
block := &pb.BeaconBlock{
|
||||
Body: &pb.BeaconBlockBody{
|
||||
CasperSlashings: slashings,
|
||||
AttesterSlashings: slashings,
|
||||
},
|
||||
}
|
||||
want := "expected intersection of vote indices to be non-empty"
|
||||
if _, err := ProcessCasperSlashings(
|
||||
if _, err := ProcessAttesterSlashings(
|
||||
beaconState,
|
||||
block,
|
||||
); !strings.Contains(err.Error(), want) {
|
||||
@@ -637,7 +625,7 @@ func TestProcessCasperSlashings_EmptyVoteIndexIntersection(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessCasperSlashings_AppliesCorrectStatus(t *testing.T) {
|
||||
func TestProcessAttesterSlashings_AppliesCorrectStatus(t *testing.T) {
|
||||
// We test the case when data is correct and verify the validator
|
||||
// registry has been updated.
|
||||
validators := make([]*pb.ValidatorRecord, config.EpochLength*2)
|
||||
@@ -656,17 +644,17 @@ func TestProcessCasperSlashings_AppliesCorrectStatus(t *testing.T) {
|
||||
Slot: 5,
|
||||
JustifiedSlot: 4,
|
||||
}
|
||||
slashings := []*pb.CasperSlashing{
|
||||
slashings := []*pb.AttesterSlashing{
|
||||
{
|
||||
SlashableVoteData_1: &pb.SlashableVoteData{
|
||||
Data: att1,
|
||||
CustodyBit_0Indices: []uint32{0, 1},
|
||||
CustodyBit_1Indices: []uint32{2, 3},
|
||||
SlashableVote_1: &pb.SlashableVote{
|
||||
Data: att1,
|
||||
ValidatorIndices: []uint64{1},
|
||||
CustodyBitfield: []byte{0xFF},
|
||||
},
|
||||
SlashableVoteData_2: &pb.SlashableVoteData{
|
||||
Data: att2,
|
||||
CustodyBit_0Indices: []uint32{4, 5},
|
||||
CustodyBit_1Indices: []uint32{6, 1},
|
||||
SlashableVote_2: &pb.SlashableVote{
|
||||
Data: att2,
|
||||
ValidatorIndices: []uint64{1},
|
||||
CustodyBitfield: []byte{0xFF},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -680,10 +668,10 @@ func TestProcessCasperSlashings_AppliesCorrectStatus(t *testing.T) {
|
||||
}
|
||||
block := &pb.BeaconBlock{
|
||||
Body: &pb.BeaconBlockBody{
|
||||
CasperSlashings: slashings,
|
||||
AttesterSlashings: slashings,
|
||||
},
|
||||
}
|
||||
newState, err := ProcessCasperSlashings(
|
||||
newState, err := ProcessAttesterSlashings(
|
||||
beaconState,
|
||||
block,
|
||||
)
|
||||
|
||||
@@ -208,7 +208,7 @@ func PrevHeadAttestations(
|
||||
// sum([get_effective_balance(state, i) for i in active_validator_indices])
|
||||
func TotalBalance(
|
||||
state *pb.BeaconState,
|
||||
activeValidatorIndices []uint32) uint64 {
|
||||
activeValidatorIndices []uint64) uint64 {
|
||||
|
||||
var totalBalance uint64
|
||||
for _, index := range activeValidatorIndices {
|
||||
@@ -225,7 +225,7 @@ func TotalBalance(
|
||||
// Let inclusion_slot(state, index) =
|
||||
// a.slot_included for the attestation a where index is in
|
||||
// get_attestation_participants(state, a.data, a.participation_bitfield)
|
||||
func InclusionSlot(state *pb.BeaconState, validatorIndex uint32) (uint64, error) {
|
||||
func InclusionSlot(state *pb.BeaconState, validatorIndex uint64) (uint64, error) {
|
||||
|
||||
for _, attestation := range state.LatestAttestations {
|
||||
participatedValidators, err := validators.AttestationParticipants(state, attestation.Data, attestation.ParticipationBitfield)
|
||||
@@ -249,7 +249,7 @@ func InclusionSlot(state *pb.BeaconState, validatorIndex uint32) (uint64, error)
|
||||
// Let inclusion_distance(state, index) =
|
||||
// a.slot_included - a.data.slot where a is the above attestation same as
|
||||
// inclusion_slot
|
||||
func InclusionDistance(state *pb.BeaconState, validatorIndex uint32) (uint64, error) {
|
||||
func InclusionDistance(state *pb.BeaconState, validatorIndex uint64) (uint64, error) {
|
||||
|
||||
for _, attestation := range state.LatestAttestations {
|
||||
participatedValidators, err := validators.AttestationParticipants(state, attestation.Data, attestation.ParticipationBitfield)
|
||||
@@ -274,7 +274,7 @@ func InclusionDistance(state *pb.BeaconState, validatorIndex uint32) (uint64, er
|
||||
func AttestingValidators(
|
||||
state *pb.BeaconState,
|
||||
shard uint64, thisEpochAttestations []*pb.PendingAttestationRecord,
|
||||
prevEpochAttestations []*pb.PendingAttestationRecord) ([]uint32, error) {
|
||||
prevEpochAttestations []*pb.PendingAttestationRecord) ([]uint64, error) {
|
||||
|
||||
root, err := winningRoot(
|
||||
state,
|
||||
|
||||
@@ -388,7 +388,7 @@ func TestAttestingValidatorsOk(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify the winner root is attested by validator 45 based on shuffling.
|
||||
if !reflect.DeepEqual(attestedValidators, []uint32{45}) {
|
||||
if !reflect.DeepEqual(attestedValidators, []uint64{45}) {
|
||||
t.Errorf("Active validators don't match. Wanted:[109, 97], Got: %v", attestedValidators)
|
||||
}
|
||||
}
|
||||
@@ -465,7 +465,7 @@ func TestTotalBalance(t *testing.T) {
|
||||
}
|
||||
|
||||
// 20 + 25 + 30 + 30 + 32 + 32 + 32 + 32 = 233
|
||||
totalBalance := TotalBalance(state, []uint32{0, 1, 2, 3, 4, 5, 6, 7})
|
||||
totalBalance := TotalBalance(state, []uint64{0, 1, 2, 3, 4, 5, 6, 7})
|
||||
if totalBalance != 233*1e9 {
|
||||
t.Errorf("Incorrect total balance. Wanted: 233*1e9, got: %d", totalBalance)
|
||||
}
|
||||
@@ -506,7 +506,7 @@ func TestInclusionSlotBadBitfield(t *testing.T) {
|
||||
func TestInclusionSlotNotFound(t *testing.T) {
|
||||
state := buildState(0, config.EpochLength)
|
||||
|
||||
badIndex := uint32(10000)
|
||||
badIndex := uint64(10000)
|
||||
want := fmt.Sprintf("could not find inclusion slot for validator index %d", badIndex)
|
||||
if _, err := InclusionSlot(state, badIndex); !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
@@ -552,7 +552,7 @@ func TestInclusionDistanceBadBitfield(t *testing.T) {
|
||||
func TestInclusionDistanceNotFound(t *testing.T) {
|
||||
state := buildState(0, config.EpochLength)
|
||||
|
||||
badIndex := uint32(10000)
|
||||
badIndex := uint64(10000)
|
||||
want := fmt.Sprintf("could not find inclusion distance for validator index %d", badIndex)
|
||||
if _, err := InclusionDistance(state, badIndex); !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
|
||||
@@ -70,7 +70,6 @@ func InitialBeaconState(
|
||||
Pubkey: depositInput.Pubkey,
|
||||
RandaoCommitmentHash32: depositInput.RandaoCommitmentHash32,
|
||||
WithdrawalCredentialsHash32: depositInput.WithdrawalCredentialsHash32,
|
||||
CustodyCommitmentHash32: depositInput.CustodyCommitmentHash32,
|
||||
Balance: amount,
|
||||
ExitSlot: config.FarFutureSlot,
|
||||
PenalizedSlot: config.FarFutureSlot,
|
||||
@@ -101,7 +100,6 @@ func InitialBeaconState(
|
||||
|
||||
// Randomness and committees.
|
||||
LatestRandaoMixesHash32S: latestRandaoMixes,
|
||||
LatestVdfOutputsHash32S: latestVDFOutputs,
|
||||
PreviousEpochStartShard: config.GenesisStartShard,
|
||||
CurrentEpochStartShard: config.GenesisStartShard,
|
||||
PreviousEpochCalculationSlot: config.GenesisSlot,
|
||||
@@ -109,11 +107,6 @@ func InitialBeaconState(
|
||||
PreviousEpochRandaoMixHash32: config.ZeroHash[:],
|
||||
CurrentEpochRandaoMixHash32: config.ZeroHash[:],
|
||||
|
||||
// Proof of custody.
|
||||
// Place holder, proof of custody challenge is defined in phase 1.
|
||||
// This list will remain empty through out phase 0.
|
||||
CustodyChallenges: []*pb.CustodyChallenge{},
|
||||
|
||||
// Finality.
|
||||
PreviousJustifiedSlot: config.GenesisSlot,
|
||||
JustifiedSlot: config.GenesisSlot,
|
||||
@@ -152,16 +145,15 @@ func InitialBeaconState(
|
||||
depositInput.ProofOfPossession,
|
||||
depositInput.WithdrawalCredentialsHash32,
|
||||
depositInput.RandaoCommitmentHash32,
|
||||
depositInput.CustodyCommitmentHash32,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not process validator deposit: %v", err)
|
||||
}
|
||||
}
|
||||
for i := 0; i < len(state.ValidatorRegistry); i++ {
|
||||
if v.EffectiveBalance(state, uint32(i)) ==
|
||||
if v.EffectiveBalance(state, uint64(i)) ==
|
||||
config.MaxDeposit {
|
||||
state, err = v.ActivateValidator(state, uint32(i), true)
|
||||
state, err = v.ActivateValidator(state, uint64(i), true)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not activate validator: %v", err)
|
||||
}
|
||||
|
||||
@@ -37,8 +37,6 @@ func TestInitialBeaconState_Ok(t *testing.T) {
|
||||
t.Error("LatestRandaoMixesLength should be 8192 for these tests to pass")
|
||||
}
|
||||
latestRandaoMixesLength := int(params.BeaconConfig().LatestRandaoMixesLength)
|
||||
LatestVdfMixesLength := int(params.BeaconConfig().LatestRandaoMixesLength /
|
||||
params.BeaconConfig().EpochLength)
|
||||
|
||||
if params.BeaconConfig().ShardCount != 1024 {
|
||||
t.Error("ShardCount should be 1024 for these tests to pass")
|
||||
@@ -124,14 +122,6 @@ func TestInitialBeaconState_Ok(t *testing.T) {
|
||||
if len(state.LatestRandaoMixesHash32S) != latestRandaoMixesLength {
|
||||
t.Error("Length of LatestRandaoMixesHash32S was not correctly initialized")
|
||||
}
|
||||
if len(state.LatestVdfOutputsHash32S) != LatestVdfMixesLength {
|
||||
t.Error("Length of LatestRandaoMixesHash32S was not correctly initialized")
|
||||
}
|
||||
|
||||
// Proof of custody field check.
|
||||
if !reflect.DeepEqual(state.CustodyChallenges, []*pb.CustodyChallenge{}) {
|
||||
t.Error("CustodyChallenges was not correctly initialized")
|
||||
}
|
||||
|
||||
// Finality fields checks.
|
||||
if state.PreviousJustifiedSlot != initialSlotNumber {
|
||||
|
||||
@@ -77,9 +77,9 @@ func ProcessBlock(state *pb.BeaconState, block *pb.BeaconBlock) (*pb.BeaconState
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not verify block proposer slashings: %v", err)
|
||||
}
|
||||
state, err = b.ProcessCasperSlashings(state, block)
|
||||
state, err = b.ProcessAttesterSlashings(state, block)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not verify block casper slashings: %v", err)
|
||||
return nil, fmt.Errorf("could not verify block attester slashings: %v", err)
|
||||
}
|
||||
state, err = b.ProcessBlockAttestations(state, block)
|
||||
if err != nil {
|
||||
@@ -104,7 +104,7 @@ func ProcessBlock(state *pb.BeaconState, block *pb.BeaconBlock) (*pb.BeaconState
|
||||
// update_justification(state)
|
||||
// update_finalization(state)
|
||||
// update_crosslinks(state)
|
||||
// process_casper_reward_penalties(state)
|
||||
// process_attester_reward_penalties(state)
|
||||
// process_crosslink_reward_penalties(state)
|
||||
// update_validator_registry(state)
|
||||
// final_book_keeping(state)
|
||||
@@ -194,7 +194,7 @@ func ProcessEpoch(state *pb.BeaconState) (*pb.BeaconState, error) {
|
||||
return nil, fmt.Errorf("could not process crosslink records: %v", err)
|
||||
}
|
||||
|
||||
// Process casper rewards and penalties.
|
||||
// Process attester rewards and penalties.
|
||||
epochsSinceFinality := e.SinceFinality(state)
|
||||
switch {
|
||||
case epochsSinceFinality <= 4:
|
||||
|
||||
@@ -67,7 +67,7 @@ func TestProcessBlock_IncorrectProposerSlashing(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessBlock_IncorrectCasperSlashing(t *testing.T) {
|
||||
func TestProcessBlock_IncorrectAttesterSlashing(t *testing.T) {
|
||||
registry := validators.InitialValidatorRegistry()
|
||||
|
||||
slashings := []*pb.ProposerSlashing{
|
||||
@@ -85,7 +85,7 @@ func TestProcessBlock_IncorrectCasperSlashing(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
casperSlashings := make([]*pb.CasperSlashing, config.MaxCasperSlashings+1)
|
||||
attesterSlashings := make([]*pb.AttesterSlashing, config.MaxAttesterSlashings+1)
|
||||
latestMixes := make([][]byte, config.LatestRandaoMixesLength)
|
||||
beaconState := &pb.BeaconState{
|
||||
LatestRandaoMixesHash32S: latestMixes,
|
||||
@@ -97,10 +97,10 @@ func TestProcessBlock_IncorrectCasperSlashing(t *testing.T) {
|
||||
RandaoRevealHash32: []byte{},
|
||||
Body: &pb.BeaconBlockBody{
|
||||
ProposerSlashings: slashings,
|
||||
CasperSlashings: casperSlashings,
|
||||
AttesterSlashings: attesterSlashings,
|
||||
},
|
||||
}
|
||||
want := "could not verify block casper slashing"
|
||||
want := "could not verify block attester slashing"
|
||||
if _, err := ProcessBlock(beaconState, block); !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
@@ -131,17 +131,17 @@ func TestProcessBlock_IncorrectProcessBlockAttestations(t *testing.T) {
|
||||
Slot: 5,
|
||||
JustifiedSlot: 4,
|
||||
}
|
||||
casperSlashings := []*pb.CasperSlashing{
|
||||
attesterSlashings := []*pb.AttesterSlashing{
|
||||
{
|
||||
SlashableVoteData_1: &pb.SlashableVoteData{
|
||||
Data: att1,
|
||||
CustodyBit_0Indices: []uint32{0, 1},
|
||||
CustodyBit_1Indices: []uint32{2, 3},
|
||||
SlashableVote_1: &pb.SlashableVote{
|
||||
Data: att1,
|
||||
ValidatorIndices: []uint64{1},
|
||||
CustodyBitfield: []byte{0xFF},
|
||||
},
|
||||
SlashableVoteData_2: &pb.SlashableVoteData{
|
||||
Data: att2,
|
||||
CustodyBit_0Indices: []uint32{4, 5},
|
||||
CustodyBit_1Indices: []uint32{6, 1},
|
||||
SlashableVote_2: &pb.SlashableVote{
|
||||
Data: att2,
|
||||
ValidatorIndices: []uint64{1},
|
||||
CustodyBitfield: []byte{0xFF},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -158,7 +158,7 @@ func TestProcessBlock_IncorrectProcessBlockAttestations(t *testing.T) {
|
||||
RandaoRevealHash32: []byte{},
|
||||
Body: &pb.BeaconBlockBody{
|
||||
ProposerSlashings: proposerSlashings,
|
||||
CasperSlashings: casperSlashings,
|
||||
AttesterSlashings: attesterSlashings,
|
||||
Attestations: blockAttestations,
|
||||
},
|
||||
}
|
||||
@@ -193,17 +193,17 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
|
||||
Slot: 5,
|
||||
JustifiedSlot: 4,
|
||||
}
|
||||
casperSlashings := []*pb.CasperSlashing{
|
||||
attesterSlashings := []*pb.AttesterSlashing{
|
||||
{
|
||||
SlashableVoteData_1: &pb.SlashableVoteData{
|
||||
Data: att1,
|
||||
CustodyBit_0Indices: []uint32{0, 1},
|
||||
CustodyBit_1Indices: []uint32{2, 3},
|
||||
SlashableVote_1: &pb.SlashableVote{
|
||||
Data: att1,
|
||||
ValidatorIndices: []uint64{1},
|
||||
CustodyBitfield: []byte{0xFF},
|
||||
},
|
||||
SlashableVoteData_2: &pb.SlashableVoteData{
|
||||
Data: att2,
|
||||
CustodyBit_0Indices: []uint32{4, 5},
|
||||
CustodyBit_1Indices: []uint32{6, 1},
|
||||
SlashableVote_2: &pb.SlashableVote{
|
||||
Data: att2,
|
||||
ValidatorIndices: []uint64{1},
|
||||
CustodyBitfield: []byte{0xFF},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -244,7 +244,7 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
|
||||
RandaoRevealHash32: []byte{},
|
||||
Body: &pb.BeaconBlockBody{
|
||||
ProposerSlashings: proposerSlashings,
|
||||
CasperSlashings: casperSlashings,
|
||||
AttesterSlashings: attesterSlashings,
|
||||
Attestations: attestations,
|
||||
Exits: exits,
|
||||
},
|
||||
@@ -280,17 +280,17 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) {
|
||||
Slot: 5,
|
||||
JustifiedSlot: 4,
|
||||
}
|
||||
casperSlashings := []*pb.CasperSlashing{
|
||||
attesterSlashings := []*pb.AttesterSlashing{
|
||||
{
|
||||
SlashableVoteData_1: &pb.SlashableVoteData{
|
||||
Data: att1,
|
||||
CustodyBit_0Indices: []uint32{0, 1},
|
||||
CustodyBit_1Indices: []uint32{2, 3},
|
||||
SlashableVote_1: &pb.SlashableVote{
|
||||
Data: att1,
|
||||
ValidatorIndices: []uint64{1},
|
||||
CustodyBitfield: []byte{0xFF},
|
||||
},
|
||||
SlashableVoteData_2: &pb.SlashableVoteData{
|
||||
Data: att2,
|
||||
CustodyBit_0Indices: []uint32{4, 5},
|
||||
CustodyBit_1Indices: []uint32{6, 1},
|
||||
SlashableVote_2: &pb.SlashableVote{
|
||||
Data: att2,
|
||||
ValidatorIndices: []uint64{1},
|
||||
CustodyBitfield: []byte{0xFF},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -336,7 +336,7 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) {
|
||||
RandaoRevealHash32: []byte{},
|
||||
Body: &pb.BeaconBlockBody{
|
||||
ProposerSlashings: proposerSlashings,
|
||||
CasperSlashings: casperSlashings,
|
||||
AttesterSlashings: attesterSlashings,
|
||||
Attestations: attestations,
|
||||
Exits: exits,
|
||||
},
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
|
||||
// CrosslinkCommittee defines the validator committee of slot and shard combinations.
|
||||
type CrosslinkCommittee struct {
|
||||
Committee []uint32
|
||||
Committee []uint64
|
||||
Shard uint64
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ func ShuffleValidatorRegistryToCommittees(
|
||||
// committee to a slot and a shard. If the validator set is large, multiple committees are assigned
|
||||
// to a single slot and shard. See getCommitteesPerSlot for more details.
|
||||
// To be deprecated by #1352.
|
||||
func splitBySlotShard(shuffledValidatorRegistry []uint32, crosslinkStartShard uint64) []*pb.ShardCommitteeArray {
|
||||
func splitBySlotShard(shuffledValidatorRegistry []uint64, crosslinkStartShard uint64) []*pb.ShardCommitteeArray {
|
||||
committeesPerSlot := getCommitteesPerSlot(uint64(len(shuffledValidatorRegistry)))
|
||||
committeBySlotAndShard := []*pb.ShardCommitteeArray{}
|
||||
|
||||
@@ -117,7 +117,7 @@ func getCommitteesPerSlot(numActiveValidatorRegistry uint64) uint64 {
|
||||
func AttestationParticipants(
|
||||
state *pb.BeaconState,
|
||||
attestationData *pb.AttestationData,
|
||||
participationBitfield []byte) ([]uint32, error) {
|
||||
participationBitfield []byte) ([]uint64, error) {
|
||||
|
||||
// Find the relevant committee.
|
||||
crosslinkCommittees, err := CrosslinkCommitteesAtSlot(state, attestationData.Slot)
|
||||
@@ -125,7 +125,7 @@ func AttestationParticipants(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var committee []uint32
|
||||
var committee []uint64
|
||||
for _, crosslinkCommittee := range crosslinkCommittees {
|
||||
if crosslinkCommittee.Shard == attestationData.Shard {
|
||||
committee = crosslinkCommittee.Committee
|
||||
@@ -140,7 +140,7 @@ func AttestationParticipants(
|
||||
}
|
||||
|
||||
// Find the participating validators in the committee.
|
||||
var participants []uint32
|
||||
var participants []uint64
|
||||
for i, validatorIndex := range committee {
|
||||
bitSet, err := bitutil.CheckBit(participationBitfield, i)
|
||||
if err != nil {
|
||||
@@ -209,7 +209,7 @@ func CrosslinkCommitteesAtSlot(state *pb.BeaconState, slot uint64) ([]*Crosslink
|
||||
var earliestSlot uint64
|
||||
var countPerSlot uint64
|
||||
var startShard uint64
|
||||
var shuffledIndices [][]uint32
|
||||
var shuffledIndices [][]uint64
|
||||
var err error
|
||||
|
||||
epochLength := config.EpochLength
|
||||
@@ -295,7 +295,7 @@ func CrosslinkCommitteesAtSlot(state *pb.BeaconState, slot uint64) ([]*Crosslink
|
||||
func Shuffling(
|
||||
seed [32]byte,
|
||||
validators []*pb.ValidatorRecord,
|
||||
slot uint64) ([][]uint32, error) {
|
||||
slot uint64) ([][]uint64, error) {
|
||||
|
||||
// Normalize slot to start of epoch boundary.
|
||||
slot -= slot % config.EpochLength
|
||||
|
||||
@@ -102,10 +102,10 @@ func TestGetCommitteesPerSlotSmallShardCount(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorRegistryBySlotShardRegularValidatorSet(t *testing.T) {
|
||||
validatorIndices := []uint32{}
|
||||
validatorIndices := []uint64{}
|
||||
numValidatorRegistry := int(config.EpochLength * config.TargetCommitteeSize)
|
||||
for i := 0; i < numValidatorRegistry; i++ {
|
||||
validatorIndices = append(validatorIndices, uint32(i))
|
||||
validatorIndices = append(validatorIndices, uint64(i))
|
||||
}
|
||||
|
||||
ShardCommitteeArray := splitBySlotShard(validatorIndices, 0)
|
||||
@@ -128,10 +128,10 @@ func TestValidatorRegistryBySlotShardRegularValidatorSet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorRegistryBySlotShardLargeValidatorSet(t *testing.T) {
|
||||
validatorIndices := []uint32{}
|
||||
validatorIndices := []uint64{}
|
||||
numValidatorRegistry := int(config.EpochLength*config.TargetCommitteeSize) * 2
|
||||
for i := 0; i < numValidatorRegistry; i++ {
|
||||
validatorIndices = append(validatorIndices, uint32(i))
|
||||
validatorIndices = append(validatorIndices, uint64(i))
|
||||
}
|
||||
|
||||
ShardCommitteeArray := splitBySlotShard(validatorIndices, 0)
|
||||
@@ -157,10 +157,10 @@ func TestValidatorRegistryBySlotShardLargeValidatorSet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorRegistryBySlotShardSmallValidatorSet(t *testing.T) {
|
||||
validatorIndices := []uint32{}
|
||||
validatorIndices := []uint64{}
|
||||
numValidatorRegistry := int(config.EpochLength * config.TargetCommitteeSize)
|
||||
for i := 0; i < numValidatorRegistry; i++ {
|
||||
validatorIndices = append(validatorIndices, uint32(i))
|
||||
validatorIndices = append(validatorIndices, uint64(i))
|
||||
}
|
||||
|
||||
ShardCommitteeArray := splitBySlotShard(validatorIndices, 0)
|
||||
@@ -208,42 +208,42 @@ func TestAttestationParticipants_ok(t *testing.T) {
|
||||
stateSlot uint64
|
||||
shard uint64
|
||||
bitfield []byte
|
||||
wanted []uint32
|
||||
wanted []uint64
|
||||
}{
|
||||
{
|
||||
attestationSlot: 2,
|
||||
stateSlot: 5,
|
||||
shard: 2,
|
||||
bitfield: []byte{0xFF},
|
||||
wanted: []uint32{11, 121},
|
||||
wanted: []uint64{11, 121},
|
||||
},
|
||||
{
|
||||
attestationSlot: 1,
|
||||
stateSlot: 10,
|
||||
shard: 1,
|
||||
bitfield: []byte{77},
|
||||
wanted: []uint32{117},
|
||||
wanted: []uint64{117},
|
||||
},
|
||||
{
|
||||
attestationSlot: 10,
|
||||
stateSlot: 20,
|
||||
shard: 10,
|
||||
bitfield: []byte{0xFF},
|
||||
wanted: []uint32{14, 30},
|
||||
wanted: []uint64{14, 30},
|
||||
},
|
||||
{
|
||||
attestationSlot: 64,
|
||||
stateSlot: 100,
|
||||
shard: 0,
|
||||
bitfield: []byte{0xFF},
|
||||
wanted: []uint32{109, 97},
|
||||
wanted: []uint64{109, 97},
|
||||
},
|
||||
{
|
||||
attestationSlot: 999,
|
||||
stateSlot: 1000,
|
||||
shard: 39,
|
||||
bitfield: []byte{99},
|
||||
wanted: []uint32{89},
|
||||
wanted: []uint64{89},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -47,11 +47,11 @@ func InitialValidatorRegistry() []*pb.ValidatorRecord {
|
||||
// Gets indices of active validators from ``validators``.
|
||||
// """
|
||||
// return [i for i, v in enumerate(validators) if is_active_validator(v, slot)]
|
||||
func ActiveValidatorIndices(validators []*pb.ValidatorRecord, slot uint64) []uint32 {
|
||||
indices := make([]uint32, 0, len(validators))
|
||||
func ActiveValidatorIndices(validators []*pb.ValidatorRecord, slot uint64) []uint64 {
|
||||
indices := make([]uint64, 0, len(validators))
|
||||
for i, v := range validators {
|
||||
if isActiveValidator(v, slot) {
|
||||
indices = append(indices, uint32(i))
|
||||
indices = append(indices, uint64(i))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -80,7 +80,7 @@ func ActiveValidators(state *pb.BeaconState, validatorIndices []uint32) []*pb.Va
|
||||
// """
|
||||
// first_committee, _ = get_crosslink_committees_at_slot(state, slot)[0]
|
||||
// return first_committee[slot % len(first_committee)]
|
||||
func BeaconProposerIdx(state *pb.BeaconState, slot uint64) (uint32, error) {
|
||||
func BeaconProposerIdx(state *pb.BeaconState, slot uint64) (uint64, error) {
|
||||
committeeArray, err := CrosslinkCommitteesAtSlot(state, slot)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -91,11 +91,11 @@ func BeaconProposerIdx(state *pb.BeaconState, slot uint64) (uint32, error) {
|
||||
}
|
||||
|
||||
// ValidatorIdx returns the idx of the validator given an input public key.
|
||||
func ValidatorIdx(pubKey []byte, validators []*pb.ValidatorRecord) (uint32, error) {
|
||||
func ValidatorIdx(pubKey []byte, validators []*pb.ValidatorRecord) (uint64, error) {
|
||||
|
||||
for idx := range validators {
|
||||
if bytes.Equal(validators[idx].Pubkey, pubKey) {
|
||||
return uint32(idx), nil
|
||||
return uint64(idx), nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ func ValidatorIdx(pubKey []byte, validators []*pb.ValidatorRecord) (uint32, erro
|
||||
//
|
||||
// Spec pseudocode definition:
|
||||
// sum([get_effective_balance(state, i) for i in active_validator_indices])
|
||||
func TotalEffectiveBalance(state *pb.BeaconState, validatorIndices []uint32) uint64 {
|
||||
func TotalEffectiveBalance(state *pb.BeaconState, validatorIndices []uint64) uint64 {
|
||||
var totalDeposit uint64
|
||||
|
||||
for _, idx := range validatorIndices {
|
||||
@@ -136,7 +136,7 @@ func TotalEffectiveBalance(state *pb.BeaconState, validatorIndices []uint32) uin
|
||||
// )
|
||||
func NewRegistryDeltaChainTip(
|
||||
flag pb.ValidatorRegistryDeltaBlock_ValidatorRegistryDeltaFlags,
|
||||
idx uint32,
|
||||
idx uint64,
|
||||
slot uint64,
|
||||
pubKey []byte,
|
||||
currentValidatorRegistryDeltaChainTip []byte) ([32]byte, error) {
|
||||
@@ -166,8 +166,8 @@ func NewRegistryDeltaChainTip(
|
||||
// """
|
||||
// Returns the effective balance (also known as "balance at stake") for a ``validator`` with the given ``index``.
|
||||
// """
|
||||
// return min(state.validator_balances[idx], MAX_DEPOSIT * GWEI_PER_ETH)
|
||||
func EffectiveBalance(state *pb.BeaconState, idx uint32) uint64 {
|
||||
// return min(state.validator_balances[idx], MAX_DEPOSIT)
|
||||
func EffectiveBalance(state *pb.BeaconState, idx uint64) uint64 {
|
||||
if state.ValidatorBalances[idx] > config.MaxDeposit {
|
||||
return config.MaxDeposit
|
||||
}
|
||||
@@ -179,7 +179,7 @@ func EffectiveBalance(state *pb.BeaconState, idx uint32) uint64 {
|
||||
// Spec pseudocode definition:
|
||||
// Let this_epoch_boundary_attesters = [state.validator_registry[i]
|
||||
// for indices in this_epoch_boundary_attester_indices for i in indices].
|
||||
func Attesters(state *pb.BeaconState, attesterIndices []uint32) []*pb.ValidatorRecord {
|
||||
func Attesters(state *pb.BeaconState, attesterIndices []uint64) []*pb.ValidatorRecord {
|
||||
|
||||
var boundaryAttesters []*pb.ValidatorRecord
|
||||
for _, attesterIdx := range attesterIndices {
|
||||
@@ -199,9 +199,9 @@ func Attesters(state *pb.BeaconState, attesterIndices []uint32) []*pb.ValidatorR
|
||||
func ValidatorIndices(
|
||||
state *pb.BeaconState,
|
||||
attestations []*pb.PendingAttestationRecord,
|
||||
) ([]uint32, error) {
|
||||
) ([]uint64, error) {
|
||||
|
||||
var attesterIndicesIntersection []uint32
|
||||
var attesterIndicesIntersection []uint64
|
||||
for _, attestation := range attestations {
|
||||
attesterIndices, err := AttestationParticipants(
|
||||
state,
|
||||
@@ -231,9 +231,9 @@ func AttestingValidatorIndices(
|
||||
shard uint64,
|
||||
shardBlockRoot []byte,
|
||||
thisEpochAttestations []*pb.PendingAttestationRecord,
|
||||
prevEpochAttestations []*pb.PendingAttestationRecord) ([]uint32, error) {
|
||||
prevEpochAttestations []*pb.PendingAttestationRecord) ([]uint64, error) {
|
||||
|
||||
var validatorIndicesCommittees []uint32
|
||||
var validatorIndicesCommittees []uint64
|
||||
attestations := append(thisEpochAttestations, prevEpochAttestations...)
|
||||
|
||||
for _, attestation := range attestations {
|
||||
@@ -256,7 +256,7 @@ func AttestingValidatorIndices(
|
||||
// Spec pseudocode definition:
|
||||
// Let this_epoch_boundary_attesting_balance =
|
||||
// sum([get_effective_balance(state, i) for i in this_epoch_boundary_attester_indices])
|
||||
func AttestingBalance(state *pb.BeaconState, boundaryAttesterIndices []uint32) uint64 {
|
||||
func AttestingBalance(state *pb.BeaconState, boundaryAttesterIndices []uint64) uint64 {
|
||||
|
||||
var boundaryAttestingBalance uint64
|
||||
for _, idx := range boundaryAttesterIndices {
|
||||
@@ -268,10 +268,10 @@ func AttestingBalance(state *pb.BeaconState, boundaryAttesterIndices []uint32) u
|
||||
|
||||
// AllValidatorsIndices returns all validator indices from 0 to
|
||||
// the last validator.
|
||||
func AllValidatorsIndices(state *pb.BeaconState) []uint32 {
|
||||
validatorIndices := make([]uint32, len(state.ValidatorRegistry))
|
||||
func AllValidatorsIndices(state *pb.BeaconState) []uint64 {
|
||||
validatorIndices := make([]uint64, len(state.ValidatorRegistry))
|
||||
for i := 0; i < len(validatorIndices); i++ {
|
||||
validatorIndices[i] = uint32(i)
|
||||
validatorIndices[i] = uint64(i)
|
||||
}
|
||||
return validatorIndices
|
||||
}
|
||||
@@ -290,7 +290,6 @@ func ProcessDeposit(
|
||||
_ /*proofOfPossession*/ []byte,
|
||||
withdrawalCredentials []byte,
|
||||
randaoCommitment []byte,
|
||||
custodyCommitment []byte,
|
||||
) (*pb.BeaconState, error) {
|
||||
// TODO(#258): Validate proof of possession using BLS.
|
||||
var publicKeyExists bool
|
||||
@@ -301,18 +300,15 @@ func ProcessDeposit(
|
||||
// If public key does not exist in the registry, we add a new validator
|
||||
// to the beacon state.
|
||||
newValidator := &pb.ValidatorRecord{
|
||||
Pubkey: pubkey,
|
||||
RandaoCommitmentHash32: randaoCommitment,
|
||||
RandaoLayers: 0,
|
||||
ExitCount: 0,
|
||||
CustodyCommitmentHash32: custodyCommitment,
|
||||
LatestCustodyReseedSlot: config.GenesisSlot,
|
||||
PenultimateCustodyReseedSlot: config.GenesisSlot,
|
||||
ActivationSlot: config.FarFutureSlot,
|
||||
ExitSlot: config.FarFutureSlot,
|
||||
WithdrawalSlot: config.FarFutureSlot,
|
||||
PenalizedSlot: config.FarFutureSlot,
|
||||
StatusFlags: 0,
|
||||
Pubkey: pubkey,
|
||||
RandaoCommitmentHash32: randaoCommitment,
|
||||
RandaoLayers: 0,
|
||||
ExitCount: 0,
|
||||
ActivationSlot: config.FarFutureSlot,
|
||||
ExitSlot: config.FarFutureSlot,
|
||||
WithdrawalSlot: config.FarFutureSlot,
|
||||
PenalizedSlot: config.FarFutureSlot,
|
||||
StatusFlags: 0,
|
||||
}
|
||||
state.ValidatorRegistry = append(state.ValidatorRegistry, newValidator)
|
||||
state.ValidatorBalances = append(state.ValidatorBalances, amount)
|
||||
@@ -364,7 +360,7 @@ func isActiveValidator(validator *pb.ValidatorRecord, slot uint64) bool {
|
||||
// flag=ACTIVATION,
|
||||
// )
|
||||
// )
|
||||
func ActivateValidator(state *pb.BeaconState, idx uint32, genesis bool) (*pb.BeaconState, error) {
|
||||
func ActivateValidator(state *pb.BeaconState, idx uint64, genesis bool) (*pb.BeaconState, error) {
|
||||
validator := state.ValidatorRegistry[idx]
|
||||
if genesis {
|
||||
validator.ActivationSlot = config.GenesisSlot
|
||||
@@ -393,7 +389,7 @@ func ActivateValidator(state *pb.BeaconState, idx uint32, genesis bool) (*pb.Bea
|
||||
// def initiate_validator_exit(state: BeaconState, index: int) -> None:
|
||||
// validator = state.validator_registry[index]
|
||||
// validator.status_flags |= INITIATED_EXIT
|
||||
func InitiateValidatorExit(state *pb.BeaconState, idx uint32) *pb.BeaconState {
|
||||
func InitiateValidatorExit(state *pb.BeaconState, idx uint64) *pb.BeaconState {
|
||||
state.ValidatorRegistry[idx].StatusFlags |=
|
||||
pb.ValidatorRecord_INITIATED_EXIT
|
||||
return state
|
||||
@@ -422,7 +418,7 @@ func InitiateValidatorExit(state *pb.BeaconState, idx uint32) *pb.BeaconState {
|
||||
// flag=EXIT,
|
||||
// )
|
||||
// )
|
||||
func ExitValidator(state *pb.BeaconState, idx uint32) (*pb.BeaconState, error) {
|
||||
func ExitValidator(state *pb.BeaconState, idx uint64) (*pb.BeaconState, error) {
|
||||
validator := state.ValidatorRegistry[idx]
|
||||
|
||||
if validator.ExitSlot < state.Slot+config.EntryExitDelay {
|
||||
@@ -463,7 +459,7 @@ func ExitValidator(state *pb.BeaconState, idx uint32) (*pb.BeaconState, error) {
|
||||
// state.validator_balances[whistleblower_index] += whistleblower_reward
|
||||
// state.validator_balances[index] -= whistleblower_reward
|
||||
// validator.penalized_slot = state.slot
|
||||
func PenalizeValidator(state *pb.BeaconState, idx uint32) (*pb.BeaconState, error) {
|
||||
func PenalizeValidator(state *pb.BeaconState, idx uint64) (*pb.BeaconState, error) {
|
||||
state, err := ExitValidator(state, idx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not exit penalized validator: %v", err)
|
||||
@@ -495,7 +491,7 @@ func PenalizeValidator(state *pb.BeaconState, idx uint32) (*pb.BeaconState, erro
|
||||
// def prepare_validator_for_withdrawal(state: BeaconState, index: int) -> None:
|
||||
// validator = state.validator_registry[index]
|
||||
// validator.status_flags |= WITHDRAWABLE
|
||||
func PrepareValidatorForWithdrawal(state *pb.BeaconState, idx uint32) *pb.BeaconState {
|
||||
func PrepareValidatorForWithdrawal(state *pb.BeaconState, idx uint64) *pb.BeaconState {
|
||||
state.ValidatorRegistry[idx].StatusFlags |=
|
||||
pb.ValidatorRecord_WITHDRAWABLE
|
||||
return state
|
||||
@@ -561,11 +557,11 @@ func UpdateRegistry(state *pb.BeaconState) (*pb.BeaconState, error) {
|
||||
// Activate validators within the allowable balance churn.
|
||||
if validator.ActivationSlot > state.Slot+config.EntryExitDelay &&
|
||||
state.ValidatorBalances[idx] >= config.MaxDeposit {
|
||||
balChurn += EffectiveBalance(state, uint32(idx))
|
||||
balChurn += EffectiveBalance(state, uint64(idx))
|
||||
if balChurn > maxBalChurn {
|
||||
break
|
||||
}
|
||||
state, err = ActivateValidator(state, uint32(idx), false)
|
||||
state, err = ActivateValidator(state, uint64(idx), false)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not activate validator %d: %v", idx, err)
|
||||
}
|
||||
@@ -577,11 +573,11 @@ func UpdateRegistry(state *pb.BeaconState) (*pb.BeaconState, error) {
|
||||
// Exit validators within the allowable balance churn.
|
||||
if validator.ExitSlot > state.Slot+config.EntryExitDelay &&
|
||||
validator.StatusFlags == pb.ValidatorRecord_INITIATED_EXIT {
|
||||
balChurn += EffectiveBalance(state, uint32(idx))
|
||||
balChurn += EffectiveBalance(state, uint64(idx))
|
||||
if balChurn > maxBalChurn {
|
||||
break
|
||||
}
|
||||
state, err = ExitValidator(state, uint32(idx))
|
||||
state, err = ExitValidator(state, uint64(idx))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not exit validator %d: %v", idx, err)
|
||||
}
|
||||
@@ -637,13 +633,13 @@ func ProcessPenaltiesAndExits(state *pb.BeaconState) *pb.BeaconState {
|
||||
if totalBalance < penaltyMultiplier {
|
||||
penaltyMultiplier = totalBalance
|
||||
}
|
||||
penalty := EffectiveBalance(state, uint32(idx)) *
|
||||
penalty := EffectiveBalance(state, uint64(idx)) *
|
||||
penaltyMultiplier / totalBalance
|
||||
state.ValidatorBalances[idx] -= penalty
|
||||
}
|
||||
}
|
||||
allIndices := AllValidatorsIndices(state)
|
||||
var eligibleIndices []uint32
|
||||
var eligibleIndices []uint64
|
||||
for _, idx := range allIndices {
|
||||
if eligibleToExit(state, idx) {
|
||||
eligibleIndices = append(eligibleIndices, idx)
|
||||
@@ -689,7 +685,7 @@ func maxBalanceChurn(totalBalance uint64) uint64 {
|
||||
// return state.slot >= validator.penalized_slot + PENALIZED_WITHDRAWAL_TIME
|
||||
// else:
|
||||
// return state.slot >= validator.exit_slot + MIN_VALIDATOR_WITHDRAWAL_TIME
|
||||
func eligibleToExit(state *pb.BeaconState, idx uint32) bool {
|
||||
func eligibleToExit(state *pb.BeaconState, idx uint64) bool {
|
||||
validator := state.ValidatorRegistry[idx]
|
||||
|
||||
if validator.PenalizedSlot <= state.Slot {
|
||||
|
||||
@@ -115,9 +115,9 @@ func TestTotalEffectiveBalance(t *testing.T) {
|
||||
}}
|
||||
|
||||
// 27 + 28 + 32 + 32 = 119
|
||||
if TotalEffectiveBalance(state, []uint32{0, 1, 2, 3}) != 119*1e9 {
|
||||
if TotalEffectiveBalance(state, []uint64{0, 1, 2, 3}) != 119*1e9 {
|
||||
t.Errorf("Incorrect TotalEffectiveBalance. Wanted: 119, got: %d",
|
||||
TotalEffectiveBalance(state, []uint32{0, 1, 2, 3})/1e9)
|
||||
TotalEffectiveBalance(state, []uint64{0, 1, 2, 3})/1e9)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ func TestBoundaryAttestingBalance(t *testing.T) {
|
||||
25 * 1e9, 26 * 1e9, 32 * 1e9, 33 * 1e9, 100 * 1e9,
|
||||
}}
|
||||
|
||||
attestedBalances := AttestingBalance(state, []uint32{0, 1, 2, 3, 4})
|
||||
attestedBalances := AttestingBalance(state, []uint64{0, 1, 2, 3, 4})
|
||||
|
||||
// 25 + 26 + 32 + 32 + 32 = 147
|
||||
if attestedBalances != 147*1e9 {
|
||||
@@ -188,7 +188,7 @@ func TestBoundaryAttesters(t *testing.T) {
|
||||
|
||||
state := &pb.BeaconState{ValidatorRegistry: validators}
|
||||
|
||||
boundaryAttesters := Attesters(state, []uint32{5, 2, 87, 42, 99, 0})
|
||||
boundaryAttesters := Attesters(state, []uint64{5, 2, 87, 42, 99, 0})
|
||||
|
||||
expectedBoundaryAttesters := []*pb.ValidatorRecord{
|
||||
{Pubkey: []byte{byte(5)}},
|
||||
@@ -229,9 +229,9 @@ func TestBoundaryAttesterIndices(t *testing.T) {
|
||||
t.Fatalf("Failed to run BoundaryAttesterIndices: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(attesterIndices, []uint32{242, 237, 224, 2}) {
|
||||
if !reflect.DeepEqual(attesterIndices, []uint64{242, 237, 224, 2}) {
|
||||
t.Errorf("Incorrect boundary attester indices. Wanted: %v, got: %v",
|
||||
[]uint32{242, 237, 224, 2}, attesterIndices)
|
||||
[]uint64{242, 237, 224, 2}, attesterIndices)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ func TestBeaconProposerIdx(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
slot uint64
|
||||
index uint32
|
||||
index uint64
|
||||
}{
|
||||
{
|
||||
slot: 1,
|
||||
@@ -298,8 +298,8 @@ func TestAttestingValidatorIndices_Ok(t *testing.T) {
|
||||
t.Errorf("EpochLength should be 64 for these tests to pass")
|
||||
}
|
||||
|
||||
var committeeIndices []uint32
|
||||
for i := uint32(0); i < 8; i++ {
|
||||
var committeeIndices []uint64
|
||||
for i := uint64(0); i < 8; i++ {
|
||||
committeeIndices = append(committeeIndices, i)
|
||||
}
|
||||
|
||||
@@ -343,9 +343,9 @@ func TestAttestingValidatorIndices_Ok(t *testing.T) {
|
||||
t.Fatalf("Could not execute AttestingValidatorIndices: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(indices, []uint32{267, 15}) {
|
||||
if !reflect.DeepEqual(indices, []uint64{267, 15}) {
|
||||
t.Errorf("Could not get incorrect validator indices. Wanted: %v, got: %v",
|
||||
[]uint32{267, 15}, indices)
|
||||
[]uint64{267, 15}, indices)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,11 +387,11 @@ func TestAttestingValidatorIndices_OutOfBound(t *testing.T) {
|
||||
func TestAllValidatorIndices(t *testing.T) {
|
||||
tests := []struct {
|
||||
registries []*pb.ValidatorRecord
|
||||
indices []uint32
|
||||
indices []uint64
|
||||
}{
|
||||
{registries: []*pb.ValidatorRecord{}, indices: []uint32{}},
|
||||
{registries: []*pb.ValidatorRecord{{}}, indices: []uint32{0}},
|
||||
{registries: []*pb.ValidatorRecord{{}, {}, {}, {}}, indices: []uint32{0, 1, 2, 3}},
|
||||
{registries: []*pb.ValidatorRecord{}, indices: []uint64{}},
|
||||
{registries: []*pb.ValidatorRecord{{}}, indices: []uint64{0}},
|
||||
{registries: []*pb.ValidatorRecord{{}, {}, {}, {}}, indices: []uint64{0, 1, 2, 3}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
state := &pb.BeaconState{ValidatorRegistry: tt.registries}
|
||||
@@ -405,7 +405,7 @@ func TestAllValidatorIndices(t *testing.T) {
|
||||
func TestNewRegistryDeltaChainTip(t *testing.T) {
|
||||
tests := []struct {
|
||||
flag uint64
|
||||
idx uint32
|
||||
idx uint64
|
||||
pubKey []byte
|
||||
currentRegistryDeltaChainTip []byte
|
||||
newRegistryDeltaChainTip []byte
|
||||
@@ -453,7 +453,6 @@ func TestProcessDeposit_PublicKeyExistsBadWithdrawalCredentials(t *testing.T) {
|
||||
proofOfPossession := []byte{}
|
||||
withdrawalCredentials := []byte{1}
|
||||
randaoCommitment := []byte{}
|
||||
pocCommitment := []byte{}
|
||||
|
||||
want := "expected withdrawal credentials to match"
|
||||
if _, err := ProcessDeposit(
|
||||
@@ -464,7 +463,6 @@ func TestProcessDeposit_PublicKeyExistsBadWithdrawalCredentials(t *testing.T) {
|
||||
proofOfPossession,
|
||||
withdrawalCredentials,
|
||||
randaoCommitment,
|
||||
pocCommitment,
|
||||
); !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Wanted error to contain %s, received %v", want, err)
|
||||
}
|
||||
@@ -490,7 +488,6 @@ func TestProcessDeposit_PublicKeyExistsGoodWithdrawalCredentials(t *testing.T) {
|
||||
proofOfPossession := []byte{}
|
||||
withdrawalCredentials := []byte{1}
|
||||
randaoCommitment := []byte{}
|
||||
pocCommitment := []byte{}
|
||||
|
||||
newState, err := ProcessDeposit(
|
||||
beaconState,
|
||||
@@ -500,7 +497,6 @@ func TestProcessDeposit_PublicKeyExistsGoodWithdrawalCredentials(t *testing.T) {
|
||||
proofOfPossession,
|
||||
withdrawalCredentials,
|
||||
randaoCommitment,
|
||||
pocCommitment,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("Process deposit failed: %v", err)
|
||||
@@ -531,7 +527,6 @@ func TestProcessDeposit_PublicKeyDoesNotExistNoEmptyValidator(t *testing.T) {
|
||||
proofOfPossession := []byte{}
|
||||
withdrawalCredentials := []byte{1}
|
||||
randaoCommitment := []byte{}
|
||||
pocCommitment := []byte{}
|
||||
|
||||
newState, err := ProcessDeposit(
|
||||
beaconState,
|
||||
@@ -541,7 +536,6 @@ func TestProcessDeposit_PublicKeyDoesNotExistNoEmptyValidator(t *testing.T) {
|
||||
proofOfPossession,
|
||||
withdrawalCredentials,
|
||||
randaoCommitment,
|
||||
pocCommitment,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("Process deposit failed: %v", err)
|
||||
@@ -576,7 +570,6 @@ func TestProcessDeposit_PublicKeyDoesNotExistEmptyValidatorExists(t *testing.T)
|
||||
proofOfPossession := []byte{}
|
||||
withdrawalCredentials := []byte{1}
|
||||
randaoCommitment := []byte{}
|
||||
pocCommitment := []byte{}
|
||||
|
||||
newState, err := ProcessDeposit(
|
||||
beaconState,
|
||||
@@ -586,7 +579,6 @@ func TestProcessDeposit_PublicKeyDoesNotExistEmptyValidatorExists(t *testing.T)
|
||||
proofOfPossession,
|
||||
withdrawalCredentials,
|
||||
randaoCommitment,
|
||||
pocCommitment,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("Process deposit failed: %v", err)
|
||||
|
||||
@@ -29,13 +29,13 @@ var (
|
||||
cleanedFinalizedSlotKey = []byte("cleaned-finalized-slot")
|
||||
)
|
||||
|
||||
// encodeSlotNumber encodes a slot number as big endian uint64.
|
||||
// encodeSlotNumber encodes a slot number as big endian uint32.
|
||||
func encodeSlotNumber(number uint64) []byte {
|
||||
return bytes.Bytes8(number)
|
||||
}
|
||||
|
||||
// decodeSlotNumber returns a slot number which has been
|
||||
// encoded as a big endian uint64 in the byte array.
|
||||
// encoded as a big endian uint32 in the byte array.
|
||||
func decodeToSlotNumber(bytearray []byte) uint64 {
|
||||
return bytes.FromBytes8(bytearray)
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ func TestComputeStateRoot(t *testing.T) {
|
||||
RandaoRevealHash32: nil,
|
||||
Body: &pbp2p.BeaconBlockBody{
|
||||
ProposerSlashings: nil,
|
||||
CasperSlashings: nil,
|
||||
AttesterSlashings: nil,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
// and total deposit supported for such block hash.
|
||||
type BlockVote struct {
|
||||
VoterIndices []uint32
|
||||
VoteTotalDeposit uint64
|
||||
VoteTotalDeposit uint32
|
||||
}
|
||||
|
||||
// BlockVoteCache is a map from hash to BlockVote object.
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
// ShuffleIndices returns a list of pseudorandomly sampled
|
||||
// indices. This is used to shuffle validators on ETH2.0 beacon chain.
|
||||
func ShuffleIndices(seed common.Hash, indicesList []uint32) ([]uint32, error) {
|
||||
func ShuffleIndices(seed common.Hash, indicesList []uint64) ([]uint64, error) {
|
||||
// Each entropy is consumed from the seed in randBytes chunks.
|
||||
randBytes := params.BeaconConfig().RandBytes
|
||||
|
||||
@@ -60,8 +60,8 @@ func ShuffleIndices(seed common.Hash, indicesList []uint32) ([]uint32, error) {
|
||||
}
|
||||
|
||||
// SplitIndices splits a list into n pieces.
|
||||
func SplitIndices(l []uint32, n uint64) [][]uint32 {
|
||||
var divided [][]uint32
|
||||
func SplitIndices(l []uint64, n uint64) [][]uint64 {
|
||||
var divided [][]uint64
|
||||
var lSize = uint64(len(l))
|
||||
for i := uint64(0); i < n; i++ {
|
||||
start := lSize * i / n
|
||||
|
||||
@@ -9,12 +9,12 @@ import (
|
||||
)
|
||||
|
||||
func TestFaultyShuffleIndices(t *testing.T) {
|
||||
var list []uint32
|
||||
var list []uint64
|
||||
|
||||
upperBound := 1<<(params.BeaconConfig().RandBytes*8) - 1
|
||||
|
||||
for i := 0; i < upperBound+1; i++ {
|
||||
list = append(list, uint32(i))
|
||||
list = append(list, uint64(i))
|
||||
}
|
||||
|
||||
if _, err := ShuffleIndices(common.Hash{'a'}, list); err == nil {
|
||||
@@ -25,13 +25,13 @@ func TestFaultyShuffleIndices(t *testing.T) {
|
||||
func TestShuffleIndices(t *testing.T) {
|
||||
hash1 := common.BytesToHash([]byte{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g'})
|
||||
hash2 := common.BytesToHash([]byte{'1', '2', '3', '4', '5', '6', '7', '1', '2', '3', '4', '5', '6', '7', '1', '2', '3', '4', '5', '6', '7', '1', '2', '3', '4', '5', '6', '7', '1', '2', '3', '4', '5', '6', '7'})
|
||||
var list1 []uint32
|
||||
var list1 []uint64
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
list1 = append(list1, uint32(i))
|
||||
list1 = append(list1, uint64(i))
|
||||
}
|
||||
|
||||
list2 := make([]uint32, len(list1))
|
||||
list2 := make([]uint64, len(list1))
|
||||
copy(list2, list1)
|
||||
|
||||
list1, err := ShuffleIndices(hash1, list1)
|
||||
@@ -47,19 +47,19 @@ func TestShuffleIndices(t *testing.T) {
|
||||
if reflect.DeepEqual(list1, list2) {
|
||||
t.Errorf("2 shuffled lists shouldn't be equal")
|
||||
}
|
||||
if !reflect.DeepEqual(list1, []uint32{5, 4, 9, 6, 7, 3, 0, 1, 8, 2}) {
|
||||
if !reflect.DeepEqual(list1, []uint64{5, 4, 9, 6, 7, 3, 0, 1, 8, 2}) {
|
||||
t.Errorf("list 1 was incorrectly shuffled")
|
||||
}
|
||||
if !reflect.DeepEqual(list2, []uint32{9, 0, 1, 5, 3, 2, 4, 7, 8, 6}) {
|
||||
if !reflect.DeepEqual(list2, []uint64{9, 0, 1, 5, 3, 2, 4, 7, 8, 6}) {
|
||||
t.Errorf("list 2 was incorrectly shuffled")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitIndices(t *testing.T) {
|
||||
var l []uint32
|
||||
var l []uint64
|
||||
validators := 64000
|
||||
for i := 0; i < validators; i++ {
|
||||
l = append(l, uint32(i))
|
||||
l = append(l, uint64(i))
|
||||
}
|
||||
split := SplitIndices(l, params.BeaconConfig().EpochLength)
|
||||
if len(split) != int(params.BeaconConfig().EpochLength) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -95,17 +95,17 @@ message ProposerSlashingResponse {
|
||||
ProposerSlashing proposer_slashing = 2;
|
||||
}
|
||||
|
||||
message CasperSlashingAnnounce {
|
||||
message AttesterSlashingAnnounce {
|
||||
bytes hash = 1;
|
||||
}
|
||||
|
||||
message CasperSlashingRequest {
|
||||
message AttesterSlashingRequest {
|
||||
bytes hash = 1;
|
||||
}
|
||||
|
||||
message CasperSlashingResponse {
|
||||
message AttesterSlashingResponse {
|
||||
bytes hash = 1;
|
||||
CasperSlashing casper_slashing = 2;
|
||||
AttesterSlashing Attester_slashing = 2;
|
||||
}
|
||||
|
||||
message DepositAnnounce {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -16,13 +16,12 @@ message BeaconState {
|
||||
// TODO(#1300): shard_committees_at_slots and ShardCommitteeArray to be removed.
|
||||
repeated ShardCommitteeArray shard_committees_at_slots = 1003;
|
||||
repeated bytes latest_randao_mixes_hash32s = 1004;
|
||||
repeated bytes latest_vdf_outputs_hash32s = 1005;
|
||||
uint64 previous_epoch_start_shard = 1006;
|
||||
uint64 current_epoch_start_shard = 1007;
|
||||
uint64 previous_epoch_calculation_slot = 1008;
|
||||
uint64 current_epoch_calculation_slot = 1009;
|
||||
bytes previous_epoch_randao_mix_hash32 = 1010;
|
||||
bytes current_epoch_randao_mix_hash32 = 1011;
|
||||
uint64 previous_epoch_start_shard = 1005;
|
||||
uint64 current_epoch_start_shard = 1006;
|
||||
uint64 previous_epoch_calculation_slot = 1007;
|
||||
uint64 current_epoch_calculation_slot = 1008;
|
||||
bytes previous_epoch_randao_mix_hash32 = 1009;
|
||||
bytes current_epoch_randao_mix_hash32 = 1010;
|
||||
|
||||
// Finality [2001-3000]
|
||||
uint64 previous_justified_slot = 2001;
|
||||
@@ -45,11 +44,6 @@ message BeaconState {
|
||||
uint64 genesis_time = 5001;
|
||||
Fork fork = 5002;
|
||||
uint64 slot = 5003;
|
||||
|
||||
// Proof of custody [6001-7000]
|
||||
// Placeholders, ProofOfCustodyChallenge is defined in phase 1,
|
||||
// the list will remain empty throughout phase 0
|
||||
repeated CustodyChallenge custody_challenges = 6001;
|
||||
}
|
||||
|
||||
message Fork {
|
||||
@@ -112,9 +106,6 @@ message ValidatorRecord {
|
||||
WITHDRAWABLE = 2; // validator is participating validator duties.
|
||||
}
|
||||
StatusFlags status_flags = 10;
|
||||
bytes custody_commitment_hash32 = 11;
|
||||
uint64 latest_custody_reseed_slot = 12;
|
||||
uint64 penultimate_custody_reseed_slot = 13;
|
||||
|
||||
// Deprecated fields
|
||||
// All fields must be annotated with [deprecated=true];
|
||||
@@ -123,7 +114,7 @@ message ValidatorRecord {
|
||||
}
|
||||
|
||||
message ShardReassignmentRecord {
|
||||
uint32 validator_index = 1;
|
||||
uint64 validator_index = 1;
|
||||
uint64 shard = 2;
|
||||
uint64 slot = 3;
|
||||
}
|
||||
@@ -139,7 +130,7 @@ message ShardCommitteeArray {
|
||||
|
||||
message ShardCommittee {
|
||||
uint64 shard = 1;
|
||||
repeated uint32 committee = 2;
|
||||
repeated uint64 committee = 2;
|
||||
uint64 total_validator_count = 3;
|
||||
}
|
||||
|
||||
@@ -158,7 +149,7 @@ message BeaconBlock {
|
||||
message BeaconBlockBody {
|
||||
repeated Attestation attestations = 1;
|
||||
repeated ProposerSlashing proposer_slashings = 2;
|
||||
repeated CasperSlashing casper_slashings = 3;
|
||||
repeated AttesterSlashing attester_slashings = 3;
|
||||
repeated Deposit deposits = 4;
|
||||
repeated Exit exits = 5;
|
||||
}
|
||||
@@ -178,9 +169,9 @@ message ProposalSignedData {
|
||||
bytes block_root_hash32 = 3;
|
||||
}
|
||||
|
||||
message SlashableVoteData {
|
||||
repeated uint32 custody_bit_0_indices = 1; // proof of custody indices for 0 bits.
|
||||
repeated uint32 custody_bit_1_indices = 2; // proof of custody indices for 1 bits.
|
||||
message SlashableVote {
|
||||
repeated uint64 validator_indices = 1;
|
||||
bytes custody_bitfield = 2;
|
||||
AttestationData data = 3;
|
||||
bytes aggregate_signature = 4; // Type of [uint384]?
|
||||
}
|
||||
@@ -192,16 +183,16 @@ message DepositData {
|
||||
}
|
||||
|
||||
message ProposerSlashing {
|
||||
uint32 proposer_index = 1;
|
||||
uint64 proposer_index = 1;
|
||||
ProposalSignedData proposal_data_1 = 2;
|
||||
bytes proposal_signature_1 = 3; // Type of [uint384]?
|
||||
ProposalSignedData proposal_data_2 = 4;
|
||||
bytes proposal_signature_2 = 5;
|
||||
}
|
||||
|
||||
message CasperSlashing {
|
||||
SlashableVoteData slashable_vote_data_1 = 1;
|
||||
SlashableVoteData slashable_vote_data_2 = 2;
|
||||
message AttesterSlashing {
|
||||
SlashableVote slashable_vote_1 = 1;
|
||||
SlashableVote slashable_vote_2 = 2;
|
||||
}
|
||||
|
||||
message Deposit {
|
||||
@@ -212,13 +203,13 @@ message Deposit {
|
||||
|
||||
message Exit {
|
||||
uint64 slot = 1;
|
||||
uint32 validator_index = 2;
|
||||
uint64 validator_index = 2;
|
||||
bytes signature = 3; // Type of [uint384]?
|
||||
}
|
||||
|
||||
message ValidatorRegistryDeltaBlock {
|
||||
bytes latest_registry_delta_root_hash32 = 1;
|
||||
uint32 validator_index = 2;
|
||||
uint64 validator_index = 2;
|
||||
bytes pubkey = 3;
|
||||
uint64 slot = 4;
|
||||
enum ValidatorRegistryDeltaFlags {
|
||||
@@ -227,5 +218,3 @@ message ValidatorRegistryDeltaBlock {
|
||||
}
|
||||
ValidatorRegistryDeltaFlags flag = 5;
|
||||
}
|
||||
|
||||
message CustodyChallenge {} // Empty until phase 1
|
||||
|
||||
@@ -48,7 +48,7 @@ func (x ValidatorRole) String() string {
|
||||
return proto.EnumName(ValidatorRole_name, int32(x))
|
||||
}
|
||||
func (ValidatorRole) EnumDescriptor() ([]byte, []int) {
|
||||
return fileDescriptor_services_aaf07938ceaf5b56, []int{0}
|
||||
return fileDescriptor_services_e10adba4df963591, []int{0}
|
||||
}
|
||||
|
||||
type ProposeRequest struct {
|
||||
@@ -56,7 +56,7 @@ type ProposeRequest struct {
|
||||
SlotNumber uint64 `protobuf:"varint,2,opt,name=slot_number,json=slotNumber,proto3" json:"slot_number,omitempty"`
|
||||
RandaoRevealHash32 []byte `protobuf:"bytes,3,opt,name=randao_reveal_hash32,json=randaoRevealHash32,proto3" json:"randao_reveal_hash32,omitempty"`
|
||||
AttestationBitmask []byte `protobuf:"bytes,4,opt,name=attestation_bitmask,json=attestationBitmask,proto3" json:"attestation_bitmask,omitempty"`
|
||||
AttestationAggregateSig []uint32 `protobuf:"varint,5,rep,packed,name=attestation_aggregate_sig,json=attestationAggregateSig" json:"attestation_aggregate_sig,omitempty"`
|
||||
AttestationAggregateSig []uint64 `protobuf:"varint,5,rep,packed,name=attestation_aggregate_sig,json=attestationAggregateSig" json:"attestation_aggregate_sig,omitempty"`
|
||||
Timestamp *types.Timestamp `protobuf:"bytes,6,opt,name=timestamp" json:"timestamp,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
@@ -67,7 +67,7 @@ func (m *ProposeRequest) Reset() { *m = ProposeRequest{} }
|
||||
func (m *ProposeRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*ProposeRequest) ProtoMessage() {}
|
||||
func (*ProposeRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_services_aaf07938ceaf5b56, []int{0}
|
||||
return fileDescriptor_services_e10adba4df963591, []int{0}
|
||||
}
|
||||
func (m *ProposeRequest) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
@@ -124,7 +124,7 @@ func (m *ProposeRequest) GetAttestationBitmask() []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ProposeRequest) GetAttestationAggregateSig() []uint32 {
|
||||
func (m *ProposeRequest) GetAttestationAggregateSig() []uint64 {
|
||||
if m != nil {
|
||||
return m.AttestationAggregateSig
|
||||
}
|
||||
@@ -149,7 +149,7 @@ func (m *ProposeResponse) Reset() { *m = ProposeResponse{} }
|
||||
func (m *ProposeResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*ProposeResponse) ProtoMessage() {}
|
||||
func (*ProposeResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_services_aaf07938ceaf5b56, []int{1}
|
||||
return fileDescriptor_services_e10adba4df963591, []int{1}
|
||||
}
|
||||
func (m *ProposeResponse) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
@@ -196,7 +196,7 @@ func (m *ProposerIndexRequest) Reset() { *m = ProposerIndexRequest{} }
|
||||
func (m *ProposerIndexRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*ProposerIndexRequest) ProtoMessage() {}
|
||||
func (*ProposerIndexRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_services_aaf07938ceaf5b56, []int{2}
|
||||
return fileDescriptor_services_e10adba4df963591, []int{2}
|
||||
}
|
||||
func (m *ProposerIndexRequest) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
@@ -233,7 +233,7 @@ func (m *ProposerIndexRequest) GetSlotNumber() uint64 {
|
||||
}
|
||||
|
||||
type ProposerIndexResponse struct {
|
||||
Index uint32 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"`
|
||||
Index uint64 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
@@ -243,7 +243,7 @@ func (m *ProposerIndexResponse) Reset() { *m = ProposerIndexResponse{} }
|
||||
func (m *ProposerIndexResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*ProposerIndexResponse) ProtoMessage() {}
|
||||
func (*ProposerIndexResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_services_aaf07938ceaf5b56, []int{3}
|
||||
return fileDescriptor_services_e10adba4df963591, []int{3}
|
||||
}
|
||||
func (m *ProposerIndexResponse) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
@@ -272,7 +272,7 @@ func (m *ProposerIndexResponse) XXX_DiscardUnknown() {
|
||||
|
||||
var xxx_messageInfo_ProposerIndexResponse proto.InternalMessageInfo
|
||||
|
||||
func (m *ProposerIndexResponse) GetIndex() uint32 {
|
||||
func (m *ProposerIndexResponse) GetIndex() uint64 {
|
||||
if m != nil {
|
||||
return m.Index
|
||||
}
|
||||
@@ -290,7 +290,7 @@ func (m *StateRootResponse) Reset() { *m = StateRootResponse{} }
|
||||
func (m *StateRootResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*StateRootResponse) ProtoMessage() {}
|
||||
func (*StateRootResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_services_aaf07938ceaf5b56, []int{4}
|
||||
return fileDescriptor_services_e10adba4df963591, []int{4}
|
||||
}
|
||||
func (m *StateRootResponse) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
@@ -337,7 +337,7 @@ func (m *AttestRequest) Reset() { *m = AttestRequest{} }
|
||||
func (m *AttestRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*AttestRequest) ProtoMessage() {}
|
||||
func (*AttestRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_services_aaf07938ceaf5b56, []int{5}
|
||||
return fileDescriptor_services_e10adba4df963591, []int{5}
|
||||
}
|
||||
func (m *AttestRequest) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
@@ -384,7 +384,7 @@ func (m *AttestResponse) Reset() { *m = AttestResponse{} }
|
||||
func (m *AttestResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*AttestResponse) ProtoMessage() {}
|
||||
func (*AttestResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_services_aaf07938ceaf5b56, []int{6}
|
||||
return fileDescriptor_services_e10adba4df963591, []int{6}
|
||||
}
|
||||
func (m *AttestResponse) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
@@ -434,7 +434,7 @@ func (m *Assignment) Reset() { *m = Assignment{} }
|
||||
func (m *Assignment) String() string { return proto.CompactTextString(m) }
|
||||
func (*Assignment) ProtoMessage() {}
|
||||
func (*Assignment) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_services_aaf07938ceaf5b56, []int{7}
|
||||
return fileDescriptor_services_e10adba4df963591, []int{7}
|
||||
}
|
||||
func (m *Assignment) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
@@ -502,7 +502,7 @@ func (m *ValidatorIndexRequest) Reset() { *m = ValidatorIndexRequest{} }
|
||||
func (m *ValidatorIndexRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*ValidatorIndexRequest) ProtoMessage() {}
|
||||
func (*ValidatorIndexRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_services_aaf07938ceaf5b56, []int{8}
|
||||
return fileDescriptor_services_e10adba4df963591, []int{8}
|
||||
}
|
||||
func (m *ValidatorIndexRequest) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
@@ -539,7 +539,7 @@ func (m *ValidatorIndexRequest) GetPublicKey() []byte {
|
||||
}
|
||||
|
||||
type ValidatorIndexResponse struct {
|
||||
Index uint32 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"`
|
||||
Index uint64 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
@@ -549,7 +549,7 @@ func (m *ValidatorIndexResponse) Reset() { *m = ValidatorIndexResponse{}
|
||||
func (m *ValidatorIndexResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*ValidatorIndexResponse) ProtoMessage() {}
|
||||
func (*ValidatorIndexResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_services_aaf07938ceaf5b56, []int{9}
|
||||
return fileDescriptor_services_e10adba4df963591, []int{9}
|
||||
}
|
||||
func (m *ValidatorIndexResponse) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
@@ -578,7 +578,7 @@ func (m *ValidatorIndexResponse) XXX_DiscardUnknown() {
|
||||
|
||||
var xxx_messageInfo_ValidatorIndexResponse proto.InternalMessageInfo
|
||||
|
||||
func (m *ValidatorIndexResponse) GetIndex() uint32 {
|
||||
func (m *ValidatorIndexResponse) GetIndex() uint64 {
|
||||
if m != nil {
|
||||
return m.Index
|
||||
}
|
||||
@@ -597,7 +597,7 @@ func (m *ValidatorEpochAssignmentsRequest) Reset() { *m = ValidatorEpoch
|
||||
func (m *ValidatorEpochAssignmentsRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*ValidatorEpochAssignmentsRequest) ProtoMessage() {}
|
||||
func (*ValidatorEpochAssignmentsRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_services_aaf07938ceaf5b56, []int{10}
|
||||
return fileDescriptor_services_e10adba4df963591, []int{10}
|
||||
}
|
||||
func (m *ValidatorEpochAssignmentsRequest) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
@@ -651,7 +651,7 @@ func (m *ValidatorEpochAssignmentsResponse) Reset() { *m = ValidatorEpoc
|
||||
func (m *ValidatorEpochAssignmentsResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*ValidatorEpochAssignmentsResponse) ProtoMessage() {}
|
||||
func (*ValidatorEpochAssignmentsResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_services_aaf07938ceaf5b56, []int{11}
|
||||
return fileDescriptor_services_e10adba4df963591, []int{11}
|
||||
}
|
||||
func (m *ValidatorEpochAssignmentsResponse) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
@@ -1872,7 +1872,7 @@ func (m *ProposeRequest) Unmarshal(dAtA []byte) error {
|
||||
iNdEx = postIndex
|
||||
case 5:
|
||||
if wireType == 0 {
|
||||
var v uint32
|
||||
var v uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowServices
|
||||
@@ -1882,7 +1882,7 @@ func (m *ProposeRequest) Unmarshal(dAtA []byte) error {
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
v |= (uint32(b) & 0x7F) << shift
|
||||
v |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
@@ -1912,7 +1912,7 @@ func (m *ProposeRequest) Unmarshal(dAtA []byte) error {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
for iNdEx < postIndex {
|
||||
var v uint32
|
||||
var v uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowServices
|
||||
@@ -1922,7 +1922,7 @@ func (m *ProposeRequest) Unmarshal(dAtA []byte) error {
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
v |= (uint32(b) & 0x7F) << shift
|
||||
v |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
@@ -2182,7 +2182,7 @@ func (m *ProposerIndexResponse) Unmarshal(dAtA []byte) error {
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
m.Index |= (uint32(b) & 0x7F) << shift
|
||||
m.Index |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
@@ -2721,7 +2721,7 @@ func (m *ValidatorIndexResponse) Unmarshal(dAtA []byte) error {
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
m.Index |= (uint32(b) & 0x7F) << shift
|
||||
m.Index |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
@@ -3039,63 +3039,63 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
proto.RegisterFile("proto/beacon/rpc/v1/services.proto", fileDescriptor_services_aaf07938ceaf5b56)
|
||||
proto.RegisterFile("proto/beacon/rpc/v1/services.proto", fileDescriptor_services_e10adba4df963591)
|
||||
}
|
||||
|
||||
var fileDescriptor_services_aaf07938ceaf5b56 = []byte{
|
||||
// 857 bytes of a gzipped FileDescriptorProto
|
||||
var fileDescriptor_services_e10adba4df963591 = []byte{
|
||||
// 856 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0xd1, 0x6e, 0x23, 0x35,
|
||||
0x14, 0x65, 0xb2, 0xdd, 0x85, 0xbd, 0x49, 0xda, 0xac, 0xe9, 0x96, 0xec, 0x20, 0xda, 0x30, 0x2b,
|
||||
0x14, 0x65, 0xb2, 0xd9, 0x85, 0xbd, 0x49, 0xda, 0xac, 0xe9, 0x96, 0xec, 0x20, 0xda, 0x30, 0x2b,
|
||||
0xa0, 0x8b, 0xd8, 0x49, 0x3b, 0x2b, 0x41, 0x81, 0xa7, 0x64, 0x15, 0xa9, 0x68, 0x57, 0x6d, 0x35,
|
||||
0x29, 0xcb, 0x03, 0x48, 0x23, 0x4f, 0x62, 0x26, 0xa3, 0x4e, 0xc6, 0xc6, 0x76, 0x22, 0xfa, 0x0d,
|
||||
0xbc, 0xf0, 0xc4, 0x4f, 0xf0, 0xc4, 0x27, 0xf0, 0xc6, 0x23, 0x9f, 0x80, 0xfa, 0x25, 0xc8, 0xf6,
|
||||
0xcc, 0xd4, 0x4d, 0x9b, 0x36, 0xf0, 0xe8, 0x73, 0xcf, 0xb9, 0xf7, 0xfa, 0xf8, 0xfa, 0x82, 0xc7,
|
||||
0x38, 0x95, 0xb4, 0x1b, 0x13, 0x3c, 0xa2, 0x79, 0x97, 0xb3, 0x51, 0x77, 0xbe, 0xdf, 0x15, 0x84,
|
||||
0xcf, 0xd3, 0x11, 0x11, 0xbe, 0x0e, 0xa2, 0x2d, 0x22, 0x27, 0x84, 0x93, 0xd9, 0xd4, 0x37, 0x34,
|
||||
0x9f, 0xb3, 0x91, 0x3f, 0xdf, 0x77, 0x77, 0xae, 0x68, 0x59, 0xc0, 0x94, 0x56, 0x9e, 0xb3, 0x52,
|
||||
0xe8, 0xbe, 0x9f, 0x50, 0x9a, 0x64, 0xa4, 0xab, 0x4f, 0xf1, 0xec, 0xc7, 0x2e, 0x99, 0x32, 0x79,
|
||||
0x5e, 0x04, 0x77, 0x16, 0x83, 0x32, 0x9d, 0x12, 0x21, 0xf1, 0x94, 0x19, 0x82, 0xf7, 0x7b, 0x0d,
|
||||
0xd6, 0x4f, 0x38, 0x65, 0x54, 0x90, 0x90, 0xfc, 0x34, 0x23, 0x42, 0xa2, 0x1d, 0xa8, 0x33, 0xcc,
|
||||
0x49, 0x2e, 0xa3, 0x09, 0x16, 0x93, 0xb6, 0xd3, 0x71, 0x76, 0x1b, 0x21, 0x18, 0xe8, 0x10, 0x8b,
|
||||
0x89, 0x22, 0x88, 0x8c, 0xca, 0x28, 0x9f, 0x4d, 0x63, 0xc2, 0xdb, 0xb5, 0x8e, 0xb3, 0xbb, 0x16,
|
||||
0x82, 0x82, 0x8e, 0x34, 0x82, 0xf6, 0x60, 0x93, 0xe3, 0x7c, 0x8c, 0x69, 0xc4, 0xc9, 0x9c, 0xe0,
|
||||
0x4c, 0x27, 0x7a, 0x11, 0xb4, 0xef, 0xe9, 0x54, 0xc8, 0xc4, 0x42, 0x1d, 0x3a, 0xd4, 0x11, 0xd4,
|
||||
0x85, 0x77, 0xb1, 0x94, 0xaa, 0x33, 0x99, 0xd2, 0x3c, 0x8a, 0x53, 0x39, 0xc5, 0xe2, 0xac, 0xbd,
|
||||
0x66, 0x04, 0x56, 0xa8, 0x6f, 0x22, 0xe8, 0x2b, 0x78, 0x62, 0x0b, 0x70, 0x92, 0x70, 0x92, 0x60,
|
||||
0x49, 0x22, 0x91, 0x26, 0xed, 0xfb, 0x9d, 0x7b, 0xbb, 0xcd, 0xf0, 0x3d, 0x8b, 0xd0, 0x2b, 0xe3,
|
||||
0xc3, 0x34, 0x41, 0x07, 0xf0, 0xb0, 0xb2, 0xa1, 0xfd, 0xa0, 0xe3, 0xec, 0xd6, 0x03, 0xd7, 0x37,
|
||||
0x46, 0xf9, 0xa5, 0x51, 0xfe, 0x69, 0xc9, 0x08, 0x2f, 0xc9, 0xde, 0x1e, 0x6c, 0x54, 0x66, 0x09,
|
||||
0x46, 0x73, 0x41, 0xd0, 0x07, 0x00, 0x71, 0x46, 0x47, 0x67, 0xb6, 0x59, 0x0f, 0x35, 0xa2, 0xae,
|
||||
0xe6, 0x7d, 0x01, 0x9b, 0x85, 0x82, 0x7f, 0x93, 0x8f, 0xc9, 0xcf, 0x96, 0xc9, 0xb6, 0x87, 0xce,
|
||||
0xa2, 0x87, 0xde, 0x73, 0x78, 0xbc, 0x20, 0x2c, 0x0a, 0x6e, 0xc2, 0xfd, 0x54, 0x01, 0x5a, 0xd3,
|
||||
0x0c, 0xcd, 0xc1, 0x0b, 0xe0, 0xd1, 0x50, 0x62, 0x49, 0x42, 0x4a, 0xa5, 0xdd, 0x9b, 0xba, 0x3f,
|
||||
0x89, 0x38, 0xa5, 0xb2, 0xec, 0x4d, 0x94, 0x34, 0xef, 0x0d, 0x34, 0x7b, 0xda, 0xa2, 0xb2, 0xa9,
|
||||
0x01, 0xd4, 0x2d, 0xcf, 0xb4, 0xa0, 0x1e, 0x3c, 0xf5, 0x17, 0x27, 0x93, 0x05, 0xcc, 0x9f, 0xef,
|
||||
0xfb, 0xbd, 0x4b, 0x6a, 0x68, 0xeb, 0xbc, 0xaf, 0x61, 0xbd, 0xcc, 0x5b, 0x34, 0xf2, 0x0c, 0x5a,
|
||||
0xf6, 0x6b, 0x59, 0x56, 0x6d, 0x58, 0xb8, 0x36, 0xec, 0x17, 0x07, 0xa0, 0x27, 0x44, 0x9a, 0xe4,
|
||||
0x53, 0x92, 0x4b, 0x75, 0x05, 0x36, 0x8b, 0xb3, 0x74, 0x14, 0x9d, 0x91, 0xf3, 0xf2, 0x0a, 0x06,
|
||||
0x79, 0x45, 0xce, 0x95, 0x19, 0x62, 0x82, 0xf9, 0xb8, 0x18, 0x42, 0x73, 0x40, 0x4f, 0xa1, 0x69,
|
||||
0xd2, 0x12, 0x1e, 0x29, 0x4b, 0xf5, 0xe0, 0xad, 0x85, 0x8d, 0x12, 0x1c, 0x66, 0x54, 0x2a, 0x12,
|
||||
0x2b, 0x0c, 0x36, 0xa4, 0x35, 0x43, 0x2a, 0x41, 0x45, 0xf2, 0x3e, 0x87, 0xc7, 0x6f, 0x70, 0x96,
|
||||
0x8e, 0xb1, 0xa4, 0x57, 0xdf, 0xef, 0xf6, 0xbe, 0x3c, 0x1f, 0xb6, 0x16, 0x75, 0xb7, 0x3e, 0x5f,
|
||||
0x0c, 0x9d, 0x8a, 0x3f, 0x60, 0x74, 0x34, 0xb9, 0xb4, 0x40, 0x58, 0x23, 0x43, 0x54, 0x28, 0x12,
|
||||
0x12, 0x73, 0x59, 0x8e, 0x8c, 0x86, 0x86, 0x0a, 0x59, 0xe8, 0xa9, 0xb6, 0xd8, 0x53, 0x02, 0x1f,
|
||||
0xde, 0x52, 0xa3, 0x68, 0xaf, 0x0f, 0x80, 0x2b, 0x58, 0xe7, 0xa8, 0x07, 0x9e, 0x7f, 0xf3, 0x6e,
|
||||
0xf2, 0x2f, 0x13, 0x84, 0x96, 0xea, 0xd3, 0x03, 0x68, 0x56, 0x85, 0x42, 0x9a, 0x11, 0x54, 0x87,
|
||||
0xb7, 0xbf, 0x3d, 0x7a, 0x75, 0x74, 0xfc, 0xdd, 0x51, 0xeb, 0x2d, 0xd4, 0x80, 0x77, 0x7a, 0xa7,
|
||||
0xa7, 0x83, 0xe1, 0xe9, 0x20, 0x6c, 0x39, 0xea, 0x74, 0x12, 0x1e, 0x9f, 0x1c, 0x0f, 0x07, 0x61,
|
||||
0xab, 0x16, 0xfc, 0xe1, 0x40, 0xb3, 0xaf, 0x4b, 0x0c, 0xcd, 0x76, 0x44, 0xaf, 0xa1, 0xf9, 0x12,
|
||||
0xe7, 0x34, 0x4f, 0x47, 0x38, 0x3b, 0x24, 0x78, 0x8c, 0xb6, 0xae, 0xfd, 0xd4, 0x81, 0xda, 0x77,
|
||||
0xee, 0xd2, 0x31, 0x35, 0xf9, 0xfa, 0xea, 0x47, 0xa2, 0x10, 0x1e, 0xbd, 0xc6, 0x6a, 0x06, 0xac,
|
||||
0xd9, 0xfd, 0xef, 0x19, 0x2d, 0xf1, 0x9e, 0x13, 0xe4, 0xb0, 0xd1, 0x2b, 0xe7, 0xaa, 0x68, 0xfa,
|
||||
0x7b, 0x00, 0x03, 0xe9, 0x8e, 0x3f, 0x5a, 0x6a, 0x9f, 0xfd, 0xf9, 0xdc, 0x8f, 0xef, 0xa2, 0x99,
|
||||
0x17, 0x0a, 0xfe, 0xac, 0x55, 0x4b, 0xa8, 0x2a, 0x98, 0x41, 0xf3, 0xca, 0xb2, 0x40, 0x9f, 0x2d,
|
||||
0x4b, 0x76, 0xd3, 0x32, 0x72, 0x9f, 0xaf, 0xc8, 0x2e, 0x66, 0xe4, 0x07, 0x68, 0x14, 0x01, 0xe3,
|
||||
0xea, 0x2a, 0xd6, 0xbb, 0x9f, 0xdc, 0x51, 0xa3, 0xca, 0x1e, 0x43, 0xeb, 0x25, 0x9d, 0xb2, 0x99,
|
||||
0x24, 0xd5, 0x42, 0x5b, 0xad, 0xc2, 0xb3, 0x65, 0x15, 0xae, 0x2d, 0xc6, 0xe0, 0xb7, 0x1a, 0xb4,
|
||||
0xaa, 0x11, 0x2d, 0x4d, 0xa4, 0xb0, 0x7e, 0xf5, 0xcf, 0xa2, 0xa5, 0xbe, 0xdc, 0xb8, 0x13, 0x5c,
|
||||
0x7f, 0x55, 0x7a, 0x71, 0xd3, 0x5f, 0x1d, 0x78, 0xb2, 0xf4, 0x47, 0xa2, 0x83, 0x3b, 0xb3, 0x2d,
|
||||
0x59, 0x14, 0xee, 0x97, 0xff, 0x43, 0x69, 0x5a, 0xea, 0x37, 0xfe, 0xba, 0xd8, 0x76, 0xfe, 0xbe,
|
||||
0xd8, 0x76, 0xfe, 0xb9, 0xd8, 0x76, 0xe2, 0x07, 0xfa, 0x47, 0xbc, 0xf8, 0x37, 0x00, 0x00, 0xff,
|
||||
0xff, 0x9b, 0xe5, 0x23, 0xf9, 0xc0, 0x08, 0x00, 0x00,
|
||||
0xcc, 0xd4, 0x4d, 0x9b, 0xb6, 0xf0, 0xe8, 0x73, 0xcf, 0xb9, 0xf7, 0xfa, 0xf8, 0xfa, 0x82, 0xc7,
|
||||
0x38, 0x95, 0xb4, 0x17, 0x13, 0x3c, 0xa6, 0x79, 0x8f, 0xb3, 0x71, 0x6f, 0xb1, 0xd7, 0x13, 0x84,
|
||||
0x2f, 0xd2, 0x31, 0x11, 0xbe, 0x0e, 0xa2, 0x4d, 0x22, 0xa7, 0x84, 0x93, 0xf9, 0xcc, 0x37, 0x34,
|
||||
0x9f, 0xb3, 0xb1, 0xbf, 0xd8, 0x73, 0xb7, 0x2f, 0x69, 0x59, 0xc0, 0x94, 0x56, 0x9e, 0xb1, 0x52,
|
||||
0xe8, 0xbe, 0x9f, 0x50, 0x9a, 0x64, 0xa4, 0xa7, 0x4f, 0xf1, 0xfc, 0xc7, 0x1e, 0x99, 0x31, 0x79,
|
||||
0x56, 0x04, 0xb7, 0x97, 0x83, 0x32, 0x9d, 0x11, 0x21, 0xf1, 0x8c, 0x19, 0x82, 0xf7, 0x7b, 0x0d,
|
||||
0xd6, 0x8e, 0x39, 0x65, 0x54, 0x90, 0x90, 0xfc, 0x34, 0x27, 0x42, 0xa2, 0x6d, 0x68, 0x30, 0xcc,
|
||||
0x49, 0x2e, 0xa3, 0x29, 0x16, 0xd3, 0x8e, 0xd3, 0x75, 0x76, 0x9a, 0x21, 0x18, 0xe8, 0x00, 0x8b,
|
||||
0xa9, 0x22, 0x88, 0x8c, 0xca, 0x28, 0x9f, 0xcf, 0x62, 0xc2, 0x3b, 0xb5, 0xae, 0xb3, 0x53, 0x0f,
|
||||
0x41, 0x41, 0x87, 0x1a, 0x41, 0xbb, 0xb0, 0xc1, 0x71, 0x3e, 0xc1, 0x34, 0xe2, 0x64, 0x41, 0x70,
|
||||
0xa6, 0x13, 0xbd, 0x08, 0x3a, 0xf7, 0x74, 0x2a, 0x64, 0x62, 0xa1, 0x0e, 0x1d, 0xe8, 0x08, 0xea,
|
||||
0xc1, 0xbb, 0x58, 0x4a, 0xd5, 0x99, 0x4c, 0x69, 0x1e, 0xc5, 0xa9, 0x9c, 0x61, 0x71, 0xda, 0xa9,
|
||||
0x1b, 0x81, 0x15, 0x1a, 0x98, 0x08, 0xfa, 0x0a, 0x9e, 0xd8, 0x02, 0x9c, 0x24, 0x9c, 0x24, 0x58,
|
||||
0x92, 0x48, 0xa4, 0x49, 0xe7, 0x7e, 0xf7, 0xde, 0x4e, 0x3d, 0x7c, 0xcf, 0x22, 0xf4, 0xcb, 0xf8,
|
||||
0x28, 0x4d, 0xd0, 0x3e, 0x3c, 0xac, 0x6c, 0xe8, 0x3c, 0xe8, 0x3a, 0x3b, 0x8d, 0xc0, 0xf5, 0x8d,
|
||||
0x51, 0x7e, 0x69, 0x94, 0x7f, 0x52, 0x32, 0xc2, 0x0b, 0xb2, 0xb7, 0x0b, 0xeb, 0x95, 0x59, 0x82,
|
||||
0xd1, 0x5c, 0x10, 0xf4, 0x01, 0x40, 0x9c, 0xd1, 0xf1, 0xa9, 0x6d, 0xd6, 0x43, 0x8d, 0xa8, 0xab,
|
||||
0x79, 0x5f, 0xc0, 0x46, 0xa1, 0xe0, 0xdf, 0xe4, 0x13, 0xf2, 0xb3, 0x65, 0xb2, 0xed, 0xa1, 0xb3,
|
||||
0xec, 0xa1, 0xf7, 0x1c, 0x1e, 0x2f, 0x09, 0x8b, 0x82, 0x1b, 0x70, 0x3f, 0x55, 0x40, 0xa1, 0x31,
|
||||
0x07, 0x2f, 0x80, 0x47, 0x23, 0x89, 0x25, 0x09, 0x29, 0x95, 0x76, 0x6f, 0xea, 0xfe, 0x24, 0xe2,
|
||||
0x94, 0xca, 0xb2, 0x37, 0x51, 0xd2, 0xbc, 0x37, 0xd0, 0xea, 0x6b, 0x8b, 0xca, 0xa6, 0x86, 0xd0,
|
||||
0xb0, 0x3c, 0xd3, 0x82, 0x46, 0xf0, 0xd4, 0x5f, 0x9e, 0x4c, 0x16, 0x30, 0x7f, 0xb1, 0xe7, 0xf7,
|
||||
0x2f, 0xa8, 0xa1, 0xad, 0xf3, 0xbe, 0x86, 0xb5, 0x32, 0x6f, 0xd1, 0xc8, 0x33, 0x68, 0xdb, 0xaf,
|
||||
0x65, 0x59, 0xb5, 0x6e, 0xe1, 0xda, 0xb0, 0x5f, 0x1c, 0x80, 0xbe, 0x10, 0x69, 0x92, 0xcf, 0x48,
|
||||
0x2e, 0xd5, 0x15, 0xd8, 0x3c, 0xce, 0xd2, 0x71, 0x74, 0x4a, 0xce, 0xca, 0x2b, 0x18, 0xe4, 0x15,
|
||||
0x39, 0x53, 0x66, 0x88, 0x29, 0xe6, 0x93, 0x62, 0x08, 0xcd, 0x01, 0x3d, 0x85, 0x96, 0x49, 0x4b,
|
||||
0x78, 0xa4, 0x2c, 0xd5, 0x83, 0x57, 0x0f, 0x9b, 0x25, 0x38, 0xca, 0xa8, 0x54, 0x24, 0x56, 0x18,
|
||||
0x6c, 0x48, 0x75, 0x43, 0x2a, 0x41, 0x45, 0xf2, 0x3e, 0x87, 0xc7, 0x6f, 0x70, 0x96, 0x4e, 0xb0,
|
||||
0xa4, 0x97, 0xdf, 0xef, 0xe6, 0xbe, 0x3c, 0x1f, 0x36, 0x97, 0x75, 0x37, 0x3e, 0x5f, 0x0c, 0xdd,
|
||||
0x8a, 0x3f, 0x64, 0x74, 0x3c, 0xbd, 0xb0, 0x40, 0x58, 0x23, 0x43, 0x54, 0x28, 0x12, 0x12, 0x73,
|
||||
0x59, 0x8e, 0x8c, 0x86, 0x46, 0x0a, 0x59, 0xea, 0xa9, 0xb6, 0xdc, 0x53, 0x02, 0x1f, 0xde, 0x50,
|
||||
0xa3, 0x68, 0x6f, 0x00, 0x80, 0x2b, 0x58, 0xe7, 0x68, 0x04, 0x9e, 0x7f, 0xfd, 0x6e, 0xf2, 0x2f,
|
||||
0x12, 0x84, 0x96, 0xea, 0xd3, 0x7d, 0x68, 0x55, 0x85, 0x42, 0x9a, 0x11, 0xd4, 0x80, 0xb7, 0xbf,
|
||||
0x3d, 0x7c, 0x75, 0x78, 0xf4, 0xdd, 0x61, 0xfb, 0x2d, 0xd4, 0x84, 0x77, 0xfa, 0x27, 0x27, 0xc3,
|
||||
0xd1, 0xc9, 0x30, 0x6c, 0x3b, 0xea, 0x74, 0x1c, 0x1e, 0x1d, 0x1f, 0x8d, 0x86, 0x61, 0xbb, 0x16,
|
||||
0xfc, 0xe1, 0x40, 0x6b, 0xa0, 0x4b, 0x8c, 0xcc, 0x76, 0x44, 0xaf, 0xa1, 0xf5, 0x12, 0xe7, 0x34,
|
||||
0x4f, 0xc7, 0x38, 0x3b, 0x20, 0x78, 0x82, 0x36, 0xaf, 0xfc, 0xd4, 0xa1, 0xda, 0x77, 0xee, 0xca,
|
||||
0x31, 0x35, 0xf9, 0x06, 0xea, 0x47, 0xa2, 0x10, 0x1e, 0xbd, 0xc6, 0x6a, 0x06, 0xac, 0xd9, 0xfd,
|
||||
0xef, 0x19, 0x2d, 0xf1, 0xae, 0x13, 0xe4, 0xb0, 0xde, 0x2f, 0xe7, 0xaa, 0x68, 0xfa, 0x7b, 0x00,
|
||||
0x03, 0xe9, 0x8e, 0x3f, 0x5a, 0x69, 0x9f, 0xfd, 0xf9, 0xdc, 0x8f, 0x6f, 0xa3, 0x99, 0x17, 0x0a,
|
||||
0xfe, 0xac, 0x55, 0x4b, 0xa8, 0x2a, 0x98, 0x41, 0xeb, 0xd2, 0xb2, 0x40, 0x9f, 0xad, 0x4a, 0x76,
|
||||
0xdd, 0x32, 0x72, 0x9f, 0xdf, 0x91, 0x5d, 0xcc, 0xc8, 0x0f, 0xd0, 0x2c, 0x02, 0xc6, 0xd5, 0xbb,
|
||||
0x58, 0xef, 0x7e, 0x72, 0x4b, 0x8d, 0x2a, 0x7b, 0x0c, 0xed, 0x97, 0x74, 0xc6, 0xe6, 0x92, 0x54,
|
||||
0x0b, 0xed, 0x6e, 0x15, 0x9e, 0xad, 0xaa, 0x70, 0x65, 0x31, 0x06, 0xbf, 0xd5, 0xa0, 0x5d, 0x8d,
|
||||
0x68, 0x69, 0x22, 0x85, 0xb5, 0xcb, 0x7f, 0x16, 0xad, 0xf4, 0xe5, 0xda, 0x9d, 0xe0, 0xfa, 0x77,
|
||||
0xa5, 0x17, 0x37, 0xfd, 0xd5, 0x81, 0x27, 0x2b, 0x7f, 0x24, 0xda, 0xbf, 0x35, 0xdb, 0x8a, 0x45,
|
||||
0xe1, 0x7e, 0xf9, 0x3f, 0x94, 0xa6, 0xa5, 0x41, 0xf3, 0xaf, 0xf3, 0x2d, 0xe7, 0xef, 0xf3, 0x2d,
|
||||
0xe7, 0x9f, 0xf3, 0x2d, 0x27, 0x7e, 0xa0, 0x7f, 0xc4, 0x8b, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff,
|
||||
0xbe, 0x05, 0x6e, 0x91, 0xc0, 0x08, 0x00, 0x00,
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ message ProposeRequest {
|
||||
uint64 slot_number = 2;
|
||||
bytes randao_reveal_hash32 = 3;
|
||||
bytes attestation_bitmask = 4;
|
||||
repeated uint32 attestation_aggregate_sig = 5;
|
||||
repeated uint64 attestation_aggregate_sig = 5;
|
||||
google.protobuf.Timestamp timestamp = 6;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ message ProposerIndexRequest {
|
||||
}
|
||||
|
||||
message ProposerIndexResponse {
|
||||
uint32 index = 1;
|
||||
uint64 index = 1;
|
||||
}
|
||||
|
||||
message StateRootResponse {
|
||||
@@ -82,7 +82,7 @@ message ValidatorIndexRequest {
|
||||
}
|
||||
|
||||
message ValidatorIndexResponse {
|
||||
uint32 index = 1;
|
||||
uint64 index = 1;
|
||||
}
|
||||
|
||||
message ValidatorEpochAssignmentsRequest {
|
||||
|
||||
@@ -17,17 +17,17 @@ func makeEmptySignature() [][]byte {
|
||||
// BeaconChainConfig contains constant configs for node to participate in beacon chain.
|
||||
type BeaconChainConfig struct {
|
||||
// Misc constants.
|
||||
ShardCount uint64 // ShardCount is the number of shard chains in Ethereum 2.0.
|
||||
TargetCommitteeSize uint64 // TargetCommitteeSize is the number of validators in a committee when the chain is healthy.
|
||||
EjectionBalance uint64 // EjectionBalance is the minimal GWei a validator needs to have before ejected.
|
||||
MaxBalanceChurnQuotient uint64 // MaxBalanceChurnQuotient is used to determine how many validators can rotate per epoch.
|
||||
Gwei uint64 // Gwei is the denomination of Gwei in Ether.
|
||||
BeaconChainShardNumber uint64 // BeaconChainShardNumber is the shard number of the beacon chain.
|
||||
MaxCasperVotes uint64 // MaxCasperVotes is used to verify slashable Casper vote data.
|
||||
LatestBlockRootsLength uint64 // LatestBlockRootsLength is the number of block roots kept in the beacon state.
|
||||
LatestRandaoMixesLength uint64 // LatestRandaoMixesLength is the number of randao mixes kept in the beacon state.
|
||||
LatestPenalizedExitLength uint64 // LatestPenalizedExitLength is used to track penalized exit balances per time interval.
|
||||
MaxWithdrawalsPerEpoch uint64 // MaxWithdrawalsPerEpoch is the max withdrawals can happen for a single epoch.
|
||||
ShardCount uint64 // ShardCount is the number of shard chains in Ethereum 2.0.
|
||||
TargetCommitteeSize uint64 // TargetCommitteeSize is the number of validators in a committee when the chain is healthy.
|
||||
EjectionBalance uint64 // EjectionBalance is the minimal GWei a validator needs to have before ejected.
|
||||
MaxBalanceChurnQuotient uint64 // MaxBalanceChurnQuotient is used to determine how many validators can rotate per epoch.
|
||||
Gwei uint64 // Gwei is the denomination of Gwei in Ether.
|
||||
BeaconChainShardNumber uint64 // BeaconChainShardNumber is the shard number of the beacon chain.
|
||||
MaxIndicesPerSlashableVote uint64 // MaxIndicesPerSlashableVote is used to determine how many validators can be slashed per vote.
|
||||
LatestBlockRootsLength uint64 // LatestBlockRootsLength is the number of block roots kept in the beacon state.
|
||||
LatestRandaoMixesLength uint64 // LatestRandaoMixesLength is the number of randao mixes kept in the beacon state.
|
||||
LatestPenalizedExitLength uint64 // LatestPenalizedExitLength is used to track penalized exit balances per time interval.
|
||||
MaxWithdrawalsPerEpoch uint64 // MaxWithdrawalsPerEpoch is the max withdrawals can happen for a single epoch.
|
||||
|
||||
// Deposit contract constants.
|
||||
DepositContractAddress []byte // DepositContractAddress is the address of the deposit contract in PoW chain.
|
||||
@@ -64,7 +64,7 @@ type BeaconChainConfig struct {
|
||||
MaxDeposits uint64 // MaxExits determines the maximum number of validator deposits in a block.
|
||||
MaxAttestations uint64 // MaxAttestations defines the maximum allowed attestations in a beacon block.
|
||||
MaxProposerSlashings uint64 // MaxProposerSlashings defines the maximum number of slashings of proposers possible in a block.
|
||||
MaxCasperSlashings uint64 // MaxCasperSlashings defines the maximum number of casper FFG slashings possible in a block.
|
||||
MaxAttesterSlashings uint64 // MaxAttesterSlashings defines the maximum number of casper FFG slashings possible in a block.
|
||||
|
||||
// Prysm constants.
|
||||
DepositsForChainStart uint64 // DepositsForChainStart defines how many validator deposits needed to kick off beacon chain.
|
||||
@@ -90,16 +90,16 @@ type ShardChainConfig struct {
|
||||
|
||||
var defaultBeaconConfig = &BeaconChainConfig{
|
||||
// Misc constant.
|
||||
ShardCount: 1024,
|
||||
TargetCommitteeSize: 128,
|
||||
EjectionBalance: 16 * 1e9,
|
||||
MaxBalanceChurnQuotient: 32,
|
||||
BeaconChainShardNumber: 1<<64 - 1,
|
||||
MaxCasperVotes: 1024,
|
||||
LatestBlockRootsLength: 8192,
|
||||
LatestRandaoMixesLength: 8192,
|
||||
LatestPenalizedExitLength: 8192,
|
||||
MaxWithdrawalsPerEpoch: 4,
|
||||
ShardCount: 1024,
|
||||
TargetCommitteeSize: 128,
|
||||
EjectionBalance: 16 * 1e9,
|
||||
MaxBalanceChurnQuotient: 32,
|
||||
BeaconChainShardNumber: 1<<64 - 1,
|
||||
MaxIndicesPerSlashableVote: 1,
|
||||
LatestBlockRootsLength: 8192,
|
||||
LatestRandaoMixesLength: 8192,
|
||||
LatestPenalizedExitLength: 8192,
|
||||
MaxWithdrawalsPerEpoch: 4,
|
||||
|
||||
// Deposit contract constants.
|
||||
DepositContractTreeDepth: 32,
|
||||
@@ -133,7 +133,7 @@ var defaultBeaconConfig = &BeaconChainConfig{
|
||||
MaxDeposits: 16,
|
||||
MaxAttestations: 128,
|
||||
MaxProposerSlashings: 16,
|
||||
MaxCasperSlashings: 16,
|
||||
MaxAttesterSlashings: 1,
|
||||
|
||||
// Prysm constants.
|
||||
DepositsForChainStart: 16384,
|
||||
@@ -145,16 +145,16 @@ var defaultBeaconConfig = &BeaconChainConfig{
|
||||
|
||||
var demoBeaconConfig = &BeaconChainConfig{
|
||||
// Misc constant.
|
||||
ShardCount: 5,
|
||||
TargetCommitteeSize: 3,
|
||||
EjectionBalance: defaultBeaconConfig.EjectionBalance,
|
||||
MaxBalanceChurnQuotient: defaultBeaconConfig.MaxBalanceChurnQuotient,
|
||||
BeaconChainShardNumber: defaultBeaconConfig.BeaconChainShardNumber,
|
||||
MaxCasperVotes: defaultBeaconConfig.MaxCasperVotes,
|
||||
LatestBlockRootsLength: defaultBeaconConfig.LatestBlockRootsLength,
|
||||
LatestRandaoMixesLength: defaultBeaconConfig.LatestRandaoMixesLength,
|
||||
LatestPenalizedExitLength: defaultBeaconConfig.LatestPenalizedExitLength,
|
||||
MaxWithdrawalsPerEpoch: defaultBeaconConfig.MaxWithdrawalsPerEpoch,
|
||||
ShardCount: 5,
|
||||
TargetCommitteeSize: 3,
|
||||
EjectionBalance: defaultBeaconConfig.EjectionBalance,
|
||||
MaxBalanceChurnQuotient: defaultBeaconConfig.MaxBalanceChurnQuotient,
|
||||
BeaconChainShardNumber: defaultBeaconConfig.BeaconChainShardNumber,
|
||||
MaxIndicesPerSlashableVote: defaultBeaconConfig.MaxIndicesPerSlashableVote,
|
||||
LatestBlockRootsLength: defaultBeaconConfig.LatestBlockRootsLength,
|
||||
LatestRandaoMixesLength: defaultBeaconConfig.LatestRandaoMixesLength,
|
||||
LatestPenalizedExitLength: defaultBeaconConfig.LatestPenalizedExitLength,
|
||||
MaxWithdrawalsPerEpoch: defaultBeaconConfig.MaxWithdrawalsPerEpoch,
|
||||
|
||||
// Deposit contract constants.
|
||||
DepositContractTreeDepth: defaultBeaconConfig.DepositContractTreeDepth,
|
||||
@@ -188,7 +188,7 @@ var demoBeaconConfig = &BeaconChainConfig{
|
||||
MaxDeposits: defaultBeaconConfig.MaxDeposits,
|
||||
MaxAttestations: defaultBeaconConfig.MaxAttestations,
|
||||
MaxProposerSlashings: defaultBeaconConfig.MaxProposerSlashings,
|
||||
MaxCasperSlashings: defaultBeaconConfig.MaxCasperSlashings,
|
||||
MaxAttesterSlashings: defaultBeaconConfig.MaxAttesterSlashings,
|
||||
|
||||
// Prysm constants.
|
||||
DepositsForChainStart: defaultBeaconConfig.DepositsForChainStart,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package slices
|
||||
|
||||
// Intersection of two uint32 slices with time
|
||||
// Intersection of two uint64 slices with time
|
||||
// complexity of approximately O(n) leveraging a map to
|
||||
// check for element existence off by a constant factor
|
||||
// of underlying map efficiency.
|
||||
func Intersection(a []uint32, b []uint32) []uint32 {
|
||||
set := make([]uint32, 0)
|
||||
m := make(map[uint32]bool)
|
||||
func Intersection(a []uint64, b []uint64) []uint64 {
|
||||
set := make([]uint64, 0)
|
||||
m := make(map[uint64]bool)
|
||||
|
||||
for i := 0; i < len(a); i++ {
|
||||
m[a[i]] = true
|
||||
@@ -19,13 +19,13 @@ func Intersection(a []uint32, b []uint32) []uint32 {
|
||||
return set
|
||||
}
|
||||
|
||||
// Union of two uint32 slices with time
|
||||
// Union of two uint64 slices with time
|
||||
// complexity of approximately O(n) leveraging a map to
|
||||
// check for element existence off by a constant factor
|
||||
// of underlying map efficiency.
|
||||
func Union(a []uint32, b []uint32) []uint32 {
|
||||
set := make([]uint32, 0)
|
||||
m := make(map[uint32]bool)
|
||||
func Union(a []uint64, b []uint64) []uint64 {
|
||||
set := make([]uint64, 0)
|
||||
m := make(map[uint64]bool)
|
||||
|
||||
for i := 0; i < len(a); i++ {
|
||||
m[a[i]] = true
|
||||
@@ -39,13 +39,13 @@ func Union(a []uint32, b []uint32) []uint32 {
|
||||
return set
|
||||
}
|
||||
|
||||
// Not returns the uint32 in slice a that are
|
||||
// Not returns the uint64 in slice a that are
|
||||
// not in slice b with time complexity of approximately
|
||||
// O(n) leveraging a map to check for element existence
|
||||
// off by a constant factor of underlying map efficiency.
|
||||
func Not(a []uint32, b []uint32) []uint32 {
|
||||
set := make([]uint32, 0)
|
||||
m := make(map[uint32]bool)
|
||||
func Not(a []uint64, b []uint64) []uint64 {
|
||||
set := make([]uint64, 0)
|
||||
m := make(map[uint64]bool)
|
||||
|
||||
for i := 0; i < len(a); i++ {
|
||||
m[a[i]] = true
|
||||
@@ -59,7 +59,7 @@ func Not(a []uint32, b []uint32) []uint32 {
|
||||
}
|
||||
|
||||
// IsIn returns true if a is in b and False otherwise.
|
||||
func IsIn(a uint32, b []uint32) bool {
|
||||
func IsIn(a uint64, b []uint64) bool {
|
||||
for _, v := range b {
|
||||
if a == v {
|
||||
return true
|
||||
@@ -136,13 +136,13 @@ func IsInUint64(a uint64, b []uint64) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IntersectionInt32 of two int32 slices with time
|
||||
// Intersectionint64 of two int64 slices with time
|
||||
// complexity of approximately O(n) leveraging a map to
|
||||
// check for element existence off by a constant factor
|
||||
// of underlying map efficiency.
|
||||
func IntersectionInt32(a []int32, b []int32) []int32 {
|
||||
set := make([]int32, 0)
|
||||
m := make(map[int32]bool)
|
||||
func Intersectionint64(a []int64, b []int64) []int64 {
|
||||
set := make([]int64, 0)
|
||||
m := make(map[int64]bool)
|
||||
|
||||
for i := 0; i < len(a); i++ {
|
||||
m[a[i]] = true
|
||||
@@ -155,13 +155,13 @@ func IntersectionInt32(a []int32, b []int32) []int32 {
|
||||
return set
|
||||
}
|
||||
|
||||
// UnionInt32 of two int32 slices with time
|
||||
// Unionint64 of two int64 slices with time
|
||||
// complexity of approximately O(n) leveraging a map to
|
||||
// check for element existence off by a constant factor
|
||||
// of underlying map efficiency.
|
||||
func UnionInt32(a []int32, b []int32) []int32 {
|
||||
set := make([]int32, 0)
|
||||
m := make(map[int32]bool)
|
||||
func Unionint64(a []int64, b []int64) []int64 {
|
||||
set := make([]int64, 0)
|
||||
m := make(map[int64]bool)
|
||||
|
||||
for i := 0; i < len(a); i++ {
|
||||
m[a[i]] = true
|
||||
@@ -175,13 +175,13 @@ func UnionInt32(a []int32, b []int32) []int32 {
|
||||
return set
|
||||
}
|
||||
|
||||
// NotInt32 returns the int32 in slice a that are
|
||||
// Notint64 returns the int64 in slice a that are
|
||||
// not in slice b with time complexity of approximately
|
||||
// O(n) leveraging a map to check for element existence
|
||||
// off by a constant factor of underlying map efficiency.
|
||||
func NotInt32(a []int32, b []int32) []int32 {
|
||||
set := make([]int32, 0)
|
||||
m := make(map[int32]bool)
|
||||
func Notint64(a []int64, b []int64) []int64 {
|
||||
set := make([]int64, 0)
|
||||
m := make(map[int64]bool)
|
||||
|
||||
for i := 0; i < len(a); i++ {
|
||||
m[a[i]] = true
|
||||
@@ -194,8 +194,8 @@ func NotInt32(a []int32, b []int32) []int32 {
|
||||
return set
|
||||
}
|
||||
|
||||
// IsInInt32 returns true if a is in b and False otherwise.
|
||||
func IsInInt32(a int32, b []int32) bool {
|
||||
// IsInint64 returns true if a is in b and False otherwise.
|
||||
func IsInint64(a int64, b []int64) bool {
|
||||
for _, v := range b {
|
||||
if a == v {
|
||||
return true
|
||||
|
||||
@@ -10,18 +10,18 @@ import (
|
||||
|
||||
func TestGenericIntersection(t *testing.T) {
|
||||
testCases := []struct {
|
||||
setA []uint32
|
||||
setB []uint32
|
||||
out []uint32
|
||||
setA []uint64
|
||||
setB []uint64
|
||||
out []uint64
|
||||
}{
|
||||
{[]uint32{2, 3, 5}, []uint32{3}, []uint32{3}},
|
||||
{[]uint32{2, 3, 5}, []uint32{3, 5}, []uint32{3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{5, 3, 2}, []uint32{5, 3, 2}},
|
||||
{[]uint32{2, 3, 5}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{}, []uint32{}},
|
||||
{[]uint32{}, []uint32{2, 3, 5}, []uint32{}},
|
||||
{[]uint32{}, []uint32{}, []uint32{}},
|
||||
{[]uint32{1}, []uint32{1}, []uint32{1}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3}, []uint64{3}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3, 5}, []uint64{3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{5, 3, 2}, []uint64{5, 3, 2}},
|
||||
{[]uint64{2, 3, 5}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{}, []uint64{}},
|
||||
{[]uint64{}, []uint64{2, 3, 5}, []uint64{}},
|
||||
{[]uint64{}, []uint64{}, []uint64{}},
|
||||
{[]uint64{1}, []uint64{1}, []uint64{1}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
result, err := GenericIntersection(tt.setA, tt.setB)
|
||||
@@ -37,18 +37,18 @@ func TestGenericIntersection(t *testing.T) {
|
||||
|
||||
func TestGenericIntersectionWithSSZ(t *testing.T) {
|
||||
testCases := []struct {
|
||||
setA []uint32
|
||||
setB []uint32
|
||||
out []uint32
|
||||
setA []uint64
|
||||
setB []uint64
|
||||
out []uint64
|
||||
}{
|
||||
{[]uint32{2, 3, 5}, []uint32{3}, []uint32{3}},
|
||||
{[]uint32{2, 3, 5}, []uint32{3, 5}, []uint32{3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{5, 3, 2}, []uint32{5, 3, 2}},
|
||||
{[]uint32{2, 3, 5}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{}, []uint32{}},
|
||||
{[]uint32{}, []uint32{2, 3, 5}, []uint32{}},
|
||||
{[]uint32{}, []uint32{}, []uint32{}},
|
||||
{[]uint32{1}, []uint32{1}, []uint32{1}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3}, []uint64{3}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3, 5}, []uint64{3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{5, 3, 2}, []uint64{5, 3, 2}},
|
||||
{[]uint64{2, 3, 5}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{}, []uint64{}},
|
||||
{[]uint64{}, []uint64{2, 3, 5}, []uint64{}},
|
||||
{[]uint64{}, []uint64{}, []uint64{}},
|
||||
{[]uint64{1}, []uint64{1}, []uint64{1}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
b1 := new(bytes.Buffer)
|
||||
@@ -150,17 +150,17 @@ func TestIntGenericIntersection(t *testing.T) {
|
||||
|
||||
func TestGenericNot(t *testing.T) {
|
||||
testCases := []struct {
|
||||
setA []uint32
|
||||
setB []uint32
|
||||
out []uint32
|
||||
setA []uint64
|
||||
setB []uint64
|
||||
out []uint64
|
||||
}{
|
||||
{[]uint32{4, 6}, []uint32{2, 3, 5, 4, 6}, []uint32{2, 3, 5}},
|
||||
{[]uint32{3, 5}, []uint32{2, 3, 5}, []uint32{2}},
|
||||
{[]uint32{2, 3, 5}, []uint32{2, 3, 5}, []uint32{}},
|
||||
{[]uint32{2}, []uint32{2, 3, 5}, []uint32{3, 5}},
|
||||
{[]uint32{}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{}, []uint32{}, []uint32{}},
|
||||
{[]uint32{1}, []uint32{1}, []uint32{}},
|
||||
{[]uint64{4, 6}, []uint64{2, 3, 5, 4, 6}, []uint64{2, 3, 5}},
|
||||
{[]uint64{3, 5}, []uint64{2, 3, 5}, []uint64{2}},
|
||||
{[]uint64{2, 3, 5}, []uint64{2, 3, 5}, []uint64{}},
|
||||
{[]uint64{2}, []uint64{2, 3, 5}, []uint64{3, 5}},
|
||||
{[]uint64{}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{}, []uint64{}, []uint64{}},
|
||||
{[]uint64{1}, []uint64{1}, []uint64{}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
result, err := GenericNot(tt.setA, tt.setB)
|
||||
@@ -249,17 +249,17 @@ func TestIntGenericNot(t *testing.T) {
|
||||
|
||||
func TestGenericUnion(t *testing.T) {
|
||||
testCases := []struct {
|
||||
setA []uint32
|
||||
setB []uint32
|
||||
out []uint32
|
||||
setA []uint64
|
||||
setB []uint64
|
||||
out []uint64
|
||||
}{
|
||||
{[]uint32{2, 3, 5}, []uint32{4, 6}, []uint32{2, 3, 5, 4, 6}},
|
||||
{[]uint32{2, 3, 5}, []uint32{3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{}, []uint32{2, 3, 5}},
|
||||
{[]uint32{}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{}, []uint32{}, []uint32{}},
|
||||
{[]uint32{1}, []uint32{1}, []uint32{1}},
|
||||
{[]uint64{2, 3, 5}, []uint64{4, 6}, []uint64{2, 3, 5, 4, 6}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{}, []uint64{2, 3, 5}},
|
||||
{[]uint64{}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{}, []uint64{}, []uint64{}},
|
||||
{[]uint64{1}, []uint64{1}, []uint64{1}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
result, err := GenericUnion(tt.setA, tt.setB)
|
||||
@@ -301,14 +301,14 @@ func TestFloatGenericUnion(t *testing.T) {
|
||||
|
||||
func TestGenericIsIn(t *testing.T) {
|
||||
testCases := []struct {
|
||||
a uint32
|
||||
b []uint32
|
||||
a uint64
|
||||
b []uint64
|
||||
result bool
|
||||
}{
|
||||
{0, []uint32{}, false},
|
||||
{0, []uint32{0}, true},
|
||||
{4, []uint32{2, 3, 5, 4, 6}, true},
|
||||
{100, []uint32{2, 3, 5, 4, 6}, false},
|
||||
{0, []uint64{}, false},
|
||||
{0, []uint64{0}, true},
|
||||
{4, []uint64{2, 3, 5, 4, 6}, true},
|
||||
{100, []uint64{2, 3, 5, 4, 6}, false},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
result := GenericIsIn(tt.a, tt.b)
|
||||
@@ -322,18 +322,18 @@ func TestGenericIsIn(t *testing.T) {
|
||||
func BenchmarkGenericIntersection(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
testCases := []struct {
|
||||
setA []uint32
|
||||
setB []uint32
|
||||
out []uint32
|
||||
setA []uint64
|
||||
setB []uint64
|
||||
out []uint64
|
||||
}{
|
||||
{[]uint32{2, 3, 5}, []uint32{3}, []uint32{3}},
|
||||
{[]uint32{2, 3, 5}, []uint32{3, 5}, []uint32{3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{5, 3, 2}, []uint32{5, 3, 2}},
|
||||
{[]uint32{2, 3, 5}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{}, []uint32{}},
|
||||
{[]uint32{}, []uint32{2, 3, 5}, []uint32{}},
|
||||
{[]uint32{}, []uint32{}, []uint32{}},
|
||||
{[]uint32{1}, []uint32{1}, []uint32{1}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3}, []uint64{3}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3, 5}, []uint64{3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{5, 3, 2}, []uint64{5, 3, 2}},
|
||||
{[]uint64{2, 3, 5}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{}, []uint64{}},
|
||||
{[]uint64{}, []uint64{2, 3, 5}, []uint64{}},
|
||||
{[]uint64{}, []uint64{}, []uint64{}},
|
||||
{[]uint64{1}, []uint64{1}, []uint64{1}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
res, err := GenericIntersection(tt.setA, tt.setB)
|
||||
@@ -349,18 +349,18 @@ func BenchmarkGenericIntersection(b *testing.B) {
|
||||
func BenchmarkIntersection(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
testCases := []struct {
|
||||
setA []uint32
|
||||
setB []uint32
|
||||
out []uint32
|
||||
setA []uint64
|
||||
setB []uint64
|
||||
out []uint64
|
||||
}{
|
||||
{[]uint32{2, 3, 5}, []uint32{3}, []uint32{3}},
|
||||
{[]uint32{2, 3, 5}, []uint32{3, 5}, []uint32{3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{5, 3, 2}, []uint32{5, 3, 2}},
|
||||
{[]uint32{2, 3, 5}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{}, []uint32{}},
|
||||
{[]uint32{}, []uint32{2, 3, 5}, []uint32{}},
|
||||
{[]uint32{}, []uint32{}, []uint32{}},
|
||||
{[]uint32{1}, []uint32{1}, []uint32{1}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3}, []uint64{3}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3, 5}, []uint64{3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{5, 3, 2}, []uint64{5, 3, 2}},
|
||||
{[]uint64{2, 3, 5}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{}, []uint64{}},
|
||||
{[]uint64{}, []uint64{2, 3, 5}, []uint64{}},
|
||||
{[]uint64{}, []uint64{}, []uint64{}},
|
||||
{[]uint64{1}, []uint64{1}, []uint64{1}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
Intersection(tt.setA, tt.setB)
|
||||
@@ -372,18 +372,18 @@ func BenchmarkIntersection(b *testing.B) {
|
||||
func BenchmarkUnion(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
testCases := []struct {
|
||||
setA []uint32
|
||||
setB []uint32
|
||||
out []uint32
|
||||
setA []uint64
|
||||
setB []uint64
|
||||
out []uint64
|
||||
}{
|
||||
{[]uint32{2, 3, 5}, []uint32{3}, []uint32{3}},
|
||||
{[]uint32{2, 3, 5}, []uint32{3, 5}, []uint32{3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{5, 3, 2}, []uint32{5, 3, 2}},
|
||||
{[]uint32{2, 3, 5}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{}, []uint32{}},
|
||||
{[]uint32{}, []uint32{2, 3, 5}, []uint32{}},
|
||||
{[]uint32{}, []uint32{}, []uint32{}},
|
||||
{[]uint32{1}, []uint32{1}, []uint32{1}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3}, []uint64{3}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3, 5}, []uint64{3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{5, 3, 2}, []uint64{5, 3, 2}},
|
||||
{[]uint64{2, 3, 5}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{}, []uint64{}},
|
||||
{[]uint64{}, []uint64{2, 3, 5}, []uint64{}},
|
||||
{[]uint64{}, []uint64{}, []uint64{}},
|
||||
{[]uint64{1}, []uint64{1}, []uint64{1}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
Union(tt.setA, tt.setB)
|
||||
@@ -396,18 +396,18 @@ func BenchmarkUnion(b *testing.B) {
|
||||
func BenchmarkGenericUnion(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
testCases := []struct {
|
||||
setA []uint32
|
||||
setB []uint32
|
||||
out []uint32
|
||||
setA []uint64
|
||||
setB []uint64
|
||||
out []uint64
|
||||
}{
|
||||
{[]uint32{2, 3, 5}, []uint32{3}, []uint32{3}},
|
||||
{[]uint32{2, 3, 5}, []uint32{3, 5}, []uint32{3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{5, 3, 2}, []uint32{5, 3, 2}},
|
||||
{[]uint32{2, 3, 5}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{}, []uint32{}},
|
||||
{[]uint32{}, []uint32{2, 3, 5}, []uint32{}},
|
||||
{[]uint32{}, []uint32{}, []uint32{}},
|
||||
{[]uint32{1}, []uint32{1}, []uint32{1}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3}, []uint64{3}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3, 5}, []uint64{3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{5, 3, 2}, []uint64{5, 3, 2}},
|
||||
{[]uint64{2, 3, 5}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{}, []uint64{}},
|
||||
{[]uint64{}, []uint64{2, 3, 5}, []uint64{}},
|
||||
{[]uint64{}, []uint64{}, []uint64{}},
|
||||
{[]uint64{1}, []uint64{1}, []uint64{1}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
res, err := GenericUnion(tt.setA, tt.setB)
|
||||
@@ -422,18 +422,18 @@ func BenchmarkGenericUnion(b *testing.B) {
|
||||
func BenchmarkNot(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
testCases := []struct {
|
||||
setA []uint32
|
||||
setB []uint32
|
||||
out []uint32
|
||||
setA []uint64
|
||||
setB []uint64
|
||||
out []uint64
|
||||
}{
|
||||
{[]uint32{2, 3, 5}, []uint32{3}, []uint32{3}},
|
||||
{[]uint32{2, 3, 5}, []uint32{3, 5}, []uint32{3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{5, 3, 2}, []uint32{5, 3, 2}},
|
||||
{[]uint32{2, 3, 5}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{}, []uint32{}},
|
||||
{[]uint32{}, []uint32{2, 3, 5}, []uint32{}},
|
||||
{[]uint32{}, []uint32{}, []uint32{}},
|
||||
{[]uint32{1}, []uint32{1}, []uint32{1}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3}, []uint64{3}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3, 5}, []uint64{3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{5, 3, 2}, []uint64{5, 3, 2}},
|
||||
{[]uint64{2, 3, 5}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{}, []uint64{}},
|
||||
{[]uint64{}, []uint64{2, 3, 5}, []uint64{}},
|
||||
{[]uint64{}, []uint64{}, []uint64{}},
|
||||
{[]uint64{1}, []uint64{1}, []uint64{1}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
Not(tt.setA, tt.setB)
|
||||
@@ -446,18 +446,18 @@ func BenchmarkNot(b *testing.B) {
|
||||
func BenchmarkGenericNot(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
testCases := []struct {
|
||||
setA []uint32
|
||||
setB []uint32
|
||||
out []uint32
|
||||
setA []uint64
|
||||
setB []uint64
|
||||
out []uint64
|
||||
}{
|
||||
{[]uint32{2, 3, 5}, []uint32{3}, []uint32{3}},
|
||||
{[]uint32{2, 3, 5}, []uint32{3, 5}, []uint32{3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{5, 3, 2}, []uint32{5, 3, 2}},
|
||||
{[]uint32{2, 3, 5}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{}, []uint32{}},
|
||||
{[]uint32{}, []uint32{2, 3, 5}, []uint32{}},
|
||||
{[]uint32{}, []uint32{}, []uint32{}},
|
||||
{[]uint32{1}, []uint32{1}, []uint32{1}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3}, []uint64{3}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3, 5}, []uint64{3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{5, 3, 2}, []uint64{5, 3, 2}},
|
||||
{[]uint64{2, 3, 5}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{}, []uint64{}},
|
||||
{[]uint64{}, []uint64{2, 3, 5}, []uint64{}},
|
||||
{[]uint64{}, []uint64{}, []uint64{}},
|
||||
{[]uint64{1}, []uint64{1}, []uint64{1}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
res, err := GenericNot(tt.setA, tt.setB)
|
||||
@@ -473,14 +473,14 @@ func BenchmarkGenericNot(b *testing.B) {
|
||||
func BenchmarkIsIn(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
testCases := []struct {
|
||||
a uint32
|
||||
b []uint32
|
||||
a uint64
|
||||
b []uint64
|
||||
result bool
|
||||
}{
|
||||
{0, []uint32{}, false},
|
||||
{0, []uint32{0}, true},
|
||||
{4, []uint32{2, 3, 5, 4, 6}, true},
|
||||
{100, []uint32{2, 3, 5, 4, 6}, false},
|
||||
{0, []uint64{}, false},
|
||||
{0, []uint64{0}, true},
|
||||
{4, []uint64{2, 3, 5, 4, 6}, true},
|
||||
{100, []uint64{2, 3, 5, 4, 6}, false},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
IsIn(tt.a, tt.b)
|
||||
@@ -493,14 +493,14 @@ func BenchmarkIsIn(b *testing.B) {
|
||||
func BenchmarkGenericIsIn(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
testCases := []struct {
|
||||
a uint32
|
||||
b []uint32
|
||||
a uint64
|
||||
b []uint64
|
||||
result bool
|
||||
}{
|
||||
{0, []uint32{}, false},
|
||||
{0, []uint32{0}, true},
|
||||
{4, []uint32{2, 3, 5, 4, 6}, true},
|
||||
{100, []uint32{2, 3, 5, 4, 6}, false},
|
||||
{0, []uint64{}, false},
|
||||
{0, []uint64{0}, true},
|
||||
{4, []uint64{2, 3, 5, 4, 6}, true},
|
||||
{100, []uint64{2, 3, 5, 4, 6}, false},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
GenericIsIn(tt.a, tt.b)
|
||||
@@ -513,18 +513,18 @@ func BenchmarkGenericIsIn(b *testing.B) {
|
||||
func BenchmarkGenericIntersectionWithSSZ(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
testCases := []struct {
|
||||
setA []uint32
|
||||
setB []uint32
|
||||
out []uint32
|
||||
setA []uint64
|
||||
setB []uint64
|
||||
out []uint64
|
||||
}{
|
||||
{[]uint32{2, 3, 5}, []uint32{3}, []uint32{3}},
|
||||
{[]uint32{2, 3, 5}, []uint32{3, 5}, []uint32{3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{5, 3, 2}, []uint32{5, 3, 2}},
|
||||
{[]uint32{2, 3, 5}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{}, []uint32{}},
|
||||
{[]uint32{}, []uint32{2, 3, 5}, []uint32{}},
|
||||
{[]uint32{}, []uint32{}, []uint32{}},
|
||||
{[]uint32{1}, []uint32{1}, []uint32{1}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3}, []uint64{3}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3, 5}, []uint64{3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{5, 3, 2}, []uint64{5, 3, 2}},
|
||||
{[]uint64{2, 3, 5}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{}, []uint64{}},
|
||||
{[]uint64{}, []uint64{2, 3, 5}, []uint64{}},
|
||||
{[]uint64{}, []uint64{}, []uint64{}},
|
||||
{[]uint64{1}, []uint64{1}, []uint64{1}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
b1 := new(bytes.Buffer)
|
||||
@@ -547,18 +547,18 @@ func BenchmarkGenericIntersectionWithSSZ(b *testing.B) {
|
||||
func BenchmarkIntersectionWithSSZ(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
testCases := []struct {
|
||||
setA []uint32
|
||||
setB []uint32
|
||||
out []uint32
|
||||
setA []uint64
|
||||
setB []uint64
|
||||
out []uint64
|
||||
}{
|
||||
{[]uint32{2, 3, 5}, []uint32{3}, []uint32{3}},
|
||||
{[]uint32{2, 3, 5}, []uint32{3, 5}, []uint32{3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{5, 3, 2}, []uint32{5, 3, 2}},
|
||||
{[]uint32{2, 3, 5}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{}, []uint32{}},
|
||||
{[]uint32{}, []uint32{2, 3, 5}, []uint32{}},
|
||||
{[]uint32{}, []uint32{}, []uint32{}},
|
||||
{[]uint32{1}, []uint32{1}, []uint32{1}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3}, []uint64{3}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3, 5}, []uint64{3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{5, 3, 2}, []uint64{5, 3, 2}},
|
||||
{[]uint64{2, 3, 5}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{}, []uint64{}},
|
||||
{[]uint64{}, []uint64{2, 3, 5}, []uint64{}},
|
||||
{[]uint64{}, []uint64{}, []uint64{}},
|
||||
{[]uint64{1}, []uint64{1}, []uint64{1}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
b1 := new(bytes.Buffer)
|
||||
@@ -579,18 +579,18 @@ func BenchmarkIntersectionWithSSZ(b *testing.B) {
|
||||
func BenchmarkGenericUnionWithSSZ(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
testCases := []struct {
|
||||
setA []uint32
|
||||
setB []uint32
|
||||
out []uint32
|
||||
setA []uint64
|
||||
setB []uint64
|
||||
out []uint64
|
||||
}{
|
||||
{[]uint32{2, 3, 5}, []uint32{3}, []uint32{3}},
|
||||
{[]uint32{2, 3, 5}, []uint32{3, 5}, []uint32{3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{5, 3, 2}, []uint32{5, 3, 2}},
|
||||
{[]uint32{2, 3, 5}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{}, []uint32{}},
|
||||
{[]uint32{}, []uint32{2, 3, 5}, []uint32{}},
|
||||
{[]uint32{}, []uint32{}, []uint32{}},
|
||||
{[]uint32{1}, []uint32{1}, []uint32{1}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3}, []uint64{3}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3, 5}, []uint64{3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{5, 3, 2}, []uint64{5, 3, 2}},
|
||||
{[]uint64{2, 3, 5}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{}, []uint64{}},
|
||||
{[]uint64{}, []uint64{2, 3, 5}, []uint64{}},
|
||||
{[]uint64{}, []uint64{}, []uint64{}},
|
||||
{[]uint64{1}, []uint64{1}, []uint64{1}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
b1 := new(bytes.Buffer)
|
||||
@@ -613,18 +613,18 @@ func BenchmarkGenericUnionWithSSZ(b *testing.B) {
|
||||
func BenchmarkUnionWithSSZ(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
testCases := []struct {
|
||||
setA []uint32
|
||||
setB []uint32
|
||||
out []uint32
|
||||
setA []uint64
|
||||
setB []uint64
|
||||
out []uint64
|
||||
}{
|
||||
{[]uint32{2, 3, 5}, []uint32{3}, []uint32{3}},
|
||||
{[]uint32{2, 3, 5}, []uint32{3, 5}, []uint32{3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{5, 3, 2}, []uint32{5, 3, 2}},
|
||||
{[]uint32{2, 3, 5}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{}, []uint32{}},
|
||||
{[]uint32{}, []uint32{2, 3, 5}, []uint32{}},
|
||||
{[]uint32{}, []uint32{}, []uint32{}},
|
||||
{[]uint32{1}, []uint32{1}, []uint32{1}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3}, []uint64{3}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3, 5}, []uint64{3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{5, 3, 2}, []uint64{5, 3, 2}},
|
||||
{[]uint64{2, 3, 5}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{}, []uint64{}},
|
||||
{[]uint64{}, []uint64{2, 3, 5}, []uint64{}},
|
||||
{[]uint64{}, []uint64{}, []uint64{}},
|
||||
{[]uint64{1}, []uint64{1}, []uint64{1}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
b1 := new(bytes.Buffer)
|
||||
@@ -645,18 +645,18 @@ func BenchmarkUnionWithSSZ(b *testing.B) {
|
||||
func BenchmarkGenericNotWithSSZ(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
testCases := []struct {
|
||||
setA []uint32
|
||||
setB []uint32
|
||||
out []uint32
|
||||
setA []uint64
|
||||
setB []uint64
|
||||
out []uint64
|
||||
}{
|
||||
{[]uint32{2, 3, 5}, []uint32{3}, []uint32{3}},
|
||||
{[]uint32{2, 3, 5}, []uint32{3, 5}, []uint32{3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{5, 3, 2}, []uint32{5, 3, 2}},
|
||||
{[]uint32{2, 3, 5}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{}, []uint32{}},
|
||||
{[]uint32{}, []uint32{2, 3, 5}, []uint32{}},
|
||||
{[]uint32{}, []uint32{}, []uint32{}},
|
||||
{[]uint32{1}, []uint32{1}, []uint32{1}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3}, []uint64{3}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3, 5}, []uint64{3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{5, 3, 2}, []uint64{5, 3, 2}},
|
||||
{[]uint64{2, 3, 5}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{}, []uint64{}},
|
||||
{[]uint64{}, []uint64{2, 3, 5}, []uint64{}},
|
||||
{[]uint64{}, []uint64{}, []uint64{}},
|
||||
{[]uint64{1}, []uint64{1}, []uint64{1}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
b1 := new(bytes.Buffer)
|
||||
@@ -679,18 +679,18 @@ func BenchmarkGenericNotWithSSZ(b *testing.B) {
|
||||
func BenchmarkNotWithSSZ(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
testCases := []struct {
|
||||
setA []uint32
|
||||
setB []uint32
|
||||
out []uint32
|
||||
setA []uint64
|
||||
setB []uint64
|
||||
out []uint64
|
||||
}{
|
||||
{[]uint32{2, 3, 5}, []uint32{3}, []uint32{3}},
|
||||
{[]uint32{2, 3, 5}, []uint32{3, 5}, []uint32{3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{5, 3, 2}, []uint32{5, 3, 2}},
|
||||
{[]uint32{2, 3, 5}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{}, []uint32{}},
|
||||
{[]uint32{}, []uint32{2, 3, 5}, []uint32{}},
|
||||
{[]uint32{}, []uint32{}, []uint32{}},
|
||||
{[]uint32{1}, []uint32{1}, []uint32{1}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3}, []uint64{3}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3, 5}, []uint64{3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{5, 3, 2}, []uint64{5, 3, 2}},
|
||||
{[]uint64{2, 3, 5}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{}, []uint64{}},
|
||||
{[]uint64{}, []uint64{2, 3, 5}, []uint64{}},
|
||||
{[]uint64{}, []uint64{}, []uint64{}},
|
||||
{[]uint64{1}, []uint64{1}, []uint64{1}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
b1 := new(bytes.Buffer)
|
||||
|
||||
@@ -7,18 +7,18 @@ import (
|
||||
|
||||
func TestIntersection(t *testing.T) {
|
||||
testCases := []struct {
|
||||
setA []uint32
|
||||
setB []uint32
|
||||
out []uint32
|
||||
setA []uint64
|
||||
setB []uint64
|
||||
out []uint64
|
||||
}{
|
||||
{[]uint32{2, 3, 5}, []uint32{3}, []uint32{3}},
|
||||
{[]uint32{2, 3, 5}, []uint32{3, 5}, []uint32{3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{5, 3, 2}, []uint32{5, 3, 2}},
|
||||
{[]uint32{2, 3, 5}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{}, []uint32{}},
|
||||
{[]uint32{}, []uint32{2, 3, 5}, []uint32{}},
|
||||
{[]uint32{}, []uint32{}, []uint32{}},
|
||||
{[]uint32{1}, []uint32{1}, []uint32{1}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3}, []uint64{3}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3, 5}, []uint64{3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{5, 3, 2}, []uint64{5, 3, 2}},
|
||||
{[]uint64{2, 3, 5}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{}, []uint64{}},
|
||||
{[]uint64{}, []uint64{2, 3, 5}, []uint64{}},
|
||||
{[]uint64{}, []uint64{}, []uint64{}},
|
||||
{[]uint64{1}, []uint64{1}, []uint64{1}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
result := Intersection(tt.setA, tt.setB)
|
||||
@@ -30,17 +30,17 @@ func TestIntersection(t *testing.T) {
|
||||
|
||||
func TestUnion(t *testing.T) {
|
||||
testCases := []struct {
|
||||
setA []uint32
|
||||
setB []uint32
|
||||
out []uint32
|
||||
setA []uint64
|
||||
setB []uint64
|
||||
out []uint64
|
||||
}{
|
||||
{[]uint32{2, 3, 5}, []uint32{4, 6}, []uint32{2, 3, 5, 4, 6}},
|
||||
{[]uint32{2, 3, 5}, []uint32{3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{2, 3, 5}, []uint32{}, []uint32{2, 3, 5}},
|
||||
{[]uint32{}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{}, []uint32{}, []uint32{}},
|
||||
{[]uint32{1}, []uint32{1}, []uint32{1}},
|
||||
{[]uint64{2, 3, 5}, []uint64{4, 6}, []uint64{2, 3, 5, 4, 6}},
|
||||
{[]uint64{2, 3, 5}, []uint64{3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{2, 3, 5}, []uint64{}, []uint64{2, 3, 5}},
|
||||
{[]uint64{}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{}, []uint64{}, []uint64{}},
|
||||
{[]uint64{1}, []uint64{1}, []uint64{1}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
result := Union(tt.setA, tt.setB)
|
||||
@@ -52,17 +52,17 @@ func TestUnion(t *testing.T) {
|
||||
|
||||
func TestNot(t *testing.T) {
|
||||
testCases := []struct {
|
||||
setA []uint32
|
||||
setB []uint32
|
||||
out []uint32
|
||||
setA []uint64
|
||||
setB []uint64
|
||||
out []uint64
|
||||
}{
|
||||
{[]uint32{4, 6}, []uint32{2, 3, 5, 4, 6}, []uint32{2, 3, 5}},
|
||||
{[]uint32{3, 5}, []uint32{2, 3, 5}, []uint32{2}},
|
||||
{[]uint32{2, 3, 5}, []uint32{2, 3, 5}, []uint32{}},
|
||||
{[]uint32{2}, []uint32{2, 3, 5}, []uint32{3, 5}},
|
||||
{[]uint32{}, []uint32{2, 3, 5}, []uint32{2, 3, 5}},
|
||||
{[]uint32{}, []uint32{}, []uint32{}},
|
||||
{[]uint32{1}, []uint32{1}, []uint32{}},
|
||||
{[]uint64{4, 6}, []uint64{2, 3, 5, 4, 6}, []uint64{2, 3, 5}},
|
||||
{[]uint64{3, 5}, []uint64{2, 3, 5}, []uint64{2}},
|
||||
{[]uint64{2, 3, 5}, []uint64{2, 3, 5}, []uint64{}},
|
||||
{[]uint64{2}, []uint64{2, 3, 5}, []uint64{3, 5}},
|
||||
{[]uint64{}, []uint64{2, 3, 5}, []uint64{2, 3, 5}},
|
||||
{[]uint64{}, []uint64{}, []uint64{}},
|
||||
{[]uint64{1}, []uint64{1}, []uint64{}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
result := Not(tt.setA, tt.setB)
|
||||
@@ -74,14 +74,14 @@ func TestNot(t *testing.T) {
|
||||
|
||||
func TestIsIn(t *testing.T) {
|
||||
testCases := []struct {
|
||||
a uint32
|
||||
b []uint32
|
||||
a uint64
|
||||
b []uint64
|
||||
result bool
|
||||
}{
|
||||
{0, []uint32{}, false},
|
||||
{0, []uint32{0}, true},
|
||||
{4, []uint32{2, 3, 5, 4, 6}, true},
|
||||
{100, []uint32{2, 3, 5, 4, 6}, false},
|
||||
{0, []uint64{}, false},
|
||||
{0, []uint64{0}, true},
|
||||
{4, []uint64{2, 3, 5, 4, 6}, true},
|
||||
{100, []uint64{2, 3, 5, 4, 6}, false},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
result := IsIn(tt.a, tt.b)
|
||||
@@ -116,23 +116,23 @@ func TestIntersectionUint64(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntersectionInt32(t *testing.T) {
|
||||
func TestIntersectionint64(t *testing.T) {
|
||||
testCases := []struct {
|
||||
setA []int32
|
||||
setB []int32
|
||||
out []int32
|
||||
setA []int64
|
||||
setB []int64
|
||||
out []int64
|
||||
}{
|
||||
{[]int32{2, 3, 5}, []int32{3}, []int32{3}},
|
||||
{[]int32{2, 3, 5}, []int32{3, 5}, []int32{3, 5}},
|
||||
{[]int32{2, 3, 5}, []int32{5, 3, 2}, []int32{5, 3, 2}},
|
||||
{[]int32{2, 3, 5}, []int32{2, 3, 5}, []int32{2, 3, 5}},
|
||||
{[]int32{2, 3, 5}, []int32{}, []int32{}},
|
||||
{[]int32{}, []int32{2, 3, 5}, []int32{}},
|
||||
{[]int32{}, []int32{}, []int32{}},
|
||||
{[]int32{1}, []int32{1}, []int32{1}},
|
||||
{[]int64{2, 3, 5}, []int64{3}, []int64{3}},
|
||||
{[]int64{2, 3, 5}, []int64{3, 5}, []int64{3, 5}},
|
||||
{[]int64{2, 3, 5}, []int64{5, 3, 2}, []int64{5, 3, 2}},
|
||||
{[]int64{2, 3, 5}, []int64{2, 3, 5}, []int64{2, 3, 5}},
|
||||
{[]int64{2, 3, 5}, []int64{}, []int64{}},
|
||||
{[]int64{}, []int64{2, 3, 5}, []int64{}},
|
||||
{[]int64{}, []int64{}, []int64{}},
|
||||
{[]int64{1}, []int64{1}, []int64{1}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
result := IntersectionInt32(tt.setA, tt.setB)
|
||||
result := Intersectionint64(tt.setA, tt.setB)
|
||||
if !reflect.DeepEqual(result, tt.out) {
|
||||
t.Errorf("got %d, want %d", result, tt.out)
|
||||
}
|
||||
@@ -189,22 +189,22 @@ func TestUnionUint64(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnionInt32(t *testing.T) {
|
||||
func TestUnionint64(t *testing.T) {
|
||||
testCases := []struct {
|
||||
setA []int32
|
||||
setB []int32
|
||||
out []int32
|
||||
setA []int64
|
||||
setB []int64
|
||||
out []int64
|
||||
}{
|
||||
{[]int32{2, 3, 5}, []int32{4, 6}, []int32{2, 3, 5, 4, 6}},
|
||||
{[]int32{2, 3, 5}, []int32{3, 5}, []int32{2, 3, 5}},
|
||||
{[]int32{2, 3, 5}, []int32{2, 3, 5}, []int32{2, 3, 5}},
|
||||
{[]int32{2, 3, 5}, []int32{}, []int32{2, 3, 5}},
|
||||
{[]int32{}, []int32{2, 3, 5}, []int32{2, 3, 5}},
|
||||
{[]int32{}, []int32{}, []int32{}},
|
||||
{[]int32{1}, []int32{1}, []int32{1}},
|
||||
{[]int64{2, 3, 5}, []int64{4, 6}, []int64{2, 3, 5, 4, 6}},
|
||||
{[]int64{2, 3, 5}, []int64{3, 5}, []int64{2, 3, 5}},
|
||||
{[]int64{2, 3, 5}, []int64{2, 3, 5}, []int64{2, 3, 5}},
|
||||
{[]int64{2, 3, 5}, []int64{}, []int64{2, 3, 5}},
|
||||
{[]int64{}, []int64{2, 3, 5}, []int64{2, 3, 5}},
|
||||
{[]int64{}, []int64{}, []int64{}},
|
||||
{[]int64{1}, []int64{1}, []int64{1}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
result := UnionInt32(tt.setA, tt.setB)
|
||||
result := Unionint64(tt.setA, tt.setB)
|
||||
if !reflect.DeepEqual(result, tt.out) {
|
||||
t.Errorf("got %d, want %d", result, tt.out)
|
||||
}
|
||||
@@ -280,22 +280,22 @@ func TestNotInt64(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotInt32(t *testing.T) {
|
||||
func TestNotint64(t *testing.T) {
|
||||
testCases := []struct {
|
||||
setA []int32
|
||||
setB []int32
|
||||
out []int32
|
||||
setA []int64
|
||||
setB []int64
|
||||
out []int64
|
||||
}{
|
||||
{[]int32{4, 6}, []int32{2, 3, 5, 4, 6}, []int32{2, 3, 5}},
|
||||
{[]int32{3, 5}, []int32{2, 3, 5}, []int32{2}},
|
||||
{[]int32{2, 3, 5}, []int32{2, 3, 5}, []int32{}},
|
||||
{[]int32{2}, []int32{2, 3, 5}, []int32{3, 5}},
|
||||
{[]int32{}, []int32{2, 3, 5}, []int32{2, 3, 5}},
|
||||
{[]int32{}, []int32{}, []int32{}},
|
||||
{[]int32{1}, []int32{1}, []int32{}},
|
||||
{[]int64{4, 6}, []int64{2, 3, 5, 4, 6}, []int64{2, 3, 5}},
|
||||
{[]int64{3, 5}, []int64{2, 3, 5}, []int64{2}},
|
||||
{[]int64{2, 3, 5}, []int64{2, 3, 5}, []int64{}},
|
||||
{[]int64{2}, []int64{2, 3, 5}, []int64{3, 5}},
|
||||
{[]int64{}, []int64{2, 3, 5}, []int64{2, 3, 5}},
|
||||
{[]int64{}, []int64{}, []int64{}},
|
||||
{[]int64{1}, []int64{1}, []int64{}},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
result := NotInt32(tt.setA, tt.setB)
|
||||
result := Notint64(tt.setA, tt.setB)
|
||||
if !reflect.DeepEqual(result, tt.out) {
|
||||
t.Errorf("got %d, want %d", result, tt.out)
|
||||
}
|
||||
@@ -322,19 +322,19 @@ func TestIsInUint64(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsInInt32(t *testing.T) {
|
||||
func TestIsInint64(t *testing.T) {
|
||||
testCases := []struct {
|
||||
a int32
|
||||
b []int32
|
||||
a int64
|
||||
b []int64
|
||||
result bool
|
||||
}{
|
||||
{0, []int32{}, false},
|
||||
{0, []int32{0}, true},
|
||||
{4, []int32{2, 3, 5, 4, 6}, true},
|
||||
{100, []int32{2, 3, 5, 4, 6}, false},
|
||||
{0, []int64{}, false},
|
||||
{0, []int64{0}, true},
|
||||
{4, []int64{2, 3, 5, 4, 6}, true},
|
||||
{100, []int64{2, 3, 5, 4, 6}, false},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
result := IsInInt32(tt.a, tt.b)
|
||||
result := IsInint64(tt.a, tt.b)
|
||||
if result != tt.result {
|
||||
t.Errorf("IsIn(%d, %v)=%v, wanted: %v",
|
||||
tt.a, tt.b, result, tt.result)
|
||||
|
||||
Reference in New Issue
Block a user