aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDeterminant <tederminant@gmail.com>2018-08-03 20:14:42 -0400
committerDeterminant <tederminant@gmail.com>2018-08-03 20:14:42 -0400
commit086e37788e16ddf62c0676a223002a3ea1b6d2e0 (patch)
treeee222cc3f81ac2f1bb6539d33111f70b62bbbaa9 /src
parentedcadfb47b736e6c9dd6b078689114aecf5c1add (diff)
...
Diffstat (limited to 'src')
-rw-r--r--src/consensus.cpp2
-rw-r--r--src/entity.cpp22
2 files changed, 15 insertions, 9 deletions
diff --git a/src/consensus.cpp b/src/consensus.cpp
index e25558a..6505c20 100644
--- a/src/consensus.cpp
+++ b/src/consensus.cpp
@@ -110,7 +110,7 @@ bool HotStuffCore::update(const uint256_t &bqc_hash) {
void HotStuffCore::on_propose(const std::vector<command_t> &cmds,
const std::vector<block_t> &parents,
- serializable_bt &&extra) {
+ bytearray_t &&extra) {
if (parents.empty())
throw std::runtime_error("empty parents");
for (const auto &_: parents) tails.erase(_);
diff --git a/src/entity.cpp b/src/entity.cpp
index a5dc44e..594fdbe 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -4,38 +4,44 @@
namespace hotstuff {
void Block::serialize(DataStream &s) const {
- s << (uint32_t)parent_hashes.size();
+ s << htole((uint32_t)parent_hashes.size());
for (const auto &hash: parent_hashes)
s << hash;
- s << (uint32_t)cmds.size();
+ s << htole((uint32_t)cmds.size());
for (auto cmd: cmds)
s << *cmd;
if (qc)
s << (uint8_t)1 << *qc;
else
s << (uint8_t)0;
- if (extra)
- s << (uint8_t)1 << *extra;
- else
- s << (uint8_t)0;
+ s << htole((uint32_t)extra.size()) << extra;
}
void Block::unserialize(DataStream &s, HotStuffCore *hsc) {
uint32_t n;
uint8_t flag;
s >> n;
+ n = letoh(n);
parent_hashes.resize(n);
for (auto &hash: parent_hashes)
s >> hash;
s >> n;
+ n = letoh(n);
cmds.resize(n);
for (auto &cmd: cmds)
cmd = hsc->parse_cmd(s);
s >> flag;
qc = flag ? hsc->parse_quorum_cert(s) : nullptr;
+ s >> n;
+ n = letoh(n);
+ if (n == 0)
+ extra.clear();
+ else
+ {
+ auto base = s.get_data_inplace(n);
+ extra = bytearray_t(base, base + n);
+ }
this->hash = salticidae::get_hash(*this);
- s >> flag;
- extra = flag ? hsc->parse_extra_block_data(s) : nullptr;
}
}