<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.internetcomputer.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Yotam.harchol</id>
	<title>Internet Computer Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.internetcomputer.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Yotam.harchol"/>
	<link rel="alternate" type="text/html" href="https://wiki.internetcomputer.org/wiki/Special:Contributions/Yotam.harchol"/>
	<updated>2026-05-23T17:35:57Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.17</generator>
	<entry>
		<id>https://wiki.internetcomputer.org/w/index.php?title=Exchange_rate_canister&amp;diff=6114</id>
		<title>Exchange rate canister</title>
		<link rel="alternate" type="text/html" href="https://wiki.internetcomputer.org/w/index.php?title=Exchange_rate_canister&amp;diff=6114"/>
		<updated>2023-08-02T07:46:10Z</updated>

		<summary type="html">&lt;p&gt;Yotam.harchol: Updated pricing&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
The exchange rate canister (XRC) is a canister running on the [https://dashboard.internetcomputer.org/subnet/uzr34-akd3s-xrdag-3ql62-ocgoh-ld2ao-tamcv-54e7j-krwgb-2gm4z-oqe uzr34 system subnet] that provides exchange rates to requesting canisters.&lt;br /&gt;
A request comprises a base asset, a quote asset, and an optional (UNIX epoch) timestamp.&lt;br /&gt;
The base and quote asset can be any combination of cryptocurrency and fiat currency assets, for example, BTC/ICP, ICP/USD, or USD/EUR.&lt;br /&gt;
The timestamp parameter makes it possible to request historic rates. If no timestamp is provided in the request, the rate for the current time is returned.&lt;br /&gt;
&lt;br /&gt;
The XRC constitutes an on-chain oracle for exchange rates, which is particularly useful for DeFi applications but can further add value to any application that requires exchange rate information.&lt;br /&gt;
&lt;br /&gt;
The cycle minting canister of the [https://wiki.internetcomputer.org/wiki/NNS_Canisters NNS] will make use of the XRC to obtain up-to-date ICP/XDR rates, which it requires for the conversion of ICP to cycles.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
The canister ID of the XRC is &amp;lt;code&amp;gt;uf6dk-hyaaa-aaaaq-qaaaq-cai&amp;lt;/code&amp;gt;.&lt;br /&gt;
A request of the form&lt;br /&gt;
&lt;br /&gt;
 type GetExchangeRateRequest = record {&lt;br /&gt;
    base_asset: Asset;&lt;br /&gt;
    quote_asset: Asset;&lt;br /&gt;
    timestamp: opt nat64;&lt;br /&gt;
 }; &lt;br /&gt;
&lt;br /&gt;
can be sent to the XRC, which replies with the following result:&lt;br /&gt;
&lt;br /&gt;
 type GetExchangeRateResult = variant {&lt;br /&gt;
    Ok: ExchangeRate;&lt;br /&gt;
    Err: ExchangeRateError;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
An &amp;lt;code&amp;gt;Asset&amp;lt;/code&amp;gt; is a record consisting of a symbol (for example, &amp;quot;ICP&amp;quot;) and a class (either &amp;lt;code&amp;gt;Cryptocurrency&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;FiatCurrency&amp;lt;/code&amp;gt;).&lt;br /&gt;
The full candid file can be found [https://github.com/dfinity/exchange-rate-canister/blob/main/src/xrc/xrc.did here].&lt;br /&gt;
The optional timestamp in the request must be a UNIX timestamp in seconds when provided. If no timestamp is provided, the timestamp corresponding to the start of the current minute is used.&lt;br /&gt;
Note that the granularity for requests is 1 minute, so seconds in a timestamp are ignored.&lt;br /&gt;
&lt;br /&gt;
It is further worth nothing that some exchanges may not always have exchange rates available for the current minute. Depending on the use case, it may be advisable to use the start of the previous minute to increase the chance to get a response based on rates collected from all queried exchanges.&lt;br /&gt;
&lt;br /&gt;
For every request, 1B cycles need to be sent along, otherwise an &amp;lt;code&amp;gt;ExchangeRateError::NotEnoughCycles&amp;lt;/code&amp;gt; error is returned. The actual cost of the call depends on two factors, the requested asset types and the state of the internal exchange rate cache, as follows:&lt;br /&gt;
&lt;br /&gt;
* If the request can be served from the cache, the actual cost is 20M cycles.&lt;br /&gt;
* If both assets are fiat currencies, the cost is 20M cycles as well.&lt;br /&gt;
* If one of the assets is a fiat currency or the cryptocurrency USDT, the cost is 260M cycles.&lt;br /&gt;
* If both assets are cryptocurrencies, the cost is 500M cycles.&lt;br /&gt;
&lt;br /&gt;
The remaining cycles are returned to the requesting canister. Note that at least 1M cycles are charged even in case of an error in order to mitigate the risk of a denial-of-service attack.&lt;br /&gt;
&lt;br /&gt;
== Technical Details ==&lt;br /&gt;
&lt;br /&gt;
The following figure depicts the work flow when receiving a request.&lt;br /&gt;
&lt;br /&gt;
[[File:XRC Flow Diagram.png|thumb|center|upright=3|Overview of the exchange rate canister work flow (bank icon from [https://www.flaticon.com/free-icon/bank_858170 flaticon.com]).]]&lt;br /&gt;
&lt;br /&gt;
After receiving a request (step 1), the exchange rate for each cryptocurrency asset in the request with respect to the quote asset USDT is queried (for the timestamp in the request) from all supported exchanges using [[HTTPS outcalls]] if this rate is not already cached (step 2).&lt;br /&gt;
If a rate can be computed based on the query results received from the exchanges, it is inserted in the cache and returned to the requesting canister (step 3).&lt;br /&gt;
The &#039;&#039;median rate&#039;&#039; of all received rates is returned as it is not susceptible to outliers (unlike the average rate).&lt;br /&gt;
&lt;br /&gt;
If a cryptocurrency/cryptocurrency base-quote pair B/Q was requested, the B/Q rate is derived from the queried B/USDT and Q/USDT rates.&lt;br /&gt;
&lt;br /&gt;
The XRC queries daily foreign exchange (forex) rates from forex data providers automatically on a fixed schedule. Furthermore, the XRC queries multiple stablecoin rates automatically to derive the USD/USDT rate as follows. Given SC1/USDT, SC2/USDT, ... rates for a set of stablecoins SC1, SC2, ..., it uses the median of these rates as the USD/USDT rate. This rule is based on the assumption that at least half of the stablecoins in the set keep their peg to USD at any time, in which case the median rate is an adequate estimate for the USD/USDT rate.&lt;br /&gt;
Given the USD/USDT rate and the forex rates for fiat currencies other than USD, the requested rate can be computed for the case when one or more assets in the request are fiat currencies.&lt;br /&gt;
&lt;br /&gt;
Since more requests to exchanges are required for cryptocurrency/cryptocurrency pairs, more cycles are charged for such requests.&lt;br /&gt;
&lt;br /&gt;
As indicated in the figure above, the response to a successful request contains metadata in addition to the rate. The metadata contains the following fields:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;decimals&amp;lt;/code&amp;gt;: The rate is returned as a scaled 64-bit integer. The scaling factor is 10 to the power of &amp;lt;code&amp;gt;decimals&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;lt;code&amp;gt;base_asset_num_received_rates&amp;lt;/code&amp;gt;: The number of received rates for the base asset from all queried exchanges.&lt;br /&gt;
* &amp;lt;code&amp;gt;base_asset_num_queried_sources&amp;lt;/code&amp;gt;: The number of queried exchanges for the base asset.&lt;br /&gt;
* &amp;lt;code&amp;gt;quote_asset_num_received_rates&amp;lt;/code&amp;gt;: The number of received rates for the quote asset from all queried exchanges.&lt;br /&gt;
* &amp;lt;code&amp;gt;quote_asset_num_queried_sources&amp;lt;/code&amp;gt;: The number of queried exchanges for the quote asset.&lt;br /&gt;
* &amp;lt;code&amp;gt;standard_deviation&amp;lt;/code&amp;gt;: The standard deviation of all received rates for this request. Note that the standard deviation is scaled by the same factor as the rate itself.&lt;br /&gt;
* &amp;lt;code&amp;gt;forex_timestamp&amp;lt;/code&amp;gt;: The timestamp of the beginning of the day for which the forex rates were retrieved, if any.&lt;br /&gt;
&lt;br /&gt;
This additional information can be used to determine the trustworthiness of the received rate, for example by checking the number of rates that went into the computation of the rate and the standard deviation.&lt;br /&gt;
If the XRC receives largely inconsistent rates from exchanges, it returns an &amp;lt;code&amp;gt;ExchangeRateError::InconsistentRatesReceived&amp;lt;/code&amp;gt; itself.&lt;/div&gt;</summary>
		<author><name>Yotam.harchol</name></author>
	</entry>
	<entry>
		<id>https://wiki.internetcomputer.org/w/index.php?title=HTTPS_outcalls&amp;diff=6041</id>
		<title>HTTPS outcalls</title>
		<link rel="alternate" type="text/html" href="https://wiki.internetcomputer.org/w/index.php?title=HTTPS_outcalls&amp;diff=6041"/>
		<updated>2023-07-26T13:13:29Z</updated>

		<summary type="html">&lt;p&gt;Yotam.harchol: Added a note on outcalls being IPv6-only&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;On the Internet Computer blockchain, canister smart contracts can make HTTP outcalls to specified URLs, either to directly obtain off-chain data, or to interact with off-chain systems, such as Web 2.0 services or enterprise IT infrastructure. The results of these calls are processed and agreed by consensus, preventing nondeterminism. This avoids the need for trusted oracles and bridges.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Often, smart contract software needs to obtain real-world data, which originates from outside the secure and unstoppable on-chain universe that the blockchain that hosts them provides. Smart contracts may also need to interact with off-chain systems that are outside this universe. Because of the way blockchains work, historically this has presented major hurdles to blockchain developers.&lt;br /&gt;
&lt;br /&gt;
For example, to obtain off-chain data, smart contracts have traditionally interacted with centrally-operated oracle services, such as [https://chain.link/ Chainlink]. These services are provided by trusted intermediaries, such as corporations, which perform the role of copying off-chain data onto the blockchain where it can be accessed by smart contracts. The problem is that these services must a) be trusted to be honest, and not get hacked, or otherwise become faulty, and b) be paid. Moreover, they cannot help when smart contracts need to &#039;&#039;interact&#039;&#039; with off-chain services, for example by calling into web-based APIs. To solve for these needs, the Internet Computer provides an &amp;quot;HTTPS outcall&amp;quot; feature.&lt;br /&gt;
&lt;br /&gt;
HTTPS outcalls allow canister smart contracts hosted on the Internet Computer to request a URL, for example to download a time series recording the recent prices of an asset published by a centralized crypto exchange such as [https://pro.coinbase.com/ Coinbase Pro]. When this occurs, every node in the subnet blockchain hosting the smart contract requests the URL separately. Each node then locally passes the result they obtained to a special function implemented by the requesting canister smart contract using a [[query call]], which pre-processes the result with the aim of making it consistent with the results the other nodes have obtained and pre-processed (in our Coinbase example, since each node would request the time series at a slightly different moment, the results could be different).&lt;br /&gt;
&lt;br /&gt;
If the pre-processed results obtained by query calls to the canister smart contract are sufficiently consistent across all the nodes, the result is agreed by consensus, and provided back to the smart contract that requested the URL so that it can continue trustlessly processing the original smart contract call (TX).&lt;br /&gt;
&lt;br /&gt;
In order to trigger an action in an off-chain system, a smart contract may include a cryptographic [[chain key]] signature in its request for a URL. This allows the target service to validate that the request it has received was generated by a genuine smart contract execution that was agreed by consensus. In such architectures, when an off-chain service receives a valid request for a URL, it must take care to only execute it once, since many nodes will make the same request, and for each subsequent request after the first, it should return exactly the same result.&lt;br /&gt;
&lt;br /&gt;
Note: Currently, HTTPS outcalls are only possible to IPv6 hosts. That is, hosts with a valid AAAA DNS record. HTTPS outcalls to IPv4-only hosts will fail on mainnet. The reason for this is that IC nodes only have an IPv6 address assigned, and the IC network is IPv6-only.&lt;br /&gt;
== Architecture ==&lt;br /&gt;
The canister HTTPS outcalls feature has been implemented as an extension of the IC protocol stack, particularly its consensus layer. The possibility of the IC protocol stack allowing for such extensions shows the powerful architecture of the IC and its consensus protocol. This section gives details on the architecture of the feature: which components of the stack are needed to be extended and which new components were required and explain a protocol flow through the stack.&lt;br /&gt;
&lt;br /&gt;
=== HTTPS Outcall Request Lifecycle ===&lt;br /&gt;
[[File:HTTPS outcall request lifecycle1.png|thumb|700px|HTTPS outcall request lifecycle]]&lt;br /&gt;
The figure above shows the process an HTTPS outcall request goes through, along with the new components that were added to make this feature work. The numbered arrows indicate the steps as follows:&lt;br /&gt;
# A canister makes an HTTPS outcall request to the management canister in the execution layer. The request is stored in the replicated state of the corresponding subnet.&lt;br /&gt;
# A new component in the Consensus layer, called the “HTTP pool manager”, is reading state changes and keeps track of outstanding HTTPS requests.&lt;br /&gt;
#Whenever the HTTP pool manager sees a new request, it forwards it to the networking layer, to a new component that is called “HTTP adapter shim”. This is a relatively lightweight component that is responsible for communicating with the “HTTP adapter”, which is a separate process running alongside the replica process, but is isolated for security reasons.&lt;br /&gt;
# The HTTP adapter shim forwards the request to the HTTP adapter using RPC.&lt;br /&gt;
# The HTTP adapter on each node issues the requested HTTPS request to the remote server.&lt;br /&gt;
# A response is returned from the server to each HTTP adapter.&lt;br /&gt;
# Each HTTP adapter returns the response to the HTTP adapter shim component.&lt;br /&gt;
# The HTTP adapter shim invokes an optional transform function on the calling canister. The purpose of this function is explained in detail below, but in short, it should help in making all responses exactly the same so that the subnet can reach consensus on them.&lt;br /&gt;
# The HTTP adapter shim forwards the transformed response to the HTTP pool manager&lt;br /&gt;
# The Consensus layer then distributes shares of the response to all peers, so that the block maker can see that enough peers received exactly the same response as it has received.&lt;br /&gt;
# The block maker then includes the response in a block.&lt;br /&gt;
# The response is made available to the execution layer.&lt;br /&gt;
# A callback is invoked to return the response to the canister asynchronously.&lt;br /&gt;
&lt;br /&gt;
== How to reach consensus on result? ==&lt;br /&gt;
&lt;br /&gt;
As explained above, every node makes a given HTTP request to the target server and receives a response. There are multiple reasons why the responses are not necessarily the same on all replicas for the same API query:&lt;br /&gt;
* Typical implementations of web servers add variable elements to otherwise equal content, e.g., timestamps or unique identifiers. In this case, the actual content, e.g., requested asset prices, can be the same in each response, while those variable fields differ.&lt;br /&gt;
* Not all APIs are implemented such that they are nicely queryable to return the same response data in each response. E.g., financial data APIs may return data elements in different order in different responses or may have different starting timestamps of responses.&lt;br /&gt;
In order for the replicas to agree on a single response value as part of consensus, the different responses need to be equal. To achieve this property, each replica invokes a so-called transformation function on its received response and continues processing with the transformed response. The transformed response is used for the attempt to achieve consensus as explained earlier by first broadcasting an artifact corresponding to the transformed response through which a block making replica can observe whether a given response has a sufficient number of equal transformed responses.&lt;br /&gt;
&lt;br /&gt;
Next, there are some examples on how consensus can be reached for HTTP responses. Different cases are illustrated below with an example of a simple weather API.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== All responses are equal ===&lt;br /&gt;
&lt;br /&gt;
The simplest case is that of all responses received by replicas being equal. In this case, no transformation function is needed as the responses themselves are already equal and consensus can be achieved on them.&lt;br /&gt;
&lt;br /&gt;
[[File:all_responses_equal.png|center|700px|Identical responses – easy to reach consensus]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Some responses are not equal ===&lt;br /&gt;
&lt;br /&gt;
Assuming the case that less than one third of the responses can be arbitrarily different to the others and the others are all equal. The different responses can be a result of the server responding differently or nodes being compromised and falsifying the received (correct) response. This case is handled exactly as above by not requiring a transformation function and the IC consensus protocol taking care of the subset of deviating responses and going with the majority of replicas.&lt;br /&gt;
&lt;br /&gt;
[[File:some_responses_not_equal.png|center|700px|At least two thirds of responses are equal – easy to reach consensus]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Variable parts in all responses ===&lt;br /&gt;
&lt;br /&gt;
The most general case is that of each response returned by the HTTP server being different due to the reasons outlined further above, e.g., variable parts being contained therein. This case requires a transformation function to &amp;quot;normalize&amp;quot; the responses to be pairwise equal (for at least two thirds of the replicas). The transformed responses then can be consented on by the protocol as in the cases above. Clearly, less than one third of the responses can still be arbitrarily different as in the case above and consensus can still be reached.&lt;br /&gt;
&lt;br /&gt;
[[File:variable_parts_in_all_responses.png|center|700px|Identical responses after transformation – easy to reach consensus]]&lt;br /&gt;
&lt;br /&gt;
As can be seen, all the above cases can be handled easily with an extension of the IC&#039;s consensus protocol. The important part is that the canister developer needs to provide the transformation function if required, i.e., in the typical case of using APIs. Refer to the feature documentation for a recipe to write a transformation function and further information to help developers getting started with the feature.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
* &#039;&#039;&#039;The Internet Computer project website (hosted on the IC): [https://internetcomputer.org/ internetcomputer.org]&#039;&#039;&#039;&lt;/div&gt;</summary>
		<author><name>Yotam.harchol</name></author>
	</entry>
	<entry>
		<id>https://wiki.internetcomputer.org/w/index.php?title=IC_P2P_(peer_to_peer)_layer&amp;diff=3447</id>
		<title>IC P2P (peer to peer) layer</title>
		<link rel="alternate" type="text/html" href="https://wiki.internetcomputer.org/w/index.php?title=IC_P2P_(peer_to_peer)_layer&amp;diff=3447"/>
		<updated>2022-11-10T09:36:03Z</updated>

		<summary type="html">&lt;p&gt;Yotam.harchol: Created page with &amp;quot;The peer-to-peer layer of the IC is responsible for delivering messages between peers within subnets. It is designed to ensure efficient delivery of messages even in the prese...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The peer-to-peer layer of the IC is responsible for delivering messages between peers within subnets. It is designed to ensure efficient delivery of messages even in the presence of malicious activity.&lt;br /&gt;
&lt;br /&gt;
== Artifacts ==&lt;br /&gt;
Each client of the P2P layer, i.e., components in the layers above it like Consensus, maintains a collection of artifacts (artifact pool). Artifacts are messages that are exchanged between peers within a subnet to create, validate and agree on blocks. These can be, for example, consensus block proposals, ingress messages from users, or signature shares of responses for the HTTPS outcalls feature. Nodes distribute these artifacts to their peers so all peers have the same view of the state of the subnet. This allows nodes to include ingress messages sent to other peers when they create block proposals and to catch up efficiently if they have been disconnected or joining a new subnet.&lt;br /&gt;
&lt;br /&gt;
The P2P layer is invoked by the artifact pools when an artifact needs to be delivered to peers. This can happen when the node itself generates a new artifact (e.g., a new block proposal), or when it wants to &#039;&#039;relay&#039;&#039; an artifact it received from another peer (for example, we would want to relay block proposals even when all peers are connected to all peers, since a malicious peer can send one block proposal to a subset of peers, and another (or none) to another subset. This can slow down a subnet. Relaying proposals prevents this). Relay also helps in cases when some nodes are only connected to some peers. This can happen when a node’s ISP changes its BGP peering settings.&lt;br /&gt;
&lt;br /&gt;
== Adverts ==&lt;br /&gt;
[[File:P2p.jpg|thumb|700px|Caption: Instead of sending an artifact from multiple peers, peers send adverts (smaller messages) and the recipient requests the artifact from a small subset of its peers.]]&lt;br /&gt;
In order to save bandwidth, which would be wasted by sending an artifact to a peer that already has the artifact in its pool, the P2P layer does not send out artifacts immediately to all peers when requested by a client to broadcast an artifact. Instead, it creates a message called &#039;&#039;advert&#039;&#039;, which is a very small message with the hash of the artifact and some more metadata, and broadcasts this advert to all peers. Other peers then see the advert and decide whether they would like to download the corresponding artifact from that peer, and if so, they send an explicit &#039;&#039;request&#039;&#039; message to that peer, which will respond with the artifact itself. This approach clearly trades throughput for latency, but for the requirements of the IC’s consensus protocol this is desired.&lt;br /&gt;
&lt;br /&gt;
To share the bandwidth fairly among all peers and to avoid running out of memory, the number of in-flight requests is limited.&lt;br /&gt;
&lt;br /&gt;
== Chunks ==&lt;br /&gt;
Some artifacts, like state sync artifacts, are too big to be sent as a single chunk. For these artifacts, a single advert represents a set of &#039;&#039;chunks&#039;&#039; that together make up a complete artifact. When a downloaded artifact is &#039;&#039;chunkable&#039;&#039;, the P2P layer will attempt to download the corresponding chunks from multiple peers which advertised the corresponding artifact. This speeds up the download and better utilizes the bandwidth.&lt;br /&gt;
&lt;br /&gt;
== Verification of Artifacts ==&lt;br /&gt;
Each advert contains an &#039;&#039;integrity hash&#039;&#039; of the corresponding artifact. The integrity hash is the result of applying a cryptographic hash function over the content of the artifact. When an artifact download is complete, the same function is applied locally on the downloaded content, and only if the result matches the advertised hash value, the artifact is processed and provided to the corresponding artifact pool of the corresponding client.&lt;br /&gt;
&lt;br /&gt;
It is important to note that this is only a first layer of defense: a malicious node can send an advert with some integrity hash, and then an artifact that matches the advertised hash. This will pass all checks in the P2P layer, and the client will then have to notice that the artifact does not meet its requirements, e.g., is not signed correctly. The clients in the IC implementation always perform validation checks to catch such attacks before processing artifacts further or relaying them to other peers.&lt;br /&gt;
&lt;br /&gt;
Chunkable artifacts are validated both per-chunk and as a whole, where the corresponding client is responsible for per-chunk validation.&lt;br /&gt;
&lt;br /&gt;
== Retransmission Requests ==&lt;br /&gt;
In some cases, for example when a node notices an error in receiving adverts, or when it joins a new subnet, it sends out a &#039;&#039;retransmission request&#039;&#039; to its peers. The request can go to one specific peer (e.g., when a connectivity issue is detected with that peer), or to all peers (e.g., when the node joins). The request contains information about the node’s current state, and peers can respond with adverts that can help the node make progress from its current state, as reported in the retransmission request.&lt;br /&gt;
&lt;br /&gt;
While retransmission requests are meant for helping nodes to catch up on missed adverts, they may also issue them periodically to make sure they haven’t missed anything.&lt;br /&gt;
&lt;br /&gt;
== Transport ==&lt;br /&gt;
The underlying Transport component of the P2P layer is responsible for maintaining the actual connections between peers in a subnet. It creates TLS over TCP connections between the peers, where both sides authenticate using their private keys.&lt;br /&gt;
&lt;br /&gt;
Each peer has its public key stored in the registry canister of the Network Nervous System (NNS). The registry canister also contains the most up-to-date subnet membership information (which nodes belong to which subnet), as well as historic information. Each node learns its own membership, as well as who its peers are, what their IP addresses are, and what their public keys are, by querying the registry canister. Nodes always make sure they only connect to peers in their subnet by enforcing two-way authentication when establishing the TLS connections. &lt;br /&gt;
&lt;br /&gt;
Subnet memberships change over time, with nodes being added and removed from subnets regularly based on NNS accepted proposals. The Transport component continuously tracks these changes and adjusts the connections accordingly. In some cases, nodes need to maintain connections to peers that are no longer in the subnet record of the newest registry canister entries, while consensus still considers them to be part of the subnet, and thus the Transport component allows for such connections until they are no longer required.&lt;br /&gt;
&lt;br /&gt;
The Transport component also provides mechanisms for keeping the connection alive, quickly identifies connection issues (using a heartbeat mechanism), and automatically reconnects when the connection breaks. Whenever a TCP connection is idle for more than 200ms, a heartbeat message is sent over. On the receive side, when no data (including heartbeats) is received for more than 5s, the connection is being dropped and reconnected. This is done to avoid waiting for a possibly very long timeout duration of the TCP protocol, which sometimes happens upon Internet routing change events. After a connection is re-established, a retransmission request is sent to the corresponding peer.&lt;/div&gt;</summary>
		<author><name>Yotam.harchol</name></author>
	</entry>
	<entry>
		<id>https://wiki.internetcomputer.org/w/index.php?title=File:P2p.jpg&amp;diff=3446</id>
		<title>File:P2p.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.internetcomputer.org/w/index.php?title=File:P2p.jpg&amp;diff=3446"/>
		<updated>2022-11-10T09:31:21Z</updated>

		<summary type="html">&lt;p&gt;Yotam.harchol: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;p2p&lt;/div&gt;</summary>
		<author><name>Yotam.harchol</name></author>
	</entry>
	<entry>
		<id>https://wiki.internetcomputer.org/w/index.php?title=File:HTTPS_outcall_request_lifecycle1.png&amp;diff=3171</id>
		<title>File:HTTPS outcall request lifecycle1.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.internetcomputer.org/w/index.php?title=File:HTTPS_outcall_request_lifecycle1.png&amp;diff=3171"/>
		<updated>2022-10-05T06:03:09Z</updated>

		<summary type="html">&lt;p&gt;Yotam.harchol: Yotam.harchol uploaded a new version of File:HTTPS outcall request lifecycle1.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;HTTPS outcall request lifecycle&lt;/div&gt;</summary>
		<author><name>Yotam.harchol</name></author>
	</entry>
	<entry>
		<id>https://wiki.internetcomputer.org/w/index.php?title=HTTPS_outcalls&amp;diff=3170</id>
		<title>HTTPS outcalls</title>
		<link rel="alternate" type="text/html" href="https://wiki.internetcomputer.org/w/index.php?title=HTTPS_outcalls&amp;diff=3170"/>
		<updated>2022-10-05T04:43:34Z</updated>

		<summary type="html">&lt;p&gt;Yotam.harchol: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;On the Internet Computer blockchain, canister smart contracts can make HTTP outcalls to specified URLs, either to directly obtain off-chain data, or to interact with off-chain systems, such as Web 2.0 services or enterprise IT infrastructure. The results of these calls are processed and agreed by consensus, preventing nondeterminism. This avoids the need for trusted oracles and bridges.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Often, smart contract software needs to obtain real-world data, which originates from outside the secure and unstoppable on-chain universe that the blockchain that hosts them provides. Smart contracts may also need to interact with off-chain systems that are outside this universe. Because of the way blockchains work, historically this has presented major hurdles to blockchain developers.&lt;br /&gt;
&lt;br /&gt;
For example, to obtain off-chain data, smart contracts have traditionally interacted with centrally-operated oracle services, such as [https://chain.link/ Chainlink]. These services are provided by trusted intermediaries, such as corporations, which perform the role of copying off-chain data onto the blockchain where it can be accessed by smart contracts. The problem is that these services must a) be trusted to be honest, and not get hacked, or otherwise become faulty, and b) be paid. Moreover, they cannot help when smart contracts need to &#039;&#039;interact&#039;&#039; with off-chain services, for example by calling into web-based APIs. To solve for these needs, the Internet Computer provides an &amp;quot;HTTPS outcall&amp;quot; feature.&lt;br /&gt;
&lt;br /&gt;
HTTPS outcalls allow canister smart contracts hosted on the Internet Computer to request a URL, for example to download a time series recording the recent prices of an asset published by a centralized crypto exchange such as [https://pro.coinbase.com/ Coinbase Pro]. When this occurs, every node in the subnet blockchain hosting the smart contract requests the URL separately. Each node then locally passes the result they obtained to a special function implemented by the requesting canister smart contract using a [[query call]], which pre-processes the result with the aim of making it consistent with the results the other nodes have obtained and pre-processed (in our Coinbase example, since each node would request the time series at a slightly different moment, the results could be different).&lt;br /&gt;
&lt;br /&gt;
If the pre-processed results obtained by query calls to the canister smart contract are sufficiently consistent across all the nodes, the result is agreed by consensus, and provided back to the smart contract that requested the URL so that it can continue trustlessly processing the original smart contract call (TX).&lt;br /&gt;
&lt;br /&gt;
In order to trigger an action in an off-chain system, a smart contract may include a cryptographic [[chain key]] signature in its request for a URL. This allows the target service to validate that the request it has received was generated by a genuine smart contract execution that was agreed by consensus. In such architectures, when an off-chain service receives a valid request for a URL, it must take care to only execute it once, since many nodes will make the same request, and for each subsequent request after the first, it should return exactly the same result.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Architecture ==&lt;br /&gt;
The canister HTTPS outcalls feature has been implemented as an extension of the IC protocol stack, particularly its consensus layer. The possibility of the IC protocol stack allowing for such extensions shows the powerful architecture of the IC and its consensus protocol. In this section we give details on the architecture of the feature: We show which components of the stack needed to be extended and which new components were required and explain a protocol flow through the stack.&lt;br /&gt;
&lt;br /&gt;
=== HTTPS Outcall Request Lifecycle ===&lt;br /&gt;
[[File:HTTPS outcall request lifecycle1.png|thumb|700px|HTTPS outcall request lifecycle]]&lt;br /&gt;
The figure above shows the process an HTTPS outcall request goes through, along with the new components that were added to make this feature work. The numbered arrows indicate the steps as follows:&lt;br /&gt;
# A canister makes an HTTPS outcall request to the management canister in the execution layer. The request is stored in the replicated state of the corresponding subnet.&lt;br /&gt;
# A new component in the Consensus layer, called the “HTTP pool manager”, is reading state changes and keeps track of outstanding HTTPS requests.&lt;br /&gt;
#Whenever the HTTP pool manager sees a new request, it forwards it to the networking layer, to a new component that is called “HTTP adapter shim”. This is a relatively lightweight component that is responsible for communicating with the “HTTP adapter”, which is a separate process running alongside the replica process, but is isolated for security reasons.&lt;br /&gt;
# The HTTP adapter shim forwards the request to the HTTP adapter using RPC.&lt;br /&gt;
# The HTTP adapter on each node issues the requested HTTPS request to the remote server.&lt;br /&gt;
# A response is returned from the server to each HTTP adapter.&lt;br /&gt;
# Each HTTP adapter returns the response to the HTTP adapter shim component.&lt;br /&gt;
# The HTTP adapter shim invokes an optional transform function on the calling canister. The purpose of this function is explained in detail below, but in short, it should help in making all responses exactly the same so that the subnet can reach consensus on them.&lt;br /&gt;
# The HTTP adapter shim forwards the transformed response to the HTTP pool manager&lt;br /&gt;
# The Consensus layer then distributes shares of the response to all peers, so that the block maker can see that enough peers received exactly the same response as it has received.&lt;br /&gt;
# The block maker then includes the response in a block.&lt;br /&gt;
# The response is made available to the execution layer.&lt;br /&gt;
# A callback is invoked to return the response to the canister asynchronously.&lt;br /&gt;
&lt;br /&gt;
== How to reach consensus on result? ==&lt;br /&gt;
&lt;br /&gt;
As explained above, every node makes a given HTTP request to the target server and receives a response. There are multiple reasons why the responses are not necessarily the same on all replicas for the same API query:&lt;br /&gt;
* Typical implementations of web servers add variable elements to otherwise equal content, e.g., timestamps or unique identifiers. In this case, the actual content, e.g., requested asset prices, can be the same in each response, while those variable fields differ.&lt;br /&gt;
* Not all APIs are implemented such that they are nicely queryable to return the same response data in each response. E.g., financial data APIs may return data elements in different order in different responses or may have different starting timestamps of responses.&lt;br /&gt;
In order for the replicas to agree on a single response value as part of consensus, the different responses need to be equal. To achieve this property, each replica invokes a so-called transformation function on its received response and continues processing with the transformed response. The transformed response is used for the attempt to achieve consensus as explained earlier by first broadcasting an artifact corresponding to the transformed response through which a block making replica can observe whether a given response has a sufficient number of equal transformed responses.&lt;br /&gt;
&lt;br /&gt;
We next look at some examples on how consensus can be reached for HTTP responses. We illustrate the different cases below with an example of a simple weather API.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== All responses are equal ===&lt;br /&gt;
&lt;br /&gt;
The simplest case is that of all responses received by replicas being equal. In this case, no transformation function is needed as the responses themselves are already equal and consensus can be achieved on them.&lt;br /&gt;
&lt;br /&gt;
[[File:all_responses_equal.png|center|700px|Identical responses – easy to reach consensus]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Some responses are not equal ===&lt;br /&gt;
&lt;br /&gt;
Assuming the case that less than one third of the responses can be arbitrarily different to the others and the others are all equal. The different responses can be a result of the server responding differently or nodes being compromised and falsifying the received (correct) response. This case is handled exactly as above by not requiring a transformation function and the IC consensus protocol taking care of the subset of deviating responses and going with the majority of replicas.&lt;br /&gt;
&lt;br /&gt;
[[File:some_responses_not_equal.png|center|700px|At least two thirds of responses are equal – easy to reach consensus]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Variable parts in all responses ===&lt;br /&gt;
&lt;br /&gt;
The most general case is that of each response returned by the HTTP server being different due to the reasons outlined further above, e.g., variable parts being contained therein. This case requires a transformation function to &amp;quot;normalize&amp;quot; the responses to be pairwise equal (for at least two thirds of the replicas). The transformed responses then can be consented on by the protocol as in the cases above. Clearly, less than one third of the responses can still be arbitrarily different as in the case above and  we can still reach consensus.&lt;br /&gt;
&lt;br /&gt;
[[File:variable_parts_in_all_responses.png|center|700px|Identical responses after transformation – easy to reach consensus]]&lt;br /&gt;
&lt;br /&gt;
As can be seen, all the above cases can be handled easily with an extension of the IC&#039;s consensus protocol. The important part is that the canister developer needs to provide the transformation function if required, i.e., in the typical case of using APIs. We refer the reader to the feature documentation for a recipe to write a transformation function and further information to help developers getting started with the feature.&lt;/div&gt;</summary>
		<author><name>Yotam.harchol</name></author>
	</entry>
	<entry>
		<id>https://wiki.internetcomputer.org/w/index.php?title=File:HTTPS_outcall_request_lifecycle1.png&amp;diff=3169</id>
		<title>File:HTTPS outcall request lifecycle1.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.internetcomputer.org/w/index.php?title=File:HTTPS_outcall_request_lifecycle1.png&amp;diff=3169"/>
		<updated>2022-10-05T04:43:13Z</updated>

		<summary type="html">&lt;p&gt;Yotam.harchol: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;HTTPS outcall request lifecycle&lt;/div&gt;</summary>
		<author><name>Yotam.harchol</name></author>
	</entry>
	<entry>
		<id>https://wiki.internetcomputer.org/w/index.php?title=HTTPS_outcalls&amp;diff=3164</id>
		<title>HTTPS outcalls</title>
		<link rel="alternate" type="text/html" href="https://wiki.internetcomputer.org/w/index.php?title=HTTPS_outcalls&amp;diff=3164"/>
		<updated>2022-09-28T12:34:57Z</updated>

		<summary type="html">&lt;p&gt;Yotam.harchol: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;On the Internet Computer blockchain, canister smart contracts can make HTTP outcalls to specified URLs, either to directly obtain off-chain data, or to interact with off-chain systems, such as Web 2.0 services or enterprise IT infrastructure. The results of these calls are processed and agreed by consensus, preventing nondeterminism. This avoids the need for trusted oracles and bridges.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Often, smart contract software needs to obtain real-world data, which originates from outside the secure and unstoppable on-chain universe that the blockchain that hosts them provides. Smart contracts may also need to interact with off-chain systems that are outside this universe. Because of the way blockchains work, historically this has presented major hurdles to blockchain developers.&lt;br /&gt;
&lt;br /&gt;
For example, to obtain off-chain data, smart contracts have traditionally interacted with centrally-operated oracle services, such as [https://chain.link/ Chainlink]. These services are provided by trusted intermediaries, such as corporations, which perform the role of copying off-chain data onto the blockchain where it can be accessed by smart contracts. The problem is that these services must a) be trusted to be honest, and not get hacked, or otherwise become faulty, and b) be paid. Moreover, they cannot help when smart contracts need to &#039;&#039;interact&#039;&#039; with off-chain services, for example by calling into web-based APIs. To solve for these needs, the Internet Computer provides an &amp;quot;HTTPS outcall&amp;quot; feature.&lt;br /&gt;
&lt;br /&gt;
HTTPS outcalls allow canister smart contracts hosted on the Internet Computer to request a URL, for example to download a time series recording the recent prices of an asset published by a centralized crypto exchange such as [https://pro.coinbase.com/ Coinbase Pro]. When this occurs, every node in the subnet blockchain hosting the smart contract requests the URL separately. Each node then locally passes the result they obtained to a special function implemented by the requesting canister smart contract using a [[query call]], which pre-processes the result with the aim of making it consistent with the results the other nodes have obtained and pre-processed (in our Coinbase example, since each node would request the time series at a slightly different moment, the results could be different).&lt;br /&gt;
&lt;br /&gt;
If the pre-processed results obtained by query calls to the canister smart contract are sufficiently consistent across all the nodes, the result is agreed by consensus, and provided back to the smart contract that requested the URL so that it can continue trustlessly processing the original smart contract call (TX).&lt;br /&gt;
&lt;br /&gt;
In order to trigger an action in an off-chain system, a smart contract may include a cryptographic [[chain key]] signature in its request for a URL. This allows the target service to validate that the request it has received was generated by a genuine smart contract execution that was agreed by consensus. In such architectures, when an off-chain service receives a valid request for a URL, it must take care to only execute it once, since many nodes will make the same request, and for each subsequent request after the first, it should return exactly the same result.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Architecture ==&lt;br /&gt;
The canister HTTPS outcalls feature has been implemented as an extension of the IC protocol stack, particularly its consensus layer. The possibility of the IC protocol stack allowing for such extensions shows the powerful architecture of the IC and its consensus protocol. In this section we give details on the architecture of the feature: We show which components of the stack needed to be extended and which new components were required and explain a protocol flow through the stack.&lt;br /&gt;
&lt;br /&gt;
=== HTTPS Outcall Request Lifecycle ===&lt;br /&gt;
[[File:HTTPS outcall request lifecycle.png|thumb|700px|HTTPS outcall request lifecycle]]&lt;br /&gt;
The figure above shows the process an HTTPS outcall request goes through, along with the new components that were added to make this feature work. The numbered arrows indicate the steps as follows:&lt;br /&gt;
# A canister makes an HTTPS outcall request to the management canister in the execution layer. The request is stored in the replicated state of the corresponding subnet.&lt;br /&gt;
# A new component in the Consensus layer, called the “HTTP pool manager”, is reading state changes and keeps track of outstanding HTTPS requests.&lt;br /&gt;
#Whenever the HTTP pool manager sees a new request, it forwards it to the networking layer, to a new component that is called “HTTP adapter shim”. This is a relatively lightweight component that is responsible for communicating with the “HTTP adapter”, which is a separate process running alongside the replica process, but is isolated for security reasons.&lt;br /&gt;
# The HTTP adapter shim forwards the request to the HTTP adapter using RPC.&lt;br /&gt;
# The HTTP adapter on each node issues the requested HTTPS request to the remote server.&lt;br /&gt;
# A response is returned from the server to each HTTP adapter.&lt;br /&gt;
# Each HTTP adapter returns the response to the HTTP adapter shim component.&lt;br /&gt;
# The HTTP adapter shim invokes an optional transform function on the calling canister. The purpose of this function is explained in detail below, but in short, it should help in making all responses exactly the same so that the subnet can reach consensus on them.&lt;br /&gt;
# The HTTP adapter shim forwards the transformed response to the HTTP pool manager&lt;br /&gt;
# The Consensus layer then distributes shares of the response to all peers, so that the block maker can see that enough peers received exactly the same response as it has received.&lt;br /&gt;
# The block maker then includes the response in a block.&lt;br /&gt;
# The response is made available to the execution layer.&lt;br /&gt;
# A callback is invoked to return the response to the canister asynchronously.&lt;br /&gt;
&lt;br /&gt;
== How to reach consensus? ==&lt;br /&gt;
&lt;br /&gt;
As explained above, every node makes a given HTTP request to the target server and receives a response. There are multiple reasons why the responses are not necessarily the same on all replicas for the same API query:&lt;br /&gt;
* Typical implementations of web servers add variable elements to otherwise equal content, e.g., timestamps or unique identifiers. In this case, the actual content, e.g., requested asset prices, can be the same in each response, while those variable fields differ.&lt;br /&gt;
* Not all APIs are implemented such that they are nicely queryable to return the same response data in each response. E.g., financial data APIs may return data elements in different order in different responses or may have different starting timestamps of responses.&lt;br /&gt;
In order for the replicas to agree on a single response value as part of consensus, the different responses need to be equal. To achieve this property, each replica invokes a so-called transformation function on its received response and continues processing with the transformed response. The transformed response is used for the attempt to achieve consensus as explained earlier by first broadcasting an artifact corresponding to the transformed response through which a block making replica can observe whether a given response has a sufficient number of equal transformed responses.&lt;br /&gt;
&lt;br /&gt;
We next look at some examples on how consensus can be reached for HTTP responses. We illustrate the different cases below with an example of a simple weather API.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== All responses are equal ===&lt;br /&gt;
&lt;br /&gt;
The simplest case is that of all responses received by replicas being equal. In this case, no transformation function is needed as the responses themselves are already equal and consensus can be achieved on them.&lt;br /&gt;
&lt;br /&gt;
[[File:all_responses_equal.png|center|700px|Identical responses – easy to reach consensus]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Some responses are not equal ===&lt;br /&gt;
&lt;br /&gt;
Assuming the case that less than one third of the responses can be arbitrarily different to the others and the others are all equal. The different responses can be a result of the server responding differently or nodes being compromised and falsifying the received (correct) response. This case is handled exactly as above by not requiring a transformation function and the IC consensus protocol taking care of the subset of deviating responses and going with the majority of replicas.&lt;br /&gt;
&lt;br /&gt;
[[File:some_responses_not_equal.png|center|700px|At least two thirds of responses are equal – easy to reach consensus]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Variable parts in all responses ===&lt;br /&gt;
&lt;br /&gt;
The most general case is that of each response returned by the HTTP server being different due to the reasons outlined further above, e.g., variable parts being contained therein. This case requires a transformation function to &amp;quot;normalize&amp;quot; the responses to be pairwise equal (for at least two thirds of the replicas). The transformed responses then can be consented on by the protocol as in the cases above. Clearly, less than one third of the responses can still be arbitrarily different as in the case above and  we can still reach consensus.&lt;br /&gt;
&lt;br /&gt;
[[File:variable_parts_in_all_responses.png|center|700px|Identical responses after transformation – easy to reach consensus]]&lt;br /&gt;
&lt;br /&gt;
As can be seen, all the above cases can be handled easily with an extension of the IC&#039;s consensus protocol. The important part is that the canister developer needs to provide the transformation function if required, i.e., in the typical case of using APIs. We refer the reader to the feature documentation for a recipe to write a transformation function and further information to help developers getting started with the feature.&lt;/div&gt;</summary>
		<author><name>Yotam.harchol</name></author>
	</entry>
	<entry>
		<id>https://wiki.internetcomputer.org/w/index.php?title=File:HTTPS_outcall_request_lifecycle.png&amp;diff=3163</id>
		<title>File:HTTPS outcall request lifecycle.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.internetcomputer.org/w/index.php?title=File:HTTPS_outcall_request_lifecycle.png&amp;diff=3163"/>
		<updated>2022-09-28T12:30:28Z</updated>

		<summary type="html">&lt;p&gt;Yotam.harchol: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;HTTPS outcall request lifecycle&lt;/div&gt;</summary>
		<author><name>Yotam.harchol</name></author>
	</entry>
</feed>