Skip to content
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

Make isQuorumSetSane() more informative #549

Merged
merged 1 commit into from
Feb 18, 2020

Conversation

AndrejMitrovic
Copy link
Contributor

If this looks good to you, I will also submit a PR upstream.

However in upstream they already use a different set of rules for isQuorumSetSane, so we would have to update our bindings to the latest version first. And that's not trivial as of now.

Part of #515

@AndrejMitrovic AndrejMitrovic added the type-enhancement An improvement of existing functionalities label Feb 18, 2020
@Geod24
Copy link
Collaborator

Geod24 commented Feb 18, 2020

Probably need to use std::string to satisfy upstream.

@AndrejMitrovic
Copy link
Contributor Author

Probably need to use std::string to satisfy upstream.

That would upset downstream. :>

{
if (reason != nullptr)
{
const char* msg = "Number of validator nodes exceeds the limit [1..1000]";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Technically it's out of bounds, as it can be 0.
You could also split it up into "Quorum set has no validator" and "Quorum set has over 1000 validators".

: mExtraChecks{extraChecks}
{
mIsSane = checkSanity(qSet, 0) && mCount >= 1 && mCount <= 1000;
mIsSane = checkSanity(qSet, 0, reason);
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can simplify the code by making the reason optional on the API, but required in the functions (IOW provides a dummy variable if reason is null so you avoid bounds check).

@AndrejMitrovic
Copy link
Contributor Author

Can we already use std::string in D code? I see there's some support code in https://github.com/dlang/druntime/blob/master/src/core/stdcpp/string.d

@Geod24
Copy link
Collaborator

Geod24 commented Feb 18, 2020

I think we can, as long as we don't copy it and just read it.

@codecov
Copy link

codecov bot commented Feb 18, 2020

Codecov Report

Merging #549 into v0.x.x will increase coverage by 0.07%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           v0.x.x     #549      +/-   ##
==========================================
+ Coverage   89.14%   89.21%   +0.07%     
==========================================
  Files          59       59              
  Lines        4285     4276       -9     
==========================================
- Hits         3820     3815       -5     
+ Misses        465      461       -4
Flag Coverage Δ
#integration 47.79% <ø> (+0.31%) ⬆️
#unittests 88.18% <ø> (+0.06%) ⬆️
Impacted Files Coverage Δ
source/agora/common/Serializer.d 98.76% <0%> (+0.09%) ⬆️
source/agora/common/Deserializer.d 95.71% <0%> (+3.94%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6584fcf...fe64a8b. Read the comment docs.

@AndrejMitrovic
Copy link
Contributor Author

Fixed to avoid bounds / null checking. I'm using std::string in another branch (https://github.com/AndrejMitrovic/agora/tree/quorum-is-sane%2Bstd-string), but it fails with:

libstdc++ std::__cxx11::basic_string is not yet supported; the struct contains an interior pointer which breaks D move semantics!

mIsSane = checkSanity(qSet, 0, reason);
if (mCount < 1)
{
const char* msg = "Number of validator nodes is zero";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Am I missing something w.r.t. the const char* msg = ...; *reason = msg pattern ? Wouldn't *reason = ... be more straightforward ?
Also assert that reason and mIsSane are consistent at the end of this constructor.

@Geod24
Copy link
Collaborator

Geod24 commented Feb 18, 2020

but it fails with:

Sad!

@@ -247,10 +247,17 @@ bool
BallotProtocol::isStatementSane(SCPStatement const& st, bool self)
{
auto qSet = mSlot.getQuorumSetFromStatement(st);
bool res = qSet != nullptr && isQuorumSetSane(*qSet, false);
const char* reason;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

bad bad bad! no T.init in C++.

This enables better debugging / UX when a quorum
set is misconfigured.

Part of bosagora#515
@AndrejMitrovic
Copy link
Contributor Author

Updated.

}

// only one of the two may be true
assert(mIsSane ^ (*reason != nullptr));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Attaboy

@Geod24 Geod24 merged commit bc6850b into bosagora:v0.x.x Feb 18, 2020
@AndrejMitrovic AndrejMitrovic deleted the quorum-is-sane branch February 18, 2020 06:37
@AndrejMitrovic AndrejMitrovic linked an issue Feb 18, 2020 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-enhancement An improvement of existing functionalities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

isQuorumSetSane is not informative
2 participants