Skip to content
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
3 changes: 2 additions & 1 deletion network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/ava-labs/avalanchego/utils/math/meter"
"github.com/ava-labs/avalanchego/utils/resource"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/utils/timer/mockable"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/version"
)
Expand Down Expand Up @@ -114,7 +115,7 @@ var (

CompressionType: constants.DefaultNetworkCompressionType,

UptimeCalculator: uptime.NewManager(uptime.NewTestState()),
UptimeCalculator: uptime.NewManager(uptime.NewTestState(), &mockable.Clock{}),
UptimeMetricFreq: 30 * time.Second,
UptimeRequirement: .8,

Expand Down
16 changes: 4 additions & 12 deletions snow/uptime/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/ava-labs/avalanchego/utils/timer/mockable"
)

var _ TestManager = (*manager)(nil)
var _ Manager = (*manager)(nil)

type Manager interface {
Tracker
Expand All @@ -35,22 +35,18 @@ type Calculator interface {
CalculateUptimePercentFrom(nodeID ids.NodeID, subnetID ids.ID, startTime time.Time) (float64, error)
}

type TestManager interface {
Manager
SetTime(time.Time)
}

type manager struct {
// Used to get time. Useful for faking time during tests.
clock mockable.Clock
clock *mockable.Clock

state State
connections map[ids.NodeID]map[ids.ID]time.Time // nodeID -> subnetID -> time
trackedSubnets set.Set[ids.ID]
}

func NewManager(state State) Manager {
func NewManager(state State, clk *mockable.Clock) Manager {
return &manager{
clock: clk,
state: state,
connections: make(map[ids.NodeID]map[ids.ID]time.Time),
}
Expand Down Expand Up @@ -206,10 +202,6 @@ func (m *manager) CalculateUptimePercentFrom(nodeID ids.NodeID, subnetID ids.ID,
return uptime, nil
}

func (m *manager) SetTime(newTime time.Time) {
m.clock.Set(newTime)
}

// updateSubnetUptime updates the subnet uptime of the node on the state by the amount
// of time that the node has been connected to the subnet.
func (m *manager) updateSubnetUptime(nodeID ids.NodeID, subnetID ids.ID) error {
Expand Down
Loading