From 1eef6ed55ef812da1ee7828373f8c062f1fc7b4a Mon Sep 17 00:00:00 2001 From: SpyCheese Date: Mon, 16 Oct 2023 11:22:41 +0300 Subject: [PATCH] Bugfix in check_neighbor_outbound_message --- validator/impl/validate-query.cpp | 33 +++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/validator/impl/validate-query.cpp b/validator/impl/validate-query.cpp index ecce370d..49885a5f 100644 --- a/validator/impl/validate-query.cpp +++ b/validator/impl/validate-query.cpp @@ -4010,8 +4010,37 @@ bool ValidateQuery::check_neighbor_outbound_message(Ref enq_msg, key.to_hex(352) + " of neighbor " + nb.blk_.to_str()); } if (shard_contains(shard_, enq.cur_prefix_)) { - // this message couldn't come from our own outbound queue because processed messages from our queue don't stay here - return fatal_error("have an already processed EnqueuedMsg from our shard: "s + key.to_hex(352)); + // if this message comes from our own outbound queue, we must have dequeued it + if (out_entry.is_null()) { + return reject_query("our old outbound queue contains EnqueuedMsg with key "s + key.to_hex(352) + + " already processed by this shard, but there is no ext_message_deq OutMsg record for this " + "message in this block"); + } + int tag = block::gen::t_OutMsg.get_tag(*out_entry); + if (tag == block::gen::OutMsg::msg_export_deq_short) { + block::gen::OutMsg::Record_msg_export_deq_short deq; + if (!tlb::csr_unpack(std::move(out_entry), deq)) { + return reject_query( + "cannot unpack msg_export_deq_short OutMsg record for already processed EnqueuedMsg with key "s + + key.to_hex(352) + " of old outbound queue"); + } + if (deq.msg_env_hash != enq.msg_env_->get_hash().bits()) { + return reject_query("unpack ext_message_deq OutMsg record for already processed EnqueuedMsg with key "s + + key.to_hex(352) + " of old outbound queue refers to MsgEnvelope with different hash " + + deq.msg_env_hash.to_hex()); + } + } else { + block::gen::OutMsg::Record_msg_export_deq deq; + if (!tlb::csr_unpack(std::move(out_entry), deq)) { + return reject_query( + "cannot unpack msg_export_deq OutMsg record for already processed EnqueuedMsg with key "s + + key.to_hex(352) + " of old outbound queue"); + } + if (deq.out_msg->get_hash() != enq.msg_env_->get_hash()) { + return reject_query("unpack ext_message_deq OutMsg record for already processed EnqueuedMsg with key "s + + key.to_hex(352) + " of old outbound queue contains a different MsgEnvelope"); + } + } } // next check is incorrect after a merge, when ns_.processed_upto has > 1 entries // we effectively comment it out