-
Notifications
You must be signed in to change notification settings - Fork 0
/
UNL-validator-statistics.ps1
215 lines (178 loc) · 9.72 KB
/
UNL-validator-statistics.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# Fetch statistics for UNL XRPL validators using API @ xrpscan.com
#
# (C) Jon Nilsen ([email protected]) 2022
# Free to use for whatever. I hold no grudges :).
#
# Usage: load up script in any Powershell and run
Function Get-VoteStatistics {
$ValidVotes = $AllAmendments | Where-Object { $_.enabled -match "False"}
[pscustomobject]$VoteStatistics = @()
foreach ($ValidVote in $ValidVotes) {
$Percent = [math]::Round(($ValidVote.count * 100 / ($ValidVote.threshold + 1)),1)
$Object = [pscustomobject]@{
AmendmentID = $ValidVote.amendment_id
AmendmentName = $ValidVote.name
Deprecated = $ValidVote.deprecated
ServerVersion = $ValidVote.introduced
Votes = $ValidVote.count
'Required votes (80% of UNL (+ 1 vote))' = $ValidVote.threshold + 1
Progress = "$($Percent)%"
}
$VoteStatistics += $Object
}
Return $VoteStatistics
}
Function Get-ValidatorVotes {
param ( [parameter(Mandatory = $true)][string] $Master_key )
[pscustomobject]$VotedOn = @()
$VotedIDs = ($dUNLValidators | Where-Object { $_.master_key -eq $Master_key }).votes.amendments
if (!$VotedIDs) {
return $VotedOn
}
foreach ($VotedID in $VotedIDs) {
# Translate ID to Name on amendment
$AmendmentName = $AllAmendments | Where-Object { $_.amendment_id -eq $AmendmentID } | Select-Object name -ExpandProperty name
$VotedOn += "$AmendmentName "
$Object = [pscustomobject]@{
MasterKey = $Master_key
AmendmentID = $VotedID
AmendmentName = $AllAmendments | Where-Object { $_.amendment_id -eq $VotedID } | Select-Object name -ExpandProperty name
Enabled = $AllAmendments | Where-Object { $_.amendment_id -eq $VotedID -and $_.enabled -match "False" } | Select-Object enabled -ExpandProperty enabled
Deprecated = $AllAmendments | Where-Object { $_.amendment_id -eq $VotedID -and $_.deprecated -match "True" } | Select-Object deprecated -ExpandProperty deprecated
}
$VotedOn += $Object
}
Return $VotedOn
}
Function Get-ValidatorVoteNames {
param ( [parameter(Mandatory = $true)][string] $Master_key )
$VotedOn = ""
$VotedIDs = ($dUNLValidators | Where-Object { $_.master_key -eq $Master_key }).votes.amendments
if (!$VotedIDs) {
return $VotedOn
}
foreach ($VotedID in $VotedIDs) {
# Translate ID to Name on amendment
$AmendmentName = $AllAmendments | Where-Object { $_.amendment_id -eq $VotedID } | Select-Object name -ExpandProperty name
$VotedOn += "$AmendmentName "
}
Return $VotedOn
}
Function Get-ValidatorVotesBaseOwner {
param ( [parameter(Mandatory = $true)][string] $Master_key )
[int]$BaseOwner = ($dUNLValidators | Where-Object { $_.master_key -eq $Master_key }).votes.reserve_base
[int]$ReserveOwner = ($dUNLValidators | Where-Object { $_.master_key -eq $Master_key }).votes.reserve_inc
if ($BaseOwner) {
$BaseOwner = $BaseOwner/1000000
}
if ($ReserveOwner) {
$ReserveOwner = $ReserveOwner/1000000
}
$NetworkBaseOwner = $($FeeSettings.node.ReserveBase) / 1000000
$NetworkReserveOwner = $($FeeSettings.node.ReserveIncrement) / 1000000
if ($BaseOwner -and $ReserveOwner) {
return "$BaseOwner / $ReserveOwner XRP"
}
elseif ($BaseOwner -and !$ReserveOwner) {
return "$BaseOwner / $NetworkReserveOwner XRP"
}
elseif (!$BaseOwner -and $ReserveOwner) {
return "$NetworkBaseOwner / $ReserveOwner XRP"
}
else {
return "$NetworkBaseOwner / $NetworkReserveOwner XRP"
}
return $Result
}
#Get-ValidatorVotesBaseOwner nHDwHQGjKTz6R6pFigSSrNBrhNYyUGFPHA75HiTccTCQzuu9d7Za
Function Get-Release_latest {
$Url = "https://github.com/ripple/rippled/releases/latest"
$Request = [System.Net.WebRequest]::Create($url)
$Response = $request.GetResponse()
$RealTagUrl = $response.ResponseUri.OriginalString
$Response.Close()
$Version = $realTagUrl.split('/')[-1].Trim('v')
if ($Version) { return $version }
else { return $null }
}
clear
try {
$Rippled_stable = Get-Release_latest
}
catch { }
if ($Rippled_stable) {
$FoundLatestVersion = "rippled-$($Rippled_stable)"
}
$UNL = "vl.xrplf.org"
$BaseURLAPI = "https://api.xrpscan.com"
$web_client = new-object system.net.webclient
try {
$AllAmendments = $Web_client.DownloadString("$BaseURLAPI/api/v1/amendments") | ConvertFrom-Json
$AllValidators = $Web_client.DownloadString("$BaseURLAPI/api/v1/validatorregistry") | ConvertFrom-Json
$FeeSettings = $Web_client.DownloadString("$BaseURLAPI/api/v1/object/FeeSettings") | ConvertFrom-Json
}
catch {
}
if ($FoundLatestVersion -and $AllAmendments -and $FeeSettings -and $AllValidators) {
$CountTestChain = $AllValidators | Where-Object { $_.chain -eq "test" } | Measure-Object | Select-Object -ExpandProperty count
$CountMainChain = $AllValidators | Where-Object { $_.chain -eq "main" } | Measure-Object | Select-Object -ExpandProperty count
$CountMainChainUNL = $AllValidators | Where-Object { $_.chain -eq "main" -and $_.unl -contains "$UNL" } | Measure-Object | Select-Object -ExpandProperty Count
$CountMainChainUNLValidators = $AllValidators | Select-Object master_key, domain_legacy, unl | Where-Object { $_.unl -contains "$UNL" }| Measure-Object | Select-Object -ExpandProperty Count
$CountAllChain = $CountTestChain + $CountMainChain
$ReportTime = Get-Date -Format "dd.MM.yyy HH:mm"
Write-Host "Status of UNL validators: " -NoNewline; Write-Host "$ReportTime" -NoNewline -ForegroundColor Green; Write-Host " CEST"
Write-Host "Found " -NoNewline; Write-Host "$CountAllChain" -NoNewline -ForegroundColor Green; Write-Host " validators in total: " -NoNewline
Write-Host "$CountMainChain" -NoNewline -ForegroundColor Green; Write-Host " mainnet + " -NoNewline; Write-Host "$CountMainChainUNLValidators" -NoNewline -ForegroundColor Green`
Write-Host " mainnet UNL + " -NoNewline; Write-Host "$CountTestChain" -NoNewline -ForegroundColor Green; Write-Host " testnet"
Write-Host "Latest stable server software: " -NoNewline; Write-Host "$FoundLatestVersion" -ForegroundColor Green; Write-Host ""
$dUNLValidators = $AllValidators | Select-Object master_key, domain_legacy, server_version, unl, votes | Where-Object { $_.unl -contains "$UNL" }
$dUNLValidatorVersions = ($AllValidators | Select-Object master_key, domain_legacy, server_version, unl, votes | Where-Object { $_.unl -contains "$UNL" }).server_version.version | Select-Object -Unique | Sort-Object -Descending
# Collect data about validators and create a collection of them.
[pscustomobject]$ValidatorStatistics = @()
foreach ($dUNLValidatorVersion in $dUNLValidatorVersions) {
$Results = $dUNLValidators | Where-Object { $_.server_version -like "*$dUNLValidatorVersion*" } | Sort-Object domain_legacy | Select-Object domain_legacy, master_key, server_version
foreach ($Result in $Results) {
$AmendmentVotes = Get-ValidatorVoteNames -Master_key $Result.master_key
$ReserveVotes = Get-ValidatorVotesBaseOwner -Master_key $Result.master_key
$Object = [pscustomobject]@{
Domain = $Result.domain_legacy
ServerVersion = $($Result.server_version.Version)
'Reserves voting' = $ReserveVotes
'Amendment voting' = $AmendmentVotes
}
$ValidatorStatistics += $Object
}
}
# Display ALL UNL validators on ALL existing versions.
foreach ($dUNLValidatorVersion in $dUNLValidatorVersions) {
$Count = $dUNLValidators | Select-Object master_key, domain_legacy, server_version, unl | Where-Object { $_.server_version -like "*$dUNLValidatorVersion*" } | Measure-Object | Select-Object -ExpandProperty Count
$CountPercent = [math]::Round(($Count * 100 / $CountMainChainUNLValidators),1)
Write-Host "UNL validators running " -NoNewline
Write-Host "$dUNLValidatorVersion" -NoNewline -ForegroundColor Green
Write-Host " [" -NoNewline
Write-Host "$Count" -NoNewline -ForegroundColor Yellow #; Write-Host " / " -NoNewline
Write-Host "|" -NoNewline; Write-Host "$CountPercent%" -NoNewline -ForegroundColor Green
Write-Host "]:" -NoNewline # base/owner reserve and amendments voted for:" -NoNewline
$NetworkStateBaseReserve = ($FeeSettings.node.ReserveBase / 1000000)
$NetworkStateOwnerReserve = ($FeeSettings.node.ReserveIncrement / 1000000)
$ValidatorStatistics | Where-Object { $_.ServerVersion -match $dUNLValidatorVersion } | Select-Object Domain, 'Reserves voting', 'Amendment voting' | ft # | Sort-Object 'Reserves voting' | ft #-HideTableHeaders
}
# Display active votes.
$AmendmentVotes = Get-VoteStatistics | Select-Object * | Where-Object { $_.Deprecated -notmatch "True" }
Write-Host "Amendments available & votes: " -NoNewline
Write-host "$($AmendmentVotes.count)" -NoNewline -ForegroundColor Green
$AmendmentVotes | Select-Object AmendmentName, ServerVersion, Votes, 'Required votes (80% of UNL (+ 1 vote))', Progress | Sort-Object Votes -Descending | ft #-HideTableHeaders
# Display active but deprecated votes.
[array]$DeprecatedAmendmentVotes = Get-VoteStatistics | Select-Object * | Where-Object { $_.Deprecated -match "True" -and $_.Votes -gt 0}
if ($DeprecatedAmendmentVotes) {
# Write-Host ""
Write-Host "Amendments (deprecated) not enabled AND being voted on.`nThese can safely be removed from active voting: " -NoNewline
Write-host "$($DeprecatedAmendmentVotes.count)" -NoNewline -ForegroundColor Red
$DeprecatedAmendmentVotes | Select-Object AmendmentName, ServerVersion, Votes, Requirement, Progress | Sort-Object Votes -Descending | ft #-HideTableHeaders
}
}
else {
Write-Host "Unable to fetch data from Cyberspace @ $BaseURLAPI. Aborted." -ForegroundColor Red
}
Write-Host "Sources:"
Write-Host "https://xrpscan.com/validators / https://xrpscan.com/amendments"