Skip to content

Commit

Permalink
fix(consensus): Get authority list returns none. (nervosnetwork#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
yejiayu authored Sep 26, 2019
1 parent 1769faa commit 2a7eb3c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 29 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ log = "0.4"
clap = "2.33"
bytes = "0.4"
hex = "0.3"
rlp = "0.4"

[workspace]
members = [
Expand Down
2 changes: 1 addition & 1 deletion core/consensus/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn gen_overlord_status(epoch_id: u64, interval: u64, validators: Vec<Validator>)

authority_list.sort();
Status {
epoch_id: epoch_id + 1,
epoch_id,
interval: Some(interval),
authority_list,
}
Expand Down
42 changes: 20 additions & 22 deletions core/consensus/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,31 @@ impl<Adapter: ConsensusAdapter + 'static> Engine<FixedPill, FixedSignedTxs>
) -> Result<(FixedPill, Bytes), Box<dyn Error + Send>> {
let current_consensus_status = { self.current_consensus_status.read().clone() };

let tmp = epoch_id;
let (ordered_tx_hashes, propose_hashes) = self
.adapter
.get_txs_from_mempool(ctx, epoch_id, current_consensus_status.cycles_limit)
.await?
.clap();

if current_consensus_status.epoch_id == epoch_id {
if current_consensus_status.epoch_id != epoch_id {
return Err(ProtocolError::from(ConsensusError::MissingEpochHeader(epoch_id)).into());
}

let header = EpochHeader {
chain_id: self.node_info.chain_id.clone(),
pre_hash: current_consensus_status.prev_hash,
epoch_id: tmp,
timestamp: time_now(),
logs_bloom: current_consensus_status.logs_bloom,
order_root: current_consensus_status.order_root.clone(),
confirm_root: current_consensus_status.confirm_root.clone(),
state_root: current_consensus_status.state_root.clone(),
receipt_root: current_consensus_status.receipt_root.clone(),
cycles_used: current_consensus_status.cycles_used,
proposer: self.node_info.self_address.clone(),
proof: current_consensus_status.proof.clone(),
chain_id: self.node_info.chain_id.clone(),
pre_hash: current_consensus_status.prev_hash,
epoch_id,
timestamp: time_now(),
logs_bloom: current_consensus_status.logs_bloom,
order_root: current_consensus_status.order_root.clone(),
confirm_root: current_consensus_status.confirm_root.clone(),
state_root: current_consensus_status.state_root.clone(),
receipt_root: current_consensus_status.receipt_root.clone(),
cycles_used: current_consensus_status.cycles_used,
proposer: self.node_info.self_address.clone(),
proof: current_consensus_status.proof.clone(),
validator_version: 0u64,
validators: current_consensus_status.validators.clone(),
validators: current_consensus_status.validators.clone(),
};
let epoch = Epoch {
header,
Expand Down Expand Up @@ -136,15 +135,14 @@ impl<Adapter: ConsensusAdapter + 'static> Engine<FixedPill, FixedSignedTxs>
}

let pill = commit.content.inner;
let tmp = commit.proof;

// Sorage save the lastest proof.
let proof = Proof {
epoch_id: tmp.epoch_id,
round: tmp.round,
epoch_hash: Hash::from_bytes(tmp.epoch_hash)?,
signature: tmp.signature.signature,
bitmap: tmp.signature.address_bitmap,
epoch_id: commit.proof.epoch_id,
round: commit.proof.round,
epoch_hash: Hash::from_bytes(commit.proof.epoch_hash)?,
signature: commit.proof.signature.signature,
bitmap: commit.proof.signature.address_bitmap,
};

self.adapter.save_proof(ctx.clone(), proof.clone()).await?;
Expand Down Expand Up @@ -181,7 +179,7 @@ impl<Adapter: ConsensusAdapter + 'static> Engine<FixedPill, FixedSignedTxs>
};

let status = Status {
epoch_id: current_consensus_status.epoch_id,
epoch_id: epoch_id + 1,
interval: Some(current_consensus_status.consensus_interval),
authority_list: covert_to_overlord_authority(&current_consensus_status.validators),
};
Expand Down
2 changes: 1 addition & 1 deletion core/consensus/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mod engine;
mod fixed_types;
mod util;

pub mod adapter;
pub mod consensus;
pub mod fixed_types;
pub mod message;

pub use overlord::DurationConfig;
Expand Down
27 changes: 22 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use core_api::adapter::DefaultAPIAdapter;
use core_api::config::GraphQLConfig;
use core_consensus::adapter::OverlordConsensusAdapter;
use core_consensus::consensus::OverlordConsensus;
use core_consensus::fixed_types::FixedPill;
use core_consensus::message::{
ProposalMessageHandler, QCMessageHandler, VoteMessageHandler, END_GOSSIP_AGGREGATED_VOTE,
END_GOSSIP_SIGNED_PROPOSAL, END_GOSSIP_SIGNED_VOTE,
Expand All @@ -27,7 +28,8 @@ use core_storage::{adapter::rocks::RocksAdapter, ImplStorage};
use protocol::traits::executor::ExecutorFactory;
use protocol::traits::{CurrentConsensusStatus, NodeInfo, Storage};
use protocol::types::{
Address, Bloom, Epoch, EpochHeader, Genesis, Hash, MerkleRoot, Proof, UserAddress,
Address, Bloom, Epoch, EpochHeader, Genesis, Hash, MerkleRoot, Pill, Proof, UserAddress,
Validator,
};
use protocol::ProtocolResult;

Expand Down Expand Up @@ -214,20 +216,35 @@ async fn start(cfg: &Config) -> ProtocolResult<()> {
self_address: my_address.clone(),
};
let current_header = &current_epoch.header;
// TODO: pre hash.

let prevhash = Hash::digest(Bytes::from(rlp::encode(&FixedPill {
inner: Pill {
epoch: current_epoch.clone(),
propose_hashes: vec![],
},
})));
let current_consensus_status = CurrentConsensusStatus {
cycles_price: cfg.consensus.cycles_price,
cycles_limit: cfg.consensus.cycles_limit,
epoch_id: current_epoch.header.epoch_id,
prev_hash: Hash::from_empty(),
epoch_id: current_epoch.header.epoch_id + 1,
prev_hash: prevhash,
logs_bloom: current_header.logs_bloom,
order_root: current_header.order_root.clone(),
confirm_root: current_header.confirm_root.clone(),
state_root: current_header.state_root.clone(),
receipt_root: current_header.receipt_root.clone(),
cycles_used: current_header.cycles_used,
proof: current_header.proof.clone(),
validators: current_header.validators.clone(),
validators: cfg
.consensus
.verifier_list
.iter()
.map(|v| Validator {
address: UserAddress::from_hex(v).unwrap(),
propose_weight: 1,
vote_weight: 1,
})
.collect(),
consensus_interval: cfg.consensus.interval,
};

Expand Down

0 comments on commit 2a7eb3c

Please sign in to comment.