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

feat: adds dashboard census-feature parity across beacon, history, state networks #313

Merged
merged 5 commits into from
Sep 20, 2024
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
2 changes: 1 addition & 1 deletion docker-compose-clients.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
image: portalnetwork/trin:latest
environment:
RUST_LOG: info
command: "--web3-transport http --web3-http-address http://0.0.0.0:8545/ --mb 0 --no-upnp --disable-poke ${GLADOS_CLIENT_ARGUMENTS:-}"
command: "--web3-transport http --web3-http-address http://0.0.0.0:8545/ --mb 0 --portal-subnetworks history,state,beacon --no-upnp --disable-poke ${GLADOS_CLIENT_ARGUMENTS:-}"
fluffy:
image: statusim/nimbus-fluffy:amd64-master-latest
command: "--rpc --rpc-address=0.0.0.0 --storage-capacity=0 --disable-poke ${GLADOS_CLIENT_ARGUMENTS:-}"
32 changes: 31 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ services:
- glados-net
restart: always

glados_cartographer:
glados_cartographer_history:
command: "--database-url postgres://postgres:${GLADOS_POSTGRES_PASSWORD}@glados_postgres:5432/glados --transport http --http-url http://host.docker.internal:8545 --concurrency 10 --subnetwork history"
image: portalnetwork/glados-cartographer:latest
environment:
Expand All @@ -78,6 +78,36 @@ services:
- "host.docker.internal:host-gateway"
restart: always

glados_cartographer_state:
command: "--database-url postgres://postgres:${GLADOS_POSTGRES_PASSWORD}@glados_postgres:5432/glados --transport http --http-url http://host.docker.internal:8545 --concurrency 10 --subnetwork state"
image: portalnetwork/glados-cartographer:latest
environment:
RUST_LOG: warn,glados_cartographer=info
depends_on:
- glados_web
- glados_postgres
- portal_client
networks:
- glados-net
extra_hosts:
- "host.docker.internal:host-gateway"
restart: always

glados_cartographer_beacon:
command: "--database-url postgres://postgres:${GLADOS_POSTGRES_PASSWORD}@glados_postgres:5432/glados --transport http --http-url http://host.docker.internal:8545 --concurrency 10 --subnetwork beacon"
image: portalnetwork/glados-cartographer:latest
environment:
RUST_LOG: warn,glados_cartographer=info
depends_on:
- glados_web
- glados_postgres
- portal_client
networks:
- glados-net
extra_hosts:
- "host.docker.internal:host-gateway"
restart: always

networks:
glados-net:
driver: bridge
20 changes: 18 additions & 2 deletions entity/src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ethportal_api::OverlayContentKey;
use sea_orm::{entity::prelude::*, ActiveValue::NotSet, Set};

/// Portal network sub-protocol. History, state, transactions etc.
#[derive(Debug, Clone, Eq, PartialEq, EnumIter, DeriveActiveEnum)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "i32", db_type = "Integer")]
pub enum SubProtocol {
History = 0,
Expand All @@ -26,6 +26,22 @@ impl SubProtocol {
}
}

#[derive(Debug, PartialEq)]
pub struct InvalidSubProtocolError;

impl TryFrom<&String> for SubProtocol {
type Error = InvalidSubProtocolError;

fn try_from(value: &String) -> Result<Self, Self::Error> {
match value.to_lowercase().as_str() {
"history" => Ok(SubProtocol::History),
"state" => Ok(SubProtocol::State),
"beacon" => Ok(SubProtocol::Beacon),
_ => Err(InvalidSubProtocolError),
}
}
}

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "content")]
pub struct Model {
Expand Down Expand Up @@ -70,7 +86,7 @@ pub async fn get_or_create<T: OverlayContentKey>(
) -> Result<Model> {
// First try to lookup an existing entry.
if let Some(content_key_model) = Entity::find()
.filter(Column::ProtocolId.eq(sub_protocol.clone()))
.filter(Column::ProtocolId.eq(sub_protocol))
.filter(Column::ContentKey.eq(content_key.to_bytes()))
.one(conn)
.await?
Expand Down
4 changes: 2 additions & 2 deletions entity/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ async fn test_content_table_unique_constraints() {
id: NotSet,
content_id: Set(id_a.clone()),
content_key: Set(key_a.clone()),
protocol_id: Set(protocol_a.clone()),
protocol_id: Set(protocol_a),
first_available_at: Set(Utc::now()),
};
action_a.clone().insert(&conn).await.unwrap();
Expand Down Expand Up @@ -318,7 +318,7 @@ async fn test_content_table_unique_constraints() {
id: NotSet,
content_id: Set(id_b),
content_key: Set(key_a),
protocol_id: Set(protocol_a.clone()),
protocol_id: Set(protocol_a),
first_available_at: Set(Utc::now()),
};
assert!(action_c
Expand Down
20 changes: 12 additions & 8 deletions glados-web/assets/js/censustimeseries.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ function createSquareChart(width, data) {
.attr("style", "max-width: 90%; height: 100%; height: intrinsic;");


let title = data.censuses.length > 0 ? `${nodes.length} nodes found during 24 hour period beginning at ${data.censuses[0].time}`
: `No censuses found during this 24 hour period.`;
const url = new URL(window.location);
const subprotocol = url.searchParams.get('network');
let title = data.censuses.length > 0 ? `${nodes.length} ${subprotocol} nodes found during 24 hour period beginning at ${data.censuses[0].time}`
: `No ${subprotocol} censuses found during this 24 hour period.`;

// Append the title
svg.append("text")
Expand Down Expand Up @@ -360,9 +362,9 @@ function getClientStringFromDecodedEnr(decodedEnr) {
}

// Fetch the census node records from the API.
async function getCensusTimeSeriesData(numDaysAgo) {
async function getCensusTimeSeriesData(numDaysAgo, subprotocol) {

const baseUrl = `census-node-timeseries-data/?days-ago=${numDaysAgo}`;
const baseUrl = `census-node-timeseries-data/?days-ago=${numDaysAgo}&network=${subprotocol}`;
return fetch(`${baseUrl}`)
.then(response => {
if (!response.ok) {
Expand All @@ -381,18 +383,20 @@ async function censusTimeSeriesChart(daysAgo) {
svgElement.remove();
});

const data = await getCensusTimeSeriesData(daysAgo);
const url = new URL(window.location);
subprotocol = url.searchParams.get('network');

const data = await getCensusTimeSeriesData(daysAgo, subprotocol);
console.log('Census data from glados API:');
console.log(data);
if (data) {
document.getElementById('census-timeseries-graph').appendChild(createSquareChart(1700, data));
if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
alert('This page does not display well on Firefox, Chrome or Safari are recommended.');
}
} else {
console.log('No data available to plot the census chart');
}
}

// Sort nodes by nickname, latestClientString, and nodeId
function sortNodes(a, b) {

// Check for "bootnode" in nodeNickName
Expand Down
2 changes: 0 additions & 2 deletions glados-web/assets/js/stats_history.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,8 @@ function getStatsRecords(weeksAgo) {

async function updateChart(weeksAgo) {
const data = await getStatsRecords(weeksAgo);
console.log(data);

let dataSets = convertDataForChart(data);
console.log(dataSets);

// Clear the existing chart
d3.select("#stats-history-graph").html("");
Expand Down
2 changes: 1 addition & 1 deletion glados-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub async fn run_glados_web(config: Arc<State>) -> Result<()> {

// setup router
let app = Router::new()
.route("/", get(routes::root))
.route("/", get(routes::network_overview))
.route("/census/census-list/", get(routes::census_explorer_list))
.route("/census/", get(routes::single_census_view))
.route("/census/explorer", get(routes::census_explorer))
Expand Down
Loading