unicornultrafoundation / go-u2u

Implementation of U2U Network in Golang
https://u2u.xyz
GNU Lesser General Public License v3.0
4 stars 3 forks source link

Randomize output of eth_feeHistory to mimic ETH API #88

Closed b1m0n closed 5 months ago

b1m0n commented 5 months ago

In ETH API, eth_feeHistory is originally intended to return the history of gas tips in recent blocks, which has to be used as a data source for a custom gas tip estimation. Typically, the resulting gas tip is expected to be an average or a median of the historic median values. The same approach cannot be used in U2U due to the leaderless and asynchronous nature of the consensus algorithm. Instead, eth_feeHistory itself performs the estimation of gas tip and calculates a single gas tip, where percentile is interpreted as a confidence level (higher -> larger fee). This value is then copied for each requested block, in a case if multiple blocks were requested. We expect that users can reuse the same code for gas tip estimation which they use for ETH, because both an average or a median of the copied values will still be equal to the intended value. However, it causes a confusion as it's apparent that the output doesn't match the ETH API description of the method.

This PR randomizes the copied gas tip by up to 2% upward in order to closer cosmetically mimic the original ETH API variant of the method. The gas tip for last requested block is left as-is without randomization. The PR adds note to output of eth_feeHistory which explains the difference in output.

This way, we endeavor to balance fidelity to the original API design with the adaptations necessary for U2U unique architecture, thereby providing users with a tool that is both familiar and optimized for the new context.