diff --git a/packages/beacon-node/test/e2e/network/mdns.test.ts b/packages/beacon-node/test/e2e/network/mdns.test.ts index b278de4503e6..f9109e712d2b 100644 --- a/packages/beacon-node/test/e2e/network/mdns.test.ts +++ b/packages/beacon-node/test/e2e/network/mdns.test.ts @@ -16,6 +16,7 @@ import {generateState, zeroProtoBlock} from "../../utils/state.js"; import {testLogger} from "../../utils/logger.js"; import {GossipHandlers} from "../../../src/network/gossip/index.js"; import {memoOnce} from "../../utils/cache.js"; +import {computeNodeId} from "../../../src/network/subnets/index.js"; let port = 9000; const mu = "/ip4/127.0.0.1/tcp/0"; @@ -98,6 +99,7 @@ describe.skip("mdns", function () { const network = await Network.init({ ...modules, ...(await createNetworkModules(mu, peerId, {...opts, mdns: true})), + nodeId: computeNodeId(peerId), logger, }); diff --git a/packages/beacon-node/test/e2e/network/peers/peerManager.test.ts b/packages/beacon-node/test/e2e/network/peers/peerManager.test.ts index 795a4bf67ecc..2e0db44c2768 100644 --- a/packages/beacon-node/test/e2e/network/peers/peerManager.test.ts +++ b/packages/beacon-node/test/e2e/network/peers/peerManager.test.ts @@ -16,7 +16,7 @@ import {generateState} from "../../../utils/state.js"; import {waitForEvent} from "../../../utils/events/resolver.js"; import {testLogger} from "../../../utils/logger.js"; import {getValidPeerId} from "../../../utils/peer.js"; -import {IAttnetsService} from "../../../../src/network/subnets/index.js"; +import {IAttnetsService, computeNodeId} from "../../../../src/network/subnets/index.js"; import {Clock} from "../../../../src/util/clock.js"; import {LocalStatusCache} from "../../../../src/network/statusCache.js"; @@ -82,6 +82,7 @@ describe("network / peers / PeerManager", function () { syncnetsService: mockSubnetsService, gossip: {getScore: () => 0, scoreParams: {decayInterval: 1000}} as unknown as Eth2Gossipsub, peersData: new PeersData(), + nodeId: computeNodeId(peerId1), }, { targetPeers: 30, diff --git a/packages/beacon-node/test/unit/db/api/repositories/dataColumn.test.ts b/packages/beacon-node/test/unit/db/api/repositories/dataColumn.test.ts index 2eca3931e2a3..22d0603a585e 100644 --- a/packages/beacon-node/test/unit/db/api/repositories/dataColumn.test.ts +++ b/packages/beacon-node/test/unit/db/api/repositories/dataColumn.test.ts @@ -1,6 +1,7 @@ import {rimraf} from "rimraf"; import {describe, it, expect, beforeEach, afterEach, beforeAll} from "vitest"; -import {ssz} from "@lodestar/types"; +import {ByteVectorType} from "@chainsafe/ssz"; +import {ssz, electra} from "@lodestar/types"; import {createChainForkConfig} from "@lodestar/config"; import {LevelDbController} from "@lodestar/db"; import {NUMBER_OF_COLUMNS} from "@lodestar/params"; @@ -68,15 +69,18 @@ describe("block archive repository", function () { (ssz.electra.Cell.fixedSize + ssz.deneb.KZGCommitment.fixedSize + ssz.deneb.KZGProof.fixedSize); const numColumns = NUMBER_OF_COLUMNS; - const custodyColumns = new Uint8Array(numColumns); + const blobsLen = (singedBlock.message as electra.BeaconBlock).body.blobKzgCommitments.length; + // const dataColumnsSize = ssz.electra.DataColumnSidecar.minSize + blobsLen * (ssz.electra.Cell.fixedSize + ssz.deneb.KZGCommitment.fixedSize + ssz.deneb.KZGProof.fixedSize); + + // const dataColumnsLen = blockInput.blockData; const writeData = { blockRoot, slot, - numColumns, + blobsLen, columnsSize, - custodyColumns, - dataColumnSidecars, + dataColumnsIndex: new ByteVectorType(NUMBER_OF_COLUMNS), + dataColumnSidecars: ssz.electra.DataColumnSidecars, }; await dataColumnRepo.add(writeData); diff --git a/packages/beacon-node/test/unit/network/beaconBlocksMaybeBlobsByRange.test.ts b/packages/beacon-node/test/unit/network/beaconBlocksMaybeBlobsByRange.test.ts index 3fb9cb8e1c79..dee7b042b825 100644 --- a/packages/beacon-node/test/unit/network/beaconBlocksMaybeBlobsByRange.test.ts +++ b/packages/beacon-node/test/unit/network/beaconBlocksMaybeBlobsByRange.test.ts @@ -117,7 +117,7 @@ describe("beaconBlocksMaybeBlobsByRange", () => { sendBlobSidecarsByRange: async () => blobSidecars, } as Partial as INetwork; - const response = await beaconBlocksMaybeBlobsByRange(config, network, peerId, rangeRequest, 0); + const response = await beaconBlocksMaybeBlobsByRange(config, network, peerId, rangeRequest, 0, null); expect(response).toEqual(expectedResponse); }); }); diff --git a/packages/beacon-node/test/unit/sync/range/batch.test.ts b/packages/beacon-node/test/unit/sync/range/batch.test.ts index 02f49226c11f..97c1cd0c4578 100644 --- a/packages/beacon-node/test/unit/sync/range/batch.test.ts +++ b/packages/beacon-node/test/unit/sync/range/batch.test.ts @@ -42,7 +42,7 @@ describe("sync / range / batch", () => { // retry download: AwaitingDownload -> Downloading // downloadingSuccess: Downloading -> AwaitingProcessing batch.startDownloading(peer); - batch.downloadingSuccess(blocksDownloaded); + batch.downloadingSuccess({blocks: blocksDownloaded, pendingDataColumns: null}); expect(batch.state.status).toBe(BatchStatus.AwaitingProcessing); // startProcessing: AwaitingProcessing -> Processing @@ -57,7 +57,7 @@ describe("sync / range / batch", () => { // retry download + processing: AwaitingDownload -> Downloading -> AwaitingProcessing -> Processing // processingSuccess: Processing -> AwaitingValidation batch.startDownloading(peer); - batch.downloadingSuccess(blocksDownloaded); + batch.downloadingSuccess({blocks: blocksDownloaded, pendingDataColumns: null}); batch.startProcessing(); batch.processingSuccess(); expect(batch.state.status).toBe(BatchStatus.AwaitingValidation); @@ -68,7 +68,7 @@ describe("sync / range / batch", () => { // retry download + processing + validation: AwaitingDownload -> Downloading -> AwaitingProcessing -> Processing -> AwaitingValidation batch.startDownloading(peer); - batch.downloadingSuccess(blocksDownloaded); + batch.downloadingSuccess({blocks: blocksDownloaded, pendingDataColumns: null}); batch.startProcessing(); batch.processingSuccess(); expect(batch.state.status).toBe(BatchStatus.AwaitingValidation); @@ -79,7 +79,7 @@ describe("sync / range / batch", () => { const batch = new Batch(startEpoch, config); expectThrowsLodestarError( - () => batch.downloadingSuccess(blocksDownloaded), + () => batch.downloadingSuccess({blocks: blocksDownloaded, pendingDataColumns: []}), new BatchError({ code: BatchErrorCode.WRONG_STATUS, startEpoch, diff --git a/packages/beacon-node/test/unit/sync/range/chain.test.ts b/packages/beacon-node/test/unit/sync/range/chain.test.ts index 44d5cc7c173a..d368e7218dcc 100644 --- a/packages/beacon-node/test/unit/sync/range/chain.test.ts +++ b/packages/beacon-node/test/unit/sync/range/chain.test.ts @@ -72,7 +72,11 @@ describe("sync / range / chain", () => { } }; - const downloadBeaconBlocksByRange: SyncChainFns["downloadBeaconBlocksByRange"] = async (peerId, request) => { + const downloadBeaconBlocksByRange: SyncChainFns["downloadBeaconBlocksByRange"] = async ( + peer, + request, + partialDownload + ) => { const blocks: BlockInput[] = []; for (let i = request.startSlot; i < request.startSlot + request.count; i += request.step) { if (skippedSlots?.has(i)) { @@ -94,7 +98,7 @@ describe("sync / range / chain", () => { ) ); } - return blocks; + return {blocks, pendingDataColumns: null}; }; const target: ChainTarget = {slot: computeStartSlotAtEpoch(targetEpoch), root: ZERO_HASH}; @@ -111,7 +115,7 @@ describe("sync / range / chain", () => { ); const peers = [peer]; - for (const peer of peers) initialSync.addPeer(peer, target); + for (const peer of peers) initialSync.addPeer(peer, target, []); initialSync.startSyncing(startEpoch); }); @@ -124,7 +128,11 @@ describe("sync / range / chain", () => { const peers = [peer]; const processChainSegment: SyncChainFns["processChainSegment"] = async () => {}; - const downloadBeaconBlocksByRange: SyncChainFns["downloadBeaconBlocksByRange"] = async (peer, request) => { + const downloadBeaconBlocksByRange: SyncChainFns["downloadBeaconBlocksByRange"] = async ( + peer, + request, + partialDownload + ) => { const blocks: BlockInput[] = []; for (let i = request.startSlot; i < request.startSlot + request.count; i += request.step) { blocks.push( @@ -139,7 +147,7 @@ describe("sync / range / chain", () => { ) ); } - return blocks; + return {blocks, pendingDataColumns: null}; }; const target: ChainTarget = {slot: computeStartSlotAtEpoch(targetEpoch), root: ZERO_HASH}; @@ -157,7 +165,7 @@ describe("sync / range / chain", () => { // Add peers after some time setTimeout(() => { - for (const peer of peers) initialSync.addPeer(peer, target); + for (const peer of peers) initialSync.addPeer(peer, target, []); }, 20); initialSync.startSyncing(startEpoch); @@ -181,9 +189,9 @@ function logSyncChainFns(logger: Logger, fns: SyncChainFns): SyncChainFns { logger.debug("mock processChainSegment", {blocks: blocks.map((b) => b.block.message.slot).join(",")}); return fns.processChainSegment(blocks, syncType); }, - downloadBeaconBlocksByRange(peer, request) { + downloadBeaconBlocksByRange(peer, request, partialDownload) { logger.debug("mock downloadBeaconBlocksByRange", request); - return fns.downloadBeaconBlocksByRange(peer, request); + return fns.downloadBeaconBlocksByRange(peer, request, null); }, reportPeer(peer, action, actionName) { logger.debug("mock reportPeer", {peer: peer.toString(), action, actionName}); diff --git a/packages/beacon-node/test/unit/sync/range/utils/batches.test.ts b/packages/beacon-node/test/unit/sync/range/utils/batches.test.ts index c3c6a273dd8d..f521ae5ee692 100644 --- a/packages/beacon-node/test/unit/sync/range/utils/batches.test.ts +++ b/packages/beacon-node/test/unit/sync/range/utils/batches.test.ts @@ -227,7 +227,7 @@ describe("sync / range / batches", () => { batch.startDownloading(peer); if (status === BatchStatus.Downloading) return batch; - batch.downloadingSuccess([]); + batch.downloadingSuccess({blocks: [], pendingDataColumns: []}); if (status === BatchStatus.AwaitingProcessing) return batch; batch.startProcessing(); diff --git a/packages/beacon-node/test/unit/sync/range/utils/peerBalancer.test.ts b/packages/beacon-node/test/unit/sync/range/utils/peerBalancer.test.ts index a495c41683d6..34c56400de45 100644 --- a/packages/beacon-node/test/unit/sync/range/utils/peerBalancer.test.ts +++ b/packages/beacon-node/test/unit/sync/range/utils/peerBalancer.test.ts @@ -3,6 +3,7 @@ import {config} from "@lodestar/config/default"; import {Batch} from "../../../../../src/sync/range/batch.js"; import {ChainPeersBalancer} from "../../../../../src/sync/range/utils/peerBalancer.js"; import {getRandPeerIdStr} from "../../../../utils/peer.js"; +import {PeerIdStr} from "../../../../../src/util/peerId.js"; describe("sync / range / peerBalancer", () => { it("bestPeerToRetryBatch", async () => { @@ -14,6 +15,8 @@ describe("sync / range / peerBalancer", () => { const batch0 = new Batch(0, config); const batch1 = new Batch(1, config); + const custodyColumn = new Map(); + // Batch zero has a failedDownloadAttempt with peer0 batch0.startDownloading(peer1); batch0.downloadingError(); @@ -21,7 +24,7 @@ describe("sync / range / peerBalancer", () => { // peer2 is busy downloading batch1 batch1.startDownloading(peer2); - const peerBalancer = new ChainPeersBalancer([peer1, peer2, peer3], [batch0, batch1]); + const peerBalancer = new ChainPeersBalancer([peer1, peer2, peer3], custodyColumn, [batch0, batch1]); expect(peerBalancer.bestPeerToRetryBatch(batch0)).toBe(peer3); @@ -41,11 +44,13 @@ describe("sync / range / peerBalancer", () => { const batch0 = new Batch(0, config); const batch1 = new Batch(1, config); + const custodyColumn = new Map(); + // peer1 and peer2 are busy downloading batch0.startDownloading(peer1); batch1.startDownloading(peer2); - const peerBalancer = new ChainPeersBalancer([peer1, peer2, peer3, peer4], [batch0, batch1]); + const peerBalancer = new ChainPeersBalancer([peer1, peer2, peer3, peer4], custodyColumn, [batch0, batch1]); const idlePeers = peerBalancer.idlePeers(); diff --git a/packages/beacon-node/test/utils/networkWithMockDb.ts b/packages/beacon-node/test/utils/networkWithMockDb.ts index 71bd70d6259e..bb9656fea038 100644 --- a/packages/beacon-node/test/utils/networkWithMockDb.ts +++ b/packages/beacon-node/test/utils/networkWithMockDb.ts @@ -9,6 +9,7 @@ import {GossipHandlers, Network, NetworkInitModules, getReqRespHandlers} from ". import {NetworkOptions, defaultNetworkOptions} from "../../src/network/options.js"; import {GetReqRespHandlerFn} from "../../src/network/reqresp/types.js"; import {getMockedBeaconDb} from "../mocks/mockedBeaconDb.js"; +import {computeNodeId} from "../../src/network/subnets/index.js"; import {createCachedBeaconStateTest} from "./cachedBeaconState.js"; import {ClockStatic} from "./clock.js"; import {testLogger} from "./logger.js"; @@ -72,7 +73,7 @@ export async function getNetworkForTest( } ); - const modules: Omit = { + const modules: Omit = { config: beaconConfig, chain, db, @@ -81,9 +82,11 @@ export async function getNetworkForTest( metrics: null, }; + const peerId = await createSecp256k1PeerId(); const network = await Network.init({ ...modules, - peerId: await createSecp256k1PeerId(), + peerId, + nodeId: computeNodeId(peerId), opts: { ...defaultNetworkOptions, maxPeers: 1,