-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Request Data Columns When Fetching Pending Blocks (#14007)
* Support Data Columns For By Root Requests * Revert Config Changes * Fix Panic * Fix Process Block * Fix Flags * Lint * Support Checkpoint Sync * Manu's Review * Add Support For Columns in Remaining Methods * Unmarshal Uncorrectly
- Loading branch information
Showing
13 changed files
with
368 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package p2p | ||
|
||
import ( | ||
ssz "github.com/ferranbt/fastssz" | ||
"github.com/libp2p/go-libp2p/core/peer" | ||
"github.com/pkg/errors" | ||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/peerdas" | ||
"github.com/prysmaticlabs/prysm/v5/cmd/beacon-chain/flags" | ||
"github.com/prysmaticlabs/prysm/v5/config/params" | ||
) | ||
|
||
func (s *Service) GetValidCustodyPeers(peers []peer.ID) ([]peer.ID, error) { | ||
custodiedSubnetCount := params.BeaconConfig().CustodyRequirement | ||
if flags.Get().SubscribeToAllSubnets { | ||
custodiedSubnetCount = params.BeaconConfig().DataColumnSidecarSubnetCount | ||
} | ||
custodiedColumns, err := peerdas.CustodyColumns(s.NodeID(), custodiedSubnetCount) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var validPeers []peer.ID | ||
for _, pid := range peers { | ||
remoteCount, err := s.CustodyCountFromRemotePeer(pid) | ||
if err != nil { | ||
return nil, err | ||
} | ||
nodeId, err := ConvertPeerIDToNodeID(pid) | ||
if err != nil { | ||
return nil, err | ||
} | ||
remoteCustodiedColumns, err := peerdas.CustodyColumns(nodeId, remoteCount) | ||
if err != nil { | ||
return nil, err | ||
} | ||
invalidPeer := false | ||
for c := range custodiedColumns { | ||
if !remoteCustodiedColumns[c] { | ||
invalidPeer = true | ||
break | ||
} | ||
} | ||
if invalidPeer { | ||
continue | ||
} | ||
copiedId := pid | ||
// Add valid peer to list | ||
validPeers = append(validPeers, copiedId) | ||
} | ||
return validPeers, nil | ||
} | ||
|
||
func (s *Service) CustodyCountFromRemotePeer(pid peer.ID) (uint64, error) { | ||
// Retrieve the ENR of the peer. | ||
peerRecord, err := s.peers.ENR(pid) | ||
if err != nil { | ||
return 0, errors.Wrap(err, "ENR") | ||
} | ||
peerCustodiedSubnetCount := params.BeaconConfig().CustodyRequirement | ||
if peerRecord != nil { | ||
// Load the `custody_subnet_count` | ||
custodyBytes := make([]byte, 8) | ||
custodyObj := CustodySubnetCount(custodyBytes) | ||
if err := peerRecord.Load(&custodyObj); err != nil { | ||
return 0, errors.Wrap(err, "load custody_subnet_count") | ||
} | ||
actualCustodyCount := ssz.UnmarshallUint64(custodyBytes) | ||
|
||
if actualCustodyCount > peerCustodiedSubnetCount { | ||
peerCustodiedSubnetCount = actualCustodyCount | ||
} | ||
} | ||
return peerCustodiedSubnetCount, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.