Skip to content

Commit

Permalink
chore: rebase fixes
Browse files Browse the repository at this point in the history
lint

lint and type fix

update spec version

fix tests

fix spec test
  • Loading branch information
g11tech committed Aug 1, 2024
1 parent 580e593 commit 1ffa8b5
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 33 deletions.
5 changes: 5 additions & 0 deletions packages/api/test/unit/beacon/oapiSpec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ const ignoredTopics = [
topic block_gossip not implemented
*/
"block_gossip",

// Modified in electra to include version
// should be removed from the ignore list after spec update
"attestation",
"attester_slashing",
];

// eventstream types are defined as comments in the description of "examples".
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/src/api/impl/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
VERSIONED_HASH_VERSION_KZG,
COMPOUNDING_WITHDRAWAL_PREFIX,
DOMAIN_CONSOLIDATION,
UNSET_DEPOSIT_RECEIPTS_START_INDEX,
UNSET_DEPOSIT_REQUESTS_START_INDEX,
FULL_EXIT_REQUEST_AMOUNT,
} from "@lodestar/params";

Expand Down Expand Up @@ -108,6 +108,6 @@ export const specConstants = {
VERSIONED_HASH_VERSION_KZG,

// electra
UNSET_DEPOSIT_RECEIPTS_START_INDEX,
UNSET_DEPOSIT_REQUESTS_START_INDEX,
FULL_EXIT_REQUEST_AMOUNT,
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {aggregateSignatures} from "@chainsafe/blst";
import {Signature} from "@chainsafe/bls/types";
import {aggregateSignatures, Signature} from "@chainsafe/blst";
import {BitArray, toHexString} from "@chainsafe/ssz";
import {
ForkName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {PublicKey} from "@chainsafe/bls/types";
import {PublicKey} from "@chainsafe/blst";
import {DOMAIN_AGGREGATE_AND_PROOF, ForkSeq} from "@lodestar/params";
import {ssz, SignedAggregateAndProof} from "@lodestar/types";
import {Epoch} from "@lodestar/types";
Expand Down
2 changes: 0 additions & 2 deletions packages/beacon-node/src/execution/engine/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,4 @@ export interface IExecutionEngine {
getPayloadBodiesByHash(fork: ForkName, blockHash: DATA[]): Promise<(ExecutionPayloadBody | null)[]>;

getPayloadBodiesByRange(fork: ForkName, start: number, count: number): Promise<(ExecutionPayloadBody | null)[]>;

getState(): ExecutionEngineState;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import {itBench, setBenchOpts} from "@dapplion/benchmark";
import {Map} from "immutable";
import {toBufferBE} from "bigint-buffer";
import {digest} from "@chainsafe/as-sha256";
import type {SecretKey} from "@chainsafe/bls/types";
import bls from "@chainsafe/bls";
import {SecretKey} from "@chainsafe/blst";
import {ssz} from "@lodestar/types";
import {type CachedBeaconStateAllForks, PubkeyIndexMap} from "@lodestar/state-transition";
import {bytesToBigInt, intToBytes} from "@lodestar/utils";
Expand Down Expand Up @@ -106,6 +105,7 @@ describe("updateUnfinalizedPubkeys perf tests", function () {

function generatePrivateKey(index: number): SecretKey {
const secretKeyBytes = toBufferBE(bytesToBigInt(digest(intToBytes(index, 32))) % BigInt("38581184513"), 32);
return bls.SecretKey.fromBytes(secretKeyBytes);
const secret: SecretKey = SecretKey.fromBytes(secretKeyBytes);
return secret;
}
});
4 changes: 2 additions & 2 deletions packages/beacon-node/test/sim/electra-interop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import assert from "node:assert";
import {describe, it, vi, afterAll, afterEach} from "vitest";

import {LogLevel, sleep} from "@lodestar/utils";
import {ForkName, SLOTS_PER_EPOCH, UNSET_DEPOSIT_RECEIPTS_START_INDEX} from "@lodestar/params";
import {ForkName, SLOTS_PER_EPOCH, UNSET_DEPOSIT_REQUESTS_START_INDEX} from "@lodestar/params";
import {electra, Epoch, Slot} from "@lodestar/types";
import {ValidatorProposerConfig} from "@lodestar/validator";

Expand Down Expand Up @@ -431,7 +431,7 @@ describe("executionEngine / ExecutionEngineHttp", function () {
throw Error("Historical validator length for epoch 1 or 2 is not dropped properly");
}

if (headState.depositRequestsStartIndex === UNSET_DEPOSIT_RECEIPTS_START_INDEX) {
if (headState.depositRequestsStartIndex === UNSET_DEPOSIT_REQUESTS_START_INDEX) {
throw Error("state.depositRequestsStartIndex is not set upon processing new deposit receipt");
}

Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/test/spec/presets/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ const operations: TestRunnerFn<OperationsTestCase, BeaconStateAllForks> = (fork,
sszTypes: {
pre: ssz[fork].BeaconState,
post: ssz[fork].BeaconState,
attestation: ssz.phase0.Attestation,
attester_slashing: ssz.phase0.AttesterSlashing,
attestation: sszTypesFor(fork).Attestation,
attester_slashing: sszTypesFor(fork).AttesterSlashing,
block: ssz[fork].BeaconBlock,
body: ssz[fork].BeaconBlockBody,
deposit: ssz.phase0.Deposit,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {BitArray, fromHexString, toHexString} from "@chainsafe/ssz";
import {describe, it, expect, beforeEach, beforeAll, afterEach, vi} from "vitest";
import {SecretKey, Signature, fastAggregateVerify} from "@chainsafe/blst";
import {SecretKey, Signature, fastAggregateVerify, aggregateSignatures} from "@chainsafe/blst";
import {CachedBeaconStateAllForks, newFilledArray} from "@lodestar/state-transition";
import {
FAR_FUTURE_EPOCH,
Expand Down Expand Up @@ -331,9 +331,9 @@ describe("MatchingDataAttestationGroup aggregateInto", function () {
});

describe("aggregateConsolidation", function () {
const sk0 = bls.SecretKey.fromBytes(Buffer.alloc(32, 1));
const sk1 = bls.SecretKey.fromBytes(Buffer.alloc(32, 2));
const sk2 = bls.SecretKey.fromBytes(Buffer.alloc(32, 3));
const sk0 = SecretKey.fromBytes(Buffer.alloc(32, 1));
const sk1 = SecretKey.fromBytes(Buffer.alloc(32, 2));
const sk2 = SecretKey.fromBytes(Buffer.alloc(32, 3));
const skArr = [sk0, sk1, sk2];
const testCases: {
name: string;
Expand Down Expand Up @@ -397,7 +397,7 @@ describe("aggregateConsolidation", function () {
expect(finalAttestation.aggregationBits.uint8Array).toEqual(new Uint8Array(expectedAggregationBits));
expect(finalAttestation.committeeBits.toBoolArray()).toEqual(expectedCommitteeBits);
expect(finalAttestation.data).toEqual(attData);
expect(finalAttestation.signature).toEqual(bls.Signature.aggregate(sigArr).toBytes());
expect(finalAttestation.signature).toEqual(aggregateSignatures(sigArr).toBytes());
});
}
});
2 changes: 1 addition & 1 deletion packages/params/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export const KZG_COMMITMENT_SUBTREE_INDEX0 = KZG_COMMITMENT_GINDEX0 - 2 ** KZG_C
export const BLOBSIDECAR_FIXED_SIZE = ACTIVE_PRESET === PresetName.minimal ? 131672 : 131928;

// Electra Misc
export const UNSET_DEPOSIT_RECEIPTS_START_INDEX = 2n ** 64n - 1n;
export const UNSET_DEPOSIT_REQUESTS_START_INDEX = 2n ** 64n - 1n;
export const FULL_EXIT_REQUEST_AMOUNT = 0;
export const NEXT_SYNC_COMMITTEE_GINDEX_ELECTRA = 87;
export const NEXT_SYNC_COMMITTEE_DEPTH_ELECTRA = 6;
Expand Down
5 changes: 5 additions & 0 deletions packages/params/test/unit/__snapshots__/forkName.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ exports[`forkName > should have valid allForks 1`] = `
"bellatrix",
"capella",
"deneb",
"electra",
]
`;

exports[`forkName > should have valid blobs forks 1`] = `
[
"deneb",
"electra",
]
`;

Expand All @@ -21,6 +23,7 @@ exports[`forkName > should have valid execution forks 1`] = `
"bellatrix",
"capella",
"deneb",
"electra",
]
`;

Expand All @@ -30,12 +33,14 @@ exports[`forkName > should have valid lightclient forks 1`] = `
"bellatrix",
"capella",
"deneb",
"electra",
]
`;

exports[`forkName > should have valid withdrawal forks 1`] = `
[
"capella",
"deneb",
"electra",
]
`;
3 changes: 1 addition & 2 deletions packages/state-transition/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@
"types": "lib/index.d.ts",
"dependencies": {
"@chainsafe/as-sha256": "^0.4.1",
"@chainsafe/bls": "7.1.3",
"@chainsafe/blst": "^0.2.11",
"@chainsafe/blst": "^2.0.3",
"@chainsafe/persistent-merkle-tree": "^0.7.1",
"@chainsafe/ssz": "^0.16.0",
"@lodestar/config": "^1.20.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/state-transition/src/block/processDeposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function isValidDepositSignature(
const publicKey = PublicKey.fromBytes(pubkey, true);
const signature = Signature.fromBytes(depositSignature, true);

return verify(signingRoot, publicKey, signature)
return verify(signingRoot, publicKey, signature);
} catch (e) {
return false; // Catch all BLS errors: failed key validation, failed signature validation, invalid signature
}
Expand Down
4 changes: 2 additions & 2 deletions packages/state-transition/src/block/processDepositRequest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {electra} from "@lodestar/types";
import {ForkSeq, UNSET_DEPOSIT_RECEIPTS_START_INDEX} from "@lodestar/params";
import {ForkSeq, UNSET_DEPOSIT_REQUESTS_START_INDEX} from "@lodestar/params";

import {CachedBeaconStateElectra} from "../types.js";
import {applyDeposit} from "./processDeposit.js";
Expand All @@ -9,7 +9,7 @@ export function processDepositRequest(
state: CachedBeaconStateElectra,
depositRequest: electra.DepositRequest
): void {
if (state.depositRequestsStartIndex === UNSET_DEPOSIT_RECEIPTS_START_INDEX) {
if (state.depositRequestsStartIndex === UNSET_DEPOSIT_REQUESTS_START_INDEX) {
state.depositRequestsStartIndex = BigInt(depositRequest.index);
}

Expand Down
10 changes: 5 additions & 5 deletions packages/state-transition/src/slot/upgradeStateToElectra.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Epoch, ValidatorIndex, ssz} from "@lodestar/types";
import {FAR_FUTURE_EPOCH, UNSET_DEPOSIT_RECEIPTS_START_INDEX} from "@lodestar/params";
import {FAR_FUTURE_EPOCH, UNSET_DEPOSIT_REQUESTS_START_INDEX} from "@lodestar/params";
import {CachedBeaconStateDeneb} from "../types.js";
import {CachedBeaconStateElectra, getCachedBeaconState} from "../cache/stateCache.js";
import {
Expand Down Expand Up @@ -59,8 +59,8 @@ export function upgradeStateToElectra(stateDeneb: CachedBeaconStateDeneb): Cache
stateElectraView.historicalSummaries = stateElectraCloned.historicalSummaries;

// latestExecutionPayloadHeader's depositRequestsRoot and withdrawalRequestsRoot set to zeros by default
// default value of depositRequestsStartIndex is UNSET_DEPOSIT_RECEIPTS_START_INDEX
stateElectraView.depositRequestsStartIndex = UNSET_DEPOSIT_RECEIPTS_START_INDEX;
// default value of depositRequestsStartIndex is UNSET_DEPOSIT_REQUESTS_START_INDEX
stateElectraView.depositRequestsStartIndex = UNSET_DEPOSIT_REQUESTS_START_INDEX;
stateElectraView.depositBalanceToConsume = BigInt(0);
stateElectraView.exitBalanceToConsume = BigInt(0);

Expand Down Expand Up @@ -138,8 +138,8 @@ export function upgradeStateToElectraOriginal(stateDeneb: CachedBeaconStateDeneb
});

// latestExecutionPayloadHeader's depositRequestsRoot and withdrawalRequestsRoot set to zeros by default
// default value of depositRequestsStartIndex is UNSET_DEPOSIT_RECEIPTS_START_INDEX
stateElectra.depositRequestsStartIndex = UNSET_DEPOSIT_RECEIPTS_START_INDEX;
// default value of depositRequestsStartIndex is UNSET_DEPOSIT_REQUESTS_START_INDEX
stateElectra.depositRequestsStartIndex = UNSET_DEPOSIT_REQUESTS_START_INDEX;

const validatorsArr = stateElectra.validators.getAllReadonly();

Expand Down
4 changes: 2 additions & 2 deletions packages/state-transition/src/util/genesis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
GENESIS_EPOCH,
GENESIS_SLOT,
MAX_EFFECTIVE_BALANCE,
UNSET_DEPOSIT_RECEIPTS_START_INDEX,
UNSET_DEPOSIT_REQUESTS_START_INDEX,
} from "@lodestar/params";
import {Bytes32, phase0, Root, ssz, TimeSeconds} from "@lodestar/types";

Expand Down Expand Up @@ -312,7 +312,7 @@ export function initializeBeaconStateFromEth1(
stateElectra.latestExecutionPayloadHeader =
(executionPayloadHeader as CompositeViewDU<typeof ssz.electra.ExecutionPayloadHeader>) ??
ssz.electra.ExecutionPayloadHeader.defaultViewDU();
stateElectra.depositRequestsStartIndex = UNSET_DEPOSIT_RECEIPTS_START_INDEX;
stateElectra.depositRequestsStartIndex = UNSET_DEPOSIT_REQUESTS_START_INDEX;
}

state.commit();
Expand Down
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3823,7 +3823,14 @@ agent-base@^7.1.1:
dependencies:
debug "^4.3.4"

agentkeepalive@^4.1.3, agentkeepalive@^4.2.1:
agentkeepalive@^4.1.3:
version "4.5.0"
resolved "https://registry.yarnpkg.com/agentkeepalive/-/agentkeepalive-4.5.0.tgz#2673ad1389b3c418c5a20c5d7364f93ca04be923"
integrity sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==
dependencies:
humanize-ms "^1.2.1"

agentkeepalive@^4.2.1:
version "4.2.1"
resolved "https://registry.yarnpkg.com/agentkeepalive/-/agentkeepalive-4.2.1.tgz#a7975cbb9f83b367f06c90cc51ff28fe7d499717"
integrity sha512-Zn4cw2NEqd+9fiSVWMscnjyQ1a8Yfoc5oBajLeo5w+YBHgDUcEBY2hS4YpTz6iN5f/2zQiktcuM6tS8x1p9dpA==
Expand Down

0 comments on commit 1ffa8b5

Please sign in to comment.