-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
protofsm: update GR Manager usage and start using structured logging #9342
base: master
Are you sure you want to change the base?
Conversation
Important Review skippedAuto reviews are limited to specific labels. 🏷️ Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
8c9dad2
to
2fefda4
Compare
@@ -213,3 +213,5 @@ replace google.golang.org/protobuf => github.com/lightninglabs/protobuf-go-hex-d | |||
go 1.22.6 | |||
|
|||
retract v0.0.2 | |||
|
|||
replace github.com/lightningnetwork/lnd/fn/v2 => github.com/ellemouton/lnd/fn/v2 v2.0.0-20241210050749-8c19ec06a189 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW in #8512 I've made the change to update to v2
just need to get CI grteen there (check commits failing IIRC) and it should be g2g there.
protofsm/state_machine.go
Outdated
} | ||
|
||
// sendEvent sends a new event to the state machine. | ||
func (s *StateMachine[Event, Env]) sendEvent(event Event) { | ||
func (s *StateMachine[Event, Env]) sendEvent(ctx context.Context, event Event) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the motivation re the change in the prior commit? To only have the private method be what selects on the context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see the next commit which does the context decoration on any incoming ctx
@@ -101,8 +102,8 @@ type DaemonAdapters interface { | |||
// TODO(roasbeef): could abstract further? | |||
RegisterConfirmationsNtfn(txid *chainhash.Hash, pkScript []byte, | |||
numConfs, heightHint uint32, | |||
opts ...chainntnfs.NotifierOption, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prob the main stylistic diff in the codebase rn, but I prefer this option as it makes it clearer where the args end, and the return value starts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imo that only holds if the return values can in-fact fit on one line which is not always the case.
Personally I find the ) {
on the unindented line strange
protofsm/state_machine.go
Outdated
daemonEvent.TargetPeer.SerializeCompressed(), | ||
lnutils.SpewLogClosure(daemonEvent.Msgs), | ||
) | ||
log.DebugS(ctx, "Sending message", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a print sample of the before and after here re formatting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah here is an example:
2024-12-10 13:08:43.637 [DBG]: Processing daemon events fsm_name=test num_events=3
2024-12-10 13:08:43.637 [DBG]: Sending message fsm_name=test target=0356167ba3e5 msgs=([]lnwire.Message) <nil>
2024-12-10 13:08:43.637 [INF]: Waiting for send predicate to be true fsm_name=test
2024-12-10 13:08:43.637 [DBG]: Broadcasting txn fsm_name=test txid=f702453dd03b0f055e5437d76128141803984fb10acb85fc3b2184fae2f3fa78
2024-12-10 13:08:43.638 [INF]: State transition fsm_name=test from_state=*protofsm.dummyStateStart to_state=*protofsm.dummyStateStart
2024-12-10 13:08:43.740 [INF]: Send active predicate fsm_name=test
2024-12-10 13:08:43.740 [DBG]: Sending message fsm_name=test target=02ec95e4e8ad msgs=([]lnwire.Message) <nil>
2024-12-10 13:08:43.740 [DBG]: Sending post-send event fsm_name=test event=(*protofsm.goToFin)(0x100cb5240)({
})
2024-12-10 13:08:43.740 [DBG]: Sending event fsm_name=test event=(*protofsm.goToFin)(0x100cb5240)({
})
2024-12-10 13:08:43.740 [DBG]: Applying new event fsm_name=test event=(*protofsm.goToFin)(0x100cb5240)({
})
2024-12-10 13:08:43.740 [DBG]: Processing event fsm_name=test event=(*protofsm.goToFin)(0x100cb5240)({
})
2024-12-10 13:08:43.740 [INF]: State transition fsm_name=test from_state=*protofsm.dummyStateStart to_state=*protofsm.dummyStateFin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see other comment re the prefix: with the prefixed logger, they now look like this:
2024-12-10 13:20:44.552 [DBG]: FSM(test) Starting state machine
2024-12-10 13:20:44.552 [DBG]: FSM(test) Sending event event=(*protofsm.emitInternal)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [DBG]: FSM(test) Applying new event event=(*protofsm.emitInternal)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [DBG]: FSM(test) Processing event event=(*protofsm.emitInternal)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [DBG]: FSM(test) Adding new internal event to queue event !BADKEY=(*protofsm.goToFin)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [INF]: FSM(test) State transition from_state=*protofsm.dummyStateStart to_state=*protofsm.dummyStateStart
2024-12-10 13:20:44.552 [DBG]: FSM(test) Processing event event=(*protofsm.goToFin)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [INF]: FSM(test) State transition from_state=*protofsm.dummyStateStart to_state=*protofsm.dummyStateFin
protofsm/state_machine.go
Outdated
log.Debugf("FSM(%v): processing "+ | ||
"daemon %v daemon events", | ||
s.cfg.Env.Name(), len(dEvents)) | ||
log.DebugS(ctx, "Processing daemon events", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this upper case construct something new we're attempting to make standard with the new logging format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in general we go for log lines that start with upper case? searching around the code base, i can see that most of our log lines start with an upper case letter
protofsm/state_machine.go
Outdated
ctx context.Context) context.Context { | ||
|
||
return btclog.WithCtx(ctx, | ||
btclog.Fmt("fsm_name", s.cfg.Env.Name())) //nolint:govet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anyway we can keep the old prefix nature? At least when scanning, IMO it's useful for it to be at the very start as depending on the size of your editor/viewport, the end of the line may require moving the cursor to actually view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as the library stands today, no. But what can be done is: to create a prefixed logger in NewStateMachine
and then carry that around in the StateMachine struct. Then we just need to remember to do s.log.*
for log lines.
shall we do that instead here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok i've added a temporary commit at the end that does it this way. Let me know if you think this is ok and i can squash in the change.
The logs now look like this:
2024-12-10 13:20:44.552 [DBG]: FSM(test) Starting state machine
2024-12-10 13:20:44.552 [DBG]: FSM(test) Sending event event=(*protofsm.emitInternal)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [DBG]: FSM(test) Applying new event event=(*protofsm.emitInternal)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [DBG]: FSM(test) Processing event event=(*protofsm.emitInternal)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [DBG]: FSM(test) Adding new internal event to queue event !BADKEY=(*protofsm.goToFin)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [INF]: FSM(test) State transition from_state=*protofsm.dummyStateStart to_state=*protofsm.dummyStateStart
2024-12-10 13:20:44.552 [DBG]: FSM(test) Processing event event=(*protofsm.goToFin)(0x1045f1240)({
})
2024-12-10 13:20:44.552 [INF]: FSM(test) State transition from_state=*protofsm.dummyStateStart to_state=*protofsm.dummyStateFin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a look @Roasbeef - responded to your comments
protofsm/state_machine.go
Outdated
} | ||
|
||
// sendEvent sends a new event to the state machine. | ||
func (s *StateMachine[Event, Env]) sendEvent(event Event) { | ||
func (s *StateMachine[Event, Env]) sendEvent(ctx context.Context, event Event) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see the next commit which does the context decoration on any incoming ctx
protofsm/state_machine.go
Outdated
log.Debugf("FSM(%v): processing "+ | ||
"daemon %v daemon events", | ||
s.cfg.Env.Name(), len(dEvents)) | ||
log.DebugS(ctx, "Processing daemon events", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in general we go for log lines that start with upper case? searching around the code base, i can see that most of our log lines start with an upper case letter
protofsm/state_machine.go
Outdated
ctx context.Context) context.Context { | ||
|
||
return btclog.WithCtx(ctx, | ||
btclog.Fmt("fsm_name", s.cfg.Env.Name())) //nolint:govet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as the library stands today, no. But what can be done is: to create a prefixed logger in NewStateMachine
and then carry that around in the StateMachine struct. Then we just need to remember to do s.log.*
for log lines.
shall we do that instead here?
In preparation for the next commit where we will do some context decorating of any incoming context that crosses the StateMachine's API boundary, we make sure to differentiate between exported and unexported methods here.
2fefda4
to
a86da09
Compare
This PR touches the protofsm package for 2 reasons:
FSM(%V)
string for each log lineDepends on: btcsuite/btclog#20
Depends on: #9341