Concordium / concordium-node

The main concordium node implementation.
GNU Affero General Public License v3.0
45 stars 22 forks source link

Block hash: Include missing information needed for light client #1067

Closed limemloh closed 9 months ago

limemloh commented 11 months ago

To reduce the work needed for light client implementations, starting from Protocol version 7 the block hash should include more information:

limemloh commented 11 months ago

Protocol version, absolute and relative block height

The protocol version is accessible in most parts of the code, so it is easy to put pretty much anywhere in the block hash, but I think it should be very close to the top of the state hash, since the light client will need this to understand the remaining hashing structure. But it could also get the information from the node and then check it afterward without an issue.

Absolute and relative block height are not really available in the block state, since they live in the tree state, by suggestion is to introduce a node above the block state hash in the state hash, which includes this information and the block state hash as the first branch.

data BlockTreeStateHashInputs pv = BlockTreeStateHashInputs
    { blockStateHash :: BlockStateHash, -- What previously was the state hash.
      relativeBlockHeight :: RelativeBlockHeight,
      absoluteBlockHeight :: AbsoluteBlockHeight,
    }

makeBlockTreeStateHashInputs :: BlockTreeStateHashInputs pv -> StateHash
makeBlockTreeStateHashInputs {..} = 
    if includesBlockheightAndPVInHashing pv then
        StateHashV0 $
            H.hashOfHashes
                blockStateHash
                (hash $ put (relativeBlockHeight, abosluteBlockheight, pv))
    else
        StateHashV0 blockStateHash

Current and next finalization committee

To me, the simplest solution seems to be to add a _finalizationCommitteeHash field to PersistentEpochBakers type where the information to derive this is already present. Then of course have the hashing, loading and storing for this type branch on the protocol version.

The information is not as close to the root as it could be, but I think it is still reasonable.

limemloh commented 10 months ago

Including the protocol version will be done as a separate task tracked here https://github.com/Concordium/concordium-node/issues/1106