Repository: Chia-Network/chia-blockchain
Pull request: Fix memo plotid
<!-- Merging Requirements:
- Please give your PR a title that is release-note friendly
- In order to be merged, you must add the most appropriate category Label (Added, Changed, Fixed) to your PR
-->
<!-- Explain why this is an improvement (Does this add missing functionality, improve performance, or reduce complexity?) -->
### Purpose:
Fixes issues where "chia plotters" command is returning bytes and causing type issues. This also removed the bytes32 for the hex arg, which is 128 bytes.


<!-- Does this PR introduce a breaking change? -->
### Current Behavior:



### New Behavior:



<!-- As we aim for complete code coverage, please include details regarding unit, and regression tests -->
### Testing Notes:
Created and duplicated plots using the plot ID and memo using "chia plots create" and "chia plotters chiapos"


<!-- Attach any visual examples, or supporting evidence (attach any .gif/video/console output below) -->


Problem statement:
[Bug] Wrong type with memo argument
### What happened?

When trying to duplicate plots, errors were received when passing in the 128-byte hex string. Additionally, I was receiving an error when using the "chia plotters" command with a memo that the memo needed to be converted to a string.

### Version

2.3.0rc1

### What platform are you using?

macOS

### What ui mode are you using?

CLI

### Relevant log output

```shell
2024-04-09T12:44:44.606  chia.plotting.manager            : ERROR    Failed to open file /Users/pmaslana/chia-blockchain/plot/plot-k25-2024-04-09-12-37-2d6806268d3f4075a260c5dc4f8075de71a3b4c8185547fec1268a3a901dad95.plot. Invalid number of bytes 32 Traceback (most recent call last):
  File "/Users/pmaslana/chia-blockchain/chia/plotting/manager.py", line 346, in process_file
    cache_entry = CacheEntry.from_disk_prover(prover)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pmaslana/chia-blockchain/chia/plotting/cache.py", line 59, in from_disk_prover
    ) = parse_plot_info(prover.get_memo())
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pmaslana/chia-blockchain/chia/plotting/util.py", line 257, in parse_plot_info
    raise ValueError(f"Invalid number of bytes {len(memo)}")
ValueError: Invalid number of bytes 32
-------------------------------------------------------------------------------------------
  File "/Users/pmaslana/chia-blockchain/chia/util/byte_types.py", line 37, in __init__
    raise ValueError(f"bad {type(self).__name__} initializer {v}")
ValueError: bad bytes32 initializer b'\xa7\xffK\x18\xea\x93t\xb3\xee\x13\xac\xc6_^\x90\xa8\xb6\x97\xd5\xc6z\xce]\x0f\xaai\xc6\xef\x018\xb6s\xb4V5\xf4\xa6\x01z\xa50sB)W\x1c\xe0\xd4\xa68\xccN\xe9GH\x010\x954"W\xf0+\xda\xf2G/\xcb\xd2\xa9Lw\xe1\x11\xd8\x8cz\x15\xcfY\xef\xaeI\x86\x02\xd5\r\xf0Y\x88\x1fi\xce\xe9\xa8]\x18\xbc\xfcu\x18$\xac?\x0f\x8f\xe4"\x90s\x8e\xcf\xcf\xa9\xe4S^\xb3\xe7h\xd9Y\x91\xc2\xe2}\xdb\x9b'

-------------------------------------------------------------------------------------------


File "/Users/pmaslana/chia-blockchain/chia/plotting/create_plots.py", line 217, in create_plots
    plot_memo = bytes32.fromhex(args.memo)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: fromhex() argument must be str, not bytes
```

Hints from issue discussion:

Commit message: Return the args.plotid bytes32.fromhex(plot_str) instead of bytes.fromhex(plot_str)

Patch to review:
diff --git a/chia/plotting/create_plots.py b/chia/plotting/create_plots.py
index ac33b5723153..e3c60ed0a82c 100644
--- a/chia/plotting/create_plots.py
+++ b/chia/plotting/create_plots.py
@@ -210,11 +210,22 @@ async def create_plots(
 
         if args.plotid is not None:
             log.info(f"Debug plot ID: {args.plotid}")
-            plot_id = bytes32(bytes.fromhex(args.plotid))
+            # Check if args.memo is of type bytes and convert it to a string if so
+            if isinstance(args.plotid, bytes):
+                plot_str = args.plotid.hex()  # Convert bytes to hex string
+            else:
+                plot_str = args.plotid
+            plot_id = bytes32.fromhex(plot_str)
 
         if args.memo is not None:
+            print(f"Type of args.memo: {type(args.memo)}")  # Should print: <class 'str'>
             log.info(f"Debug memo: {args.memo}")
-            plot_memo = bytes32.fromhex(args.memo)
+            # Check if args.memo is of type bytes and convert it to a string if so
+            if isinstance(args.memo, bytes):
+                memo_str = args.memo.hex()  # Convert bytes to hex string
+            else:
+                memo_str = args.memo
+            plot_memo = bytes.fromhex(memo_str)
 
         dt_string = datetime.now().strftime("%Y-%m-%d-%H-%M")
 


Code review comments:
diff_hunk: @@ -210,11 +210,22 @@ async def create_plots(
 
         if args.plotid is not None:
             log.info(f"Debug plot ID: {args.plotid}")
-            plot_id = bytes32(bytes.fromhex(args.plotid))
+            # Check if args.memo is of type bytes and convert it to a string if so
+            if isinstance(args.plotid, bytes):
+                plot_str = args.plotid.hex()  # Convert bytes to hex string
+            else:
+                plot_str = args.plotid
+            plot_id = bytes32.fromhex(plot_str)
 
         if args.memo is not None:
+            print(f"Type of args.memo: {type(args.memo)}")  # Should print: <class 'str'>
path: chia/plotting/create_plots.py
text: @user1:
this seems like a debugging print that should be removed

@author:
I removed the debugging print line and fixed the bytes32. Did we want to leave in the changes for the type check or try to fix chia plotters?