Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid computing peerDAS info again and again. #14893

Open
wants to merge 4 commits into
base: peerDAS
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions beacon-chain/blockchain/process_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,12 +652,12 @@ func uint64MapToSortedSlice(input map[uint64]bool) []uint64 {
return output
}

func (s *Service) areDataColumnsAvailable(ctx context.Context, root [32]byte, signed interfaces.ReadOnlySignedBeaconBlock) error {
if signed.Version() < version.Fulu {
func (s *Service) areDataColumnsAvailable(ctx context.Context, root [32]byte, signedBlock interfaces.ReadOnlySignedBeaconBlock) error {
if signedBlock.Version() < version.Fulu {
return nil
}

block := signed.Block()
block := signedBlock.Block()
if block == nil {
return errors.New("invalid nil beacon block")
}
Expand Down Expand Up @@ -688,24 +688,19 @@ func (s *Service) areDataColumnsAvailable(ctx context.Context, root [32]byte, si
// All columns to sample need to be available for the block to be considered available.
// https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.10/specs/fulu/das-core.md#custody-sampling
nodeID := s.cfg.P2P.NodeID()
custodyGroupSamplingSize := peerdas.CustodyGroupSamplingSize()

custodyGroups, err := peerdas.CustodyGroups(nodeID, custodyGroupSamplingSize)
// Get the custody group sampling size for the node.
custodyGroupSamplingSize := peerdas.CustodyGroupSamplingSize()
peerInfo, _, err := peerdas.Info(nodeID, custodyGroupSamplingSize)
if err != nil {
return errors.Wrap(err, "custody groups")
return errors.Wrap(err, "peer info")
}

// Exit early if the node is not expected to custody any data columns.
if len(custodyGroups) == 0 {
if len(peerInfo.CustodyColumns) == 0 {
return nil
}

// Get the custody columns from the groups.
columnsMap, err := peerdas.CustodyColumns(custodyGroups)
if err != nil {
return errors.Wrap(err, "custody columns")
}

// Subscribe to newsly data columns stored in the database.
rootIndexChan := make(chan filesystem.RootIndexPair)
subscription := s.blobStorage.DataColumnFeed.Subscribe(rootIndexChan)
Expand All @@ -726,7 +721,7 @@ func (s *Service) areDataColumnsAvailable(ctx context.Context, root [32]byte, si
}

// Get a map of data column indices that are not currently available.
missingMap, err := missingDataColumns(s.blobStorage, root, columnsMap)
missingMap, err := missingDataColumns(s.blobStorage, root, peerInfo.CustodyColumns)
if err != nil {
return err
}
Expand All @@ -738,7 +733,7 @@ func (s *Service) areDataColumnsAvailable(ctx context.Context, root [32]byte, si
}

// Log for DA checks that cross over into the next slot; helpful for debugging.
nextSlot := slots.BeginsAt(signed.Block().Slot()+1, s.genesisTime)
nextSlot := slots.BeginsAt(signedBlock.Block().Slot()+1, s.genesisTime)
// Avoid logging if DA check is called after next slot start.
if nextSlot.After(time.Now()) {
nst := time.AfterFunc(time.Until(nextSlot), func() {
Expand All @@ -754,18 +749,18 @@ func (s *Service) areDataColumnsAvailable(ctx context.Context, root [32]byte, si
)

numberOfColumns := params.BeaconConfig().NumberOfColumns
colMapCount := uint64(len(columnsMap))
colMapCount := uint64(len(peerInfo.CustodyColumns))

if colMapCount < numberOfColumns {
expected = uint64MapToSortedSlice(columnsMap)
expected = uint64MapToSortedSlice(peerInfo.CustodyColumns)
}

if missingMapCount < numberOfColumns {
missing = uint64MapToSortedSlice(missingMap)
}

log.WithFields(logrus.Fields{
"slot": signed.Block().Slot(),
"slot": signedBlock.Block().Slot(),
"root": fmt.Sprintf("%#x", root),
"columnsExpected": expected,
"columnsWaiting": missing,
Expand Down
1 change: 0 additions & 1 deletion beacon-chain/cache/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ go_library(
"attestation_data.go",
"balance_cache_key.go",
"checkpoint_state.go",
"column_subnet_ids.go",
"committee.go",
"committee_disabled.go", # keep
"committees.go",
Expand Down
70 changes: 0 additions & 70 deletions beacon-chain/cache/column_subnet_ids.go

This file was deleted.

20 changes: 16 additions & 4 deletions beacon-chain/core/peerdas/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"helpers.go",
"log.go",
"das_core.go",
"info.go",
"metrics.go",
"p2p_interface.go",
"peer_sampling.go",
"reconstruction.go",
],
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/peerdas",
visibility = ["//visibility:public"],
Expand All @@ -21,18 +24,25 @@ go_library(
"//proto/prysm/v1alpha1:go_default_library",
"@com_github_ethereum_go_ethereum//p2p/enode:go_default_library",
"@com_github_ethereum_go_ethereum//p2p/enr:go_default_library",
"@com_github_hashicorp_golang_lru//:go_default_library",
"@com_github_holiman_uint256//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@org_golang_x_sync//errgroup:go_default_library",
],
)

go_test(
name = "go_default_test",
srcs = ["helpers_test.go"],
srcs = [
"das_core_test.go",
"info_test.go",
"p2p_interface_test.go",
"peer_sampling_test.go",
"reconstruction_test.go",
"utils_test.go",
],
deps = [
":go_default_library",
"//beacon-chain/blockchain/kzg:go_default_library",
Expand All @@ -45,7 +55,9 @@ go_test(
"//testing/util:go_default_library",
"@com_github_consensys_gnark_crypto//ecc/bls12-381/fr:go_default_library",
"@com_github_crate_crypto_go_kzg_4844//:go_default_library",
"@com_github_ethereum_go_ethereum//p2p/enode:go_default_library",
"@com_github_ethereum_go_ethereum//p2p/enr:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],
)
Loading
Loading