mirror of
https://github.com/luxfi/node.git
synced 2026-10-30 15:24:05 +00:00
Two packages were named for the same word and meant different things. network/ dialed peers, exchanged keys, throttled and tracked them; nets/ tracked which chains share a validator set and when they have all bootstrapped. One letter apart, and neither name said which was which. The peer layer is mesh — the word this estate already uses for it, in lux-rs/node's own mesh.rs. That frees network for the thing that is actually a network: a set of chains sharing a validator set. A network holds chains; a chain belongs to one network. github.com/luxfi/p2p stays what it is, the gossip library the VMs use. Three concerns, three names, none of them borrowed from another. Co-authored-by: Hanzo Dev <[email protected]>
56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package tracker
|
|
|
|
import (
|
|
"sync/atomic"
|
|
)
|
|
|
|
// NewTargeter creates a new targeter with configurable target usage
|
|
// For disk throttling, VdrAlloc should be in bytes/second (e.g., 1000 GiB)
|
|
// For CPU throttling, VdrAlloc should be the number of CPU cores
|
|
func NewTargeter(config *TargeterConfig) Targeter {
|
|
// Default to a very high value (1 TB/s) to effectively disable throttling
|
|
// unless explicitly configured
|
|
targetUsage := uint64(1024 * 1024 * 1024 * 1024) // 1 TB
|
|
if config != nil {
|
|
if config.VdrAlloc > 0 {
|
|
// If VdrAlloc is specified, use it directly as bytes/second or CPU cores
|
|
// For disk, this should be a large value like 1000 GiB
|
|
// For CPU, this should be the number of CPU cores
|
|
targetUsage = uint64(config.VdrAlloc)
|
|
}
|
|
}
|
|
|
|
t := &targeterImpl{
|
|
targetUsage: targetUsage,
|
|
}
|
|
return t
|
|
}
|
|
|
|
// TargeterConfig defines resource allocation configuration
|
|
type TargeterConfig struct {
|
|
// VdrAlloc is the percentage of resource usage attributed to validators (0-1)
|
|
VdrAlloc float64
|
|
// MaxNonVdrUsage is the max resource usage for non-validators (0-1)
|
|
MaxNonVdrUsage float64
|
|
// MaxNonVdrNodeUsage is the max resource usage per non-validator node (0-1)
|
|
MaxNonVdrNodeUsage float64
|
|
}
|
|
|
|
type targeterImpl struct {
|
|
targetUsage uint64
|
|
}
|
|
|
|
func (t *targeterImpl) TargetUsage() uint64 {
|
|
return atomic.LoadUint64(&t.targetUsage)
|
|
}
|
|
|
|
func (t *targeterImpl) SetTargetUsage(usage uint64) {
|
|
if usage > 100 {
|
|
usage = 100
|
|
}
|
|
atomic.StoreUint64(&t.targetUsage, usage)
|
|
}
|