From 8abe2f89e113dc4569eaf62c19f5f312c1ec8de4 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Thu, 18 May 2023 15:17:22 +0200 Subject: [PATCH] watchtower: use a stable blob identifier In this commit, we add an Identifier method to the blob.Type struct which returns a unique identifier for a given blob type. This identifier is then used for initialising the disk overflow queue of the given client. --- watchtower/blob/type.go | 14 ++++++++++++++ watchtower/wtclient/client.go | 13 ++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/watchtower/blob/type.go b/watchtower/blob/type.go index 73d963c81..87dd52aab 100644 --- a/watchtower/blob/type.go +++ b/watchtower/blob/type.go @@ -67,6 +67,20 @@ const ( TypeRewardCommit = Type(FlagCommitOutputs | FlagReward) ) +// Identifier returns a unique, stable string identifier for the blob Type. +func (t Type) Identifier() (string, error) { + switch t { + case TypeAltruistCommit: + return "legacy", nil + case TypeAltruistAnchorCommit: + return "anchor", nil + case TypeRewardCommit: + return "reward", nil + default: + return "", fmt.Errorf("unknown blob type: %v", t) + } +} + // Has returns true if the Type has the passed flag enabled. func (t Type) Has(flag Flag) bool { return Flag(t)&flag == flag diff --git a/watchtower/wtclient/client.go b/watchtower/wtclient/client.go index cff768569..85d7e19f2 100644 --- a/watchtower/wtclient/client.go +++ b/watchtower/wtclient/client.go @@ -350,10 +350,12 @@ func New(config *Config) (*TowerClient, error) { cfg.WriteTimeout = DefaultWriteTimeout } - prefix := "(legacy)" - if cfg.Policy.IsAnchorChannel() { - prefix = "(anchor)" + identifier, err := cfg.Policy.BlobType.Identifier() + if err != nil { + return nil, err } + prefix := fmt.Sprintf("(%s)", identifier) + plog := build.NewPrefixLog(prefix, log) // Load the sweep pkscripts that have been generated for all previously @@ -363,10 +365,7 @@ func New(config *Config) (*TowerClient, error) { return nil, err } - var ( - policy = cfg.Policy.BlobType.String() - queueDB = cfg.DB.GetDBQueue([]byte(policy)) - ) + queueDB := cfg.DB.GetDBQueue([]byte(identifier)) queue, err := NewDiskOverflowQueue[*wtdb.BackupID]( queueDB, cfg.MaxTasksInMemQueue, plog, )