Skip to content

Commit

Permalink
feat: log blocks (#48)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
  • Loading branch information
wolf31o2 authored May 21, 2024
1 parent 505b65a commit e10d246
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
10 changes: 10 additions & 0 deletions chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ func (n *Node) chainsyncClientRollBackward(
point ocommon.Point,
tip ochainsync.Tip,
) error {
n.config.logger.Info(fmt.Sprintf(
"rollback: slot: %d, hash: %s",
point.Slot,
hex.EncodeToString(point.Hash),
))
n.chainsyncState.Rollback(
point.Slot,
hex.EncodeToString(point.Hash),
Expand Down Expand Up @@ -204,6 +209,11 @@ func (n *Node) chainsyncClientRollForward(
default:
return fmt.Errorf("unexpected block data type: %T", v)
}
n.config.logger.Info(fmt.Sprintf(
"chain extended, new tip: %s at slot %d",
blk.Hash(),
blk.SlotNumber(),
))
n.chainsyncState.AddBlock(
chainsync.ChainsyncBlock{
Point: chainsync.ChainsyncPoint{
Expand Down
6 changes: 3 additions & 3 deletions internal/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (

func Run(logger *slog.Logger) error {
// TODO: make this configurable
l, err := net.Listen("tcp", ":3000")
l, err := net.Listen("tcp", ":3001")
if err != nil {
return err
}
logger.Info("listening for ouroboros node-to-node connections on :3000")
logger.Info("listening for ouroboros node-to-node connections on :3001")
n, err := node.New(
node.NewConfig(
node.WithLogger(logger),
Expand Down Expand Up @@ -60,7 +60,7 @@ func Run(logger *slog.Logger) error {
return err
}
go func() {
if err := n.StartMetrics(logger); err != nil {
if err := n.StartMetrics(); err != nil {
logger.Error("failed to start metrics listener %v", err)
}
}()
Expand Down
5 changes: 2 additions & 3 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
package node

import (
"log/slog"
"net/http"

"github.com/prometheus/client_golang/prometheus/promhttp"
)

func (n *Node) StartMetrics(logger *slog.Logger) error {
func (n *Node) StartMetrics() error {
http.Handle("/metrics", promhttp.Handler())
logger.Info("listening for prometheus metrics connections on :12798")
n.config.logger.Info("listening for prometheus metrics connections on :12798")
// TODO: make this configurable
err := http.ListenAndServe(":12798", nil)
if err != nil {
Expand Down

0 comments on commit e10d246

Please sign in to comment.