aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/consensus.cpp49
-rw-r--r--src/crypto.cpp16
-rw-r--r--src/hotstuff.cpp13
3 files changed, 34 insertions, 44 deletions
diff --git a/src/consensus.cpp b/src/consensus.cpp
index 8b21064..8b6e977 100644
--- a/src/consensus.cpp
+++ b/src/consensus.cpp
@@ -70,7 +70,7 @@ bool HotStuffCore::on_deliver_blk(const block_t &blk) {
if (blk->qc)
{
- block_t _blk = storage->find_blk(blk->qc->get_blk_hash());
+ block_t _blk = storage->find_blk(blk->qc->get_obj_hash());
if (_blk == nullptr)
throw std::runtime_error("block referred by qc not fetched");
blk->qc_ref = std::move(_blk);
@@ -142,7 +142,6 @@ void HotStuffCore::on_propose(const std::vector<uint256_t> &cmds,
if (p != b0 && p->voted.size() >= config.nmajority)
{
qc = p->self_qc->clone();
- qc->compute();
qc_ref = p;
}
/* create the new block */
@@ -194,14 +193,12 @@ void HotStuffCore::on_receive_proposal(const Proposal &prop) {
if (bnew->qc_ref)
on_qc_finish(bnew->qc_ref);
on_receive_proposal_(prop);
- do_vote(prop.proposer,
- Vote(id,
- bqc->get_hash(),
- bnew->get_hash(),
- ((opinion && !neg_vote) ?
- create_part_cert(*priv_key, bnew->get_hash()) :
- nullptr),
- this));
+ if (opinion && !neg_vote)
+ do_vote(prop.proposer,
+ Vote(id,
+ bqc->get_hash(),
+ bnew->get_hash(),
+ create_part_cert(*priv_key, bnew->get_hash()), this));
}
void HotStuffCore::on_receive_vote(const Vote &vote) {
@@ -209,33 +206,29 @@ void HotStuffCore::on_receive_vote(const Vote &vote) {
LOG_PROTO("got %s", std::string(vote).c_str());
LOG_PROTO("now state: %s", std::string(*this).c_str());
block_t blk = get_delivered_blk(vote.blk_hash);
- if (vote.cert == nullptr) return;
- /* otherwise the vote is positive */
- //if (!vote.verify())
- //{
- // LOG_WARN("invalid vote from %d", vote.voter);
- // return;
- //}
+ assert(vote.cert);
+ size_t qsize = blk->voted.size();
+ if (qsize >= config.nmajority) return;
if (!blk->voted.insert(vote.voter).second)
{
LOG_WARN("duplicate vote from %d", vote.voter);
return;
}
- size_t qsize = blk->voted.size();
- if (qsize <= config.nmajority)
+ auto &qc = blk->self_qc;
+ if (qc == nullptr)
{
- auto &qc = blk->self_qc;
- if (qc == nullptr)
- {
- LOG_WARN("vote for block not proposed by itself");
- qc = create_quorum_cert(blk->get_hash());
- }
- qc->add_part(vote.voter, *vote.cert);
- if (qsize == config.nmajority)
- on_qc_finish(blk);
+ LOG_WARN("vote for block not proposed by itself");
+ qc = create_quorum_cert(blk->get_hash());
+ }
+ qc->add_part(vote.voter, *vote.cert);
+ if (qsize + 1 == config.nmajority)
+ {
+ qc->compute();
+ on_qc_finish(blk);
}
}
/*** end HotStuff protocol logic ***/
+void HotStuffCore::on_init(uint32_t nfaulty) { config.nmajority = 2 * nfaulty + 1; }
void HotStuffCore::prune(uint32_t staleness) {
block_t start;
diff --git a/src/crypto.cpp b/src/crypto.cpp
index c51cc02..7e839ef 100644
--- a/src/crypto.cpp
+++ b/src/crypto.cpp
@@ -23,8 +23,8 @@ secp256k1_context_t secp256k1_default_sign_ctx = new Secp256k1Context(true);
secp256k1_context_t secp256k1_default_verify_ctx = new Secp256k1Context(false);
QuorumCertSecp256k1::QuorumCertSecp256k1(
- const ReplicaConfig &config, const uint256_t &blk_hash):
- QuorumCert(), blk_hash(blk_hash), rids(config.nreplicas) {
+ const ReplicaConfig &config, const uint256_t &obj_hash):
+ QuorumCert(), obj_hash(obj_hash), rids(config.nreplicas) {
rids.clear();
}
@@ -33,9 +33,9 @@ bool QuorumCertSecp256k1::verify(const ReplicaConfig &config) {
for (size_t i = 0; i < rids.size(); i++)
if (rids.get(i))
{
- HOTSTUFF_LOG_DEBUG("checking cert(%d), blk_hash=%s",
- i, get_hex10(blk_hash).c_str());
- if (!sigs[i].verify(blk_hash,
+ HOTSTUFF_LOG_DEBUG("checking cert(%d), obj_hash=%s",
+ i, get_hex10(obj_hash).c_str());
+ if (!sigs[i].verify(obj_hash,
static_cast<const PubKeySecp256k1 &>(config.get_pubkey(i)),
secp256k1_default_verify_ctx))
return false;
@@ -50,9 +50,9 @@ promise_t QuorumCertSecp256k1::verify(const ReplicaConfig &config, VeriPool &vpo
for (size_t i = 0; i < rids.size(); i++)
if (rids.get(i))
{
- HOTSTUFF_LOG_DEBUG("checking cert(%d), blk_hash=%s",
- i, get_hex10(blk_hash).c_str());
- vpm.push_back(vpool.verify(new Secp256k1VeriTask(blk_hash,
+ HOTSTUFF_LOG_DEBUG("checking cert(%d), obj_hash=%s",
+ i, get_hex10(obj_hash).c_str());
+ vpm.push_back(vpool.verify(new Secp256k1VeriTask(obj_hash,
static_cast<const PubKeySecp256k1 &>(config.get_pubkey(i)),
sigs[i])));
}
diff --git a/src/hotstuff.cpp b/src/hotstuff.cpp
index 957d7b4..557a81e 100644
--- a/src/hotstuff.cpp
+++ b/src/hotstuff.cpp
@@ -229,7 +229,7 @@ promise_t HotStuffBase::async_deliver_blk(const uint256_t &blk_hash,
std::vector<promise_t> pms;
const auto &qc = blk->get_qc();
if (qc)
- pms.push_back(async_fetch_blk(qc->get_blk_hash(), &replica_id));
+ pms.push_back(async_fetch_blk(qc->get_obj_hash(), &replica_id));
/* the parents should be delivered */
for (const auto &phash: blk->get_parent_hashes())
pms.push_back(async_deliver_blk(phash, replica_id));
@@ -262,16 +262,13 @@ void HotStuffBase::vote_handler(MsgVote &&msg, const Net::conn_t &conn) {
RcObj<Vote> v(new Vote(std::move(msg.vote)));
promise::all(std::vector<promise_t>{
async_deliver_blk(v->bqc_hash, peer),
- async_deliver_blk(v->blk_hash, peer)
- }).then([this, v=std::move(v)]() {
- //bool result = vote->verify();
- auto pm = v->verify(vpool);
- pm.then([this, v=std::move(v)](bool result) {
- if (!result)
+ async_deliver_blk(v->blk_hash, peer),
+ v->verify(vpool),
+ }).then([this, v=std::move(v)](const promise::values_t values) {
+ if (!promise::any_cast<bool>(values[2]))
LOG_WARN("invalid vote from %d", v->voter);
else
on_receive_vote(*v);
- });
});
}