-
-
Notifications
You must be signed in to change notification settings - Fork 306
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
Implement light-client spec tests #4908
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
87d7f3a
Implement light-client spec tests
dapplion 9535ba3
Pick all fork epochs
dapplion f5ed5a0
Re-use spec code
dapplion eff9426
Fix processor logic
dapplion a7b081e
Be compatible with spec tests
dapplion 4b7bc28
Prune data structures
dapplion b4f81ee
Intercept store set
dapplion 445bf47
FIx lightclient sync test
dapplion 1094788
Use MAX_CLOCK_DISPARITY_SEC in currentSlot
dapplion 1296db8
Update validateLightClientBootstrap.ts
dapplion 1170bdd
Update index.ts
dapplion 9b68d7d
Update sync.ts
dapplion 07aef96
Merge branch 'unstable' into dapplion/lightclient-spec-tests
dapplion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/beacon-node/test/spec/presets/light_client/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {TestRunnerFn} from "../../utils/types.js"; | ||
import {singleMerkleProof} from "./single_merkle_proof.js"; | ||
import {sync} from "./sync.js"; | ||
import {updateRanking} from "./update_ranking.js"; | ||
|
||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
|
||
export const lightClient: TestRunnerFn<any, any> = (fork, testName, testSuite) => { | ||
const testFn = lightclientTestFns[testName]; | ||
if (testFn === undefined) { | ||
throw Error(`Unknown lightclient test ${testName}`); | ||
} | ||
|
||
return testFn(fork, testName, testSuite); | ||
}; | ||
|
||
const lightclientTestFns: Record<string, TestRunnerFn<any, any>> = { | ||
single_merkle_proof: singleMerkleProof, | ||
sync: sync, | ||
update_ranking: updateRanking, | ||
}; |
57 changes: 57 additions & 0 deletions
57
packages/beacon-node/test/spec/presets/light_client/single_merkle_proof.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import {expect} from "chai"; | ||
import {RootHex, ssz} from "@lodestar/types"; | ||
import {InputType} from "@lodestar/spec-test-util"; | ||
import {ForkName} from "@lodestar/params"; | ||
import {Tree} from "@chainsafe/persistent-merkle-tree"; | ||
import {TreeViewDU, Type} from "@chainsafe/ssz"; | ||
import {toHex} from "@lodestar/utils"; | ||
import {TestRunnerFn} from "../../utils/types.js"; | ||
|
||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
|
||
// https://github.com/ethereum/consensus-specs/blob/da3f5af919be4abb5a6db5a80b235deb8b4b5cba/tests/formats/light_client/single_merkle_proof.md | ||
type SingleMerkleProofTestCase = { | ||
meta?: any; | ||
object: TreeViewDU<any>; | ||
// leaf: Bytes32 # string, hex encoded, with 0x prefix | ||
// leaf_index: int # integer, decimal | ||
// branch: list of Bytes32 # list, each element is a string, hex encoded, with 0x prefix | ||
proof: { | ||
leaf: RootHex; | ||
leaf_index: bigint; | ||
branch: RootHex[]; | ||
}; | ||
}; | ||
|
||
export const singleMerkleProof: TestRunnerFn<SingleMerkleProofTestCase, RootHex[]> = (fork, testHandler, testSuite) => { | ||
return { | ||
testFunction: (testcase) => { | ||
// Assert correct proof generation | ||
const branch = new Tree(testcase.object.node).getSingleProof(testcase.proof.leaf_index); | ||
return branch.map(toHex); | ||
}, | ||
options: { | ||
inputTypes: { | ||
object: InputType.SSZ_SNAPPY, | ||
proof: InputType.YAML, | ||
}, | ||
sszTypes: { | ||
object: getObjectType(fork, testSuite), | ||
}, | ||
getExpected: (testCase) => testCase.proof.branch, | ||
expectFunc: (testCase, expected, actual) => { | ||
expect(actual).deep.equals(expected); | ||
}, | ||
// Do not manually skip tests here, do it in packages/beacon-node/test/spec/presets/index.test.ts | ||
}, | ||
}; | ||
}; | ||
|
||
function getObjectType(fork: ForkName, objectName: string): Type<unknown> { | ||
switch (objectName) { | ||
case "BeaconState": | ||
return ssz[fork].BeaconState; | ||
default: | ||
throw Error(`Unknown objectName ${objectName}`); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it safe to assume the finalised header slot will always be the first slot at the epoch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this very specific case, IMO yes. That
finalizedHeaderSlot
is used only to break ties in the is_better_update function. If the finalized checkpoint advances is extremely unlikely that the referenced block's slot does not increase. Even if it didn't the consequence is just persisting a slightly different update under some circumstances