From 7fe18e9968041eed15274c543cb5f0b7db7eb2c6 Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Thu, 25 May 2023 11:23:45 +0200 Subject: [PATCH 01/11] dropped validators set cache to bench worst case scenario --- vms/platformvm/validators/manager.go | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/vms/platformvm/validators/manager.go b/vms/platformvm/validators/manager.go index 7ded28c7c4e5..1d5b794ab47c 100644 --- a/vms/platformvm/validators/manager.go +++ b/vms/platformvm/validators/manager.go @@ -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" @@ -24,7 +23,6 @@ import ( ) const ( - validatorSetsCacheSize = 64 maxRecentlyAcceptedWindowSize = 256 recentlyAcceptedWindowTTL = 5 * time.Minute ) @@ -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, @@ -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] @@ -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 @@ -192,9 +172,6 @@ func (m *manager) GetValidatorSet(ctx context.Context, height uint64, subnetID i } } - // cache the validator set - validatorSetsCache.Put(height, vdrSet) - endTime := m.clk.Time() m.metrics.IncValidatorSetsCreated() m.metrics.AddValidatorSetsDuration(endTime.Sub(startTime)) From 8d7bc2e64baf636e0c4a7ab4ab7f60efe6ebd228 Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Thu, 25 May 2023 12:57:32 +0200 Subject: [PATCH 02/11] wip: added fake subnet validators for benchmarks --- vms/platformvm/vm.go | 90 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/vms/platformvm/vm.go b/vms/platformvm/vm.go index b2d3c7ef2f94..5657288214fd 100644 --- a/vms/platformvm/vm.go +++ b/vms/platformvm/vm.go @@ -41,6 +41,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/metrics" "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/state" + "github.com/ava-labs/avalanchego/vms/platformvm/status" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool" "github.com/ava-labs/avalanchego/vms/platformvm/utxo" @@ -205,7 +206,94 @@ func (vm *VM) Initialize( chainCtx.Log.Info("initializing last accepted", zap.Stringer("blkID", lastAcceptedID), ) - return vm.SetPreference(ctx, lastAcceptedID) + if err := vm.SetPreference(ctx, lastAcceptedID); err != nil { + return err + } + + return vm.loadFakeSubnetForBenchmarks() +} + +func (vm *VM) loadFakeSubnetForBenchmarks() error { + // duly create a fake subnet + unsignedSubnetTx := &txs.CreateSubnetTx{ + BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ + NetworkID: vm.ctx.NetworkID, + BlockchainID: vm.ctx.ChainID, + Ins: []*avax.TransferableInput{}, + Outs: []*avax.TransferableOutput{}, + }}, + Owner: &secp256k1fx.OutputOwners{ + Threshold: 1, + Addrs: []ids.ShortID{ids.GenerateTestShortID()}, + }, + } + subnetTx, err := txs.NewSigned(unsignedSubnetTx, txs.Codec, nil) + if err != nil { + return fmt.Errorf("failed signing fake subnet tx, %w", err) + } + if err := subnetTx.SyntacticVerify(vm.ctx); err != nil { + return fmt.Errorf("failed sintax verification of fake subnet tx, %w", err) + } + fakeSubnetID := subnetTx.ID() + + vm.state.AddSubnet(subnetTx) + vm.state.AddTx(subnetTx, status.Committed) + if err := vm.state.Commit(); err != nil { + return fmt.Errorf("failed committing fake subnet, %w", err) + } + + // promote all primary network validators to fake subnet validators + primaryVals, ok := vm.Config.Validators.Get(constants.PrimaryNetworkID) + if !ok { + return pvalidators.ErrMissingValidator + } + primaryValsList := primaryVals.List() + diff, err := state.NewDiff(vm.state.GetLastAccepted(), vm.manager) + if err != nil { + return fmt.Errorf("could not create diff for fake subnet, %w", err) + } + for _, val := range primaryValsList { + unsignedAddSubnetVal := &txs.AddSubnetValidatorTx{ + BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ + NetworkID: vm.ctx.NetworkID, + BlockchainID: vm.ctx.ChainID, + Ins: []*avax.TransferableInput{}, + Outs: []*avax.TransferableOutput{}, + }}, + SubnetValidator: txs.SubnetValidator{ + Validator: txs.Validator{ + NodeID: val.NodeID, + Start: uint64(vm.state.GetTimestamp().Unix()), + End: uint64(mockable.MaxTime.Unix()), + Wght: 10, + }, + Subnet: fakeSubnetID, + }, + SubnetAuth: &secp256k1fx.Input{ + SigIndices: []uint32{0, 1}, + }, + } + addSubnetVal, err := txs.NewSigned(unsignedAddSubnetVal, txs.Codec, nil) + if err != nil { + return fmt.Errorf("failed signing fake subnet tx, %w", err) + } + if err := addSubnetVal.SyntacticVerify(vm.ctx); err != nil { + return fmt.Errorf("failed sintax verification of fake subnet tx, %w", err) + } + + staker, err := state.NewCurrentStaker(addSubnetVal.TxID, unsignedAddSubnetVal, 10) + if err != nil { + return fmt.Errorf("failed creating staker object from stakerTx, %w", err) + } + + diff.AddTx(addSubnetVal, status.Committed) + diff.PutCurrentValidator(staker) + } + if err := diff.Apply(vm.state); err != nil { + return fmt.Errorf("failed applying diff, %w", err) + } + + return nil } // Create all chains that exist that this node validates. From 639c636160503ae21aa1ced18080457f89c071ac Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Thu, 25 May 2023 15:41:23 +0200 Subject: [PATCH 03/11] reverted fake subnet --- vms/platformvm/vm.go | 90 +------------------------------------------- 1 file changed, 1 insertion(+), 89 deletions(-) diff --git a/vms/platformvm/vm.go b/vms/platformvm/vm.go index 5657288214fd..b2d3c7ef2f94 100644 --- a/vms/platformvm/vm.go +++ b/vms/platformvm/vm.go @@ -41,7 +41,6 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/metrics" "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/state" - "github.com/ava-labs/avalanchego/vms/platformvm/status" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool" "github.com/ava-labs/avalanchego/vms/platformvm/utxo" @@ -206,94 +205,7 @@ func (vm *VM) Initialize( chainCtx.Log.Info("initializing last accepted", zap.Stringer("blkID", lastAcceptedID), ) - if err := vm.SetPreference(ctx, lastAcceptedID); err != nil { - return err - } - - return vm.loadFakeSubnetForBenchmarks() -} - -func (vm *VM) loadFakeSubnetForBenchmarks() error { - // duly create a fake subnet - unsignedSubnetTx := &txs.CreateSubnetTx{ - BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ - NetworkID: vm.ctx.NetworkID, - BlockchainID: vm.ctx.ChainID, - Ins: []*avax.TransferableInput{}, - Outs: []*avax.TransferableOutput{}, - }}, - Owner: &secp256k1fx.OutputOwners{ - Threshold: 1, - Addrs: []ids.ShortID{ids.GenerateTestShortID()}, - }, - } - subnetTx, err := txs.NewSigned(unsignedSubnetTx, txs.Codec, nil) - if err != nil { - return fmt.Errorf("failed signing fake subnet tx, %w", err) - } - if err := subnetTx.SyntacticVerify(vm.ctx); err != nil { - return fmt.Errorf("failed sintax verification of fake subnet tx, %w", err) - } - fakeSubnetID := subnetTx.ID() - - vm.state.AddSubnet(subnetTx) - vm.state.AddTx(subnetTx, status.Committed) - if err := vm.state.Commit(); err != nil { - return fmt.Errorf("failed committing fake subnet, %w", err) - } - - // promote all primary network validators to fake subnet validators - primaryVals, ok := vm.Config.Validators.Get(constants.PrimaryNetworkID) - if !ok { - return pvalidators.ErrMissingValidator - } - primaryValsList := primaryVals.List() - diff, err := state.NewDiff(vm.state.GetLastAccepted(), vm.manager) - if err != nil { - return fmt.Errorf("could not create diff for fake subnet, %w", err) - } - for _, val := range primaryValsList { - unsignedAddSubnetVal := &txs.AddSubnetValidatorTx{ - BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ - NetworkID: vm.ctx.NetworkID, - BlockchainID: vm.ctx.ChainID, - Ins: []*avax.TransferableInput{}, - Outs: []*avax.TransferableOutput{}, - }}, - SubnetValidator: txs.SubnetValidator{ - Validator: txs.Validator{ - NodeID: val.NodeID, - Start: uint64(vm.state.GetTimestamp().Unix()), - End: uint64(mockable.MaxTime.Unix()), - Wght: 10, - }, - Subnet: fakeSubnetID, - }, - SubnetAuth: &secp256k1fx.Input{ - SigIndices: []uint32{0, 1}, - }, - } - addSubnetVal, err := txs.NewSigned(unsignedAddSubnetVal, txs.Codec, nil) - if err != nil { - return fmt.Errorf("failed signing fake subnet tx, %w", err) - } - if err := addSubnetVal.SyntacticVerify(vm.ctx); err != nil { - return fmt.Errorf("failed sintax verification of fake subnet tx, %w", err) - } - - staker, err := state.NewCurrentStaker(addSubnetVal.TxID, unsignedAddSubnetVal, 10) - if err != nil { - return fmt.Errorf("failed creating staker object from stakerTx, %w", err) - } - - diff.AddTx(addSubnetVal, status.Committed) - diff.PutCurrentValidator(staker) - } - if err := diff.Apply(vm.state); err != nil { - return fmt.Errorf("failed applying diff, %w", err) - } - - return nil + return vm.SetPreference(ctx, lastAcceptedID) } // Create all chains that exist that this node validates. From 7f4e109a8fcb28c1fb381537c0ef9fc397e0245b Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Thu, 25 May 2023 16:33:05 +0200 Subject: [PATCH 04/11] nit --- vms/platformvm/validators/manager.go | 1 - 1 file changed, 1 deletion(-) diff --git a/vms/platformvm/validators/manager.go b/vms/platformvm/validators/manager.go index 1d5b794ab47c..ab89c225878b 100644 --- a/vms/platformvm/validators/manager.go +++ b/vms/platformvm/validators/manager.go @@ -173,7 +173,6 @@ func (m *manager) GetValidatorSet(ctx context.Context, height uint64, subnetID i } endTime := m.clk.Time() - m.metrics.IncValidatorSetsCreated() m.metrics.AddValidatorSetsDuration(endTime.Sub(startTime)) m.metrics.AddValidatorSetsHeightDiff(lastAcceptedHeight - height) return vdrSet, nil From 8bd92da0806c9db904107416b6d80a8332f768bc Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Thu, 25 May 2023 21:27:37 +0200 Subject: [PATCH 05/11] fix following code review --- vms/platformvm/validators/manager.go | 1 + 1 file changed, 1 insertion(+) diff --git a/vms/platformvm/validators/manager.go b/vms/platformvm/validators/manager.go index ab89c225878b..1d5b794ab47c 100644 --- a/vms/platformvm/validators/manager.go +++ b/vms/platformvm/validators/manager.go @@ -173,6 +173,7 @@ func (m *manager) GetValidatorSet(ctx context.Context, height uint64, subnetID i } endTime := m.clk.Time() + m.metrics.IncValidatorSetsCreated() m.metrics.AddValidatorSetsDuration(endTime.Sub(startTime)) m.metrics.AddValidatorSetsHeightDiff(lastAcceptedHeight - height) return vdrSet, nil From 6cb965715b8c0b64994ed9630758e4de803bcea5 Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Fri, 26 May 2023 13:14:30 +0200 Subject: [PATCH 06/11] =?UTF-8?q?fixed=20validators=20set=20metrics=C2=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vms/platformvm/metrics/metrics.go | 12 ++++++------ vms/platformvm/metrics/no_op.go | 4 ++-- vms/platformvm/validators/manager.go | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/vms/platformvm/metrics/metrics.go b/vms/platformvm/metrics/metrics.go index b1ff4af89544..39b86ce4cb3c 100644 --- a/vms/platformvm/metrics/metrics.go +++ b/vms/platformvm/metrics/metrics.go @@ -31,10 +31,10 @@ type Metrics interface { // Mark that a validator set was cached. IncValidatorSetsCached() // Mark that we spent the given time computing validator diffs. - AddValidatorSetsDuration(time.Duration) + SetValidatorSetsDuration(time.Duration) // Mark that we computed a validator diff at a height with the given // difference from the top. - AddValidatorSetsHeightDiff(uint64) + SetValidatorSetsHeightDiff(uint64) // Mark that this much stake is staked on the node. SetLocalStake(uint64) // Mark that this much stake is staked in the network. @@ -199,12 +199,12 @@ func (m *metrics) IncValidatorSetsCached() { m.validatorSetsCached.Inc() } -func (m *metrics) AddValidatorSetsDuration(d time.Duration) { - m.validatorSetsDuration.Add(float64(d)) +func (m *metrics) SetValidatorSetsDuration(d time.Duration) { + m.validatorSetsDuration.Set(float64(d)) } -func (m *metrics) AddValidatorSetsHeightDiff(d uint64) { - m.validatorSetsHeightDiff.Add(float64(d)) +func (m *metrics) SetValidatorSetsHeightDiff(d uint64) { + m.validatorSetsHeightDiff.Set(float64(d)) } func (m *metrics) SetLocalStake(s uint64) { diff --git a/vms/platformvm/metrics/no_op.go b/vms/platformvm/metrics/no_op.go index d5948348f86b..a7a3b23f18d9 100644 --- a/vms/platformvm/metrics/no_op.go +++ b/vms/platformvm/metrics/no_op.go @@ -35,9 +35,9 @@ func (noopMetrics) IncValidatorSetsCreated() {} func (noopMetrics) IncValidatorSetsCached() {} -func (noopMetrics) AddValidatorSetsDuration(time.Duration) {} +func (noopMetrics) SetValidatorSetsDuration(time.Duration) {} -func (noopMetrics) AddValidatorSetsHeightDiff(uint64) {} +func (noopMetrics) SetValidatorSetsHeightDiff(uint64) {} func (noopMetrics) SetLocalStake(uint64) {} diff --git a/vms/platformvm/validators/manager.go b/vms/platformvm/validators/manager.go index 1d5b794ab47c..e159e9f38881 100644 --- a/vms/platformvm/validators/manager.go +++ b/vms/platformvm/validators/manager.go @@ -174,8 +174,8 @@ func (m *manager) GetValidatorSet(ctx context.Context, height uint64, subnetID i endTime := m.clk.Time() m.metrics.IncValidatorSetsCreated() - m.metrics.AddValidatorSetsDuration(endTime.Sub(startTime)) - m.metrics.AddValidatorSetsHeightDiff(lastAcceptedHeight - height) + m.metrics.SetValidatorSetsDuration(endTime.Sub(startTime)) + m.metrics.SetValidatorSetsHeightDiff(lastAcceptedHeight - height) return vdrSet, nil } From 00627b48223d2b42a6953bf41364b59de6011c48 Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Fri, 26 May 2023 14:00:01 +0200 Subject: [PATCH 07/11] cleanup --- vms/platformvm/metrics/metrics.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vms/platformvm/metrics/metrics.go b/vms/platformvm/metrics/metrics.go index 39b86ce4cb3c..250908968e0c 100644 --- a/vms/platformvm/metrics/metrics.go +++ b/vms/platformvm/metrics/metrics.go @@ -119,13 +119,13 @@ func New( }), validatorSetsHeightDiff: prometheus.NewGauge(prometheus.GaugeOpts{ Namespace: namespace, - Name: "validator_sets_height_diff_sum", - Help: "Total number of validator sets diffs applied for generating validator sets", + Name: "validator_sets_height_diff", + Help: "Number of validator sets diffs applied for generating a validator sets request", }), validatorSetsDuration: prometheus.NewGauge(prometheus.GaugeOpts{ Namespace: namespace, - Name: "validator_sets_duration_sum", - Help: "Total amount of time generating validator sets in nanoseconds", + Name: "validator_sets_duration", + Help: "Time spent serving a validator sets request in nanoseconds", }), } From 0f65e6e2346f18468a71b144900ac4724d56f0c6 Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Fri, 26 May 2023 17:30:11 +0200 Subject: [PATCH 08/11] reverted faulty change --- vms/platformvm/metrics/metrics.go | 20 ++++++++++---------- vms/platformvm/metrics/no_op.go | 4 ++-- vms/platformvm/validators/manager.go | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/vms/platformvm/metrics/metrics.go b/vms/platformvm/metrics/metrics.go index 250908968e0c..b1ff4af89544 100644 --- a/vms/platformvm/metrics/metrics.go +++ b/vms/platformvm/metrics/metrics.go @@ -31,10 +31,10 @@ type Metrics interface { // Mark that a validator set was cached. IncValidatorSetsCached() // Mark that we spent the given time computing validator diffs. - SetValidatorSetsDuration(time.Duration) + AddValidatorSetsDuration(time.Duration) // Mark that we computed a validator diff at a height with the given // difference from the top. - SetValidatorSetsHeightDiff(uint64) + AddValidatorSetsHeightDiff(uint64) // Mark that this much stake is staked on the node. SetLocalStake(uint64) // Mark that this much stake is staked in the network. @@ -119,13 +119,13 @@ func New( }), validatorSetsHeightDiff: prometheus.NewGauge(prometheus.GaugeOpts{ Namespace: namespace, - Name: "validator_sets_height_diff", - Help: "Number of validator sets diffs applied for generating a validator sets request", + Name: "validator_sets_height_diff_sum", + Help: "Total number of validator sets diffs applied for generating validator sets", }), validatorSetsDuration: prometheus.NewGauge(prometheus.GaugeOpts{ Namespace: namespace, - Name: "validator_sets_duration", - Help: "Time spent serving a validator sets request in nanoseconds", + Name: "validator_sets_duration_sum", + Help: "Total amount of time generating validator sets in nanoseconds", }), } @@ -199,12 +199,12 @@ func (m *metrics) IncValidatorSetsCached() { m.validatorSetsCached.Inc() } -func (m *metrics) SetValidatorSetsDuration(d time.Duration) { - m.validatorSetsDuration.Set(float64(d)) +func (m *metrics) AddValidatorSetsDuration(d time.Duration) { + m.validatorSetsDuration.Add(float64(d)) } -func (m *metrics) SetValidatorSetsHeightDiff(d uint64) { - m.validatorSetsHeightDiff.Set(float64(d)) +func (m *metrics) AddValidatorSetsHeightDiff(d uint64) { + m.validatorSetsHeightDiff.Add(float64(d)) } func (m *metrics) SetLocalStake(s uint64) { diff --git a/vms/platformvm/metrics/no_op.go b/vms/platformvm/metrics/no_op.go index a7a3b23f18d9..d5948348f86b 100644 --- a/vms/platformvm/metrics/no_op.go +++ b/vms/platformvm/metrics/no_op.go @@ -35,9 +35,9 @@ func (noopMetrics) IncValidatorSetsCreated() {} func (noopMetrics) IncValidatorSetsCached() {} -func (noopMetrics) SetValidatorSetsDuration(time.Duration) {} +func (noopMetrics) AddValidatorSetsDuration(time.Duration) {} -func (noopMetrics) SetValidatorSetsHeightDiff(uint64) {} +func (noopMetrics) AddValidatorSetsHeightDiff(uint64) {} func (noopMetrics) SetLocalStake(uint64) {} diff --git a/vms/platformvm/validators/manager.go b/vms/platformvm/validators/manager.go index e159e9f38881..1d5b794ab47c 100644 --- a/vms/platformvm/validators/manager.go +++ b/vms/platformvm/validators/manager.go @@ -174,8 +174,8 @@ func (m *manager) GetValidatorSet(ctx context.Context, height uint64, subnetID i endTime := m.clk.Time() m.metrics.IncValidatorSetsCreated() - m.metrics.SetValidatorSetsDuration(endTime.Sub(startTime)) - m.metrics.SetValidatorSetsHeightDiff(lastAcceptedHeight - height) + m.metrics.AddValidatorSetsDuration(endTime.Sub(startTime)) + m.metrics.AddValidatorSetsHeightDiff(lastAcceptedHeight - height) return vdrSet, nil } From 87729172db8fa5333acbfc9593441986c5ce1f90 Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Tue, 6 Jun 2023 17:27:13 +0200 Subject: [PATCH 09/11] added script to poll getValidatorsAt depths --- scripts/warp_measures.sh | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 scripts/warp_measures.sh diff --git a/scripts/warp_measures.sh b/scripts/warp_measures.sh new file mode 100755 index 000000000000..cc9ea945fdf6 --- /dev/null +++ b/scripts/warp_measures.sh @@ -0,0 +1,56 @@ +#! /bin/bash +set -eu + +avalanche_node_ip="127.0.0.1:9650/" +p_chain_endpoint=$avalanche_node_ip"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 + +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"') +echo $current_height + +polled_height=$(($current_height - 200)) +echo $polled_height + +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 +echo $validators_call + +prometheus_node_addr="127.0.0.1:9090/" +prometheus_endpoint=$prometheus_node_addr"api/v1/query_range?query=rate(avalanche_P_vm_validator_sets_height_diff_sum\[30s\])&range_input=5m&step=1s" + +prom_validators_call=$(curl $prometheus_endpoint) +echo $prom_validators_call + + +# curl 'http://ec2-18-221-44-174.us-east-2.compute.amazonaws.com:9090/api/v1/query_range?query=deriv(avalanche_P_vm_validator_sets_height_diff_sum\[30s\])&start=2023-05-25T23:00:00.000Z&end=2023-05-25T23:59:00.000Z&step=1s' | jq + From 7bbd2924d0504b0d59e43a0e392b821c7029784d Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Tue, 6 Jun 2023 23:45:50 +0200 Subject: [PATCH 10/11] the script --- scripts/warp_measures.sh | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/scripts/warp_measures.sh b/scripts/warp_measures.sh index cc9ea945fdf6..763e4260d9c1 100755 --- a/scripts/warp_measures.sh +++ b/scripts/warp_measures.sh @@ -1,8 +1,13 @@ #! /bin/bash set -eu -avalanche_node_ip="127.0.0.1:9650/" -p_chain_endpoint=$avalanche_node_ip"ext/bc/P" +# 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 @@ -14,6 +19,10 @@ cat > "${temp_height_file}" << EOF } 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" @@ -21,10 +30,10 @@ if [ $? -ne 0 ]; then fi current_height=$(echo $height_call | jq -r '."result"."height"') -echo $current_height +timestamp=$(date +%s) +echo $timestamp "current height" $current_height -polled_height=$(($current_height - 200)) -echo $polled_height +polled_height=$(($current_height - depth)) temp_validatorsAt_file="/tmp/warp_validators_at_file.json" cat > "${temp_validatorsAt_file}" << EOF @@ -43,14 +52,11 @@ if [ $? -ne 0 ]; then echo "validators at call errored. Exiting" exit 1 fi -echo $validators_call - -prometheus_node_addr="127.0.0.1:9090/" -prometheus_endpoint=$prometheus_node_addr"api/v1/query_range?query=rate(avalanche_P_vm_validator_sets_height_diff_sum\[30s\])&range_input=5m&step=1s" - -prom_validators_call=$(curl $prometheus_endpoint) -echo $prom_validators_call - +timestamp=$(date +%s) +echo $timestamp "validtrs height" $polled_height -# curl 'http://ec2-18-221-44-174.us-east-2.compute.amazonaws.com:9090/api/v1/query_range?query=deriv(avalanche_P_vm_validator_sets_height_diff_sum\[30s\])&start=2023-05-25T23:00:00.000Z&end=2023-05-25T23:59:00.000Z&step=1s' | jq +sleep 30 +done +timestamp=$(date +%s) +echo $timestamp "DONE" From b6cddd36d39fded7b326dbe5dc3a0d6c34e8ce1f Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Wed, 7 Jun 2023 10:26:36 +0200 Subject: [PATCH 11/11] added metric --- vms/platformvm/metrics/metrics.go | 21 +++++++++++++++++---- vms/platformvm/metrics/no_op.go | 2 ++ vms/platformvm/validators/manager.go | 20 ++++++++++++++------ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/vms/platformvm/metrics/metrics.go b/vms/platformvm/metrics/metrics.go index b1ff4af89544..c5e5e7d5b46b 100644 --- a/vms/platformvm/metrics/metrics.go +++ b/vms/platformvm/metrics/metrics.go @@ -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. @@ -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", @@ -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), ) @@ -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() { @@ -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)) } diff --git a/vms/platformvm/metrics/no_op.go b/vms/platformvm/metrics/no_op.go index d5948348f86b..45a8e34530a0 100644 --- a/vms/platformvm/metrics/no_op.go +++ b/vms/platformvm/metrics/no_op.go @@ -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) {} diff --git a/vms/platformvm/validators/manager.go b/vms/platformvm/validators/manager.go index 1d5b794ab47c..c55dea9832f1 100644 --- a/vms/platformvm/validators/manager.go +++ b/vms/platformvm/validators/manager.go @@ -165,17 +165,20 @@ 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 } 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 } @@ -183,12 +186,13 @@ 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 { @@ -197,6 +201,7 @@ func (m *manager) applyValidatorDiffs( NodeID: nodeID, } vdrSet[nodeID] = vdr + opsCount++ } // The weight of this node changed at this block. @@ -209,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 { @@ -233,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) {