Skip to content

Commit 16b4754

Browse files
authored
devnet instructions and more API requests (#48)
1 parent 2be5db0 commit 16b4754

File tree

11 files changed

+239
-35
lines changed

11 files changed

+239
-35
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@
2424
# Live configs
2525
testdata/*-config.json
2626
testdata/*-secrets.json
27+
/database.dump

Makefile

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
VERSION := $(shell git describe --tags --always --dirty="-dev")
66

7+
# A few colors
8+
RED:=\033[0;31m
9+
GREEN:=\033[0;32m
10+
NC:=\033[0m
11+
712
##@ Help
813

914
.PHONY: help
@@ -27,6 +32,16 @@ build: ## Build the HTTP server
2732

2833
##@ Test & Development
2934

35+
.PHONY: lt
36+
lt: lint test ## Run linters and tests (always do this!)
37+
38+
.PHONY: fmt
39+
fmt: ## Format the code (use this often)
40+
gofmt -s -w .
41+
gci write .
42+
gofumpt -w -extra .
43+
go mod tidy
44+
3045
.PHONY: test
3146
test: ## Run tests
3247
go test ./...
@@ -43,20 +58,10 @@ lint: ## Run linters
4358
staticcheck ./...
4459
golangci-lint run
4560

46-
.PHONY: fmt
47-
fmt: ## Format the code
48-
gofmt -s -w .
49-
gci write .
50-
gofumpt -w -extra .
51-
go mod tidy
52-
5361
.PHONY: gofumpt
5462
gofumpt: ## Run gofumpt
5563
gofumpt -l -w -extra .
5664

57-
.PHONY: lt
58-
lt: lint test ## Run linters and tests
59-
6065
.PHONY: cover
6166
cover: ## Run tests with coverage
6267
go test -coverprofile=/tmp/go-sim-lb.cover.tmp ./...
@@ -72,8 +77,30 @@ cover-html: ## Run tests with coverage and open the HTML report
7277
.PHONY: docker-httpserver
7378
docker-httpserver: ## Build the HTTP server Docker image
7479
DOCKER_BUILDKIT=1 docker build \
80+
--file docker/httpserver/Dockerfile \
7581
--platform linux/amd64 \
7682
--build-arg VERSION=${VERSION} \
77-
--file httpserver.dockerfile \
78-
--tag your-project \
83+
--tag builder-hub \
7984
.
85+
86+
.PHONY: db-dump
87+
db-dump: ## Dump the database contents to file 'database.dump'
88+
pg_dump -h localhost -U postgres --column-inserts --data-only postgres -f database.dump
89+
@printf "Database dumped to file: $(GREEN)database.dump$(NC) ✅\n"
90+
91+
.PHONY: dev-db-setup
92+
db-dev-setup: ## Create the basic database entries for testing and development
93+
@printf "$(GREEN)Create the allow-all measurements $(NC)\n"
94+
curl --request POST --url http://localhost:8081/api/admin/v1/measurements --data '{"measurement_id": "test1","attestation_type": "test","measurements": {}}'
95+
96+
@printf "$(GREEN)Enable the measurements $(NC)\n"
97+
curl --request POST --url http://localhost:8081/api/admin/v1/measurements/activation/test1 --data '{"enabled": true}'
98+
99+
@printf "$(GREEN)Create the builder $(NC)\n"
100+
curl --request POST --url http://localhost:8081/api/admin/v1/builders --data '{"name": "test_builder","ip_address": "1.2.3.4"}'
101+
102+
@printf "$(GREEN)Create the builder configuration $(NC)\n"
103+
curl --request POST --url http://localhost:8081/api/admin/v1/builders/configuration/test_builder --data '{"dns_name": "foobar-v1.a.b.c","rbuilder": {"extra_data": "FooBar"}}'
104+
105+
@printf "$(GREEN)Enable the builder $(NC)\n"
106+
curl --request POST --url http://localhost:8081/api/admin/v1/builders/activation/test_builder --data '{"enabled": true}'

README.md

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ BuilderHub has these responsibilities:
1313
2. Provisioning of secrets and configuration
1414
3. Peer discovery
1515

16-
System context diagram:
16+
---
1717

1818
![Architecture](https://buildernet.org/assets/ideal-img/flashbots-infra-dataflow.7377b1f.3909.png)
1919

2020
---
2121

2222
## Getting started
2323

24+
25+
### Manual setup
26+
2427
**Start the database and the server:**
2528

2629
```bash
@@ -34,21 +37,11 @@ for file in schema/*.sql; do psql "postgres://postgres:postgres@localhost:5432/p
3437
go run cmd/httpserver/main.go
3538
```
3639

37-
**Start everything in Docker from our published images:**
38-
39-
```bash
40-
# Switch into the 'docker' directory
41-
cd docker
42-
43-
# Update and start the services
44-
docker-compose pull
45-
docker-compose up
40+
### Using Docker
4641

47-
# Make an example request
48-
curl localhost:8888
49-
```
42+
See instructions on using Docker to run the full stack at [`docs/devenv-setup.md`](./docs/devenv-setup.md)
5043

51-
**Query a few endpoints:**
44+
### Example requests
5245

5346
```bash
5447
# Public endpoints
@@ -60,16 +53,12 @@ curl localhost:8080/api/l1-builder/v1/configuration
6053
curl -X POST localhost:8080/api/l1-builder/v1/register_credentials/rbuilder
6154
```
6255

63-
Run database tests>
64-
65-
```bash
66-
RUN_DB_TESTS=1 make test
67-
```
56+
### Testing
6857

69-
**Stop the database:**
58+
Run test suite with database tests included:
7059

7160
```bash
72-
docker rm -f postgres-test
61+
RUN_DB_TESTS=1 make test
7362
```
7463

7564
---

docker/docker-compose.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
services:
22
db:
33
image: flashbots/builder-hub-db
4+
ports:
5+
- 5432:5432
46
environment:
57
PGUSER: postgres
68
POSTGRES_DB: postgres
79
POSTGRES_USER: postgres
810
POSTGRES_PASSWORD: postgres
911
healthcheck:
10-
test: ["CMD-SHELL", "pg_isready", "-U", "${POSTGRES_USER}", "-d", "${POSTGRES_PASSWORD}"]
12+
test: ["CMD-SHELL", "pg_isready"]
1113
interval: 5s
1214
retries: 5
1315
start_period: 2s
@@ -27,6 +29,7 @@ services:
2729
- 8082:8082
2830
- 8090:8090
2931
environment:
32+
MOCK_SECRETS: true
3033
POSTGRES_DSN: "postgres://postgres:postgres@db:5432/postgres?sslmode=disable"
3134
LISTEN_ADDR: "0.0.0.0:8080"
3235
ADMIN_ADDR: "0.0.0.0:8081"

docs/api-docs/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
You can load the Bruno collection with https://www.usebruno.com
22

33
The docs include these collections:
4-
- [Admin API](./admin-api/)
4+
- [Admin API](./admin-api/)
5+
- [Instance API](./instance-api/)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
meta {
2+
name: Get measurements
3+
type: http
4+
seq: 2
5+
}
6+
7+
get {
8+
url: http://localhost:8888/api/l1-builder/v1/measurements
9+
body: none
10+
auth: none
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
meta {
2+
name: Get peers
3+
type: http
4+
seq: 3
5+
}
6+
7+
get {
8+
url: http://localhost:8888/api/l1-builder/v1/builders
9+
body: none
10+
auth: none
11+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
meta {
2+
name: Register credentials
3+
type: http
4+
seq: 4
5+
}
6+
7+
post {
8+
url: http://localhost:8888/api/l1-builder/v1/register_credentials/rbuilder
9+
body: json
10+
auth: none
11+
}
12+
13+
body:json {
14+
{
15+
"ecdsa_pubkey_address": "0x321f3426eEc20DE1910af1CD595c4DD83BEA0BA5"
16+
}
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"version": "1",
3+
"name": "BuilderHub Instance API",
4+
"type": "collection",
5+
"ignore": [
6+
"node_modules",
7+
".git"
8+
]
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
meta {
2+
name: Get measurements
3+
type: http
4+
seq: 11
5+
}
6+
7+
get {
8+
url: http://localhost:8081/api/admin/v1/builders/configuration/{builder}/full
9+
body: none
10+
auth: none
11+
}

0 commit comments

Comments
 (0)