Beem-0.20.12: unable to use Blockchain.stream()/blocks() with only_ops=True and threads

Project Information

A GitHub issue and a PR to fix the problem were provided and merged to master. The fix will be included in the next release.

Expected result

Blockchain.stream/blocks(start, stop, only_ops=True) should return all ops in the given block range. Additionally using threading=True should eventually speed things up.

Actual result

Blockchain.stream/blocks(start, stop, only_ops=True, threading=True) prints errors

int() argument must be a string, a bytes-like object or a number, not 'NoneType'

and never completes.

How to reproduce

from beem.blockchain import Blockchain
b = Blockchain()
for op in b.blocks(start=25000000, stop=25000010, only_ops=True,
                   threading=True):
    continue

Output:

int() argument must be a string, a bytes-like object or a number, not 'NoneType'
int() argument must be a string, a bytes-like object or a number, not 'NoneType'
int() argument must be a string, a bytes-like object or a number, not 'NoneType'
int() argument must be a string, a bytes-like object or a number, not 'NoneType'
int() argument must be a string, a bytes-like object or a number, not 'NoneType'
int() argument must be a string, a bytes-like object or a number, not 'NoneType'
...

Cause/Fix

When only_ops=False (default), beem uses the get_block API call. The get_block() answer contains the block_id field, which is correctly parsed by Block.block_num here.

When only_ops=True, beem uses the get_ops_in_block API call, which also includes virtual operations (e.g. author/curation rewards etc.) The get_ops_in_block() answer, however, does not contain a block_id field. Calling Block.block_num on this data returns None, causing the threads bookkeeping logic to fail to register the received block data. The Blockchain.blocks() logic then endlessly retries to fetch the corresponding block data.

The get_ops_in_block() answer contains the corresponding block number in a block field. By adding a check for the block field into the Block.block_num method, both cases can be treated correctly and Blockchain.blocks() doesn't run into int(None) errors anymore here.

Environment

# beempy --version
beempy, version 0.20.12
# python --version
Python 3.6.6

GitHub Account

https://github.com/crokkon

H2
H3
H4
Upload from PC
Video gallery
3 columns
2 columns
1 column
3 Comments