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/signing"
|
|
|
|
"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"
|
2021-06-01 17:44:09 +01:00
|
|
|
"storj.io/storj/satellite/accounting/nodetally"
|
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"
|
|
|
|
"storj.io/storj/satellite/audit"
|
2022-01-06 19:46:53 +00:00
|
|
|
"storj.io/storj/satellite/console/consoleauth"
|
|
|
|
"storj.io/storj/satellite/console/emailreminders"
|
2019-11-04 19:01:02 +00:00
|
|
|
"storj.io/storj/satellite/gracefulexit"
|
2022-01-06 19:46:53 +00:00
|
|
|
"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"
|
2019-11-04 19:01:02 +00:00
|
|
|
"storj.io/storj/satellite/metrics"
|
|
|
|
"storj.io/storj/satellite/orders"
|
|
|
|
"storj.io/storj/satellite/overlay"
|
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"
|
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"
|
2019-11-04 19:01:02 +00:00
|
|
|
"storj.io/storj/satellite/payments/stripecoinpayments"
|
|
|
|
"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 {
|
2020-12-31 18:43:13 +00:00
|
|
|
DB overlay.DB
|
|
|
|
Service *overlay.Service
|
|
|
|
DQStrayNodes *straynodes.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
|
|
|
}
|
|
|
|
|
|
|
|
Orders struct {
|
2020-01-10 18:53:42 +00:00
|
|
|
DB orders.DB
|
2019-11-04 19:01:02 +00:00
|
|
|
Service *orders.Service
|
2020-01-10 18:53:42 +00:00
|
|
|
Chore *orders.Chore
|
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 {
|
2020-08-20 14:29:02 +01:00
|
|
|
Queues *audit.Queues
|
2019-11-04 19:01:02 +00:00
|
|
|
Worker *audit.Worker
|
|
|
|
Chore *audit.Chore
|
|
|
|
Verifier *audit.Verifier
|
2022-04-11 17:47:14 +01:00
|
|
|
Reporter audit.Reporter
|
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
|
2021-06-01 17:44:09 +01:00
|
|
|
NodeTally *nodetally.Service
|
2020-07-07 15:48:09 +01:00
|
|
|
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 {
|
2022-06-17 00:29:31 +01:00
|
|
|
Accounts payments.Accounts
|
|
|
|
BillingChore *billing.Chore
|
|
|
|
Chore *stripecoinpayments.Chore
|
|
|
|
StorjscanClient *storjscan.Client
|
|
|
|
StorjscanService *storjscan.Service
|
|
|
|
StorjscanChore *storjscan.Chore
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GracefulExit struct {
|
|
|
|
Chore *gracefulexit.Chore
|
|
|
|
}
|
|
|
|
|
|
|
|
Metrics struct {
|
|
|
|
Chore *metrics.Chore
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
2020-10-29 16:54:35 +00:00
|
|
|
liveAccounting accounting.Cache, rollupsWriteCache *orders.RollupsWriteCache,
|
2020-05-12 20:10:32 +01:00
|
|
|
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()
|
2022-09-28 20:53:48 +01:00
|
|
|
peer.Overlay.Service, err = overlay.NewService(peer.Log.Named("overlay"), peer.Overlay.DB, peer.Mail.Service, 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
|
|
|
|
|
|
|
if config.StrayNodes.EnableDQ {
|
|
|
|
peer.Overlay.DQStrayNodes = straynodes.NewChore(peer.Log.Named("overlay:dq-stray-nodes"), peer.Overlay.DB, config.StrayNodes)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup live accounting
|
|
|
|
peer.LiveAccounting.Cache = liveAccounting
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup orders
|
2020-01-17 22:55:53 +00:00
|
|
|
peer.Orders.DB = rollupsWriteCache
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Orders.Chore = orders.NewChore(log.Named("orders:chore"), rollupsWriteCache, config.Orders)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
2021-10-19 17:44:15 +01:00
|
|
|
Name: "orders:chore",
|
2020-01-28 23:13:59 +00:00
|
|
|
Run: peer.Orders.Chore.Run,
|
|
|
|
Close: peer.Orders.Chore.Close,
|
|
|
|
})
|
2020-07-24 18:13:15 +01:00
|
|
|
var err error
|
|
|
|
peer.Orders.Service, err = orders.NewService(
|
2019-11-04 19:01:02 +00:00
|
|
|
peer.Log.Named("orders:service"),
|
|
|
|
signing.SignerFromFullIdentity(peer.Identity),
|
|
|
|
peer.Overlay.Service,
|
2020-01-10 18:53:42 +00:00
|
|
|
peer.Orders.DB,
|
2020-08-27 15:30:04 +01:00
|
|
|
config.Orders,
|
2019-11-04 19:01:02 +00:00
|
|
|
)
|
2020-07-24 18:13:15 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // 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
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup datarepair
|
|
|
|
// TODO: simplify argument list somehow
|
|
|
|
peer.Repair.Checker = checker.NewChecker(
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Log.Named("repair:checker"),
|
2019-11-04 19:01:02 +00:00
|
|
|
peer.DB.RepairQueue(),
|
2020-12-14 17:33:03 +00:00
|
|
|
peer.Metainfo.Metabase,
|
2021-06-25 10:46:38 +01:00
|
|
|
peer.Metainfo.SegmentLoop,
|
2019-11-04 19:01:02 +00:00
|
|
|
peer.Overlay.Service,
|
|
|
|
config.Checker)
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "repair:checker",
|
|
|
|
Run: peer.Repair.Checker.Run,
|
|
|
|
Close: peer.Repair.Checker.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
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
|
2022-02-16 15:56:01 +00:00
|
|
|
// force tcp for now because audit is very sensitive to how errors
|
|
|
|
// are returned, and adding quic can cause problems
|
|
|
|
dialer := peer.Dialer
|
|
|
|
//lint:ignore SA1019 deprecated is fine here.
|
|
|
|
//nolint:staticcheck // deprecated is fine here.
|
|
|
|
dialer.Connector = rpc.NewDefaultTCPConnector(nil)
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
config := config.Audit
|
|
|
|
|
2020-08-20 14:29:02 +01:00
|
|
|
peer.Audit.Queues = audit.NewQueues()
|
2019-11-04 19:01:02 +00:00
|
|
|
|
|
|
|
peer.Audit.Verifier = audit.NewVerifier(log.Named("audit:verifier"),
|
2020-12-14 12:54:22 +00:00
|
|
|
peer.Metainfo.Metabase,
|
2022-02-16 15:56:01 +00:00
|
|
|
dialer,
|
2019-11-04 19:01:02 +00:00
|
|
|
peer.Overlay.Service,
|
|
|
|
peer.DB.Containment(),
|
|
|
|
peer.Orders.Service,
|
|
|
|
peer.Identity,
|
|
|
|
config.MinBytesPerSecond,
|
|
|
|
config.MinDownloadTimeout,
|
|
|
|
)
|
|
|
|
|
|
|
|
peer.Audit.Reporter = audit.NewReporter(log.Named("audit:reporter"),
|
2021-06-23 00:09:39 +01:00
|
|
|
peer.Reputation.Service,
|
2019-11-04 19:01:02 +00:00
|
|
|
peer.DB.Containment(),
|
|
|
|
config.MaxRetriesStatDB,
|
|
|
|
int32(config.MaxReverifyCount),
|
|
|
|
)
|
|
|
|
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Audit.Worker, err = audit.NewWorker(peer.Log.Named("audit:worker"),
|
2020-08-20 14:29:02 +01:00
|
|
|
peer.Audit.Queues,
|
2019-11-04 19:01:02 +00:00
|
|
|
peer.Audit.Verifier,
|
|
|
|
peer.Audit.Reporter,
|
|
|
|
config,
|
|
|
|
)
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "audit:worker",
|
|
|
|
Run: peer.Audit.Worker.Run,
|
|
|
|
Close: peer.Audit.Worker.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Audit Worker", peer.Audit.Worker.Loop))
|
2019-11-04 19:01:02 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Audit.Chore = audit.NewChore(peer.Log.Named("audit:chore"),
|
2020-08-20 14:29:02 +01:00
|
|
|
peer.Audit.Queues,
|
2021-06-14 16:40:46 +01:00
|
|
|
peer.Metainfo.SegmentLoop,
|
2019-11-04 19:01:02 +00:00
|
|
|
config,
|
|
|
|
)
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "audit:chore",
|
|
|
|
Run: peer.Audit.Chore.Run,
|
|
|
|
Close: peer.Audit.Chore.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Audit Chore", peer.Audit.Chore.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
|
|
|
|
2021-06-01 17:44:09 +01:00
|
|
|
// storage nodes tally
|
|
|
|
peer.Accounting.NodeTally = nodetally.New(peer.Log.Named("accounting:nodetally"), peer.DB.StoragenodeAccounting(), peer.Metainfo.SegmentLoop, config.Tally.Interval)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "accounting:nodetally",
|
|
|
|
Run: peer.Accounting.NodeTally.Run,
|
|
|
|
Close: peer.Accounting.NodeTally.Close,
|
|
|
|
})
|
|
|
|
|
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
|
|
|
|
2020-05-18 10:17:05 +01:00
|
|
|
var stripeClient stripecoinpayments.StripeClient
|
2019-11-05 20:26:19 +00:00
|
|
|
switch pc.Provider {
|
2019-11-04 19:01:02 +00:00
|
|
|
default:
|
2020-10-08 18:14:09 +01:00
|
|
|
stripeClient = stripecoinpayments.NewStripeMock(
|
|
|
|
peer.ID(),
|
|
|
|
peer.DB.StripeCoinPayments().Customers(),
|
|
|
|
peer.DB.Console().Users(),
|
|
|
|
)
|
2019-11-04 19:01:02 +00:00
|
|
|
case "stripecoinpayments":
|
2020-05-18 10:17:05 +01:00
|
|
|
stripeClient = stripecoinpayments.NewStripeClient(log, pc.StripeCoinPayments)
|
|
|
|
}
|
2019-11-04 19:01:02 +00:00
|
|
|
|
2020-05-18 10:17:05 +01:00
|
|
|
service, err := stripecoinpayments.NewService(
|
|
|
|
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(),
|
|
|
|
peer.DB.ProjectAccounting(),
|
|
|
|
pc.StorageTBPrice,
|
|
|
|
pc.EgressTBPrice,
|
2021-10-20 23:54:34 +01:00
|
|
|
pc.SegmentPrice,
|
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()
|
|
|
|
|
|
|
|
peer.Payments.Chore = stripecoinpayments.NewChore(
|
|
|
|
peer.Log.Named("payments.stripe:clearing"),
|
|
|
|
service,
|
|
|
|
pc.StripeCoinPayments.TransactionUpdateInterval,
|
|
|
|
pc.StripeCoinPayments.AccountBalanceUpdateInterval,
|
|
|
|
)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "payments.stripe:service",
|
|
|
|
Run: peer.Payments.Chore.Run,
|
|
|
|
})
|
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Payments Stripe Transactions", peer.Payments.Chore.TransactionCycle),
|
|
|
|
debug.Cycle("Payments Stripe Account Balance", peer.Payments.Chore.AccountBalanceCycle),
|
|
|
|
)
|
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,
|
|
|
|
)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup graceful exit
|
|
|
|
if config.GracefulExit.Enabled {
|
2021-07-21 12:36:17 +01:00
|
|
|
peer.GracefulExit.Chore = gracefulexit.NewChore(peer.Log.Named("gracefulexit"), peer.DB.GracefulExit(), peer.Overlay.DB, peer.Metainfo.SegmentLoop, config.GracefulExit)
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "gracefulexit",
|
|
|
|
Run: peer.GracefulExit.Chore.Run,
|
|
|
|
Close: peer.GracefulExit.Chore.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Graceful Exit", peer.GracefulExit.Chore.Loop))
|
2020-01-06 12:34:54 +00:00
|
|
|
} else {
|
|
|
|
peer.Log.Named("gracefulexit").Info("disabled")
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup metrics service
|
|
|
|
peer.Metrics.Chore = metrics.NewChore(
|
|
|
|
peer.Log.Named("metrics"),
|
|
|
|
config.Metrics,
|
2021-07-01 15:48:07 +01:00
|
|
|
peer.Metainfo.SegmentLoop,
|
2019-11-04 19:01:02 +00:00
|
|
|
)
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "metrics",
|
|
|
|
Run: peer.Metrics.Chore.Run,
|
|
|
|
Close: peer.Metrics.Chore.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Metrics", peer.Metrics.Chore.Loop))
|
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 }
|