Skip to content

Commit 5d13c27

Browse files
committed
protofsm: add a Name() method to the env
This'll be used later to uniquely identify state machines for routing/dispatch purposes.
1 parent ea60fe0 commit 5d13c27

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

protofsm/state_machine.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ type Environment interface {
5353
// state machine.
5454
CleanUp() error
5555

56+
// Name returns the name of the environment. This is used to uniquely
57+
// identify the environment of related state machines.
58+
Name() string
59+
5660
// TODO(roasbeef): also add checkpointing?
5761
}
5862

@@ -223,6 +227,11 @@ func (s *StateMachine[Event, Env]) CanHandle(msg lnwire.Message) bool {
223227
})
224228
}
225229

230+
// Name returns the name of the state machine's environment.
231+
func (s *StateMachine[Event, Env]) Name() string {
232+
return s.cfg.Env.Name()
233+
}
234+
226235
// SendMessage attempts to send a wire message to the state machine. If the
227236
// message can be mapped using the default message mapper, then true is
228237
// returned indicating that the message was processed. Otherwise, false is

protofsm/state_machine_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ func (d *dummyEnv) CleanUp() error {
4848
return args.Error(0)
4949
}
5050

51+
func (d *dummyEnv) Name() string {
52+
return "test"
53+
}
54+
5155
type dummyStateStart struct {
5256
canSend *atomic.Bool
5357
}

0 commit comments

Comments
 (0)