Skip to content

Commit

Permalink
New ssz, persistent-merkle-tree and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed Aug 31, 2021
1 parent 5410ecf commit fa28b64
Show file tree
Hide file tree
Showing 22 changed files with 41 additions and 40 deletions.
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"@chainsafe/lodestar-params": "^0.29.1",
"@chainsafe/lodestar-types": "^0.29.1",
"@chainsafe/lodestar-utils": "^0.29.1",
"@chainsafe/persistent-merkle-tree": "^0.3.5",
"@chainsafe/ssz": "^0.8.15",
"@chainsafe/persistent-merkle-tree": "^0.3.7",
"@chainsafe/ssz": "^0.8.17",
"cross-fetch": "^3.1.4",
"eventsource": "^1.1.0",
"qs": "^6.10.1"
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/routes/beacon/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export function getReturnTypes(): ReturnTypes<Api> {
const ValidatorResponse = new ContainerType<ValidatorResponse>({
fields: {
index: ssz.ValidatorIndex,
balance: ssz.Gwei,
balance: ssz.Number64,
status: new StringType<ValidatorStatus>(),
validator: ssz.phase0.Validator,
},
Expand All @@ -246,7 +246,7 @@ export function getReturnTypes(): ReturnTypes<Api> {
const ValidatorBalance = new ContainerType<ValidatorBalance>({
fields: {
index: ssz.ValidatorIndex,
balance: ssz.Gwei,
balance: ssz.Number64,
},
});

Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/unit/beacon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {runGenericServerTest} from "../utils/genericServerTest";

describe("beacon", () => {
const root = Buffer.alloc(32, 1);
const balance = BigInt(32e9);
const balance = 32e9;
const pubkeyHex = toHexString(Buffer.alloc(48, 1));

const blockHeaderResponse: BlockHeaderResponse = {
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-state-transition/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
"@chainsafe/lodestar-params": "^0.29.1",
"@chainsafe/lodestar-types": "^0.29.1",
"@chainsafe/lodestar-utils": "^0.29.1",
"@chainsafe/persistent-merkle-tree": "^0.3.5",
"@chainsafe/persistent-merkle-tree": "^0.3.7",
"@chainsafe/persistent-ts": "^0.19.0",
"@chainsafe/ssz": "^0.8.15",
"@chainsafe/ssz": "^0.8.17",
"bigint-buffer": "^1.1.5",
"buffer-xor": "^2.0.2"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export function processEffectiveBalanceUpdates(
epochProcess.balances.forEach((balanceNbr: number, i: number) => {
// TODO: effectiveBalance as number
const balance = BigInt(balanceNbr);
let effectiveBalance = epochProcess.validators[i].effectiveBalance;
const validator = epochProcess.validators[i];
let effectiveBalance = validator.effectiveBalance;
if (
// Too big
effectiveBalance > balance + DOWNWARD_THRESHOLD ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ export class BalanceList implements List<number> {
}

applyDelta(index: number, delta: number): number {
return this.type.tree_applyUint64Delta(this.tree, index, delta);
return this.type.tree_applyDeltaAtIndex(this.tree, index, delta);
}

applyDeltaInBatch(deltaByIndex: Map<number, number>): void {
this.type.tree_applyUint64DeltaInBatch(this.tree, deltaByIndex);
this.type.tree_applyDeltaInBatch(this.tree, deltaByIndex);
}

/** Return the new balances */
updateAll(deltas: number[]): number[] {
const [node, newBalances] = this.type.tree_newTreeFromUint64Deltas(this.tree, deltas);
this.tree.rootNode = node;
const [newTree, newBalances] = this.type.tree_newTreeFromDeltas(this.tree, deltas);
this.tree.rootNode = newTree.rootNode;
this.type.tree_setLength(this.tree, newBalances.length);
return newBalances;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export interface IEpochProcess {

statuses: IAttesterStatus[];
validators: phase0.Validator[];
balances?: BigUint64Array;
balances?: number[];
/**
* Active validator indices for currentEpoch + 2.
* This is only used in `afterProcessEpoch` to compute epoch shuffling, it's not efficient to calculate it at that time
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@chainsafe/lodestar-types": "^0.29.1",
"@chainsafe/lodestar-utils": "^0.29.1",
"@chainsafe/lodestar-validator": "^0.29.2",
"@chainsafe/ssz": "^0.8.15",
"@chainsafe/ssz": "^0.8.17",
"@types/lockfile": "^1.0.1",
"bip39": "^3.0.2",
"deepmerge": "^3.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
"dependencies": {
"@chainsafe/lodestar-params": "^0.29.1",
"@chainsafe/lodestar-types": "^0.29.1",
"@chainsafe/ssz": "^0.8.15"
"@chainsafe/ssz": "^0.8.17"
}
}
2 changes: 1 addition & 1 deletion packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"dependencies": {
"@chainsafe/lodestar-config": "^0.29.1",
"@chainsafe/lodestar-utils": "^0.29.1",
"@chainsafe/ssz": "^0.8.15",
"@chainsafe/ssz": "^0.8.17",
"it-all": "^1.0.2",
"level": "^6.0.1",
"levelup": "^4.4.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/fork-choice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@chainsafe/lodestar-params": "^0.29.1",
"@chainsafe/lodestar-types": "^0.29.1",
"@chainsafe/lodestar-utils": "^0.29.1",
"@chainsafe/ssz": "^0.8.15"
"@chainsafe/ssz": "^0.8.17"
},
"keywords": [
"ethereum",
Expand Down
4 changes: 2 additions & 2 deletions packages/light-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"@chainsafe/lodestar-params": "^0.29.1",
"@chainsafe/lodestar-types": "^0.29.1",
"@chainsafe/lodestar-utils": "^0.29.1",
"@chainsafe/persistent-merkle-tree": "^0.3.5",
"@chainsafe/ssz": "^0.8.15",
"@chainsafe/persistent-merkle-tree": "^0.3.7",
"@chainsafe/ssz": "^0.8.17",
"cross-fetch": "^3.1.4",
"mitt": "^2.1.0"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/light-client/test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {PointFormat, PublicKey, SecretKey, Signature} from "@chainsafe/bls";
import {computeDomain, computeSigningRoot, interopSecretKey} from "@chainsafe/lodestar-beacon-state-transition";
import {DOMAIN_SYNC_COMMITTEE, SYNC_COMMITTEE_SIZE} from "@chainsafe/lodestar-params";
import {altair, Bytes4, Gwei, Root, Slot, ssz, SyncPeriod} from "@chainsafe/lodestar-types";
import {altair, Bytes4, Root, Slot, ssz, SyncPeriod} from "@chainsafe/lodestar-types";
import {fromHexString, List} from "@chainsafe/ssz";
import {SyncCommitteeFast} from "../src/client/types";

Expand Down Expand Up @@ -102,6 +102,6 @@ export function generateValidators(n: number, opts?: Partial<altair.Validator>):
return Array.from({length: n}, () => generateValidator(opts)) as List<altair.Validator>;
}

export function generateBalances(n: number): List<Gwei> {
return Array.from({length: n}, () => BigInt(32000000000)) as List<Gwei>;
export function generateBalances(n: number): List<number> {
return Array.from({length: n}, () => 32e9) as List<number>;
}
4 changes: 2 additions & 2 deletions packages/lodestar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
"@chainsafe/lodestar-types": "^0.29.1",
"@chainsafe/lodestar-utils": "^0.29.1",
"@chainsafe/lodestar-validator": "^0.29.2",
"@chainsafe/persistent-merkle-tree": "^0.3.5",
"@chainsafe/persistent-merkle-tree": "^0.3.7",
"@chainsafe/snappy-stream": "5.0.0",
"@chainsafe/ssz": "^0.8.15",
"@chainsafe/ssz": "^0.8.17",
"@ethersproject/abi": "^5.0.0",
"@types/datastore-level": "^1.1.1",
"bl": "^4.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/lodestar/test/utils/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export function generateState(
for (const key in opts) {
const newValue = opts[key as keyof TestBeaconState];
// eslint-disable-next-line
resultState[key as keyof TreeBacked<allForks.BeaconState>] = (newValue as unknown) as any;
resultState[key as keyof TestBeaconState] = (newValue as unknown) as any;
}
return resultState;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/params/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"blockchain"
],
"dependencies": {
"@chainsafe/ssz": "^0.8.15",
"@chainsafe/ssz": "^0.8.17",
"js-yaml": "^3.13.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/spec-test-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@chainsafe/lodestar-types": "^0.29.1",
"@chainsafe/lodestar-utils": "^0.29.1",
"@chainsafe/lodestar-validator": "^0.29.2",
"@chainsafe/ssz": "^0.8.15",
"@chainsafe/ssz": "^0.8.17",
"@types/yargs": "^13.0.2"
},
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion packages/spec-test-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
],
"dependencies": {
"@chainsafe/lodestar-utils": "^0.29.1",
"@chainsafe/ssz": "^0.8.15",
"@chainsafe/ssz": "^0.8.17",
"axios": "^0.21.0",
"chai": "^4.2.0",
"mocha": "^8.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"types": "lib/index.d.ts",
"dependencies": {
"@chainsafe/lodestar-params": "^0.29.1",
"@chainsafe/ssz": "^0.8.15"
"@chainsafe/ssz": "^0.8.17"
},
"keywords": [
"ethereum",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"types": "lib/index.d.ts",
"dependencies": {
"@chainsafe/abort-controller": "^3.0.1",
"@chainsafe/ssz": "^0.8.15",
"@chainsafe/ssz": "^0.8.17",
"any-signal": "2.1.1",
"bigint-buffer": "^1.1.5",
"chalk": "^2.4.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@chainsafe/lodestar-params": "^0.29.1",
"@chainsafe/lodestar-types": "^0.29.1",
"@chainsafe/lodestar-utils": "^0.29.1",
"@chainsafe/ssz": "^0.8.15",
"@chainsafe/ssz": "^0.8.17",
"bigint-buffer": "^1.1.5"
},
"devDependencies": {
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,10 @@
protobufjs "^6.10.1"
uint8arrays "^3.0.0"

"@chainsafe/persistent-merkle-tree@^0.3.5":
version "0.3.5"
resolved "https://registry.yarnpkg.com/@chainsafe/persistent-merkle-tree/-/persistent-merkle-tree-0.3.5.tgz#39ae7e266b8029b4e227b8f46b3757960253d47f"
integrity sha512-DOwTdY5q2YVhBBKZj8zZWydGrFNIvLgTPD6Vh3prjiX4Hk1VvLosmtsSGryaYkgFXKWQrPPtKO8RfPuTMmvTyQ==
"@chainsafe/persistent-merkle-tree@^0.3.7":
version "0.3.7"
resolved "https://registry.yarnpkg.com/@chainsafe/persistent-merkle-tree/-/persistent-merkle-tree-0.3.7.tgz#d257674fcacf1770e54df1e7e476bb55efcb3ed4"
integrity sha512-UXXzvCN8P4eQWCsaTaHRrNa+2sTwY3NB0Vf+uWgM4cU1qf8LOsTU7aU2CeXFAGJag5W/xEQfVGNh463kXTYAgg==
dependencies:
"@chainsafe/as-sha256" "^0.2.3"

Expand All @@ -503,13 +503,13 @@
buffer-from "^1.1.1"
snappy "^6.3.5"

"@chainsafe/ssz@^0.8.15":
version "0.8.15"
resolved "https://registry.yarnpkg.com/@chainsafe/ssz/-/ssz-0.8.15.tgz#fdc90c28f193c91cfd3fcfc8d4c7bef2467ea9d1"
integrity sha512-iEUbzGglqZ6VLKYDbiHkndbyHPyXhSK2iAwWC1lcqQvGeB0fTCGVbuQzQNQJusFYkyKqnBfSl4iU1f+Fw9cdFQ==
"@chainsafe/ssz@^0.8.17":
version "0.8.17"
resolved "https://registry.yarnpkg.com/@chainsafe/ssz/-/ssz-0.8.17.tgz#5c96271b7b73fd195d5ebdb4f3c910b199609156"
integrity sha512-PIw+FiFBdHmLfOA7AX19ydA9wVXhzfZeqiWKrWse4xiQ8GSaWXqpNwWwD2AX84cdJAypuP/Byve/UDymNO6bPg==
dependencies:
"@chainsafe/as-sha256" "^0.2.4"
"@chainsafe/persistent-merkle-tree" "^0.3.5"
"@chainsafe/persistent-merkle-tree" "^0.3.7"
case "^1.6.3"

"@dabh/diagnostics@^2.0.2":
Expand Down

0 comments on commit fa28b64

Please sign in to comment.