-
Notifications
You must be signed in to change notification settings - Fork 28
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
Add CalNumOfVoterToElect
function to calculate the number of voter to elect
#86
Changes from 4 commits
d2e2058
0f8cf90
48f73a8
370cee7
b86864a
4171152
9507c51
e018662
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"sort" | ||
"strings" | ||
|
||
"github.com/datastream/probab/dst" | ||
"github.com/pkg/errors" | ||
"github.com/tendermint/tendermint/crypto/merkle" | ||
"github.com/tendermint/tendermint/crypto/tmhash" | ||
|
@@ -486,3 +487,21 @@ func RandVoterSet(numVoters int, votingPower int64) (*ValidatorSet, *VoterSet, [ | |
sort.Sort(PrivValidatorsByAddress(privValidators)) | ||
return vals, SelectVoter(vals, []byte{}), privValidators | ||
} | ||
|
||
// CalNumOfVoterToElect calculate the number of voter to elect and return the number. | ||
func CalNumOfVoterToElect(n int64, byzantineRatio float64, accuracy float64) int64 { | ||
if byzantineRatio < 0 || byzantineRatio > 1 || accuracy < 0 || accuracy > 1 { | ||
panic("byzantineRatio and accuracy should be the float between 0 and 1") | ||
} | ||
byzantine := int64(math.Floor(float64(n) * byzantineRatio)) | ||
|
||
for i := int64(1); i <= n; i++ { | ||
q := dst.HypergeometricQtlFor(n, byzantine, i, accuracy) | ||
p := q / float64(i) | ||
if p < 0.33 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not important: it's possible to reduce the number of division and floating-point comparison by writing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh. that's a good idea. |
||
return i | ||
} | ||
} | ||
|
||
return n | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not important: Since n≥3f+1 and
byzantineRatio
!=0,byzantine
≥1, we can assume that n≥4 and so it seems to be able to start with 4.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's a good point.
But, the Byzantine ratio and the number of Byzantine nodes cannot be viewed as the same value. Because it is the ratio and number. So, we cannot specify a value with the starting value of
n
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's right, I confirmed that if ratio<1/n then byzantine=0.