Skip to content

Commit

Permalink
fix(rs-drive-abci): config file is broken (#892)
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek authored Apr 7, 2023
1 parent af2bd42 commit 0d51294
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 13 deletions.
5 changes: 3 additions & 2 deletions packages/rs-drive-abci/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ INITIAL_CORE_CHAINLOCKED_HEIGHT=1243
VALIDATOR_SET_LLMQ_TYPE=100
VALIDATOR_SET_QUORUM_ROTATION_BLOCK_COUNT=1024

DKG_INTERVAL=
MIN_QUORUM_VALID_MEMBERS=
DKG_INTERVAL=24
MIN_QUORUM_VALID_MEMBERS=3

# DPNS Contract

Expand Down Expand Up @@ -61,3 +61,4 @@ WITHDRAWALS_SECOND_PUBLIC_KEY=022084d827fea4823a69aa7c8d3e02fe780eaa0ef1e5e9841a
TENDERDASH_P2P_PORT=26656

QUORUM_SIZE=5
QUORUM_TYPE=llmq_25_67
5 changes: 5 additions & 0 deletions packages/rs-drive-abci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,14 @@ ENV DB_PATH=/var/lib/platform/rs-drive-abci/db
#
WORKDIR /var/lib/platform

RUN apk add --no-cache libgcc libstdc++

COPY --from=build /usr/src/platform/drive-abci /usr/bin/drive-abci
COPY --from=build /usr/src/platform/packages/rs-drive-abci/.env.example /var/lib/platform/rs-drive-abci/.env

# Double-check that we don't have missing deps
RUN ldd /usr/bin/drive-abci

#
# Create new non-root user
#
Expand Down
49 changes: 41 additions & 8 deletions packages/rs-drive-abci/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,32 @@ pub struct CoreConfig {
pub rpc: CoreRpcConfig,

/// DKG interval
pub dkg_interval: u32,
pub dkg_interval: String, // String due to https://github.com/softprops/envy/issues/26
/// Minimum number of valid members to use the quorum
pub min_quorum_valid_members: u32,
pub min_quorum_valid_members: String, // String due to https://github.com/softprops/envy/issues/26
}

impl CoreConfig {
/// return dkg_interval
pub fn dkg_interval(&self) -> u32 {
return self
.dkg_interval
.parse::<u32>()
.expect("DKG_INTERVAL is not an int");
}
/// Returns minimal number of quorum members
pub fn min_quorum_valid_members(&self) -> u32 {
return self
.min_quorum_valid_members
.parse::<u32>()
.expect("MIN_QUORUM_VALID_MEMBERS is not an int");
}
}
impl Default for CoreConfig {
fn default() -> Self {
Self {
dkg_interval: 24,
min_quorum_valid_members: 3,
dkg_interval: String::from("24"),
min_quorum_valid_members: String::from("3"),
rpc: Default::default(),
}
}
Expand Down Expand Up @@ -134,7 +150,7 @@ pub struct PlatformConfig {
pub verify_sum_trees: bool,

/// The default quorum type
pub quorum_type: QuorumType,
pub quorum_type: String,

/// The default quorum size
pub quorum_size: u16,
Expand All @@ -151,6 +167,21 @@ impl PlatformConfig {
fn default_verify_sum_trees() -> bool {
true
}

/// Return type of quorum
pub fn quorum_type(&self) -> QuorumType {
let found = if let Ok(t) = self.quorum_type.trim().parse::<u32>() {
QuorumType::from(t)
} else {
QuorumType::from(self.quorum_type.as_str())
};

if found == QuorumType::UNKNOWN {
panic!("config: unsupported QUORUM_TYPE: {}", self.quorum_type);
}

found
}
}
/// create new object using values from environment variables
pub trait FromEnv {
Expand All @@ -169,7 +200,7 @@ impl Default for PlatformConfig {
fn default() -> Self {
Self {
verify_sum_trees: true,
quorum_type: QuorumType::Llmq100_67,
quorum_type: "llmq_100_67".to_string(),
quorum_size: 100,
validator_set_quorum_rotation_block_count: 15,
drive: Default::default(),
Expand All @@ -188,17 +219,19 @@ impl Default for PlatformConfig {
mod tests {
use std::env;

use dashcore_rpc::dashcore_rpc_json::QuorumType;

use super::FromEnv;

#[test]
fn test_config_from_env() {
let envfile = format!("{}/.env.example", env!("CARGO_MANIFEST_DIR"));
let envfile = std::path::PathBuf::from(envfile);
let envfile = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(".env.example");

dotenvy::from_path(envfile.as_path()).expect("cannot load .env file");
assert_eq!("5", env::var("QUORUM_SIZE").unwrap());

let config = super::PlatformConfig::from_env().unwrap();
assert_eq!(config.verify_sum_trees, true);
assert_ne!(config.quorum_type(), QuorumType::UNKNOWN);
}
}
2 changes: 1 addition & 1 deletion packages/rs-drive-abci/src/execution/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ where
let public_key = self
.core_rpc
.get_quorum_info(
self.config.quorum_type.clone(),
self.config.quorum_type(),
&QuorumHash { 0: quorum_hash },
Some(false),
)?
Expand Down
4 changes: 2 additions & 2 deletions packages/rs-drive-abci/src/validator_set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ impl ValidatorSet {
) -> Result<Quorum, ValidatorSetError> {
// read some config
let rotation_block_interval: CoreHeight = config.validator_set_quorum_rotation_block_count;
let min_valid_members = config.core.min_quorum_valid_members;
let dkg_interval = config.core.dkg_interval;
let min_valid_members = config.core.min_quorum_valid_members();
let dkg_interval = config.core.dkg_interval();

let min_ttl: CoreHeight = rotation_block_interval * 3;

Expand Down

0 comments on commit 0d51294

Please sign in to comment.