Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into moveAroundRunner
  • Loading branch information
nisdas committed May 19, 2022
2 parents 6022a02 + 092e9e1 commit 2516c54
Show file tree
Hide file tree
Showing 54 changed files with 470 additions and 187 deletions.
8 changes: 3 additions & 5 deletions api/client/beacon/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ const (
type StateOrBlockId string

const (
IdFinalized StateOrBlockId = "finalized"
IdGenesis StateOrBlockId = "genesis"
IdHead StateOrBlockId = "head"
IdJustified StateOrBlockId = "justified"
IdGenesis StateOrBlockId = "genesis"
IdHead StateOrBlockId = "head"
)

var ErrMalformedHostname = errors.New("hostname must include port, separated by one colon, like example.com:3500")
Expand All @@ -60,7 +58,7 @@ func IdFromRoot(r [32]byte) StateOrBlockId {
return StateOrBlockId(fmt.Sprintf("%#x", r))
}

// IdFromRoot encodes a Slot in the format expected by the API in places where a slot can be used to identify
// IdFromSlot encodes a Slot in the format expected by the API in places where a slot can be used to identify
// a BeaconState or SignedBeaconBlock.
func IdFromSlot(s types.Slot) StateOrBlockId {
return StateOrBlockId(strconv.FormatUint(uint64(s), 10))
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/blockchain/testing/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func (_ *ChainService) HeadGenesisValidatorsRoot() [32]byte {
return [32]byte{}
}

// VerifyBlkDescendant mocks VerifyBlkDescendant and always returns nil.
// VerifyFinalizedBlkDescendant mocks VerifyBlkDescendant and always returns nil.
func (s *ChainService) VerifyFinalizedBlkDescendant(_ context.Context, _ [32]byte) error {
return s.VerifyBlkDescendantErr
}
Expand Down Expand Up @@ -451,7 +451,7 @@ func (s *ChainService) IsOptimisticForRoot(_ context.Context, _ [32]byte) (bool,
return s.Optimistic, nil
}

// ProcessAttestationsAndUpdateHead mocks the same method in the chain service.
// UpdateHead mocks the same method in the chain service.
func (s *ChainService) UpdateHead(_ context.Context) error { return nil }

// ReceiveAttesterSlashing mocks the same method in the chain service.
Expand Down
7 changes: 3 additions & 4 deletions beacon-chain/blockchain/weak_subjectivity_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ type WeakSubjectivityVerifier struct {
db weakSubjectivityDB
}

// NewWeakSubjectivityVerifier validates a checkpoint, and if valid, uses it to initialize a weak subjectivity verifier
// NewWeakSubjectivityVerifier validates a checkpoint, and if valid, uses it to initialize a weak subjectivity verifier.
func NewWeakSubjectivityVerifier(wsc *ethpb.Checkpoint, db weakSubjectivityDB) (*WeakSubjectivityVerifier, error) {
if wsc == nil || len(wsc.Root) == 0 || wsc.Epoch == 0 {
log.Warn("No valid weak subjectivity checkpoint specified, running without weak subjectivity verification")
log.Info("No checkpoint for syncing provided, node will begin syncing from genesis. Checkpoint Sync is an optional feature that allows your node to sync from a more recent checkpoint, " +
"which enhances the security of your local beacon node and the broader network. See https://docs.prylabs.network/docs/next/prysm-usage/checkpoint-sync/ to learn how to configure Checkpoint Sync.")
return &WeakSubjectivityVerifier{
enabled: false,
}, nil
Expand All @@ -58,7 +59,6 @@ func (v *WeakSubjectivityVerifier) VerifyWeakSubjectivity(ctx context.Context, f
if v.verified || !v.enabled {
return nil
}

// Two conditions are described in the specs:
// IF epoch_number > store.finalized_checkpoint.epoch,
// then ASSERT during block sync that block with root block_root
Expand Down Expand Up @@ -92,6 +92,5 @@ func (v *WeakSubjectivityVerifier) VerifyWeakSubjectivity(ctx context.Context, f
return nil
}
}

return errors.Wrap(errWSBlockNotFoundInEpoch, fmt.Sprintf("root=%#x, epoch=%d", v.root, v.epoch))
}
2 changes: 1 addition & 1 deletion beacon-chain/cache/committee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestCommitteeCache_CanRotate(t *testing.T) {
sort.Slice(k, func(i, j int) bool {
return k[i].(string) < k[j].(string)
})
wanted := end - int(maxCommitteesCacheSize)
wanted := end - maxCommitteesCacheSize
s := bytesutil.ToBytes32([]byte(strconv.Itoa(wanted)))
assert.Equal(t, key(s), k[0], "incorrect key received for slot 190")

Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/db/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var ErrNotFoundState = kv.ErrNotFoundState
// ErrNotFoundOriginBlockRoot wraps ErrNotFound for an error specific to the origin block root.
var ErrNotFoundOriginBlockRoot = kv.ErrNotFoundOriginBlockRoot

// ErrNotFoundOriginBlockRoot wraps ErrNotFound for an error specific to the origin block root.
// ErrNotFoundBackfillBlockRoot wraps ErrNotFound for an error specific to the backfill block root.
var ErrNotFoundBackfillBlockRoot = kv.ErrNotFoundBackfillBlockRoot

// ErrNotFoundGenesisBlockRoot means no genesis block root was found, indicating the db was not initialized with genesis
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/db/kv/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var ErrNotFoundOriginBlockRoot = errors.Wrap(ErrNotFound, "OriginBlockRoot")
// ErrNotFoundGenesisBlockRoot means no genesis block root was found, indicating the db was not initialized with genesis
var ErrNotFoundGenesisBlockRoot = errors.Wrap(ErrNotFound, "OriginGenesisRoot")

// ErrNotFoundOriginBlockRoot is an error specifically for the origin block root getter
// ErrNotFoundBackfillBlockRoot is an error specifically for the origin block root getter
var ErrNotFoundBackfillBlockRoot = errors.Wrap(ErrNotFound, "BackfillBlockRoot")

// ErrNotFoundFeeRecipient is a not found error specifically for the fee recipient getter
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/monitor/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestUpdateSyncCommitteeTrackedVals(t *testing.T) {

func TestNewService(t *testing.T) {
config := &ValidatorMonitorConfig{}
tracked := []types.ValidatorIndex{}
var tracked []types.ValidatorIndex
ctx := context.Background()
_, err := NewService(ctx, config, tracked)
require.NoError(t, err)
Expand Down
12 changes: 9 additions & 3 deletions beacon-chain/powchain/rpc_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ func (s *Service) pollConnectionStatus(ctx context.Context) {
continue
}
// Close previous client, if connection was successful.
currClient.Close()
if currClient != nil {
currClient.Close()
}
log.Infof("Connected to new endpoint: %s", logs.MaskCredentialsLogging(s.cfg.currHttpEndpoint.Url))
return
case <-s.ctx.Done():
Expand All @@ -92,7 +94,9 @@ func (s *Service) retryExecutionClientConnection(ctx context.Context, err error)
return
}
// Close previous client, if connection was successful.
currClient.Close()
if currClient != nil {
currClient.Close()
}
// Reset run error in the event of a successful connection.
s.runError = nil
}
Expand All @@ -114,7 +118,9 @@ func (s *Service) checkDefaultEndpoint(ctx context.Context) {
return
}
// Close previous client, if connection was successful.
currClient.Close()
if currClient != nil {
currClient.Close()
}
s.updateCurrHttpEndpoint(primaryEndpoint)
}

Expand Down
40 changes: 20 additions & 20 deletions beacon-chain/rpc/eth/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2835,50 +2835,50 @@ func TestGetAggregateAttestation(t *testing.T) {
},
Signature: sig1,
}
root2_1 := bytesutil.PadTo([]byte("root2_1"), 32)
sig2_1 := bytesutil.PadTo([]byte("sig2_1"), fieldparams.BLSSignatureLength)
attSlot2_1 := &ethpbalpha.Attestation{
root21 := bytesutil.PadTo([]byte("root2_1"), 32)
sig21 := bytesutil.PadTo([]byte("sig2_1"), fieldparams.BLSSignatureLength)
attslot21 := &ethpbalpha.Attestation{
AggregationBits: []byte{0, 1, 1},
Data: &ethpbalpha.AttestationData{
Slot: 2,
CommitteeIndex: 2,
BeaconBlockRoot: root2_1,
BeaconBlockRoot: root21,
Source: &ethpbalpha.Checkpoint{
Epoch: 1,
Root: root2_1,
Root: root21,
},
Target: &ethpbalpha.Checkpoint{
Epoch: 1,
Root: root2_1,
Root: root21,
},
},
Signature: sig2_1,
Signature: sig21,
}
root2_2 := bytesutil.PadTo([]byte("root2_2"), 32)
sig2_2 := bytesutil.PadTo([]byte("sig2_2"), fieldparams.BLSSignatureLength)
attSlot2_2 := &ethpbalpha.Attestation{
root22 := bytesutil.PadTo([]byte("root2_2"), 32)
sig22 := bytesutil.PadTo([]byte("sig2_2"), fieldparams.BLSSignatureLength)
attslot22 := &ethpbalpha.Attestation{
AggregationBits: []byte{0, 1, 1, 1},
Data: &ethpbalpha.AttestationData{
Slot: 2,
CommitteeIndex: 3,
BeaconBlockRoot: root2_2,
BeaconBlockRoot: root22,
Source: &ethpbalpha.Checkpoint{
Epoch: 1,
Root: root2_2,
Root: root22,
},
Target: &ethpbalpha.Checkpoint{
Epoch: 1,
Root: root2_2,
Root: root22,
},
},
Signature: sig2_2,
Signature: sig22,
}
vs := &Server{
AttestationsPool: &mock.PoolMock{AggregatedAtts: []*ethpbalpha.Attestation{attSlot1, attSlot2_1, attSlot2_2}},
AttestationsPool: &mock.PoolMock{AggregatedAtts: []*ethpbalpha.Attestation{attSlot1, attslot21, attslot22}},
}

t.Run("OK", func(t *testing.T) {
reqRoot, err := attSlot2_2.Data.HashTreeRoot()
reqRoot, err := attslot22.Data.HashTreeRoot()
require.NoError(t, err)
req := &ethpbv1.AggregateAttestationRequest{
AttestationDataRoot: reqRoot[:],
Expand All @@ -2889,16 +2889,16 @@ func TestGetAggregateAttestation(t *testing.T) {
require.NotNil(t, att)
require.NotNil(t, att.Data)
assert.DeepEqual(t, bitfield.Bitlist{0, 1, 1, 1}, att.Data.AggregationBits)
assert.DeepEqual(t, sig2_2, att.Data.Signature)
assert.DeepEqual(t, sig22, att.Data.Signature)
assert.Equal(t, types.Slot(2), att.Data.Data.Slot)
assert.Equal(t, types.CommitteeIndex(3), att.Data.Data.Index)
assert.DeepEqual(t, root2_2, att.Data.Data.BeaconBlockRoot)
assert.DeepEqual(t, root22, att.Data.Data.BeaconBlockRoot)
require.NotNil(t, att.Data.Data.Source)
assert.Equal(t, types.Epoch(1), att.Data.Data.Source.Epoch)
assert.DeepEqual(t, root2_2, att.Data.Data.Source.Root)
assert.DeepEqual(t, root22, att.Data.Data.Source.Root)
require.NotNil(t, att.Data.Data.Target)
assert.Equal(t, types.Epoch(1), att.Data.Data.Target.Epoch)
assert.DeepEqual(t, root2_2, att.Data.Data.Target.Root)
assert.DeepEqual(t, root22, att.Data.Data.Target.Root)
})

t.Run("No matching attestation", func(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion beacon-chain/rpc/prysm/v1alpha1/debug/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ go_test(
"//beacon-chain/db/testing:go_default_library",
"//beacon-chain/forkchoice/protoarray:go_default_library",
"//beacon-chain/p2p/testing:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/state/stategen/mock:go_default_library",
"//config/fieldparams:go_default_library",
Expand Down
4 changes: 1 addition & 3 deletions beacon-chain/rpc/prysm/v1alpha1/debug/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
mockstategen "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen/mock"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
Expand Down Expand Up @@ -83,10 +82,9 @@ func TestServer_GetBeaconState(t *testing.T) {
Slot: slot + 1,
},
}
state := state.BeaconState(st)
// since we are requesting a state at a skipped slot, use the same method as stategen
// to advance to the pre-state for the subsequent slot
state, err = stategen.ReplayProcessSlots(ctx, state, slot+1)
state, err := stategen.ReplayProcessSlots(ctx, st, slot+1)
require.NoError(t, err)
wanted, err = state.MarshalSSZ()
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions beacon-chain/rpc/testutil/mock_powchain_info_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import (
"math/big"
)

// MockGenesisTimeFetcher is a fake implementation of the powchain.ChainInfoFetcher
// MockPOWChainInfoFetcher is a fake implementation of the powchain.ChainInfoFetcher
type MockPOWChainInfoFetcher struct {
CurrEndpoint string
CurrError error
Endpoints []string
Errors []error
}

func (m *MockPOWChainInfoFetcher) Eth2GenesisPowchainInfo() (uint64, *big.Int) {
func (*MockPOWChainInfoFetcher) Eth2GenesisPowchainInfo() (uint64, *big.Int) {
return uint64(0), &big.Int{}
}

func (m *MockPOWChainInfoFetcher) IsConnectedToETH1() bool {
func (*MockPOWChainInfoFetcher) IsConnectedToETH1() bool {
return true
}

Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/state/fieldtrie/field_trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (f *FieldTrie) RecomputeTrie(indices []uint64, elements interface{}) ([32]b
}
// We remove the duplicates here in order to prevent
// duplicated insertions into the trie.
newIndices := []uint64{}
var newIndices []uint64
indexExists := make(map[uint64]bool)
newRoots := make([][32]byte, 0, len(fieldRoots)/iNumOfElems)
for i, idx := range indices {
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/state/fieldtrie/field_trie_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func handleBalanceSlice(val, indices []uint64, convertAll bool) ([][32]byte, err
if err != nil {
return nil, err
}
roots := [][32]byte{}
var roots [][32]byte
for _, idx := range indices {
// We split the indexes into their relevant groups. Balances
// are compressed according to 4 values -> 1 chunk.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var _ fssz.HashRoot = (HistoricalRoots)([][32]byte{})
var _ fssz.Marshaler = (*HistoricalRoots)(nil)
var _ fssz.Unmarshaler = (*HistoricalRoots)(nil)

// Byte32 represents a 32 bytes HistoricalRoots object in Ethereum beacon chain consensus.
// HistoricalRoots represents a 32 bytes HistoricalRoots object in Ethereum beacon chain consensus.
type HistoricalRoots [][32]byte

// HashTreeRoot returns calculated hash root.
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/state/stategen/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewMockService() *MockStateManager {
}
}

// StateByRootIfCachedNoCopy
// StateByRootIfCachedNoCopy --
func (_ *MockStateManager) StateByRootIfCachedNoCopy(_ [32]byte) state.BeaconState {
panic("implement me")
}
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/sync/validate_beacon_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms
}
s.pendingQueueLock.Unlock()
err := errors.Errorf("unknown parent for block with slot %d and parent root %#x", blk.Block().Slot(), blk.Block().ParentRoot())
log.WithError(err).WithFields(getBlockFields(blk)).Debug("Could not process early block")
log.WithError(err).WithFields(getBlockFields(blk)).Debug("Could not identify parent for block")
return pubsub.ValidationIgnore, err
}

Expand Down
Loading

0 comments on commit 2516c54

Please sign in to comment.