Standard gas limit api (#3450)

## Issue Addressed

Resolves https://github.com/sigp/lighthouse/issues/3403

## Proposed Changes

Implements https://ethereum.github.io/keymanager-APIs/#/Gas%20Limit

## Additional Info

N/A

Co-authored-by: realbigsean <sean@sigmaprime.io>
This commit is contained in:
realbigsean
2022-08-15 01:30:58 +00:00
parent 92d597ad23
commit dd93aa8701
8 changed files with 430 additions and 6 deletions

View File

@@ -519,6 +519,18 @@ impl ValidatorClientHttpClient {
Ok(url)
}
fn make_gas_limit_url(&self, pubkey: &PublicKeyBytes) -> Result<Url, Error> {
let mut url = self.server.full.clone();
url.path_segments_mut()
.map_err(|()| Error::InvalidUrl(self.server.clone()))?
.push("eth")
.push("v1")
.push("validator")
.push(&pubkey.to_string())
.push("gas_limit");
Ok(url)
}
/// `GET lighthouse/auth`
pub async fn get_auth(&self) -> Result<AuthResponse, Error> {
let mut url = self.server.full.clone();
@@ -598,11 +610,38 @@ impl ValidatorClientHttpClient {
self.post_with_raw_response(url, req).await
}
/// `POST /eth/v1/validator/{pubkey}/feerecipient`
/// `DELETE /eth/v1/validator/{pubkey}/feerecipient`
pub async fn delete_fee_recipient(&self, pubkey: &PublicKeyBytes) -> Result<Response, Error> {
let url = self.make_fee_recipient_url(pubkey)?;
self.delete_with_raw_response(url, &()).await
}
/// `GET /eth/v1/validator/{pubkey}/gas_limit`
pub async fn get_gas_limit(
&self,
pubkey: &PublicKeyBytes,
) -> Result<GetGasLimitResponse, Error> {
let url = self.make_gas_limit_url(pubkey)?;
self.get(url)
.await
.map(|generic: GenericResponse<GetGasLimitResponse>| generic.data)
}
/// `POST /eth/v1/validator/{pubkey}/gas_limit`
pub async fn post_gas_limit(
&self,
pubkey: &PublicKeyBytes,
req: &UpdateGasLimitRequest,
) -> Result<Response, Error> {
let url = self.make_gas_limit_url(pubkey)?;
self.post_with_raw_response(url, req).await
}
/// `DELETE /eth/v1/validator/{pubkey}/gas_limit`
pub async fn delete_gas_limit(&self, pubkey: &PublicKeyBytes) -> Result<Response, Error> {
let url = self.make_gas_limit_url(pubkey)?;
self.delete_with_raw_response(url, &()).await
}
}
/// Returns `Ok(response)` if the response is a `200 OK` response or a

View File

@@ -10,6 +10,13 @@ pub struct GetFeeRecipientResponse {
pub ethaddress: Address,
}
#[derive(Debug, Deserialize, Serialize, PartialEq)]
pub struct GetGasLimitResponse {
pub pubkey: PublicKeyBytes,
#[serde(with = "eth2_serde_utils::quoted_u64")]
pub gas_limit: u64,
}
#[derive(Debug, Deserialize, Serialize, PartialEq)]
pub struct AuthResponse {
pub token_path: String,

View File

@@ -138,3 +138,9 @@ pub struct Web3SignerValidatorRequest {
pub struct UpdateFeeRecipientRequest {
pub ethaddress: Address,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct UpdateGasLimitRequest {
#[serde(with = "eth2_serde_utils::quoted_u64")]
pub gas_limit: u64,
}