Skip to content

Commit

Permalink
Remove extractNodeID and uses ConvertPeerIDToNodeID instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
nalepae committed Jun 14, 2024
1 parent 6685a94 commit 2625427
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 41 deletions.
3 changes: 0 additions & 3 deletions beacon-chain/sync/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,8 @@ go_library(
"//runtime/version:go_default_library",
"//time:go_default_library",
"//time/slots:go_default_library",
"@com_github_btcsuite_btcd_btcec_v2//:go_default_library",
"@com_github_ethereum_c_kzg_4844//bindings/go:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_ethereum_go_ethereum//common/math:go_default_library",
"@com_github_ethereum_go_ethereum//crypto:go_default_library",
"@com_github_hashicorp_golang_lru//:go_default_library",
"@com_github_libp2p_go_libp2p//core:go_default_library",
"@com_github_libp2p_go_libp2p//core/host:go_default_library",
Expand Down
40 changes: 2 additions & 38 deletions beacon-chain/sync/data_columns_sampling.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import (
"fmt"
"sort"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/feed"
statefeed "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/feed/state"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/peerdas"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/types"
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
"github.com/prysmaticlabs/prysm/v5/config/params"
Expand Down Expand Up @@ -50,40 +48,6 @@ func sortedListFromMap(m map[uint64]bool) []uint64 {
return result
}

// extractNodeID extracts the node ID from a peer ID.
func extractNodeID(pid peer.ID) ([32]byte, error) {
var nodeID [32]byte

// Retrieve the public key object of the peer under "crypto" form.
pubkeyObjCrypto, err := pid.ExtractPublicKey()
if err != nil {
return nodeID, errors.Wrap(err, "extract public key")
}

// Extract the bytes representation of the public key.
compressedPubKeyBytes, err := pubkeyObjCrypto.Raw()
if err != nil {
return nodeID, errors.Wrap(err, "public key raw")
}

// Retrieve the public key object of the peer under "SECP256K1" form.
pubKeyObjSecp256k1, err := btcec.ParsePubKey(compressedPubKeyBytes)
if err != nil {
return nodeID, errors.Wrap(err, "parse public key")
}

// Concatenate the X and Y coordinates represented in bytes.
buf := make([]byte, 64)
math.ReadBits(pubKeyObjSecp256k1.X(), buf[:32])
math.ReadBits(pubKeyObjSecp256k1.Y(), buf[32:])

// Get the node ID by hashing the concatenated X and Y coordinates.
nodeIDBytes := crypto.Keccak256(buf)
copy(nodeID[:], nodeIDBytes)

return nodeID, nil
}

// sampleDataColumnFromPeer samples data columns from a peer.
// It returns the missing columns after sampling.
func (s *Service) sampleDataColumnFromPeer(
Expand All @@ -101,7 +65,7 @@ func (s *Service) sampleDataColumnFromPeer(
peerCustodiedSubnetCount := s.cfg.p2p.CustodyCountFromRemotePeer(pid)

// Extract the node ID from the peer ID.
nodeID, err := extractNodeID(pid)
nodeID, err := p2p.ConvertPeerIDToNodeID(pid)
if err != nil {
return nil, errors.Wrap(err, "extract node ID")
}
Expand Down

0 comments on commit 2625427

Please sign in to comment.