## Insurance mechanism with finite termination time
We first need to define the exponential distribution on a finite interval from $0$ to $x_{\rm max}$. Since $x$ can only take values inside this interval, we need to properly normalize it to one,
$$P_\lambda(x)=\mathcal{N}e^{-\lambda x},$$
where
$$1=\mathcal{N}\int_0^{x_{\rm max}}e^{-\lambda x}dx=\mathcal{N}\frac{1}{\lambda}\left(1-e^{-\lambda x_{\rm max}}\right),$$
so we define
$$\mathcal{N}\equiv \frac{\lambda}{1-e^{-\lambda x_{\rm max}}}.$$
Next we find the expected value of $x$ (which we will call $1/\tilde\lambda$) for a given $\lambda$,
$$\frac{1}{\tilde{\lambda}}\equiv E_\lambda[x]=\mathcal{N}\int_0^{x_{\rm max}}x\,e^{-\lambda x}dx=\mathcal{N}\left[\frac{1}{\lambda^2}-\frac{(\lambda x_{\rm max}+1)e^{-\lambda x_{\rm max}}}{\lambda^2}\right]$$
We now assume the reward during a fault of duration $x$ has a form
$$Reward(x)=-Fx+R(x)$$
where $R(x)$ is a function that grows faster than linearly. We can choose, keeping some generality some power function $R(x)=cx^\alpha$, with $c$ and $\alpha>1$ to be chosen later.
For miners with expected recovery time, $1/\tilde\lambda$, their expected reward is
$$E_{Reward,\lambda}=-\int_0^{x_{\rm max}}\left(F x-c x^\alpha\right)\mathcal{N}e^{-\lambda x}dx$$
$$=-\frac{F}{\tilde{\lambda}}-\mathcal{N}c\left[\Gamma(\alpha+1,\lambda x_{\rm max})-\Gamma(\alpha+1,0)\right]\lambda^{-\alpha-1},$$
where $\Gamma(s,x)$ is the *Incomplete Gamma function* (https://en.wikipedia.org/wiki/Incomplete_gamma_function).
This can be simplified if we choose $\alpha=2$ as in the original proposal, then,
$$E_{Reward,\lambda}\vert_{\alpha=2}=-\frac{F}{\tilde{\lambda}}-\mathcal{N}c\left[\frac{2}{\lambda^3}-\frac{\lambda^2 x_{\rm max}^2+2\lambda x_{\rm max}+2}{\lambda^3}e^{-\lambda x_{\rm max}}\right].$$
The longest the miner can wait before being terminated is $x_{\rm max}$, for which there is a reward
$$Reward(x_{\rm max})=-F x_{\rm max}+c x_{\rm max}^\alpha$$.
The free parameters, $c$ and $\alpha$ must be chosen such that they satisfy the constraints:
1) The expected reward should be greater for miners who fix their fault faster:
$$E_{Reward,\lambda_1}> E_{Reward,\lambda_2},\,\,\,{\rm for\,\,\,all}\,\,\frac{1}{\tilde\lambda_1}<\frac{1}{\tilde{\lambda}_2}.$$
2) The Expected reward should always be greater if the fault is fixed before termination:
$$E_{Reward, \lambda}>Reward(x_{\rm max})\,\,\,{\rm for\,\,any}\,\,\,\frac{1}{\tilde\lambda}<x_{\rm max}.$$
## Visualization of insurance
We assume the fee the total miner will have to pay for their fault is of the form
$$Reward(x)=-Fx+cx^\alpha$$
The discount policy and constraints are easier to visualize if instead we consider a *reward rate*, defined as
$$Rate(x)=\frac{d Reward(x)}{dx}=-F+
\alpha c x^{\alpha-1},$$
If a miner repairs their fault at a time $x$, then the total fee they will pay will be given by the area between the two curves, $F$, and $\alpha c x^{\alpha-1}$.
Take for instance, the case where there is no insuirance discount, $c=0$. The maximum fee that will be paid will be if the miner waits until termination time $x_{\rm max}$ without repairing the fault. We represent the total fee as the total area under the curve given by the constant line at $F$, as seen below. For simplicity, from now on we will set $F=x_{\rm max}=1$ when plotting these curves.

where the total green area is the fee the miner will pay.
If we now introduce a discount, with for example $\alpha=2$, we want to adjust $c$ such that the two constraints are always satisfied, that is, the more the miner waits to fix the fault, the more they will pay.
Below we show the case with $\alpha=2$ and a few values of $c=\frac{1}{1.4}\frac{F}{\alpha x_{\rm max}^{\alpha-1}},\,\,\,1.4\frac{F}{\alpha x_{\rm max}^{\alpha-1}},\,\,\,\frac{F}{\alpha x_{\rm max}^{\alpha-1}}$

In the first plot we see the constraint is satisfied, the longer the miner waits, the more they will pay. In the second image, at some point, the discount outgrows the fee around $x=.7$, After that point, the area between the curves becomes negative, cancelling some of the fee, so the longer the miner waits the less they pay. The third graph represents the optimal value, the largest $c$ that can be chosen such that the contraints are satisfied.
For general $\alpha$, the constraint on $c$ is then
$$c\le \frac{F}{\alpha x_{\rm max}^{\alpha-1}}$$.
We show below, if we choose $\alpha=2$, and optimal $c$, the total fee a miner will pay if they wait different amounts of time to fix their fault.

### $\alpha$ as network generosity parameter
Now that we understand how to fix $c$ such that the constraints are satisfied, the parameter $\alpha>1$ is still flexible, and we can study the effect of adjusting it.
We plot the total fee areas for optimal $c$ and varying values of $\alpha$.

It is helpful to understand the limits. If we let $\alpha\to\infty$, this amounts to having no discount at all. If we let $\alpha\to0$, this amounts to the system eliminating all the fee. The value $\alpha=2$ corresponds to eliminating exactly half of the fee, when the miner waits all the way to the termination time.
The parameter $\alpha$ then controls how generous the network wants to be about forgiving miner fees. This parameter could be considered adjustable depending on the needs of the network. Under normal times, it can be kept at a high value, such that most of the fee is paid. In a shock situation, $\alpha$ can be reduced as needed to satisfy the stress of the network.
## Further customizing discount shape
Now that we have a visual understanding of what we want the discount to do, we can engineer some custom curve for $R(x)$, which best suits our needs.
For instance, all the $R(x)=c x^\alpha$ curves we have discussed, start at a maximum amount of fee rate at $x=0$, and then the fee rate decreases. We might want instead to change this such that we give an initial grace period with smaller fees, which later grows, and later on the discount kicks in again. We might also want to start with some specific amount of fee rate at $x=0$, and end with some specific amount at $x=x_{\rm max}$.
A more general type of curve we might want to implement will then look something like the following:

If we want to have control over these five variables defined in the plot, we will need some function $R(x)$ with enough parameters to control.
### Beta and four parameter Beta Distribution
A type of function that satisfies our requirements can be borrowed from the statistics literature. The Beta distribution, for instance is specified by a function with support $[0,1]$, with two parameters $\alpha,\beta$, which control the shape of the curve (can be used to specify a location of the maximum, and variance, for instance).
More useful for us is the four parameter generalization of the beta distribution, which introduces parameters $a,c$, which essentially extend the support from $[0,1]$, to $[a,c]$. These parameters for instance would be useful to control the initial discount and the under constraint. The Max fee rate, for instance can be controlled by multiplying the whole distribution by some specific factor.
We therefore propose the following function, inspired by the four parameter beta distribution:
$$R^\prime(x)=F-n\frac{(x-a)^{\alpha-1}(c-x)^{\beta-1}}{B(\alpha,\beta)(c-a)^{\alpha+\beta-1}}$$
with 5 tunable parameters, $n\,a,\,c,\,\alpha,\,\beta$, and where $B(\alpha,\beta)$ is the Beta function.
We now have 5 parameters, and 5 variables we want to fix(defined in the plot). We can thus fix our parameters by solving the following 5 equation system.
1) Fix location of Max fee rate (which we will call $x^*$): This is given by computing the mode of this distribution,
$$x^*\equiv{\rm Loc.\,\, of\,\, max\,\, fee\,\, rate}=a+\frac{\alpha}{\alpha+\beta}(c-a),$$
with constraints,
$$\alpha>1,\,\,\,,\beta>1.$$
2) Fix the variance/shape:
$${\rm Variance}=\frac{\alpha\beta(c-a)^2}{(\alpha+\beta)^2(\alpha+\beta+1)}.$$
Note that alternatively we could choose to fix the Skewness or Kurtosis, for instance, which also have closed form expressions, instead of the variance. To control the Skewness, we use,
$${\rm Skewness}=2\frac{\beta-\alpha}{\alpha+\beta+2}\sqrt{\frac{\alpha+\beta+1}{\alpha\beta}}$$
3) Fix initial discount: Given by fixing the value of $R^\prime(0)$:
$$F-R^\prime(0)=n\frac{(-a)^{\alpha-1}c^{\beta-1}}{B(\alpha,\beta)(c-a)^{\alpha+\beta-1}},$$
with constraint,
$$a\le 0.$$
4) Fix the under constraint: Done by fixing the value of $R^\prime(x_{\rm max})$,
$$F-R^\prime(x_{\rm max})=n\frac{(x_{\rm max}-a)^{\alpha-1}(c-x_{\rm max})^{\beta-1}}{B(\alpha,\beta)(c-a)^{\alpha+\beta-1}},$$
with constraint,
$$c\ge x_{\rm max}.$$
5) Fix the max fee rate (or the value of $F-R^\prime(x^*)$):
$$F-R^\prime(x^*)=n\frac{(x^*-a)^{\alpha-1}(c-x^*)^{\beta-1}}{B(\alpha,\beta)(c-a)^{\alpha+\beta-1}}.$$
Solving this set of equation completely fixes all paremeters of the curve.
Once we know these parameters, the amount of Reward a miner who fixes their fault in time $x$ will get is then
$$Reward(x)=\int_0^x-F+R^\prime(x^\prime)dx^\prime$$
$$=-\frac{n}{B(\alpha,\beta)(c-a)^{\alpha+\beta-1}}\int_0^x(x^\prime-a)^{\alpha-1}(c-x^\prime)^{\beta-1}dx^\prime.$$
### Ohter options:
While the conditions above can be used to specify the curve we want, it requires solving a set of 5 nonlinear equations, which may not be such a simple numerical task. There are a few other curve options we can try that could reduce this computational burden.
### Polynomial
We could could choose a curve of the form
$$R^\prime(x)=c+a x^\alpha+bx^\beta,$$
with $\alpha,\beta>0$. If we want the curve to have the general form that it starts at a certain value, then dips to a minimum, and then rises again, then we need
$$\alpha<\beta,\,\,\,a<0,\,\,\,\,b>0.$$
We then have free (with constraints above) parameters $c,a,b,\alpha,\beta$ which we can use to fix the values we want.
1) Fix the initial discount:
$$F-R^\prime(0) = F-c,$$
So that parameter is fix, and will not contribute to the computational complexity of the problem. New we only have four parameters, $a,b,\alpha,\beta$ to fix.
2) Fix the location, $x^*$ of the minimum:
$$R^{\prime\prime}(x)\vert_{x^*}=0$$
$$\Rightarrow x^*=\left(-\frac{a\alpha}{b\beta}\right)^{\frac{1}{\beta-\alpha}}$$
3) Fix the under constraint:
$$F-R^\prime(x_{\rm max})=F-c-ax_{\rm max}^\alpha-bx_{\rm max}^\beta$$
4) Fix the max fee rate:
$$F-R^\prime(x^*)=F-c-a\left(-\frac{a\alpha}{b\beta}\right)^{\frac{\alpha}{\beta-\alpha}}-b\left(-\frac{a\alpha}{b\beta}\right)^{\frac{\beta}{\beta-\alpha}}$$
5) Finally, as we've seen in previous sections, we can use the higher exponent $\beta$, as a shape parameter for the curve. So this is something we can tune as we want.
We therefore only have to fix three parameters, $a,b,\alpha$, using the three equations above, which is a simpler problem than the previous proposal. The equations are also simpler, without special functions like the Beta function. Also, the polinomial expression is easier to integrate, if we want to compute the total reward up to time $x$,
$$Reward(x)=\int_0^{x}-F+R^\prime(x^\prime)dx^\prime=-Fx+cx+\frac{a}{\alpha+1}x^{\alpha+1}+\frac{b}{\beta+1}x^{\beta+1},$$
Which is a simple algebraic expression, once all parameters are fixed.
Below we show an example of a reward rate curve produced with this polynomial expession.

Polynomial with $c=0.8F,\,\beta=0.5, \,a=-327.092, \,b= 327.158, \, \alpha=0.497$.
### Multi step function
Another approach which is relatively easy to implement is to model the reward curve as a multi step function.
We could model a simple smooth *single step* function as
$$f(x)=a+b\tanh(m(x-l))$$
where as pictured below,

pictured here with $a=0.2,b=0.6, m=15, l=0.4$. This function steps from the value $a-b$ at $x\to-\infty$, to $a+b$ at $x\to\infty$. The step is centered around the point $x=l$. The parameter $m$ controls the sharpness of the step. We can also model an *antistep* as
$$f_{\rm anti}(x)=a+b\tanh(-m(x-l))$$
which steps from $a+b$ to $a-b$ at $x=l$.
We could then model a reward curve as a anti-step+step curve:
$$R^\prime(x)=a+b\tanh(-m_1(x-l_1))+c\tanh(m_2(x-l_2))$$
With $0<l_1<l_2<x_{\rm max}$. This is pictured below.
If $m_1$ and $m_2$ are high enough, so that the steps are sharp enough, then we sart with an initial discount,
$$F-R^\prime(0)\approx F-a-b+c.$$
The under constraint is,
$$F-R^\prime(x_{\rm max})\approx F-a+b-c.$$
Finally, the Max fee rate is given by
$${\rm Max\,\, fee\,\, rate}\approx F-a-b-c,$$
Which stays approximately at that constant rate in the region $x\in(l_1,l_2)$
These are simple linear equations that determine the values of $a,b,c$, and then we can tune the locations $l$ and sharpness $m$ by hand, so this is a much simpler problem than the beta distribution version.
Here we plot an example with $a=0.9F,\, b=0.4F, \,c=0.45F,$ $l_1=0.1x_{\rm max},\, l_2=0.6x_{\rm max},\,m_1=30,\,m_2=10$,

We could of course add as many steps as we want:
$$R^\prime(x)=a+\sum_i^{N_{\rm steps}}b_i\tanh( m_i(x- l_i))$$
Where all the parameters $a,\{b_i\}$, are fixed by a set of $N_{\rm steps}$ *linear* equations, and $m_i>0$ for a step, $m_i<0$ for an anti step.
The total reward upt to time $x$ has a closed form expression too, given by
$$Reward(x)=Fx-ax-\sum_{i}^{N_{\rm steps}}b_i\frac{\ln(\cosh( m_i(x- l_i)))-\ln(\cosh(m_il_i))}{m_i}$$
## Auto-Adjusting increasing reward
Despite satisfying the proper constraints, the curves presented above are not necessarily completely fair, since slow-repairing miners are rewarded with lower fee rates for late times. We could argue that efficient fast miners should receive the best rates.
Furthermore, if a large set of miners starts recovering much slower, those miners that are still quick to repari their fault should be rewarded with a lower fee.
We therefore propose a self-adjusting increasing curve defined as follows.
Suppose we have data available on the distribution of observed miner repari times $x$. Under normal times, this is assumed to follow an exponential distribution with parameter $\lambda_1$.
When there is some network-wide shock, it is expected that a significan number of miners will become slower, and follow a different exponential distribution with parameter $\lambda_2$.
We could take the current observed data on $x$ and fit it with an exponential mixture distribution, such that it follows:
$$f(x)=w_1\lambda_1e^{-\lambda_1 x}+w_1\lambda_2e^{-\lambda_2x}$$
Where the parameters $\lambda_1,\lambda_2$ and weights $w_1,w_2$ can be learned from the data.
In principle the mixture could have more than two components, so one could also try to estimate the number of components from the data (appropriately penalizing overfitting somehow). For now we will stick with two components.
We propose a reward rate curve of the form
$$R^\prime(x)=F-\mathcal{N}\int_0^xf(x^\prime)dx^\prime$$
$$=F-\mathcal{N}w_1(1-e^{-\lambda_1x})-\mathcal{N}w_2(1-e^{-\lambda_2x}),$$
where $\mathcal{N}$ is a normalziation constant we can use to balance the fee.
The reward function is then given by
$$Reward(x)=\int_0^x -F+R^\prime(x^\prime)dx^\prime$$
$$=-\mathcal{N}\left[-\left(\frac{w_1}{\lambda_1}+\frac{w_2}{\lambda_2}\right)+x+\frac{w_1}{\lambda_1}e^{-\lambda_1x}+\frac{w_2}{\lambda_2}e^{-\lambda_1x}\right]$$
We could use the normalization constant to ensure that the expected reward will stay constant,
$$E[Reward(x)]=\int_0^\infty Reward(x)f(x)dx$$
$$=\mathcal{N}\left[\frac{w_1^2}{2\lambda_1}+\frac{w_2^2}{2\lambda_2}+\frac{w_1w_2}{(\lambda_1+\lambda_2)}\left(\frac{\lambda_2}{\lambda_1}+\frac{\lambda_1}{\lambda_2}\right)\right].$$
We can therefore choose $\mathcal{N}$ such that
$$\mathcal{N}=\frac{C}{\frac{w_1^2}{2\lambda_1}+\frac{w_2^2}{2\lambda_2}+\frac{w_1w_2}{(\lambda_1+\lambda_2)}\left(\frac{\lambda_2}{\lambda_1}+\frac{\lambda_1}{\lambda_2}\right)},$$
Where $C$ is the value we can fixed for the average reward (fee) that a miner will pay. Keeping this quantity fixed means:
* If a shock causes a large set of miners to become slow, the average fee paid by miners will stay the same, and not increase.
* The miners that remain fast and efficient will be rewarded with lower rates. The larger the proportion of slow miners, and the slower they are, the more the fast miners will be rewarded.
* miners that are even faster than the average fast miner will be even further rewarded, since the fee rate starts at zero, and reaches a first plateau around $1/\lambda_1$.
#### Example plots

An exponential mixture, with $\lambda_1=6$, $\lambda_2=2$, $w_1=0.2$, $w_2=0.8$

Reward rate for $\lambda_1=6$, $\lambda_2=2$, $w_1=0.2$, $w_2=0.8$, and $\mathcal{N}=1$, $F=1$.

TTT
## Simplified version or auto-adjusting rate
We can strip down the complexity previous plan, and keep only the self-adjusting aspect, which sill gives a reasonable solution to system shocks.
We then propose a rate curve with the same shape as we currently have: a constant rate, $-\mathcal{N}$ for $x\in(0,x_{\rm max})$, and a single termination fee $\mathcal{N}T$, which comes at $x=x_{\rm max}$ The only difference will be that the parameter $\mathcal{N}$ wil be adjusted based on current data, to keep the expected reward constant, even if a group of miners becomes slower.
We can write the Rate function explicitly as
$$Rate(x)=\mathcal{N }\left[H(x-x_{\rm max})-1-T\delta(x-_{\rm max})\right]$$
where $H(x)$ is a Heavyside step function (https://en.wikipedia.org/wiki/Heaviside_step_function), and $\delta(x)$ is a Dirac delta function (https://en.wikipedia.org/wiki/Dirac_delta_function)
We can integrate this to obtain the total Reward function,
$$Reward(x)=\mathcal{N}\left[x\left(H(x-x_{\rm max})-1\right)-TH(x-x_{\rm max})\right]$$
We now assume the miner repair time, $x$ follows a *single* exponential distribution,
$$f(x)=\lambda e^{-\lambda x}.$$
where the $\lambda$ can be estimated from the set of observed repair times as $\lambda_{MLE}=1/\bar{x}_{\rm observed}$ (where $\lambda_{\rm MLE}$ is the maximum likelihood estimator).
Here we are simplifying the problem by grouping together all miners. This still would capture shock behavior, in the sense that if a significant number of miners become slower, this would pull $\lambda$ to a lower value.
Once $\lambda$ is fitted from the data, we can estimate the expected reward as
$$E[Reward]=\int_0^\infty Reward(x)f(x)dx$$
$$=\mathcal{N}\left[-\frac{1}{\lambda}+\int_{x_{\rm max}}^\infty x\lambda e^{-\lambda x}dx-T\int_{x_{\rm max}}^\infty \lambda e^{-\lambda x}dx\right]$$
$$=\mathcal{N}\left\{\frac{1}{\lambda}\left[(\lambda x_{\rm max}+1)e^{-\lambda x_{\rm max}}-1\right]-Te^{-\lambda x_{\rm max}}\right\}.$$
We can then choose the constant $\mathcal{N}$ such that the expected reward is fixed at a chosen value $C$,
$$\mathcal{N}=\frac{C}{\frac{1}{\lambda}\left[(\lambda x_{\rm max}+1)e^{-\lambda x_{\rm max}}-1\right]-Te^{-\lambda x_{\rm max}}}.$$
This approach automatically adapts to a shock in the system, reducing the fee rate accordingly if a group of miners becomes slow.
We note that here we have two parameters we need to control: the target expected reward $C$, and the proportion of that reward that will come from the termination fee, which is controlled by $T$.
This model only requires information on the mean $\bar{x}$ for the current period.
## Another approach with governance surface
Given the governance surface
$$C=\mathcal{N}\left\{\frac{1}{\lambda}\left[(\lambda x_{\rm max}+1)e^{-\lambda x_{\rm max}}-1\right]-Te^{-\lambda x_{\rm max}}\right\}$$
We may try to accomplish as many goals as possible. Here we present one strategy that accomplishes the following :
1) We use $\mathcal{N}T=\mathcal{T}$ as a fixed input, since the termination fee should be independent of the fault mechanism (since miners should also have the choice to terminate even without going in to fault, so fee should be determined from that). We also point out that the this termination fee depends on how long the miner has been operating.
2) The termination time $x_{\rm max}$ should be optimized such that it is the most reasonable time. From Jamsheed's work we see this is done by choosing
$$x_{\rm max}=T=\mathcal{T}/\mathcal{N}$$
The public likes $x_{\rm max}=6weeks$. In this approach $x_{\rm max}$ will be variable, but we can aim for having 6 weeks when there are "normal" conditions.
3) We would like the expected reward, $C$ to be independent of $\lambda$, and the reward rate to be roughly proportional to $\mathcal{N}=a\lambda$ as an insuirance mechanism
4) It would be good if these fees $a$ and $C$ could be chosen in some optimal fair way.
From applying 1) and 2), we now have the surface
$$C=\frac{\mathcal{N}}{\lambda}\left[\left(\lambda\frac{\mathcal{T}}{\mathcal{N}}+1\right)e^{-\frac{\lambda\mathcal{T}}{\mathcal{N}}}-1\right]-\mathcal{T}e^{-\frac{\lambda\mathcal{T}}{\mathcal{N}}}$$
We now see that condition 3) can be accomplished choosing $\mathcal{N}=a\lambda$, with
$$C=a\left[\left(\frac{\mathcal{T}}{a}+1\right)e^{-\frac{\mathcal{T}}{a}}-1\right]-\mathcal{T}e^{-\frac{\mathcal{T}}{a}}$$
We can use 2) to fix $a$ by enforcing that for some "normal" repair rate $\bar\lambda$, and for a maximum termination fee $\mathcal{T}_{\rm max}$ (corresponding to miners that have operated more than 90 days), then
$$6weeks=\frac{\mathcal{T}_{\rm max}}{a\bar\lambda}\Rightarrow a=\frac{\mathcal{T}_{\rm max}}{\bar\lambda*6weeks}$$
This fixes what is the optimal fault fee rate.
We could conversely also use this last equation to fix the termination fee. Say we are happy with our current rate $\mathcal{N}_{\rm current}$, we can make that the standard for normal times
$$a_{\rm current}=\frac{\mathcal{N}_{\rm current}}{\bar\lambda}$$
and then we coud fix the termination fee by choosing
$$\mathcal{T}_{\rm max}=6weeks*\bar\lambda a_{\rm current}$$