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
Hare rolacle #458
Conversation
gavraz
commented
Jan 16, 2019
- Added rolacle mock for testing
- Added unit tests
- Rebased to include last changes pushed to develop
hare/mock_oracle.go
Outdated
func NewMockHashOracle(expectedSize int, comitySize int) *MockHashOracle { | ||
mock := new(MockHashOracle) | ||
mock.clients = make(map[string]struct{}, expectedSize) | ||
mock.comitySize = comitySize |
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.
typo: committee
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.
Fixed
hare/mock_oracle.go
Outdated
} | ||
|
||
func (mock *MockHashOracle) calcThreshold(comitySize int) uint32 { | ||
if len(mock.clients) == 0 { |
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.
you should also lock when checking for the length. Consider using RWMutex instead of Mutex
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.
It is good to have this check to detect bug, but you also need to check that committeeSize <= len(mock.clients)
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.
Fixed.
hare/mock_oracle.go
Outdated
|
||
func (mock *MockHashOracle) calcThreshold(comitySize int) uint32 { | ||
if len(mock.clients) == 0 { | ||
panic("Called calcThreshold with 0 clients registered") |
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.
No reason to panic, print a fat error message and return 0
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.
Changed
hare/mock_oracle.go
Outdated
data := binary.LittleEndian.Uint32(proof) | ||
// calculate thresholds | ||
threshLeader := mock.calcThreshold(3) // expect 3 leaders | ||
threshActive := mock.calcThreshold(mock.comitySize) // expect comitySize-3 actives |
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.
don't understand the comment, why -3?
hare/mock_oracle.go
Outdated
|
||
if data < 10 { | ||
// calculate hash of proof | ||
hash := fnv.New32() |
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.
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
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.
Fixed
* Added mock oracle for testing