Problem: Users trying to use an incompatible version of Tendermint#2541
Problem: Users trying to use an incompatible version of Tendermint#2541kansi merged 12 commits intobigchaindb:masterfrom
Conversation
- depracated pymongo methods - direct use of fixtures
Codecov Report
@@ Coverage Diff @@
## master #2541 +/- ##
==========================================
+ Coverage 93.64% 93.67% +0.02%
==========================================
Files 44 44
Lines 2582 2593 +11
==========================================
+ Hits 2418 2429 +11
Misses 164 164 |
kansi
left a comment
There was a problem hiding this comment.
It would be good to have a test which passes unsupported Tendermint version and asserts system exit
bigchaindb/core.py
Outdated
| f" Currently, BigchainDB only supports {__tm_supported_versions__} .Exiting!") | ||
| sys.exit(1) | ||
| except AttributeError: | ||
| logger.debug("Skipping Tendermint version check.") |
There was a problem hiding this comment.
According to the docs, the version field is not optional, so I would as well panic when there is no version.
| :type running_tm_ver: str | ||
| :return: True/False depending on the compatability with BigchainDB server | ||
| :rtype: bool | ||
| """ |
There was a problem hiding this comment.
A nitpick:
if not tm_ver:
return False
for ver in __tm_supported_versions__:
if version.parse(ver) == version.parse(tm_ver[0]):
return True
return False
Also, in this version it does not fail if the first match fails but only if it does not match any version in the list.
bigchaindb/commands/bigchaindb.py
Outdated
| "description": "BigchainDB supports the following Tendermint version(s)", | ||
| "tendermint": [], | ||
| } | ||
| [supported_tm_ver["tendermint"].append(ver) for ver in __tm_supported_versions__] |
There was a problem hiding this comment.
It may be slightly more concise:
supported_tm_ver = {
'description': 'BigchainDB supports the following Tendermint version(s)',
'tendermint': __tm_supported_versions__
}
On a side note, PEP8 recommends to stick to a single type of quotes, and we generally use '.
ttmc
left a comment
There was a problem hiding this comment.
This pull request is doing two different things so it really should have been two pull requests. I'm not going to ask you to split this pull request apart, just to be mindful of that principle in future pull requests.
bigchaindb/core.py
Outdated
| logger.info(f"Tendermint version: {request.version}") | ||
| else: | ||
| logger.error(f"Error: Tendermint version {request.version} not supported." | ||
| f" Currently, BigchainDB only supports {__tm_supported_versions__} .Exiting!") |
There was a problem hiding this comment.
The spacing is slightly off near the end of this line. It should end with }. Exiting!")
bigchaindb/core.py
Outdated
|
|
||
| # Check if BigchainDB supports the Tendermint version | ||
| try: | ||
| if check_tendermint_version(request.version): |
There was a problem hiding this comment.
This function (currently named check_tendermint_version()) returns a Boolean, so it could be renamed so that lines like this read more like plain English, e.g.
if tendermint_version_is_compatible(request.version):In other words, I'm suggesting renaming the function check_tendermint_version() as tendermint_version_is_compatible().
bigchaindb/core.py
Outdated
| f" Currently, BigchainDB only supports {__tm_supported_versions__} .Exiting!") | ||
| sys.exit(1) | ||
| except AttributeError: | ||
| logger.debug("Skipping Tendermint version check.") |
There was a problem hiding this comment.
Maybe we should say why the Tendermint version check is being skipped: apparently the request from Tendermint didn't include a version attribute.
| :return: True/False depending on the compatability with BigchainDB server | ||
| :rtype: bool | ||
| """ | ||
| tm_ver = running_tm_ver.split('-') |
There was a problem hiding this comment.
Maybe put a comment with an example value of running_tm_ver so it's clear why you're doing this split.
- neatpicks - Add tests for sys exit
- Update name of tm version check function - some typos
|
|
||
| self.abort_if_abci_chain_is_not_synced() | ||
|
|
||
| # Check if BigchainDB supports the Tendermint version |
There was a problem hiding this comment.
One more nitpick:
if not hasattr(request, 'version') or not tendermint_version_is_compatible(request.version):
logger.error('Unsupported Tendermint version: {getattr(request, "version", "no version")} ..')
sys.exit(1)
There was a problem hiding this comment.
A slight correction:
not (hasattr(request, 'version') and tendermint_version_is_compatible(request.version))
bigchaindb/utils.py
Outdated
| for ver in __tm_supported_versions__: | ||
| if version.parse(ver) == version.parse(tm_ver[0]): | ||
| return True | ||
| else: |
There was a problem hiding this comment.
return False belongs to the outer scope, not to if-else.
- neatpicks
Solution
bigchaindb tendermint-versionto display the supported Tendermint versions.Issues Resolved
Resolves #2525