1
+ module ccv_happy {
2
+ import ccv_model.* from "ccv_model"
3
+ import ccv_types as ccvt from "ccv"
4
+ import ccv from "ccv"
5
+ import Time.* from "./libraries/Time"
6
+ import extraSpells.* from "./libraries/extraSpells"
7
+
8
+
9
+ // The boundeddrift module has its own step function.
10
+ // They ensure that chains do not drift from each other in terms of time
11
+ // more than a given bound.
12
+ // It differs from the sync module in that it does not require
13
+ // the chains to produce blocks at the same time.
14
+
15
+ // The maximal drift that this module will allow between chains.
16
+ // In particular, it will ensure that the lastTime of any chain
17
+ // does not differ from the runningTime of any other chain by more than
18
+ // this value.
19
+ pure val maxDrift = defUnbondingPeriod - 2 * Hour
20
+
21
+ // Finds the maximal time advancement that can be done for a given chain
22
+ // without violating the maxDrift constraint.
23
+ pure def findMaxTimeAdvancement(advancingChain: ccvt::ChainState, otherChains: Set[ccvt::ChainState]): Time =
24
+ val otherChainsLastTimes = otherChains.map(c => c.lastTimestamp)
25
+ 0
26
+ // // start with advancingChain.RunningTime - if this is the minimal element, we can advance by maxDrift anyways
27
+ // val otherChainsMinLastTime = otherChainsLastTimes.fold(advancingChain.runningTimestamp, (acc, t) => if (acc < t) acc else t)
28
+ // val maxTime = advancingChain.runningTimestamp - otherChainsMinLastTime + maxDrift
29
+
30
+ // step will advance time for all chains at the same rate,
31
+ // thus the clock times are always in sync.
32
+ // This is useful to test happy paths.
33
+ action stepBoundedDrift = any {
34
+ step_common, // allow actions that do not influence time
35
+
36
+ all {
37
+ // advance a block for a consumer
38
+ all {
39
+ runningConsumers.size() > 0, // ensure there is a running consumer, otherwise this action does not make sense
40
+ nondet chain = oneOf(runningConsumers)
41
+ nondet timeAdvancement = oneOf(timeAdvancements)
42
+ EndAndBeginBlockForConsumer(chain, timeAdvancement),
43
+ },
44
+
45
+ // advance a block for the provider
46
+ val consumerStatus = currentState.providerState.consumerStatus
47
+ nondet consumersToStart = oneOf(nonConsumers.powerset())
48
+ nondet consumersToStop = oneOf(runningConsumers.powerset())
49
+ nondet timeAdvancement = oneOf(timeAdvancements)
50
+ EndAndBeginBlockForProvider(timeAdvancement, consumersToStart, consumersToStop),
51
+ }
52
+ }
53
+ }
0 commit comments