input+lnrpc: realign witness types#7473
input+lnrpc: realign witness types#7473Roasbeef merged 4 commits intolightningnetwork:masterfrom emilioziniades:realign-witness-types
Conversation
|
I think we need to test the mapping where it is needed in the codebase, because this will not prevent any errors when we are not actually changing the function where the mapping is done. mapping My recommendation: Try to use |
@ziggie1984 thanks for the feedback, I have
Would you mind taking another look? |
ziggie1984
left a comment
There was a problem hiding this comment.
Looks really good, left some comments :)
ziggie1984
left a comment
There was a problem hiding this comment.
Almost good from my side, had some final nits.
guggero
left a comment
There was a problem hiding this comment.
Thanks for the PR!
Unfortunately we're between a rock and a hard place. We can't change the RPC values to not break older clients. And we can't change the native enum, because that's used for database values.
So we have to rely on the mapping.
|
@guggero: review reminder |
guggero
left a comment
There was a problem hiding this comment.
Looks good, thanks for the update!
Can you rebase so the fixup commits are applied please? Then I'll do the final pass.
lnrpc/walletrpc/walletkit_server.go
Outdated
There was a problem hiding this comment.
nit: logging and error function calls get an exception in the formatting to help distinguish them from actual ("business logic") function calls: https://github.com/lightningnetwork/lnd/blob/master/docs/code_formatting_rules.md#exception-for-log-and-error-message-formatting.
There was a problem hiding this comment.
I see, makes sense. I've changed it from
return nil, fmt.Errorf(
"an error",
)
to
return nil, fmt.Errorf(
"an error")
There was a problem hiding this comment.
Actually, it should even be:
return nil, fmt.Errorf( "an error")
So in this case:
return nil, fmt.Errorf("unhandled witness type %v for "+
"input %v", pendingInput.WitnessType,
pendingInput.OutPoint)
There was a problem hiding this comment.
Right. Fixed it.
|
@guggero I've rebased the fixup commits. The PR is ready for a final pass. |
Refactor `PendingSweeps` to use `allWitnessTypes` map, and return an error from `PendingSweeps` if an unknown witness type is used, instead of logging a warning.
Fixes #7460
This PR brings the
StandardWitnessTypeenum back in line with theWitnessTypeenum.To avoid breaking compatibility with the existing protobuf definition, I added the missing enum values there, and renumbered the enum values in the
inputpackage to match.I wasn't quite sure how to go about testing this. Really you'd want to iterate over all the values of a defined enum. Not sure if this is even possible in Go.
So instead I created a map from enum values to strings, and compared the values in that map with the generated protobuf enum values. Admittedly it's not foolproof.Whilst I was there, I also thought it made sense to refactor the.Stringmethod to use this new mapEDIT: I reworked this a little, and the test now uses the.Stringmethod directly without creating a global mapEDIT EDIT: went with the explicit map.