Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
62ca861
LeiosDemo202510: draft Leios mini protocols
nfrisby Oct 8, 2025
12e5667
Add the initial version of the demo script
dnadales Oct 10, 2025
7ebe7b5
Add node-0 to the path of different files
dnadales Oct 13, 2025
79d58e4
leiosdemo202510: add this demo exe
nfrisby Oct 13, 2025
97a4949
leiosdemo202510: combine via join
nfrisby Oct 13, 2025
1e71416
leiosdemo202510: suggestive check on MsgLeiosBlockTxsRequest
nfrisby Oct 13, 2025
f92cb19
Run a second Cardano node as downstream peer
dnadales Oct 14, 2025
35af3c9
leiosdemo202510: add msgLeiosBlockRequest and also stub limit on popC…
nfrisby Oct 14, 2025
f514ce0
leiosdemo202510: relocate SQL definitions near use
nfrisby Oct 14, 2025
cc15804
Scaffold leios-mvd NixOS test with leios-node
bladyjoker Oct 14, 2025
cbdd85a
Git ignore NixOS test history files and direnv
bladyjoker Oct 14, 2025
231a2a1
leiosdemo202510: avoid reversing long lists
nfrisby Oct 14, 2025
7efc564
leiosdemo202510: fallback for requests of many txs
nfrisby Oct 14, 2025
cc1e3b6
leiosdemo202510: avoid reversing lists 2
nfrisby Oct 14, 2025
ee4871b
leiosdemo202510: use map CBOR and handle MsgLeiosBlock
nfrisby Oct 14, 2025
9ad22ea
leiosdemo202510: handle MsgLeiosBlockTxs
nfrisby Oct 14, 2025
c4a9387
Implements immdb-node and Immutable DB NixOS systemd service
bladyjoker Oct 15, 2025
f78487b
Add `--address` flag to `immdb-server` executable
bladyjoker Oct 15, 2025
62db8e4
Add `address` options to `immdb-server` NixOS service
bladyjoker Oct 15, 2025
5b454c2
DNS tweaks to Leios MVD and formatting
bladyjoker Oct 15, 2025
7c25e7f
Add immutable db fixture (50 blocks)
bladyjoker Oct 15, 2025
ba949db
Configure the private testnet such that it doesn't update the system …
bladyjoker Oct 15, 2025
2cb6afa
Add README.md for Leios MVD and an actual test scenario condition
bladyjoker Oct 15, 2025
d2ab9f1
leiosdemo202510: merge ebBodies and ebClosures, use only points in CL…
nfrisby Oct 15, 2025
9e3d427
leiosdemo202510: minor refactor
nfrisby Oct 15, 2025
7036dd2
leiosdemo202510: add fetch-decision and hash-txs commands
nfrisby Oct 15, 2025
c9a6d68
leiosdemo202510: only use "point" in the table name ebPoints
nfrisby Oct 15, 2025
1c2a031
leiosdemo202510: add some of the missing Haddock
nfrisby Oct 15, 2025
41358c1
Add a script to analyze the two node log files
dnadales Oct 20, 2025
31c21cf
Hook the python script to the demo script
dnadales Oct 20, 2025
daaf2ea
Add requirements.txt for log_parser.py
dnadales Oct 20, 2025
2b7cbe9
Nixify the Leios demo environment
bladyjoker Oct 21, 2025
7bd63e1
Appliy black python formatter
bladyjoker Oct 21, 2025
a4d5b2a
Add Leios demo test data
bladyjoker Oct 21, 2025
c6d35dc
Nixify the Leios demo environment (#1724)
bladyjoker Oct 21, 2025
cbb0ae3
Add the IPython notebook for interactive analysis
bladyjoker Oct 21, 2025
0bd8498
Thread the onset of the reference slot through the immdb-server code
dnadales Oct 21, 2025
089702b
Pass a function that abstracts away slot delay calculation
dnadales Oct 21, 2025
0945ffd
Freeze the Python environment from Nix into requirements.txt
bladyjoker Oct 22, 2025
59587e8
leiosdemo202510: redo the fetch iteration logic and MsgLeiosBlockTxs …
nfrisby Oct 22, 2025
fb92641
leiosdemo202510: add the first bash script that mimics requests and r…
nfrisby Oct 22, 2025
ba40262
Implement mkGetSlotDelay
dnadales Oct 22, 2025
02dc37e
leiosdemo202510: add tx sharing to the generator
nfrisby Oct 22, 2025
1ce37c7
leiosdemo202510: fix off-by-one sterraf noticed
nfrisby Oct 22, 2025
dbd74db
Remove unnecessary venvShellHook
bladyjoker Oct 23, 2025
b543c22
Merge branch 'bladyjoker/leios-mvd-nixostests' into 1709-initial-demo…
bladyjoker Oct 23, 2025
893a4b6
Leios MVD setup with NixOS tests (#1718)
bladyjoker Oct 23, 2025
25879a4
Add new options for ImmDB NixOS service
bladyjoker Oct 23, 2025
464dfb0
leiosdemo202510: some renamings, add MkLeiosBlockRequest ctor
nfrisby Oct 23, 2025
88d080d
leiosdemo202510: some renamings, add EB body requests etc
nfrisby Oct 23, 2025
5eca7c5
leiosdemo202510: small polishing pass
nfrisby Oct 23, 2025
bdee13c
leiosdemo202510: also insert into TxCache
nfrisby Oct 23, 2025
e7e3104
leiosdemo202510: do not fetch txs already in TxCache
nfrisby Oct 23, 2025
3d5487e
leiosdemo202510: add cache-copy command
nfrisby Oct 24, 2025
ccbe693
leiosdemo202510: rename binder to nickname in myManifest.json
nfrisby Oct 24, 2025
2dafd96
Set all followert instructions to blocking
bladyjoker Oct 24, 2025
f69528b
Cosmetic changes to aid my own comprehension
bladyjoker Oct 24, 2025
f0e793f
Switch to using plotly for charting events
bladyjoker Oct 24, 2025
7b894e5
Merge remote-tracking branch 'origin/1709-initial-demo-setup' into nf…
nfrisby Oct 24, 2025
58abd61
leiosdemo202510: add mini protocol stubs to ImmDB server
nfrisby Oct 24, 2025
8ecc04b
Delay throwing ReachedImmutableTip to allow clients to fetch blocks
bladyjoker Oct 24, 2025
5976d2d
Adds journal logs from leios-node and adjust up the Python scripts
bladyjoker Oct 24, 2025
97784e7
leiosdemo202510: added generalized LeiosNotify peers to ouroboros-con…
nfrisby Oct 24, 2025
30f4ce8
Add arguments for the anchor slot and its corresponding onset
dnadales Oct 24, 2025
384f0fc
Add support for POSIX timestamps
dnadales Oct 24, 2025
31bffbe
Calculate slot onset time for each slot in the logs
dnadales Oct 24, 2025
45c59c7
Pass anchor slot and its onset to the log_parser script
dnadales Oct 24, 2025
31af74a
Add a sanity check for the slot onset calculation
dnadales Oct 24, 2025
d42ef8a
Make the script generate a scatter plot
dnadales Oct 24, 2025
2912259
WIP
nfrisby Oct 24, 2025
9571dbf
WIP the script
nfrisby Oct 24, 2025
4b3cc38
WIP my TODO list
nfrisby Oct 24, 2025
bf9731e
Revert "WIP the script"
nfrisby Oct 24, 2025
643f4b4
Merge remote-tracking branch 'origin/1709-initial-demo-setup' into nf…
nfrisby Oct 24, 2025
a8bd024
WIP hacking on script file
nfrisby Oct 25, 2025
64d8c2c
WIP fixup 291225921 LeiosSchedule parsing in immdb-server
nfrisby Oct 25, 2025
6c48bd8
leiosdemo202510: use in-mem table instead of batching retrievals
nfrisby Oct 25, 2025
350943e
leiosdemo202510: polishing model exe
nfrisby Oct 25, 2025
6c0dbbe
leiosdemo202510: adding Leios state to NodeKernel
nfrisby Oct 25, 2025
6cefae1
leiosdemo202510: switch from RealPoint to bespoke LeiosPoint
nfrisby Oct 25, 2025
2be294f
leiosdemo202510: add basic logic to LeiosNotify client
nfrisby Oct 25, 2025
6efd6d8
leiosdemo202510: migrate EbId logic from the model exe
nfrisby Oct 25, 2025
6f2a6af
fixup leiosdemo202510: LeiosNotify
nfrisby Oct 25, 2025
40cddd1
leiosdemo202510: add LeiosFetch to NodeToNode
nfrisby Oct 25, 2025
4238e12
fixup leiosdemo202510: LeiosNotify
nfrisby Oct 25, 2025
dc09aab
leiosdemo202510: add generalized LeiosFetch pipelined client
nfrisby Oct 25, 2025
15052f5
leiosdemo202510: switch requestsToSend to TVar, for convenience
nfrisby Oct 25, 2025
eff731f
leiosdemo202510: use MutVar instead of MVar for drainThePipe
nfrisby Oct 25, 2025
c3c90b6
leiosdemo202510: polishing demo script
nfrisby Oct 26, 2025
1c690a3
leiosdemo202510: add LeiosFetch to immdb-server
nfrisby Oct 26, 2025
f9dc066
leiosdemo202510: fixup LeiosNotify client
nfrisby Oct 26, 2025
6a25c0b
leiosdemo202510: add LeiosFetch server to node
nfrisby Oct 26, 2025
43b6bb8
leiosdemo202510: more direct LeiosNotify server
nfrisby Oct 26, 2025
9c5584f
leiosdemo202510: add fetch decision logic to node
nfrisby Oct 26, 2025
d8e11d7
leiosdemo202510: now sending LeiosFetch requests, but ignoring responses
nfrisby Oct 26, 2025
3a1e330
leiosdemo202510: update model exe EB codec to match
nfrisby Oct 26, 2025
4f7c88c
leiosdemo202510: now processing MsgLeiosBlock, but ignoring MsgLeiosB…
nfrisby Oct 26, 2025
8057562
WIP one minute copies
nfrisby Oct 27, 2025
c1a2c95
WIP bugfix, see longer message
nfrisby Oct 27, 2025
473d06f
WIP disable the most noisy traces
nfrisby Oct 27, 2025
6438535
WIP fixup warnings
nfrisby Oct 27, 2025
772f6ee
leiosdemo202510: drop the netstat stuff
nfrisby Oct 27, 2025
e7aed1e
leiosdemo202510: consolidate magic numbers (absorbing maxIngressQueue)
nfrisby Oct 27, 2025
fe3b41f
leiosdemo202510: consolidate ebId magic number
nfrisby Oct 27, 2025
c567c18
leiosdemo202510: also generate typical schedule.json file
nfrisby Oct 27, 2025
15c2a46
leiosdemo202510: track outstanding EbTxs count per EB
nfrisby Oct 27, 2025
4d7c1bc
leiosdemo202510: more interpretable packing of ebIds, for now
nfrisby Oct 27, 2025
b635ebd
leiosdemo202510: LeiosNotify server in node, but DB locked :/
nfrisby Oct 28, 2025
6e5d547
WIP HasCallStack for db
nfrisby Oct 28, 2025
41fbed6
WIP node-0 freezing???
nfrisby Oct 28, 2025
ff77ac3
WIP change host-addr?
nfrisby Oct 28, 2025
3973252
WIP fix missing finalize and dieStack = dieStack :'(
nfrisby Oct 28, 2025
19f5707
leiosdemo202510: LeiosFetch for downstream too
nfrisby Oct 28, 2025
ea74e1b
leiosdemo202510: add a 2nd node-under-test, but not seeing mixed traf…
nfrisby Oct 28, 2025
903890c
Revert "leiosdemo202510: add a 2nd node-under-test, but not seeing mi…
nfrisby Oct 28, 2025
1886752
leiosdemo202510: add missing VACUUM
nfrisby Oct 28, 2025
af08f6a
leiosdemo202510: do not elide CompletedBlockFetch
nfrisby Oct 28, 2025
1a50c3b
leiosdemo202510: hack leios-october-script.sh and log_parser.py to sh…
nfrisby Oct 28, 2025
49026a6
leiosdemo202510: disable scatter plot for now
nfrisby Oct 28, 2025
17b4292
leiosdemo202510: polishing the leios-october-script.sh
nfrisby Oct 28, 2025
c0d12b9
leiosdemo202510: add README-Leios-October-demo.md and demoManifest.json
nfrisby Oct 28, 2025
0720059
leiosdemo202510: add some documentation to README-Leios-October-demo.md
nfrisby Oct 28, 2025
660207b
leiosdemo202510: fix typos in README-Leios-October-demo.md
nfrisby Oct 28, 2025
1dba9a7
leiosdemo202510: update now that the simplest first experiment is wor…
nfrisby Oct 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,5 @@ cabal.project.local
cabal.project.local~
.HTF/
.ghc.environment.*
.nixos-test-history
.direnv/
220 changes: 220 additions & 0 deletions README-Leios-October-demo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
# How to run the Leios October demo

See https://github.com/IntersectMBO/ouroboros-consensus/issues/1701 for context.

## Prepare the shell environment

- If your environment can successfully execute `cabal build exe:cardano-node` from this commit, then it can build this demo's exes.
````
$ git log -1 10.5.1
commit ca1ec278070baf4481564a6ba7b4a5b9e3d9f366 (tag: 10.5.1, origin/release/10.5.1, nfrisby/leiosdemo2025-anchor)
Author: Jordan Millar <[email protected]>
Date: Wed Jul 2 08:24:11 2025 -0400

Bump node version to 10.5.1
```
- The Python script needs `pandas` and `matplotlib`.
- The various commands and bash scripts below needs `toxiproxy`, `sqlite`, `ps` (which on a `nix-shell` might require the `procps` package for matching CLIB, eg), and so on.
- Set `CONSENSUS_BUILD_DIR` to the absolute path of a directory in which `cabal build exe:immdb-server` will succeed.
- Set `NODE_BUILD_DIR` to the absolute path of a directory in which `cabal build exe:cardano-node` will succeed.
- Set `CONSENSUS_REPO_DIR` to the absolute path of the `ouroboros-consensus` repo.

- Checkout a patched version of the `cardano-node` repository, something like the following, eg.

```
6119c5cff0 - (HEAD -> nfrisby/leiosdemo2025, origin/nfrisby/leiosdemo2025) WIP add Leios demo Consensus s-r-p (25 hours ago) <Nicolas Frisby>
```

- If you're using a `source-repository-package` stanza for the `cabal build exe:cardano-node` command in the `NODE_BUILD_DIR`, confirm that it identifies the `ouroboros-consensus` commit you want to use (eg the one you're reading this file in).

## Build the exes

```
$ (cd $CONSENSUS_BUILD_DIR; cabal build exe:immdb-server exe:leiosdemo202510)
$ IMMDB_SERVER="$(cd $CONSENSUS_BUILD_DIR; cabal list-bin exe:immdb-server)"
$ DEMO_TOOL="$(cd $CONSENSUS_BUILD_DIR; cabal list-bin exe:leiosdemo202510)"
$ (cd $CONSENSUS_BUILD_DIR; cabal build exe:cardano-node)
$ CARDANO_NODE="$(cd $CONSENSUS_BUILD_DIR; cabal list-bin exe:cardano-node)"
```

## Prepare the input data files

```
$ (cd $CONSENSUS_BUILD_DIR; $DEMO_TOOL generate demoUpstream.db "${CONSENSUS_REPO_DIR}/demoManifest.json" demoBaseSchedule.json)
$ cp demoBaseSchedule.json demoSchedule.json
$ # You must now edit demoSchedule.json so that the first number in each array is 182.9
$ echo '[]' >emptySchedule.json
$ # create the following symlinks
$ (cd $CONSENSUS_REPO_DIR; ls -l $(find nix/ -name genesis-*.json))
lrwxrwxrwx 1 nfrisby nifr 30 Oct 24 16:27 nix/leios-mvd/immdb-node/genesis-alonzo.json -> ../genesis/genesis.alonzo.json
lrwxrwxrwx 1 nfrisby nifr 29 Oct 24 16:27 nix/leios-mvd/immdb-node/genesis-byron.json -> ../genesis/genesis.byron.json
lrwxrwxrwx 1 nfrisby nifr 30 Oct 24 16:27 nix/leios-mvd/immdb-node/genesis-conway.json -> ../genesis/genesis.conway.json
lrwxrwxrwx 1 nfrisby nifr 31 Oct 24 16:27 nix/leios-mvd/immdb-node/genesis-shelley.json -> ../genesis/genesis.shelley.json
lrwxrwxrwx 1 nfrisby nifr 30 Oct 24 16:27 nix/leios-mvd/leios-node/genesis-alonzo.json -> ../genesis/genesis.alonzo.json
lrwxrwxrwx 1 nfrisby nifr 29 Oct 24 16:27 nix/leios-mvd/leios-node/genesis-byron.json -> ../genesis/genesis.byron.json
lrwxrwxrwx 1 nfrisby nifr 30 Oct 24 16:27 nix/leios-mvd/leios-node/genesis-conway.json -> ../genesis/genesis.conway.json
lrwxrwxrwx 1 nfrisby nifr 31 Oct 24 16:27 nix/leios-mvd/leios-node/genesis-shelley.json -> ../genesis/genesis.shelley.json
```

## Prepare to run scenarios

Ensure a toxiproxy server is running.

```
$ toxiproxy-server 1>toxiproxy.log 2>&1 &
```

## Run the scenario

Run the scenario with `emptySchedule.json`, ie no Leios traffic.

```
$ LEIOS_UPSTREAM_DB_PATH="$(pwd)/demoUpstream.db" LEIOS_SCHEDULE="$(pwd)/emptySchedule.json" SECONDS_UNTIL_REF_SLOT=5 REF_SLOT=177 CLUSTER_RUN_DATA="${CONSENSUS_REPO_DIR}/nix/leios-mvd" CARDANO_NODE=$CARDANO_NODE IMMDB_SERVER=$IMMDB_SERVER ${CONSENSUS_REPO_DIR}/scripts/leios-demo/leios-october-demo.sh
$ # wait about ~20 seconds before stopping the execution by pressing any key
```

Run the scenario with `demoSchedule.json`.

```
$ LEIOS_UPSTREAM_DB_PATH="$(pwd)/demoUpstream.db" LEIOS_SCHEDULE="$(pwd)/demoSchedule.json" SECONDS_UNTIL_REF_SLOT=5 REF_SLOT=177 CLUSTER_RUN_DATA="${CONSENSUS_REPO_DIR}/nix/leios-mvd" CARDANO_NODE=$CARDANO_NODE IMMDB_SERVER=$IMMDB_SERVER ${CONSENSUS_REPO_DIR}/scripts/leios-demo/leios-october-demo.sh
$ # wait about ~20 seconds before stopping the execution by pressing any key
```

## Analysis

Compare and contrast the `latency_ms` column for the rows with a slot that's after the reference slot 177.
The first few such ros (ie those within a couple seconds of the reference slot) seem to often also be disrupted, because the initial bulk syncing to catch up to the reference slot presumably leaves the node in a disrupted state for a short interval.

**WARNING**.
Each execution consumes about 0.5 gigabytes of disk.
The script announces where (eg `Temporary data stored at: /run/user/1000/leios-october-demo.c5Wmxc`), so you can delete each run's data when necessary.

**INFO**.
If you don't see any data in the 'Extracted and Merged Data Summary' table, then check the log files in the run's temporary directory.
This is where you might see messages about, eg, the missing `genesis-*.json` files, bad syntax in the `demoSchedule.json` file, etc.

# Details about the demo components

## The topology

For this first iteration, the demo topology is a simple linear graph.

```mermaid
flowchart TD
MockedUpstreamPeer --> Node0 --> MockedDownstreamPeer
```

**INFO**.
In this iteration of the demo, the mocked downstream peer (see section below) is simply another node, ie Node1.

## The Praos traffic and Leios traffic

In this iteration of the demo, the data and traffic is very simple.

- The Praos data is a simple chain provided by the Performance&Tracing team.
- The mocked upstream peer serves each Praos block when the mocked wall-clock reaches the onset of their slots.
- The Leios data is ten 12.5 megabyte EBs.
They use the minimal number of txs necessary in order to accumulate 12.5 megabytes in order to minimize the CPU&heap overhead of the patched-in Leios logic, since this iteration of trhe demo is primarily intended to focus on networking.
- The mocked upstream peer serves those EBs just prior to the onset of one of the Praos block's slot, akin to (relatively minor) ATK-LeiosProtocolBurst attack.
Thus, the patched nodes are under significant Leios load when that Praos block begins diffusing.

## The demo tool

The `cabal run exe:leiosdemo202510 -- generate ...` command generates a SQLite database with the following schema.

```
CREATE TABLE ebPoints (
ebSlot INTEGER NOT NULL
,
ebHashBytes BLOB NOT NULL
,
ebId INTEGER NOT NULL
,
PRIMARY KEY (ebSlot, ebHashBytes)
) WITHOUT ROWID;
CREATE TABLE ebTxs (
ebId INTEGER NOT NULL -- foreign key ebPoints.ebId
,
txOffset INTEGER NOT NULL
,
txHashBytes BLOB NOT NULL -- raw bytes
,
txBytesSize INTEGER NOT NULL
,
txBytes BLOB -- valid CBOR
,
PRIMARY KEY (ebId, txOffset)
) WITHOUT ROWID;
```

The contents of the generated database are determine by the given `manifest.json` file.
For now, see the `demoManifest.json` file for the primary schema: each "`txRecipe`" is simply the byte size of the transaction.

The `generate` subcommand also generates a default `schedule.json`.
Each EB will have two array elements in the schedule.
The first number in an array element is a fractional slot, which determines when the mocked upstream peer will offer the payload.
The rest of the array element is `MsgLeiosBlockOffer` if the EB's byte size is listed or `MsgLeiosBlockTxsOffer` if `null` is listed.

The secondary schema of the manifest allows for EBs to overlap (which isn't necessary for this demo, despite the pathced node fully supporting it).
Overlap is created by an alternative "`txRecipe`", an object `{"share": "XYZ", "startIncl": 90, "stopExcl": 105}` where `"nickname": "XYZ"` was included in a preceding _source_ EB recipe.
The `"startIncl`" and `"stopExcl"` are inclusive and exclusive indices into the source EB (aka a left-closed right-open interval); `"stopExcl"` is optional and defaults to the length of the source EB.
With this `"share"` syntax, it is possible for an EB to include the same tx multiple times.
That would not be a well-formed EB, but the prototype's behavior in response to such an EB is undefined---it's fine for the prototype to simply assume all the Leios EBs and txs in their closures are well-formed.
(TODO check for this one, since it's easy to check for---just in the patched node itself, or also in `generate`?)

## The mocked upstream peer

The mocked upstream peer is a patched variant of `immdb-server`.

- It runs incomplete variants of LeiosNotify and LeiosFetch: just EBs and EB closures, nothing else (no EB announcements, no votes, no range requests).
- It serves the EBs present in the given `--leios-db`; it sends Leios notificaitons offering the data according to the given `--leios-schedule`.
See the demo tool section above for how to generate those files.

## The patched node/node-under-test

The patched node is a patched variant of `cardano-node`.
All of the material changes were made in the `ouroboros-consensus` repo; the `cardano-node` changes are merely for integration.

- It runs the same incomplete variants of LeiosNotify and LeiosFetch as the mocked upstream peer.
- The Leios fetch request logic is a fully fledged first draft, with following primary shortcomings.
- It only handles EBs and EB closures, not votes and not range requests.
- It retains a number of heap objects in proportion with the number of txs in EBs it has acquired.
The real node---and so subsequent iterations of this prototype---must instead keep that data on disk.
This first draft was intended to do so, but we struggled to invent the fetch logic algorithm with the constraint that some of its state was on-disk; that's currently presumed to be possible, but has been deferred to a subsequent iteration of the prototype.
- It never discards any information.
The real node---and so subsequent iterations of this prototype---must instead discard EBs and EB closures once they're old enough, unless they are needed for the immutable chain.
- Once it decides to fetch a set of txs from an upstream peer for the sake of some EB closure(s), it does not necessarily compose those into an optimal set of requests for that peer.
We had not identified the potential for an optimizing algorithm here until writing this first prototype, so it just does something straight-forward and naive for now (which might be sufficient even for the real-node---we'll have to investigate later).

There are no other changes.
In particular, that means the `ouroboros-network` mux doesn't not deprioritize Leios traffic.
That change is an example of what this first prototype is intended to potentially demonstrate the need for.
There are many such changes, from small to large.
Some examples includes the following.

- The prototype uses SQLite3 with entirely default settings.
Maybe Write-Ahead Log mode would be much preferable, likely need to VACUUM at some point, and so on.
- The prototype uses a mutex to completely isolate every SQLite3 invocation---that's probably excessive, but was useful for some debugging during initial development (see the Engineering Notes appendix)
- The prototype chooses several _magic numbers_ for resource utilization limits (eg max bytes per reqeust, max outsanding bytes per peer, fetch decision logic rate-limiting, txCache disk-bandwidth rate-limiting, etc).
These all ultimately need to be tuned for the intended behvaiors on `mainnet`.
- The prototype does not deduplicate the storage of EBs' closures when they share txs.
This decision makes the LeiosFetch server a trivial single-pass instead of a join.
However, it "wastes" disk space and disk bandwidth.
It's left to future work to decide whether that's a worthwhile trade-off.

## The mocked downstream node

For simplicity, this is simply another instance of the patched node.
In the future, it could be comparatively lightweight and moreover could replay an arbitrary schedule of downstream requests, dual to the mocked upstream peer's arbitrary schedule of upstream notifications.

# Appendix: Engineering Notes

This section summarizes some lessons learned during the development of this prototype.

- Hypothesis: A SQLite connection will continue to hold SQLite's internal EXCLUSIVE lock _even after the transaction is COMMITed_ when the write transaction involved a prepared statement that was accidentally not finalized.
That hypothesis was inferred from a painstaking debugging session, but I haven't not yet confirmed it in isolation.
The bugfix unsuprisingly amounted to using `bracket` for all prepare/finalize pairs and all BEGIN/COMMIT pairs; thankfully our DB patterns seem to accommodate such bracketing.
- The SQLite query plan optimizer might need more information in order to be reliable.
Therefore at least one join (the one that copies out of `txCache` for the EbTxs identified in an in-memory table) was replaced with application-level iteration.
It's not yet clear whether a one-time ANALYZE call might suffice, for example.
Even if it did, it's also not yet clear how much bandwidth usage/latency/jitter/etc might be reduced.
Loading
Loading