Skip to content

Commit a011bd0

Browse files
authored
Implement ledger peering lisp logic
1 parent 0cbfc3e commit a011bd0

File tree

13 files changed

+47
-782
lines changed

13 files changed

+47
-782
lines changed

.github/workflows/service-cryptography.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
- name: Retag and push latest Docker image
3333
if: github.ref == 'refs/heads/main'
3434
run: |
35+
cd ./services/cryptography
3536
docker tag ghcr.io/${{ github.repository }}/cryptography:$( cargo pkgid | cut -d '@' -f 2 ) \
3637
ghcr.io/${{ github.repository }}/cryptography:latest
3738
docker push ghcr.io/${{ github.repository }}/cryptography:latest

compose/ledger/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM ghcr.io/sandialabs/sync-journal/journal-sdk:1.0.1
2+
3+
RUN wget https://raw.githubusercontent.com/sandialabs/sync-records/refs/heads/main/lisp/record.scm
4+
RUN wget https://raw.githubusercontent.com/sandialabs/sync-records/refs/heads/main/lisp/control.scm
5+
RUN wget https://raw.githubusercontent.com/sandialabs/sync-records/refs/heads/main/lisp/ledger.scm
6+
7+
COPY run.sh .
8+
9+
CMD ./run.sh

compose/ledger/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ This repository contains materials to deploy a single ledger journal using Docke
1111

1212
Please set the following environmental variables to configure the notary journal.
1313

14+
- `SECRET` (required): a string used to generate authentication credentials
1415
- `PORT`: port number to forward on the host machine (default:8192)
15-
- `SEED` (required): a 32-byte hex string used to identify and authenticate journal requests
1616
- `PERIODICITY`: a nonnegative integer that determines the period of each synchronization step where period = 2 ^ PERIODICITY
17-
- `NOTARY`: a URL pointing to an instance of a synchronic web notary
1817

1918
## Start
2019

21-
`$ docker compose up`
20+
`$ SECRET=password PORT=80 docker compose up --build`
2221

2322
## End
2423

compose/ledger/docker-compose.yml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,36 @@ networks:
44

55
services:
66
cryptography:
7-
image: synchronic-web/cryptography-service:latest
7+
image: ghcr.io/sandialabs/sync-services/cryptography:1.0.0
8+
container_name: cryptography
89
networks:
910
- docker
1011

1112
journal:
12-
image: synchronic-web/synchronic-web/journal-sdk:latest
13-
volumes:
14-
- ./source.scm:/srv/source.scm
15-
- ./run.sh:/srv/run.sh
13+
build:
14+
context: .
15+
container_name: journal
1616
networks:
1717
- docker
1818
depends_on:
1919
- cryptography
2020
environment:
21-
SEED: ${SEED}
21+
SECRET: ${SECRET}
2222
PERIODICITY: ${PERIODICITY:-2}
2323
CRYPTOGRAPHY: http://cryptography.docker
24-
REST: '"$NOTARY"'
25-
command: ./run.sh
24+
25+
explorer:
26+
image: ghcr.io/sandialabs/sync-services/explorer:1.0.0
27+
container_name: explorer
28+
networks:
29+
- docker
30+
depends_on:
31+
- journal
32+
command: python service.py --secret $SECRET --journal http://journal.docker/interface --port 80
2633

2734
interface:
2835
image: nginx:stable-alpine
36+
container_name: interface
2937
volumes:
3038
- ./nginx.conf:/etc/nginx/conf.d/default.conf
3139
depends_on:

compose/ledger/nginx.conf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
server {
2-
location / {
2+
location /.interface {
33
proxy_pass http://journal.docker/interface;
44
}
5+
location / {
6+
proxy_pass http://explorer.docker;
7+
}
58
}

compose/ledger/run.sh

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,26 @@
11
#!/bin/sh
22

3-
if [ -z "$SEED" ]; then
4-
echo Must set the secret SEED variable""
3+
if [ -z "$SECRET" ]; then
4+
echo Must set the SECRET variable""
55
exit 1
66
fi
77

8+
record=$( cat record.scm )
9+
control=$( cat control.scm )
10+
ledger=$( cat ledger.scm )
11+
812
check_status() {
913
while true; do
10-
response=$( wget -qO - "$1" 2>/dev/null)
11-
if [ -n "$response" ]; then
12-
return 0
13-
else
14+
echo "Polling for cryptography service"
15+
response=$( wget -qO - "$1" 2>/dev/null)
16+
if [ -n "$response" ]; then
17+
return 0
18+
else
1419
sleep 1
15-
fi
16-
done
17-
}
18-
19-
check_status "${CRYPTOGRAPHY}/signature/key/${SEED}"
20-
21-
routine() {
22-
check_status "localhost/"
23-
24-
while true; do
25-
start_time=$(date +%s)
26-
response=$( wget -qO - localhost/interface --post-data "(step \"$SEED\")" )
27-
echo $response >> steps.log
28-
next_time=$((start_time + $(( 2 ** $PERIODICITY ))))
29-
current_time=$(date +%s)
30-
sleep_duration=$((next_time - current_time))
31-
if [ $sleep_duration -gt 0 ]; then
32-
sleep $sleep_duration
33-
fi
20+
fi
3421
done
3522
}
3623

37-
routine &
24+
check_status "${CRYPTOGRAPHY}/signature/key/deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
3825

39-
./journal-sdk -p 80 --database db --boot "($( cat source.scm ) \"$SEED\" $PERIODICITY \"$CRYPTOGRAPHY\" $REST)"
26+
./journal-sdk -b "($record \"$SECRET\" $control ($ledger \"$CRYPTOGRAPHY\" #t #f))" -s "(*step* \"$SECRET\")" -p 80 -c $PERIODICITY

0 commit comments

Comments
 (0)