question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] uncaught KeyError exception in block_record

See original GitHub issue

What happened?

I am not sure if this would be possible to reproduce, but I was running chia on raspberry (4GB RAM) for a like half a year, when in October the entire FS crashed, and I had to reinstall and unfortunately sync from scratch. After like 2 months of checking and regular restarts of chia daemon it got into near sync state of blockchain (wallet was full sync, but chain last day missing, this was somewhere between 21-22nd December). But when I’ve checked it after Christmas, the log is full of this:

2021-12-27T13:59:13.294 full_node full_node_server        : WARNING  Banning 99.152.32.71 for 10 seconds
2021-12-27T13:59:13.296 full_node chia.full_node.full_node: INFO     peer disconnected {'host': '99.152.32.71', 'port': 8444}
2021-12-27T13:59:13.298 full_node full_node_server        : ERROR    Exception b'\xd7\x80\xd2,z\x87\xc9\xe0\x1d\x98\xb4\x9a\t\x10\xf6p\x1c;\x95\x01WA1k?\xda\x04.]{\x81\xd2', exception Stack: Traceback (most recent call last):
  File "chia/server/server.py", line 437, in start_client
  File "chia/server/server.py", line 335, in connection_added
  File "chia/full_node/full_node.py", line 619, in on_connect
  File "chia/full_node/full_node.py", line 585, in synced
  File "chia/consensus/blockchain.py", line 157, in get_peak
  File "chia/consensus/blockchain.py", line 674, in height_to_block_record
  File "chia/consensus/blockchain.py", line 670, in block_record
KeyError: b'\xd7\x80\xd2,z\x87\xc9\xe0\x1d\x98\xb4\x9a\t\x10\xf6p\x1c;\x95\x01WA1k?\xda\x04.]{\x81\xd2'

2021-12-27T13:59:13.301 full_node asyncio                 : ERROR    Task exception was never retrieved
future: <Task finished name='Task-291378' coro=<RpcServer._state_changed() done, defined at chia/rpc/rpc_server.py:48> exception=KeyError(b'\xd7\x80\xd2,z\x87\xc9\xe0\x1d\x98\xb4\x9a\t\x10\xf6p\x1c;\x95\x01WA1k?\xda\x04.]{\x81\xd2')>
Traceback (most recent call last):
  File "chia/rpc/rpc_server.py", line 51, in _state_changed
  File "chia/rpc/full_node_rpc_api.py", line 61, in _state_changed
  File "chia/rpc/full_node_rpc_api.py", line 102, in get_blockchain_state
  File "chia/consensus/blockchain.py", line 157, in get_peak
  File "chia/consensus/blockchain.py", line 674, in height_to_block_record
  File "chia/consensus/blockchain.py", line 670, in block_record
KeyError: b'\xd7\x80\xd2,z\x87\xc9\xe0\x1d\x98\xb4\x9a\t\x10\xf6p\x1c;\x95\x01WA1k?\xda\x04.]{\x81\xd2'
2021-12-27T13:59:14.603 full_node full_node_server        : INFO     Cannot connect to host 112.25.210.130:8444 ssl:<ssl.SSLContext object at 0xffff377097c0> [Connect call failed ('112.25.210.130', 8444)]

running eg. chia show -s results in similar message:

Exception from 'show' Traceback (most recent call last):
  File "chia/cmds/show.py", line 41, in show_async
  File "chia/rpc/full_node_rpc_client.py", line 27, in get_blockchain_state
  File "chia/rpc/rpc_client.py", line 49, in fetch
ValueError: {'error': "b'\\xd7\\x80\\xd2,z\\x87\\xc9\\xe0\\x1d\\x98\\xb4\\x9a\\t\\x10\\xf6p\\x1c;\\x95\\x01WA1k?\\xda\\x04.]{\\x81\\xd2'", 'success': False}

but chia wallet show is ok, so seems only main daemon is somehow stuck:

chia wallet show
Wallet height: 1338206
Sync status: Synced
...

Version

1.2.11

What platform are you using?

Pi4

What ui mode are you using?

CLI

Relevant log output

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:88 (5 by maintainers)

github_iconTop GitHub Comments

10reactions
durdin85commented, Dec 29, 2021

Same problem, same header hash. Looking at the db I found this: … EDIT: With that change in the database the sync continued to work, the node is fully synced now

I’ve just checked my node, and you are right, the block 0 is actually set as peak:

sqlite> select header_hash, prev_hash, height, is_peak, is_block from block_records where is_peak == 1 and is_block == 1;

header_hash|prev_hash|height|is_peak|is_block
d780d22c7a87c9e01d98b49a0910f6701c3b95015741316b3fda042e5d7b81d2|ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb|0|1|1

sqlite> select header_hash, prev_hash, height, is_peak, is_block from block_records where height == (select max(height) from block_records);

header_hash|prev_hash|height|is_peak|is_block
3c61c9e9730722c45f738cd5cb3e3203428683679e966cc52dbfc78a623e69d5|356586bc3f5fa2e3671a1498e8d875e7892a59dccb40cd5cfdd369329132d561|1313895|0|1

So I’ve tried swapping peak on block 0 vs last block as suggested:

sqlite> update block_records set is_peak = 1 where height == (select max(height) from block_records);
sqlite> update block_records set is_peak = 0 where height == 0;
sqlite> select header_hash, prev_hash, height, is_peak, is_block from block_records where is_peak == 1 and is_block == 1;

header_hash|prev_hash|height|is_peak|is_block
3c61c9e9730722c45f738cd5cb3e3203428683679e966cc52dbfc78a623e69d5|356586bc3f5fa2e3671a1498e8d875e7892a59dccb40cd5cfdd369329132d561|1313895|1|1

and yes, it solves the problem, chia is again syncing. Question still remains how this could happen? Some remote trigger? ( / attacker?) Client bug? Protocol bug?

4reactions
mariano54commented, Feb 10, 2022

We will shortly release 1.3 beta which fixes this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python KeyError Exceptions and How to Handle Them
In this tutorial, you'll learn how to handle Python KeyError exceptions. They are often caused by a bad key lookup in a dictionary,...
Read more >
How to fix Python KeyError Exceptions in simple steps?
First, we access an existing key in the try-except block. If the Keyerror is not raised, there are no errors. Then the else...
Read more >
How to Fix KeyError Exceptions in Python - Rollbar
The Python KeyError is an exception that occurs when an attempt is made to access an item in a dictionary that does not...
Read more >
How to fix " KeyError: 'log_context' " on Flask - Stack Overflow
error ('Uncaught error thrown by Flask/Werkzeug', exc_info=ex) response = jsonify(message=str(ex), type='api_error') response.status_code = (ex.
Read more >
login key error on Manual talk:Pywikibot - MediaWiki
and (response['messagecode'] == 'login-throttled'. KeyError: 'messagecode'. CRITICAL: Exiting due to uncaught exception <class 'KeyError'>.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found