Skip to content

Commit

Permalink
fix the keymanager routes
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Jan 8, 2024
1 parent 0119cd9 commit bca1d63
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 10 deletions.
52 changes: 48 additions & 4 deletions packages/api/src/keymanager/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export type GasLimitData = {
pubkey: string;
gasLimit: number;
};
export type BuilderBoostFactorData = {
pubkey: string;
builderBoostFactor: bigint;
};

export type SignerDefinition = {
pubkey: PubkeyHex;
Expand Down Expand Up @@ -247,7 +251,10 @@ export type Api = {
>
>;

updateBuilderBoostFactor(
getBuilderBoostFactor(
pubkey: string
): Promise<ApiClientResponse<{[HttpStatusCode.OK]: {data: BuilderBoostFactorData}}>>;
setBuilderBoostFactor(
pubkey: string,
builderBoostFactor: bigint
): Promise<
Expand All @@ -256,6 +263,14 @@ export type Api = {
HttpStatusCode.UNAUTHORIZED | HttpStatusCode.FORBIDDEN | HttpStatusCode.NOT_FOUND
>
>;
deleteBuilderBoostFactor(
pubkey: string
): Promise<
ApiClientResponse<
{[HttpStatusCode.OK]: void; [HttpStatusCode.NO_CONTENT]: void},
HttpStatusCode.UNAUTHORIZED | HttpStatusCode.FORBIDDEN | HttpStatusCode.NOT_FOUND
>
>;

/**
* Create a signed voluntary exit message for an active validator, identified by a public key known to the validator
Expand Down Expand Up @@ -300,7 +315,9 @@ export const routesData: RoutesData<Api> = {
setGasLimit: {url: "/eth/v1/validator/{pubkey}/gas_limit", method: "POST", statusOk: 202},
deleteGasLimit: {url: "/eth/v1/validator/{pubkey}/gas_limit", method: "DELETE", statusOk: 204},

updateBuilderBoostFactor: {url: "/eth/v1/validator/{pubkey}/builder_boost_factor", method: "POST", statusOk: 202},
getBuilderBoostFactor: {url: "/eth/v1/validator/{pubkey}/builder_boost_factor", method: "GET"},
setBuilderBoostFactor: {url: "/eth/v1/validator/{pubkey}/builder_boost_factor", method: "POST", statusOk: 202},
deleteBuilderBoostFactor: {url: "/eth/v1/validator/{pubkey}/builder_boost_factor", method: "DELETE", statusOk: 204},

signVoluntaryExit: {url: "/eth/v1/validator/{pubkey}/voluntary_exit", method: "POST"},
};
Expand Down Expand Up @@ -338,7 +355,9 @@ export type ReqTypes = {
setGasLimit: {params: {pubkey: string}; body: {gas_limit: string}};
deleteGasLimit: {params: {pubkey: string}};

updateBuilderBoostFactor: {params: {pubkey: string}; body: {builder_boost_factor: string}};
getBuilderBoostFactor: {params: {pubkey: string}};
setBuilderBoostFactor: {params: {pubkey: string}; body: {builder_boost_factor: string}};
deleteBuilderBoostFactor: {params: {pubkey: string}};

signVoluntaryExit: {params: {pubkey: string}; query: {epoch?: number}};
};
Expand Down Expand Up @@ -437,7 +456,15 @@ export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
params: {pubkey: Schema.StringRequired},
},
},
updateBuilderBoostFactor: {

getBuilderBoostFactor: {
writeReq: (pubkey) => ({params: {pubkey}}),
parseReq: ({params: {pubkey}}) => [pubkey],
schema: {
params: {pubkey: Schema.StringRequired},
},
},
setBuilderBoostFactor: {
writeReq: (pubkey, builderBoostFactor) => ({
params: {pubkey},
body: {builder_boost_factor: builderBoostFactor.toString(10)},
Expand All @@ -448,6 +475,14 @@ export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
body: Schema.Object,
},
},
deleteBuilderBoostFactor: {
writeReq: (pubkey) => ({params: {pubkey}}),
parseReq: ({params: {pubkey}}) => [pubkey],
schema: {
params: {pubkey: Schema.StringRequired},
},
},

signVoluntaryExit: {
writeReq: (pubkey, epoch) => ({params: {pubkey}, query: epoch !== undefined ? {epoch} : {}}),
parseReq: ({params: {pubkey}, query: {epoch}}) => [pubkey, epoch],
Expand Down Expand Up @@ -480,6 +515,15 @@ export function getReturnTypes(): ReturnTypes<Api> {
{jsonCase: "eth2"}
)
),
getBuilderBoostFactor: ContainerData(
new ContainerType(
{
pubkey: stringType,
builderBoostFactor: ssz.UintBn64,
},
{jsonCase: "eth2"}
)
),
signVoluntaryExit: ContainerData(ssz.phase0.SignedVoluntaryExit),
};
}
Expand Down
14 changes: 11 additions & 3 deletions packages/api/test/unit/keymanager/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const pubkeyRand = "0x84105a985058fc8740a48bf1ede9d223ef09e8c6b1735ba0a55cf4a9ff
const ethaddressRand = "0xabcf8e0d4e9587369b2301d0790347320302cc09";
const graffitiRandUtf8 = "636861696e736166652f6c6f64657374";
const gasLimitRand = 30_000_000;
const builderBoostFactor = BigInt(100);
const builderBoostFactorRand = BigInt(100);

export const testData: GenericServerTestCases<Api> = {
listKeys: {
Expand Down Expand Up @@ -100,8 +100,16 @@ export const testData: GenericServerTestCases<Api> = {
args: [pubkeyRand, 1],
res: {data: ssz.phase0.SignedVoluntaryExit.defaultValue()},
},
updateBuilderBoostFactor: {
args: [pubkeyRand, builderBoostFactor],
getBuilderBoostFactor: {
args: [pubkeyRand],
res: {data: {pubkey: pubkeyRand, builderBoostFactor: builderBoostFactorRand}},
},
setBuilderBoostFactor: {
args: [pubkeyRand, builderBoostFactorRand],
res: undefined,
},
deleteBuilderBoostFactor: {
args: [pubkeyRand],
res: undefined,
},
};
18 changes: 16 additions & 2 deletions packages/cli/src/cmds/validator/keymanager/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,23 @@ export class KeymanagerApi implements Api {
};
}

async updateBuilderBoostFactor(pubkeyHex: string, builderBoostFactor: bigint): Promise<void> {
async getBuilderBoostFactor(pubkeyHex: string): ReturnType<Api["getBuilderBoostFactor"]> {
const builderBoostFactor = this.validator.validatorStore.getBuilderBoostFactor(pubkeyHex);
return {data: {pubkey: pubkeyHex, builderBoostFactor}};
}

async setBuilderBoostFactor(pubkeyHex: string, builderBoostFactor: bigint): Promise<void> {
this.checkIfProposerWriteEnabled();
this.validator.validatorStore.setBuilderBoostFactor(pubkeyHex, builderBoostFactor);
this.persistedKeysBackend.writeProposerConfig(
pubkeyHex,
this.validator.validatorStore.getProposerConfig(pubkeyHex)
);
}

async deleteBuilderBoostFactor(pubkeyHex: string): Promise<void> {
this.checkIfProposerWriteEnabled();
this.validator.validatorStore.updateBuilderBoostFactor(pubkeyHex, builderBoostFactor);
this.validator.validatorStore.deleteBuilderBoostFactor(pubkeyHex);
this.persistedKeysBackend.writeProposerConfig(
pubkeyHex,
this.validator.validatorStore.getProposerConfig(pubkeyHex)
Expand Down
18 changes: 17 additions & 1 deletion packages/validator/src/services/validatorStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,15 @@ export class ValidatorStore {
delete validatorData.builder?.gasLimit;
}

updateBuilderBoostFactor(pubkeyHex: PubkeyHex, boostFactor: bigint): void {
getBuilderBoostFactor(pubkeyHex: PubkeyHex): bigint {
const validatorData = this.validators.get(pubkeyHex);
if (validatorData === undefined) {
throw Error(`Validator pubkey ${pubkeyHex} not known`);
}
return validatorData?.builder?.boostFactor ?? this.defaultProposerConfig.builder.boostFactor;
}

setBuilderBoostFactor(pubkeyHex: PubkeyHex, boostFactor: bigint): void {
if (boostFactor > MAX_BUILDER_BOOST_FACTOR) {
throw Error(`Invalid builderBoostFactor=${boostFactor} > MAX_BUILDER_BOOST_FACTOR`);
}
Expand All @@ -328,6 +336,14 @@ export class ValidatorStore {
validatorData.builder = {...validatorData.builder, boostFactor};
}

deleteBuilderBoostFactor(pubkeyHex: PubkeyHex): void {
const validatorData = this.validators.get(pubkeyHex);
if (validatorData === undefined) {
throw Error(`Validator pubkey ${pubkeyHex} not known`);
}
delete validatorData.builder?.boostFactor;
}

/** Return true if `index` is active part of this validator client */
hasValidatorIndex(index: ValidatorIndex): boolean {
return this.indicesService.index2pubkey.has(index);
Expand Down

0 comments on commit bca1d63

Please sign in to comment.