Skip to content

[Deprecated]Darwinia 1.0 offchain worker shadow service spec

fisher edited this page Apr 24, 2023 · 1 revision

Darwinia offchain worker is an offchain module based on Substrate offchain worker.

Darwinia uses a shadow service as a companion external service to serve the data request from offchain worker located in node runtime.

This document defines the spec of the shadow service for the offchain worker.

JSON RPC

There is a option to fallback the request with json format without codec and reuse most of the current code.

Wtihout option, default SCALE encoding

Request:

POST with application/json payload

{
  id: 1,
  jsonrpc: "2.0",
  method: "shadow_getEthHeaderWithProofByNumber",
  params: {"block_num": 1000, "transaction": false}
}

Response:

all value in response encoded by SCALE Codec

{
  "id":1,
  "jsonrpc":"2.0",
  "result": {
    "eth_header":  "0xd4e5 ...scale_encoded_str",
    "proof": "0xd4e5...scale_encoded_str"
  }
}

With options, use current implementation without SCALE encoding

params.options.format description
"raw" all number fields just number
"json" all number fields in hex
"scale" scale codec instead of common fields

Request:

POST with application/json payload

{
  id: 1,
  jsonrpc: "2.0",
  method: "shadow_getEthHeaderWithProofByNumber",
  params: {"block_num": 1000, "transaction": false, "options": {"format": "json"}}
}

Response:

The value is followed our current test https://github.com/darwinia-network/darwinia-common/blob/master/frame/bridge/eth/offchain/src/tests.rs#L14

{
  "id":1,
  "jsonrpc":"2.0",
  "result": {
     "eth_header": {
            "author": "0x05FC5a079e0583B8A07526023A16E2022c4C6296",
            "difficulty": "0x234abd97",
            "extra_data": [222, 131, 2, 7, 2, 143, 80, 97, 114, 105, 116, 121, 45, 69, 116, 104, 101, 114, 101, 117, 109, 134, 49, 46, 52, 49, 46, 48, 130, 108, 105],
            "gas_limit": "0x7a121d",
            "gas_used": "0x5be61f",
            "hash": "0x03558de481bd6bc7f38d03935bc90fb1333d6d72b2d2b217a32bb367ef4e8950",
            "log_bloom": "0x00040010004080040000000008000402800010100000040002088000108080020000008102404001002804400010000000000902000200000000000000000040108800000000000000020108010000400000000000000000000002000c00040000000000020020000c00000004100800400002200401100008040050110010001012480000002c0000000090020500000000048000000010000411000000000000000000080000000000410600040001000400000010080000000000000000040000000610000400296004020c8a0108000000010080480000000100010820100240010000800018100000800028020020010030000000006000008080002000",
            "number": 7575769,
            "parent_hash": "0xda6db2ef04f5f7ba97b16de78b3706b174926168e3e6b83d4923b19188a07e4f",
            "receipts_root": "0xe3b2454f74ec640c3eeb9fe1b1e181c2a91b8974c2921f69d628c1cfcb01a317",
            "seal": [
            	    [28, 97, 77, 163, 122, 91, 131, 138, 244, 93, 148, 8, 229, 5, 23, 127, 220, 236, 124, 150, 203, 242, 1, 163, 34, 149, 27, 62, 92, 202, 133, 120],
            	    [120, 155, 112, 159, 229, 170, 148, 183],
            "state_root": "0x273c41988cf142adff03b7b9ab8146574c0bcbd453cebefd5ef777ec1356dec6",
            "timestamp": 1584984734,
            "transactions_root": "0xfa985cdf3bd670a7b6c0349633c27f7823ef7d09b044dce53690e284fc00f4af",
            "uncles_hash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
        },
    "proof": [
               {
			"dag_nodes": ["0xabcd...", "0xebcd..."],
			"proof":["0xbbcde...", "0xabcde..."]
               },
		{
			"dag_nodes": ["0xabcd...", "0xebcd..."],
			"proof":["0xcccde...", "0xbbcde..."]
               }, ...
         ]
  }
}