2019-11-04 19:01:02 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package satellite
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-01-29 23:04:30 +00:00
|
|
|
"errors"
|
2020-01-28 17:35:45 +00:00
|
|
|
"net"
|
2022-05-06 22:04:07 +01:00
|
|
|
"runtime/pprof"
|
2019-11-04 19:01:02 +00:00
|
|
|
|
2019-11-08 20:40:39 +00:00
|
|
|
"github.com/spacemonkeygo/monkit/v3"
|
2019-11-04 19:01:02 +00:00
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/identity"
|
|
|
|
"storj.io/common/peertls/extensions"
|
|
|
|
"storj.io/common/peertls/tlsopts"
|
|
|
|
"storj.io/common/rpc"
|
|
|
|
"storj.io/common/storj"
|
2020-03-23 19:18:20 +00:00
|
|
|
"storj.io/private/debug"
|
2020-03-23 19:30:31 +00:00
|
|
|
"storj.io/private/version"
|
2020-01-28 23:13:59 +00:00
|
|
|
"storj.io/storj/private/lifecycle"
|
2019-11-14 19:46:15 +00:00
|
|
|
version_checker "storj.io/storj/private/version/checker"
|
2019-11-04 19:01:02 +00:00
|
|
|
"storj.io/storj/satellite/accounting"
|
2020-07-07 15:48:09 +01:00
|
|
|
"storj.io/storj/satellite/accounting/projectbwcleanup"
|
2019-11-04 19:01:02 +00:00
|
|
|
"storj.io/storj/satellite/accounting/rollup"
|
2020-11-30 19:34:42 +00:00
|
|
|
"storj.io/storj/satellite/accounting/rolluparchive"
|
2019-11-04 19:01:02 +00:00
|
|
|
"storj.io/storj/satellite/accounting/tally"
|
2023-02-13 17:32:39 +00:00
|
|
|
"storj.io/storj/satellite/analytics"
|
2019-11-04 19:01:02 +00:00
|
|
|
"storj.io/storj/satellite/audit"
|
2023-02-13 17:32:39 +00:00
|
|
|
"storj.io/storj/satellite/console"
|
2022-01-06 19:46:53 +00:00
|
|
|
"storj.io/storj/satellite/console/consoleauth"
|
2023-04-28 12:43:27 +01:00
|
|
|
"storj.io/storj/satellite/console/dbcleanup"
|
2022-01-06 19:46:53 +00:00
|
|
|
"storj.io/storj/satellite/console/emailreminders"
|
|
|
|
"storj.io/storj/satellite/mailservice"
|
2021-05-13 09:14:18 +01:00
|
|
|
"storj.io/storj/satellite/metabase"
|
2021-05-28 10:42:55 +01:00
|
|
|
"storj.io/storj/satellite/metabase/segmentloop"
|
2021-05-06 12:54:10 +01:00
|
|
|
"storj.io/storj/satellite/metabase/zombiedeletion"
|
2020-04-15 20:20:16 +01:00
|
|
|
"storj.io/storj/satellite/metainfo/expireddeletion"
|
2022-11-07 19:08:53 +00:00
|
|
|
"storj.io/storj/satellite/nodeevents"
|
2019-11-04 19:01:02 +00:00
|
|
|
"storj.io/storj/satellite/overlay"
|
2022-10-07 21:28:51 +01:00
|
|
|
"storj.io/storj/satellite/overlay/offlinenodes"
|
2020-12-31 18:43:13 +00:00
|
|
|
"storj.io/storj/satellite/overlay/straynodes"
|
2019-11-04 19:01:02 +00:00
|
|
|
"storj.io/storj/satellite/payments"
|
2023-02-13 17:32:39 +00:00
|
|
|
"storj.io/storj/satellite/payments/accountfreeze"
|
2022-06-17 00:29:31 +01:00
|
|
|
"storj.io/storj/satellite/payments/billing"
|
2022-07-08 16:23:56 +01:00
|
|
|
"storj.io/storj/satellite/payments/storjscan"
|
2023-04-06 12:41:14 +01:00
|
|
|
"storj.io/storj/satellite/payments/stripe"
|
2019-11-04 19:01:02 +00:00
|
|
|
"storj.io/storj/satellite/repair/checker"
|
2021-06-23 00:09:39 +01:00
|
|
|
"storj.io/storj/satellite/reputation"
|
2019-11-04 19:01:02 +00:00
|
|
|
)
|
|
|
|
|
2020-12-05 16:01:42 +00:00
|
|
|
// Core is the satellite core process that runs chores.
|
2019-11-04 19:01:02 +00:00
|
|
|
//
|
|
|
|
// architecture: Peer
|
|
|
|
type Core struct {
|
|
|
|
// core dependencies
|
|
|
|
Log *zap.Logger
|
|
|
|
Identity *identity.FullIdentity
|
|
|
|
DB DB
|
|
|
|
|
2020-01-28 23:13:59 +00:00
|
|
|
Servers *lifecycle.Group
|
|
|
|
Services *lifecycle.Group
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
Dialer rpc.Dialer
|
|
|
|
|
2020-02-21 17:41:54 +00:00
|
|
|
Version struct {
|
|
|
|
Chore *version_checker.Chore
|
|
|
|
Service *version_checker.Service
|
|
|
|
}
|
2019-11-04 19:01:02 +00:00
|
|
|
|
2022-01-06 19:46:53 +00:00
|
|
|
Mail struct {
|
|
|
|
Service *mailservice.Service
|
|
|
|
EmailReminders *emailreminders.Chore
|
|
|
|
}
|
|
|
|
|
2020-01-28 17:35:45 +00:00
|
|
|
Debug struct {
|
|
|
|
Listener net.Listener
|
|
|
|
Server *debug.Server
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
// services and endpoints
|
|
|
|
Overlay struct {
|
2022-10-07 21:28:51 +01:00
|
|
|
DB overlay.DB
|
|
|
|
Service *overlay.Service
|
|
|
|
OfflineNodeEmails *offlinenodes.Chore
|
|
|
|
DQStrayNodes *straynodes.Chore
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
2022-11-07 19:08:53 +00:00
|
|
|
NodeEvents struct {
|
|
|
|
DB nodeevents.DB
|
|
|
|
Notifier nodeevents.Notifier
|
|
|
|
Chore *nodeevents.Chore
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
Metainfo struct {
|
2021-05-28 10:42:55 +01:00
|
|
|
Metabase *metabase.DB
|
|
|
|
SegmentLoop *segmentloop.Service
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 00:09:39 +01:00
|
|
|
Reputation struct {
|
|
|
|
Service *reputation.Service
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
Repair struct {
|
2020-01-29 01:02:30 +00:00
|
|
|
Checker *checker.Checker
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
2020-12-31 18:43:13 +00:00
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
Audit struct {
|
2023-01-26 01:21:47 +00:00
|
|
|
VerifyQueue audit.VerifyQueue
|
|
|
|
ReverifyQueue audit.ReverifyQueue
|
|
|
|
ContainmentSyncChore *audit.ContainmentSyncChore
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
2020-04-15 20:20:16 +01:00
|
|
|
ExpiredDeletion struct {
|
|
|
|
Chore *expireddeletion.Chore
|
|
|
|
}
|
|
|
|
|
2021-05-06 12:54:10 +01:00
|
|
|
ZombieDeletion struct {
|
|
|
|
Chore *zombiedeletion.Chore
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
Accounting struct {
|
2020-07-07 15:48:09 +01:00
|
|
|
Tally *tally.Service
|
|
|
|
Rollup *rollup.Service
|
2020-11-30 19:34:42 +00:00
|
|
|
RollupArchiveChore *rolluparchive.Chore
|
2020-07-07 15:48:09 +01:00
|
|
|
ProjectBWCleanupChore *projectbwcleanup.Chore
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LiveAccounting struct {
|
|
|
|
Cache accounting.Cache
|
|
|
|
}
|
|
|
|
|
|
|
|
Payments struct {
|
2023-02-13 17:32:39 +00:00
|
|
|
AccountFreeze *accountfreeze.Chore
|
2022-06-17 00:29:31 +01:00
|
|
|
Accounts payments.Accounts
|
|
|
|
BillingChore *billing.Chore
|
|
|
|
StorjscanClient *storjscan.Client
|
|
|
|
StorjscanService *storjscan.Service
|
|
|
|
StorjscanChore *storjscan.Chore
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
2023-04-28 12:43:27 +01:00
|
|
|
|
|
|
|
ConsoleDBCleanup struct {
|
|
|
|
Chore *dbcleanup.Chore
|
|
|
|
}
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// New creates a new satellite.
|
2020-01-17 22:55:53 +00:00
|
|
|
func New(log *zap.Logger, full *identity.FullIdentity, db DB,
|
2021-05-13 09:14:18 +01:00
|
|
|
metabaseDB *metabase.DB, revocationDB extensions.RevocationDB,
|
2023-03-07 09:29:25 +00:00
|
|
|
liveAccounting accounting.Cache, versionInfo version.Info, config *Config,
|
|
|
|
atomicLogLevel *zap.AtomicLevel) (*Core, error) {
|
2019-11-04 19:01:02 +00:00
|
|
|
peer := &Core{
|
|
|
|
Log: log,
|
|
|
|
Identity: full,
|
|
|
|
DB: db,
|
2020-01-28 23:13:59 +00:00
|
|
|
|
|
|
|
Servers: lifecycle.NewGroup(log.Named("servers")),
|
|
|
|
Services: lifecycle.NewGroup(log.Named("services")),
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 17:35:45 +00:00
|
|
|
{ // setup debug
|
|
|
|
var err error
|
|
|
|
if config.Debug.Address != "" {
|
|
|
|
peer.Debug.Listener, err = net.Listen("tcp", config.Debug.Address)
|
|
|
|
if err != nil {
|
2020-01-29 23:04:30 +00:00
|
|
|
withoutStack := errors.New(err.Error())
|
|
|
|
peer.Log.Debug("failed to start debug endpoints", zap.Error(withoutStack))
|
2020-01-28 17:35:45 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-30 12:49:40 +00:00
|
|
|
debugConfig := config.Debug
|
|
|
|
debugConfig.ControlTitle = "Core"
|
2020-05-12 20:10:32 +01:00
|
|
|
peer.Debug.Server = debug.NewServerWithAtomicLevel(log.Named("debug"), peer.Debug.Listener, monkit.Default, debugConfig, atomicLogLevel)
|
2020-01-28 17:35:45 +00:00
|
|
|
peer.Servers.Add(lifecycle.Item{
|
|
|
|
Name: "debug",
|
|
|
|
Run: peer.Debug.Server.Run,
|
|
|
|
Close: peer.Debug.Server.Close,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
var err error
|
|
|
|
|
|
|
|
{ // setup version control
|
2020-04-15 20:32:22 +01:00
|
|
|
peer.Log.Info("Version info",
|
|
|
|
zap.Stringer("Version", versionInfo.Version.Version),
|
|
|
|
zap.String("Commit Hash", versionInfo.CommitHash),
|
|
|
|
zap.Stringer("Build Timestamp", versionInfo.Timestamp),
|
|
|
|
zap.Bool("Release Build", versionInfo.Release),
|
|
|
|
)
|
2020-02-21 17:41:54 +00:00
|
|
|
peer.Version.Service = version_checker.NewService(log.Named("version"), config.Version, versionInfo, "Satellite")
|
|
|
|
peer.Version.Chore = version_checker.NewChore(peer.Version.Service, config.Version.CheckInterval)
|
2020-01-28 23:13:59 +00:00
|
|
|
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "version",
|
2020-02-21 17:41:54 +00:00
|
|
|
Run: peer.Version.Chore.Run,
|
2020-01-28 23:13:59 +00:00
|
|
|
})
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup listener and server
|
|
|
|
sc := config.Server
|
|
|
|
|
|
|
|
tlsOptions, err := tlsopts.NewOptions(peer.Identity, sc.Config, revocationDB)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
peer.Dialer = rpc.NewDefaultDialer(tlsOptions)
|
|
|
|
}
|
|
|
|
|
2022-01-06 19:46:53 +00:00
|
|
|
{ // setup mailservice
|
|
|
|
peer.Mail.Service, err = setupMailService(peer.Log, *config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "mail:service",
|
|
|
|
Close: peer.Mail.Service.Close,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup email reminders
|
2022-05-27 18:16:14 +01:00
|
|
|
if config.EmailReminders.Enable {
|
|
|
|
authTokens := consoleauth.NewService(config.ConsoleAuth, &consoleauth.Hmac{Secret: []byte(config.Console.AuthTokenSecret)})
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2022-01-06 19:46:53 +00:00
|
|
|
|
2022-05-27 18:16:14 +01:00
|
|
|
peer.Mail.EmailReminders = emailreminders.NewChore(
|
|
|
|
peer.Log.Named("console:chore"),
|
|
|
|
authTokens,
|
|
|
|
peer.DB.Console().Users(),
|
|
|
|
peer.Mail.Service,
|
|
|
|
config.EmailReminders,
|
|
|
|
config.Console.ExternalAddress,
|
|
|
|
)
|
2022-01-06 19:46:53 +00:00
|
|
|
|
2022-05-27 18:16:14 +01:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "mail:email-reminders",
|
|
|
|
Run: peer.Mail.EmailReminders.Run,
|
|
|
|
Close: peer.Mail.EmailReminders.Close,
|
|
|
|
})
|
|
|
|
}
|
2022-01-06 19:46:53 +00:00
|
|
|
}
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
{ // setup overlay
|
2020-03-12 18:37:57 +00:00
|
|
|
peer.Overlay.DB = peer.DB.OverlayCache()
|
2023-03-08 12:25:10 +00:00
|
|
|
peer.Overlay.Service, err = overlay.NewService(peer.Log.Named("overlay"), peer.Overlay.DB, peer.DB.NodeEvents(), config.Console.ExternalAddress, config.Console.SatelliteName, config.Overlay)
|
2020-12-22 19:07:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "overlay",
|
2022-06-28 12:53:39 +01:00
|
|
|
Run: peer.Overlay.Service.Run,
|
2020-01-28 23:13:59 +00:00
|
|
|
Close: peer.Overlay.Service.Close,
|
|
|
|
})
|
2020-12-31 18:43:13 +00:00
|
|
|
|
2022-10-07 21:28:51 +01:00
|
|
|
if config.Overlay.SendNodeEmails {
|
|
|
|
peer.Overlay.OfflineNodeEmails = offlinenodes.NewChore(log.Named("overlay:offline-node-emails"), peer.Mail.Service, peer.Overlay.Service, config.OfflineNodes)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "overlay:offline-node-emails",
|
|
|
|
Run: peer.Overlay.OfflineNodeEmails.Run,
|
|
|
|
Close: peer.Overlay.OfflineNodeEmails.Close,
|
|
|
|
})
|
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Overlay Offline Node Emails", peer.Overlay.OfflineNodeEmails.Loop))
|
|
|
|
}
|
|
|
|
|
2020-12-31 18:43:13 +00:00
|
|
|
if config.StrayNodes.EnableDQ {
|
2022-10-12 18:56:15 +01:00
|
|
|
peer.Overlay.DQStrayNodes = straynodes.NewChore(peer.Log.Named("overlay:dq-stray-nodes"), peer.Overlay.Service, config.StrayNodes)
|
2020-12-31 18:43:13 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "overlay:dq-stray-nodes",
|
|
|
|
Run: peer.Overlay.DQStrayNodes.Run,
|
|
|
|
Close: peer.Overlay.DQStrayNodes.Close,
|
|
|
|
})
|
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Overlay DQ Stray Nodes", peer.Overlay.DQStrayNodes.Loop))
|
|
|
|
}
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
2022-11-07 19:08:53 +00:00
|
|
|
{ // setup node events
|
|
|
|
if config.Overlay.SendNodeEmails {
|
2022-11-14 22:15:29 +00:00
|
|
|
var notifier nodeevents.Notifier
|
|
|
|
switch config.NodeEvents.Notifier {
|
|
|
|
case "customer.io":
|
|
|
|
notifier = nodeevents.NewCustomerioNotifier(
|
|
|
|
log.Named("node-events:customer.io-notifier"),
|
|
|
|
config.NodeEvents.Customerio,
|
|
|
|
)
|
|
|
|
default:
|
|
|
|
notifier = nodeevents.NewMockNotifier(log.Named("node-events:mock-notifier"))
|
|
|
|
}
|
|
|
|
peer.NodeEvents.Notifier = notifier
|
2022-11-07 19:08:53 +00:00
|
|
|
peer.NodeEvents.DB = peer.DB.NodeEvents()
|
2022-11-14 22:15:29 +00:00
|
|
|
peer.NodeEvents.Chore = nodeevents.NewChore(peer.Log.Named("node-events:chore"), peer.NodeEvents.DB, config.Console.SatelliteName, peer.NodeEvents.Notifier, config.NodeEvents)
|
2022-11-07 19:08:53 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "node-events:chore",
|
|
|
|
Run: peer.NodeEvents.Chore.Run,
|
|
|
|
Close: peer.NodeEvents.Chore.Close,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
{ // setup live accounting
|
|
|
|
peer.LiveAccounting.Cache = liveAccounting
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup metainfo
|
2020-10-29 16:54:35 +00:00
|
|
|
peer.Metainfo.Metabase = metabaseDB
|
2021-09-09 16:21:42 +01:00
|
|
|
|
2021-05-28 10:42:55 +01:00
|
|
|
peer.Metainfo.SegmentLoop = segmentloop.New(
|
2021-07-29 09:28:23 +01:00
|
|
|
peer.Log.Named("metainfo:segmentloop"),
|
2021-05-28 10:42:55 +01:00
|
|
|
config.Metainfo.SegmentLoop,
|
|
|
|
peer.Metainfo.Metabase,
|
|
|
|
)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "metainfo:segmentloop",
|
|
|
|
Run: peer.Metainfo.SegmentLoop.Run,
|
|
|
|
Close: peer.Metainfo.SegmentLoop.Close,
|
|
|
|
})
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
2023-01-19 16:17:01 +00:00
|
|
|
{ // setup data repair
|
|
|
|
log := peer.Log.Named("repair:checker")
|
|
|
|
if config.Repairer.UseRangedLoop {
|
|
|
|
log.Info("using ranged loop")
|
|
|
|
} else {
|
|
|
|
peer.Repair.Checker = checker.NewChecker(
|
|
|
|
log,
|
|
|
|
peer.DB.RepairQueue(),
|
|
|
|
peer.Metainfo.Metabase,
|
|
|
|
peer.Metainfo.SegmentLoop,
|
|
|
|
peer.Overlay.Service,
|
|
|
|
config.Checker)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "repair:checker",
|
|
|
|
Run: peer.Repair.Checker.Run,
|
|
|
|
Close: peer.Repair.Checker.Close,
|
|
|
|
})
|
|
|
|
|
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Repair Checker", peer.Repair.Checker.Loop))
|
|
|
|
}
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 00:09:39 +01:00
|
|
|
{ // setup reputation
|
2022-05-07 20:04:12 +01:00
|
|
|
reputationDB := peer.DB.Reputation()
|
|
|
|
if config.Reputation.FlushInterval > 0 {
|
2022-07-28 00:43:02 +01:00
|
|
|
cachingDB := reputation.NewCachingDB(log.Named("reputation:writecache"), reputationDB, config.Reputation)
|
2022-05-07 20:04:12 +01:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "reputation:writecache",
|
|
|
|
Run: cachingDB.Manage,
|
|
|
|
})
|
|
|
|
reputationDB = cachingDB
|
|
|
|
}
|
2021-06-23 00:09:39 +01:00
|
|
|
peer.Reputation.Service = reputation.NewService(log.Named("reputation:service"),
|
2022-09-29 15:03:01 +01:00
|
|
|
peer.Overlay.Service,
|
2022-05-07 20:04:12 +01:00
|
|
|
reputationDB,
|
2021-06-23 00:09:39 +01:00
|
|
|
config.Reputation,
|
|
|
|
)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "reputation",
|
|
|
|
Close: peer.Reputation.Service.Close,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
{ // setup audit
|
|
|
|
config := config.Audit
|
|
|
|
|
2022-11-11 23:11:40 +00:00
|
|
|
peer.Audit.VerifyQueue = db.VerifyQueue()
|
2023-01-26 01:21:47 +00:00
|
|
|
peer.Audit.ReverifyQueue = db.ReverifyQueue()
|
2019-11-04 19:01:02 +00:00
|
|
|
|
2023-04-24 11:07:16 +01:00
|
|
|
peer.Audit.ContainmentSyncChore = audit.NewContainmentSyncChore(peer.Log.Named("audit:containment-sync-chore"),
|
|
|
|
peer.Audit.ReverifyQueue,
|
|
|
|
peer.Overlay.DB,
|
|
|
|
config.ContainmentSyncChoreInterval,
|
|
|
|
)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "audit:containment-sync-chore",
|
|
|
|
Run: peer.Audit.ContainmentSyncChore.Run,
|
|
|
|
})
|
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Audit Containment Sync Chore", peer.Audit.ContainmentSyncChore.Loop))
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
2020-04-15 20:20:16 +01:00
|
|
|
{ // setup expired segment cleanup
|
|
|
|
peer.ExpiredDeletion.Chore = expireddeletion.NewChore(
|
|
|
|
peer.Log.Named("core-expired-deletion"),
|
|
|
|
config.ExpiredDeletion,
|
2020-11-30 12:33:06 +00:00
|
|
|
peer.Metainfo.Metabase,
|
2020-04-15 20:20:16 +01:00
|
|
|
)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
2020-11-30 12:33:06 +00:00
|
|
|
Name: "expireddeletion:chore",
|
|
|
|
Run: peer.ExpiredDeletion.Chore.Run,
|
|
|
|
Close: peer.ExpiredDeletion.Chore.Close,
|
2020-04-15 20:20:16 +01:00
|
|
|
})
|
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Expired Segments Chore", peer.ExpiredDeletion.Chore.Loop))
|
|
|
|
}
|
|
|
|
|
2021-05-06 12:54:10 +01:00
|
|
|
{ // setup zombie objects cleanup
|
|
|
|
peer.ZombieDeletion.Chore = zombiedeletion.NewChore(
|
|
|
|
peer.Log.Named("core-zombie-deletion"),
|
|
|
|
config.ZombieDeletion,
|
|
|
|
peer.Metainfo.Metabase,
|
|
|
|
)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "zombiedeletion:chore",
|
|
|
|
Run: peer.ZombieDeletion.Chore.Run,
|
|
|
|
Close: peer.ZombieDeletion.Chore.Close,
|
|
|
|
})
|
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Zombie Objects Chore", peer.ZombieDeletion.Chore.Loop))
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
{ // setup accounting
|
2022-10-05 11:53:02 +01:00
|
|
|
peer.Accounting.Tally = tally.New(peer.Log.Named("accounting:tally"), peer.DB.StoragenodeAccounting(), peer.DB.ProjectAccounting(), peer.LiveAccounting.Cache, peer.Metainfo.Metabase, peer.DB.Buckets(), config.Tally)
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "accounting:tally",
|
|
|
|
Run: peer.Accounting.Tally.Run,
|
|
|
|
Close: peer.Accounting.Tally.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Accounting Tally", peer.Accounting.Tally.Loop))
|
2020-01-28 23:13:59 +00:00
|
|
|
|
2020-11-16 09:02:54 +00:00
|
|
|
// Lets add 1 more day so we catch any off by one errors when deleting tallies
|
|
|
|
orderExpirationPlusDay := config.Orders.Expiration + config.Rollup.Interval
|
2022-07-20 09:10:29 +01:00
|
|
|
peer.Accounting.Rollup = rollup.New(peer.Log.Named("accounting:rollup"), peer.DB.StoragenodeAccounting(), config.Rollup, orderExpirationPlusDay)
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "accounting:rollup",
|
|
|
|
Run: peer.Accounting.Rollup.Run,
|
|
|
|
Close: peer.Accounting.Rollup.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Accounting Rollup", peer.Accounting.Rollup.Loop))
|
2020-01-28 23:13:59 +00:00
|
|
|
|
2020-07-07 15:48:09 +01:00
|
|
|
peer.Accounting.ProjectBWCleanupChore = projectbwcleanup.NewChore(peer.Log.Named("accounting:chore"), peer.DB.ProjectAccounting(), config.ProjectBWCleanup)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "accounting:project-bw-rollup",
|
|
|
|
Run: peer.Accounting.ProjectBWCleanupChore.Run,
|
|
|
|
Close: peer.Accounting.ProjectBWCleanupChore.Close,
|
|
|
|
})
|
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Accounting Project Bandwidth Rollup", peer.Accounting.ProjectBWCleanupChore.Loop))
|
2020-11-30 19:34:42 +00:00
|
|
|
|
|
|
|
if config.RollupArchive.Enabled {
|
|
|
|
peer.Accounting.RollupArchiveChore = rolluparchive.New(peer.Log.Named("accounting:rollup-archive"), peer.DB.StoragenodeAccounting(), peer.DB.ProjectAccounting(), config.RollupArchive)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "accounting:rollup-archive",
|
|
|
|
Run: peer.Accounting.RollupArchiveChore.Run,
|
|
|
|
Close: peer.Accounting.RollupArchiveChore.Close,
|
|
|
|
})
|
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Accounting Rollup Archive", peer.Accounting.RollupArchiveChore.Loop))
|
|
|
|
} else {
|
|
|
|
peer.Log.Named("rolluparchive").Info("disabled")
|
|
|
|
}
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: remove in future, should be in API
|
|
|
|
{ // setup payments
|
2019-11-05 20:26:19 +00:00
|
|
|
pc := config.Payments
|
2019-11-04 19:01:02 +00:00
|
|
|
|
2023-04-06 12:41:14 +01:00
|
|
|
var stripeClient stripe.Client
|
2019-11-05 20:26:19 +00:00
|
|
|
switch pc.Provider {
|
2023-03-03 18:10:01 +00:00
|
|
|
case "": // just new mock, only used in testing binaries
|
2023-04-06 12:41:14 +01:00
|
|
|
stripeClient = stripe.NewStripeMock(
|
2020-10-08 18:14:09 +01:00
|
|
|
peer.DB.StripeCoinPayments().Customers(),
|
|
|
|
peer.DB.Console().Users(),
|
|
|
|
)
|
2023-03-03 18:10:01 +00:00
|
|
|
case "mock":
|
|
|
|
stripeClient = pc.MockProvider
|
2019-11-04 19:01:02 +00:00
|
|
|
case "stripecoinpayments":
|
2023-04-06 12:41:14 +01:00
|
|
|
stripeClient = stripe.NewStripeClient(log, pc.StripeCoinPayments)
|
2023-03-03 18:10:01 +00:00
|
|
|
default:
|
|
|
|
return nil, errs.New("invalid stripe coin payments provider %q", pc.Provider)
|
2020-05-18 10:17:05 +01:00
|
|
|
}
|
2019-11-04 19:01:02 +00:00
|
|
|
|
2022-12-01 07:40:52 +00:00
|
|
|
prices, err := pc.UsagePrice.ToModel()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
priceOverrides, err := pc.UsagePriceOverrides.ToModels()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
2023-04-06 12:41:14 +01:00
|
|
|
service, err := stripe.NewService(
|
2020-05-18 10:17:05 +01:00
|
|
|
peer.Log.Named("payments.stripe:service"),
|
|
|
|
stripeClient,
|
|
|
|
pc.StripeCoinPayments,
|
|
|
|
peer.DB.StripeCoinPayments(),
|
2022-05-10 20:19:53 +01:00
|
|
|
peer.DB.Wallets(),
|
|
|
|
peer.DB.Billing(),
|
2020-05-18 10:17:05 +01:00
|
|
|
peer.DB.Console().Projects(),
|
2023-01-30 22:11:12 +00:00
|
|
|
peer.DB.Console().Users(),
|
2020-05-18 10:17:05 +01:00
|
|
|
peer.DB.ProjectAccounting(),
|
2022-12-01 07:40:52 +00:00
|
|
|
prices,
|
|
|
|
priceOverrides,
|
2023-01-30 22:11:12 +00:00
|
|
|
pc.PackagePlans.Packages,
|
2021-08-27 01:51:26 +01:00
|
|
|
pc.BonusRate)
|
2020-05-18 10:17:05 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
2020-05-18 10:17:05 +01:00
|
|
|
|
|
|
|
peer.Payments.Accounts = service.Accounts()
|
|
|
|
|
2022-07-08 16:23:56 +01:00
|
|
|
peer.Payments.StorjscanClient = storjscan.NewClient(
|
|
|
|
pc.Storjscan.Endpoint,
|
|
|
|
pc.Storjscan.Auth.Identifier,
|
|
|
|
pc.Storjscan.Auth.Secret)
|
|
|
|
|
2022-06-17 00:29:31 +01:00
|
|
|
peer.Payments.StorjscanService = storjscan.NewService(log.Named("storjscan-service"),
|
|
|
|
peer.DB.Wallets(),
|
|
|
|
peer.DB.StorjscanPayments(),
|
|
|
|
peer.Payments.StorjscanClient)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
2022-07-08 16:23:56 +01:00
|
|
|
peer.Payments.StorjscanChore = storjscan.NewChore(
|
|
|
|
peer.Log.Named("payments.storjscan:chore"),
|
|
|
|
peer.Payments.StorjscanClient,
|
|
|
|
peer.DB.StorjscanPayments(),
|
|
|
|
config.Payments.Storjscan.Confirmations,
|
|
|
|
config.Payments.Storjscan.Interval,
|
|
|
|
config.Payments.Storjscan.DisableLoop,
|
|
|
|
)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "payments.storjscan:chore",
|
|
|
|
Run: peer.Payments.StorjscanChore.Run,
|
|
|
|
})
|
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Payments Storjscan", peer.Payments.StorjscanChore.TransactionCycle),
|
|
|
|
)
|
2022-06-17 00:29:31 +01:00
|
|
|
|
|
|
|
peer.Payments.BillingChore = billing.NewChore(
|
|
|
|
peer.Log.Named("payments.billing:chore"),
|
|
|
|
[]billing.PaymentType{peer.Payments.StorjscanService},
|
|
|
|
peer.DB.Billing(),
|
|
|
|
config.Payments.BillingConfig.Interval,
|
|
|
|
config.Payments.BillingConfig.DisableLoop,
|
2023-03-28 02:42:26 +01:00
|
|
|
config.Payments.BonusRate,
|
2022-06-17 00:29:31 +01:00
|
|
|
)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "billing:chore",
|
|
|
|
Run: peer.Payments.BillingChore.Run,
|
|
|
|
Close: peer.Payments.BillingChore.Close,
|
|
|
|
})
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
2023-02-13 17:32:39 +00:00
|
|
|
{ // setup account freeze
|
|
|
|
if config.AccountFreeze.Enabled {
|
2023-03-10 11:19:07 +00:00
|
|
|
analyticService := analytics.NewService(peer.Log.Named("analytics:service"), config.Analytics, config.Console.SatelliteName)
|
2023-02-13 17:32:39 +00:00
|
|
|
peer.Payments.AccountFreeze = accountfreeze.NewChore(
|
|
|
|
peer.Log.Named("payments.accountfreeze:chore"),
|
|
|
|
peer.DB.StripeCoinPayments(),
|
|
|
|
peer.Payments.Accounts,
|
|
|
|
peer.DB.Console().Users(),
|
2023-03-10 11:19:07 +00:00
|
|
|
console.NewAccountFreezeService(db.Console().AccountFreezeEvents(), db.Console().Users(), db.Console().Projects(), analyticService),
|
|
|
|
analyticService,
|
2023-02-13 17:32:39 +00:00
|
|
|
config.AccountFreeze,
|
|
|
|
)
|
|
|
|
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "accountfreeze:chore",
|
|
|
|
Run: peer.Payments.AccountFreeze.Run,
|
|
|
|
Close: peer.Payments.AccountFreeze.Close,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-28 12:43:27 +01:00
|
|
|
// setup console DB cleanup service
|
|
|
|
if config.ConsoleDBCleanup.Enabled {
|
|
|
|
peer.ConsoleDBCleanup.Chore = dbcleanup.NewChore(
|
|
|
|
peer.Log.Named("console.dbcleanup:chore"),
|
|
|
|
peer.DB.Console(),
|
|
|
|
config.ConsoleDBCleanup,
|
|
|
|
)
|
|
|
|
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "dbcleanup:chore",
|
|
|
|
Run: peer.ConsoleDBCleanup.Chore.Run,
|
|
|
|
Close: peer.ConsoleDBCleanup.Chore.Close,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
return peer, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run runs satellite until it's either closed or it errors.
|
|
|
|
func (peer *Core) Run(ctx context.Context) (err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
group, ctx := errgroup.WithContext(ctx)
|
|
|
|
|
2022-05-06 22:04:07 +01:00
|
|
|
pprof.Do(ctx, pprof.Labels("subsystem", "core"), func(ctx context.Context) {
|
|
|
|
peer.Servers.Run(ctx, group)
|
|
|
|
peer.Services.Run(ctx, group)
|
2020-01-07 21:34:48 +00:00
|
|
|
|
2022-05-06 22:04:07 +01:00
|
|
|
pprof.Do(ctx, pprof.Labels("name", "subsystem-wait"), func(ctx context.Context) {
|
|
|
|
err = group.Wait()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
return err
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Close closes all the resources.
|
|
|
|
func (peer *Core) Close() error {
|
2020-01-28 23:13:59 +00:00
|
|
|
return errs.Combine(
|
|
|
|
peer.Servers.Close(),
|
|
|
|
peer.Services.Close(),
|
|
|
|
)
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ID returns the peer ID.
|
|
|
|
func (peer *Core) ID() storj.NodeID { return peer.Identity.ID }
|