satellite/overlay: check node difficulty before entering database

closes https://github.com/storj/storj/issues/5568

Change-Id: Id413637c2678e7a7cf8dbf414e082c687c8e8a39
This commit is contained in:
JT Olio 2023-02-15 11:41:26 -05:00 committed by Storj Robot
parent 0a525292e4
commit 77bf88e916
3 changed files with 18 additions and 1 deletions

View File

@ -28,6 +28,7 @@ type Config struct {
NodeSoftwareUpdateEmailCooldown time.Duration `help:"the amount of time to wait between sending Node Software Update emails" default:"168h"`
RepairExcludedCountryCodes []string `help:"list of country codes to exclude nodes from target repair selection" default:"" testDefault:"FR,BE"`
SendNodeEmails bool `help:"whether to send emails to nodes" default:"false"`
MinimumNewNodeIDDifficulty int `help:"the minimum node id difficulty required for new nodes. existing nodes remain allowed" devDefault:"0" releaseDefault:"36"`
}
// AsOfSystemTimeConfig is a configuration struct to enable 'AS OF SYSTEM TIME' for CRDB queries.

View File

@ -41,6 +41,9 @@ var ErrNodeFinishedGE = errs.Class("node finished graceful exit")
// ErrNotEnoughNodes is when selecting nodes failed with the given parameters.
var ErrNotEnoughNodes = errs.Class("not enough nodes")
// ErrLowDifficulty is when the node id's difficulty is too low.
var ErrLowDifficulty = errs.Class("node id difficulty too low")
// DB implements the database for overlay.Service.
//
// architecture: Database
@ -621,7 +624,7 @@ func (service *Service) SetNodeContained(ctx context.Context, node storj.NodeID,
// UpdateCheckIn updates a single storagenode's check-in info if needed.
/*
The check-in info is updated in the database if:
(1) there is no previous entry;
(1) there is no previous entry and the node is allowed (id difficulty, etc);
(2) it has been too long since the last known entry; or
(3) the node hostname, IP address, port, wallet, sw version, or disk capacity
has changed.
@ -645,6 +648,16 @@ func (service *Service) UpdateCheckIn(ctx context.Context, node NodeCheckInInfo,
return nil
}
difficulty, err := node.NodeID.Difficulty()
if err != nil {
// this should never happen
return err
}
if int(difficulty) < service.config.MinimumNewNodeIDDifficulty {
return ErrLowDifficulty.New("node id difficulty is %d when %d is the minimum",
difficulty, service.config.MinimumNewNodeIDDifficulty)
}
node.CountryCode, err = service.GeoIP.LookupISOCountryCode(node.LastIPPort)
if err != nil {
failureMeter.Mark(1)

View File

@ -751,6 +751,9 @@ identity.key-path: /root/.local/share/storj/identity/satellite/identity.key
# a mock list of countries the satellite will attribute to nodes (useful for testing)
# overlay.geo-ip.mock-countries: []
# the minimum node id difficulty required for new nodes. existing nodes remain allowed
# overlay.minimum-new-node-id-difficulty: 36
# the amount of time to wait before accepting a redundant check-in from a node (unmodified info since last check-in)
# overlay.node-check-in-wait-period: 2h0m0s