Skip to content

Commit f6dffab

Browse files
committed
fix: use set rpc addr method of client
1 parent 789175b commit f6dffab

File tree

5 files changed

+71
-27
lines changed

5 files changed

+71
-27
lines changed

api/info/handlers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ func handlerGetInfo(c *core.Context) gin.HandlerFunc {
2121
// Construct the result structure with node information.
2222
res := &node.GetInfoResult{
2323
Addr: c.NodeAddr().String(),
24-
EgressRate: ulSpeed.String(),
24+
Downlink: ulSpeed.String(),
2525
HandshakeDNS: false,
26-
IngressRate: dlSpeed.String(),
2726
Location: &geoip.Location{
2827
City: loc.City,
2928
Country: loc.Country,
@@ -34,6 +33,7 @@ func handlerGetInfo(c *core.Context) gin.HandlerFunc {
3433
Moniker: c.Moniker(),
3534
Peers: c.Service().PeersLen(),
3635
ServiceType: c.Service().Type().String(),
36+
Uplink: dlSpeed.String(),
3737
Version: version.Get(),
3838
}
3939

core/context.go

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,58 +51,95 @@ func NewContext() *Context {
5151
}
5252
}
5353

54+
// checkSealed verifies if the context is sealed to prevent modification.
55+
func (c *Context) checkSealed() {
56+
if c.sealed {
57+
panic(errors.New("context is sealed"))
58+
}
59+
}
60+
61+
// Seal marks the context as sealed, preventing further modifications.
62+
func (c *Context) Seal() *Context {
63+
c.sealed = true
64+
return c
65+
}
66+
5467
// AccAddr returns the transaction sender address set in the context.
5568
func (c *Context) AccAddr() cosmossdk.AccAddress {
69+
c.fm.RLock()
70+
defer c.fm.RUnlock()
5671
return c.accAddr.Bytes()
5772
}
5873

5974
// APIAddrs returns the api addresses set in the context.
6075
func (c *Context) APIAddrs() []string {
76+
c.fm.RLock()
77+
defer c.fm.RUnlock()
6178
return c.apiAddrs
6279
}
6380

6481
// APIListenAddr returns the listen address of the node API.
6582
func (c *Context) APIListenAddr() string {
83+
c.fm.RLock()
84+
defer c.fm.RUnlock()
6685
return c.apiListenAddr
6786
}
6887

6988
// Client returns the client instance set in the context.
7089
func (c *Context) Client() *core.Client {
71-
return c.client.WithRPCAddr(c.RPCAddr()) // TODO: is it needed?
90+
c.fm.RLock()
91+
defer c.fm.RUnlock()
92+
93+
c.client.SetRPCAddr(c.RPCAddr())
94+
return c.client
7295
}
7396

7497
// Database returns the database connection set in the context.
7598
func (c *Context) Database() *gorm.DB {
99+
c.fm.RLock()
100+
defer c.fm.RUnlock()
76101
return c.database
77102
}
78103

79104
// DatabaseFile returns the database path of the node.
80105
func (c *Context) DatabaseFile() string {
106+
c.fm.RLock()
107+
defer c.fm.RUnlock()
81108
return filepath.Join(c.HomeDir(), "data.db")
82109
}
83110

84111
// GeoIPClient returns the GeoIP client set in the context.
85112
func (c *Context) GeoIPClient() geoip.Client {
113+
c.fm.RLock()
114+
defer c.fm.RUnlock()
86115
return c.geoIPClient
87116
}
88117

89118
// GigabytePrices returns the gigabyte prices for nodes.
90119
func (c *Context) GigabytePrices() v1.Prices {
120+
c.fm.RLock()
121+
defer c.fm.RUnlock()
91122
return c.gigabytePrices
92123
}
93124

94125
// HomeDir returns the home directory set in the context.
95126
func (c *Context) HomeDir() string {
127+
c.fm.RLock()
128+
defer c.fm.RUnlock()
96129
return c.homeDir
97130
}
98131

99132
// HourlyPrices returns the hourly prices for nodes.
100133
func (c *Context) HourlyPrices() v1.Prices {
134+
c.fm.RLock()
135+
defer c.fm.RUnlock()
101136
return c.hourlyPrices
102137
}
103138

104139
// Input returns the keyring input set in the context.
105140
func (c *Context) Input() io.Reader {
141+
c.fm.RLock()
142+
defer c.fm.RUnlock()
106143
return c.input
107144
}
108145

@@ -115,27 +152,38 @@ func (c *Context) Location() *geoip.Location {
115152

116153
// MaxPeers returns the maximum peers for the service.
117154
func (c *Context) MaxPeers() uint {
155+
c.fm.RLock()
156+
defer c.fm.RUnlock()
118157
return c.maxPeers
119158
}
120159

121160
// Moniker returns the name or identifier for the node.
122161
func (c *Context) Moniker() string {
162+
c.fm.RLock()
163+
defer c.fm.RUnlock()
123164
return c.moniker
124165
}
125166

126167
func (c *Context) NodeAddr() sentinelhub.NodeAddress {
168+
c.fm.RLock()
169+
defer c.fm.RUnlock()
127170
return c.accAddr.Bytes()
128171
}
129172

130173
// RemoteAddrs returns the remote addresses set in the context.
131174
func (c *Context) RemoteAddrs() []string {
175+
c.fm.RLock()
176+
defer c.fm.RUnlock()
132177
return c.remoteAddrs
133178
}
134179

135180
// RPCAddr returns the first RPC address from the list or an empty string if no addresses are available.
136181
func (c *Context) RPCAddr() string {
182+
c.fm.RLock()
183+
defer c.fm.RUnlock()
184+
137185
addrs := c.RPCAddrs()
138-
if len(addrs) == 0 { // TODO: is it needed?
186+
if len(addrs) == 0 { // TODO: remove this?
139187
return ""
140188
}
141189

@@ -149,24 +197,31 @@ func (c *Context) RPCAddrs() []string {
149197
return c.rpcAddrs
150198
}
151199

152-
// Seal marks the context as sealed, preventing further modifications.
153-
func (c *Context) Seal() *Context {
154-
c.sealed = true
155-
return c
156-
}
157-
158200
// Service returns the server service instance set in the context.
159201
func (c *Context) Service() sentinelsdk.ServerService {
202+
c.fm.RLock()
203+
defer c.fm.RUnlock()
160204
return c.service
161205
}
162206

207+
// SpeedtestResults returns the download and upload speeds set in the context.
208+
func (c *Context) SpeedtestResults() (dlSpeed, ulSpeed math.Int) {
209+
c.fm.RLock()
210+
defer c.fm.RUnlock()
211+
return c.dlSpeed, c.ulSpeed
212+
}
213+
163214
// TLSCertFile returns the TLS certificate path of the node API server.
164215
func (c *Context) TLSCertFile() string {
216+
c.fm.RLock()
217+
defer c.fm.RUnlock()
165218
return filepath.Join(c.HomeDir(), "tls.crt")
166219
}
167220

168221
// TLSKeyFile returns the TLS key path of the node API server.
169222
func (c *Context) TLSKeyFile() string {
223+
c.fm.RLock()
224+
defer c.fm.RUnlock()
170225
return filepath.Join(c.HomeDir(), "tls.key")
171226
}
172227

@@ -192,13 +247,6 @@ func (c *Context) SetSpeedtestResults(dlSpeed, ulSpeed math.Int) {
192247
c.ulSpeed = ulSpeed
193248
}
194249

195-
// SpeedtestResults returns the download and upload speeds set in the context.
196-
func (c *Context) SpeedtestResults() (dlSpeed, ulSpeed math.Int) {
197-
c.fm.RLock()
198-
defer c.fm.RUnlock()
199-
return c.dlSpeed, c.ulSpeed
200-
}
201-
202250
// WithAccAddr sets the transaction sender address in the context and returns the updated context.
203251
func (c *Context) WithAccAddr(addr cosmossdk.AccAddress) *Context {
204252
c.checkSealed()
@@ -303,10 +351,3 @@ func (c *Context) WithService(service sentinelsdk.ServerService) *Context {
303351
c.service = service
304352
return c
305353
}
306-
307-
// checkSealed verifies if the context is sealed to prevent modification.
308-
func (c *Context) checkSealed() {
309-
if c.sealed {
310-
panic(errors.New("context is sealed"))
311-
}
312-
}

core/setup.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ func (c *Context) SetupClient(cfg *config.Config) error {
5252
return fmt.Errorf("setting up keyring: %w", err)
5353
}
5454

55+
// Seal the client.
56+
cc.Seal()
57+
5558
// Assign the initialized client to the context.
5659
c.WithClient(cc)
5760
return nil

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/cosmos/cosmos-sdk v0.47.17
88
github.com/gin-contrib/cors v1.7.6
99
github.com/gin-gonic/gin v1.10.1
10-
github.com/sentinel-official/sentinel-go-sdk v1.0.0-rc.6.0.20250818145401-1e9f376abb11
10+
github.com/sentinel-official/sentinel-go-sdk v1.0.0-rc.6.0.20250819043521-99e9556b0d55
1111
github.com/sentinel-official/sentinelhub/v12 v12.0.0-rc.11
1212
github.com/spf13/cobra v1.9.1
1313
github.com/spf13/pflag v1.0.7

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ github.com/secure-io/siv-go v0.0.0-20180922214919-5ff40651e2c4 h1:zOjq+1/uLzn/Xo
511511
github.com/secure-io/siv-go v0.0.0-20180922214919-5ff40651e2c4/go.mod h1:aI+8yClBW+1uovkHw6HM01YXnYB8vohtB9C83wzx34E=
512512
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb h1:XfLJSPIOUX+osiMraVgIrMR27uMXnRJWGm1+GL8/63U=
513513
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb/go.mod h1:bR6DqgcAl1zTcOX8/pE2Qkj9XO00eCNqmKb7lXP8EAg=
514-
github.com/sentinel-official/sentinel-go-sdk v1.0.0-rc.6.0.20250818145401-1e9f376abb11 h1:GB2rSEZYvaQ0UAA33MSMAj+MHec9ZSLzVyGX2WHRCNE=
515-
github.com/sentinel-official/sentinel-go-sdk v1.0.0-rc.6.0.20250818145401-1e9f376abb11/go.mod h1:7QQH3IAo5YcbrqUNBZYClLi4d+lH9Ed36tDIbwewHHc=
514+
github.com/sentinel-official/sentinel-go-sdk v1.0.0-rc.6.0.20250819043521-99e9556b0d55 h1:HswbpqyxKFtcOEssy25KFQr7YyPAjfKP1rZJdA59N/0=
515+
github.com/sentinel-official/sentinel-go-sdk v1.0.0-rc.6.0.20250819043521-99e9556b0d55/go.mod h1:7QQH3IAo5YcbrqUNBZYClLi4d+lH9Ed36tDIbwewHHc=
516516
github.com/sentinel-official/sentinelhub/v12 v12.0.0-rc.11 h1:B3ylnKZSLP9aDYnS2f98Gx/QTohPuD36tjl75kYJSMs=
517517
github.com/sentinel-official/sentinelhub/v12 v12.0.0-rc.11/go.mod h1:LXcOAEffAn4Pw58xhoYN9j8ZVuM02OCgPNTI6lkGG2E=
518518
github.com/shirou/gopsutil/v4 v4.25.7 h1:bNb2JuqKuAu3tRlPv5piSmBZyMfecwQ+t/ILq+1JqVM=

0 commit comments

Comments
 (0)