Skip to content

Commit 254b0df

Browse files
authored
release: v8.1.0 (#252)
2 parents d58a610 + 6325be4 commit 254b0df

File tree

6 files changed

+59
-11
lines changed

6 files changed

+59
-11
lines changed

config/node.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"time"
1111

12+
"github.com/asaskevich/govalidator"
1213
"github.com/sentinel-official/sentinel-go-sdk/libs/netip"
1314
"github.com/sentinel-official/sentinel-go-sdk/types"
1415
"github.com/sentinel-official/sentinel-go-sdk/utils"
@@ -372,5 +373,10 @@ func validateRemoteAddr(addr string) error {
372373
return errors.New("addr is neither IPv4 nor IPv6")
373374
}
374375

375-
return nil
376+
// Validate the DNS name format.
377+
if govalidator.IsDNSName(addr) {
378+
return nil
379+
}
380+
381+
return fmt.Errorf("unsupported addr %q", addr)
376382
}

core/context.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package core
22

33
import (
4+
"context"
45
"errors"
56
"io"
67
"path/filepath"
@@ -250,6 +251,26 @@ func (c *Context) TLSKeyFile() string {
250251
return filepath.Join(c.HomeDir(), "tls.key")
251252
}
252253

254+
// SanitizedGigabytePrices returns gigabyte prices filtered to include only valid denominations.
255+
func (c *Context) SanitizedGigabytePrices(ctx context.Context) v1.Prices {
256+
params, err := c.Client().NodeParams(ctx)
257+
if err != nil {
258+
panic(err)
259+
}
260+
261+
return c.sanitizePrices(c.GigabytePrices(), params.GetMinGigabytePrices())
262+
}
263+
264+
// SanitizedHourlyPrices returns hourly prices filtered to include only valid denominations.
265+
func (c *Context) SanitizedHourlyPrices(ctx context.Context) v1.Prices {
266+
params, err := c.Client().NodeParams(ctx)
267+
if err != nil {
268+
panic(err)
269+
}
270+
271+
return c.sanitizePrices(c.HourlyPrices(), params.GetMinHourlyPrices())
272+
}
273+
253274
// SetLocation sets the geolocation data in the context.
254275
func (c *Context) SetLocation(location *geoip.Location) {
255276
c.fm.Lock()
@@ -409,3 +430,15 @@ func (c *Context) checkSealed() {
409430
panic(errors.New("context is sealed"))
410431
}
411432
}
433+
434+
// sanitizePrices filters and validates a set of prices against the minimum required prices.
435+
func (c *Context) sanitizePrices(prices v1.Prices, minPrices v1.Prices) (newPrices v1.Prices) {
436+
m := minPrices.Map()
437+
for _, price := range prices {
438+
if _, ok := m[price.Denom]; ok {
439+
newPrices = newPrices.Add(price)
440+
}
441+
}
442+
443+
return
444+
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.24.6
44

55
require (
66
cosmossdk.io/math v1.5.3
7+
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
78
github.com/cosmos/cosmos-sdk v0.47.17
89
github.com/gin-contrib/cors v1.7.6
910
github.com/gin-gonic/gin v1.11.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ github.com/apernet/quic-go v0.48.2-0.20241104191913-cb103fcecfe7 h1:zO38yBOvQ1dL
6666
github.com/apernet/quic-go v0.48.2-0.20241104191913-cb103fcecfe7/go.mod h1:LoSUY2chVqNQCDyi4IZGqPpXLy1FuCkE37PKwtJvNGg=
6767
github.com/armon/go-metrics v0.4.1 h1:hR91U9KYmb6bLBYLQjyM+3j+rcd/UhE+G78SFnF8gJA=
6868
github.com/armon/go-metrics v0.4.1/go.mod h1:E6amYzXo6aW1tqzoZGT755KkbgrJsSdpwZ+3JqfkOG4=
69+
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
70+
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
6971
github.com/avast/retry-go/v4 v4.7.0 h1:yjDs35SlGvKwRNSykujfjdMxMhMQQM0TnIjJaHB+Zio=
7072
github.com/avast/retry-go/v4 v4.7.0/go.mod h1:ZMPDa3sY2bKgpLtap9JRUgk2yTAba7cgiFhqxY2Sg6Q=
7173
github.com/aws/aws-sdk-go v1.44.203 h1:pcsP805b9acL3wUqa4JR2vg1k2wnItkDYNvfmcy6F+U=

node/node.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,20 @@ func (n *Node) Register(ctx context.Context) error {
8080
return nil
8181
}
8282

83+
gigabytePrices := n.Context().SanitizedGigabytePrices(ctx)
84+
hourlyPrices := n.Context().SanitizedHourlyPrices(ctx)
85+
8386
log.Info("Registering node",
84-
"gigabyte_price", n.Context().GigabytePrices(),
85-
"hourly_price", n.Context().HourlyPrices(),
87+
"gigabyte_prices", gigabytePrices,
88+
"hourly_price", hourlyPrices,
8689
"remote_addrs", n.Context().APIAddrs(),
8790
)
8891

8992
// Prepare a message to register the node.
9093
msg := v3.NewMsgRegisterNodeRequest(
9194
n.Context().AccAddr(),
92-
n.Context().GigabytePrices(),
93-
n.Context().HourlyPrices(),
95+
gigabytePrices,
96+
hourlyPrices,
9497
n.Context().APIAddrs(),
9598
)
9699

@@ -106,17 +109,20 @@ func (n *Node) Register(ctx context.Context) error {
106109

107110
// UpdateDetails updates the node's pricing and address details on the network.
108111
func (n *Node) UpdateDetails(ctx context.Context) error {
112+
gigabytePrices := n.Context().SanitizedGigabytePrices(ctx)
113+
hourlyPrices := n.Context().SanitizedHourlyPrices(ctx)
114+
109115
log.Info("Updating node details",
110-
"gigabyte_prices", n.Context().GigabytePrices(),
111-
"hourly_prices", n.Context().HourlyPrices(),
116+
"gigabyte_prices", gigabytePrices,
117+
"hourly_prices", hourlyPrices,
112118
"remote_addrs", n.Context().APIAddrs(),
113119
)
114120

115121
// Prepare a message to update the node's details.
116122
msg := v3.NewMsgUpdateNodeDetailsRequest(
117123
n.Context().NodeAddr(),
118-
n.Context().GigabytePrices(),
119-
n.Context().HourlyPrices(),
124+
gigabytePrices,
125+
hourlyPrices,
120126
n.Context().APIAddrs(),
121127
)
122128

workers/node.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func NewNodePricesUpdateWorker(c *core.Context, interval time.Duration) cron.Wor
5454

5555
var gigabytePrices v1.Prices
5656

57-
for _, price := range c.GigabytePrices() {
57+
for _, price := range c.SanitizedGigabytePrices(ctx) {
5858
price, err := price.UpdateQuoteValue(ctx, client.GetQuotePrice)
5959
if err != nil {
6060
return fmt.Errorf("updating quote price for denom %q: %w", price.Denom, err)
@@ -65,7 +65,7 @@ func NewNodePricesUpdateWorker(c *core.Context, interval time.Duration) cron.Wor
6565

6666
var hourlyPrices v1.Prices
6767

68-
for _, price := range c.HourlyPrices() {
68+
for _, price := range c.SanitizedHourlyPrices(ctx) {
6969
price, err := price.UpdateQuoteValue(ctx, client.GetQuotePrice)
7070
if err != nil {
7171
return fmt.Errorf("updating quote price for denom %q: %w", price.Denom, err)

0 commit comments

Comments
 (0)