@@ -28,7 +28,8 @@ const (
2828 maxDelayExcess = 46_516_320 // ConversionRate * ln(MaxUint64 / MinDelayMilliseconds) + 1
2929)
3030
31- // DelayExcess represents the excess for delay calculation in the dynamic minimum block delay mechanism.
31+ // DelayExcess represents the excess for delay calculation in the dynamic
32+ // minimum block delay mechanism.
3233type DelayExcess uint64
3334
3435// Delay returns the minimum block delay in milliseconds, `m`.
@@ -44,25 +45,25 @@ func (t DelayExcess) Delay() uint64 {
4445
4546// UpdateDelayExcess updates the DelayExcess to be as close as possible to the
4647// desiredDelayExcess without exceeding the maximum DelayExcess change.
47- func (t * DelayExcess ) UpdateDelayExcess (desiredDelayExcess uint64 ) {
48- * t = DelayExcess ( calculateDelayExcess (uint64 ( * t ) , desiredDelayExcess ) )
48+ func (t * DelayExcess ) UpdateDelayExcess (desiredDelayExcess DelayExcess ) {
49+ * t = calculateDelayExcess (* t , desiredDelayExcess )
4950}
5051
5152// DesiredDelayExcess calculates the optimal delay excess given the desired
52- // delay.
53- func DesiredDelayExcess (desiredDelay uint64 ) uint64 {
53+ // delay in milliseconds .
54+ func DesiredDelayExcess (desiredDelay uint64 ) DelayExcess {
5455 // This could be solved directly by calculating D * ln(desired / M)
5556 // using floating point math. However, it introduces inaccuracies. So, we
5657 // use a binary search to find the closest integer solution.
57- return uint64 (sort .Search (maxDelayExcess , func (delayExcessGuess int ) bool {
58+ return DelayExcess (sort .Search (maxDelayExcess , func (delayExcessGuess int ) bool {
5859 excess := DelayExcess (delayExcessGuess )
5960 return excess .Delay () >= desiredDelay
6061 }))
6162}
6263
63- // calculateDelayExcess calculates the optimal new DelayExcess for a block proposer to
64- // include given the current and desired excess values.
65- func calculateDelayExcess (excess , desired uint64 ) uint64 {
64+ // calculateDelayExcess calculates the optimal new DelayExcess for a block
65+ // proposer to include given the current and desired excess values.
66+ func calculateDelayExcess (excess , desired DelayExcess ) DelayExcess {
6667 change := safemath .AbsDiff (excess , desired )
6768 change = min (change , MaxDelayExcessDiff )
6869 if excess < desired {
0 commit comments