OCR Setup for Validators

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.

  • 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>'

/****************/

  • To set up the foundry repository pull the code base to your local environment git clone https://github.com/GoPlugin/foundry.git
  • Now move into the foundry contracts directory
  • Invoke remix to deploy Offchainaggregator contract
  • Once the remix is invoked, open the remix in the browser "https://remix.xinfin.network" URL. 
  • Now select Offchainaggregator.sol contract as given below.

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 : 0x00000000000000 00000000000000000 000000000 

viii) PLI : 0x33f4212b027E22a F7e6BA21Fc572843C0D701CD1 

ix) Max gas price : 3000

x) Reasonable Gas Price: 75

xi) MicroPliPerEth: 305186108

xii) PliWeiPerObservation : 151513582

xiii) PliWeiPerTransmission : 9090766

  • To get the OS instruction set of server, execute the command "uname -m" in CLI.
  • 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>"

  • Get the [5th] parameter field from the above output as the value of hexString
  • 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);  
   }  
}  
```

/******************/

  • In the 'hexStringToBytes' option pass the hexString value and click to get the solidity converted bytes.
  • 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>"]

 

  • Now set Offchainaggregator config using setConfig option

Copysigners: [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

  • It is time to submit the 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.

Copytype = "offchainreporting" schemaVersion = 1 name = "Get >  Uint256 <Offchainaggregator_contract_address> (ocr)" forwardingAllowed = false 

maxTaskDuration = "0s" 

blockchainTimeout = "20s" 

contractAddress = "<Offchainaggregator_contract_address>" 

contractConfigConfirmations = 3 

contractConfigTrackerPollInterval = "2m0s"

ontractConfigTrackerSubscribeInterval = "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 """

  • Job submission output - Once the job is submitted you can see the job is running in Plugin UI @ "Jobs" option.

 

We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies

More