Skip to content

Commit

Permalink
Merge branch '__develop' into native-blocks-swap-usage
Browse files Browse the repository at this point in the history
# Conflicts:
#	beacon-chain/blockchain/chain_info_test.go
#	beacon-chain/blockchain/execution_engine_test.go
#	beacon-chain/blockchain/head.go
#	beacon-chain/blockchain/head_test.go
#	beacon-chain/blockchain/init_sync_process_block_test.go
#	beacon-chain/blockchain/new_slot_test.go
#	beacon-chain/blockchain/process_attestation_test.go
#	beacon-chain/blockchain/process_block_test.go
#	beacon-chain/blockchain/receive_attestation_test.go
#	beacon-chain/blockchain/receive_block_test.go
#	beacon-chain/blockchain/service_test.go
#	beacon-chain/blockchain/weak_subjectivity_checks_test.go
#	beacon-chain/rpc/eth/beacon/blocks_test.go
#	beacon-chain/rpc/eth/beacon/state_test.go
#	beacon-chain/rpc/eth/beacon/sync_committee_test.go
#	beacon-chain/rpc/eth/beacon/validator_test.go
#	beacon-chain/rpc/eth/debug/debug_test.go
#	beacon-chain/rpc/eth/validator/validator_test.go
#	beacon-chain/rpc/prysm/v1alpha1/beacon/assignments_test.go
#	beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go
#	beacon-chain/rpc/prysm/v1alpha1/beacon/blocks_test.go
#	beacon-chain/rpc/prysm/v1alpha1/beacon/committees_test.go
#	beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go
#	beacon-chain/rpc/prysm/v1alpha1/debug/block_test.go
#	beacon-chain/rpc/prysm/v1alpha1/debug/state_test.go
#	beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go
#	beacon-chain/rpc/prysm/v1alpha1/validator/blocks_test.go
#	beacon-chain/rpc/prysm/v1alpha1/validator/proposer_execution_payload_test.go
#	beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go
#	beacon-chain/rpc/statefetcher/fetcher_test.go
#	beacon-chain/state/stategen/getter_test.go
#	beacon-chain/state/stategen/migrate_test.go
#	beacon-chain/state/stategen/replay_test.go
#	beacon-chain/state/stategen/service_test.go
#	beacon-chain/state/stategen/setter_test.go
#	beacon-chain/sync/initial-sync/blocks_fetcher_test.go
#	beacon-chain/sync/initial-sync/blocks_fetcher_utils_test.go
#	beacon-chain/sync/initial-sync/blocks_queue_test.go
#	beacon-chain/sync/initial-sync/initial_sync_test.go
#	beacon-chain/sync/initial-sync/round_robin_test.go
#	beacon-chain/sync/initial-sync/service_test.go
#	beacon-chain/sync/pending_attestations_queue_test.go
#	beacon-chain/sync/pending_blocks_queue_test.go
#	beacon-chain/sync/rpc_beacon_blocks_by_range_test.go
#	beacon-chain/sync/rpc_beacon_blocks_by_root_test.go
#	beacon-chain/sync/rpc_status_test.go
#	beacon-chain/sync/service_test.go
#	beacon-chain/sync/sync_fuzz_test.go
#	beacon-chain/sync/validate_aggregate_proof_test.go
#	beacon-chain/sync/validate_beacon_attestation_test.go
#	beacon-chain/sync/validate_beacon_blocks_test.go
  • Loading branch information
rkapka committed Jun 27, 2022
2 parents 5f2685b + f8b4d8c commit 9064b3d
Show file tree
Hide file tree
Showing 112 changed files with 1,220 additions and 2,849 deletions.
5 changes: 2 additions & 3 deletions beacon-chain/blockchain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ go_library(
"log.go",
"merge_ascii_art.go",
"metrics.go",
"new_slot.go",
"options.go",
"pow_block.go",
"process_attestation.go",
Expand All @@ -35,7 +34,6 @@ go_library(
deps = [
"//async:go_default_library",
"//async/event:go_default_library",
"//beacon-chain/blockchain/store:go_default_library",
"//beacon-chain/cache:go_default_library",
"//beacon-chain/cache/depositcache:go_default_library",
"//beacon-chain/core/altair:go_default_library",
Expand Down Expand Up @@ -113,7 +111,6 @@ go_test(
"log_test.go",
"metrics_test.go",
"mock_test.go",
"new_slot_test.go",
"pow_block_test.go",
"process_attestation_test.go",
"process_block_test.go",
Expand All @@ -133,6 +130,7 @@ go_test(
"//beacon-chain/core/transition:go_default_library",
"//beacon-chain/db:go_default_library",
"//beacon-chain/db/testing:go_default_library",
"//beacon-chain/forkchoice/types:go_default_library",
"//beacon-chain/p2p:go_default_library",
"//beacon-chain/powchain:go_default_library",
"//beacon-chain/powchain/testing:go_default_library",
Expand Down Expand Up @@ -190,6 +188,7 @@ go_test(
"//beacon-chain/core/transition:go_default_library",
"//beacon-chain/db:go_default_library",
"//beacon-chain/db/testing:go_default_library",
"//beacon-chain/forkchoice/types:go_default_library",
"//beacon-chain/p2p:go_default_library",
"//beacon-chain/powchain:go_default_library",
"//beacon-chain/powchain/testing:go_default_library",
Expand Down
61 changes: 19 additions & 42 deletions beacon-chain/blockchain/chain_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"time"

"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain/store"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice"
doublylinkedtree "github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/doubly-linked-tree"
Expand Down Expand Up @@ -81,9 +79,9 @@ type CanonicalFetcher interface {
// FinalizationFetcher defines a common interface for methods in blockchain service which
// directly retrieve finalization and justification related data.
type FinalizationFetcher interface {
FinalizedCheckpt() (*ethpb.Checkpoint, error)
CurrentJustifiedCheckpt() (*ethpb.Checkpoint, error)
PreviousJustifiedCheckpt() (*ethpb.Checkpoint, error)
FinalizedCheckpt() *ethpb.Checkpoint
CurrentJustifiedCheckpt() *ethpb.Checkpoint
PreviousJustifiedCheckpt() *ethpb.Checkpoint
VerifyFinalizedBlkDescendant(ctx context.Context, blockRoot [32]byte) error
}

Expand All @@ -94,47 +92,27 @@ type OptimisticModeFetcher interface {
}

// FinalizedCheckpt returns the latest finalized checkpoint from chain store.
func (s *Service) FinalizedCheckpt() (*ethpb.Checkpoint, error) {
cp, err := s.store.FinalizedCheckpt()
if err != nil {
return nil, err
}

return ethpb.CopyCheckpoint(cp), nil
func (s *Service) FinalizedCheckpt() *ethpb.Checkpoint {
cp := s.ForkChoicer().FinalizedCheckpoint()
return &ethpb.Checkpoint{Epoch: cp.Epoch, Root: bytesutil.SafeCopyBytes(cp.Root[:])}
}

// CurrentJustifiedCheckpt returns the current justified checkpoint from chain store.
func (s *Service) CurrentJustifiedCheckpt() (*ethpb.Checkpoint, error) {
cp, err := s.store.JustifiedCheckpt()
if err != nil {
return nil, err
}

return ethpb.CopyCheckpoint(cp), nil
// PreviousJustifiedCheckpt returns the current justified checkpoint from chain store.
func (s *Service) PreviousJustifiedCheckpt() *ethpb.Checkpoint {
cp := s.ForkChoicer().PreviousJustifiedCheckpoint()
return &ethpb.Checkpoint{Epoch: cp.Epoch, Root: bytesutil.SafeCopyBytes(cp.Root[:])}
}

// PreviousJustifiedCheckpt returns the previous justified checkpoint from chain store.
func (s *Service) PreviousJustifiedCheckpt() (*ethpb.Checkpoint, error) {
cp, err := s.store.PrevJustifiedCheckpt()
if err != nil {
return nil, err
}

return ethpb.CopyCheckpoint(cp), nil
// CurrentJustifiedCheckpt returns the current justified checkpoint from chain store.
func (s *Service) CurrentJustifiedCheckpt() *ethpb.Checkpoint {
cp := s.ForkChoicer().JustifiedCheckpoint()
return &ethpb.Checkpoint{Epoch: cp.Epoch, Root: bytesutil.SafeCopyBytes(cp.Root[:])}
}

// BestJustifiedCheckpt returns the best justified checkpoint from store.
func (s *Service) BestJustifiedCheckpt() (*ethpb.Checkpoint, error) {
cp, err := s.store.BestJustifiedCheckpt()
if err != nil {
// If there is no best justified checkpoint, return the checkpoint with root as zeros to be used for genesis cases.
if errors.Is(err, store.ErrNilCheckpoint) {
return &ethpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}, nil
}
return nil, err
}

return ethpb.CopyCheckpoint(cp), nil
func (s *Service) BestJustifiedCheckpt() *ethpb.Checkpoint {
cp := s.ForkChoicer().BestJustifiedCheckpoint()
return &ethpb.Checkpoint{Epoch: cp.Epoch, Root: bytesutil.SafeCopyBytes(cp.Root[:])}
}

// HeadSlot returns the slot of the head of the chain.
Expand All @@ -154,9 +132,8 @@ func (s *Service) HeadRoot(ctx context.Context) ([]byte, error) {
s.headLock.RLock()
defer s.headLock.RUnlock()

if s.headRoot() != params.BeaconConfig().ZeroHash {
r := s.headRoot()
return r[:], nil
if s.head != nil && s.head.root != params.BeaconConfig().ZeroHash {
return bytesutil.SafeCopyBytes(s.head.root[:]), nil
}

b, err := s.cfg.BeaconDB.HeadBlock(ctx)
Expand Down
Loading

0 comments on commit 9064b3d

Please sign in to comment.