Skip to content

Commit

Permalink
requestId -> request_id
Browse files Browse the repository at this point in the history
  • Loading branch information
yperbasis committed Sep 16, 2024
1 parent ff86feb commit d97b418
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 52 deletions.
12 changes: 6 additions & 6 deletions silkworm/sync/internals/body_sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Penalty BodySequence::accept_requested_bodies(BlockBodiesPacket66& packet, const
statistics_.received_items += packet.request.size();

// Find matching requests and completing BodyRequest
auto matching_requests = body_requests_.find_by_request_id(packet.requestId);
auto matching_requests = body_requests_.find_by_request_id(packet.request_id);

for (auto& body : packet.request) {
Hash oh = protocol::compute_ommers_hash(body);
Expand Down Expand Up @@ -144,7 +144,7 @@ std::shared_ptr<OutboundMessage> BodySequence::request_bodies(time_point_t tp) {

auto body_request = std::make_shared<OutboundGetBlockBodies>();
auto& packet = body_request->packet();
packet.requestId = Singleton<RandomNumber>::instance().generate_one();
packet.request_id = Singleton<RandomNumber>::instance().generate_one();

auto penalizations = renew_stale_requests(packet, min_block, tp, timeout);

Expand Down Expand Up @@ -189,7 +189,7 @@ std::vector<PeerPenalization> BodySequence::renew_stale_requests(
if (!fulfill_from_announcements(past_request)) {
packet.request.push_back(past_request.block_hash);
past_request.request_time = tp;
past_request.request_id = packet.requestId;
past_request.request_id = packet.request_id;

min_block = std::max(min_block, past_request.block_height);

Expand Down Expand Up @@ -226,7 +226,7 @@ void BodySequence::make_new_requests(GetBlockBodiesPacket66& packet, BlockNum& m
if (!fulfill_from_announcements(new_request)) {
packet.request.push_back(new_request.block_hash);
new_request.request_time = tp;
new_request.request_id = packet.requestId;
new_request.request_id = packet.request_id;

min_block = std::max(min_block, new_request.block_height); // the min block the peer must have (so it is our max)

Expand All @@ -236,7 +236,7 @@ void BodySequence::make_new_requests(GetBlockBodiesPacket66& packet, BlockNum& m
// << ", hash= " << new_request.block_hash;
}

new_request.request_id = packet.requestId;
new_request.request_id = packet.request_id;

if (packet.request.size() >= kMaxBlocksPerMessage) break;
}
Expand Down Expand Up @@ -287,7 +287,7 @@ void BodySequence::request_nack(const GetBlockBodiesPacket66& packet) {
seconds_t timeout = SentryClient::kRequestDeadline;
for (auto& br : body_requests_) {
BodyRequest& past_request = br.second;
if (past_request.request_id == packet.requestId)
if (past_request.request_id == packet.request_id)
past_request.request_time -= timeout;
}
last_nack_ = std::chrono::system_clock::now();
Expand Down
8 changes: 4 additions & 4 deletions silkworm/sync/internals/body_sequence_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ TEST_CASE("body downloading", "[silkworm][sync][BodySequence]") {
// accepting
PeerId peer_id{byte_ptr_cast("1")};
BlockBodiesPacket66 response_packet;
response_packet.requestId = packet.requestId;
response_packet.request_id = packet.request_id;
response_packet.request.push_back(block1);

auto penalty = bs.accept_requested_bodies(response_packet, peer_id);
Expand Down Expand Up @@ -226,7 +226,7 @@ TEST_CASE("body downloading", "[silkworm][sync][BodySequence]") {

PeerId peer_id{byte_ptr_cast("1")};
BlockBodiesPacket66 response_packet;
response_packet.requestId = packet.requestId; // correct request-id
response_packet.request_id = packet.request_id; // correct request-id
response_packet.request.push_back(block1tampered); // wrong body

[[maybe_unused]] auto penalty = bs.accept_requested_bodies(response_packet, peer_id);
Expand Down Expand Up @@ -265,7 +265,7 @@ TEST_CASE("body downloading", "[silkworm][sync][BodySequence]") {
// accepting
PeerId peer_id{byte_ptr_cast("1")};
BlockBodiesPacket66 response_packet;
response_packet.requestId = packet.requestId;
response_packet.request_id = packet.request_id;
response_packet.request.push_back(block1);

bs.accept_requested_bodies(response_packet, peer_id);
Expand Down Expand Up @@ -309,7 +309,7 @@ TEST_CASE("body downloading", "[silkworm][sync][BodySequence]") {

PeerId peer_id{byte_ptr_cast("1")};
BlockBodiesPacket66 response_packet;
response_packet.requestId = packet.requestId - 1; // simulate response to prev request
response_packet.request_id = packet.request_id - 1; // simulate response to prev request
response_packet.request.push_back(block1);

auto penalty = bs.accept_requested_bodies(response_packet, peer_id);
Expand Down
20 changes: 10 additions & 10 deletions silkworm/sync/internals/header_chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ std::shared_ptr<OutboundMessage> HeaderChain::anchor_skeleton_request(time_point
if (target_block_) { // we are syncing to a specific block
skeleton_condition_ = "near the top";
auto request_message = std::make_shared<OutboundGetBlockHeaders>();
request_message->packet().requestId = generate_request_id();
request_message->packet().request_id = generate_request_id();
request_message->packet().request = {{top}, kMaxLen, 0, true}; // request top header only
return request_message;
}
Expand All @@ -382,7 +382,7 @@ std::shared_ptr<OutboundMessage> HeaderChain::anchor_skeleton_request(time_point

auto request_message = std::make_shared<OutboundGetBlockHeaders>();
auto& packet = request_message->packet();
packet.requestId = generate_request_id();
packet.request_id = generate_request_id();
packet.request.origin = {highest_in_db_ + kStride};
packet.request.amount = length;
packet.request.skip = length > 1 ? kStride - 1 : 0;
Expand Down Expand Up @@ -469,7 +469,7 @@ std::shared_ptr<OutboundMessage> HeaderChain::anchor_extension_request(time_poin

auto request_message = send_penalties;
auto& packet = request_message->packet();
packet.requestId = generate_request_id();
packet.request_id = generate_request_id();
packet.request = {{anchor->block_height}, // requesting from origin=block_height-1 make debugging difficult
kMaxLen,
0,
Expand Down Expand Up @@ -517,7 +517,7 @@ std::optional<GetBlockHeadersPacket66> HeaderChain::save_external_announce(Hash
if (has_link(hash)) return std::nullopt; // we already have this link, no need to request it

GetBlockHeadersPacket66 request;
request.requestId = Singleton<RandomNumber>::instance().generate_one();
request.request_id = Singleton<RandomNumber>::instance().generate_one();
request.request.origin = {hash};
request.request.amount = 1;
request.request.skip = 0;
Expand Down Expand Up @@ -545,12 +545,12 @@ void HeaderChain::request_nack(const GetBlockHeadersPacket66& packet) {
}

if (anchor == nullptr) {
log::Trace() << "[WARNING] HeaderChain: failed restoring timestamp due to request nack, requestId="
<< packet.requestId;
log::Trace() << "[WARNING] HeaderChain: failed restoring timestamp due to request nack, request_id="
<< packet.request_id;
return; // not found
}

log::Trace() << "[INFO] HeaderChain: restoring timestamp due to request nack, requestId=" << packet.requestId;
log::Trace() << "[INFO] HeaderChain: restoring timestamp due to request nack, request_id=" << packet.request_id;

anchor_queue_.update(anchor, [&](auto& anchor_) { anchor_->restore_timestamp(); });
}
Expand All @@ -577,7 +577,7 @@ bool HeaderChain::find_bad_header(const std::vector<BlockHeader>& headers) {
});
}

std::tuple<Penalty, HeaderChain::RequestMoreHeaders> HeaderChain::accept_headers(const std::vector<BlockHeader>& headers, uint64_t requestId, const PeerId& peer_id) {
std::tuple<Penalty, HeaderChain::RequestMoreHeaders> HeaderChain::accept_headers(const std::vector<BlockHeader>& headers, uint64_t request_id, const PeerId& peer_id) {
bool request_more_headers = false;

if (headers.empty()) {
Expand All @@ -589,9 +589,9 @@ std::tuple<Penalty, HeaderChain::RequestMoreHeaders> HeaderChain::accept_headers
statistics_.received_items += headers.size();

if (headers.begin()->number < top_seen_height_ && // an old header announcement?
!is_valid_request_id(requestId)) { // anyway is not requested by us...
!is_valid_request_id(request_id)) { // anyway is not requested by us...
statistics_.reject_causes.not_requested += headers.size();
SILK_TRACE << "Rejecting message with reqId=" << requestId << " and first block=" << headers.begin()->number;
SILK_TRACE << "Rejecting message with reqId=" << request_id << " and first block=" << headers.begin()->number;
return {Penalty::kNoPenalty, request_more_headers};
}

Expand Down
2 changes: 1 addition & 1 deletion silkworm/sync/internals/header_chain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class HeaderChain {
// core functionalities: process receiving headers
// when a remote peer satisfy our request we receive one or more headers that will be processed
using RequestMoreHeaders = bool;
std::tuple<Penalty, RequestMoreHeaders> accept_headers(const std::vector<BlockHeader>&, uint64_t requestId, const PeerId&);
std::tuple<Penalty, RequestMoreHeaders> accept_headers(const std::vector<BlockHeader>&, uint64_t request_id, const PeerId&);

// core functionalities: process header announcement
std::optional<GetBlockHeadersPacket66> save_external_announce(Hash hash);
Expand Down
2 changes: 1 addition & 1 deletion silkworm/sync/messages/inbound_block_bodies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void InboundBlockBodies::execute(db::ROAccess, HeaderChain&, BodySequence& bs, S
}
}

uint64_t InboundBlockBodies::reqId() const { return packet_.requestId; }
uint64_t InboundBlockBodies::reqId() const { return packet_.request_id; }

std::string InboundBlockBodies::content() const {
std::stringstream content;
Expand Down
4 changes: 2 additions & 2 deletions silkworm/sync/messages/inbound_block_headers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void InboundBlockHeaders::execute(db::ROAccess, HeaderChain& hc, BodySequence&,
}

// Save the headers
auto [penalty, requestMoreHeaders] = hc.accept_headers(packet_.request, packet_.requestId, peer_id_);
auto [penalty, requestMoreHeaders] = hc.accept_headers(packet_.request, packet_.request_id, peer_id_);

// Reply
if (penalty != Penalty::kNoPenalty) {
Expand All @@ -61,7 +61,7 @@ void InboundBlockHeaders::execute(db::ROAccess, HeaderChain& hc, BodySequence&,
}
}

uint64_t InboundBlockHeaders::reqId() const { return packet_.requestId; }
uint64_t InboundBlockHeaders::reqId() const { return packet_.request_id; }

std::string InboundBlockHeaders::content() const {
std::stringstream content;
Expand Down
4 changes: 2 additions & 2 deletions silkworm/sync/messages/inbound_get_block_bodies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void InboundGetBlockBodies::execute(db::ROAccess db, HeaderChain&, BodySequence&
BodyRetrieval body_retrieval(db);

BlockBodiesPacket66 reply;
reply.requestId = packet_.requestId;
reply.request_id = packet_.request_id;
reply.request = body_retrieval.recover(packet_.request);

if (reply.request.empty()) {
Expand All @@ -64,7 +64,7 @@ void InboundGetBlockBodies::execute(db::ROAccess db, HeaderChain&, BodySequence&
}
}

uint64_t InboundGetBlockBodies::reqId() const { return packet_.requestId; }
uint64_t InboundGetBlockBodies::reqId() const { return packet_.request_id; }

std::string InboundGetBlockBodies::content() const {
std::stringstream content;
Expand Down
4 changes: 2 additions & 2 deletions silkworm/sync/messages/inbound_get_block_headers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void InboundGetBlockHeaders::execute(db::ROAccess db, HeaderChain&, BodySequence
HeaderRetrieval header_retrieval(db);

BlockHeadersPacket66 reply;
reply.requestId = packet_.requestId;
reply.request_id = packet_.request_id;
if (holds_alternative<Hash>(packet_.request.origin)) {
reply.request = header_retrieval.recover_by_hash(get<Hash>(packet_.request.origin), packet_.request.amount,
packet_.request.skip, packet_.request.reverse);
Expand Down Expand Up @@ -71,7 +71,7 @@ void InboundGetBlockHeaders::execute(db::ROAccess db, HeaderChain&, BodySequence
}
}

uint64_t InboundGetBlockHeaders::reqId() const { return packet_.requestId; }
uint64_t InboundGetBlockHeaders::reqId() const { return packet_.request_id; }

std::string InboundGetBlockHeaders::content() const {
std::stringstream content;
Expand Down
2 changes: 1 addition & 1 deletion silkworm/sync/messages/outbound_get_block_bodies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ std::vector<PeerId> OutboundGetBlockBodies::send_packet(SentryClient& sentry) {

auto peers = sentry.send_message_by_min_block(*this, min_block_, 0);

// SILK_TRACE << "Received sentry result of OutboundGetBlockBodies reqId=" << packet_.requestId << ": "
// SILK_TRACE << "Received sentry result of OutboundGetBlockBodies reqId=" << packet_.request_id << ": "
// << std::to_string(peers.size()) + " peer(s)";

return peers;
Expand Down
2 changes: 1 addition & 1 deletion silkworm/sync/messages/outbound_get_block_headers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ std::vector<PeerId> OutboundGetBlockHeaders::send_packet(SentryClient& sentry) {

auto peers = sentry.send_message_by_min_block(*this, min_block, 0);

// SILK_TRACE << "Received sentry result of OutboundGetBlockHeaders reqId=" << packet_.requestId << ": "
// SILK_TRACE << "Received sentry result of OutboundGetBlockHeaders reqId=" << packet_.request_id << ": "
// << std::to_string(peers.size()) + " peer(s)";

return peers;
Expand Down
4 changes: 2 additions & 2 deletions silkworm/sync/packets/block_bodies_packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace silkworm {
using BlockBodiesPacket = std::vector<BlockBody>;

struct BlockBodiesPacket66 { // eth/66 version
uint64_t requestId{0};
uint64_t request_id{0};
BlockBodiesPacket request;
};

Expand All @@ -38,7 +38,7 @@ namespace rlp {
} // namespace rlp

inline std::ostream& operator<<(std::ostream& os, const BlockBodiesPacket66& packet) {
os << "reqId=" << packet.requestId;
os << "reqId=" << packet.request_id;
os << " bodies=" << packet.request.size();
return os;
}
Expand Down
4 changes: 2 additions & 2 deletions silkworm/sync/packets/block_headers_packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace silkworm {
using BlockHeadersPacket = std::vector<BlockHeader>;

struct BlockHeadersPacket66 { // eth/66 version
uint64_t requestId{0};
uint64_t request_id{0};
BlockHeadersPacket request;
};

Expand All @@ -40,7 +40,7 @@ namespace rlp {
} // namespace rlp

inline std::ostream& operator<<(std::ostream& os, const BlockHeadersPacket66& packet) {
os << "reqId=" << packet.requestId;
os << "reqId=" << packet.request_id;
os << " headers(bn)=";

const size_t max_display = 3;
Expand Down
10 changes: 5 additions & 5 deletions silkworm/sync/packets/get_block_bodies_packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace silkworm {
using GetBlockBodiesPacket = std::vector<Hash>;

struct GetBlockBodiesPacket66 { // eth/66 version
uint64_t requestId{0};
uint64_t request_id{0};
GetBlockBodiesPacket request;
};

Expand All @@ -38,13 +38,13 @@ namespace rlp {
} // namespace rlp

inline std::ostream& operator<<(std::ostream& os, const GetBlockBodiesPacket66& packet) {
os << "reqId=" << packet.requestId;
os << "reqId=" << packet.request_id;

if (packet.request.size() == 1)
if (packet.request.size() == 1) {
os << " hash=" << to_hex(packet.request[0]);
else
} else {
os << " requested=" << packet.request.size() << " block hashes";

}
return os;
}

Expand Down
4 changes: 2 additions & 2 deletions silkworm/sync/packets/get_block_headers_packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct GetBlockHeadersPacket {
};

struct GetBlockHeadersPacket66 { // eth/66 version
uint64_t requestId{0};
uint64_t request_id{0};
GetBlockHeadersPacket request;
};

Expand All @@ -49,7 +49,7 @@ namespace rlp {
} // namespace rlp

inline std::ostream& operator<<(std::ostream& os, const GetBlockHeadersPacket66& packet) {
os << "reqId=" << packet.requestId << " origin=" << packet.request.origin << " amount=" << packet.request.amount
os << "reqId=" << packet.request_id << " origin=" << packet.request.origin << " amount=" << packet.request.amount
<< " skip=" << packet.request.skip << " reverse=" << packet.request.reverse;
return os;
}
Expand Down
12 changes: 6 additions & 6 deletions silkworm/sync/packets/packet_coding_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ TEST_CASE("GetBlockHeadersPacket (eth/66) decoding") {
ByteView encoded_view = encoded.value();
REQUIRE(rlp::decode(encoded_view, packet));

REQUIRE(packet.requestId == 0x6b1a456ba6e2f81d);
REQUIRE(packet.request_id == 0x6b1a456ba6e2f81d);
REQUIRE(std::holds_alternative<BlockNum>(packet.request.origin) == true);
REQUIRE(std::get<BlockNum>(packet.request.origin) == 0xb9ffff); // 12189695
REQUIRE(packet.request.amount == 1);
Expand All @@ -970,7 +970,7 @@ TEST_CASE("GetBlockHeadersPacket (eth/66) encoding") {

GetBlockHeadersPacket66 packet;

packet.requestId = 0x6b1a456ba6e2f81d;
packet.request_id = 0x6b1a456ba6e2f81d;
packet.request.origin = {BlockNum{0xb9ffff}};
packet.request.amount = 1;
packet.request.skip = 0;
Expand Down Expand Up @@ -1014,7 +1014,7 @@ TEST_CASE("GetBlockBodiesPacket (eth/66) decoding") {
ByteView encoded_view = encoded.value();
REQUIRE(rlp::decode(encoded_view, packet));

REQUIRE(packet.requestId == 0xae9405dbeebf3f01);
REQUIRE(packet.request_id == 0xae9405dbeebf3f01);
REQUIRE(packet.request.size() == 2);
REQUIRE(packet.request[0] == Hash::from_hex("a36b1595c5acd878b63f83d3b62f6882edd27b757582f5319aebc17bc3e98246"));
REQUIRE(packet.request[1] == Hash::from_hex("9f20a871bf5151959fff4c88783bf4ef27b170a4cbe92b8f63ca1fe7d6ab829c"));
Expand All @@ -1025,7 +1025,7 @@ TEST_CASE("GetBlockBodiesPacket (eth/66) encoding") {

GetBlockBodiesPacket66 packet;

packet.requestId = 0xae9405dbeebf3f01;
packet.request_id = 0xae9405dbeebf3f01;
packet.request.push_back(*Hash::from_hex("a36b1595c5acd878b63f83d3b62f6882edd27b757582f5319aebc17bc3e98246"));
packet.request.push_back(*Hash::from_hex("9f20a871bf5151959fff4c88783bf4ef27b170a4cbe92b8f63ca1fe7d6ab829c"));

Expand Down Expand Up @@ -1080,7 +1080,7 @@ TEST_CASE("BlockHeadersPacket (eth/66) decoding/encoding") {
REQUIRE(rlp::decode(encoded_view, packet));

// packet values from etherscan
REQUIRE(packet.requestId == 0x81fb'063b'42d7'd3a1);
REQUIRE(packet.request_id == 0x81fb'063b'42d7'd3a1);
REQUIRE(packet.request.size() == 1);
REQUIRE(packet.request[0].number == 12593053);
REQUIRE(packet.request[0].gas_limit == 14'926'879);
Expand Down Expand Up @@ -1110,7 +1110,7 @@ TEST_CASE("BlockBodiesPacket (eth/66) decoding/encoding") {
ByteView view{rlp_bytes};
BlockBodiesPacket66 packet;
CHECK(rlp::decode(view, packet));
CHECK(packet.requestId == 0x0d2c08e12ca20890);
CHECK(packet.request_id == 0x0d2c08e12ca20890);
CHECK(packet.request.empty());
}
SECTION("non-empty list of empty bodies: INVALID") {
Expand Down
Loading

0 comments on commit d97b418

Please sign in to comment.