Skip to content

Commit 9237c34

Browse files
committed
Start writing model with boundeddrift
1 parent 8bbb86a commit 9237c34

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

tests/difference/core/quint_model/ccv.qnt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,10 @@ module ccv {
399399
res._1
400400
)
401401

402+
// check whether the local client for the provider has expired on any consumer
402403
val expiredConsumers = getRunningConsumers(providerStateAfterTimeAdvancement).filter(
403404
consumer =>
404-
providerStateAfterTimeAdvancement.chainState.runningTimestamp > tmpState.consumerStates.get(consumer).chainState.lastTimestamp + TrustingPeriodPerChain.get("provider")
405+
providerStateAfterTimeAdvancement.chainState.lastTimestamp > tmpState.consumerStates.get(consumer).chainState.runningTimestamp + TrustingPeriodPerChain.get(consumer)
405406
).exclude(timedOutConsumers)
406407

407408
// send vsc packets
@@ -507,9 +508,9 @@ module ccv {
507508
}
508509
)
509510
)
510-
// checks whether the local client for the provider chain has expired on the consumer
511+
// checks whether the local client for the consumer has expired on the provider
511512
val clientExpired =
512-
if (newChainState.runningTimestamp > currentState.providerState.chainState.lastTimestamp + TrustingPeriodPerChain.get(chain)) {
513+
if (newChainState.lastTimestamp > currentState.providerState.chainState.runningTimestamp + TrustingPeriodPerChain.get(chain)) {
513514
true
514515
} else {
515516
false
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}

tests/difference/core/quint_model/ccv_model.qnt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ module ccv_model {
170170
}
171171

172172
// step_common is the core functionality of steps that does not have anything to do with time.
173-
// Thus, it is part of both step and stepBoundedDrift.
174173
action step_common = any {
175174
nondet node = oneOf(nodes)
176175
// very restricted set of voting powers. exact values are not important,

tests/difference/core/quint_model/ccv_happy.qnt renamed to tests/difference/core/quint_model/ccv_sync.qnt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
module ccv_happy {
1+
module ccv_sync {
22
import ccv_model.* from "ccv_model"
33
import ccv_types as ccvt from "ccv"
44
import ccv from "ccv"
55
import Time.* from "./libraries/Time"
66
import extraSpells.* from "./libraries/extraSpells"
77

88

9-
// The happy path module has its own init and step functions.
9+
// The sync module has its own init and step functions.
1010
// They ensure that chains do not drift from each other in terms of time,
1111
// and all chains produce blocks synchronously.
1212
// To do so, it makes use of
@@ -15,7 +15,7 @@ module ccv_happy {
1515

1616
// QueuedEndBlocks contains a list of chains which will end their blocks next,
1717
// together with the time advancement they should advance by.
18-
// When stepHappyPath selects an action, it checks if there are any chains in this list,
18+
// When stepHappy selects an action, it checks if there are any chains in this list,
1919
// and if so, it will only select actions that end blocks on the head of the list.
2020
// QueuedEndBlocks is thus used to schedule actions.
2121
var QueuedEndBlocks: List[(ccvt::Chain, Time)]

0 commit comments

Comments
 (0)