Skip to content

Problem: Users trying to use an incompatible version of Tendermint#2541

Merged
kansi merged 12 commits intobigchaindb:masterfrom
muawiakh:tm_version_compatible
Sep 14, 2018
Merged

Problem: Users trying to use an incompatible version of Tendermint#2541
kansi merged 12 commits intobigchaindb:masterfrom
muawiakh:tm_version_compatible

Conversation

@muawiakh
Copy link
Copy Markdown
Contributor

Solution

  • Hard-wire the supported Tendermint version(s) right in the code of BigchainDB Server. Check the version of Tendermint and disconnect if Tendermint version is an unsupported one.
  • Expose a CLI command bigchaindb tendermint-version to display the supported Tendermint versions.
  • PR also takes care the long list of warnings we get when we run tests.
    • Updated deprecated pymongo methods
    • Do not call pytest fixtures directly.
  • Also added the doc for the new cli command

Issues Resolved

Resolves #2525

@muawiakh muawiakh requested review from kansi, ttmc, vrde and z-bowen September 13, 2018 14:43
@codecov-io
Copy link
Copy Markdown

codecov-io commented Sep 13, 2018

Codecov Report

Merging #2541 into master will increase coverage by 0.02%.
The diff coverage is 100%.

@@            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

Copy link
Copy Markdown
Contributor

@kansi kansi left a comment

Choose a reason for hiding this comment

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

It would be good to have a test which passes unsupported Tendermint version and asserts system exit

f" Currently, BigchainDB only supports {__tm_supported_versions__} .Exiting!")
sys.exit(1)
except AttributeError:
logger.debug("Skipping Tendermint version check.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
"""
Copy link
Copy Markdown
Contributor

@ldmberman ldmberman Sep 13, 2018

Choose a reason for hiding this comment

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

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.

"description": "BigchainDB supports the following Tendermint version(s)",
"tendermint": [],
}
[supported_tm_ver["tendermint"].append(ver) for ver in __tm_supported_versions__]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 '.

Copy link
Copy Markdown
Contributor

@ttmc ttmc left a comment

Choose a reason for hiding this comment

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

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.

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!")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The spacing is slightly off near the end of this line. It should end with }. Exiting!")


# Check if BigchainDB supports the Tendermint version
try:
if check_tendermint_version(request.version):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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().

f" Currently, BigchainDB only supports {__tm_supported_versions__} .Exiting!")
sys.exit(1)
except AttributeError:
logger.debug("Skipping Tendermint version check.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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('-')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor

@ldmberman ldmberman Sep 14, 2018

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor

@ldmberman ldmberman Sep 14, 2018

Choose a reason for hiding this comment

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

A slight correction:

not (hasattr(request, 'version') and tendermint_version_is_compatible(request.version))

for ver in __tm_supported_versions__:
if version.parse(ver) == version.parse(tm_ver[0]):
return True
else:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

return False belongs to the outer scope, not to if-else.

@kansi kansi merged commit bd39076 into bigchaindb:master Sep 14, 2018
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.

Problem: Users trying to use an incompatible version of Tendermint

5 participants