Skip to content

Commit

Permalink
Merge branch 'main' into registry-query
Browse files Browse the repository at this point in the history
  • Loading branch information
BoredApe8461 authored Aug 19, 2024
2 parents 4f45ab9 + 11ba118 commit b4aa2c3
Show file tree
Hide file tree
Showing 39 changed files with 2,740 additions and 327 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,18 @@ jobs:

- name: Ensure the project builds
run: cargo build
test:
needs: install
runs-on: ubuntu-latest
steps:
- name: Use cashed cargo
uses: actions/cache@v3
with:
path: ~/.cargo
key: ${{ runner.os }}-rust-${{ hashFiles('rust-toolchain.toml') }}

- name: Checkout the source code
uses: actions/checkout@v3

- name: Ensure the project builds
run: cargo test -- --test-threads=1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/out
logs/
134 changes: 124 additions & 10 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ license = "GPL-3.0-only"

[workspace]
members = [
"bin/processor",
"bin/server",
"bin/tracker",
"routes",
Expand Down
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@ A basic example of registering a parachain:

```
curl -X POST http://127.0.0.1:8000/register_para -H "Content-Type: application/json" -d '{
"para": {
"name": "Acala",
"rpc_url": "wss://acala-rpc.dwellir.com",
"para_id": 2000,
"relay_chain": "Polkadot"
}
"para": ["Polkadot", 2000]
}'
```

Expand Down
13 changes: 13 additions & 0 deletions bin/processor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "processor"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
log = "0.4"
shared = { path = "../../shared" }
env_logger = "0.10.1"
polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
types = { path = "../../types" }
84 changes: 84 additions & 0 deletions bin/processor/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// This file is part of RegionX.
//
// RegionX is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// RegionX is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with RegionX. If not, see <https://www.gnu.org/licenses/>.

use shared::{
config::config,
consumption::{delete_consumption, get_consumption, write_batch_consumption},
registry::registered_paras,
};
use std::collections::BTreeMap;
use types::WeightConsumption;

const LOG_TARGET: &str = "processor";

fn main() {
env_logger::init();

let outputs = config().outputs;
let paras = registered_paras();

paras.iter().for_each(|para| {
let mut processed = BTreeMap::new();

log::info!(
target: LOG_TARGET,
"{}-{} - Processing consumption.",
para.relay_chain,
para.para_id,
);

(0..outputs).for_each(|output_index| {
let consumption = if let Ok(data) = get_consumption(para.clone(), Some(output_index)) {
data
} else {
log::error!(
target: LOG_TARGET,
"{}-{} - Failed to get consumption.",
para.relay_chain,
para.para_id,
);
vec![]
};

consumption.into_iter().for_each(|data| {
processed.entry(data.block_number).or_insert(data);
});
});

let processed: Vec<WeightConsumption> = processed.values().cloned().collect();

log::info!(
target: LOG_TARGET,
"{}-{} - Writing processed consumption. Total blocks tracked: {}",
para.relay_chain,
para.para_id,
processed.len()
);

if let Err(e) = write_batch_consumption(para.clone(), processed) {
log::error!(
target: LOG_TARGET,
"{}-{} - Failed to write batch consumption: {:?}",
para.relay_chain,
para.para_id,
e,
);

return;
}

(0..outputs).for_each(|output_index| delete_consumption(para.clone(), output_index));
});
}
9 changes: 7 additions & 2 deletions bin/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
/// - `/consumption`: Used to query consumption data associated with a parachain.
/// - `/register`: Used to register a parachain for consumption tracking.
use rocket_cors::CorsOptions;
use routes::{consumption::consumption, register::register_para, registry::registry};
use routes::{
consumption::consumption, extend_subscription::extend_subscription, register::register_para,
registry::registry,
};

#[macro_use]
extern crate rocket;
Expand All @@ -28,5 +31,7 @@ extern crate rocket;
fn rocket() -> _ {
rocket::build()
.attach(CorsOptions::default().to_cors().unwrap())
.mount("/", routes![consumption, register_para, registry])

.mount("/", routes![consumption, register_para, registry, extend_subscription])

}
1 change: 1 addition & 0 deletions bin/tracker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ tokio = { version = "1", features = ["full"] }

types = { path = "../../types" }
shared = { path = "../../shared" }
clap = { version = "4.4.18", features = ["derive"] }
Loading

0 comments on commit b4aa2c3

Please sign in to comment.