-
-
Notifications
You must be signed in to change notification settings - Fork 323
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
feat: use napi-rs pubkey-index-map #7091
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map"; | ||
import {routes} from "@lodestar/api"; | ||
import {FAR_FUTURE_EPOCH, GENESIS_SLOT} from "@lodestar/params"; | ||
import {BeaconStateAllForks, PubkeyIndexMap} from "@lodestar/state-transition"; | ||
import {BeaconStateAllForks} from "@lodestar/state-transition"; | ||
import {BLSPubkey, Epoch, phase0, RootHex, Slot, ValidatorIndex} from "@lodestar/types"; | ||
import {fromHex} from "@lodestar/utils"; | ||
import {CheckpointWithHex, IForkChoice} from "@lodestar/fork-choice"; | ||
|
@@ -187,7 +188,7 @@ export function getStateValidatorIndex( | |
|
||
// typeof id === Uint8Array | ||
const validatorIndex = pubkey2index.get(id); | ||
if (validatorIndex === undefined) { | ||
if (validatorIndex === null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its a little annoying that the return type is changed from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is generated by napi-rs so I just follow the interface there https://github.com/ChainSafe/pubkey-index-map/blob/b2f2ba42850aaf131559c8790174260e996b475a/index.d.ts#L9 we can have a proxy map to return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, lets just keep it as is, returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also tend to like |
||
return {valid: false, code: 404, reason: "Validator pubkey not found in state"}; | ||
} | ||
if (validatorIndex >= state.validators.length) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import {itBench, setBenchOpts} from "@dapplion/benchmark"; | ||
import {Map} from "immutable"; | ||
import {Map as ImmutableMap} from "immutable"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good change. We should not shadow namespaces |
||
import {toBufferBE} from "bigint-buffer"; | ||
import {digest} from "@chainsafe/as-sha256"; | ||
import {SecretKey} from "@chainsafe/blst"; | ||
import {ssz} from "@lodestar/types"; | ||
import {type CachedBeaconStateAllForks, PubkeyIndexMap} from "@lodestar/state-transition"; | ||
import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map"; | ||
import {ValidatorIndex, ssz} from "@lodestar/types"; | ||
import {type CachedBeaconStateAllForks, toMemoryEfficientHexStr} from "@lodestar/state-transition"; | ||
import {bytesToBigInt, intToBytes} from "@lodestar/utils"; | ||
import {InMemoryCheckpointStateCache, BlockStateCacheImpl} from "../../../../src/chain/stateCache/index.js"; | ||
import {BlockStateCache} from "../../../../src/chain/stateCache/types.js"; | ||
|
@@ -31,7 +32,7 @@ describe("updateUnfinalizedPubkeys perf tests", function () { | |
itBench({ | ||
id: `updateUnfinalizedPubkeys - updating ${numPubkeysToBeFinalized} pubkeys`, | ||
beforeEach: async () => { | ||
baseState.epochCtx.unfinalizedPubkey2index = Map(unfinalizedPubkey2Index.map); | ||
baseState.epochCtx.unfinalizedPubkey2index = ImmutableMap(unfinalizedPubkey2Index); | ||
baseState.epochCtx.pubkey2index = new PubkeyIndexMap(); | ||
baseState.epochCtx.index2pubkey = []; | ||
|
||
|
@@ -80,12 +81,14 @@ describe("updateUnfinalizedPubkeys perf tests", function () { | |
}); | ||
} | ||
|
||
function generatePubkey2Index(startIndex: number, endIndex: number): PubkeyIndexMap { | ||
const pubkey2Index = new PubkeyIndexMap(); | ||
type PubkeyHex = string; | ||
|
||
function generatePubkey2Index(startIndex: number, endIndex: number): Map<PubkeyHex, ValidatorIndex> { | ||
const pubkey2Index = new Map<string, number>(); | ||
const pubkeys = generatePubkeys(endIndex - startIndex); | ||
|
||
for (let i = startIndex; i < endIndex; i++) { | ||
pubkey2Index.set(pubkeys[i], i); | ||
pubkey2Index.set(toMemoryEfficientHexStr(pubkeys[i]), i); | ||
} | ||
|
||
return pubkey2Index; | ||
|
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.
soo nice that we dont need to stringify anymore!!! rust for the win!