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

Update relayer endpoints #519

Merged
merged 7 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
67 changes: 66 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 19 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ The relayer has 3 endpoints available to query from. They are outlined below for
<summary>Expected Response</summary>

```json
{
{
"relayer_config" : {
"evm": {
"rinkeby": {
"enabled": true,
Expand All @@ -286,6 +287,13 @@ The relayer has 3 endpoints available to query from. They are outlined below for
"smart-anchor-updates": false,
"smart-anchor-updates-retries": 0
}
},
"build_info" : {
"version": "0.5.0",
"commit": "c8875ba78298d34272e40c2e302fcfe33f191147",
"branch": "develop",
"build_time": "2023-05-19T15:57:40Z"
}
}
```
</details>
Expand Down Expand Up @@ -324,30 +332,16 @@ The relayer has 3 endpoints available to query from. They are outlined below for
```json
{
"leaves": [
[
42, 255, 162, 80, 180, 134, 202, 153,
49, 119, 64, 112, 255, 230, 46, 130,
230, 68, 98, 78, 34, 206, 175, 181,
18, 112, 14, 188, 166, 72, 115, 130
],
[
2, 103, 50, 103, 246, 93, 14, 110,
51, 252, 154, 157, 102, 157, 16, 237,
117, 55, 107, 175, 233, 112, 144, 18,
178, 30, 175, 223, 81, 29, 227, 71
],
[
40, 30, 11, 223, 86, 95, 109, 18,
31, 93, 224, 12, 208, 111, 222, 217,
80, 195, 194, 100, 220, 183, 40, 142,
232, 45, 32, 187, 98, 174, 142, 231
],
[
31, 141, 59, 100, 22, 69, 177, 39,
226, 21, 59, 203, 47, 116, 66, 133,
11, 254, 53, 179, 205, 251, 172, 32,
8, 228, 96, 148, 230, 134, 80, 122
],
"0x015110a4b1a8bf29f7b6b2cb3fe5f52c2eeccd9ff7e8a0fb7d4ff2ae61516562",
"0x2fa56e6179d1bf0afc6f3ee2a52dc68cc2076d380a55165578c1c558e1f6f1dc",
"0x031317e0fe026ce99cf9b3cf8fefed7ddc21c5f4181e49fd6e8370aea5006da0",
"0x07507826af3c90c457222ad0305d90bf8bcfb1d343c2a9c17d280ff648b43582",
"0x0ff8f7f0fc798b9b34464ba51a10bdde16d17506f3251f9658335504f07c9c5f",
"0x0b92b3c5013eb2374527a167af6464f1ab8b11da1dd36e5a6a2cf76130fee9e3",
"0x2bccea444d1078a2b5778f3c8f28013219abfe5c236d1276b87276ec5eec4354",
"0x0be7c8578e746b1b7d913c79affb80c715b96a1304edb68d1d7e6dc33f30260f",
"0x117dae7ac7b62ed97525cc8541823c2caae25ffaf6168361ac19ca484851744f",
"0x0c187c0b413f2c2e8ebaeffbe9351fda6eb46dfa396b0c73298215950439fa75"
],
"lastQueriedBlock": 37
}
Expand Down
4 changes: 2 additions & 2 deletions crates/relayer-handlers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ pub async fn handle_cmd(
/// gets parsed incorrectly.
pub async fn handle_evm_fee_info(
State(ctx): State<Arc<RelayerContext>>,
Path((chain_id, vanchor, gas_amount)): Path<(u64, Address, u64)>,
Path((chain_id, vanchor, gas_amount)): Path<(u32, Address, u64)>,
) -> Result<Json<EvmFeeInfo>, HandlerError> {
let chain_id = TypedChainId::from(chain_id);
let chain_id = TypedChainId::Evm(chain_id);
let gas_amount = U256::from(gas_amount);
Ok(
get_evm_fee_info(chain_id, vanchor, gas_amount, ctx.as_ref())
Expand Down
37 changes: 35 additions & 2 deletions crates/relayer-handlers/src/routes/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,35 @@ use webb::evm::ethers::{
};
use webb_relayer_context::RelayerContext;

/// Build info data
#[derive(Debug, Serialize)]
pub struct BuildInfo {
/// Version of the relayer
pub version: String,
/// Commit hash of the relayer
pub commit: String,
/// Branch of the relayer
pub branch: String,
salman01zp marked this conversation as resolved.
Show resolved Hide resolved
/// Build time of the relayer
pub build_time: String,
salman01zp marked this conversation as resolved.
Show resolved Hide resolved
}

/// Relayer config data
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RelayerConfig {
/// Relayer chain config
pub config: webb_relayer_config::WebbRelayerConfig,
/// Relayer build info
pub build_info: BuildInfo,
}

/// Relayer configuration response
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RelayerInformationResponse {
#[serde(flatten)]
config: webb_relayer_config::WebbRelayerConfig,
relayer_config: RelayerConfig,
}
salman01zp marked this conversation as resolved.
Show resolved Hide resolved

/// Handles relayer configuration requests
Expand Down Expand Up @@ -53,5 +76,15 @@ pub async fn handle_relayer_info(
v.beneficiary = Some(suri.public());
webb_relayer_utils::Result::Ok(())
});
Json(RelayerInformationResponse { config })

// Build info
let build_info = BuildInfo {
version: std::env::var("CARGO_PKG_VERSION").unwrap_or_default(),
commit: std::env::var("GIT_COMMIT").unwrap_or_default(),
branch: std::env::var("GIT_BRANCH").unwrap_or_default(),
build_time: std::env::var("SOURCE_TIMESTAMP").unwrap_or_default(),
};
let relayer_config = RelayerConfig { config, build_info };

Json(RelayerInformationResponse { relayer_config })
}
16 changes: 5 additions & 11 deletions crates/relayer-handlers/src/routes/leaves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use axum::extract::{Path, Query, State};
use axum::http::StatusCode;
use axum::Json;
use std::{collections::HashMap, sync::Arc};
use webb::evm::ethers::types;

use ethereum_types::Address;
use serde::Serialize;
Expand All @@ -32,7 +33,7 @@ use super::OptionalRangeQuery;
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct LeavesCacheResponse {
leaves: Vec<Vec<u8>>,
leaves: Vec<types::H256>,
last_queried_block: u64,
}

Expand Down Expand Up @@ -117,11 +118,7 @@ pub async fn handle_leaves_cache_evm(
let leaves = ctx
.store()
.get_leaves_with_range(history_store_key, query_range.into())
.map(|tree| {
tree.into_values()
.map(|v| v.to_fixed_bytes().to_vec())
.collect::<Vec<_>>()
})?;
.map(|tree| tree.into_values().collect::<Vec<_>>())?;
let last_queried_block = ctx
.store()
.get_last_deposit_block_number(history_store_key)?;
Expand Down Expand Up @@ -171,11 +168,8 @@ pub async fn handle_leaves_cache_substrate(
let leaves = ctx
.store()
.get_leaves_with_range(history_store_key, query_range.into())
.map(|tree| {
tree.into_values()
.map(|v| v.to_fixed_bytes().to_vec())
.collect::<Vec<_>>()
})?;
.map(|tree| tree.into_values().collect::<Vec<_>>())?;

let last_queried_block = ctx
.store()
.get_last_deposit_block_number(history_store_key)?;
Expand Down
18 changes: 9 additions & 9 deletions crates/relayer-store/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type MemStoreForMap = HashMap<HistoryStoreKey, BTreeMap<u32, types::H256>>;
#[derive(Clone, Default)]
pub struct InMemoryStore {
_store: Arc<RwLock<MemStore>>,
store_for_vec: Arc<RwLock<MemStoreForVec>>,
store_for_map: Arc<RwLock<MemStoreForMap>>,
leaf_store: Arc<RwLock<MemStoreForMap>>,
encrypted_output_store: Arc<RwLock<MemStoreForVec>>,
last_block_numbers: Arc<RwLock<HashMap<HistoryStoreKey, u64>>>,
target_block_numbers: Arc<RwLock<HashMap<HistoryStoreKey, u64>>>,
last_deposit_block_numbers: Arc<RwLock<HashMap<HistoryStoreKey, u64>>>,
Expand Down Expand Up @@ -119,7 +119,7 @@ impl LeafCacheStore for InMemoryStore {
&self,
key: K,
) -> crate::Result<()> {
let mut guard = self.store_for_map.write();
let mut guard = self.leaf_store.write();
guard.clear();
Ok(())
}
Expand All @@ -129,7 +129,7 @@ impl LeafCacheStore for InMemoryStore {
&self,
key: K,
) -> crate::Result<Self::Output> {
let guard = self.store_for_map.read();
let guard = self.leaf_store.read();
let val = guard.get(&key.into()).cloned().unwrap_or_default();
Ok(val)
}
Expand All @@ -139,7 +139,7 @@ impl LeafCacheStore for InMemoryStore {
key: K,
range: core::ops::Range<u32>,
) -> crate::Result<Self::Output> {
let guard = self.store_for_map.read();
let guard = self.leaf_store.read();
let val = guard.get(&key.into()).cloned().unwrap_or_default();
let iter = val
.into_iter()
Expand Down Expand Up @@ -171,7 +171,7 @@ impl LeafCacheStore for InMemoryStore {
leaves: &[(u32, Vec<u8>)],
block_number: u64,
) -> crate::Result<()> {
let mut guard1 = self.store_for_map.write();
let mut guard1 = self.leaf_store.write();
let mut guard2 = self.last_deposit_block_numbers.write();
let mut guard3 = self.last_block_numbers.write();
{
Expand Down Expand Up @@ -207,7 +207,7 @@ impl EncryptedOutputCacheStore for InMemoryStore {
&self,
key: K,
) -> crate::Result<Self::Output> {
let guard = self.store_for_vec.read();
let guard = self.encrypted_output_store.read();
let val = guard.get(&key.into()).cloned().unwrap_or_default();
Ok(val)
}
Expand All @@ -218,7 +218,7 @@ impl EncryptedOutputCacheStore for InMemoryStore {
key: K,
range: core::ops::Range<u32>,
) -> crate::Result<Self::Output> {
let guard = self.store_for_vec.read();
let guard = self.encrypted_output_store.read();
let val = guard.get(&key.into()).cloned().unwrap_or_default();
let iter = val
.into_iter()
Expand Down Expand Up @@ -252,7 +252,7 @@ impl EncryptedOutputCacheStore for InMemoryStore {
encrypted_outputs: &[(u32, Vec<u8>)],
block_number: u64,
) -> crate::Result<()> {
let mut guard1 = self.store_for_vec.write();
let mut guard1 = self.encrypted_output_store.write();
let mut guard2 = self.last_deposit_block_numbers.write();
{
guard1
Expand Down
3 changes: 3 additions & 0 deletions services/webb-relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ documentation = { workspace = true }
homepage = { workspace = true }
repository = { workspace = true }

[build-dependencies]
build-data = "0"

salman01zp marked this conversation as resolved.
Show resolved Hide resolved
[lib]
doctest = false

Expand Down
9 changes: 9 additions & 0 deletions services/webb-relayer/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// build.rs

fn main() {
build_data::set_GIT_BRANCH();
build_data::set_GIT_COMMIT();
build_data::set_GIT_DIRTY();
build_data::set_SOURCE_TIMESTAMP();
build_data::no_debug_rebuilds();
}
2 changes: 1 addition & 1 deletion tests/lib/webbRelayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ export interface WebbRelayerInfo {
}

export interface LeavesCacheResponse {
leaves: number[][];
leaves: [`0x${string}`];
lastQueriedBlock: string;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test/evm/RelayerTxTransfer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ describe('Relayer transfer assets', function () {
);

const feeInfoResponse = await webbRelayer.getEvmFeeInfo(
localChain1.chainId,
localChain1.underlyingChainId,
vanchor1.getAddress(),
gas_amount
);
Expand Down
Loading