Skip to content

Commit 2ef76ce

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 8e3a8f3 commit 2ef76ce

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

@@ -226,6 +230,11 @@ func (s *StateMachine[Event, Env]) CanHandle(msg lnwire.Message) bool {
226230
})
227231
}
228232

233+
// Name returns the name of the state machine's environment.
234+
func (s *StateMachine[Event, Env]) Name() string {
235+
return s.cfg.Env.Name()
236+
}
237+
229238
// SendMessage attempts to send a wire message to the state machine. If the
230239
// message can be mapped using the default message mapper, then true is
231240
// 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)