-
-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LightClient server no state cache + tracks head (#3461)
* WIP * Refactor lightclient server db repositories * WIP Lightclient refactor * Lightclient tracking head * Fix branch proof sorting * Move lightclient code to package root * Move LightclientServer code to module index * Add e2e test and fix bugs * Log sync committee periods * Sync 3 periods * Clean logging in LC * Fix broken tests * Rename getCommitteeUpdates route * Use getStateV2 to download altair states * Remove blockRoot from LightclientHeaderUpdate * Polish lightclient * Remove clock * Remove beacon state transition dependency * Add mock sync test * Change getStateProof to GET * Deprecate un-used db buckets * Test fetching proofs on lightclient head state * Test fetching proofs in sim test * Test query serializtion * Fix proof paths serdes in api * Use Promise.all in storeSyncCommittee * Rename finalizedHeader to checkpointHeader * Remove genesisWitness * Remove genesis proof dead code * Rename lightclient_update to lightclient_header_update * Pass only checkpoint root * Use console levels in getLcLoggerConsole * Remove stateProofPaths dead code * Rename to initializeFromCheckpointRoot * lightclient snapshot type has a single SyncCommittee * Simplify tree position constants * Log 'New sync committee period' message only once
- Loading branch information
Showing
81 changed files
with
2,891 additions
and
2,013 deletions.
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
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
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
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,45 @@ | ||
import {Path} from "@chainsafe/ssz"; | ||
|
||
/** | ||
* Serialize proof path to JSON. | ||
* @param paths `[["finalized_checkpoint", 0, "root", 12000]]` | ||
* @returns `['["finalized_checkpoint",0,"root",12000]']` | ||
*/ | ||
export function querySerializeProofPathsArr(paths: Path[]): string[] { | ||
return paths.map((path) => JSON.stringify(path)); | ||
} | ||
|
||
/** | ||
* Deserialize JSON proof path to proof path | ||
* @param pathStrs `['["finalized_checkpoint",0,"root",12000]']` | ||
* @returns `[["finalized_checkpoint", 0, "root", 12000]]` | ||
*/ | ||
export function queryParseProofPathsArr(pathStrs: string | string[]): Path[] { | ||
if (Array.isArray(pathStrs)) { | ||
return pathStrs.map((pathStr) => queryParseProofPaths(pathStr)); | ||
} else { | ||
return [queryParseProofPaths(pathStrs) as Path]; | ||
} | ||
} | ||
|
||
/** | ||
* Deserialize single JSON proof path to proof path | ||
* @param pathStr `'["finalized_checkpoint",0,"root",12000]'` | ||
* @returns `["finalized_checkpoint", 0, "root", 12000]` | ||
*/ | ||
export function queryParseProofPaths(pathStr: string): Path { | ||
const path = JSON.parse(pathStr) as Path; | ||
|
||
if (!Array.isArray(path)) { | ||
throw Error("Proof pathStr is not an array"); | ||
} | ||
|
||
for (let i = 0; i < path.length; i++) { | ||
const elType = typeof path[i]; | ||
if (elType !== "string" && elType !== "number") { | ||
throw Error(`Proof pathStr[${i}] not string or number`); | ||
} | ||
} | ||
|
||
return path; | ||
} |
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
Oops, something went wrong.