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

Hare rolacle #458

Merged
merged 5 commits into from Jan 17, 2019
Merged

Hare rolacle #458

merged 5 commits into from Jan 17, 2019

Conversation

gavraz
Copy link
Contributor

@gavraz gavraz commented Jan 16, 2019

  • Added rolacle mock for testing
  • Added unit tests
  • Rebased to include last changes pushed to develop

func NewMockHashOracle(expectedSize int, comitySize int) *MockHashOracle {
mock := new(MockHashOracle)
mock.clients = make(map[string]struct{}, expectedSize)
mock.comitySize = comitySize
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: committee

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

}

func (mock *MockHashOracle) calcThreshold(comitySize int) uint32 {
if len(mock.clients) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

you should also lock when checking for the length. Consider using RWMutex instead of Mutex

Copy link
Contributor

Choose a reason for hiding this comment

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

It is good to have this check to detect bug, but you also need to check that committeeSize <= len(mock.clients)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


func (mock *MockHashOracle) calcThreshold(comitySize int) uint32 {
if len(mock.clients) == 0 {
panic("Called calcThreshold with 0 clients registered")
Copy link
Contributor

Choose a reason for hiding this comment

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

No reason to panic, print a fat error message and return 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

data := binary.LittleEndian.Uint32(proof)
// calculate thresholds
threshLeader := mock.calcThreshold(3) // expect 3 leaders
threshActive := mock.calcThreshold(mock.comitySize) // expect comitySize-3 actives
Copy link
Contributor

Choose a reason for hiding this comment

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

don't understand the comment, why -3?


if data < 10 {
// calculate hash of proof
hash := fnv.New32()
Copy link
Contributor

Choose a reason for hiding this comment

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

you should have a struct responsible for hashing, this struct should also return the max value (instead of the maxUint32 above). This way you'll make sure that no one changes the hash type without forgetting to update the max value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@gavraz gavraz merged commit 6f699fc into develop Jan 17, 2019
y0sher pushed a commit that referenced this pull request Jan 21, 2019
* Added mock oracle for testing
@y0sher y0sher deleted the hare_rolacle branch June 25, 2019 07:48
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.

None yet

2 participants