Skip to content

Commit

Permalink
feat(docs): initial gateway docs (#214)
Browse files Browse the repository at this point in the history
* docs(skeleton for gateway follower): initial napkin sketches

* docs(skeleton for gateway follower): initial napkin sketches

* docs(skeleton for gateway follower): initial napkin sketches

* docs(skeleton for gateway follower): initial napkin sketches

* docs(skeleton for gateway follower): initial napkin sketches

* docs(skeleton for gateway follower): initial napkin sketches

* docs(skeleton for gateway follower): initial napkin sketches

* docs(skeleton for gateway follower): initial napkin sketches

* docs(skeleton for gateway follower): initial napkin sketches

* docs(skeleton for gateway follower): initial napkin sketches

* docs(skeleton for gateway follower): initial napkin sketches

* docs(skeleton for gateway follower): initial napkin sketches

* docs(skeleton for gateway follower): initial napkin sketches

* docs(skeleton for gateway follower): initial napkin sketches

* docs(skeleton for gateway follower): initial napkin sketches

* docs(skeleton for gateway follower): initial napkin sketches

* docs(skeleton for gateway follower): initial napkin sketches

* docs(skeleton for gateway follower): initial napkin sketches

* docs(skeleton for gateway follower): initial napkin sketches

* docs(skeleton for gateway follower): initial napkin sketches

* ci lints

* ci lints

* ci lint

* ci lints

* ci lints

* ci lints

* ci lints

* ci lints
  • Loading branch information
cong-or authored Jan 23, 2024
1 parent 6181d21 commit ed887e3
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/src/architecture/.pages
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ nav:
- 10_quality_requirements.md
- 11_technical_risks.md
- 12_glossary.md

126 changes: 126 additions & 0 deletions docs/src/architecture/08_concepts/gateway/concrete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
icon: material/hub
---

# Pseudo code

Building blocks in the form of *pseudo code*;
Intended to make the conceptual design more concrete; not setting rules.

## Node

Restart node with new config

```rust
fn restart_node(config: Config) -> Result<(), Err>{
// graceful restart
}
```

## Config

Check if config exists; all orchestration is coordinated via the DB, more specifically the config.

```rust
fn config_exists(db: DBHandler) -> Option<Config> {
// lock db
// if config exists { Some(config) }
// else { None }
// Resource acquisition is initialization: drop trait -> unlock db
}
```

Node polls for config until it exists in database

```rust
fn poll_config(db: DBHandler) -> Option<Config> {
loop {
if let Some(r) = config_exists(db) {
return Some(r)
}
}
}
```

Check if config has been updated

```rust
fn config_updated(db: DBHandler) -> Option<Config> {
// lock db
// if config updated { Some(config) }
// else { None }
// Resource acquisition is initialization: drop trait -> unlock db
}
```

## Updates

Continually race to update database

```rust
fn index_follower_data(db: DBHandler, stream: FollowerIo)-> Result<(), Err> {
loop {
if database_ready_to_update(db) {
update_database(db, stream)
}
}
}
```

Check most recent update on cardano update table
If it falls within the threshold boundary, node should update db with latest data

```rust
fn database_ready_to_update(db: DBHandler) -> bool {
// lock db
// let last_updated = CardanoUpdateTable()
// return update_threshold(last_updated)
// Resource acquisition is initialization: drop trait -> unlock db
}
```

Update database with follower data

```rust
fn update_database(db: DBHandler, stream: FollowerIo) -> Result<(), Err> {
// lock db
while let Some(block) = stream.next().await {
let metadata = parse(block);
db.insert(metadata);
}
// Resource acquisition is initialization: drop trait -> unlock db
}
```

Parse block

```rust
fn parse(block: Block) -> Result<MetaBlock, Err> {
// extract era, unspent transaction output, spent Transactions and registration metadata
}
```

Calculate if threshold conditional has been met

```rust
fn update_threshold(last_updated: ThresholdMetric) -> bool {
// threshold calculation
// define conditional
}
```

## Follower

* Start follower with specified networks

* Stream blocks from given (slot,epoch)

## Syncing

Nodes race to update

## Contention

## Multiple nodes

## Roll backs
71 changes: 71 additions & 0 deletions docs/src/architecture/08_concepts/gateway/mechanics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
icon: material/airplane-cog
---

# Initial blueprint

```mermaid
stateDiagram-v2
state if_state <<choice>>
Node -->if_state
if_state --> node : config exists
if_state --> Node: config does not exist
note right of node
Indexing blockchain data provided by follower
end note
note left of node
checkConfig = thread A
end note
note right of node
checkDB = thread B
end note
note right of Node
Orchestration is coordinated via the config
end note
state Node {
init --> init: try until config exists
}
state Follower {
[*]
}
state node {
checkConfig-->Database: release
Database-->checkConfig: wait
checkDB-->Database: release
Database-->checkDB: wait
State checkConfig{
Tick --> Updated
Tick --> NoChange:
Updated --> Restart: stop all followers cleanly
Restart --> Tick: Restart with new config
NoChange--> Tick
}
State checkDB{
tick --> UpdateThreshold
UpdateThreshold --> tick: data is fresh
UpdateThreshold--> Follower: data is stale
updateDB --> tick
updateDB-->Follower
Follower -->updateDB
}
state Database{
Unlocked --> Locked
Locked--> Unlocked
}
}
```

:construction: Design is still active and not final :construction:

0 comments on commit ed887e3

Please sign in to comment.