Skip to content

Commit bcd8a40

Browse files
committed
feat(cbt): add external model bounds and interval types config
Add support for xatu-cbt external model bounds configuration: - EXTERNAL_MODEL_MIN_TIMESTAMP: set to 1 hour ago by default - EXTERNAL_MODEL_MIN_BLOCK: defaults to 0, mainnet uses 23800000 - GenesisTimestamp from network constants - interval_types configuration for slot/datetime/timestamp Related to ethpandaops/xatu-cbt#135
1 parent 90755b3 commit bcd8a40

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

pkg/configgen/generator.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"path/filepath"
1111
"strings"
1212
"text/template"
13+
"time"
1314

1415
"github.com/ethpandaops/xcli/pkg/config"
1516
"github.com/ethpandaops/xcli/pkg/constants"
@@ -66,18 +67,33 @@ func (g *Generator) GenerateCBTConfig(network string, overridesPath string) (str
6667
}
6768

6869
frontendPort := g.cfg.GetCBTFrontendPort(network)
70+
externalModelMinTimestamp := time.Now().Add(-1 * time.Hour).Unix()
71+
72+
// Set sane default for mainnet
73+
externalModelMinBlock := 0
74+
if network == "mainnet" {
75+
externalModelMinBlock = 23800000
76+
}
77+
78+
var genesisTimestamp uint64
79+
if timestamp, ok := constants.NetworkGenesisTimestamps[network]; ok {
80+
genesisTimestamp = timestamp
81+
}
6982

7083
data := map[string]interface{}{
7184
"Network": network,
7285
"MetricsPort": metricsPort,
7386
"RedisDB": redisDB,
7487
"FrontendPort": frontendPort,
88+
"GenesisTimestamp": genesisTimestamp,
7589
"IsHybrid": g.cfg.Mode == constants.ModeHybrid,
7690
"XatuMode": g.cfg.Infrastructure.ClickHouse.Xatu.Mode,
7791
"ExternalClickHouseURL": g.cfg.Infrastructure.ClickHouse.Xatu.ExternalURL,
7892
"ExternalClickHouseDatabase": externalDatabase,
7993
"ExternalClickHouseUsername": g.cfg.Infrastructure.ClickHouse.Xatu.ExternalUsername,
8094
"ExternalClickHousePassword": g.cfg.Infrastructure.ClickHouse.Xatu.ExternalPassword,
95+
"ExternalModelMinBlock": externalModelMinBlock,
96+
"ExternalModelMinTimestamp": externalModelMinTimestamp,
8197
"OverridesPath": overridesPath,
8298
"HasOverrides": overridesPath != "",
8399
}

pkg/configgen/templates/cbt.yaml.tmpl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ clickhouse:
1616
scheduled:
1717
database: "{{ .Network }}"
1818
table: "admin_cbt_scheduled"
19+
interval_types:
20+
slot:
21+
- name: Slot
22+
expression: "math.floor((value - {{ .GenesisTimestamp }}) / 12)"
23+
- name: Datetime
24+
format: datetime
25+
expression: "value * 1000"
26+
- name: Timestamp
1927

2028
redis:
2129
url: "redis://localhost:6380/{{ .RedisDB }}"
@@ -35,6 +43,8 @@ models:
3543
{{- end }}
3644
env:
3745
NETWORK: "{{ .Network }}"
46+
EXTERNAL_MODEL_MIN_TIMESTAMP: "{{ .ExternalModelMinTimestamp }}"
47+
EXTERNAL_MODEL_MIN_BLOCK: "{{ .ExternalModelMinBlock }}"
3848

3949
frontend:
4050
enabled: true

0 commit comments

Comments
 (0)