From 492543a007e73c8bdd51c2aeaff198952679737d Mon Sep 17 00:00:00 2001 From: Kim De Mey Date: Mon, 2 Oct 2023 11:41:11 +0200 Subject: [PATCH] Fix and enable optimistic/finality update portal network test (#1794) --- .../test_beacon_light_client_network.nim | 123 +++++++++--------- 1 file changed, 61 insertions(+), 62 deletions(-) diff --git a/fluffy/tests/beacon_light_client_tests/test_beacon_light_client_network.nim b/fluffy/tests/beacon_light_client_tests/test_beacon_light_client_network.nim index fa3a1281f..998aa3fba 100644 --- a/fluffy/tests/beacon_light_client_tests/test_beacon_light_client_network.nim +++ b/fluffy/tests/beacon_light_client_tests/test_beacon_light_client_network.nim @@ -65,80 +65,79 @@ procSuite "Beacon Light Client Content Network": await lcNode2.stop() asyncTest "Get latest optimistic and finality updates": - skip() - # let - # lcNode1 = newLCNode(rng, 20302) - # lcNode2 = newLCNode(rng, 20303) - # forkDigests = testForkDigests + let + lcNode1 = newLCNode(rng, 20302) + lcNode2 = newLCNode(rng, 20303) + forkDigests = testForkDigests - # check: - # lcNode1.portalProtocol().addNode(lcNode2.localNode()) == Added - # lcNode2.portalProtocol().addNode(lcNode1.localNode()) == Added + check: + lcNode1.portalProtocol().addNode(lcNode2.localNode()) == Added + lcNode2.portalProtocol().addNode(lcNode1.localNode()) == Added - # (await lcNode1.portalProtocol().ping(lcNode2.localNode())).isOk() - # (await lcNode2.portalProtocol().ping(lcNode1.localNode())).isOk() + (await lcNode1.portalProtocol().ping(lcNode2.localNode())).isOk() + (await lcNode2.portalProtocol().ping(lcNode1.localNode())).isOk() - # let - # finalityUpdateData = SSZ.decode( - # lightClientFinalityUpdateBytes, altair.LightClientFinalityUpdate) - # finalityUpdate = ForkedLightClientFinalityUpdate( - # kind: LightClientDataFork.Altair, altairData: finalityUpdateData) - # finalizedHeaderSlot = finalityUpdateData.finalized_header.beacon.slot - # finalizedOptimisticHeaderSlot = - # finalityUpdateData.attested_header.beacon.slot + let + finalityUpdateData = SSZ.decode( + lightClientFinalityUpdateBytes, altair.LightClientFinalityUpdate) + finalityUpdate = ForkedLightClientFinalityUpdate( + kind: LightClientDataFork.Altair, altairData: finalityUpdateData) + finalizedHeaderSlot = finalityUpdateData.finalized_header.beacon.slot + finalizedOptimisticHeaderSlot = + finalityUpdateData.attested_header.beacon.slot - # optimisticUpdateData = SSZ.decode( - # lightClientOptimisticUpdateBytes, altair.LightClientOptimisticUpdate) - # optimisticUpdate = ForkedLightClientOptimisticUpdate( - # kind: LightClientDataFork.Altair, altairData: optimisticUpdateData) - # optimisticHeaderSlot = optimisticUpdateData.attested_header.beacon.slot + optimisticUpdateData = SSZ.decode( + lightClientOptimisticUpdateBytes, altair.LightClientOptimisticUpdate) + optimisticUpdate = ForkedLightClientOptimisticUpdate( + kind: LightClientDataFork.Altair, altairData: optimisticUpdateData) + optimisticHeaderSlot = optimisticUpdateData.attested_header.beacon.slot - # finalityUpdateKey = finalityUpdateContentKey( - # distinctBase(finalizedHeaderSlot), - # distinctBase(finalizedOptimisticHeaderSlot) - # ) - # finalityKeyEnc = encode(finalityUpdateKey) - # finalityUpdateId = toContentId(finalityKeyEnc) + finalityUpdateKey = finalityUpdateContentKey( + distinctBase(finalizedHeaderSlot), + distinctBase(finalizedOptimisticHeaderSlot) + ) + finalityKeyEnc = encode(finalityUpdateKey) + finalityUpdateId = toContentId(finalityKeyEnc) - # optimistUpdateKey = optimisticUpdateContentKey( - # distinctBase(optimisticHeaderSlot)) - # optimisticKeyEnc = encode(optimistUpdateKey) - # optimisticUpdateId = toContentId(optimisticKeyEnc) + optimisticUpdateKey = optimisticUpdateContentKey( + distinctBase(optimisticHeaderSlot)) + optimisticKeyEnc = encode(optimisticUpdateKey) + optimisticUpdateId = toContentId(optimisticKeyEnc) - # # This silently assumes that peer stores only one latest update, under - # # the contentId coresponding to latest update content key - # lcNode2.portalProtocol().storeContent( - # finalityKeyEnc, - # finalityUpdateId, - # encodeForkedLightClientObject(finalityUpdate, forkDigests.altair) - # ) + # This silently assumes that peer stores only one latest update, under + # the contentId coresponding to latest update content key + lcNode2.portalProtocol().storeContent( + finalityKeyEnc, + finalityUpdateId, + encodeForkedLightClientObject(finalityUpdate, forkDigests.altair) + ) - # lcNode2.portalProtocol().storeContent( - # optimisticKeyEnc, - # optimisticUpdateId, - # encodeForkedLightClientObject(optimisticUpdate, forkDigests.altair) - # ) + lcNode2.portalProtocol().storeContent( + optimisticKeyEnc, + optimisticUpdateId, + encodeForkedLightClientObject(optimisticUpdate, forkDigests.altair) + ) - # let - # finalityResult = - # await lcNode1.lightClientNetwork.getLightClientFinalityUpdate( - # distinctBase(finalizedHeaderSlot) - 1, - # distinctBase(finalizedOptimisticHeaderSlot) - 1 - # ) - # optimisticResult = - # await lcNode1.lightClientNetwork.getLightClientOptimisticUpdate( - # distinctBase(optimisticHeaderSlot) - 1 - # ) + let + finalityResult = + await lcNode1.lightClientNetwork.getLightClientFinalityUpdate( + distinctBase(finalizedHeaderSlot), + distinctBase(finalizedOptimisticHeaderSlot) + ) + optimisticResult = + await lcNode1.lightClientNetwork.getLightClientOptimisticUpdate( + distinctBase(optimisticHeaderSlot) + ) - # check: - # finalityResult.isOk() - # optimisticResult.isOk() - # finalityResult.get().altairData == finalityUpdate.altairData - # optimisticResult.get().altairData == optimisticUpdate.altairData + check: + finalityResult.isOk() + optimisticResult.isOk() + finalityResult.get().altairData == finalityUpdate.altairData + optimisticResult.get().altairData == optimisticUpdate.altairData - # await lcNode1.stop() - # await lcNode2.stop() + await lcNode1.stop() + await lcNode2.stop() asyncTest "Get range of light client updates": let