Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ coverage.html
# Local config
config.local.yaml

# Project
ISSUES.md

# OS
.DS_Store
Thumbs.db
65 changes: 61 additions & 4 deletions cmd/apex/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package main

import (
"context"
"errors"
"fmt"
"os"
"os/signal"
"syscall"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"

"github.com/evstack/apex/config"
"github.com/evstack/apex/pkg/fetch"
"github.com/evstack/apex/pkg/store"
syncer "github.com/evstack/apex/pkg/sync"
)

// Set via ldflags at build time.
Expand Down Expand Up @@ -90,10 +97,7 @@ func startCmd() *cobra.Command {
Int("namespaces", len(cfg.DataSource.Namespaces)).
Msg("starting apex indexer")

// TODO(phase1): wire store, fetcher, and sync coordinator.
log.Info().Msg("apex indexer is not yet implemented — scaffolding only")

return nil
return runIndexer(cmd.Context(), cfg)
},
}
}
Expand All @@ -112,3 +116,56 @@ func setupLogger(cfg config.LogConfig) {
log.Logger = log.Output(os.Stdout)
}
}

func runIndexer(ctx context.Context, cfg *config.Config) error {
// Parse namespaces from config.
namespaces, err := cfg.ParsedNamespaces()
if err != nil {
return fmt.Errorf("parse namespaces: %w", err)
}

// Open store.
db, err := store.Open(cfg.Storage.DBPath)
if err != nil {
return fmt.Errorf("open store: %w", err)
}
defer db.Close() //nolint:errcheck

// Persist configured namespaces.
ctx, stop := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
defer stop()

for _, ns := range namespaces {
if err := db.PutNamespace(ctx, ns); err != nil {
return fmt.Errorf("put namespace: %w", err)
}
}

// Connect to Celestia node.
fetcher, err := fetch.NewCelestiaNodeFetcher(ctx, cfg.DataSource.CelestiaNodeURL, cfg.DataSource.AuthToken, log.Logger)
if err != nil {
return fmt.Errorf("connect to celestia node: %w", err)
}
defer fetcher.Close() //nolint:errcheck

// Build and run the sync coordinator.
coord := syncer.New(db, fetcher,
syncer.WithStartHeight(cfg.Sync.StartHeight),
syncer.WithBatchSize(cfg.Sync.BatchSize),
syncer.WithConcurrency(cfg.Sync.Concurrency),
syncer.WithLogger(log.Logger),
)

log.Info().
Int("namespaces", len(namespaces)).
Uint64("start_height", cfg.Sync.StartHeight).
Msg("sync coordinator starting")

err = coord.Run(ctx)
if err != nil && !errors.Is(err, context.Canceled) {
return fmt.Errorf("coordinator: %w", err)
}

log.Info().Msg("apex indexer stopped")
return nil
}
22 changes: 21 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,35 @@ module github.com/evstack/apex
go 1.24.0

require (
github.com/filecoin-project/go-jsonrpc v0.10.1
github.com/rs/zerolog v1.34.0
github.com/spf13/cobra v1.10.2
gopkg.in/yaml.v3 v3.0.1
modernc.org/sqlite v1.46.1
)

require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/ipfs/go-log/v2 v2.0.8 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/ncruces/go-strftime v1.0.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/spf13/pflag v1.0.9 // indirect
go.opencensus.io v0.22.3 // indirect
go.uber.org/atomic v1.6.0 // indirect
go.uber.org/multierr v1.5.0 // indirect
go.uber.org/zap v1.14.1 // indirect
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
modernc.org/libc v1.67.6 // indirect
modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.11.0 // indirect
)
159 changes: 157 additions & 2 deletions go.sum

Large diffs are not rendered by default.

Loading