diff options
-rwxr-xr-x | scripts/run_demo.sh | 5 | ||||
-rw-r--r-- | src/consensus.cpp | 17 | ||||
-rw-r--r-- | src/hotstuff.cpp | 9 |
3 files changed, 21 insertions, 10 deletions
diff --git a/scripts/run_demo.sh b/scripts/run_demo.sh index 0ad462e..bda33cf 100755 --- a/scripts/run_demo.sh +++ b/scripts/run_demo.sh @@ -3,6 +3,11 @@ rep=({0..3}) if [[ $# -gt 0 ]]; then rep=($@) fi + +# avoid stack overflow as in our simple demo the bootstrapping replica will +# potentially have a long chain of promise resolution +ulimit -s unlimited + for i in "${rep[@]}"; do echo "starting replica $i" #valgrind --leak-check=full ./examples/hotstuff-app --conf hotstuff-sec${i}.conf > log${i} 2>&1 & diff --git a/src/consensus.cpp b/src/consensus.cpp index 9de7cc2..c6381a5 100644 --- a/src/consensus.cpp +++ b/src/consensus.cpp @@ -171,13 +171,10 @@ block_t HotStuffCore::on_propose(const std::vector<uint256_t> &cmds, update(bnew); Proposal prop(id, bnew, nullptr); LOG_PROTO("propose %s", std::string(*bnew).c_str()); - /* self-vote */ if (bnew->height <= vheight) throw std::runtime_error("new block should be higher than vheight"); - vheight = bnew->height; - on_receive_vote( - Vote(id, bnew_hash, - create_part_cert(*priv_key, bnew_hash), this)); + /* self-receive the proposal (no need to send it through the network) */ + on_receive_proposal(prop); on_propose_(prop); /* boradcast to other replicas */ do_broadcast_proposal(prop); @@ -186,9 +183,13 @@ block_t HotStuffCore::on_propose(const std::vector<uint256_t> &cmds, void HotStuffCore::on_receive_proposal(const Proposal &prop) { LOG_PROTO("got %s", std::string(prop).c_str()); + bool self_prop = prop.proposer == get_id(); block_t bnew = prop.blk; - sanity_check_delivered(bnew); - update(bnew); + if (!self_prop) + { + sanity_check_delivered(bnew); + update(bnew); + } bool opinion = false; if (bnew->height > vheight) { @@ -211,7 +212,7 @@ void HotStuffCore::on_receive_proposal(const Proposal &prop) { } } LOG_PROTO("now state: %s", std::string(*this).c_str()); - if (bnew->qc_ref) + if (!self_prop && bnew->qc_ref) on_qc_finish(bnew->qc_ref); on_receive_proposal_(prop); if (opinion && !vote_disabled) diff --git a/src/hotstuff.cpp b/src/hotstuff.cpp index af1b2b4..591397c 100644 --- a/src/hotstuff.cpp +++ b/src/hotstuff.cpp @@ -206,6 +206,11 @@ void HotStuffBase::propose_handler(MsgPropose &&msg, const Net::conn_t &conn) { auto &prop = msg.proposal; block_t blk = prop.blk; if (!blk) return; + if (peer != get_config().get_peer_id(prop.proposer)) + { + LOG_WARN("invalid proposal from %d", prop.proposer); + return; + } promise::all(std::vector<promise_t>{ async_deliver_blk(blk->get_hash(), peer) }).then([this, prop = std::move(prop)]() { @@ -383,8 +388,8 @@ void HotStuffBase::do_vote(ReplicaID last_proposer, const Vote &vote) { .then([this, vote](ReplicaID proposer) { if (proposer == get_id()) { - throw HotStuffError("unreachable line"); - //on_receive_vote(vote); + //throw HotStuffError("unreachable line"); + on_receive_vote(vote); } else pn.send_msg(MsgVote(vote), get_config().get_peer_id(proposer)); |