diff --git a/crates/ethcore/src/snapshot/service.rs b/crates/ethcore/src/snapshot/service.rs index 9b94f1543..b94d36199 100644 --- a/crates/ethcore/src/snapshot/service.rs +++ b/crates/ethcore/src/snapshot/service.rs @@ -853,6 +853,13 @@ impl SnapshotService for Service { self.reader.read().as_ref().map(|r| r.manifest().clone()) } + fn manifest_block(&self) -> Option<(u64, H256)> { + self.reader.read().as_ref().map(|reader| { + let manifest = reader.manifest(); + (manifest.block_number, manifest.block_hash) + }) + } + fn supported_versions(&self) -> Option<(u64, u64)> { self.engine .snapshot_components() diff --git a/crates/ethcore/src/snapshot/traits.rs b/crates/ethcore/src/snapshot/traits.rs index 6b17d2f03..e0d556022 100644 --- a/crates/ethcore/src/snapshot/traits.rs +++ b/crates/ethcore/src/snapshot/traits.rs @@ -26,6 +26,9 @@ pub trait SnapshotService: Sync + Send { /// Query the most recent manifest data. fn manifest(&self) -> Option; + /// Query the most recent snapshoted block number and hash. + fn manifest_block(&self) -> Option<(u64, H256)>; + /// Get the supported range of snapshot version numbers. /// `None` indicates warp sync isn't supported by the consensus engine. fn supported_versions(&self) -> Option<(u64, u64)>; diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index 5cea92488..aa82fe776 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -406,6 +406,11 @@ impl PrometheusMetrics for EthSync { let restoration = self.eth_handler.snapshot_service.restoration_status(); let creation = self.eth_handler.snapshot_service.creation_status(); + let (manifest_block_num, _) = self + .eth_handler + .snapshot_service + .manifest_block() + .unwrap_or((0, H256::zero())); prometheus_gauge( r, @@ -427,6 +432,12 @@ impl PrometheusMetrics for EthSync { 0 }, ); + prometheus_gauge( + r, + "snapshot_manifest_block", + "First block number of the present snapshot", + manifest_block_num as i64, + ); } } diff --git a/crates/ethcore/sync/src/tests/snapshot.rs b/crates/ethcore/sync/src/tests/snapshot.rs index 03ae2873e..89f635b5f 100644 --- a/crates/ethcore/sync/src/tests/snapshot.rs +++ b/crates/ethcore/sync/src/tests/snapshot.rs @@ -89,6 +89,12 @@ impl SnapshotService for TestSnapshotService { self.manifest.as_ref().cloned() } + fn manifest_block(&self) -> Option<(u64, H256)> { + self.manifest + .as_ref() + .map(|manifest| (manifest.block_number, manifest.block_hash)) + } + fn supported_versions(&self) -> Option<(u64, u64)> { Some((1, 2)) } diff --git a/crates/rpc/src/v1/tests/helpers/snapshot_service.rs b/crates/rpc/src/v1/tests/helpers/snapshot_service.rs index cbc4d79d8..cc2bbbcb8 100644 --- a/crates/rpc/src/v1/tests/helpers/snapshot_service.rs +++ b/crates/rpc/src/v1/tests/helpers/snapshot_service.rs @@ -44,6 +44,9 @@ impl SnapshotService for TestSnapshotService { fn manifest(&self) -> Option { None } + fn manifest_block(&self) -> Option<(u64, H256)> { + None + } fn supported_versions(&self) -> Option<(u64, u64)> { None }