Separate pending and effective validator updates.#2556
Separate pending and effective validator updates.#2556kansi merged 8 commits intobigchaindb:masterfrom
Conversation
- Pending validator updates do not prevent elections from concluding. - ValidatorElection overrides has_conclude to not conclude when there is a pending update for the matching height. - Effective validator updates deem past elections inconclusive.
Codecov Report
@@ Coverage Diff @@
## master #2556 +/- ##
==========================================
- Coverage 93.65% 93.63% -0.02%
==========================================
Files 45 45
Lines 2630 2623 -7
==========================================
- Hits 2463 2456 -7
Misses 167 167 |
Solution: Record placed elections, update the records upon election conclusion.
7c8ee8c to
4a96216
Compare
bigchaindb/elections/election.py
Outdated
| elections = OrderedDict() | ||
| for tx in txns: | ||
| if isinstance(tx, Election): | ||
| tx.store(bigchain, new_height, is_concluded=False) |
There was a problem hiding this comment.
I would recommend to aggregate and store
bigchaindb/elections/election.py
Outdated
| (votes_committed + votes_current >= (2/3)*total_votes): | ||
| return True | ||
| if self.has_validator_set_changed(bigchain): | ||
| return False |
There was a problem hiding this comment.
It would be better to move this check to the beginning of the function so that the votes are not counted unnecessarily.
Otherwise, one can significantly slow nodes down by posting a whole bunch of unique elections.
|
Election records are inserted in bulk now. There is also the crash recovery issue (already in master) which is not only connected with election records but all database artifacts we create during |
bigchaindb/elections/election.py
Outdated
| (votes_committed + votes_current >= (2/3)*total_votes): | ||
| return True | ||
| current_validators = self.get_validators(bigchain) | ||
| total_votes = sum(current_validators.values()) |
There was a problem hiding this comment.
It occured to me that one could sum the "amount" of the outputs of the election to get the total_votes and avoid the query.
| cursor = conn.run( | ||
| conn.collection('elections') | ||
| .find(query, projection={'_id': False}) | ||
| .sort([('height', DESCENDING)]) |
There was a problem hiding this comment.
It would be better to use find_one and sort as an argument to the query.
|
This code is a dependency for fixing crash recovery so I will merge it. @vrde Please leave your comments and @ldmberman will address them in a separate a PR. |
has_concludedto not conclude when there is a pending update for the matching height.