Skip to content
Closed
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
62 changes: 62 additions & 0 deletions scripts/warp_measures.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#! /bin/bash
set -eu

# TODO:
# Just make a bunch of calls, recording timestamp and height called
# Calls may be alternated among height and getValidatorsAt
# All the other data can be retrieved from prometheus and processed by hand.

avalanche_node_addr="127.0.0.1:9650/"
p_chain_endpoint=$avalanche_node_addr"ext/bc/P"

temp_height_file="/tmp/warp_height_file.json"
cat > "${temp_height_file}" << EOF
{
"jsonrpc": "2.0",
"method": "platform.getHeight",
"params": {},
"id": 1
}
EOF

timestamp=$(date +%s)
echo $timestamp "START"

for depth in {10000..1..50}; do
height_call=$(curl $p_chain_endpoint -X POST -H 'content-type:application/json' --silent --data "@${temp_height_file}")
if [ $? -ne 0 ]; then
echo "height call errored. Exiting"
exit 1
fi

current_height=$(echo $height_call | jq -r '."result"."height"')
timestamp=$(date +%s)
echo $timestamp "current height" $current_height

polled_height=$(($current_height - depth))

temp_validatorsAt_file="/tmp/warp_validators_at_file.json"
cat > "${temp_validatorsAt_file}" << EOF
{
"jsonrpc": "2.0",
"method": "platform.getValidatorsAt",
"params": {
"height":$polled_height
},
"id": 1
}
EOF

validators_call=$(curl $p_chain_endpoint -X POST -H 'content-type:application/json' --silent --data "@${temp_validatorsAt_file}")
if [ $? -ne 0 ]; then
echo "validators at call errored. Exiting"
exit 1
fi
timestamp=$(date +%s)
echo $timestamp "validtrs height" $polled_height

sleep 30
done

timestamp=$(date +%s)
echo $timestamp "DONE"
21 changes: 17 additions & 4 deletions vms/platformvm/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type Metrics interface {
// Mark that we computed a validator diff at a height with the given
// difference from the top.
AddValidatorSetsHeightDiff(uint64)

AddValidatorSetsOpsCountDiff(uint)
// Mark that this much stake is staked on the node.
SetLocalStake(uint64)
// Mark that this much stake is staked in the network.
Expand Down Expand Up @@ -122,6 +124,11 @@ func New(
Name: "validator_sets_height_diff_sum",
Help: "Total number of validator sets diffs applied for generating validator sets",
}),
validatorSetsOpsCountDiff: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_sets_diffs_ops_count_sum",
Help: "Total number of validator sets operations in diffs for generating validator sets",
}),
validatorSetsDuration: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "validator_sets_duration_sum",
Expand All @@ -148,6 +155,7 @@ func New(
registerer.Register(m.validatorSetsCreated),
registerer.Register(m.validatorSetsCached),
registerer.Register(m.validatorSetsHeightDiff),
registerer.Register(m.validatorSetsOpsCountDiff),
registerer.Register(m.validatorSetsDuration),
)

Expand All @@ -173,10 +181,11 @@ type metrics struct {

numVotesWon, numVotesLost prometheus.Counter

validatorSetsCached prometheus.Counter
validatorSetsCreated prometheus.Counter
validatorSetsHeightDiff prometheus.Gauge
validatorSetsDuration prometheus.Gauge
validatorSetsCached prometheus.Counter
validatorSetsCreated prometheus.Counter
validatorSetsHeightDiff prometheus.Gauge
validatorSetsOpsCountDiff prometheus.Gauge
validatorSetsDuration prometheus.Gauge
}

func (m *metrics) MarkOptionVoteWon() {
Expand Down Expand Up @@ -207,6 +216,10 @@ func (m *metrics) AddValidatorSetsHeightDiff(d uint64) {
m.validatorSetsHeightDiff.Add(float64(d))
}

func (m *metrics) AddValidatorSetsOpsCountDiff(d uint) {
m.validatorSetsOpsCountDiff.Add(float64(d))
}

func (m *metrics) SetLocalStake(s uint64) {
m.localStake.Set(float64(s))
}
Expand Down
2 changes: 2 additions & 0 deletions vms/platformvm/metrics/no_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func (noopMetrics) AddValidatorSetsDuration(time.Duration) {}

func (noopMetrics) AddValidatorSetsHeightDiff(uint64) {}

func (noopMetrics) AddValidatorSetsOpsCountDiff(uint) {}

func (noopMetrics) SetLocalStake(uint64) {}

func (noopMetrics) SetTotalStake(uint64) {}
Expand Down
45 changes: 15 additions & 30 deletions vms/platformvm/validators/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"time"

"github.com/ava-labs/avalanchego/cache"
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/validators"
Expand All @@ -24,7 +23,6 @@ import (
)

const (
validatorSetsCacheSize = 64
maxRecentlyAcceptedWindowSize = 256
recentlyAcceptedWindowTTL = 5 * time.Minute
)
Expand Down Expand Up @@ -56,7 +54,6 @@ func NewManager(
state: state,
metrics: metrics,
clk: clk,
caches: make(map[ids.ID]cache.Cacher[uint64, map[ids.NodeID]*validators.GetValidatorOutput]),
recentlyAccepted: window.New[ids.ID](
window.Config{
Clock: clk,
Expand All @@ -73,10 +70,7 @@ type manager struct {
metrics metrics.Metrics
clk *mockable.Clock

// Maps caches for each subnet that is currently tracked.
// Key: Subnet ID
// Value: cache mapping height -> validator set map
caches map[ids.ID]cache.Cacher[uint64, map[ids.NodeID]*validators.GetValidatorOutput]
// dropped caches to simulate worst case scenario when serving validators set

// sliding window of blocks that were recently accepted
recentlyAccepted window.Window[ids.ID]
Expand Down Expand Up @@ -132,20 +126,6 @@ func (m *manager) GetCurrentHeight(context.Context) (uint64, error) {
}

func (m *manager) GetValidatorSet(ctx context.Context, height uint64, subnetID ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error) {
validatorSetsCache, exists := m.caches[subnetID]
if !exists {
validatorSetsCache = &cache.LRU[uint64, map[ids.NodeID]*validators.GetValidatorOutput]{Size: validatorSetsCacheSize}
// Only cache tracked subnets
if subnetID == constants.PrimaryNetworkID || m.cfg.TrackedSubnets.Contains(subnetID) {
m.caches[subnetID] = validatorSetsCache
}
}

if validatorSet, ok := validatorSetsCache.Get(height); ok {
m.metrics.IncValidatorSetsCached()
return validatorSet, nil
}

lastAcceptedHeight, err := m.GetCurrentHeight(ctx)
if err != nil {
return nil, err
Expand Down Expand Up @@ -185,33 +165,34 @@ func (m *manager) GetValidatorSet(ctx context.Context, height uint64, subnetID i
}
}

totalOpsCount := uint(0)
for diffHeight := lastAcceptedHeight; diffHeight > height; diffHeight-- {
err := m.applyValidatorDiffs(vdrSet, subnetID, diffHeight)
opsCount, err := m.applyValidatorDiffs(vdrSet, subnetID, diffHeight)
if err != nil {
return nil, err
}
totalOpsCount += opsCount
}

// cache the validator set
validatorSetsCache.Put(height, vdrSet)

endTime := m.clk.Time()
m.metrics.IncValidatorSetsCreated()
m.metrics.AddValidatorSetsDuration(endTime.Sub(startTime))
m.metrics.AddValidatorSetsHeightDiff(lastAcceptedHeight - height)
m.metrics.AddValidatorSetsOpsCountDiff(totalOpsCount)
return vdrSet, nil
}

func (m *manager) applyValidatorDiffs(
vdrSet map[ids.NodeID]*validators.GetValidatorOutput,
subnetID ids.ID,
height uint64,
) error {
) (uint, error) {
weightDiffs, err := m.state.GetValidatorWeightDiffs(height, subnetID)
if err != nil {
return err
return 0, err
}

opsCount := uint(0)
for nodeID, weightDiff := range weightDiffs {
vdr, ok := vdrSet[nodeID]
if !ok {
Expand All @@ -220,6 +201,7 @@ func (m *manager) applyValidatorDiffs(
NodeID: nodeID,
}
vdrSet[nodeID] = vdr
opsCount++
}

// The weight of this node changed at this block.
Expand All @@ -232,20 +214,22 @@ func (m *manager) applyValidatorDiffs(
// prior block it was lower.
vdr.Weight, err = math.Sub(vdr.Weight, weightDiff.Amount)
}
opsCount++
if err != nil {
return err
return 0, err
}

if vdr.Weight == 0 {
// The validator's weight was 0 before this block so
// they weren't in the validator set.
delete(vdrSet, nodeID)
opsCount++
}
}

pkDiffs, err := m.state.GetValidatorPublicKeyDiffs(height)
if err != nil {
return err
return 0, err
}

for nodeID, pk := range pkDiffs {
Expand All @@ -256,9 +240,10 @@ func (m *manager) applyValidatorDiffs(
// The validator's public key was removed at this block, so it
// was in the validator set before.
vdr.PublicKey = pk
opsCount++
}
}
return nil
return opsCount, nil
}

func (m *manager) GetSubnetID(_ context.Context, chainID ids.ID) (ids.ID, error) {
Expand Down