mirror of
https://github.com/luxfi/node.git
synced 2026-10-30 15:24:05 +00:00
The module already called itself github.com/luxfi/node while containing no node in Go: cmd/luxd was twenty-one lines that printed the size of a few types, and the Go column of the matrix measured a VM plugin. A repo that fetches the thing it claims to be has not replaced it, so the Go sources move in — 1515 files, the daemon and everything under it — and the build reaches outside this module for nothing. Rust and C++ sit beside it unchanged and are still measured against it by the differential. That is the point of one repo: the reference implementation and the two ports are the same checkout, so parity is a thing you can run rather than a thing you assert. Verified: builds, and the closure carries no lux-private — checked at build time rather than believed. The daemon starts twelve chains on a local network (P X C Q Z A B G K M F, plus D through its plugin) and reports healthy.
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
//go:build linux || netbsd || openbsd
|
|
|
|
package ulimit
|
|
|
|
import (
|
|
"fmt"
|
|
"syscall"
|
|
|
|
"github.com/luxfi/log"
|
|
)
|
|
|
|
const DefaultFDLimit = 32 * 1024
|
|
|
|
// Set attempts to bump the Rlimit which has a soft (Cur) and a hard (Max) value.
|
|
// The soft limit is what is used by the kernel to report EMFILE errors. The hard
|
|
// limit is a secondary limit which the process can be bumped to without additional
|
|
// privileges. Bumping the Max limit further would require superuser privileges.
|
|
// If the current Max is below our recommendation we will warn on start.
|
|
// see: http://0pointer.net/blog/file-descriptor-limits.html
|
|
func Set(limit uint64, log log.Logger) error {
|
|
var rLimit syscall.Rlimit
|
|
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
|
if err != nil {
|
|
return fmt.Errorf("error getting rlimit: %w", err)
|
|
}
|
|
|
|
if limit > rLimit.Max {
|
|
return fmt.Errorf("error fd-limit: (%d) greater than max: (%d)", limit, rLimit.Max)
|
|
}
|
|
|
|
rLimit.Cur = limit
|
|
|
|
// set new limit
|
|
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil {
|
|
return fmt.Errorf("error setting fd-limit: %w", err)
|
|
}
|
|
|
|
// verify limit
|
|
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil {
|
|
return fmt.Errorf("error getting rlimit: %w", err)
|
|
}
|
|
|
|
if rLimit.Cur < DefaultFDLimit {
|
|
log.Warn("fd-limit is less than recommended and could result in reduced performance",
|
|
"currentLimit", rLimit.Cur,
|
|
"recommendedLimit", DefaultFDLimit,
|
|
)
|
|
}
|
|
|
|
return nil
|
|
}
|