vote propose

This commit is contained in:
keorn 2016-11-28 18:58:15 +00:00
parent 0f1eefc00d
commit 61cf8b8b7e

View File

@ -194,14 +194,16 @@ impl Tendermint {
trace!(target: "poa", "to_step: Transitioning to Commit."); trace!(target: "poa", "to_step: Transitioning to Commit.");
// Commit the block using a complete signature set. // Commit the block using a complete signature set.
let round = self.round.load(AtomicOrdering::SeqCst); let round = self.round.load(AtomicOrdering::SeqCst);
if let Some(seal) = self.votes.seal_signatures(self.height.load(AtomicOrdering::SeqCst), round, *self.proposal.read()) { if let Some(block_hash) = *self.proposal.read() {
let seal = vec![ if let Some(seal) = self.votes.seal_signatures(self.height.load(AtomicOrdering::SeqCst), round, block_hash) {
::rlp::encode(&round).to_vec(), let seal = vec![
::rlp::encode(&seal.proposal).to_vec(), ::rlp::encode(&round).to_vec(),
::rlp::encode(&seal.votes).to_vec() ::rlp::encode(&seal.proposal).to_vec(),
]; ::rlp::encode(&seal.votes).to_vec()
if let Some(block_hash) = *self.proposal.read() { ];
self.submit_seal(block_hash, seal); self.submit_seal(block_hash, seal);
} else {
warn!(target: "poa", "Proposal was not found!");
} }
} }
*self.lock_change.write() = None; *self.lock_change.write() = None;
@ -327,12 +329,16 @@ impl Engine for Tendermint {
if let Some(ref ap) = *self.account_provider.lock() { if let Some(ref ap) = *self.account_provider.lock() {
let header = block.header(); let header = block.header();
let author = header.author(); let author = header.author();
let vote_info = message_info_rlp(header.number() as Height, self.round.load(AtomicOrdering::SeqCst), Step::Propose, Some(header.bare_hash())); let height = header.number() as Height;
if let Ok(signature) = ap.sign(*author, None, vote_info.sha3()) { let round = self.round.load(AtomicOrdering::SeqCst);
let bh = Some(header.bare_hash());
let vote_info = message_info_rlp(height, round, Step::Propose, bh);
if let Ok(signature) = ap.sign(*author, None, vote_info.sha3()).map(H520::from) {
self.votes.vote(ConsensusMessage { signature: signature, height: height, round: round, step: Step::Propose, block_hash: bh }, *author);
*self.proposal.write() = Some(header.bare_hash()); *self.proposal.write() = Some(header.bare_hash());
Some(vec![ Some(vec![
::rlp::encode(&self.round.load(AtomicOrdering::SeqCst)).to_vec(), ::rlp::encode(&self.round.load(AtomicOrdering::SeqCst)).to_vec(),
::rlp::encode(&H520::from(signature)).to_vec(), ::rlp::encode(&signature).to_vec(),
Vec::new() Vec::new()
]) ])
} else { } else {
@ -551,16 +557,16 @@ mod tests {
} }
struct TestIo { struct TestIo {
received: Mutex<Option<ClientIoMessage>> received: RwLock<Vec<ClientIoMessage>>
} }
impl TestIo { impl TestIo {
fn new() -> Arc<Self> { Arc::new(TestIo { received: Mutex::new(None) }) } fn new() -> Arc<Self> { Arc::new(TestIo { received: RwLock::new(Vec::new()) }) }
} }
impl IoHandler<ClientIoMessage> for TestIo { impl IoHandler<ClientIoMessage> for TestIo {
fn message(&self, _io: &IoContext<ClientIoMessage>, net_message: &ClientIoMessage) { fn message(&self, _io: &IoContext<ClientIoMessage>, net_message: &ClientIoMessage) {
*self.received.lock() = Some(net_message.clone()); self.received.write().push(net_message.clone());
} }
} }
@ -671,7 +677,6 @@ mod tests {
} }
#[test] #[test]
#[should_panic]
fn step_transitioning() { fn step_transitioning() {
::env_logger::init().unwrap(); ::env_logger::init().unwrap();
let (spec, tap) = setup(); let (spec, tap) = setup();
@ -704,8 +709,8 @@ mod tests {
vote(&engine, |mh| tap.sign(v1, None, mh).ok().map(H520::from), h, r, Step::Precommit, proposal); vote(&engine, |mh| tap.sign(v1, None, mh).ok().map(H520::from), h, r, Step::Precommit, proposal);
vote(&engine, |mh| tap.sign(v0, None, mh).ok().map(H520::from), h, r, Step::Precommit, proposal); vote(&engine, |mh| tap.sign(v0, None, mh).ok().map(H520::from), h, r, Step::Precommit, proposal);
::std::thread::sleep(::std::time::Duration::from_millis(50)); ::std::thread::sleep(::std::time::Duration::from_millis(500));
assert_eq!(*test_io.received.lock(), Some(ClientIoMessage::SubmitSeal(proposal.unwrap(), seal))); assert_eq!(test_io.received.read()[5], ClientIoMessage::SubmitSeal(proposal.unwrap(), seal));
} }
#[test] #[test]