Block rewards without transaction hash

Hi,

need some help with representing validator rewards in every block, the problem is that those rewards are transaction-less state changes handled by the consensus.

It’s possible to read values from the internal smart contract as implemented here: https://github.com/energywebfoundation/ewc-rosetta/blob/69a2cbe029c8e3299c87ab2e1db95e7f6625b8d8/src/block/reward.service.ts#L7

Now, the example block including those rewards can look like:

{
    "block": {
        "block_identifier": {
            "index": 7344513,
            "hash": "0x28df95568e887461751d425d2af242996b11ff2fb85f5d84ccff90eef9b18c65"
        },
        "parent_block_identifier": {
            "index": 7344512,
            "hash": "0x0cf08a7221459ed55f519f47ea8a5f861da112b99ac9110e59a8cea12268bf74"
        },
        "timestamp": 1597757040,
        "transactions": [
            {
                "transaction_identifier": null,
                "operations": [
                    {
                        "operation_identifier": {
                            "index": 0
                        },
                        "type": "Reward",
                        "status": "Success",
                        "account": {
                            "address": "0x1204700000000000000000000000000000000002"
                        }
                    },
                    {
                        "operation_identifier": {
                            "index": 1
                        },
                        "type": "Reward",
                        "status": "Success",
                        "account": {
                            "address": "0xb600409101aB33d1a7DF8aF526a2eFBC72e475BB"
                        },
                        "amount": {
                            "value": "301997447685326464",
                            "currency": {
                                "symbol": "EWT",
                                "decimals": 18
                            }
                        },
                        "related_operations": [
                            {
                                "index": 0
                            }
                        ]
                    },
                    {
                        "operation_identifier": {
                            "index": 2
                        },
                        "type": "Reward",
                        "status": "Success",
                        "account": {
                            "address": "0x1204700000000000000000000000000000000002"
                        }
                    },
                    {
                        "operation_identifier": {
                            "index": 3
                        },
                        "type": "Reward",
                        "status": "Success",
                        "account": {
                            "address": "0x1204700000000000000000000000000000000003"
                        },
                        "amount": {
                            "value": "600900558100000000",
                            "currency": {
                                "symbol": "EWT",
                                "decimals": 18
                            }
                        },
                        "related_operations": [
                            {
                                "index": 2
                            }
                        ]
                    }
                ]
            }
        ]
    }
}

Since there is no transaction_identifier the rosetta-cli validation is failing with

Error: assertion failed: /block TransactionIdentifier is nil: /block not attempting retry: unable to sync to 7375301: unable to sync to 7375301

What would be the recommended way of handling those transactions?

Sorry for the delay here @pkosin!

The recommended way for dealing with “transaction-less” operations (i.e. balance changes that occur as a result of consensus) is to create a “block transaction” in each block with the transaction_identifier.hash equal to the block_identifier.hash.

Be sure to create at most 1 “block transaction” in each block otherwise you will violate the “tx_hash” universality assumptions.

In your example, this would mean:

{
  "block": {
    "block_identifier": {
      "index": 7344513,
      "hash": "0x28df95568e887461751d425d2af242996b11ff2fb85f5d84ccff90eef9b18c65"
    },
    "parent_block_identifier": {
      "index": 7344512,
      "hash": "0x0cf08a7221459ed55f519f47ea8a5f861da112b99ac9110e59a8cea12268bf74"
    },
    "timestamp": 1597757040,
    "transactions": [
      {
        "transaction_identifier": {
          "hash": "0x28df95568e887461751d425d2af242996b11ff2fb85f5d84ccff90eef9b18c65"
        },
        "operations": [
          {
            "operation_identifier": {
              "index": 0
            },
            "type": "Reward",
            "status": "Success",
            "account": {
              "address": "0x1204700000000000000000000000000000000002"
            }
          },
          {
            "operation_identifier": {
              "index": 1
            },
            "type": "Reward",
            "status": "Success",
            "account": {
              "address": "0xb600409101aB33d1a7DF8aF526a2eFBC72e475BB"
            },
            "amount": {
              "value": "301997447685326464",
              "currency": {
                "symbol": "EWT",
                "decimals": 18
              }
            },
            "related_operations": [
              {
                "index": 0
              }
            ]
          },
          {
            "operation_identifier": {
              "index": 2
            },
            "type": "Reward",
            "status": "Success",
            "account": {
              "address": "0x1204700000000000000000000000000000000002"
            }
          },
          {
            "operation_identifier": {
              "index": 3
            },
            "type": "Reward",
            "status": "Success",
            "account": {
              "address": "0x1204700000000000000000000000000000000003"
            },
            "amount": {
              "value": "600900558100000000",
              "currency": {
                "symbol": "EWT",
                "decimals": 18
              }
            },
            "related_operations": [
              {
                "index": 2
              }
            ]
          }
        ]
      }
    ]
  }
}``

Hope that helps!

Hey @patrick.ogrady

thanks for your answer, works just fine, reconciliation are now passing!

1 Like