Skip to content
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

Use Uint8Array in config getDomain #3475

Merged
merged 1 commit into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions packages/config/src/genesisConfig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {ForkDigestHex, ICachedGenesis} from "./types";
export {IForkDigestContext} from "./types";

export function createICachedGenesis(chainForkConfig: IChainForkConfig, genesisValidatorsRoot: Root): ICachedGenesis {
const domainCache = new Map<ForkName, Map<DomainType, Buffer>>();
const domainCache = new Map<ForkName, Map<DomainType, Uint8Array>>();

const forkDigestByForkName = new Map<ForkName, ForkDigest>();
const forkDigestHexByForkName = new Map<ForkName, ForkDigestHex>();
Expand All @@ -22,11 +22,11 @@ export function createICachedGenesis(chainForkConfig: IChainForkConfig, genesisV
}

return {
getDomain(domainType: DomainType, slot: Slot): Buffer {
getDomain(domainType: DomainType, slot: Slot): Uint8Array {
const forkInfo = chainForkConfig.getForkInfo(slot);
let domainByType = domainCache.get(forkInfo.name);
if (!domainByType) {
domainByType = new Map<DomainType, Buffer>();
domainByType = new Map<DomainType, Uint8Array>();
domainCache.set(forkInfo.name, domainByType);
}
let domain = domainByType.get(domainType);
Expand Down Expand Up @@ -73,9 +73,12 @@ export function createICachedGenesis(chainForkConfig: IChainForkConfig, genesisV
};
}

function computeDomain(domainType: DomainType, forkVersion: Version, genesisValidatorRoot: Root): Buffer {
function computeDomain(domainType: DomainType, forkVersion: Version, genesisValidatorRoot: Root): Uint8Array {
const forkDataRoot = computeForkDataRoot(forkVersion, genesisValidatorRoot);
return Buffer.concat([domainType as Buffer, forkDataRoot.slice(0, 28)]);
const domain = new Uint8Array(32);
domain.set(domainType, 0);
domain.set(forkDataRoot.slice(0, 28), 4);
return domain;
}

function computeForkDataRoot(currentVersion: Version, genesisValidatorsRoot: Root): Uint8Array {
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/genesisConfig/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export interface IForkDigestContext {
}

export interface ICachedGenesis extends IForkDigestContext {
getDomain(domainType: DomainType, slot: Slot): Buffer;
getDomain(domainType: DomainType, slot: Slot): Uint8Array;
}