Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Setting invalid DID metadata breaks a lot of rpc commands #17412

Closed
Gaerax opened this issue Jan 27, 2024 · 2 comments
Closed

[Bug] Setting invalid DID metadata breaks a lot of rpc commands #17412

Gaerax opened this issue Jan 27, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@Gaerax
Copy link

Gaerax commented Jan 27, 2024

What happened?

I guess DID metadata is expected to be a flat key value pair. If you try setting it to a multi-layer json, it breaks any rpc command that causes a transaction.

Here is an example:

(base) PS C:\Users\gaerax> chia rpc wallet did_get_metadata '{\"wallet_id\": 8}'
{
    "metadata": {
        "foo": "bar"               <--- correctly formatted metadata, everything works fine
    },
    "success": true,
    "wallet_id": 8
}
(base) PS C:\Users\gaerax> chia rpc wallet did_update_metadata '{\"wallet_id\": 8, \"metadata\": {\"foo\": {\"bar\": \"foobar\"}}, \"fee\": 500000}'
Request failed: {'error': "can't cast <class 'dict'> ({'bar': 'foobar'}) to bytes", 'success': False, 'traceback': 'Traceback (most recent call last):\n  File "chia\\rpc\\util.py", line 21, in inner\n  File "chia\\rpc\\util.py", line 82, in rpc_endpoint\n  File "chia\\rpc\\wallet_rpc_api.py", line 2404, in did_update_metadata\n  File "chia\\wallet\\did_wallet\\did_wallet.py", line 1430, in update_metadata\n  File "chia\\wallet\\wallet_state_manager.py", line 505, in update_wallet_puzzle_hashes\n  File "chia\\wallet\\did_wallet\\did_wallet.py", line 527, in puzzle_hash_for_pk\n  File "chia\\wallet\\did_wallet\\did_wallet_puzzles.py", line 191, in metadata_to_program\n  File "clvm\\SExp.py", line 182, in to\n  File "clvm\\SExp.py", line 98, in to_sexp_type\n  File "clvm\\SExp.py", line 55, in convert_atom_to_bytes\nValueError: can\'t cast <class \'dict\'> ({\'bar\': \'foobar\'}) to bytes\n'}
(base) PS C:\Users\gaerax> chia rpc wallet did_get_metadata '{\"wallet_id\": 8}'
{
    "metadata": {
        "foo": {
            "bar": "foobar"           <--- bad metadata, should not be here given the above error
        }
    },
    "success": true,
    "wallet_id": 8
}
(base) PS C:\Users\gaerax> chia wallet did create       <--- now this doesn't work

Failed to create DID wallet: {'error': "can't cast <class 'dict'> ({'bar': 'foobar'}) to bytes", 'success': False, 'traceback': 'Traceback (most recent call last):\n  File "chia\\rpc\\util.py", line 21, in inner\n  File "chia\\rpc\\util.py", line 82, in rpc_endpoint\n  File "chia\\rpc\\wallet_rpc_api.py", line 726, in create_new_wallet\n  File "chia\\wallet\\did_wallet\\did_wallet.py", line 128, in create_new_did_wallet\n  File "chia\\wallet\\did_wallet\\did_wallet.py", line 1251, in generate_new_decentralised_id\n  File "chia\\wallet\\did_wallet\\did_wallet.py", line 1119, in get_new_did_innerpuz\n  File "chia\\wallet\\did_wallet\\did_wallet.py", line 1106, in get_new_p2_inner_puzzle\n  File "chia\\wallet\\wallet.py", line 168, in get_new_puzzle\n  File "chia\\wallet\\wallet_state_manager.py", line 546, in get_unused_derivation_record\n  File "chia\\wallet\\wallet_state_manager.py", line 439, in create_more_puzzle_hashes\n  File "chia\\wallet\\did_wallet\\did_wallet.py", line 527, in puzzle_hash_for_pk\n  File "chia\\wallet\\did_wallet\\did_wallet_puzzles.py", line 191, in metadata_to_program\n  File "clvm\\SExp.py", line 182, in to\n  File "clvm\\SExp.py", line 98, in to_sexp_type\n  File "clvm\\SExp.py", line 55, in convert_atom_to_bytes\nValueError: can\'t cast <class \'dict\'> ({\'bar\': \'foobar\'}) to bytes\n'}

The transaction to update the metadata doesn't happen, but I guess it saves the metadata somewhere, because even if you restart chia, the error persists.
The error also comes up in the gui when creatings a did, sending a transaction, burning an nft, etc.
image
and gives this error in the console.

useShowError.tsx:12 Error: can't cast <class 'dict'> ({'bar': 'foobar'}) to bytes
    at o.<anonymous> (Client.ts:236:16)
    at o.emit (node:events:514:28)
    at u.re (websocket.js:1098:20)
    at u.emit (node:events:514:28)
    at u.value (receiver.js:528:14)
    at receiver.js:479:23
    at permessage-deflate.js:308:9
    at permessage-deflate.js:391:7
    at afterWrite (node:internal/streams/writable:500:5)
    at onwrite (node:internal/streams/writable:480:7)

You can fix the error by making another valid update to the metadata.

Version

2.1.4

What platform are you using?

Windows

What ui mode are you using?

CLI

Relevant log output

2024-01-26T20:16:41.208 wallet chia.rpc.util              : WARNING  Error while handling message: Traceback (most recent call last):
  File "chia\rpc\util.py", line 21, in inner
  File "chia\rpc\util.py", line 82, in rpc_endpoint
  File "chia\rpc\wallet_rpc_api.py", line 2404, in did_update_metadata
  File "chia\wallet\did_wallet\did_wallet.py", line 1430, in update_metadata
  File "chia\wallet\wallet_state_manager.py", line 505, in update_wallet_puzzle_hashes
  File "chia\wallet\did_wallet\did_wallet.py", line 527, in puzzle_hash_for_pk
  File "chia\wallet\did_wallet\did_wallet_puzzles.py", line 191, in metadata_to_program
  File "clvm\SExp.py", line 182, in to
  File "clvm\SExp.py", line 98, in to_sexp_type
  File "clvm\SExp.py", line 55, in convert_atom_to_bytes
ValueError: can't cast <class 'dict'> ({'bar': 'foobar'}) to bytes

2024-01-26T20:25:02.291 wallet chia.rpc.util              : WARNING  Error while handling message: Traceback (most recent call last):
  File "chia\rpc\util.py", line 21, in inner
  File "chia\rpc\util.py", line 82, in rpc_endpoint
  File "chia\rpc\wallet_rpc_api.py", line 726, in create_new_wallet
  File "chia\wallet\did_wallet\did_wallet.py", line 128, in create_new_did_wallet
  File "chia\wallet\did_wallet\did_wallet.py", line 1251, in generate_new_decentralised_id
  File "chia\wallet\did_wallet\did_wallet.py", line 1119, in get_new_did_innerpuz
  File "chia\wallet\did_wallet\did_wallet.py", line 1106, in get_new_p2_inner_puzzle
  File "chia\wallet\wallet.py", line 168, in get_new_puzzle
  File "chia\wallet\wallet_state_manager.py", line 546, in get_unused_derivation_record
  File "chia\wallet\wallet_state_manager.py", line 439, in create_more_puzzle_hashes
  File "chia\wallet\did_wallet\did_wallet.py", line 527, in puzzle_hash_for_pk
  File "chia\wallet\did_wallet\did_wallet_puzzles.py", line 191, in metadata_to_program
  File "clvm\SExp.py", line 182, in to
  File "clvm\SExp.py", line 98, in to_sexp_type
  File "clvm\SExp.py", line 55, in convert_atom_to_bytes
ValueError: can't cast <class 'dict'> ({'bar': 'foobar'}) to bytes

2024-01-26T20:45:21.196 wallet chia.rpc.rpc_server        : WARNING  Error while handling message: Traceback (most recent call last):
  File "chia\rpc\rpc_server.py", line 325, in safe_handle
  File "chia\rpc\rpc_server.py", line 316, in ws_api
  File "chia\rpc\util.py", line 82, in rpc_endpoint
  File "chia\rpc\wallet_rpc_api.py", line 1112, in send_transaction
  File "chia\wallet\wallet.py", line 450, in generate_signed_transaction
  File "chia\wallet\wallet.py", line 362, in _generate_unsigned_transaction
  File "chia\wallet\wallet.py", line 196, in get_new_puzzlehash
  File "chia\wallet\wallet_state_manager.py", line 546, in get_unused_derivation_record
  File "chia\wallet\wallet_state_manager.py", line 439, in create_more_puzzle_hashes
  File "chia\wallet\did_wallet\did_wallet.py", line 527, in puzzle_hash_for_pk
  File "chia\wallet\did_wallet\did_wallet_puzzles.py", line 191, in metadata_to_program
  File "clvm\SExp.py", line 182, in to
  File "clvm\SExp.py", line 98, in to_sexp_type
  File "clvm\SExp.py", line 55, in convert_atom_to_bytes
ValueError: can't cast <class 'dict'> ({'bar': 'foobar'}) to bytes
@Gaerax Gaerax added the bug Something isn't working label Jan 27, 2024
@wjblanke
Copy link
Contributor

wjblanke commented Jan 31, 2024

Hey Geoff can you check on the DID error handling here and the dict versus value issue.

Thanks for the report!

geoffwalmsley added a commit that referenced this issue Feb 9, 2024
Starttoaster pushed a commit that referenced this issue Feb 15, 2024
* Fix DID update metadata bug #17412

* coverage
@wjblanke
Copy link
Contributor

This should be fixed in main. If you can test it there, let us know if you still have issues. Thanks!

@wjblanke wjblanke closed this as completed Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants