PingPongClient

Git Source

Inherits: MessageRecipient

State Variables

random

uint256 public random;

pingsSent

Amount of "Ping" messages sent.

uint256 public pingsSent;

pingsReceived

Amount of "Ping" messages received. Every received Ping message leads to sending a Pong message back to initial sender.

uint256 public pingsReceived;

pongsReceived

Amount of "Pong" messages received. When all messages are delivered, should be equal to pingsSent

uint256 public pongsReceived;

Functions

constructor

constructor(address origin_, address destination_) MessageRecipient(origin_, destination_);

doPings

function doPings(uint16 pingCount, uint32 destination_, address recipient, uint16 counter) external;

doPing

Send a Ping message to destination chain. Upon receiving a Ping, a Pong message will be sent back. If counter > 0, this process will be repeated when the Pong message is received.

function doPing(uint32 destination_, address recipient, uint16 counter) external;

Parameters

NameTypeDescription
destination_uint32Chain to send Ping message to
recipientaddressRecipient of Ping message
counteruint16Additional amount of Ping-Pong rounds to conclude

nextOptimisticPeriod

function nextOptimisticPeriod() public view returns (uint32 period);

_receiveBaseMessageUnsafe

*Child contracts should implement the logic for receiving a Base Message in an "unsafe way". Following checks HAVE been performed:

  • receiveBaseMessage() was called by Destination (i.e. this is a legit base message).
  • Nonce is not zero.
  • Message sender on origin chain is not a zero address.
  • Proof maturity is not zero. Following checks HAVE NOT been performed (thus "unsafe"):
  • Message sender on origin chain could be anything non-zero at this point.
  • Proof maturity could be anything non-zero at this point.*
function _receiveBaseMessageUnsafe(uint32 origin_, uint32, bytes32 sender, uint256, uint32, bytes memory content)
    internal
    override;

_optimisticPeriod

Returns a random optimistic period value from 0 to 59 seconds.

function _optimisticPeriod() internal returns (uint32 period);

_sendMessage

Send a "Ping" or "Pong" message.

function _sendMessage(uint32 destination_, bytes32 recipient, PingPongMessage memory message) internal;

Parameters

NameTypeDescription
destination_uint32Domain of destination chain
recipientbytes32Message recipient on destination chain
messagePingPongMessagePing-pong message

_ping

Initiate a new Ping-Pong round.

function _ping(uint32 destination_, bytes32 recipient, uint16 counter) internal;

_pong

Send a Pong message back.

function _pong(uint32 destination_, bytes32 recipient, PingPongMessage memory message) internal;

Events

PingSent

Emitted when a Ping message is sent. Triggered externally, or by receveing a Pong message with instructions to do more pings.

event PingSent(uint256 pingId);

PingReceived

Emitted when a Ping message is received. Will always send a Pong message back.

event PingReceived(uint256 pingId);

PongSent

Emitted when a Pong message is sent. Triggered whenever a Ping message is received.

event PongSent(uint256 pingId);

PongReceived

Emitted when a Pong message is received. Will initiate a new Ping, if the counter in the message is non-zero.

event PongReceived(uint256 pingId);

Structs

PingPongMessage

struct PingPongMessage {
    uint256 pingId;
    bool isPing;
    uint16 counter;
}