mirror of https://github.com/poanetwork/hbbft.git
Rename input to handle_input.
Also update `.gitignore` to avoid checking in test logs.
This commit is contained in:
parent
85550fcf82
commit
f27eed4eef
|
@ -2,3 +2,4 @@ src/proto/message.rs
|
|||
/target
|
||||
**/*.rs.bk
|
||||
Cargo.lock
|
||||
net-trace_*.txt
|
||||
|
|
|
@ -147,7 +147,9 @@ impl<T: Clone + Debug + AsRef<[u8]> + PartialEq + Send + Sync + From<Vec<u8>> +
|
|||
|
||||
if let Some(v) = value {
|
||||
// FIXME: Use the output.
|
||||
let step = broadcast.input(v.clone().into()).expect("propose value");
|
||||
let step = broadcast
|
||||
.handle_input(v.clone().into())
|
||||
.expect("propose value");
|
||||
for msg in step.messages {
|
||||
tx_from_algo.send(msg).expect("send from algo");
|
||||
}
|
||||
|
|
|
@ -79,8 +79,8 @@ impl<N: NodeUidT> DistAlgorithm for Agreement<N> {
|
|||
type Message = Message;
|
||||
type Error = Error;
|
||||
|
||||
fn input(&mut self, input: Self::Input) -> Result<Step<N>> {
|
||||
self.set_input(input)
|
||||
fn handle_input(&mut self, input: Self::Input) -> Result<Step<N>> {
|
||||
self.handle_input(input)
|
||||
}
|
||||
|
||||
/// Receive input from a remote node.
|
||||
|
@ -131,14 +131,14 @@ impl<N: NodeUidT> Agreement<N> {
|
|||
}
|
||||
|
||||
/// Sets the input value for agreement.
|
||||
fn set_input(&mut self, input: bool) -> Result<Step<N>> {
|
||||
fn handle_input(&mut self, input: bool) -> Result<Step<N>> {
|
||||
if self.epoch != 0 || self.estimated.is_some() {
|
||||
return Err(Error::InputNotAccepted);
|
||||
}
|
||||
// Set the initial estimated value to the input value.
|
||||
self.estimated = Some(input);
|
||||
debug!("{:?}/{:?} Input {}", self.our_id(), self.proposer_id, input);
|
||||
let sbvb_step = self.sbv_broadcast.input(input)?;
|
||||
let sbvb_step = self.sbv_broadcast.handle_input(input)?;
|
||||
self.handle_sbvb_step(sbvb_step)
|
||||
}
|
||||
|
||||
|
@ -357,9 +357,9 @@ impl<N: NodeUidT> Agreement<N> {
|
|||
// Invoke the coin.
|
||||
let coin_step = match self.coin_state {
|
||||
CoinState::Decided(_) => return Ok(Step::default()), // Coin has already decided.
|
||||
CoinState::InProgress(ref mut coin) => {
|
||||
coin.input(()).map_err(Error::TryFinishConfRoundCoin)?
|
||||
}
|
||||
CoinState::InProgress(ref mut coin) => coin
|
||||
.handle_input(())
|
||||
.map_err(Error::TryFinishConfRoundCoin)?,
|
||||
};
|
||||
let mut step = self.on_coin_step(coin_step)?;
|
||||
step.extend(self.try_update_epoch()?);
|
||||
|
@ -391,7 +391,7 @@ impl<N: NodeUidT> Agreement<N> {
|
|||
);
|
||||
|
||||
self.estimated = Some(b);
|
||||
let sbvb_step = self.sbv_broadcast.input(b)?;
|
||||
let sbvb_step = self.sbv_broadcast.handle_input(b)?;
|
||||
let mut step = self.handle_sbvb_step(sbvb_step)?;
|
||||
let queued_msgs = Itertools::flatten(self.incoming_queue.remove(&self.epoch).into_iter());
|
||||
for (sender_id, content) in queued_msgs {
|
||||
|
|
|
@ -65,7 +65,7 @@ impl<N: NodeUidT> DistAlgorithm for SbvBroadcast<N> {
|
|||
type Message = Message;
|
||||
type Error = Error;
|
||||
|
||||
fn input(&mut self, input: Self::Input) -> Result<Step<N>> {
|
||||
fn handle_input(&mut self, input: Self::Input) -> Result<Step<N>> {
|
||||
self.send_bval(input)
|
||||
}
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ impl<N: NodeUidT> DistAlgorithm for Broadcast<N> {
|
|||
type Message = Message;
|
||||
type Error = Error;
|
||||
|
||||
fn input(&mut self, input: Self::Input) -> Result<Step<N>> {
|
||||
fn handle_input(&mut self, input: Self::Input) -> Result<Step<N>> {
|
||||
if *self.netinfo.our_uid() != self.proposer_id {
|
||||
return Err(Error::InstanceCannotPropose);
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@
|
|||
//! // Now we can start the algorithm, its input is the payload.
|
||||
//! let initial_step = {
|
||||
//! let proposer = nodes.get_mut(&PROPOSER_ID).unwrap();
|
||||
//! proposer.input(payload.clone()).unwrap()
|
||||
//! proposer.handle_input(payload.clone()).unwrap()
|
||||
//! };
|
||||
//! on_step(
|
||||
//! PROPOSER_ID,
|
||||
|
|
|
@ -87,7 +87,7 @@ where
|
|||
type Error = Error;
|
||||
|
||||
/// Sends our threshold signature share if not yet sent.
|
||||
fn input(&mut self, _input: Self::Input) -> Result<Step<N, T>> {
|
||||
fn handle_input(&mut self, _input: Self::Input) -> Result<Step<N, T>> {
|
||||
if !self.had_input {
|
||||
self.had_input = true;
|
||||
self.get_coin()
|
||||
|
@ -173,7 +173,7 @@ where
|
|||
let parity = sig.parity();
|
||||
debug!("{:?} output {}", self.netinfo.our_uid(), parity);
|
||||
self.terminated = true;
|
||||
let step = self.input(())?; // Before terminating, make sure we sent our share.
|
||||
let step = self.handle_input(())?; // Before terminating, make sure we sent our share.
|
||||
Ok(step.with_output(parity))
|
||||
} else {
|
||||
Ok(Step::default())
|
||||
|
|
|
@ -49,7 +49,7 @@ where
|
|||
type Message = Message<N>;
|
||||
type Error = Error;
|
||||
|
||||
fn input(&mut self, input: Self::Input) -> Result<Step<C, N>> {
|
||||
fn handle_input(&mut self, input: Self::Input) -> Result<Step<C, N>> {
|
||||
// User contributions are forwarded to `HoneyBadger` right away. Votes are signed and
|
||||
// broadcast.
|
||||
match input {
|
||||
|
@ -112,7 +112,7 @@ where
|
|||
pub fn propose(&mut self, contrib: C) -> Result<Step<C, N>> {
|
||||
let step = self
|
||||
.honey_badger
|
||||
.input(InternalContrib {
|
||||
.handle_input(InternalContrib {
|
||||
contrib,
|
||||
key_gen_messages: self.key_gen_msg_buffer.clone(),
|
||||
votes: self.vote_counter.pending_votes().cloned().collect(),
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
//! algorithm.
|
||||
//!
|
||||
//! Each algorithm can propogate their faulty node logs upwards to a
|
||||
//! calling algorithm via `DistAlgorihm`'s `.input()` and
|
||||
//! calling algorithm via `DistAlgorihm`'s `.handle_input()` and
|
||||
//! `.handle_message()` trait methods.
|
||||
|
||||
/// A fault log entry.
|
||||
|
|
|
@ -44,7 +44,7 @@ where
|
|||
/// Handles a ciphertext input.
|
||||
fn set_ciphertext(&mut self, ciphertext: Ciphertext) -> td::Result<td::Step<N>> {
|
||||
match self {
|
||||
DecryptionState::Ongoing(ref mut td) => td.input(ciphertext),
|
||||
DecryptionState::Ongoing(ref mut td) => td.handle_input(ciphertext),
|
||||
DecryptionState::Complete(_) => Ok(td::Step::default()),
|
||||
}
|
||||
}
|
||||
|
@ -72,9 +72,9 @@ where
|
|||
N: NodeUidT + Rand,
|
||||
{
|
||||
/// Provides input to the Subset instance, unless it has already completed.
|
||||
fn input(&mut self, proposal: Vec<u8>) -> Result<cs::Step<N>> {
|
||||
fn handle_input(&mut self, proposal: Vec<u8>) -> Result<cs::Step<N>> {
|
||||
match self {
|
||||
SubsetState::Ongoing(ref mut cs) => cs.input(proposal),
|
||||
SubsetState::Ongoing(ref mut cs) => cs.handle_input(proposal),
|
||||
SubsetState::Complete(_) => return Ok(cs::Step::default()),
|
||||
}.map_err(|err| ErrorKind::InputSubset(err).into())
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ where
|
|||
/// If the instance hasn't terminated yet, inputs our encrypted contribution.
|
||||
pub fn propose(&mut self, ciphertext: &Ciphertext) -> Result<Step<C, N>> {
|
||||
let ser_ct = bincode::serialize(ciphertext).map_err(|err| ErrorKind::ProposeBincode(*err))?;
|
||||
let cs_step = self.subset.input(ser_ct)?;
|
||||
let cs_step = self.subset.handle_input(ser_ct)?;
|
||||
self.process_subset(cs_step)
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ where
|
|||
type Message = Message<N>;
|
||||
type Error = Error;
|
||||
|
||||
fn input(&mut self, input: Self::Input) -> Result<Step<C, N>> {
|
||||
fn handle_input(&mut self, input: Self::Input) -> Result<Step<C, N>> {
|
||||
self.propose(&input)
|
||||
}
|
||||
|
||||
|
|
|
@ -198,7 +198,7 @@ pub trait DistAlgorithm {
|
|||
type Error: Fail;
|
||||
|
||||
/// Handles an input provided by the user, and returns
|
||||
fn input(&mut self, input: Self::Input) -> Result<Step<Self>, Self::Error>
|
||||
fn handle_input(&mut self, input: Self::Input) -> Result<Step<Self>, Self::Error>
|
||||
where
|
||||
Self: Sized;
|
||||
|
||||
|
|
|
@ -185,7 +185,7 @@ where
|
|||
type Message = Message<N>;
|
||||
type Error = Error;
|
||||
|
||||
fn input(&mut self, input: Self::Input) -> Result<Step<T, N>> {
|
||||
fn handle_input(&mut self, input: Self::Input) -> Result<Step<T, N>> {
|
||||
// User transactions are forwarded to `HoneyBadger` right away. Internal messages are
|
||||
// in addition signed and broadcast.
|
||||
let mut step = match input {
|
||||
|
@ -195,7 +195,7 @@ where
|
|||
}
|
||||
Input::Change(change) => self
|
||||
.dyn_hb
|
||||
.input(Input::Change(change))
|
||||
.handle_input(Input::Change(change))
|
||||
.map_err(ErrorKind::Input)?
|
||||
.convert(),
|
||||
};
|
||||
|
@ -259,7 +259,7 @@ where
|
|||
let proposal = self.queue.choose(amount, self.batch_size);
|
||||
step.extend(
|
||||
self.dyn_hb
|
||||
.input(Input::User(proposal))
|
||||
.handle_input(Input::User(proposal))
|
||||
.map_err(ErrorKind::Propose)?
|
||||
.convert(),
|
||||
);
|
||||
|
|
|
@ -93,7 +93,7 @@ impl<N: NodeUidT + Rand> DistAlgorithm for Subset<N> {
|
|||
type Message = Message<N>;
|
||||
type Error = Error;
|
||||
|
||||
fn input(&mut self, input: Self::Input) -> Result<Step<N>> {
|
||||
fn handle_input(&mut self, input: Self::Input) -> Result<Step<N>> {
|
||||
debug!(
|
||||
"{:?} Proposing {:?}",
|
||||
self.netinfo.our_uid(),
|
||||
|
@ -161,7 +161,7 @@ impl<N: NodeUidT + Rand> Subset<N> {
|
|||
}
|
||||
let uid = self.netinfo.our_uid().clone();
|
||||
// Upon receiving input v_i , input v_i to RBC_i. See Figure 2.
|
||||
self.process_broadcast(&uid, |bc| bc.input(value))
|
||||
self.process_broadcast(&uid, |bc| bc.handle_input(value))
|
||||
}
|
||||
|
||||
/// Returns the number of validators from which we have already received a proposal.
|
||||
|
@ -220,7 +220,7 @@ impl<N: NodeUidT + Rand> Subset<N> {
|
|||
self.broadcast_results.insert(proposer_id.clone(), value);
|
||||
let set_agreement_input = |agreement: &mut Agreement<N>| {
|
||||
if agreement.accepts_input() {
|
||||
agreement.input(true)
|
||||
agreement.handle_input(true)
|
||||
} else {
|
||||
Ok(agreement::Step::default())
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ impl<N: NodeUidT + Rand> Subset<N> {
|
|||
let to_msg = |a_msg| Message::Agreement(uid.clone(), a_msg);
|
||||
for output in step.extend_with(
|
||||
agreement
|
||||
.input(false)
|
||||
.handle_input(false)
|
||||
.map_err(Error::ProcessAgreementAgreement1)?,
|
||||
to_msg,
|
||||
) {
|
||||
|
|
|
@ -61,7 +61,7 @@ impl<N: NodeUidT> DistAlgorithm for ThresholdDecryption<N> {
|
|||
type Message = Message;
|
||||
type Error = Error;
|
||||
|
||||
fn input(&mut self, input: Ciphertext) -> Result<Step<N>> {
|
||||
fn handle_input(&mut self, input: Ciphertext) -> Result<Step<N>> {
|
||||
self.set_ciphertext(input)
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ impl Adversary<Broadcast<NodeUid>> for ProposeAdversary {
|
|||
);
|
||||
let mut bc = Broadcast::new(netinfo, id).expect("broadcast instance");
|
||||
// FIXME: Use the output.
|
||||
let step = bc.input(b"Fake news".to_vec()).expect("propose");
|
||||
let step = bc.handle_input(b"Fake news".to_vec()).expect("propose");
|
||||
step.messages
|
||||
.into_iter()
|
||||
.map(|msg| MessageWithSender::new(id, msg))
|
||||
|
|
|
@ -30,7 +30,7 @@ where
|
|||
A: Adversary<Coin<NodeUid, String>>,
|
||||
{
|
||||
network.input_all(());
|
||||
network.observer.input(()); // Observer will only return after `input` was called.
|
||||
network.observer.handle_input(()); // Observer will only return after `input` was called.
|
||||
|
||||
// Handle messages until all good nodes have terminated.
|
||||
while !network.nodes.values().all(TestNode::terminated) {
|
||||
|
|
|
@ -588,7 +588,7 @@ where
|
|||
.get_mut(&id)
|
||||
.expect("cannot handle input on non-existing node")
|
||||
.algorithm
|
||||
.input(input)?;
|
||||
.handle_input(input)?;
|
||||
|
||||
self.message_count = self.message_count.saturating_add(process_step(
|
||||
&mut self.nodes,
|
||||
|
@ -727,7 +727,12 @@ where
|
|||
let steps: Vec<_> = self
|
||||
.nodes
|
||||
.values_mut()
|
||||
.map(move |node| Ok((node.id().clone(), node.algorithm.input(input.clone())?)))
|
||||
.map(move |node| {
|
||||
Ok((
|
||||
node.id().clone(),
|
||||
node.algorithm.handle_input(input.clone())?,
|
||||
))
|
||||
})
|
||||
.collect::<Result<_, _>>()?;
|
||||
|
||||
// Process all messages from all steps in the queue.
|
||||
|
|
|
@ -134,7 +134,7 @@ fn do_drop_and_readd(
|
|||
.public_key();
|
||||
let _ = net[node_id]
|
||||
.algorithm_mut()
|
||||
.input(Input::Change(Change::Add(*pivot_node_id, pk)))
|
||||
.handle_input(Input::Change(Change::Add(*pivot_node_id, pk)))
|
||||
.expect("failed to send `Add` input");
|
||||
}
|
||||
|
||||
|
|
|
@ -39,8 +39,8 @@ impl<D: DistAlgorithm> TestNode<D> {
|
|||
}
|
||||
|
||||
/// Inputs a value into the instance.
|
||||
pub fn input(&mut self, input: D::Input) {
|
||||
let step = self.algo.input(input).expect("input");
|
||||
pub fn handle_input(&mut self, input: D::Input) {
|
||||
let step = self.algo.handle_input(input).expect("input");
|
||||
self.outputs.extend(step.output);
|
||||
self.messages.extend(step.messages);
|
||||
}
|
||||
|
@ -523,7 +523,7 @@ where
|
|||
pub fn input(&mut self, id: NodeUid, value: D::Input) {
|
||||
let msgs: Vec<_> = {
|
||||
let mut node = self.nodes.get_mut(&id).expect("input instance");
|
||||
node.input(value);
|
||||
node.handle_input(value);
|
||||
node.messages.drain(..).collect()
|
||||
};
|
||||
self.dispatch_messages(id, msgs);
|
||||
|
|
Loading…
Reference in New Issue