Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

feat: improve logging for Station #62

Merged
merged 1 commit into from
Sep 1, 2022
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
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,23 @@ At present, the L2 implementation has the following features:
```
./saturn-l2
...
Server listening on 127.0.0.1:52860
WebUI: http://localhost:52860/webui
API: http://localhost:52860/
...
```

When an L2 connects/disconnects with an L1 it will log the following at the INFO log level
When an L2 connects/disconnects with an L1 it prints this to standard output:

```
new L1 connection established {"l1": "127.0.0.1:59003", "nL1sConnected": 2}
lost connection to L1 {"l1": "127.0.0.1:59003", "nL1sConnected": 1}
INFO: Saturn Node is online and connected to 1 peer(s)
INFO: Saturn Node is online and connected to 2 peer(s)
INFO: Saturn Node is online and connected to 1 peer(s)
ERROR: Saturn Node lost connection to the network
```

If you want to connect to `WebUI`, also run `./scripts/download-webui.sh`.

Note that the the Saturn L2 node only binds to the **localhost** loopback network interface and so will only be reachable from the same machine.
Note that the Saturn L2 node only binds to the **localhost** loopback network interface and so will only be reachable from the same machine.
In the above snippet, `52860` is the port that the Saturn L2 node binds to on the localhost interface. This port can be configured using the `PORT` environment variable as mentioned above.

### HTTP APIs
Expand Down
5 changes: 3 additions & 2 deletions cmd/saturn-l2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,9 @@ func main() {
}

port := nl.Addr().(*net.TCPAddr).Port
fmt.Println("Server listening on", nl.Addr())
log.Infof("Server listening on %v", nl.Addr())
fmt.Printf("WebUI: http://localhost:%d/webui\n", port)
fmt.Printf("API: http://localhost:%d/\n", port)

if err := srv.Serve(nl); err != http.ErrServerClosed {
fmt.Fprintf(os.Stderr, "error shutting down the server: %s", err.Error())
Expand Down Expand Up @@ -335,7 +336,7 @@ func mkConfig() (config, error) {
if _, err := os.Stat(rootDirStr); err != nil {
return config{}, fmt.Errorf("root dir %s does NOT exist", rootDirStr)
}
fmt.Printf("Using root dir %s\n", rootDirStr)
log.Infof("Using root dir %s\n", rootDirStr)

var l1IPAddrs L1IPAddrs
var useL1IPAddrs bool
Expand Down
19 changes: 15 additions & 4 deletions l1interop/l1sseclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ func (l *l1SseClient) Start(nConnectedl1s *atomic.Uint64) error {

// we've registered successfully -> reset the backoff counter
backoff.Reset()
nConnectedl1s.Inc()
log.Infow("new L1 connection established", "l1", l.l1Addr, "nL1sConnected", nConnectedl1s.Load())
n := nConnectedl1s.Inc()
log.Infow("new L1 connection established", "l1", l.l1Addr, "nL1sConnected", n)
reportConnectionStatus(n)

// we've successfully connected to the L1, start reading new line delimited json requests for CAR files
scanner := bufio.NewScanner(resp.Body)
Expand Down Expand Up @@ -224,8 +225,18 @@ func (l *l1SseClient) Start(nConnectedl1s *atomic.Uint64) error {
log.Errorw("error while reading l1 requests; will reconnect and retry", "err", err)
}

nConnectedl1s.Dec()
log.Infow("lost connection to L1", "l1", l.l1Addr, "nL1sConnected", nConnectedl1s.Load())
n = nConnectedl1s.Dec()
log.Infow("lost connection to L1", "l1", l.l1Addr, "nL1sConnected", n)
reportConnectionStatus(n)
}
}

func reportConnectionStatus(nConnectedl1s uint64) {
// Report the connection status to Filecoin Station
if nConnectedl1s > 0 {
fmt.Printf("INFO: Saturn Node is online and connected to %v peer(s)\n", nConnectedl1s)
} else {
fmt.Print("ERROR: Saturn Node lost connection to the network\n")
juliangruber marked this conversation as resolved.
Show resolved Hide resolved
bajtos marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down