libp2p / libp2p/rust-libp2p

`PeerId::from_bytes` should be const

Open
#5,864 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted
Dominant language
Rust
Stars
5.6k
Forks
1.3k
Avg merge
8h 47m
Merged PRs (30d)
19

Description

Description

There's currently no way to create a PeerId in a const context.

Motivation

I'm writing unit tests, and I need a global PeerId shared between tests. A const peer id would be great for this.

Current Implementation

My work around is just to call PeerId::from_bytes every time using the same bytes.

Are you planning to do it yourself in a pull request?

No

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the implementation of PeerId::from_bytes and inspect its validation and dependencies. Check whether the existing tests cover constructing a PeerId from fixed bytes, then add coverage for const-context construction. Done means the same API can be used to define a global PeerId without repeated runtime calls.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
networking
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.