Files
zeekayandHanzo Dev d678c2d213 transform: publish upstream simplex as luxfi/bft on luxfi/log
Reapplies the fork's whole delta on top of the merge, as one reviewable diff
rather than 43 conflict resolutions. Nothing here changes consensus behaviour.

- module github.com/luxfi/bft, Go 1.26.4; root package simplex -> bft, which
  would otherwise collide with the simplex/ subpackage under this module name.
- go.uber.org/zap -> github.com/luxfi/log, so common.Logger takes ...log.Field.
  zap.Error maps to log.Err: log.Error is luxfi/log's package-level logging
  function, not a field constructor, and the compiler is the only thing that
  catches that. Needs luxfi/log v1.6.1 for the Stringers constructor.
- avalanchego/ -> host/. The package holds NodeID, VMBlock, Bitmask and size
  limits — the host node's types, vendored to avoid importing a whole node — so
  it is named for what it holds. Renaming it luxd/ would have swapped one brand
  for another and said just as little.
- testutil/logger.go reimplemented without zapcore. Upstream layers a
  keyword-filtering Core, a debug-swallowing Encoder and a Tee because that is
  zap's extension model; luxfi/log has no such seam, so every policy is applied
  in one emit. That also fixes two defects the layering caused:
  SilenceExceptKeywords rebuilt the logger and discarded an installed Intercept
  hook, and the two sinks read different env vars (LOG_LEVEL vs log_level) so
  they disagreed about suppressing debug. Hooks run outside the lock, so a hook
  that logs fails the test instead of deadlocking it. Fatal panics rather than
  exiting, because exiting takes the suite down with no attribution.
- simplex/monitor_test.go keeps a local logger: testutil imports simplex, so an
  internal test cannot import testutil back without closing a cycle.
- README keeps the name Simplex throughout — it is the protocol's own name and
  the subject of reference [1]. Only the deployment target changed. The HyperSDK
  sentence still says Avalanche because that sentence is true.
- Drops the fork's Makefile: it duplicated unit-tests.sh and fuzz.sh, and ran the
  suite with -timeout 30s when simplex alone needs over 100s.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-06 04:21:17 -07:00

84 lines
2.6 KiB
Go

// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package random_network
import (
"fmt"
"io"
"os"
"path/filepath"
"testing"
"github.com/luxfi/bft/common"
"github.com/luxfi/bft/testutil"
)
// CreateNetworkLogger creates a logger for the network that writes to both console and main.log
func CreateNetworkLogger(t *testing.T, config *FuzzConfig) *testutil.TestLogger {
if config.LogDirectory == "" {
return testutil.MakeLogger(t, 0)
}
// Clear the log directory before creating new logs
if err := clearLogDirectory(config.LogDirectory); err != nil {
t.Fatalf("Failed to clear log directory: %v", err)
}
// Create file writer for main.log
fileWriter, err := setupFileOutput(t, config.LogDirectory, "main.log")
if err != nil {
t.Fatalf("Failed to setup file output for main.log: %v", err)
}
return testutil.MakeLoggerWithFile(t, fileWriter, true)
}
// CreateNodeLogger creates a logger for a node that writes to both console and {nodeID}.log
func CreateNodeLogger(t *testing.T, config *FuzzConfig, nodeID common.NodeID) *testutil.TestLogger {
if config.LogDirectory == "" {
return testutil.MakeLogger(t, int(nodeID[0]))
}
filename := fmt.Sprintf("%s.log", nodeID.String())
// Create file writer for node-specific log
fileWriter, err := setupFileOutput(t, config.LogDirectory, filename)
if err != nil {
t.Fatalf("Failed to setup file output for %s: %v", filename, err)
}
return testutil.MakeLoggerWithFile(t, fileWriter, false, int(nodeID[0]))
}
// setupFileOutput creates a file for logging and returns it as a writer.
// The file is closed automatically when the test ends.
func setupFileOutput(t *testing.T, logDir, filename string) (io.Writer, error) {
// Create log directory if it doesn't exist
if err := os.MkdirAll(logDir, 0755); err != nil {
return nil, fmt.Errorf("failed to create log directory %s: %w", logDir, err)
}
// Create full path
logPath := filepath.Join(logDir, filename)
// Open file for appending (create if doesn't exist)
file, err := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return nil, fmt.Errorf("failed to open log file %s: %w", logPath, err)
}
t.Cleanup(func() { file.Close() })
// Concurrent writes are serialised by the logger, so the file needs no wrapper.
return file, nil
}
// clearLogDirectory removes the contents of the log directory
func clearLogDirectory(logDir string) error {
if err := os.RemoveAll(logDir); err != nil {
return fmt.Errorf("failed to remove log directory %s: %w", logDir, err)
}
return nil
}