OCR Set-up

OCR configuration, currently is specific for validators involved in participating in the Oracle price feeds. We will send an announcement to validators while changing the current price feeds to OCR protocol based price feeds.

Here are the detailed steps to enable Offchain reporting onto the Plugin Node for Peer.

  1. To enable OCR in the Plugin environment, set the parameters in the config.toml file as shown below. Once the changes are made, restart the plugin using pm2 restart 0.

// OCR parameters in config.toml in addition to Plugin parameters

[P2P]
PeerID = '<peer_ID_as shown in the image>'

[P2P.V1]
Enabled = true

[P2P.V2]
Enabled = true
AnnounceAddresses = ['<Public_IP_address_of_the_server>:5001']
DefaultBootstrappers = ['<bootStrapper_peer_ID>@<bootStrapper_node_IP>:5001']
ListenAddresses = ['<Public_IP_address_of_the_server>:5001']

[OCR]
Enabled = true
KeyBundleID = '<key_bundle_ID_as shown in the image>'

[OCR2]
Enabled = true
KeyBundleID =  '<key_bundle_ID_as shown in the image>'
  1. To set up the foundry repository pull the code base to your local environment git clone https://github.com/GoPlugin/foundry.git

  2. Now move into the foundry contracts directory

    • "cd foundry/contracts/v0.7.6"

  3. Invoke remix to deploy Offchainaggregator contract

    • "remixd -s . -u https://remix.xinfin.network"

  4. Once the remix is invoked, open the remix in the browser "https://remix.xinfin.network" URL.

  5. Now select Offchainaggregator.sol contract as given below.

  6. Parameters for deploying Offchainaggregator.sol

    i) Constructor params: ii) Decimal: 18

    iii) Billing Access Controller: <wallet_address>

    iv) Request Access Controller: <wallet_address>

    v) Min Ans : 0

    vi) Max Ans : 99999999999999999999

    vii) Validator : 0x0000000000000000000000000000000000000000 viii) PLI : 0x33f4212b027E22aF7e6BA21Fc572843C0D701CD1 ix) Max gas price : 3000

    x) Reasonable Gas Price: 75

    xi) MicroPliPerEth: 305186108

    xii) PliWeiPerObservation : 151513582

    xiii) PliWeiPerTransmission : 9090766

  7. To get the OS instruction set of server, execute the command "uname -m" in CLI.

  8. Now execute the command in foundry directory as given below.

external/OCRHelper/ocrhelper-linux-<command_7_output> NODE_ADDRESSES="<node_address_peer1>","<node_address_peer2>","<node_address_peer3>","<node_address_peer4>" OFFCHAIN_PUBLIC_KEYS="<peer1_offchain_public_key>,<peer2_offchain_public_key>,<peer3_offchain_public_key>,<peer4_offchain_public_key>" CONFIG_PUBLIC_KEYS="<peer1_config_public_key>,<peer2_config_public_key>,<peer3_config_public_key>,<peer4_config_public_key>" ONCHAIN_SIGNING_ADDRESSES="<peer1_onchain_sign_addr>,<peer2_onchain_sign_addr>,<peer3_onchain_sign_addr>,<peer4_onchain_sign_addr>" PEER_IDS="<Peer1_ID>,<Peer2_ID>,<Peer3_ID>,<Peer4_ID>"
// SAMPLE OUTPUT of the above command execution
[0x4bEDDe1B6464aC385C32E06Db3E3cD7486636BA7,0x336acE60B9247CC39996f15B2788AD7C9df7b2A1,0xeF53A8245De8169c40a2325Bab7D7369a92Fb4bC,0xae51BD92635FCbD683975aEcB778f2CE7d013FA5] 
[0xe2B935C17089b31c457B80A577338AbeDD5e6206,0xF73A7CD3908700F18e424C327c0301583bcEf41d,0x3CE7D10187eFf99DEbDC0923B2d4F447A5b42eB9,0x20A3beCE1147e33F1932AA12245E50858b261fFB] 
1 
1 
00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000826299e0000000000000000000000000000000000000000000000000000000003f5476a0000000000000000000000000000000000000000000000000000000006fc23ac0000000000000000000000000000000000000000000000000000000002cb4178000000000000000000000000000000000000000000000000000000034630b8a00000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000df847580000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000002e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004315e5b0930b10e51c9149013ed68fa88c6bc230048212ccb7066cb02f4525e282d1fb82f0b3b1fa7a32531bac38c5cb53b030711165038b1185f5259d3db678317af622227ec7bf7f4e32c5a2b4161d86147c299750b236043622a83af6901719a829bf2db49f3e215c948b8108e4da83cb61ed5c53483e237175fb57d9ec2a700000000000000000000000000000000000000000000000000000000000000e37032705f313244334b6f6f5748596e694c6b76376f7a32726a3374564c4156657231384b373546356b4e736142506277576d6a6d686158432c7032705f313244334b6f6f57506f716a36486d7a6e5738553657436e4a46486a516774486442594a3352425a4770624b46473662316461652c7032705f313244334b6f6f57536165344b624835374d446e48504b476a656739354e444d593435347273334739376e51474d6335356f396a2c7032705f313244334b6f6f57535756386a74774b363666347a435a4237597179595238734a64674b316e547743354c5347313347353472640000000000000000000000000000000000000000000000000000000000d91977e6e91d96dc1577706e4d6b4232bfdd4cdb5a26e3de7c6ba5ecade1c224bc052e956da259990fa5364def4eb76fcee1374aa863d7244db0fc39dee675870000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000467df5168d0cd9e03571d5afeb312e7df00000000000000000000000000000000a278a323a7bcc33f6dcc64fe7ec960c100000000000000000000000000000000fa7aca070b44c477a2eb93f4f17f134a000000000000000000000000000000005b1e4c4b5cd02a4861b707e23ff2c6b900000000000000000000000000000000
  1. Get the [5th] parameter field from the above output as the value of hexString

  2. Deploy the cast.sol contract in remix to convert the hexString value to solidity bytes

```remix-solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract HexToBytesConverter {
    // Function to convert hexadecimal string to bytes
    function hexStringToBytes(string memory hexa) public pure returns (bytes memory) {
        bytes memory b = bytes(hexa);
        require(b.length % 2 == 0, "Hex string has odd length");

        bytes memory result = new bytes(b.length / 2);

        for (uint256 i = 0; i < bytes(hexa).length / 2; i++) {
            result[i] = bytes1(_fromHexChar(uint8(bytes(hexa)[2 * i])) * 16 + _fromHexChar(uint8(bytes(hexa)[2 * i + 1])));
        }

        return result;
    }

    // Helper function to convert a hex character to its value
    function _fromHexChar(uint8 c) internal pure returns (uint8) {
        if (bytes1(c) >= bytes1('0') && bytes1(c) <= bytes1('9')) {
            return c - uint8(bytes1('0'));
        } else if (bytes1(c) >= bytes1('a') && bytes1(c) <= bytes1('f')) {
            return 10 + c - uint8(bytes1('a'));
        } else if (bytes1(c) >= bytes1('A') && bytes1(c) <= bytes1('F')) {
            return 10 + c - uint8(bytes1('A'));
        } else {
            revert("Invalid hex character");
        }
    }
    
    // Function to simulate the usage of envBytes
    function getEnvBytes() public view returns (bytes memory) {
        // In a real scenario, this would retrieve the environment variable
        // Using the provided long hexadecimal string as an example
        string memory hexStr = "";
        return hexStringToBytes(hexStr);
    }
}
```
  1. In the 'hexStringToBytes' option pass the hexString value and click to get the solidity converted bytes.

  1. Set the payee in Offchainaggregator.sol contract using the below-mentioned values, and click on transact, transmitters: ["<node_address_peer1>","<node_address_peer2>","<node_address_peer3>","<node_address_peer4>"] payees: ["<node_address_peer1_walletaddress>","<node_address_peer2_walletaddress>","<node_address_peer3_walletaddress>","<node_address_peer4_walletaddress>"]

  1. Now set Offchainaggregator config using setConfig option

signers: [1] value from step 8 output 
transmitters: [2] value from step 8 output 
threshold: [3] value from step 8 output 
_encodedConfigVersion: [4] value from step 8 output 
encoded: bytes value from step 11
  1. It is time to submit Job for OCR. Job spec template for Peer nodes is available in foundry directory @ ./src/sandbox/clroot/jobs/ocr_job.toml. Kindly, make the required changes in the ocr_job.toml (mentioned in between '<>')and submit the job in your node, so that it will communicate with the bootstrapper node and participate in generating the off chain report.

type = "offchainreporting"
schemaVersion = 1
name = "Get > Uint256 <Offchainaggregator_contract_address> (ocr)"
forwardingAllowed = false
maxTaskDuration = "0s"
blockchainTimeout = "20s"
contractAddress = "<Offchainaggregator_contract_address>"
contractConfigConfirmations = 3
contractConfigTrackerPollInterval = "2m0s"
contractConfigTrackerSubscribeInterval = "5m0s"
evmChainID = "51"
isBootstrapPeer = false
keyBundleID = "<key_bundle_ID_as mentioned in step 1>"
observationTimeout = "20s"
p2pBootstrapPeers = [
  "/dns4/<bootStrapper_node_IP>/tcp/5001/p2p/<bootStrapper_peer_ID>"
]
p2pv2Bootstrappers = [
  "<bootStrapper_peer_ID>@<bootStrapper_node_IP>:5001"
]
transmitterAddress = "<your_node_address>"
observationSource = """
   fetch        [type="http" method=GET url="https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd" allowUnrestrictedNetworkAccess="true"]
   parse        [type="jsonparse" path="ethereum,usd" data="$(fetch)"]
   multiply     [type="multiply" input="$(parse)" times=100]

   fetch -> parse -> multiply
"""
  1. Job submission output Once the job is submitted you can see the job is running in Plugin UI @ "Jobs" option.

Last updated