Skip to content

Commit 0628bfa

Browse files
authored
Add time column to website (#765)
* Make block hash monospace * Add time column to website main view * fix tests
1 parent 26ac3e2 commit 0628bfa

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ services:
1818
- '11211:11211'
1919

2020
db:
21-
image: postgres
21+
image: postgres:18
2222
restart: always
2323
volumes:
24-
- 'psql_data:/var/lib/postgresql/data'
24+
- 'psql_data:/var/lib/postgresql'
2525
ports:
2626
- '5432:5432'
2727
environment:

scripts/website-staticgen/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"os"
8+
"time"
89

910
"github.com/flashbots/mev-boost-relay/services/website"
1011
"github.com/goccy/go-json"
@@ -25,6 +26,14 @@ func main() {
2526
panic(err)
2627
}
2728

29+
// add fake times for some variability in rendered template
30+
diff := time.Second
31+
for i, v := range data.Payloads {
32+
v.InsertedAt = time.Now().Add(-diff)
33+
data.Payloads[i] = v
34+
diff = diff * 5 / 3
35+
}
36+
2837
indexTemplate, err := website.ParseIndexTemplate()
2938
if err != nil {
3039
panic(err)

services/website/html.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
_ "embed"
55
"math/big"
66
"text/template"
7+
"time"
78

89
"github.com/flashbots/mev-boost-relay/database"
910
"golang.org/x/text/cases"
@@ -67,10 +68,39 @@ func caseIt(s string) string {
6768
return caser.String(s)
6869
}
6970

71+
func relativeTime(t time.Time) string {
72+
diff := time.Since(t)
73+
if diff < 0 {
74+
// should be unreachable, but just in case
75+
return diff.String()
76+
}
77+
78+
seconds := int(diff.Seconds())
79+
minutes := int(diff.Minutes())
80+
hours := int(diff.Hours())
81+
days := hours / 24
82+
83+
if seconds < 60 {
84+
return printer.Sprintf("%ds ago", seconds)
85+
} else if minutes < 60 {
86+
return printer.Sprintf("%dm ago", minutes)
87+
} else if hours < 24 {
88+
return printer.Sprintf("%dh ago", hours)
89+
} else {
90+
return printer.Sprintf("%dd ago", days)
91+
}
92+
}
93+
94+
func formatUTC(t time.Time) string {
95+
return t.UTC().Format("2006-01-02 15:04:05 UTC")
96+
}
97+
7098
var funcMap = template.FuncMap{
71-
"weiToEth": weiToEth,
72-
"prettyInt": prettyInt,
73-
"caseIt": caseIt,
99+
"weiToEth": weiToEth,
100+
"prettyInt": prettyInt,
101+
"caseIt": caseIt,
102+
"relativeTime": relativeTime,
103+
"formatUTC": formatUTC,
74104
}
75105

76106
//go:embed website.html

services/website/website.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ <h2>
233233
<table class="pure-table pure-table-horizontal" style="width:100%;">
234234
<thead>
235235
<tr>
236+
<th style="text-align: right;">Time</th>
236237
<th>Epoch</th>
237238
<th>Slot</th>
238239
<th>Block number</th>
@@ -257,6 +258,9 @@ <h2>
257258
{{$linkDataAPI := .LinkDataAPI}}
258259
{{ range .Payloads }}
259260
<tr>
261+
<td style="text-align: right;">
262+
<span title="{{.InsertedAt | formatUTC}}">{{.InsertedAt | relativeTime}}</span>
263+
</td>
260264
<td>{{.Epoch | prettyInt}}</td>
261265
<td>
262266
<a href="{{$linkDataAPI}}/relay/v1/data/bidtraces/proposer_payload_delivered?slot={{.Slot}}">{{.Slot | prettyInt}}</a>
@@ -267,7 +271,7 @@ <h2>
267271
<td>
268272
<div title="Blob Gas Used: {{.BlobGasUsed}}">{{.NumBlobs }}</div>
269273
</td>
270-
<td>{{.BlockHash}}</td>
274+
<td style="font-family: monospace;">{{.BlockHash}}</td>
271275
<td>
272276
<div class="icons-container">
273277
{{ if ne $linkBeaconchain "" }}

0 commit comments

Comments
 (0)