|
|
@ -26,43 +26,54 @@ pub enum CheckpointSyncerConf { |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl CheckpointSyncerConf { |
|
|
|
/// Error for parsing announced storage locations
|
|
|
|
/// Create a CheckpointSyncerConf from a storage location string
|
|
|
|
#[derive(Debug, PartialEq, Eq)] |
|
|
|
pub fn from_storage_location(storage_location: &str) -> Option<Self> { |
|
|
|
pub struct ParseStorageLocationError; |
|
|
|
let s3_prefix = "s3://"; |
|
|
|
|
|
|
|
let local_prefix = "file://"; |
|
|
|
impl FromStr for CheckpointSyncerConf { |
|
|
|
if let Some(location) = storage_location.strip_prefix(s3_prefix) { |
|
|
|
type Err = ParseStorageLocationError; |
|
|
|
let pieces: Vec<&str> = location.split('/').collect(); |
|
|
|
|
|
|
|
if pieces.len() == 2 { |
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> { |
|
|
|
Some(CheckpointSyncerConf::S3 { |
|
|
|
let [prefix, suffix]: [&str; 2] = s |
|
|
|
bucket: pieces[0].into(), |
|
|
|
.split("://") |
|
|
|
region: pieces[1].into(), |
|
|
|
.collect::<Vec<_>>() |
|
|
|
|
|
|
|
.try_into() |
|
|
|
|
|
|
|
.map_err(|_| ParseStorageLocationError)?; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match prefix { |
|
|
|
|
|
|
|
"s3" => { |
|
|
|
|
|
|
|
let [bucket, region]: [&str; 2] = suffix |
|
|
|
|
|
|
|
.split('/') |
|
|
|
|
|
|
|
.collect::<Vec<_>>() |
|
|
|
|
|
|
|
.try_into() |
|
|
|
|
|
|
|
.map_err(|_| ParseStorageLocationError)?; |
|
|
|
|
|
|
|
Ok(CheckpointSyncerConf::S3 { |
|
|
|
|
|
|
|
bucket: bucket.into(), |
|
|
|
|
|
|
|
region: region.into(), |
|
|
|
}) |
|
|
|
}) |
|
|
|
} else { |
|
|
|
|
|
|
|
None |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
"file" => Ok(CheckpointSyncerConf::LocalStorage { |
|
|
|
storage_location |
|
|
|
path: suffix.into(), |
|
|
|
.strip_prefix(local_prefix) |
|
|
|
}), |
|
|
|
.map(|path| CheckpointSyncerConf::LocalStorage { path: path.into() }) |
|
|
|
_ => Err(ParseStorageLocationError), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl CheckpointSyncerConf { |
|
|
|
/// Turn conf info a Checkpoint Syncer
|
|
|
|
/// Turn conf info a Checkpoint Syncer
|
|
|
|
pub fn build( |
|
|
|
pub fn build( |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
latest_index_gauge: Option<IntGauge>, |
|
|
|
latest_index_gauge: Option<IntGauge>, |
|
|
|
) -> Result<Box<dyn CheckpointSyncer>, Report> { |
|
|
|
) -> Result<Box<dyn CheckpointSyncer>, Report> { |
|
|
|
match self { |
|
|
|
Ok(match self { |
|
|
|
CheckpointSyncerConf::LocalStorage { path } => { |
|
|
|
CheckpointSyncerConf::LocalStorage { path } => { |
|
|
|
Ok(Box::new(LocalStorage::new(path, latest_index_gauge))) |
|
|
|
Box::new(LocalStorage::new(path, latest_index_gauge)) |
|
|
|
} |
|
|
|
} |
|
|
|
CheckpointSyncerConf::S3 { bucket, region } => Ok(Box::new(S3Storage::new( |
|
|
|
CheckpointSyncerConf::S3 { bucket, region } => { |
|
|
|
bucket, |
|
|
|
Box::new(S3Storage::new(bucket, region.parse()?, latest_index_gauge)) |
|
|
|
region.parse().expect("invalid s3 region"), |
|
|
|
} |
|
|
|
latest_index_gauge, |
|
|
|
}) |
|
|
|
))), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -85,7 +96,11 @@ impl MultisigCheckpointSyncerConf { |
|
|
|
for (key, value) in self.checkpointsyncers.iter() { |
|
|
|
for (key, value) in self.checkpointsyncers.iter() { |
|
|
|
let gauge = |
|
|
|
let gauge = |
|
|
|
validator_checkpoint_index.with_label_values(&[origin, &key.to_lowercase()]); |
|
|
|
validator_checkpoint_index.with_label_values(&[origin, &key.to_lowercase()]); |
|
|
|
checkpoint_syncers.insert(Address::from_str(key)?, value.build(Some(gauge))?.into()); |
|
|
|
if let Ok(conf) = value.build(Some(gauge)) { |
|
|
|
|
|
|
|
checkpoint_syncers.insert(Address::from_str(key)?, conf.into()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Ok(MultisigCheckpointSyncer::new(checkpoint_syncers)) |
|
|
|
Ok(MultisigCheckpointSyncer::new(checkpoint_syncers)) |
|
|
|
} |
|
|
|
} |
|
|
|