Skip to content

Commit 2dc466d

Browse files
committed
fixes
1 parent b858b12 commit 2dc466d

File tree

7 files changed

+181
-95
lines changed

7 files changed

+181
-95
lines changed

cmd/push-validator/cmd_register.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,8 @@ func runRegisterValidatorWithDeps(d *Deps, cfg config.Config, moniker, keyName,
576576
// Always display Account Info section (whether new or existing key)
577577
p.Section("Account Info")
578578
p.KeyValueLine("EVM Address", evmAddr, "blue")
579-
p.KeyValueLine("Cosmos Address", keyInfo.Address, "dim")
579+
p.KeyValueLine("Chain", "Push Chain", "dim")
580+
p.KeyValueLine("Network", "Testnet", "dim")
580581
fmt.Println()
581582
}
582583

cmd/push-validator/cmd_validators.go

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"sort"
77
"strconv"
88
"strings"
9-
"sync"
109
"time"
1110

1211
"github.com/pushchain/push-validator-cli/internal/dashboard"
@@ -76,21 +75,18 @@ func handleValidatorsWithFormat(d *Deps, jsonOut bool) error {
7675
myValCancel()
7776

7877
type validatorDisplay struct {
79-
moniker string
80-
status string
81-
statusOrder int
82-
jailed bool
83-
tokensPC float64
84-
commissionPct float64
85-
operatorAddr string
86-
cosmosAddr string
87-
commissionRwd string
88-
outstandingRwd string
89-
evmAddress string
90-
isMyValidator bool
78+
moniker string
79+
status string
80+
statusOrder int
81+
jailed bool
82+
tokensPC float64
83+
commissionPct float64
84+
operatorAddr string
85+
cosmosAddr string
86+
evmAddress string
87+
isMyValidator bool
9188
}
9289
vals := make([]validatorDisplay, len(valList.Validators))
93-
var wg sync.WaitGroup
9490

9591
for i, v := range valList.Validators {
9692
vals[i] = validatorDisplay{
@@ -131,20 +127,9 @@ func handleValidatorsWithFormat(d *Deps, jsonOut bool) error {
131127
}
132128
}
133129

134-
// Fetch rewards and EVM address in parallel using goroutines
135-
wg.Add(1)
136-
go func(idx int, addr string) {
137-
defer wg.Done()
138-
// 3 second timeout per validator to avoid blocking
139-
fetchCtx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
140-
defer cancel()
141-
142-
vals[idx].commissionRwd, vals[idx].outstandingRwd, _ = validator.GetValidatorRewards(fetchCtx, cfg, addr)
143-
vals[idx].evmAddress = validator.GetEVMAddress(fetchCtx, addr)
144-
}(i, v.OperatorAddress)
130+
// Convert address to EVM format synchronously (pure Go, no subprocess)
131+
vals[i].evmAddress = validator.Bech32ToHex(v.OperatorAddress)
145132
}
146-
147-
wg.Wait()
148133
sort.Slice(vals, func(i, j int) bool {
149134
// My validator always comes first
150135
if vals[i].isMyValidator != vals[j].isMyValidator {
@@ -156,7 +141,7 @@ func handleValidatorsWithFormat(d *Deps, jsonOut bool) error {
156141
c := ui.NewColorConfig()
157142
fmt.Println()
158143
fmt.Println(c.Header(" 👥 Active Push Chain Validators "))
159-
headers := []string{"VALIDATOR", "COSMOS_ADDR", "STATUS", "STAKE(PC)", "COMM%", "COMM_RWD", "OUTSTND_RWD", "EVM_ADDR"}
144+
headers := []string{"VALIDATOR", "STATUS", "STAKE(PC)", "COMM%", "EVM_ADDR"}
160145
rows := make([][]string, 0, len(vals))
161146
for _, v := range vals {
162147
// Check if this is my validator
@@ -173,13 +158,10 @@ func handleValidatorsWithFormat(d *Deps, jsonOut bool) error {
173158

174159
row := []string{
175160
moniker,
176-
truncateAddress(v.cosmosAddr, 24),
177161
statusStr,
178162
dashboard.FormatLargeNumber(int64(v.tokensPC)),
179163
fmt.Sprintf("%.0f%%", v.commissionPct),
180-
dashboard.FormatSmartNumber(v.commissionRwd),
181-
dashboard.FormatSmartNumber(v.outstandingRwd),
182-
truncateAddress(v.evmAddress, 16),
164+
v.evmAddress,
183165
}
184166

185167
// Apply green highlighting to the entire row if it's my validator

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ require (
1818

1919
require (
2020
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
21+
github.com/btcsuite/btcutil v1.0.2 // indirect
2122
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
2223
github.com/charmbracelet/x/ansi v0.8.0 // indirect
2324
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect

go.sum

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
12
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
23
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
34
github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=
45
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
6+
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
7+
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
8+
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
9+
github.com/btcsuite/btcutil v1.0.2 h1:9iZ1Terx9fMIOtq1VrwdqfsATL9MC2l8ZrUY6YZ2uts=
10+
github.com/btcsuite/btcutil v1.0.2/go.mod h1:j9HUFwoQRsZL3V4n+qG+CUnEGHOarIxfC3Le2Yhbcts=
11+
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
12+
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
13+
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
14+
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
15+
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
516
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
617
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
718
github.com/charmbracelet/bubbles v0.21.0 h1:9TdC97SdRVg/1aaXNVWfFH3nnLAwOXr8Fn6u6mfQdFs=
@@ -21,19 +32,26 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod
2132
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
2233
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
2334
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
35+
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2436
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2537
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2638
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
2739
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
40+
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
2841
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
2942
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
43+
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
3044
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
3145
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
3246
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
3347
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
3448
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
49+
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
3550
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
3651
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
52+
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
53+
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
54+
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
3755
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
3856
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
3957
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
@@ -50,6 +68,9 @@ github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELU
5068
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
5169
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
5270
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
71+
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
72+
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
73+
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
5374
github.com/pierrec/lz4/v4 v4.1.25 h1:kocOqRffaIbU5djlIBr7Wh+cx82C0vtFb0fOurZHqD0=
5475
github.com/pierrec/lz4/v4 v4.1.25/go.mod h1:EoQMVJgeeEOMsCqCzqFm2O0cJvljX2nGZjcRIPL34O4=
5576
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -80,14 +101,23 @@ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavM
80101
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
81102
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
82103
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
104+
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
105+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
106+
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
83107
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
84108
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
85109
golang.org/x/mod v0.32.0 h1:9F4d3PHLljb6x//jOyokMv3eX+YDeepZSEo3mFJy93c=
86110
golang.org/x/mod v0.32.0/go.mod h1:SgipZ/3h2Ci89DlEtEXWUk/HteuRin+HHhN+WbNhguU=
111+
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
112+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
87113
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
88114
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
115+
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
89116
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
90117
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
118+
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
119+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
120+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
91121
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
92122
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
93123
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -98,10 +128,14 @@ golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
98128
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
99129
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
100130
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
131+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
101132
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
102133
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
103134
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
104135
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
105136
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
137+
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
138+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
139+
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
106140
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
107141
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/ui/colors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func DefaultTheme() *Theme {
8686
Success: BrightGreen,
8787
Warning: BrightYellow,
8888
Error: BrightRed,
89-
Info: BrightCyan,
89+
Info: BrightBlue,
9090

9191
// UI elements - Professional and readable
9292
Header: Bold + BrightCyan,

internal/validator/fetcher.go

Lines changed: 71 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package validator
22

33
import (
44
"context"
5+
"encoding/hex"
56
"encoding/json"
67
"fmt"
78
"os"
@@ -12,9 +13,32 @@ import (
1213
"sync"
1314
"time"
1415

16+
"github.com/btcsuite/btcutil/bech32"
1517
"github.com/pushchain/push-validator-cli/internal/config"
1618
)
1719

20+
// Bech32ToHex converts a bech32 address (push1..., pushvaloper1...) to EVM hex format (0x...)
21+
// This is a pure Go implementation that doesn't require subprocess calls.
22+
func Bech32ToHex(addr string) string {
23+
if addr == "" {
24+
return "—"
25+
}
26+
27+
// Decode bech32 address
28+
_, data, err := bech32.Decode(addr)
29+
if err != nil {
30+
return "—"
31+
}
32+
33+
// Convert 5-bit groups to 8-bit bytes
34+
converted, err := bech32.ConvertBits(data, 5, 8, false)
35+
if err != nil {
36+
return "—"
37+
}
38+
39+
return "0x" + strings.ToUpper(hex.EncodeToString(converted))
40+
}
41+
1842
// commandContext creates an exec.CommandContext with DYLD_LIBRARY_PATH set for macOS
1943
// to find libwasmvm.dylib in the same directory as the binary
2044
func commandContext(ctx context.Context, name string, args ...string) *exec.Cmd {
@@ -550,6 +574,7 @@ func parseStatus(status string) string {
550574
}
551575

552576
// GetValidatorRewards fetches commission and outstanding rewards for a validator
577+
// Both queries are executed in parallel for better performance.
553578
func GetValidatorRewards(ctx context.Context, cfg config.Config, validatorAddr string) (commission string, outstanding string, err error) {
554579
if validatorAddr == "" {
555580
return "—", "—", fmt.Errorf("validator address required")
@@ -560,73 +585,64 @@ func GetValidatorRewards(ctx context.Context, cfg config.Config, validatorAddr s
560585
return "—", "—", fmt.Errorf("pchaind not found: %w", err)
561586
}
562587

563-
// Create child context with 15s timeout per validator to avoid deadline issues
564-
// when fetching rewards for multiple validators in parallel
565-
// Increased from 5s to handle network latency and slower nodes
566-
queryCtx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
567-
defer cancel()
588+
// Use the provided context or create one with timeout
589+
queryCtx := ctx
590+
if queryCtx == nil {
591+
var cancel context.CancelFunc
592+
queryCtx, cancel = context.WithTimeout(context.Background(), 15*time.Second)
593+
defer cancel()
594+
}
568595

569596
remote := fmt.Sprintf("https://%s", cfg.GenesisDomain)
570597

571-
// Fetch commission rewards
598+
// Fetch commission and outstanding rewards in parallel
599+
var wg sync.WaitGroup
572600
commissionRewards := "—"
573-
commCmd := commandContext(queryCtx, bin, "query", "distribution", "commission", validatorAddr, "--node", remote, "-o", "json")
574-
if commOutput, err := commCmd.Output(); err == nil {
575-
var commResult struct {
576-
Commission struct {
577-
Commission []string `json:"commission"`
578-
} `json:"commission"`
579-
}
580-
if err := json.Unmarshal(commOutput, &commResult); err == nil && len(commResult.Commission.Commission) > 0 {
581-
// Extract numeric part from amount string (format: "123.45upc")
582-
amountStr := commResult.Commission.Commission[0]
583-
// Remove denom suffix
584-
amountStr = strings.TrimSuffix(amountStr, "upc")
585-
if amount, err := strconv.ParseFloat(amountStr, 64); err == nil {
586-
commissionRewards = fmt.Sprintf("%.2f", amount/1e18)
587-
}
588-
}
589-
}
590-
591-
// Fetch outstanding rewards with retry logic
592601
outstandingRewards := "—"
593-
var outOutput []byte
594-
var outErr error
595602

596-
// Retry up to 2 times with 2s delay on failure
597-
maxRetries := 2
598-
for attempt := 0; attempt <= maxRetries; attempt++ {
599-
outCmd := commandContext(queryCtx, bin, "query", "distribution", "validator-outstanding-rewards", validatorAddr, "--node", remote, "-o", "json")
600-
outOutput, outErr = outCmd.Output()
603+
wg.Add(2)
601604

602-
if outErr == nil {
603-
break // Success, exit retry loop
604-
}
605-
606-
// Wait before retry (except on last attempt)
607-
if attempt < maxRetries {
608-
time.Sleep(2 * time.Second)
605+
// Fetch commission rewards
606+
go func() {
607+
defer wg.Done()
608+
commCmd := commandContext(queryCtx, bin, "query", "distribution", "commission", validatorAddr, "--node", remote, "-o", "json")
609+
if commOutput, err := commCmd.Output(); err == nil {
610+
var commResult struct {
611+
Commission struct {
612+
Commission []string `json:"commission"`
613+
} `json:"commission"`
614+
}
615+
if err := json.Unmarshal(commOutput, &commResult); err == nil && len(commResult.Commission.Commission) > 0 {
616+
amountStr := commResult.Commission.Commission[0]
617+
amountStr = strings.TrimSuffix(amountStr, "upc")
618+
if amount, err := strconv.ParseFloat(amountStr, 64); err == nil {
619+
commissionRewards = fmt.Sprintf("%.2f", amount/1e18)
620+
}
621+
}
609622
}
610-
}
623+
}()
611624

612-
// Parse outstanding rewards if fetch succeeded
613-
if outErr == nil {
614-
var outResult struct {
615-
Rewards struct {
616-
Rewards []string `json:"rewards"`
617-
} `json:"rewards"`
618-
}
619-
if err := json.Unmarshal(outOutput, &outResult); err == nil && len(outResult.Rewards.Rewards) > 0 {
620-
// Extract numeric part from amount string (format: "123.45upc")
621-
amountStr := outResult.Rewards.Rewards[0]
622-
// Remove denom suffix
623-
amountStr = strings.TrimSuffix(amountStr, "upc")
624-
if amount, err := strconv.ParseFloat(amountStr, 64); err == nil {
625-
outstandingRewards = fmt.Sprintf("%.2f", amount/1e18)
625+
// Fetch outstanding rewards (no retry for speed)
626+
go func() {
627+
defer wg.Done()
628+
outCmd := commandContext(queryCtx, bin, "query", "distribution", "validator-outstanding-rewards", validatorAddr, "--node", remote, "-o", "json")
629+
if outOutput, err := outCmd.Output(); err == nil {
630+
var outResult struct {
631+
Rewards struct {
632+
Rewards []string `json:"rewards"`
633+
} `json:"rewards"`
634+
}
635+
if err := json.Unmarshal(outOutput, &outResult); err == nil && len(outResult.Rewards.Rewards) > 0 {
636+
amountStr := outResult.Rewards.Rewards[0]
637+
amountStr = strings.TrimSuffix(amountStr, "upc")
638+
if amount, err := strconv.ParseFloat(amountStr, 64); err == nil {
639+
outstandingRewards = fmt.Sprintf("%.2f", amount/1e18)
640+
}
626641
}
627642
}
628-
}
643+
}()
629644

645+
wg.Wait()
630646
return commissionRewards, outstandingRewards, nil
631647
}
632648

0 commit comments

Comments
 (0)