mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
don't return all votes
This commit is contained in:
parent
7ce79c51ea
commit
5c11fc57fa
@ -570,14 +570,20 @@ class Bigchain(object):
|
|||||||
def get_last_voted_block(self):
|
def get_last_voted_block(self):
|
||||||
"""Returns the last block that this node voted on."""
|
"""Returns the last block that this node voted on."""
|
||||||
|
|
||||||
|
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 = r.table('votes') \
|
last_voted = list(r.table('votes') \
|
||||||
.filter(r.row['node_pubkey'] == self.me) \
|
.filter(r.row['node_pubkey'] == self.me) \
|
||||||
.order_by(r.desc(r.row['vote']['timestamp'])) \
|
.filter(lambda x: x['vote']['timestamp'] == max_timestamp) \
|
||||||
.run(self.conn)
|
.run(self.conn))
|
||||||
|
|
||||||
# return last vote if last vote exists else return Genesis block
|
except r.ReqlNonExistenceError:
|
||||||
if not last_voted:
|
# return last vote if last vote exists else return Genesis block
|
||||||
return list(r.table('bigchain')
|
return list(r.table('bigchain')
|
||||||
.filter(util.is_genesis_block)
|
.filter(util.is_genesis_block)
|
||||||
.run(self.conn))[0]
|
.run(self.conn))[0]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user