Skip to content

eth/eth_handshake_guard.hpp

Namespaces

Name
eth

Types

Name
enum class HandshakeMessageDisposition { kIgnored, kAcceptedStatus, kRejected}
Result of processing one inbound ETH handshake-phase message.

Functions

Name
HandshakeMessageDisposition HandleEthHandshakeMessage(const rlpx::protocol::Message & message, uint8_t negotiated_eth_offset, uint8_t negotiated_eth_version, uint64_t network_id, const Hash256 & genesis_hash, bool & status_received)
Process one inbound ETH handshake-phase message.
std::optional< uint8_t > NormalizeEthWireMessageId(uint8_t wire_message_id, uint8_t negotiated_eth_offset)
Return the ETH-local message id for a wire-level message.
uint64_t ExtractLatestBlockNumber(const StatusMessage & status)
Return the latest block number from a validated ETH Status message.
rlp::outcome::result< StatusMessage, StatusValidationError, rlp::outcome::policy::all_narrow > DecodeValidatedStatusMessage(const rlpx::protocol::Message & message, uint8_t negotiated_eth_offset, uint8_t negotiated_eth_version, uint64_t network_id, const Hash256 & genesis_hash, const std::vector< EthMessageSchema > & eth_message_schemas ={})
Decode and validate an inbound ETH Status message.

Types Documentation

enum HandshakeMessageDisposition

Enumerator Value Description
kIgnored
kAcceptedStatus
kRejected

Result of processing one inbound ETH handshake-phase message.

Functions Documentation

function HandleEthHandshakeMessage

HandshakeMessageDisposition HandleEthHandshakeMessage(
    const rlpx::protocol::Message & message,
    uint8_t negotiated_eth_offset,
    uint8_t negotiated_eth_version,
    uint64_t network_id,
    const Hash256 & genesis_hash,
    bool & status_received
)

Process one inbound ETH handshake-phase message.

Parameters:

  • message Inbound wire-level RLPx message.
  • negotiated_eth_offset Negotiated ETH wire offset.
  • negotiated_eth_version Negotiated ETH version.
  • network_id Expected local network identifier.
  • genesis_hash Expected local genesis hash.
  • status_received Whether a valid remote ETH Status was already accepted.

Return: Disposition indicating whether the message was ignored, accepted, or rejected.

function NormalizeEthWireMessageId

std::optional< uint8_t > NormalizeEthWireMessageId(
    uint8_t wire_message_id,
    uint8_t negotiated_eth_offset
)

Return the ETH-local message id for a wire-level message.

Parameters:

  • wire_message_id Wire-level RLPx message id.
  • negotiated_eth_offset Negotiated ETH wire offset.

Return: ETH-local message id if the wire id belongs to ETH; std::nullopt otherwise.

function ExtractLatestBlockNumber

uint64_t ExtractLatestBlockNumber(
    const StatusMessage & status
)

Return the latest block number from a validated ETH Status message.

Parameters:

  • status Decoded ETH Status message.

Return: Latest block number for ETH/69, or 0 for earlier layouts.

function DecodeValidatedStatusMessage

rlp::outcome::result< StatusMessage, StatusValidationError, rlp::outcome::policy::all_narrow > DecodeValidatedStatusMessage(
    const rlpx::protocol::Message & message,
    uint8_t negotiated_eth_offset,
    uint8_t negotiated_eth_version,
    uint64_t network_id,
    const Hash256 & genesis_hash,
    const std::vector< EthMessageSchema > & eth_message_schemas ={}
)

Decode and validate an inbound ETH Status message.

Parameters:

  • message Inbound wire-level RLPx message.
  • negotiated_eth_offset Negotiated ETH wire offset.
  • negotiated_eth_version Negotiated ETH version.
  • network_id Expected local network identifier.
  • genesis_hash Expected local genesis hash.

Return: Decoded valid ETH Status message, or a validation/decode error.

Source code

// Copyright 2026 Genius Ventures, Inc.
// SPDX-License-Identifier: MIT

#ifndef EVMRELAY_INCLUDE_ETH_ETH_HANDSHAKE_GUARD_HPP
#define EVMRELAY_INCLUDE_ETH_ETH_HANDSHAKE_GUARD_HPP

#include <eth/eth_peer_session.hpp>
#include <rlpx/rlpx_session.hpp>
#include <optional>

namespace eth {

enum class HandshakeMessageDisposition
{
    kIgnored,
    kAcceptedStatus,
    kRejected
};

[[nodiscard]] HandshakeMessageDisposition HandleEthHandshakeMessage(
    const rlpx::protocol::Message& message,
    uint8_t                        negotiated_eth_offset,
    uint8_t                        negotiated_eth_version,
    uint64_t                       network_id,
    const Hash256&                 genesis_hash,
    bool&                          status_received) noexcept;

[[nodiscard]] std::optional<uint8_t> NormalizeEthWireMessageId(
    uint8_t wire_message_id,
    uint8_t negotiated_eth_offset) noexcept;

[[nodiscard]] uint64_t ExtractLatestBlockNumber(
    const StatusMessage& status) noexcept;

[[nodiscard]] rlp::outcome::result<StatusMessage, StatusValidationError, rlp::outcome::policy::all_narrow>
DecodeValidatedStatusMessage(
    const rlpx::protocol::Message& message,
    uint8_t                        negotiated_eth_offset,
    uint8_t                        negotiated_eth_version,
    uint64_t                       network_id,
    const Hash256&                 genesis_hash,
    const std::vector<EthMessageSchema>& eth_message_schemas = {}) noexcept;

} // namespace eth


#endif // EVMRELAY_INCLUDE_ETH_ETH_HANDSHAKE_GUARD_HPP

Updated on 2026-06-05 at 17:22:19 -0700