Skip to content

Commit 90135bd

Browse files
committed
supplycommit: simplify struct names for clarity
Renamed struct MultiStateMachineManager to Manager for brevity. Also renamed other closely related structs and functions to maintain consistency and improve readability.
1 parent 0e2005c commit 90135bd

File tree

3 files changed

+26
-28
lines changed

3 files changed

+26
-28
lines changed

config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ type Config struct {
195195
// SupplyCommitManager is a service that is used to manage supply
196196
// commitments for assets. Supply commitments are issuer published
197197
// attestations of the total supply of an asset.
198-
SupplyCommitManager *supplycommit.MultiStateMachineManager
198+
SupplyCommitManager *supplycommit.Manager
199199

200200
UniverseArchive *universe.Archive
201201

tapcfg/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,8 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
611611

612612
// Create the supply commitment state machine manager, which is used to
613613
// manage the supply commitment state machines for each asset group.
614-
supplyCommitManager := supplycommit.NewMultiStateMachineManager(
615-
supplycommit.MultiStateMachineManagerCfg{
614+
supplyCommitManager := supplycommit.NewManager(
615+
supplycommit.ManagerCfg{
616616
TreeView: supplyTreeStore,
617617
Commitments: supplyCommitStore,
618618
Wallet: walletAnchor,

universe/supplycommit/manager.go

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ type DaemonAdapters interface {
3333
Stop() error
3434
}
3535

36-
// MultiStateMachineManagerCfg is the configuration for the
37-
// MultiStateMachineManager. It contains all the dependencies needed to
36+
// ManagerCfg is the configuration for the
37+
// Manager. It contains all the dependencies needed to
3838
// manage multiple supply commitment state machines, one for each asset group.
39-
type MultiStateMachineManagerCfg struct {
39+
type ManagerCfg struct {
4040
// TreeView is the interface that allows the state machine to obtain an
4141
// up to date snapshot of the root supply tree, and the relevant set of
4242
// subtrees.
@@ -71,12 +71,12 @@ type MultiStateMachineManagerCfg struct {
7171
ChainParams chaincfg.Params
7272
}
7373

74-
// MultiStateMachineManager is a manager for multiple supply commitment state
74+
// Manager is a manager for multiple supply commitment state
7575
// machines, one for each asset group. It is responsible for starting and
7676
// stopping the state machines, as well as forwarding sending events to them.
77-
type MultiStateMachineManager struct {
77+
type Manager struct {
7878
// cfg is the configuration for the multi state machine manager.
79-
cfg MultiStateMachineManagerCfg
79+
cfg ManagerCfg
8080

8181
// smCache is a cache that maps asset group public keys to their
8282
// supply commitment state machines.
@@ -90,11 +90,9 @@ type MultiStateMachineManager struct {
9090
stopOnce sync.Once
9191
}
9292

93-
// NewMultiStateMachineManager creates a new multi state machine manager.
94-
func NewMultiStateMachineManager(
95-
cfg MultiStateMachineManagerCfg) *MultiStateMachineManager {
96-
97-
return &MultiStateMachineManager{
93+
// NewManager creates a new multi state machine manager.
94+
func NewManager(cfg ManagerCfg) *Manager {
95+
return &Manager{
9896
cfg: cfg,
9997
ContextGuard: &fn.ContextGuard{
10098
DefaultTimeout: DefaultTimeout,
@@ -104,7 +102,7 @@ func NewMultiStateMachineManager(
104102
}
105103

106104
// Start starts the multi state machine manager.
107-
func (m *MultiStateMachineManager) Start() error {
105+
func (m *Manager) Start() error {
108106
m.startOnce.Do(func() {
109107
// Initialize the state machine cache.
110108
m.smCache = newStateMachineCache()
@@ -115,7 +113,7 @@ func (m *MultiStateMachineManager) Start() error {
115113

116114
// Stop stops the multi state machine manager, which in turn stops all asset
117115
// group key specific supply commitment state machines.
118-
func (m *MultiStateMachineManager) Stop() error {
116+
func (m *Manager) Stop() error {
119117
m.stopOnce.Do(func() {
120118
// Cancel the state machine context to signal all state machines
121119
// to stop.
@@ -131,7 +129,7 @@ func (m *MultiStateMachineManager) Stop() error {
131129
// fetchStateMachine retrieves a state machine from the cache or creates a
132130
// new one if it doesn't exist. If a new state machine is created, it is also
133131
// started.
134-
func (m *MultiStateMachineManager) fetchStateMachine(
132+
func (m *Manager) fetchStateMachine(
135133
assetSpec asset.Specifier) (*StateMachine, error) {
136134

137135
groupKey, err := assetSpec.UnwrapGroupKeyOrErr()
@@ -212,13 +210,13 @@ func (m *MultiStateMachineManager) fetchStateMachine(
212210
// SendEvent sends an event to the state machine associated with the given asset
213211
// specifier. If a state machine for the asset group does not exist, it will be
214212
// created and started.
215-
func (m *MultiStateMachineManager) SendEvent(ctx context.Context,
213+
func (m *Manager) SendEvent(ctx context.Context,
216214
assetSpec asset.Specifier, event Event) error {
217215

218216
sm, err := m.fetchStateMachine(assetSpec)
219217
if err != nil {
220-
return fmt.Errorf("unable to get or create state "+
221-
"machine: %w", err)
218+
return fmt.Errorf("unable to get or create state machine: %w",
219+
err)
222220
}
223221

224222
sm.SendEvent(ctx, event)
@@ -228,7 +226,7 @@ func (m *MultiStateMachineManager) SendEvent(ctx context.Context,
228226
// CanHandle determines if the state machine associated with the given asset
229227
// specifier can handle the given message. If a state machine for the asset
230228
// group does not exist, it will be created and started.
231-
func (m *MultiStateMachineManager) CanHandle(assetSpec asset.Specifier,
229+
func (m *Manager) CanHandle(assetSpec asset.Specifier,
232230
msg msgmux.PeerMsg) (bool, error) {
233231

234232
sm, err := m.fetchStateMachine(assetSpec)
@@ -243,7 +241,7 @@ func (m *MultiStateMachineManager) CanHandle(assetSpec asset.Specifier,
243241
// Name returns the name of the state machine associated with the given asset
244242
// specifier. If a state machine for the asset group does not exist, it will be
245243
// created and started.
246-
func (m *MultiStateMachineManager) Name(
244+
func (m *Manager) Name(
247245
assetSpec asset.Specifier) (string, error) {
248246

249247
sm, err := m.fetchStateMachine(assetSpec)
@@ -258,7 +256,7 @@ func (m *MultiStateMachineManager) Name(
258256
// SendMessage sends a message to the state machine associated with the given
259257
// asset specifier. If a state machine for the asset group does not exist, it
260258
// will be created and started.
261-
func (m *MultiStateMachineManager) SendMessage(ctx context.Context,
259+
func (m *Manager) SendMessage(ctx context.Context,
262260
assetSpec asset.Specifier, msg msgmux.PeerMsg) (bool, error) {
263261

264262
sm, err := m.fetchStateMachine(assetSpec)
@@ -273,7 +271,7 @@ func (m *MultiStateMachineManager) SendMessage(ctx context.Context,
273271
// CurrentState returns the current state of the state machine associated with
274272
// the given asset specifier. If a state machine for the asset group does not
275273
// exist, it will be created and started.
276-
func (m *MultiStateMachineManager) CurrentState(assetSpec asset.Specifier) (
274+
func (m *Manager) CurrentState(assetSpec asset.Specifier) (
277275
protofsm.State[Event, *Environment], error) {
278276

279277
sm, err := m.fetchStateMachine(assetSpec)
@@ -288,7 +286,7 @@ func (m *MultiStateMachineManager) CurrentState(assetSpec asset.Specifier) (
288286
// RegisterStateEvents registers a state event subscriber with the state machine
289287
// associated with the given asset specifier. If a state machine for the asset
290288
// group does not exist, it will be created and started.
291-
func (m *MultiStateMachineManager) RegisterStateEvents(
289+
func (m *Manager) RegisterStateEvents(
292290
assetSpec asset.Specifier) (StateSub, error) {
293291

294292
sm, err := m.fetchStateMachine(assetSpec)
@@ -303,7 +301,7 @@ func (m *MultiStateMachineManager) RegisterStateEvents(
303301
// RemoveStateSub removes a state event subscriber from the state machine
304302
// associated with the given asset specifier. If a state machine for the asset
305303
// group does not exist, it will be created and started.
306-
func (m *MultiStateMachineManager) RemoveStateSub(assetSpec asset.Specifier,
304+
func (m *Manager) RemoveStateSub(assetSpec asset.Specifier,
307305
sub StateSub) error {
308306

309307
sm, err := m.fetchStateMachine(assetSpec)
@@ -331,7 +329,7 @@ type FetchCommitmentResp struct {
331329
}
332330

333331
// FetchCommitment fetches the supply commitment for the given asset specifier.
334-
func (m *MultiStateMachineManager) FetchCommitment(ctx context.Context,
332+
func (m *Manager) FetchCommitment(ctx context.Context,
335333
assetSpec asset.Specifier) (fn.Option[FetchCommitmentResp], error) {
336334

337335
var zero fn.Option[FetchCommitmentResp]
@@ -379,7 +377,7 @@ func (m *MultiStateMachineManager) FetchCommitment(ctx context.Context,
379377

380378
// FetchSupplyLeavesByHeight returns the set of supply leaves for the given
381379
// asset specifier within the specified height range.
382-
func (m *MultiStateMachineManager) FetchSupplyLeavesByHeight(
380+
func (m *Manager) FetchSupplyLeavesByHeight(
383381
ctx context.Context, assetSpec asset.Specifier, startHeight,
384382
endHeight uint32) (SupplyLeaves, error) {
385383

0 commit comments

Comments
 (0)