Skip to content

Commit dc803b9

Browse files
committed
w.i.p
1 parent 920678d commit dc803b9

File tree

14 files changed

+152
-111
lines changed

14 files changed

+152
-111
lines changed

docs/everything.juvix.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import node_architecture.types.identities;
2020
import node_architecture.types.messages;
2121
import node_architecture.types.engine_environment;
2222
import node_architecture.types.engine_dynamics;
23-
import node_architecture.types.engine_family;
23+
import node_architecture.types.engine;
2424
import node_architecture.types.anoma_environment;
2525
import node_architecture.types.anoma_message;
2626
import node_architecture.types;

docs/node_architecture/engines.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,5 @@ This establishes a total order of transactions for the [execution engine](./engi
9090
Proofs from the execution engine allow light clients to read the current state.
9191
When the execution engine has processed a transaction, it communicates to the [mempool](./engines/mempool.md#mempool) that the transaction can data can be garbage-collected from storage.
9292
[Read more here.](./engines/execution.md#execution)
93+
94+
Each engine implements a specific `EngineBehaviour` that defines its core dynamics and operational characteristics. The behaviour determines how the engine processes inputs, manages state, and interacts with other components.

docs/node_architecture/engines/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ engine instances will have. For Anoma specifications, the components are:
5353

5454
For the Anoma Specification, engine families are written in Juvix Markdown. All
5555
necessary types and functions to define these engines can be found in the module
56-
[[Engine Family Types|engine_family]].
56+
[[Engine Behaviour Types|engine_family]].
5757
See [[Engines in Anoma|Tutorials on Writing Engine Families]] for a tutorial on
5858
how to structure the writing of engine families in Juvix.
5959

@@ -73,4 +73,4 @@ families.
7373
## Useful Links
7474

7575
- [[Engines in Anoma|Tutorials on Writing Engine Families]]
76-
- [[Ticker Engine Overview|Example Engine Family]]
76+
- [[Ticker Engine Overview|Example Engine Behaviour]]

docs/node_architecture/engines/template.juvix.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ tags:
1515
import node_architecture.engines.template_overview open public;
1616
import node_architecture.engines.template_environment open public;
1717
import node_architecture.engines.template_dynamics open public;
18-
import node_architecture.types.engine_family as Anoma;
18+
import node_architecture.types.engine_behaviour as Anoma;
1919
```
2020

2121
# `Template` engine family type
2222

2323
<!-- --8<-- [start:template-engine-family] -->
2424
```juvix
25-
TemplateEngineFamily :
26-
Anoma.EngineFamily
25+
TemplateEngineBehaviour :
26+
Anoma.EngineBehaviour
2727
TemplateLocalState
2828
TemplateMailboxState
2929
TemplateTimerHandle
3030
TemplateMatchableArgument
3131
TemplateActionLabel
3232
TemplatePrecomputation
33-
:= Anoma.mkEngineFamily@{
33+
:= Anoma.mkEngineBehaviour@{
3434
guards := [messageOneGuard];
3535
action := templateAction;
3636
conflictSolver := templateConflictSolver;

docs/node_architecture/engines/template_overview.juvix.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tags:
1616
import prelude open;
1717
```
1818

19-
# `Template` Engine Family Overview
19+
# `Template` Engine Behaviour Overview
2020

2121
--8<-- "./docs/node_architecture/engines/template.juvix.md:template-engine-family"
2222

docs/node_architecture/engines/ticker.juvix.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,53 @@ tags:
1212
```juvix
1313
module node_architecture.engines.ticker;
1414
import prelude open;
15-
import node_architecture.types.engine_family as Anoma;
15+
import node_architecture.types.engine_behaviour as E;
1616

1717
import node_architecture.engines.ticker_overview open public;
1818
import node_architecture.engines.ticker_environment open public;
1919
import node_architecture.engines.ticker_dynamics open public;
2020
```
2121

22-
# Ticker engine family type
22+
# Ticker engine behaviour
2323

24-
<!-- --8<-- [start:ticker-engine-family] -->
24+
<!-- --8<-- [start:ticker-engine-behaviour] -->
2525
```juvix
26-
TickerEngineFamily :
27-
Anoma.EngineFamily
26+
TickerEngineBehaviour :
27+
E.EngineBehaviour
2828
TickerLocalState
2929
TickerMailboxState
3030
TickerTimerHandle
3131
TickerMatchableArgument
3232
TickerActionLabel
3333
TickerPrecomputation
34-
:= Anoma.mkEngineFamily@{
34+
:= E.mkEngineBehaviour@{
3535
guards := [incrementGuard ; countGuard];
3636
action := tickerAction;
3737
conflictSolver := tickerConflictSolver;
3838
}
3939
;
4040
```
41-
<!-- --8<-- [end:ticker-engine-family] -->
41+
<!-- --8<-- [end:ticker-engine-behaviour] -->
4242

4343

44+
```juvix
45+
TickerEngine :
46+
E.Engine TickerLocalState
47+
TickerMailboxState
48+
TickerTimerHandle
49+
TickerMatchableArgument
50+
TickerActionLabel
51+
TickerPrecomputation
52+
:= E.mkEngine@{
53+
name := "ticker";
54+
behaviour := TickerEngineBehaviour;
55+
initEnv := E.mkEngineEnvironment@{
56+
name := "ticker";
57+
localState := Unit;
58+
mailboxCluster := Map.empty;
59+
acquaintances := Set.empty;
60+
timers := [];
61+
};
62+
};
63+
64+
```

docs/node_architecture/engines/ticker_dynamics.juvix.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,6 @@ tickerAction (input : TickerActionInput) : TickerActionEffect
290290
tickerConflictSolver : Set TickerMatchableArgument -> List (Set TickerMatchableArgument) := \{ _ := [] }
291291
```
292292

293-
## `Ticker` Engine Family Summary
293+
## `Ticker` Engine Behaviour Summary
294294

295295
--8<-- "./docs/node_architecture/engines/ticker.juvix.md:ticker-engine-family"

docs/node_architecture/engines/ticker_overview.juvix.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ tags:
1515
module node_architecture.engines.ticker_overview;
1616
```
1717

18-
# `Ticker` Engine Family Overview
18+
# `Ticker` Engine Behaviour Overview
1919

2020
--8<-- "./docs/node_architecture/engines/ticker.juvix.md:ticker-engine-family"
2121

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
icon: octicons/project-template-24
3+
search:
4+
exclude: false
5+
tags:
6+
- engine-behaviour
7+
- engine-type
8+
- juvix
9+
---
10+
11+
??? quote "Juvix imports"
12+
13+
```juvix
14+
module node_architecture.types.engine;
15+
import prelude open;
16+
import node_architecture.types.identities open;
17+
import node_architecture.types.engine_environment open public;
18+
import node_architecture.types.engine_dynamics open public;
19+
```
20+
21+
# Engine
22+
23+
An **engine** is a computational unit with a specific name and behaviour, plus its
24+
own execution context called the engine environment, which comprises the
25+
specific state, the mailbox cluster, the acquaintances, and the timers. An
26+
engine instance is of type `Engine` instantiated with the types for the local
27+
states, the mailboxes' state, the time handles, the action-label action, and the
28+
precomputation. We use the following conventions:
29+
30+
- to the type for the local states as `S`,
31+
- for the mailboxes' state as `M`,
32+
- for the time handles as `H`,
33+
- for the action-label as `A`,
34+
- for the precomputation as `L`, and
35+
- for the external inputs as `X`.
36+
37+
To define the type for engine instances, we first need to define the type for
38+
engine behaviours.
39+
40+
## Engine behaviour type
41+
42+
The `EngineBehaviour` type encapsulates the concept of behaviours within Anoma. As
43+
defined, it clears up that engines are essentially a collection of guarded
44+
state-transition functions.
45+
46+
```juvix
47+
type EngineBehaviour (S M H A L X : Type) := mkEngineBehaviour {
48+
guards : List (Guard S M H A L X);
49+
action : ActionFunction S M H A L X;
50+
conflictSolver : Set A -> List (Set A);
51+
};
52+
```
53+
54+
!!! info "On the use of `List` for guards in `EngineBehaviour`"
55+
56+
The `EngineBehaviour` type uses `List` for guards to enable parallel
57+
processing. This choice acknowledges that guards can be concurrent or
58+
competing, with the latter requiring priority assignment to resolve
59+
non-determinism. While guards should form a set, using `List` simplifies the
60+
implementation and provides an inherent ordering.
61+
62+
## Engine instance type
63+
64+
An *engine* is a term of type `Engine` instantiated with the types for the local
65+
states, the mailboxes' state, the time handles, the action-label action, and the
66+
precomputation. Each engine, not its type, is associated with:
67+
68+
- a specific name (unique across the system),
69+
- a specific behaviour, and
70+
- a declaration of its own execution context, that is, the specific state, the
71+
mailbox cluster, the acquaintances, and the timers.
72+
73+
```juvix
74+
type Engine (S M H A L X : Type) := mkEngine {
75+
name : EngineName;
76+
family : EngineBehaviour S M H A L X;
77+
initEnv : EngineEnvironment S M H;
78+
};
79+
```
80+
81+
!!! example "Voting Engine"
82+
83+
As an example, we could define an engine type for a voting system:
84+
85+
- `S` could be a record with fields like `votes`, `voters`, and `results`.
86+
- The engine-specific message type might be a coproduct of `Vote` and `Result`.
87+
- The behaviour of this engine may include guarded actions like:
88+
- `storeVote` to store a vote in the local state,
89+
- `computeResult` to compute the result of the election, and
90+
- `announceResult` to send the result to some other engine instances.
91+
92+
With each different election or kind of voters, we obtain a new engine instance,
93+
while the underlining voting system, the voting engine family, remains the same.
94+
95+
!!! note
96+
97+
Both the `EngineBehaviour` and `Engine` types are parameterised by several types. When
98+
not used in the context of a new engine family declaration, these types can be
99+
replaced by the unit type `Unit`.

docs/node_architecture/types/engine_environment.juvix.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ icon: octicons/project-template-24
33
search:
44
exclude: false
55
tags:
6-
- Engine-Family
7-
- Engine-Instances
8-
- Juvix
6+
- engine-environment
7+
- engine-instances
8+
- juvix
99
---
1010

1111
??? quote "Juvix imports"
@@ -18,13 +18,13 @@ tags:
1818
import node_architecture.types.anoma_message as Anoma;
1919
```
2020

21-
# Engine family environment type
21+
# Engine behaviour environment type
2222

23-
The engine family environment encompasses static information for engine
23+
The engine behaviour environment encompasses static information for engine
2424
instances in the following categories:
2525

2626
- A global reference, `name`, for the engine instance.
27-
- Local state whose type is specific to the engine family.
27+
- Local state whose type is specific to the engine behaviour.
2828
- Mailbox cluster, which is a map of mailbox IDs to mailboxes.
2929
- A set of names of acquainted engine instances. It is implicit that the engine
3030
instance is acquainted with itself, so there is no need to include its own
@@ -44,7 +44,7 @@ types.
4444
```juvix
4545
type EngineEnvironment (S M H : Type) :=
4646
mkEngineEnvironment {
47-
name : EngineName ; -- read-only
47+
name : EngineName ; -- read-only and for internal use only
4848
localState : S;
4949
mailboxCluster : Map MailboxID (Mailbox M);
5050
acquaintances : Set EngineName;

0 commit comments

Comments
 (0)