Peering
What is a peer / a peering relationship?
A peer is a counterparty that a given party transacts with. Within the Interledger Protocol, connectors maintain peers, or counterparty connectors whom they transact with. The Interledger network is a graph of nodes (connectors) that have peered with one another by establishing a means of exchanging ILP packets and a means of paying one another for the successful forwarding and delivery of the packets. A connector may extend a given peer a limited line of credit, or none at all, depending upon their trustworthiness.
Rafiki includes an implementation of such a connector.
What are the requirements for peering?
Both counterparties need to
- run an implementation of an Interledger connector, ideally Rafiki
- agree on an asset of the peering relationship
- agree on a
maxPacketAmount
, which specifies into how many packets a payment is split (or use default value within Rafiki) - communicate their static ILP address
- communicate a connection endpoint for the peer to send packets to
- exchange auth tokens for the connection endpoint
Additionally, the two counterparties need to agree on a settlement mechanism. However, that is outside the scope of Interledger / Rafiki.
Note that two counterparties could have multiple peering relationships that differ in e.g. the underlying asset.
How to peer two Rafiki instances?
Using the Admin Dashboard
Once the frontend
project is running (typically as part of the local environment), you can navgiate to the Peers page, and then press the Create Peer button. You will be prompted to enter the peer information such as the peer’s static ILP address, as well as the corresponding HTTP info.
Using the Admin API
This section describes the process for setting up peering between two Rafiki instances using the Admin API. The examples are given for one instance, the other instance would have to run the corresponding API calls.
Assume the following peering relationship
- asset: USD with a scale of 2
- peer’s static ILP address: g.othergreatwallet
- peer’s name: “The Other Great Wallet”
Note that each GraphQL request has two parts: a query and an object containing query variables.
Create Asset
Query:
Query Variables:
Example Successful Response
Create Peer
Query:
Query Variables (substitute the asset ID from the “create asset” response for INSERT_ASSET_ID
):
Notes:
- The peer’s connector endpoint has been mapped to
ilp.othergreatwallet.com
. Locally and by default, it is on0.0.0.0:3002
. mytoken
is the token my peer will need to present to connect and send packets to metheirtoken
is the token I’ll have to present to my peer to connect and send packets to them
Example Successful Response
Deposit Peer Liquidity
Query:
Query Variables (substitute the peer ID from the “create peer” response for INSERT_PEER_ID
):
Note that the peer has a liquidity of 100 USD. How this is secured, whether the peer has to pre-fund that amount somewhere or whether that is a line of credit, is out of scope.
Example successful response:
Withdraw Peer Liquidity
This is a two-phase transaction, so the withdrawal needs to be created first and then posted (i.e. the Account Servicing Entity commits to the withdrawal). This way, the Account Servicing Entity can safely perform withdrawals in their internal system before posting in Rafiki. If the internal withdrawal failed or an error was made when creating the withdrawal in Rafiki, it can be voided rather than posted.
Create Withdrawal
Query:
Query Variables (substitute the ID from the “create peer” response for INSERT_PEER_ID
):
Example successful response:
Post Withdrawal
Query:
Query Variables (substitute the withdrawal ID from the “create withdrawal” request for INSERT_WITHDRAWAL_ID
):
Example successful response:
Void Withdrawal
Query:
Query Variables (substitute the withdrawal ID from the “create withdrawal” request for INSERT_WITHDRAWAL_ID
):
Example successful response:
Auto-peering
Additionally, certain peers will have auto-peering available. This feature is only for sandbox environments, and should not be used in production environments. Auto-peering enables easier peering integration between Rafiki instances. In order to use this feature, it requires the peer you want to peer with to publish an “auto-peering” URL. Once this peerUrl
is provided, instead of using createPeer
mutation to create a peer, you can call createOrUpdatePeerByUrl
:
with the input being:
Calling this mutation will exchange ILP peering information (staticIlpAddress
ilpConnectorAddress
, auth tokens) automatically. The instance being peered with will issue a default amount of liquidity, and you can begin sending payments to wallet addresses at the other Rafiki instance.
Prerequisites
Before making the createOrUpdatePeerByUrl
request, a few backend
environment variables about your Rafiki instance need to be configured:
ILP_ADDRESS
: The static ILP address of your Rafiki instance. This should already be defined in order to support ILP payments.ILP_CONNECTOR_ADDRESS
: The full address of the ILP connector that will receive ILP packets. Locally and by default, it is on0.0.0.0:3002
.INSTANCE_NAME
: The name of your Rafiki instance. This is how your peer will identify you.
How to enable auto-peering
Other than setting up the environment variables from the prerequisite step above, you will need to set additional backend
environment variables:
ENABLE_AUTO_PEERING
: true- Optionally, update the
AUTO_PEERING_SERVER_PORT
that the auto-peering server will run on. By default, it is3005
. - Now, your Rafiki instance is ready to accept auto-peering requests. Your
peerUrl
will be the URL you’ve mapped to correspond withAUTO_PEERING_SERVER_PORT
, and you can being communicating this URL to potential peers.