Skip to content

Commit

Permalink
Merge pull request #8 from rafal-ch/more_clean_up
Browse files Browse the repository at this point in the history
Clean up
  • Loading branch information
jacek-casper authored Jan 18, 2024
2 parents f0f90ab + d1d167a commit d4e8c2d
Show file tree
Hide file tree
Showing 8 changed files with 680 additions and 15 deletions.
2 changes: 1 addition & 1 deletion node/src/components/binary_port/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub(super) struct Metrics {
pub(super) binary_port_get_all_values_count: IntCounter,
/// Number of `Get::Trie` queries received.
pub(super) binary_port_get_trie_count: IntCounter,
/// Number of `Get::Trie` queries received.
/// Number of distinct connections to binary port.
pub(super) binary_port_connections_count: IntCounter,

registry: Registry,
Expand Down
51 changes: 47 additions & 4 deletions node/src/components/rest_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mod filters;
mod http_server;
mod info;

use std::{net::SocketAddr, sync::Arc, time::Duration};
use std::{net::SocketAddr, sync::Arc};

use datasize::DataSize;
use futures::{future::BoxFuture, join, FutureExt};
Expand Down Expand Up @@ -184,7 +184,6 @@ where
Effects::new()
}
Event::RestRequest(RestRequest::Status { responder }) => {
let node_uptime = Duration::from_secs(10);
let network_name = self.network_name.clone();
async move {
let (
Expand All @@ -194,7 +193,7 @@ where
consensus_status,
reactor_state,
last_progress,
_duration,
node_uptime,
available_block_range,
block_sync,
) = join!(
Expand All @@ -221,7 +220,7 @@ where
peers,
ChainspecInfo::new(network_name, next_upgrade),
consensus_status,
node_uptime,
node_uptime.into(),
reactor_state,
last_progress.into_inner(),
available_block_range,
Expand Down Expand Up @@ -350,3 +349,47 @@ impl Finalize for RestServer {
.boxed()
}
}

#[cfg(test)]
mod schema_tests {
use crate::{testing::assert_schema, types::GetStatusResult};
use schemars::schema_for;

use super::{GetChainspecResult, GetValidatorChangesResult};

#[test]
fn json_schema_status_check() {
let schema_path = format!(
"{}/../resources/test/rest_schema_status.json",
env!("CARGO_MANIFEST_DIR")
);
assert_schema(
schema_path,
serde_json::to_string_pretty(&schema_for!(GetStatusResult)).unwrap(),
);
}

#[test]
fn json_schema_validator_changes_check() {
let schema_path = format!(
"{}/../resources/test/rest_schema_validator_changes.json",
env!("CARGO_MANIFEST_DIR")
);
assert_schema(
schema_path,
serde_json::to_string_pretty(&schema_for!(GetValidatorChangesResult)).unwrap(),
);
}

#[test]
fn json_schema_chainspec_bytes_check() {
let schema_path = format!(
"{}/../resources/test/rest_schema_chainspec_bytes.json",
env!("CARGO_MANIFEST_DIR")
);
assert_schema(
schema_path,
serde_json::to_string_pretty(&schema_for!(GetChainspecResult)).unwrap(),
);
}
}
6 changes: 0 additions & 6 deletions node/src/components/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,6 @@ impl Storage {
let approvals_hashes_dbs =
VersionedDatabases::new(&env, "approvals_hashes", "versioned_approvals_hashes")?;

let _x: Vec<Box<dyn RawDataAccess + Send + 'static>> = vec![
Box::new(block_header_dbs),
Box::new(block_body_dbs),
Box::new(block_metadata_db),
];

let mut db_mapper: HashMap<DbId, Box<dyn RawDataAccess + Send + 'static>> = HashMap::new();
db_mapper.insert(DbId::Transaction, Box::new(transaction_dbs));
db_mapper.insert(DbId::ExecutionResult, Box::new(execution_result_dbs));
Expand Down
4 changes: 2 additions & 2 deletions node/src/components/storage/versioned_databases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ pub(super) struct VersionedDatabases<K, V> {
/// Legacy form of the data, with the key as `K::Legacy` type (converted to bytes using
/// `AsRef<[u8]>`) and the value bincode-encoded.
#[data_size(skip)]
pub(crate) legacy: Database,
pub legacy: Database,
/// Current form of the data, with the key as `K` bytesrepr-encoded and the value as `V` also
/// bytesrepr-encoded.
#[data_size(skip)]
pub(crate) current: Database,
pub current: Database,
_phantom: PhantomData<(K, V)>,
}

Expand Down
2 changes: 0 additions & 2 deletions node/src/reactor/main_reactor/tests/binary_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,12 +535,10 @@ fn node_status() -> TestCase {
response,
Some(PayloadType::NodeStatus),
|node_status| {
dbg!(&node_status);
!node_status.peers.into_inner().is_empty()
&& node_status.chainspec_name == "casper-example"
&& node_status.last_added_block_info.is_some()
&& node_status.our_public_signing_key.is_some()
&& node_status.round_length.is_some()
&& node_status.block_sync.historical().is_none()
&& node_status.block_sync.forward().is_none()
&& matches!(node_status.reactor_state, ReactorState::Validate)
Expand Down
69 changes: 69 additions & 0 deletions resources/test/rest_schema_chainspec_bytes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "GetChainspecResult",
"description": "Result for the \"info_get_chainspec\" RPC.",
"type": "object",
"required": [
"api_version",
"chainspec_bytes"
],
"properties": {
"api_version": {
"description": "The RPC API version.",
"type": "string"
},
"chainspec_bytes": {
"description": "The chainspec file bytes.",
"allOf": [
{
"$ref": "#/definitions/ChainspecRawBytes"
}
]
}
},
"definitions": {
"ChainspecRawBytes": {
"description": "The raw bytes of the chainspec.toml, genesis accounts.toml, and global_state.toml files.",
"type": "object",
"required": [
"chainspec_bytes"
],
"properties": {
"chainspec_bytes": {
"description": "Raw bytes of the current chainspec.toml file.",
"allOf": [
{
"$ref": "#/definitions/Bytes"
}
]
},
"maybe_genesis_accounts_bytes": {
"description": "Raw bytes of the current genesis accounts.toml file.",
"anyOf": [
{
"$ref": "#/definitions/Bytes"
},
{
"type": "null"
}
]
},
"maybe_global_state_bytes": {
"description": "Raw bytes of the current global_state.toml file.",
"anyOf": [
{
"$ref": "#/definitions/Bytes"
},
{
"type": "null"
}
]
}
}
},
"Bytes": {
"description": "Hex-encoded bytes.",
"type": "string"
}
}
}
Loading

0 comments on commit d4e8c2d

Please sign in to comment.