Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions config/cleanup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package config
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this in a new config package and not the settings package?


import "time"

// CleanupSettings contains configuration for the Cleanup service.
type CleanupSettings struct {
// GRPCListenAddress is the address the cleanup service listens on for gRPC requests
GRPCListenAddress string

// GRPCAddress is the address other services use to connect to the cleanup service
GRPCAddress string

// PollingInterval is how often to poll block assembly state for cleanup triggers
PollingInterval time.Duration
}
6 changes: 6 additions & 0 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const (
loggerBlockchain = "bchn"
loggerBlockchainClient = "bchc"
loggerBlockchainSQL = "bcsql"
loggerCleanup = "cleanup"
loggerKafkaConsumerBlocks = "kcb"
loggerKafkaConsumerRejectedTx = "kcrtx"
loggerKafkaConsumerSubtree = "kcs"
Expand Down Expand Up @@ -87,6 +88,8 @@ const (
serviceBlockPersister = "blockpersister"
serviceBlockPersisterFormal = "BlockPersister"
serviceBlockValidation = "blockvalidation"
serviceCleanup = "cleanup"
serviceCleanupFormal = "Cleanup"
serviceBlockValidationFormal = "BlockValidation"
serviceBlockchainFormal = "Blockchain"
serviceHelp = "help"
Expand Down Expand Up @@ -510,6 +513,9 @@ func printUsage() {
fmt.Println(" -alert=<1|0>")
fmt.Println(" whether to start the alert service")
fmt.Println("")
fmt.Println(" -cleanup=<1|0>")
fmt.Println(" whether to start the cleanup service")
fmt.Println("")
fmt.Println(" -all=0")
fmt.Println(" disable all services unless explicitly overridden")
fmt.Println("")
Expand Down
38 changes: 38 additions & 0 deletions daemon/daemon_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/bsv-blockchain/teranode/services/blockchain"
"github.com/bsv-blockchain/teranode/services/blockpersister"
"github.com/bsv-blockchain/teranode/services/blockvalidation"
"github.com/bsv-blockchain/teranode/services/cleanup"
"github.com/bsv-blockchain/teranode/services/legacy"
"github.com/bsv-blockchain/teranode/services/legacy/peer"
"github.com/bsv-blockchain/teranode/services/p2p"
Expand Down Expand Up @@ -68,6 +69,7 @@ func (d *Daemon) startServices(ctx context.Context, logger ulogger.Logger, appSe
startLegacy := d.shouldStart(serviceLegacyFormal, args)
startRPC := d.shouldStart(serviceRPCFormal, args)
startAlert := d.shouldStart(serviceAlertFormal, args)
startCleanup := d.shouldStart(serviceCleanupFormal, args)

// Create the application count based on the services that are going to be started
d.appCount += len(d.externalServices)
Expand Down Expand Up @@ -117,6 +119,7 @@ func (d *Daemon) startServices(ctx context.Context, logger ulogger.Logger, appSe
{startValidator, func() error { return d.startValidatorService(ctx, appSettings, createLogger) }},
{startPropagation, func() error { return d.startPropagationService(ctx, appSettings, createLogger) }},
{startLegacy, func() error { return d.startLegacyService(ctx, appSettings, createLogger) }},
{startCleanup, func() error { return d.startCleanupService(ctx, appSettings, createLogger) }},
}

// Loop through and start each service if needed
Expand Down Expand Up @@ -1065,3 +1068,38 @@ func (d *Daemon) startLegacyService(
blockassemblyClient,
))
}

// startCleanupService initializes and adds the Cleanup service to the ServiceManager.
func (d *Daemon) startCleanupService(ctx context.Context, appSettings *settings.Settings,
createLogger func(string) ulogger.Logger) error {
// Create the UTXO store for the Cleanup service
utxoStore, err := d.daemonStores.GetUtxoStore(ctx, createLogger(loggerUtxos), appSettings)
if err != nil {
return err
}

// Create the blockchain client for the Cleanup service
blockchainClient, err := d.daemonStores.GetBlockchainClient(
ctx, createLogger(loggerBlockchainClient), appSettings, serviceCleanup,
)
if err != nil {
return err
}

// Create the block assembly client for the Cleanup service
blockAssemblyClient, err := blockassembly.NewClient(ctx, createLogger(loggerBlockAssembly), appSettings)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use GetBlockAssemblyClient()

if err != nil {
return err
}

// Add the Cleanup service to the ServiceManager
return d.ServiceManager.AddService(serviceCleanupFormal, cleanup.New(
ctx,
createLogger(loggerCleanup),
appSettings,
utxoStore,
blockchainClient,
blockAssemblyClient,
nil, // blobStore not needed for cleanup service
))
}
174 changes: 174 additions & 0 deletions proto/cleanup/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading