Skip to content

Commit 96b6bd5

Browse files
authored
More light client features to support Espresso stack (#4786)
Expose more fields of light client state
1 parent 485560c commit 96b6bd5

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎light-client/src/state.rs‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,20 @@ pub struct LightClient<P, S> {
108108
stake_tables: RwLock<BTreeMap<EpochNumber, Arc<StakeTable>>>,
109109
}
110110

111-
impl<P, S> AsRef<S> for LightClient<P, S> {
112-
fn as_ref(&self) -> &S {
111+
impl<P, S> LightClient<P, S> {
112+
pub fn into_storage(self) -> P {
113+
self.db
114+
}
115+
116+
pub fn storage(&self) -> &P {
117+
&self.db
118+
}
119+
120+
pub fn into_inner(self) -> S {
121+
self.server
122+
}
123+
124+
pub fn inner(&self) -> &S {
113125
&self.server
114126
}
115127
}

‎light-client/src/storage.rs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#[cfg(feature = "client")]
22
use std::{
3+
cmp::min,
34
collections::HashMap,
45
path::PathBuf,
56
str::FromStr,
@@ -556,12 +557,17 @@ impl Storage for SqliteStorage {
556557
) -> Result<Option<(EpochNumber, StakeTableState, Version, Version)>> {
557558
let mut tx = self.pool.begin().await?;
558559

560+
// The largest epoch number the database can represent is `i64::MAX`. Since we are only
561+
// looking for a lower bound, if requested for an epoch number that can overflow, we can
562+
// simply return the lower bound of `i64::MAX`.
563+
let epoch = min(*epoch, i64::MAX as u64) as i64;
564+
559565
let Some((epoch, epoch_root_protocol_version, next_epoch_root_protocol_version)) =
560566
query_as::<_, (i64, String, String)>(
561567
"SELECT epoch, epoch_root_protocol_version, next_epoch_root_protocol_version FROM \
562568
stake_table_epoch WHERE epoch <= $1 ORDER BY epoch DESC LIMIT 1",
563569
)
564-
.bind(*epoch as i64)
570+
.bind(epoch)
565571
.fetch_optional(tx.as_mut())
566572
.await
567573
.context("loading epoch lower bound")?

0 commit comments

Comments
 (0)