don't return all votes

This commit is contained in:
ryan 2016-07-15 15:27:24 +02:00
parent 7ce79c51ea
commit 5c11fc57fa

View File

@ -570,14 +570,20 @@ class Bigchain(object):
def get_last_voted_block(self):
"""Returns the last block that this node voted on."""
last_voted = r.table('votes') \
.filter(r.row['node_pubkey'] == self.me) \
.order_by(r.desc(r.row['vote']['timestamp'])) \
try:
# get the latest value for the vote timestamp (over all votes)
max_timestamp = r.table('votes') \
.concat_map(lambda x: [x['vote']['timestamp']]) \
.max() \
.run(self.conn)
last_voted = list(r.table('votes') \
.filter(r.row['node_pubkey'] == self.me) \
.filter(lambda x: x['vote']['timestamp'] == max_timestamp) \
.run(self.conn))
except r.ReqlNonExistenceError:
# return last vote if last vote exists else return Genesis block
if not last_voted:
return list(r.table('bigchain')
.filter(util.is_genesis_block)
.run(self.conn))[0]