Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Persisting the state fails #46

Closed
clacladev opened this issue Feb 28, 2022 · 8 comments · Fixed by #48
Closed

Persisting the state fails #46

clacladev opened this issue Feb 28, 2022 · 8 comments · Fixed by #48
Assignees

Comments

@clacladev
Copy link

Hello team.
I am trying to use the new state dumping feature but it fails (macOS, pyenv, python 3.9.10, venv).

Apart from the fact that it would be nice to have the params for dumping and loading which don't error if the load path does not exists yet (so I can always copy and paste the same command and not having different results if it's the first or the nth time).
So having something like this always working

starknet-devnet \
  --dump-on transaction \
  --dump-path ~/.starknet_devnet \
  --load-path ~/.starknet_devnet

But there is a more pressing issue on my machine. If I start the devnet then I send the transaction, when I stop the devnet and the dump has to be written, it throws errors.

❯ starknet-devnet \                                
  --dump-on exit \    
  --dump-path ~/.starknet_devnet.pkl          
 * Running on http://localhost:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [28/Feb/2022 14:37:47] "POST /gateway/add_transaction HTTP/1.1" 200 -
^CDumping Devnet to: /Users/claudio/.starknet_devnet.pkl
Traceback (most recent call last):
  File "/Users/claudio/cairo_venv/bin/starknet-devnet", line 8, in <module>
    sys.exit(main())
  File "/Users/claudio/cairo_venv/lib/python3.9/site-packages/starknet_devnet/server.py", line 275, in main
    app.run(host=args.host, port=args.port)
  File "/Users/claudio/cairo_venv/lib/python3.9/site-packages/flask/app.py", line 920, in run
    run_simple(t.cast(str, host), port, self, **options)
  File "/Users/claudio/cairo_venv/lib/python3.9/site-packages/werkzeug/serving.py", line 1017, in run_simple
    inner()
  File "/Users/claudio/cairo_venv/lib/python3.9/site-packages/werkzeug/serving.py", line 970, in inner
    srv.serve_forever()
  File "/Users/claudio/cairo_venv/lib/python3.9/site-packages/werkzeug/serving.py", line 724, in serve_forever
    super().serve_forever(poll_interval=poll_interval)
  File "/Users/claudio/.pyenv/versions/3.9.10/lib/python3.9/socketserver.py", line 232, in serve_forever
    ready = selector.select(poll_interval)
  File "/Users/claudio/.pyenv/versions/3.9.10/lib/python3.9/selectors.py", line 416, in select
    fd_event_list = self._selector.poll(timeout)
  File "/Users/claudio/cairo_venv/lib/python3.9/site-packages/starknet_devnet/server.py", line 241, in dump_on_exit
    dumper.dump(dumper.dump_path)
  File "/Users/claudio/cairo_venv/lib/python3.9/site-packages/starknet_devnet/dump.py", line 34, in dump
    multiprocessing.Process(
  File "/Users/claudio/.pyenv/versions/3.9.10/lib/python3.9/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/Users/claudio/.pyenv/versions/3.9.10/lib/python3.9/multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/Users/claudio/.pyenv/versions/3.9.10/lib/python3.9/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/Users/claudio/.pyenv/versions/3.9.10/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/Users/claudio/.pyenv/versions/3.9.10/lib/python3.9/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/Users/claudio/.pyenv/versions/3.9.10/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 47, in _launch
    reduction.dump(process_obj, fp)
  File "/Users/claudio/.pyenv/versions/3.9.10/lib/python3.9/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'CarriedState.empty_for_testing.<locals>.<lambda>'

If I start the devnet to dump at every transaction, then as soon as I send a transaction, I get a 500 error for the transaction, and I the dump fails.

Could it be some dependency missing? Or any mismatched python version?

@FabijanC FabijanC self-assigned this Feb 28, 2022
@FabijanC
Copy link
Collaborator

Thanks for the quick feedback.

Regarding failing if load_path doesn't exist, that was done on purpose. Are you suggesting not loading in that case and starting with a fresh Devnet instance?

Regarding the error, can you reinstall devnet? Or try installing it in a new virtual environment and running there? If that doesn't help, can you try installing and running with Python 3.8 or Python 3.7?

@FabijanC
Copy link
Collaborator

Installed the devnet locally in a new virtual environment using your Python version (3.9.10) and tested invoking and dumping. Worked well. Running on Manjaro Linux.

@clacladev
Copy link
Author

Yes I am suggesting that if the load_path does not exists, the state starts anew. So in a tutorial I can tell newbies like me, always run this xyz command to preserve the state of the devnet between sessions.

I created a new venv, selected it, selected 3.9.10 as python version, reinstalled the cairo-lang and starkent-devnet (0.1.17), launched the devnet with dumping on transactions. Then in another terminal selected the venv and deployed a contract.

As soon as it starts to dump a transaction, I get the same error.

Then I repeated the process, deleting the venv folder first, using python 3.7 and 3.8. Both not working.

@FabijanC
Copy link
Collaborator

FabijanC commented Mar 1, 2022

Ok, thanks for the detailed description of what you've tried. There are known issues with multiprocessing and pickling with Python >=3.8 on MacOS.
Activate your virtual environment and run this:

python -c "import multiprocessing; print(multiprocessing.get_start_method())"

What do you get? If it's not fork, try running the following to locate your devnet installation:

python -c "import os; import starknet_devnet; print(os.path.dirname(starknet_devnet.__file__))"

Inside the printed directory, locate dump.py and paste the following line before the definition of class Dumper:

multiprocessing.set_start_method("fork")

Try starting your devnet and dumping with that line pasted.

@clacladev
Copy link
Author

With the command python -c "import multiprocessing; print(multiprocessing.get_start_method())" I get spawn.

So, I added the line you suggested in dump.py and now it works as expected.

@FabijanC
Copy link
Collaborator

FabijanC commented Mar 1, 2022

Ok, I will keep this issue open until we release a patch version. Until then, you can rely on this local fix. Thanks for reporting!

@clacladev
Copy link
Author

You're welcome. I am trying to contribute by reporting everything I find. If you need macOS specific support on other issues, ping me

@FabijanC
Copy link
Collaborator

FabijanC commented Mar 1, 2022

Great, thanks! Very much appreciated.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants