Skip to content

py/bitbox02/communication: update protobuf generated files#951

Merged
Beerosagos merged 1 commit intoBitBoxSwiss:masterfrom
Beerosagos:protobuf-update
Jul 19, 2022
Merged

py/bitbox02/communication: update protobuf generated files#951
Beerosagos merged 1 commit intoBitBoxSwiss:masterfrom
Beerosagos:protobuf-update

Conversation

@Beerosagos
Copy link
Collaborator

@Beerosagos Beerosagos commented Jul 13, 2022

Recent HWI update requires protobuf files generated with protoc =>
3.19.0. This update regenerates the files with protoc 3.21.1

EDIT: as @benma pointed out, the issue is not actually related to HWI, which currently requires protobuf 3.19.1.
The compatibility issue is between protobuf >= 3.21 and current protobuf files.

To solve it protobuf files has been regenerated with protoc >= 3.19 and protobuf dependency of bitbox02 py lib set to >= 3.21

@benma
Copy link
Collaborator

benma commented Jul 13, 2022

The protobuf files are generated by executing cd py && make (inside Docker), and this should continue working so it's easy to generate the files when changing the protobuf messages.

Please update the Dockerfile accordingly :)

@Beerosagos
Copy link
Collaborator Author

The protobuf files are generated by executing cd py && make (inside Docker), and this should continue working so it's easy to generate the files when changing the protobuf messages.

Please update the Dockerfile accordingly :)

Didn't think about that! :| Now should be ok, thanks.

@benma
Copy link
Collaborator

benma commented Jul 13, 2022

Recent HWI update requires protobuf files generated with protoc

Are you sure it's HWI? The issue originally was this:

f this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.

So it was about the protobuf package being newer than 3.20. HWI's dep list uses 3.19.1. So maybe it was something else that upgraded your protobuf package 🤔

Anyway, would be good to include the above in the commit msg :)

@benma
Copy link
Collaborator

benma commented Jul 13, 2022

We have a problem maybe. When I now run send_message.py, I get:

from google.protobuf.internal import builder as _builder

My local protobuf installation is at 3.19.4:

image

Upgrading it fixes it, but that still means it's broken for protobuf <3.20.

At the very least we need to then bump https://github.com/digitalbitbox/bitbox02-firmware/blob/57d62a98cf52fd4d700551083e925019e5eb16f3/py/bitbox02/setup.py#L78. Maybe that's sufficient 🤷

@benma
Copy link
Collaborator

benma commented Jul 14, 2022

Please also update py/bitbox02/CHANGELOG.md under 6.1.0 (to be released).

@Beerosagos
Copy link
Collaborator Author

We have a problem maybe. When I now run send_message.py, I get:

from google.protobuf.internal import builder as _builder

My local protobuf installation is at 3.19.4:

image

Upgrading it fixes it, but that still means it's broken for protobuf <3.20.

At the very least we need to then bump

https://github.com/digitalbitbox/bitbox02-firmware/blob/57d62a98cf52fd4d700551083e925019e5eb16f3/py/bitbox02/setup.py#L78
. Maybe that's sufficient shrug

Thanks for pointing this out, didn't notice it! Yes, updating setup.py seems to be sufficient, and a good way to avoid compatibility issues.

@Beerosagos
Copy link
Collaborator Author

Recent HWI update requires protobuf files generated with protoc

Are you sure it's HWI? The issue originally was this:

f this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.

So it was about the protobuf package being newer than 3.20. HWI's dep list uses 3.19.1. So maybe it was something else that upgraded your protobuf package thinking

Anyway, would be good to include the above in the commit msg :)

You are right, I was misled by the fact that both I and the user in #949 encountered the error while working on HWI.

@Beerosagos
Copy link
Collaborator Author

I am not really understanding why the CI failed. Made some tests on my local, but can't reproduce the error.

@benma
Copy link
Collaborator

benma commented Jul 14, 2022

I am not really understanding why the CI failed. Made some tests on my local, but can't reproduce the error.

I think pylint is just very bad with the member checks with protobuf, they are probably false positives. That's why you see so many # pylint: disable=no-member scattered :( I don't know why more of them are triggered now... Maybe there is a way to disable that warning altogether, otherwise try putting # pylint: disable=no-member and seeing if that helps.

You can lint it locally with ./scripts/docker_exec.sh ./scripts/lint-python .

@benma
Copy link
Collaborator

benma commented Jul 14, 2022

Fyi the member check by pylint is not so important because we also have types everywhere, and mypy does a full type check on the package, so mypy would catch any such member mistakes.

@Beerosagos
Copy link
Collaborator Author

I am not really understanding why the CI failed. Made some tests on my local, but can't reproduce the error.

I think pylint is just very bad with the member checks with protobuf, they are probably false positives. That's why you see so many # pylint: disable=no-member scattered :( I don't know why more of them are triggered now... Maybe there is a way to disable that warning altogether, otherwise try putting # pylint: disable=no-member and seeing if that helps.

You can lint it locally with ./scripts/docker_exec.sh ./scripts/lint-python .

Thanks for the explanation. I disabled no-member checks for protobuf generated modules.

Copy link
Collaborator

@benma benma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update https://github.com/digitalbitbox/bitbox02-firmware/blob//.ci/run-container-ci#L28 to version 26? I just pushed the updated Docker image with the new protoc there.

I also accidentally overwrote the 25 tag on Docker hub - will re-build and re-push that one 🙈


## 6.1.0
- Add `eth_sign_typed_msg()`
- Update brotobuf dependency to >= 3.21
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brotobuf? 😂

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL 😅


[TYPECHECK]
# Ignore protobuf generated modules for no-member checks
ignored-modules=bitbox02.communication.generated.btc_pb2,bitbox02.communication.generated.cardano_pb2,bitbox02.communication.generated.common_pb2,bitbox02.communication.generated.eth_pb2,bitbox02.communication.generated.hww_pb2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't figure out how to do this - thanks!!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the commit msg to explain this and that mypy does the member checks instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! 👍

Recent protobuf versions (>=3.21) have compatibility issues with
files generated with protoc < 3.19.0. This commit updates Dockerfile
to install a recent version of protoc (3.21.2), updates generated
protobuf files and increase Docker image version in `run-container-ci`.

Since there is also a compatibility issue between protobuf files
generated with protoc >= 3.19 and protobuf < 3.21, protobuf dependency
of bitbox02 python library has been updated to >= 3.21.

Protobuf generated modules have been excluded from pylint no-member checks,
because of a large number of false-positive errors. A full type check is
done on the package by mypy, anyway. It should be enough.
"hidapi>=0.7.99.post21",
"noiseprotocol>=0.3",
"protobuf>=3.7",
"protobuf>=3.21",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT protobuf 3.20.x is able to parse both the old and the new format
(while <3.20 can only parse the old format, and >=3.21 can only parse the new format)

Hence, would it not be better to set this to "protobuf>=3.20" ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you also find this to be correct, please relax the requirement.
See spesmilo/electrum#7922

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, how did you figure this out? The release notes don't exactly give it away.

Anyway, we're happy to make a patch release that relaxes the constraint.

Fyi, protobuf>=3.20 requires Python 3.7, see also: bitcoin-core/HWI#626

Copy link

@SomberNight SomberNight Aug 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, how did you figure this out? The release notes don't exactly give it away.

When you have new protobuf and old generated files, the runtime error says
1. Downgrade the protobuf package to 3.20.x or lower..
I manually tested a bunch of protobuf versions from PyPI around that boundary, hoping some can parse both and to learn the behaviour.
I had tried reading the release notes first but could not make sense of them either :)

Fyi, protobuf>=3.20 requires Python 3.7, see also: bitcoin-core/HWI#626

That's fine. (in Electrum, we already bumped the minimum to Python 3.8)

EDIT:

Anyway, we're happy to make a patch release that relaxes the constraint.

Thanks, that would be great!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6.1.1 is out, please give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants