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

SIM - BE - Fix - json load for validator config #272

Closed
bradleySuira opened this issue Jul 11, 2024 · 2 comments · Fixed by #273
Closed

SIM - BE - Fix - json load for validator config #272

bradleySuira opened this issue Jul 11, 2024 · 2 comments · Fixed by #273
Assignees

Comments

@bradleySuira
Copy link
Contributor

bradleySuira commented Jul 11, 2024

When test in main I got this error when try to update the validator and the same when try to get the list of them

jsonrpc-1     | ERROR | update_validator: {'status': 'error', 'message': 'the JSON object must be str, bytes or bytearray, not dict', 'data': {'traceback': 'Traceback (most recent call last):\n  File "/app/backend/protocol_rpc/endpoint_generator.py", line 18, in endpoint\n    result = function(*args, **kwargs)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/app/backend/protocol_rpc/endpoints.py", line 228, in update_validator\n    return validators_registry.update_validator(\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/app/backend/database_handler/validators_registry.py", line 85, in update_validator\n    return self._get_validator_or_fail(validator_address)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/app/backend/database_handler/validators_registry.py", line 35, in _get_validator_or_fail\n    return self._parse_validator_data(validator_data)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/app/backend/database_handler/validators_registry.py", line 22, in _parse_validator_data\n    "config": json.loads(validator_data["config"]),\n              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/usr/local/lib/python3.12/json/__init__.py", line 339, in loads\n    raise TypeError(f\'the JSON object must be str, bytes or bytearray, \'\nTypeError: the JSON object must be str, bytes or bytearray, not dict\n'}}
jsonrpc-1     | INFO | 192.168.65.1 - - [11/Jul/2024 20:23:34] "POST /api HTTP/1.1" 200 -

@bradleySuira bradleySuira self-assigned this Jul 11, 2024
@bradleySuira bradleySuira changed the title Fix - json load for validator config SIM - BE - Fix - json load for validator config Jul 11, 2024
@bradleySuira bradleySuira linked a pull request Jul 11, 2024 that will close this issue
@AgustinRamiroDiaz
Copy link
Contributor

AgustinRamiroDiaz commented Jul 12, 2024

Adding more context:

The issue revolves around how node configuration is managed:

  • in the abstract sense, the node configuration is a key-value store
  • in the implementation we have some places where it's a dictionary, and other where it's a string. This is what's causing problems since we end up parsing twice some jsons which leads to errors
  • turns out that Postgres allows us to store either 🤯 https://www.postgresql.org/docs/current/datatype-json.html

So my proposed solution would be to:

  • store node config as dict always: in python objects and in Postgres (jsonb seems like the best option)
  • review backwards compatibility
    • I think that prior to this we were storing it as string
    • We could use Alembic to do the migration, and to also enforce jsonb as the type of the column

@bradleySuira
Copy link
Contributor Author

Thanks @AgustinRamiroDiaz added cc to @cristiam86 with my solution based on your comments and pushed the changes to the PR

  • As you said be were storing a string in a jsonb field in database
  • I ended sending when call to create and update methods a valid json from the frontend
  • in the backend side in both, update and create, I ended using this "config": AsIs("'" + json.dumps(config) + "'"),, with this change the field is stored as a json in the database and not as string
  • Because the last point, we don't need to cal anymore the json.loads() method when we get the validators data, so json.loads(validator_data["config"]), is now validator_data["config"] like we have before

I tested addling listing and updating the validators and also the contract deployment and methods calls

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

Successfully merging a pull request may close this issue.

3 participants