Skip to content

Commit 68baa08

Browse files
authored
Add chaintracks to default deployment (#17)
* Add chaintracks server to default deployment * Update go.mod * Fix gitignore * Fix gitignore * Fix lint * Actually fix linter
1 parent 94fbb3d commit 68baa08

6 files changed

Lines changed: 45 additions & 23 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,6 @@ node_modules/
4444
peer_cache.json
4545

4646
*.log
47+
48+
arcade
49+
config.yaml

cmd/arcade/main.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import (
3434
fiberlogger "github.com/gofiber/fiber/v2/middleware/logger"
3535
"github.com/gofiber/fiber/v2/middleware/recover"
3636

37+
chaintracksRoutes "github.com/bsv-blockchain/go-chaintracks/routes/fiber"
38+
3739
"github.com/bsv-blockchain/arcade/config"
3840
"github.com/bsv-blockchain/arcade/docs"
3941
"github.com/bsv-blockchain/arcade/logging"
@@ -97,6 +99,13 @@ func run(ctx context.Context, cfg *config.Config, log *slog.Logger) error {
9799
Logger: log,
98100
})
99101

102+
// Setup chaintracks routes (if enabled and running in embedded mode)
103+
var chaintracksRts *chaintracksRoutes.Routes
104+
if cfg.ChaintracksServer.Enabled && services.Chaintracks != nil {
105+
chaintracksRts = chaintracksRoutes.NewRoutes(ctx, services.Chaintracks)
106+
log.Info("Chaintracks HTTP API enabled", slog.String("routes", "/chaintracks/v1/*, /chaintracks/v2/*"))
107+
}
108+
100109
// Setup dashboard
101110
dashboard := NewDashboard(services.Arcade)
102111

@@ -107,7 +116,7 @@ func run(ctx context.Context, cfg *config.Config, log *slog.Logger) error {
107116
authToken = cfg.Auth.Token
108117
log.Info("API authentication enabled")
109118
}
110-
app := setupServer(arcadeRoutes, dashboard, authToken)
119+
app := setupServer(arcadeRoutes, chaintracksRts, dashboard, authToken)
111120

112121
errCh := make(chan error, 1)
113122
go func() {
@@ -118,7 +127,10 @@ func run(ctx context.Context, cfg *config.Config, log *slog.Logger) error {
118127

119128
log.Info("Arcade started successfully")
120129

121-
// Wait for shutdown signal
130+
return waitForShutdown(ctx, cfg, log, app, errCh)
131+
}
132+
133+
func waitForShutdown(ctx context.Context, cfg *config.Config, log *slog.Logger, app *fiber.App, errCh <-chan error) error {
122134
sigCh := make(chan os.Signal, 1)
123135
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
124136

@@ -132,7 +144,6 @@ func run(ctx context.Context, cfg *config.Config, log *slog.Logger) error {
132144
log.Info("Context canceled")
133145
}
134146

135-
// Graceful shutdown
136147
log.Info("Shutting down gracefully")
137148

138149
shutdownCtx, shutdownCancel := context.WithTimeout(ctx, cfg.Server.ShutdownTimeout)
@@ -146,7 +157,7 @@ func run(ctx context.Context, cfg *config.Config, log *slog.Logger) error {
146157
return nil
147158
}
148159

149-
func setupServer(arcadeRoutes *fiberRoutes.Routes, dashboard *Dashboard, authToken string) *fiber.App {
160+
func setupServer(arcadeRoutes *fiberRoutes.Routes, chaintracksRts *chaintracksRoutes.Routes, dashboard *Dashboard, authToken string) *fiber.App {
150161
app := fiber.New(fiber.Config{
151162
DisableStartupMessage: true,
152163
})
@@ -168,6 +179,13 @@ func setupServer(arcadeRoutes *fiberRoutes.Routes, dashboard *Dashboard, authTok
168179
// Transaction endpoints (ARC-compatible)
169180
arcadeRoutes.Register(app)
170181

182+
// Chaintracks endpoints (block header tracking)
183+
if chaintracksRts != nil {
184+
chaintracksGroup := app.Group("/chaintracks")
185+
chaintracksRts.Register(chaintracksGroup.Group("/v2"))
186+
chaintracksRts.RegisterLegacy(chaintracksGroup.Group("/v1"))
187+
}
188+
171189
// Health check (standalone arcade server only)
172190
app.Get("/health", arcadeRoutes.HandleGetHealth)
173191

config/config.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ type Config struct {
1818
Network string `mapstructure:"network"` // "main", "test", "stn" - Bitcoin network
1919
StoragePath string `mapstructure:"storage_path"` // Data directory for persistent files
2020

21-
LogLevel string `mapstructure:"log_level"` // Log level (debug, info, warn, error)
22-
Server ServerConfig `mapstructure:"server"`
23-
Database DatabaseConfig `mapstructure:"database"`
24-
Events EventsConfig `mapstructure:"events"`
25-
Teranode TeranodeConfig `mapstructure:"teranode"`
26-
P2P p2p.Config `mapstructure:"p2p"`
27-
Validator ValidatorConfig `mapstructure:"validator"`
28-
Auth AuthConfig `mapstructure:"auth"`
29-
Webhook WebhookConfig `mapstructure:"webhook"`
30-
Chaintracks chaintracksconfig.Config `mapstructure:"chaintracks"`
21+
LogLevel string `mapstructure:"log_level"` // Log level (debug, info, warn, error)
22+
Server ServerConfig `mapstructure:"server"`
23+
Database DatabaseConfig `mapstructure:"database"`
24+
Events EventsConfig `mapstructure:"events"`
25+
Teranode TeranodeConfig `mapstructure:"teranode"`
26+
P2P p2p.Config `mapstructure:"p2p"`
27+
Validator ValidatorConfig `mapstructure:"validator"`
28+
Auth AuthConfig `mapstructure:"auth"`
29+
Webhook WebhookConfig `mapstructure:"webhook"`
30+
ChaintracksServer ChaintracksServerConfig `mapstructure:"chaintracks_server"`
31+
Chaintracks chaintracksconfig.Config `mapstructure:"chaintracks"`
3132
}
3233

3334
// SetDefaults sets viper defaults for arcade configuration when used as an embedded library.
@@ -77,6 +78,9 @@ func (c *Config) SetDefaults(v *viper.Viper, prefix string) {
7778
v.SetDefault(p+"webhook.max_age", "24h")
7879
v.SetDefault(p+"webhook.max_retries", 10)
7980

81+
// Chaintracks server defaults
82+
v.SetDefault(p+"chaintracks_server.enabled", true)
83+
8084
// Delegate to external libraries
8185
c.P2P.SetDefaults(v, p+"p2p")
8286
c.Chaintracks.SetDefaults(v, p+"chaintracks")
@@ -133,6 +137,11 @@ type WebhookConfig struct {
133137
MaxRetries int `mapstructure:"max_retries"`
134138
}
135139

140+
// ChaintracksServerConfig holds configuration for the chaintracks HTTP API routes.
141+
type ChaintracksServerConfig struct {
142+
Enabled bool `mapstructure:"enabled"`
143+
}
144+
136145
// GetLogLevel returns the log level, defaulting to "info".
137146
func (c *Config) GetLogLevel() string {
138147
if c.LogLevel != "" {

errors/errors.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// Package errors provides ARC-compatible error types and status codes.
2-
//
3-
//nolint:revive // package name conflicts intentionally - aliasing in imports to avoid conflicts
42
package errors
53

64
import (

go.mod

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,3 @@ require (
283283

284284
// CVE-2025-52881
285285
replace github.com/opencontainers/runc => github.com/opencontainers/runc v1.4.0
286-
287-
// Disabled this replace to test with official sdk
288-
// replace github.com/bsv-blockchain/go-chaintracks => github.com/bsv-blockchain/go-chaintracks v1.0.2-0.20251230043839-6b524e72389d
289-
290-
// Disabled this replace to test with official sdk
291-
// replace github.com/bsv-blockchain/teranode => github.com/bsv-blockchain/teranode v0.13.0-beta-3.0.20251211185306-7879a2f59199

routes/fiber/routes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (r *Routes) handlePostTxs(c *fiber.Ctx) error {
155155
}
156156

157157
// Convert to raw bytes
158-
var rawTxs [][]byte
158+
rawTxs := make([][]byte, 0, len(reqs))
159159
for _, req := range reqs {
160160
data, err := hex.DecodeString(req.RawTx)
161161
if err != nil {

0 commit comments

Comments
 (0)