ethereum / trin

An Ethereum portal client: a json-rpc server with nearly instant sync, and low CPU & storage usage
380 stars 112 forks source link

Add `total_difficulty` to header #1191

Open pedrohba1 opened 8 months ago

pedrohba1 commented 8 months ago

Other block header structs have this field called total_difficulty. Can it be added to the Header in /src/types/execution/header.rs ?

    /// TotalDifficulty is the sum of all previous blocks difficulty including this block difficulty.
    ///
    /// If the Block containing this `BlockHeader` has been produced using the Proof of Stake
    /// consensus algorithm, this field will actually be constant and set to the terminal total difficulty
    /// that was required to transition to Proof of Stake algorithm, which varies per network. It is set to
    /// 58 750 000 000 000 000 000 000 on Ethereum Mainnet and to 10 790 000 on Ethereum Testnet Goerli.
    #[prost(message, optional, tag = "17")]
    pub total_difficulty: ::core::option::Option<BigInt>,
njgheorghita commented 8 months ago

Total difficulty is not an actual field of the header structure unlike difficulty which is an actual field of the header structure. Execution clients calculate the total difficulty in memory as they process all of the headers from genesis to latest. Given that portal clients do operate in a similar fashion, there is no straightforward way to calculate the total difficulty for a given height. This is a problem that will need to be solved once we turn our attention to supporting eth_* jsonrpc endpoints. Off the top of my head, I can't recall, but I do remember some proposals for how to achieve this, given a portal client's unique architecture. However, this is not a priority at the moment.