Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Problem: reading genesis time from tendermint make dev init fail(fix
Browse files Browse the repository at this point in the history
…#1705)

Solution: overwrite genesis time with current time,  add evidence params to dev.json
Problem: reading genesis time from tendermint make `dev init` fail (fix #1705)

Solution: overwrite time to tendermint genesis, also added evidence params
add comment


tidy up


fix travis issue


add no-overwrite option


add option


fix chainbot


fix integration test


add no_evidence_overwrite option


fix travis issue
  • Loading branch information
leejw51crypto committed Jun 15, 2020
1 parent 51891a0 commit 6485ea5
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ci-scripts/check-docker-app-hash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function check_command_exist() {

check_command_exist "jq"

GENERATED_APP_HASH=$(./target/debug/dev-utils genesis generate --genesis_dev_config_path ./docker/config/devnet/dev-conf.json --tendermint_genesis_path ./docker/config/devnet/tendermint/genesis.json | jq -r '.app_hash')
GENERATED_APP_HASH=$(./target/debug/dev-utils genesis generate --no_evidence_overwrite --no_genesistime_overwrite --genesis_dev_config_path ./docker/config/devnet/dev-conf.json --tendermint_genesis_path ./docker/config/devnet/tendermint/genesis.json | jq -r '.app_hash')
GENESIS_APP_HASH=$(cat ./docker/config/devnet/tendermint/genesis.json | jq -r '.app_hash')
echo "Generated app hash: ${GENERATED_APP_HASH}"
echo "Docker app hash: ${GENESIS_APP_HASH}"
Expand Down
6 changes: 5 additions & 1 deletion dev-utils/example-dev-conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
"base_fee": "1.1",
"per_byte_fee": "1.25"
},
"evidence": {
"max_age_duration": "172800000000000",
"max_age_num_blocks": "100000"
},
"council_nodes": {
"0x3ae55c16800dc4bd0e3397a9d7806fb1f11639de": [
"test",
Expand All @@ -37,4 +41,4 @@
}
]
}
}
}
56 changes: 47 additions & 9 deletions dev-utils/src/commands/genesis_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ pub enum GenesisCommand {
help = "If unbonded address is provided, all other staking addresses will be `Bonded` from genesis except from `unbonded_address`"
)]
unbonded_address: Option<String>,

#[structopt(
name = "no_genesistime_overwrite",
short = "T",
long,
help = "Don't overwrite genesistime"
)]
no_genesistime_overwrite: bool,

#[structopt(
name = "no_evidence_overwrite",
short = "E",
long,
help = "Don't overwrite evidence"
)]
no_evidence_overwrite: bool,
},
#[structopt(
name = "fingerprint",
Expand All @@ -92,12 +108,16 @@ impl GenesisCommand {
in_place,
no_backup,
unbonded_address,
no_genesistime_overwrite,
no_evidence_overwrite,
} => generate_genesis_command(
tendermint_genesis_path,
genesis_dev_config_path,
*in_place,
*no_backup,
unbonded_address,
*no_genesistime_overwrite,
*no_evidence_overwrite,
)
.map(|_| ()),
GenesisCommand::Fingerprint {
Expand Down Expand Up @@ -143,6 +163,8 @@ fn generate_genesis_command(
in_place: bool,
no_backup: bool,
unbonded_address: &Option<String>,
no_genesistime_overwrite: bool,
no_evidence_overwrite: bool,
) -> Result<()> {
let tendermint_genesis_path = match tendermint_genesis_path {
Some(path) => path.clone(),
Expand Down Expand Up @@ -182,15 +204,31 @@ fn generate_genesis_command(
)
})?;

let genesis_time = Time::from_str(
tendermint_genesis["genesis_time"]
.as_str()
.expect("genesis time config should be string"),
)
.expect("invalid genesis time format")
.duration_since(Time::unix_epoch())
.expect("invalid genesis time")
.as_secs();
let genesis_time: u64;

if no_genesistime_overwrite {
genesis_time = Time::from_str(
tendermint_genesis["genesis_time"]
.as_str()
.expect("genesis time config should be string"),
)
.expect("invalid genesis time format")
.duration_since(Time::unix_epoch())
.expect("invalid genesis time")
.as_secs();
} else {
// just use current time
let now_utc = Time::now();
genesis_time = now_utc
.duration_since(Time::unix_epoch())
.expect("invalid genesis time")
.as_secs();
tendermint_genesis["genesis_time"] = serde_json::value::Value::String(now_utc.to_string());
}
if !no_evidence_overwrite {
tendermint_genesis["consensus_params"]["evidence"] =
serde_json::json!(&genesis_dev_config.evidence);
}
let (app_hash, app_state, validators) =
generate_genesis(&genesis_dev_config, genesis_time, unbonded_address)?;

Expand Down
11 changes: 11 additions & 0 deletions dev-utils/src/commands/genesis_dev_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct GenesisDevConfig {
pub slashing_config: SlashingParameters,
pub rewards_config: RewardsParameters,
pub initial_fee_policy: InitialFeePolicy,
pub evidence: Evidence,
pub council_nodes: BTreeMap<
RedeemAddress,
(
Expand Down Expand Up @@ -53,6 +54,10 @@ impl GenesisDevConfig {
base_fee: "1.1".to_string(),
per_byte_fee: "1.25".to_string(),
},
evidence: Evidence {
max_age_duration: "5400000000000".into(),
max_age_num_blocks: "200".into(),
},
council_nodes: BTreeMap::new(),
}
}
Expand All @@ -63,3 +68,9 @@ pub struct InitialFeePolicy {
pub base_fee: String,
pub per_byte_fee: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Evidence {
pub max_age_duration: String,
pub max_age_num_blocks: String,
}
6 changes: 5 additions & 1 deletion docker/config/devnet/dev-conf.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion integration-tests/bot/chainbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ def app_state_cfg(cfg):
"base_fee": "1.1",
"per_byte_fee": "1.25"
},
"evidence": {
"max_age_duration": "172800000000003",
"max_age_num_blocks": "100004"
},
"council_nodes": {
node['staking'][0]: [
node['name'],
Expand Down Expand Up @@ -343,7 +347,7 @@ async def fix_genesis(genesis, cfg):
json.dump(cfg, fp_cfg)
fp_cfg.flush()
await run(
f'dev-utils genesis generate --in_place --no_backup '
f'dev-utils genesis generate --in_place --no_backup --no_genesistime_overwrite --no_evidence_overwrite '
f'--genesis_dev_config_path "{fp_cfg.name}" '
f'--tendermint_genesis_path "{fp_genesis.name}"'
)
Expand Down

0 comments on commit 6485ea5

Please sign in to comment.