Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

(fix) fixed spamming empty block #68

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions consensus/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ impl Block {
// Check the TC embedded in the block (if any).
if let Some(ref tc) = self.tc {
tc.verify(committee)?;
} else {
if self.payload.is_empty() {
return Err(ConsensusError::InvalidPayload);
}
}

Ok(())
}
}
Expand Down
33 changes: 17 additions & 16 deletions consensus/src/proposer.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use crate::config::{Committee, Stake};
use crate::consensus::{ConsensusMessage, Round};
use crate::messages::{Block, QC, TC};
use std::collections::HashSet;

use bytes::Bytes;
use crypto::{Digest, PublicKey, SignatureService};
use futures::stream::futures_unordered::FuturesUnordered;
use futures::stream::StreamExt as _;
use log::{debug, info};
use network::{CancelHandler, ReliableSender};
use std::collections::HashSet;
use log::{debug, warn};
use tokio::sync::mpsc::{Receiver, Sender};

use crypto::{Digest, PublicKey, SignatureService};
use network::{CancelHandler, ReliableSender};

use crate::config::{Committee, Stake};
use crate::consensus::{ConsensusMessage, Round};
use crate::messages::{Block, QC, TC};

#[derive(Debug)]
pub enum ProposerMessage {
Make(Round, QC, Option<TC>),
Expand Down Expand Up @@ -59,6 +62,13 @@ impl Proposer {
}

async fn make_block(&mut self, round: Round, qc: QC, tc: Option<TC>) {
if self.buffer.is_empty() {
if tc.is_none() {
warn!("Not now to make a new block...");
return;
}
}

// Generate a new block.
let block = Block::new(
qc,
Expand All @@ -70,15 +80,6 @@ impl Proposer {
)
.await;

if !block.payload.is_empty() {
info!("Created {}", block);

#[cfg(feature = "benchmark")]
for x in &block.payload {
// NOTE: This log entry is used to compute performance.
info!("Created {} -> {:?}", block, x);
}
}
debug!("Created {:?}", block);

// Broadcast our new block.
Expand Down