Skip to content

fix: update types in unstable PR #7718

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

Merged
Merged
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
4 changes: 2 additions & 2 deletions packages/beacon-node/src/network/subnets/interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {PeerId, PrivateKey} from "@libp2p/interface";
import {peerIdFromPrivateKey} from "@libp2p/peer-id";
import {getV4Crypto} from "@chainsafe/enr";
import {fromHexString} from "@chainsafe/ssz";
import {PeerId, PrivateKey} from "@libp2p/interface";
import {peerIdFromPrivateKey} from "@libp2p/peer-id";
import {ForkName} from "@lodestar/params";
import {Bytes32, Slot, SubnetID, ValidatorIndex} from "@lodestar/types";
import {GossipTopic} from "../gossip/interface.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ describe("network / peers / PeerManager", () => {
},
});
const beaconConfig = createBeaconConfig(config, state.genesisValidatorsRoot);
const networkConfig = new NetworkConfig(peerId1, beaconConfig);
const privateKey = await generateKeyPair("secp256k1");
const networkConfig = new NetworkConfig(privateKey, beaconConfig);
const controller = new AbortController();
const clock = new Clock({config: beaconConfig, genesisTime: 0, signal: controller.signal});
const status = ssz.phase0.Status.defaultValue();
const statusCache = new LocalStatusCache(status);
const privateKey = await generateKeyPair("secp256k1");
const libp2p = await createNode("/ip4/127.0.0.1/tcp/0", privateKey);

afterEachCallbacks.push(async () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/beacon-node/test/e2e/network/reqrespEncode.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {noise} from "@chainsafe/libp2p-noise";
import {generateKeyPair} from "@libp2p/crypto/keys";
import {mplex} from "@libp2p/mplex";
import {tcp} from "@libp2p/tcp";
import {createBeaconConfig} from "@lodestar/config";
Expand Down Expand Up @@ -60,7 +61,7 @@ describe("reqresp encoder", () => {
};

const config = createBeaconConfig({}, ZERO_HASH);
const networkConfig = new NetworkConfig(libp2p.peerId, config);
const networkConfig = new NetworkConfig(await generateKeyPair("secp256k1"), config);
const modules: ReqRespBeaconNodeModules = {
libp2p,
peersData: new PeersData(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import crypto from "node:crypto";
import {afterAll, beforeAll, bench, describe} from "@chainsafe/benchmark";
import {fromHexString} from "@chainsafe/ssz";
import {generateKeyPair} from "@libp2p/crypto/keys";
import {config} from "@lodestar/config/default";
import {LevelDbController} from "@lodestar/db";
import {SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY} from "@lodestar/params";
Expand Down Expand Up @@ -40,7 +40,7 @@ describe("produceBlockBody", () => {
archiveMode: ArchiveMode.Frequency,
},
{
nodeId: Buffer.alloc(32, crypto.randomBytes(32)),
privateKey: await generateKeyPair("secp256k1"),
config: state.config,
db,
dataDir: ".",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import crypto from "node:crypto";
import {afterAll, beforeAll, bench, describe, setBenchOpts} from "@chainsafe/benchmark";
import {generateKeyPair} from "@libp2p/crypto/keys";
import {config} from "@lodestar/config/default";
import {LevelDbController} from "@lodestar/db";
import {SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY, SLOTS_PER_EPOCH} from "@lodestar/params";
Expand Down Expand Up @@ -89,7 +89,7 @@ describe.skip("verify+import blocks - range sync perf test", () => {
archiveMode: ArchiveMode.Frequency,
},
{
nodeId: Buffer.alloc(32, crypto.randomBytes(32)),
privateKey: await generateKeyPair("secp256k1"),
config: state.config,
db,
dataDir: ".",
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/test/spec/presets/fork_choice.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import crypto from "node:crypto";
import path from "node:path";
import {toHexString} from "@chainsafe/ssz";
import {generateKeyPair} from "@libp2p/crypto/keys";
import {createBeaconConfig} from "@lodestar/config";
import {CheckpointWithHex, ForkChoice} from "@lodestar/fork-choice";
import {ACTIVE_PRESET, ForkName, ForkSeq, isForkPostDeneb} from "@lodestar/params";
Expand Down Expand Up @@ -110,7 +110,7 @@ const forkChoiceTest =
proposerBoostReorg: true,
},
{
nodeId: Buffer.alloc(32, crypto.randomBytes(32)),
privateKey: await generateKeyPair("secp256k1"),
config: createBeaconConfig(config, state.genesisValidatorsRoot),
db: getMockedBeaconDb(),
dataDir: ".",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {generateKeyPair} from "@libp2p/crypto/keys";
import {createBeaconConfig} from "@lodestar/config";
import {
ATTESTATION_SUBNET_COUNT,
Expand All @@ -18,19 +19,18 @@ import {AttnetsService} from "../../../../src/network/subnets/attnetsService.js"
import {CommitteeSubscription} from "../../../../src/network/subnets/interface.js";
import {Clock, IClock} from "../../../../src/util/clock.js";
import {testLogger} from "../../../utils/logger.js";
import {getValidPeerId} from "../../../utils/peer.js";

vi.mock("../../../../src/network/gossip/gossipsub.js");

describe("AttnetsService", () => {
describe("AttnetsService", async () => {
const nodeId = bigIntToBytes(
BigInt("88752428858350697756262172400162263450541348766581994718383409852729519486397"),
32,
"be"
);
const ALTAIR_FORK_EPOCH = 100;
const config = createBeaconConfig({ALTAIR_FORK_EPOCH}, ZERO_HASH);
const networkConfig = new NetworkConfig(getValidPeerId(), config);
const networkConfig = new NetworkConfig(await generateKeyPair("secp256k1"), config);
// const {SECONDS_PER_SLOT} = config;
let service: AttnetsService;
let gossipStub: MockedObject<Eth2Gossipsub>;
Expand Down
3 changes: 1 addition & 2 deletions packages/beacon-node/test/utils/networkWithMockDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function getNetworkForTest(
archiveMode: ArchiveMode.Frequency,
},
{
nodeId: Buffer.alloc(32, crypto.randomBytes(32)),
privateKey: await generateKeyPair("secp256k1"),
config: beaconConfig,
db,
dataDir: ".",
Expand All @@ -86,7 +86,6 @@ export async function getNetworkForTest(
metrics: null,
};

const peerId = await createSecp256k1PeerId();
const network = await Network.init({
...modules,
privateKey: await generateKeyPair("secp256k1"),
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cmds/beacon/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export async function beaconHandlerInit(args: BeaconArgs & GlobalArgs) {
}

const logger = initLogger(args, beaconPaths.dataDir, config);
const {privateKey, enr} = await initPrivateKeyAndEnr(config, args, beaconPaths.beaconDir, logger);
const {privateKey, enr} = await initPrivateKeyAndEnr(args, beaconPaths.beaconDir, logger);

if (args.discv5 !== false) {
// Inject ENR to beacon options
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/cmds/beacon/initPeerIdAndEnr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ export function overwriteEnrWithCliArgs(
* Create new PeerId and ENR by default, unless persistNetworkIdentity is provided
*/
export async function initPrivateKeyAndEnr(
config: ChainForkConfig,
args: BeaconArgs,
beaconDir: string,
logger: Logger,
Expand Down
8 changes: 1 addition & 7 deletions packages/cli/src/cmds/bootnode/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,7 @@ export async function bootnodeHandlerInit(args: BootnodeArgs & GlobalArgs) {
);

const logger = initLogger(args, beaconPaths.dataDir, config, "bootnode.log");
const {privateKey, enr} = await initPrivateKeyAndEnr(
config,
args as unknown as BeaconArgs,
bootnodeDir,
logger,
true
);
const {privateKey, enr} = await initPrivateKeyAndEnr(args as unknown as BeaconArgs, bootnodeDir, logger, true);

return {discv5Args, metricsArgs, bootnodeDir, network, version, commit, privateKey, enr, logger};
}
3 changes: 2 additions & 1 deletion packages/cli/test/unit/cmds/initPeerIdAndEnr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from "node:fs";
import {getV4Crypto} from "@chainsafe/enr";
import {publicKeyToProtobuf} from "@libp2p/crypto/keys";
import {peerIdFromPrivateKey} from "@libp2p/peer-id";
import {ChainForkConfig} from "@lodestar/config";
import {fromHex} from "@lodestar/utils";
import tmp from "tmp";
import {afterEach, beforeEach, describe, expect, it} from "vitest";
Expand Down Expand Up @@ -31,7 +32,7 @@ describe("initPeerIdAndEnr", () => {
const peerId = peerIdFromPrivateKey(privateKey);
expect(enr.peerId.toString()).toBe(peerId.toString());
const nodeIdFromEnr = enr.nodeId;
const nodeIdFromPubkey = getV4Crypto().nodeId(peerId.publicKey.raw);
const nodeIdFromPubkey = getV4Crypto().nodeId(privateKey.publicKey.raw);
expect(nodeIdFromPubkey).toEqual(nodeIdFromEnr);
// const publicKey2 = publicKeyToProtobuf(privateKey.publicKey);
// const nodeIdFromPublickey2 = getV4Crypto().nodeId(publicKey2);
Expand Down
Loading