IntersectMBO / IntersectMBO/ouroboros-network
Refine ExitPolicy
- Dominant language
- Haskell
- Stars
- 296
- Forks
- 104
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 4
Description
Currently [`ExitPolicy`] only takes into account return value but doesn't take
into account exception type nor type of a peer. For local root peers it should
be less forgiving, than for other types of peers. Also different exception
types should be treated differently.
Note: it is easy to give an [`ExitPolicy`] access to `SomeException`, but this is
not enough as we need to clasify exceptions. In the non-p2p case we have an
[`ErrorPolicy`] which governs how each exception is treated, but it might be
difficult to use it since it expects an error type not `SomeException`. However
something similar to what [`catches`] does should work, e.g.
```hs
data ExceptionPolicy = forall e. Exception e => ExceptionPolicy (e -> ReconnectDelay)
type ExceptionPolicies = [ExceptionPolicy]
runExceptionPolicies :: ReconnectDelay -- ^ default delay
-> [ExceptionPolicy]
-> SomeException
-> ReconnectDelay
runExceptionPolicies d eps err = foldr fn d eps
where
fn (ExceptionPolicy p) d | Just e <- fromException err = p e
| otherwise = d
```
`ErrorPolicy`-ies should be used to design specific `ExceptionPolicies`:
* [`remoteNetworkErrorPolicy`]
* [`consensusErrorPolicy`]
* [`localNetworkErrorPolicy`]
[`ExitPolicy`]: https://intersectmbo.github.io/ouroboros-network/ouroboros-network/Ouroboros-Network-ExitPolicy.html#t:ExitPolicy
[`ErrorPolicy`]: https://intersectmbo.github.io/ouroboros-network/ouroboros-network/Ouroboros-Network-NodeToNode.html#t:ErrorPolicy
[`remoteNetworkErrorPolicy`]: https://intersectmbo.github.io/ouroboros-network/ouroboros-network/Ouroboros-Network-NodeToNode.html#v:remoteNetworkErrorPolicy
[`consensusErrorPolicy`]: https://intersectmbo.github.io/ouroboros-consensus/haddocks/ouroboros-consensus-diffusion/Ouroboros-Consensus-Node-ErrorPolicy.html#v:consensusErrorPolicy
[`localNetworkErrorPolicy`]: https://intersectmbo.github.io/ouroboros-network/ouroboros-network/Ouroboros-Network-NodeToNode.html#v:localNetworkErrorPolicy
[`catches`]: https://hackage.haskell.org/package/base-4.18.0.0/docs/Control-Exception.html#v:catches
Contributor guide
Assessment
This issue has not been assessed yet.