blob: ed15cc1758dae3604680212237c90cb6c54d7a78 (
plain) (
tree)
|
|
#include "hotstuff/hotstuff.h"
using salticidae::static_pointer_cast;
#define LOG_INFO HOTSTUFF_LOG_INFO
#define LOG_DEBUG HOTSTUFF_LOG_DEBUG
#define LOG_WARN HOTSTUFF_LOG_WARN
namespace hotstuff {
void MsgHotStuff::gen_propose(const Proposal &proposal) {
DataStream s;
set_opcode(PROPOSE);
s << proposal;
set_payload(std::move(s));
}
void MsgHotStuff::parse_propose(Proposal &proposal) const {
DataStream(get_payload()) >> proposal;
}
void MsgHotStuff::gen_vote(const Vote &vote) {
DataStream s;
set_opcode(VOTE);
s << vote;
set_payload(std::move(s));
}
void MsgHotStuff::parse_vote(Vote &vote) const {
DataStream(get_payload()) >> vote;
}
void MsgHotStuff::gen_qfetchblk(const std::vector<uint256_t> &blk_hashes) {
DataStream s;
set_opcode(QUERY_FETCH_BLK);
gen_hash_list(s, blk_hashes);
set_payload(std::move(s));
}
void MsgHotStuff::parse_qfetchblk(std::vector<uint256_t> &blk_hashes) const {
DataStream s(get_payload());
parse_hash_list(s, blk_hashes);
}
void MsgHotStuff::gen_rfetchblk(const std::vector<block_t> &blks) {
DataStream s;
set_opcode(RESP_FETCH_BLK);
s << htole((uint32_t)blks.size());
for (auto blk: blks) s << *blk;
set_payload(std::move(s));
}
void MsgHotStuff::parse_rfetchblk(std::vector<block_t> &blks, HotStuffCore *hsc) const {
DataStream s;
uint32_t size;
s >> size;
size = letoh(size);
blks.resize(size);
for (auto &blk: blks)
{
Block _blk;
_blk.unserialize(s, hsc);
if (!_blk.verify(hsc->get_config()))
blk = hsc->storage->add_blk(std::move(_blk));
else
{
blk = nullptr;
LOG_WARN("block is invalid");
}
}
}
ReplicaID HotStuffBase::add_command(command_t cmd) {
ReplicaID proposer = pmaker->get_proposer();
if (proposer != get_id())
return proposer;
cmd_pending.
|