Add in progress handler to committee cache (#9664)

* Add in progress handler for committee cache

* Remove debug print

* Update validators.go

* Fix all the tests

* More tests

* Update committee_disabled.go

* Update committee_disabled.go

* Update testing util

* Update main.go

Co-authored-by: Nishant Das <nishdas93@gmail.com>
This commit is contained in:
terence tsao
2021-09-26 08:27:57 -07:00
committed by GitHub
parent 6e4c2b4b20
commit 376d248c22
95 changed files with 474 additions and 323 deletions

View File

@@ -1,6 +1,7 @@
package epoch_processing
import (
"context"
"path"
"testing"
@@ -27,7 +28,7 @@ func RunRegistryUpdatesTests(t *testing.T, config string) {
}
func processRegistryUpdatesWrapper(t *testing.T, state state.BeaconState) (state.BeaconState, error) {
state, err := epoch.ProcessRegistryUpdates(state)
state, err := epoch.ProcessRegistryUpdates(context.Background(), state)
require.NoError(t, err, "Could not process registry updates")
return state, nil
}

View File

@@ -1,6 +1,7 @@
package operations
import (
"context"
"io/ioutil"
"path"
"strings"
@@ -51,7 +52,7 @@ func RunBlockHeaderTest(t *testing.T, config string) {
// Spectest blocks are not signed, so we'll call NoVerify to skip sig verification.
bodyRoot, err := block.Body.HashTreeRoot()
require.NoError(t, err)
beaconState, err := blocks.ProcessBlockHeaderNoVerify(preBeaconState, block.Slot, block.ProposerIndex, block.ParentRoot, bodyRoot[:])
beaconState, err := blocks.ProcessBlockHeaderNoVerify(context.Background(), preBeaconState, block.Slot, block.ProposerIndex, block.ParentRoot, bodyRoot[:])
if postSSZExists {
require.NoError(t, err)

View File

@@ -30,7 +30,7 @@ func RunSyncCommitteeTest(t *testing.T, config string) {
body := &ethpb.BeaconBlockBodyAltair{SyncAggregate: sc}
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) {
return altair.ProcessSyncAggregate(s, body.SyncAggregate)
return altair.ProcessSyncAggregate(context.Background(), s, body.SyncAggregate)
})
})
}

View File

@@ -1,6 +1,7 @@
package epoch_processing
import (
"context"
"path"
"testing"
@@ -27,7 +28,7 @@ func RunRegistryUpdatesTests(t *testing.T, config string) {
}
func processRegistryUpdatesWrapper(t *testing.T, state state.BeaconState) (state.BeaconState, error) {
state, err := epoch.ProcessRegistryUpdates(state)
state, err := epoch.ProcessRegistryUpdates(context.Background(), state)
require.NoError(t, err, "Could not process registry updates")
return state, nil
}

View File

@@ -1,6 +1,7 @@
package operations
import (
"context"
"io/ioutil"
"path"
"strings"
@@ -52,7 +53,7 @@ func RunBlockHeaderTest(t *testing.T, config string) {
// Spectest blocks are not signed, so we'll call NoVerify to skip sig verification.
bodyRoot, err := block.Body.HashTreeRoot()
require.NoError(t, err)
beaconState, err := blocks.ProcessBlockHeaderNoVerify(preBeaconState, block.Slot, block.ProposerIndex, block.ParentRoot, bodyRoot[:])
beaconState, err := blocks.ProcessBlockHeaderNoVerify(context.Background(), preBeaconState, block.Slot, block.ProposerIndex, block.ParentRoot, bodyRoot[:])
if postSSZExists {
require.NoError(t, err)

View File

@@ -299,7 +299,7 @@ func BlockSignatureAltair(
if err := bState.SetSlot(block.Slot); err != nil {
return nil, err
}
proposerIdx, err := helpers.BeaconProposerIndex(bState)
proposerIdx, err := helpers.BeaconProposerIndex(context.Background(), bState)
if err != nil {
return nil, err
}
@@ -405,7 +405,7 @@ func GenerateFullBlockAltair(
return nil, err
}
idx, err := helpers.BeaconProposerIndex(bState)
idx, err := helpers.BeaconProposerIndex(ctx, bState)
if err != nil {
return nil, err
}

View File

@@ -119,7 +119,7 @@ func GenerateAttestations(
headRoot = b
}
activeValidatorCount, err := helpers.ActiveValidatorCount(bState, currentEpoch)
activeValidatorCount, err := helpers.ActiveValidatorCount(context.Background(), bState, currentEpoch)
if err != nil {
return nil, err
}
@@ -154,7 +154,7 @@ func GenerateAttestations(
return nil, err
}
for c := types.CommitteeIndex(0); uint64(c) < committeesPerSlot && uint64(c) < numToGen; c++ {
committee, err := helpers.BeaconCommitteeFromState(bState, slot, c)
committee, err := helpers.BeaconCommitteeFromState(context.Background(), bState, slot, c)
if err != nil {
return nil, err
}

View File

@@ -154,7 +154,7 @@ func GenerateFullBlock(
return nil, err
}
idx, err := helpers.BeaconProposerIndex(bState)
idx, err := helpers.BeaconProposerIndex(ctx, bState)
if err != nil {
return nil, err
}
@@ -312,7 +312,7 @@ func generateAttesterSlashings(
randGen := rand.NewDeterministicGenerator()
for i := uint64(0); i < numSlashings; i++ {
committeeIndex := randGen.Uint64() % params.BeaconConfig().MaxCommitteesPerSlot
committee, err := helpers.BeaconCommitteeFromState(bState, bState.Slot(), types.CommitteeIndex(committeeIndex))
committee, err := helpers.BeaconCommitteeFromState(context.Background(), bState, bState.Slot(), types.CommitteeIndex(committeeIndex))
if err != nil {
return nil, err
}
@@ -376,7 +376,7 @@ func generateVoluntaryExits(
}
func randValIndex(bState state.BeaconState) (types.ValidatorIndex, error) {
activeCount, err := helpers.ActiveValidatorCount(bState, core.CurrentEpoch(bState))
activeCount, err := helpers.ActiveValidatorCount(context.Background(), bState, core.CurrentEpoch(bState))
if err != nil {
return 0, err
}

View File

@@ -2,6 +2,7 @@ package util
import (
"bytes"
"context"
"encoding/hex"
"testing"
@@ -254,7 +255,7 @@ func TestSetupInitialDeposits_1024Entries_PartialDeposits(t *testing.T) {
func TestDeterministicGenesisState_100Validators(t *testing.T) {
validatorCount := uint64(100)
beaconState, privKeys := DeterministicGenesisState(t, validatorCount)
activeValidators, err := helpers.ActiveValidatorCount(beaconState, 0)
activeValidators, err := helpers.ActiveValidatorCount(context.Background(), beaconState, 0)
require.NoError(t, err)
if len(privKeys) != int(validatorCount) {

View File

@@ -21,7 +21,7 @@ import (
// RandaoReveal returns a signature of the requested epoch using the beacon proposer private key.
func RandaoReveal(beaconState state.ReadOnlyBeaconState, epoch types.Epoch, privKeys []bls.SecretKey) ([]byte, error) {
// We fetch the proposer's index as that is whom the RANDAO will be verified against.
proposerIdx, err := helpers.BeaconProposerIndex(beaconState)
proposerIdx, err := helpers.BeaconProposerIndex(context.Background(), beaconState)
if err != nil {
return []byte{}, errors.Wrap(err, "could not get beacon proposer index")
}
@@ -59,7 +59,7 @@ func BlockSignature(
if err := bState.SetSlot(block.Slot); err != nil {
return nil, err
}
proposerIdx, err := helpers.BeaconProposerIndex(bState)
proposerIdx, err := helpers.BeaconProposerIndex(context.Background(), bState)
if err != nil {
return nil, err
}

View File

@@ -2,6 +2,7 @@ package util
import (
"bytes"
"context"
"encoding/binary"
"testing"
@@ -19,7 +20,7 @@ func TestBlockSignature(t *testing.T) {
require.NoError(t, err)
require.NoError(t, beaconState.SetSlot(beaconState.Slot()+1))
proposerIdx, err := helpers.BeaconProposerIndex(beaconState)
proposerIdx, err := helpers.BeaconProposerIndex(context.Background(), beaconState)
assert.NoError(t, err)
assert.NoError(t, beaconState.SetSlot(beaconState.Slot()-1))
@@ -42,7 +43,7 @@ func TestRandaoReveal(t *testing.T) {
randaoReveal, err := RandaoReveal(beaconState, epoch, privKeys)
assert.NoError(t, err)
proposerIdx, err := helpers.BeaconProposerIndex(beaconState)
proposerIdx, err := helpers.BeaconProposerIndex(context.Background(), beaconState)
assert.NoError(t, err)
buf := make([]byte, 32)
binary.LittleEndian.PutUint64(buf, uint64(epoch))