Remove full Merkle root from PBFT (#853)

This commit is contained in:
Alex 2020-02-17 19:38:07 +00:00 коммит произвёл GitHub
Родитель 1b7ada169c
Коммит 8c560a2ce3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
9 изменённых файлов: 3 добавлений и 60 удалений

Просмотреть файл

@ -19,7 +19,6 @@ Pre_prepare::Pre_prepare(
{
rep().view = v;
rep().seqno = s;
rep().full_state_merkle_root.fill(0);
rep().replicated_state_merkle_root.fill(0);
START_CC(pp_digest_cycles);
@ -216,10 +215,6 @@ bool Pre_prepare::calculate_digest(Digest& d)
d.update_last(context, (char*)&(rep().view), sizeof(View));
d.update_last(context, (char*)&(rep().seqno), sizeof(Seqno));
d.update_last(
context,
(const char*)rep().full_state_merkle_root.data(),
rep().full_state_merkle_root.size());
d.update_last(
context,
(const char*)rep().replicated_state_merkle_root.data(),
@ -407,14 +402,9 @@ bool Pre_prepare::convert(Message* m1, Pre_prepare*& m2)
}
void Pre_prepare::set_merkle_roots_and_ctx(
const std::array<uint8_t, MERKLE_ROOT_SIZE>& full_state_merkle_root,
const std::array<uint8_t, MERKLE_ROOT_SIZE>& replicated_state_merkle_root,
int64_t ctx)
{
std::copy(
std::begin(full_state_merkle_root),
std::end(full_state_merkle_root),
std::begin(rep().full_state_merkle_root));
std::copy(
std::begin(replicated_state_merkle_root),
std::end(replicated_state_merkle_root),
@ -422,12 +412,6 @@ void Pre_prepare::set_merkle_roots_and_ctx(
rep().ctx = ctx;
}
const std::array<uint8_t, MERKLE_ROOT_SIZE>& Pre_prepare::
get_full_state_merkle_root() const
{
return rep().full_state_merkle_root;
}
const std::array<uint8_t, MERKLE_ROOT_SIZE>& Pre_prepare::
get_replicated_state_merkle_root() const
{

Просмотреть файл

@ -24,7 +24,6 @@ struct Pre_prepare_rep : public Message_rep
{
View view;
Seqno seqno;
std::array<uint8_t, MERKLE_ROOT_SIZE> full_state_merkle_root;
std::array<uint8_t, MERKLE_ROOT_SIZE> replicated_state_merkle_root;
int64_t ctx; // a context provided when a the batch is executed
// the contents are opaque
@ -96,12 +95,9 @@ public:
// Effects: Fetches the digest from the message.
void set_merkle_roots_and_ctx(
const std::array<uint8_t, MERKLE_ROOT_SIZE>& full_state_merkle_root,
const std::array<uint8_t, MERKLE_ROOT_SIZE>& replicated_state_merkle_root,
int64_t ctx);
const std::array<uint8_t, MERKLE_ROOT_SIZE>& get_full_state_merkle_root()
const;
const std::array<uint8_t, MERKLE_ROOT_SIZE>&
get_replicated_state_merkle_root() const;

Просмотреть файл

@ -364,7 +364,6 @@ void Replica::receive_message(const uint8_t* data, uint32_t size)
bool Replica::compare_execution_results(
const ByzInfo& info, Pre_prepare* pre_prepare)
{
auto& pp_root = pre_prepare->get_full_state_merkle_root();
auto& r_pp_root = pre_prepare->get_replicated_state_merkle_root();
auto execution_match = true;
@ -390,17 +389,6 @@ bool Replica::compare_execution_results(
execution_match = false;
}
if (!std::equal(
std::begin(pp_root),
std::end(pp_root),
std::begin(info.full_state_merkle_root)))
{
LOG_FAIL << "Full state merkle root between execution and the pre_prepare "
"message does not match, seqno:"
<< pre_prepare->seqno() << std::endl;
execution_match = false;
}
if (!execution_match)
{
if (rollback_cb != nullptr)
@ -826,10 +814,7 @@ void Replica::send_pre_prepare(bool do_not_wait_for_batch_size)
{
LOG_DEBUG << "adding to plog from pre prepare: " << next_pp_seqno
<< std::endl;
pp->set_merkle_roots_and_ctx(
info.full_state_merkle_root,
info.replicated_state_merkle_root,
info.ctx);
pp->set_merkle_roots_and_ctx(info.replicated_state_merkle_root, info.ctx);
pp->set_digest(signed_version.load());
plog.fetch(next_pp_seqno).add_mine(pp);

Просмотреть файл

@ -212,8 +212,6 @@ ExecCommand exec_command =
counter++;
have_executed_request = true;
info.full_state_merkle_root.fill(0);
((Long*)(info.full_state_merkle_root.data()))[0] = counter;
info.replicated_state_merkle_root.fill(0);
((Long*)(info.replicated_state_merkle_root.data()))[0] = counter;
info.ctx = counter;

Просмотреть файл

@ -58,9 +58,7 @@ public:
outb.size = 0;
auto request = reinterpret_cast<fake_req*>(inb->contents);
info.ctx = request->ctx;
info.full_state_merkle_root.fill(0);
info.replicated_state_merkle_root.fill(0);
info.full_state_merkle_root.data()[0] = request->rt;
info.replicated_state_merkle_root.data()[0] = request->rt;
REQUIRE(request->rt == command_counter);
@ -270,16 +268,11 @@ TEST_CASE("Test Ledger Replay")
// imitate exec command
ByzInfo info;
info.ctx = i;
info.full_state_merkle_root.fill(0);
info.replicated_state_merkle_root.fill(0);
// mess up merkle roots
info.full_state_merkle_root.data()[0] = i + 1;
info.replicated_state_merkle_root.data()[0] = i + 1;
pp->set_merkle_roots_and_ctx(
info.full_state_merkle_root,
info.replicated_state_merkle_root,
info.ctx);
pp->set_merkle_roots_and_ctx(info.replicated_state_merkle_root, info.ctx);
ledger_writer.write_pre_prepare(pp.get());
}

Просмотреть файл

@ -47,7 +47,6 @@ typedef struct _Byz_buffer Byz_rep;
static const uint32_t MERKLE_ROOT_SIZE = 32;
struct ByzInfo
{
std::array<uint8_t, MERKLE_ROOT_SIZE> full_state_merkle_root;
std::array<uint8_t, MERKLE_ROOT_SIZE> replicated_state_merkle_root;
int64_t ctx;
};

Просмотреть файл

@ -95,17 +95,11 @@ namespace pbft
rep = frontend->process_pbft(ctx, msg->include_merkle_roots);
}
static_assert(
sizeof(info.full_state_merkle_root) == sizeof(crypto::Sha256Hash));
static_assert(
sizeof(info.replicated_state_merkle_root) ==
sizeof(crypto::Sha256Hash));
if (msg->include_merkle_roots)
{
std::copy(
std::begin(rep.full_state_merkle_root.h),
std::end(rep.full_state_merkle_root.h),
std::begin(info.full_state_merkle_root));
std::copy(
std::begin(rep.replicated_state_merkle_root.h),
std::end(rep.replicated_state_merkle_root.h),

Просмотреть файл

@ -32,7 +32,6 @@ namespace enclave
struct ProcessPbftResp
{
std::vector<uint8_t> result;
crypto::Sha256Hash full_state_merkle_root;
crypto::Sha256Hash replicated_state_merkle_root;
kv::Version version;
};

Просмотреть файл

@ -343,7 +343,6 @@ namespace ccf
bool playback,
bool include_merkle_roots) override
{
crypto::Sha256Hash full_state_merkle_root;
crypto::Sha256Hash replicated_state_merkle_root;
kv::Version version = kv::NoVersion;
@ -368,14 +367,10 @@ namespace ccf
version = tx.get_version();
if (include_merkle_roots)
{
full_state_merkle_root = history->get_full_state_root();
replicated_state_merkle_root = history->get_replicated_state_root();
}
return {rep.value(),
full_state_merkle_root,
replicated_state_merkle_root,
version};
return {rep.value(), replicated_state_merkle_root, version};
}
/** Process a serialised input forwarded from another node