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

Update raw.hpp so that we can serialize and deserialize const types #938

Merged
merged 8 commits into from
Oct 16, 2024

Conversation

greg7mdp
Copy link
Contributor

@greg7mdp greg7mdp commented Oct 15, 2024

Resolves #796.

Some types are only set in the constructor and never modified. So they are logically const and could be accessed from multiple threads safely.

Using this would allow us to remove some friend declarations (we use private as a way to prevent unchecked access to non thread-safe members).

Ideally we would make the member type const.
The serialization is what trips us up. I feel that the unpack functions in raw.hpp should accept to unpack const members of structs (logically deserializing to recreate a value which is never modified after creation). Right now we cannot mark non-funadamental types that needs to be serialized const.

Also added a test.

@greg7mdp greg7mdp requested review from heifner and linh2931 October 15, 2024 18:45
Copy link
Member

@heifner heifner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have the time. What about making a pass through the code and making what can be const, const.

@greg7mdp
Copy link
Contributor Author

Since we have the time. What about making a pass through the code and making what can be const, const.

I started doing that, but it does require a lot of changes through the code. For example most of the block_header_state should be const. But typically we create the empty struct and assign members after the fact (see here for example). Also the finish_next function.

Probably if we want to do this I should create another issue.

@heifner
Copy link
Member

heifner commented Oct 15, 2024

I started doing that, but it does require a lot of changes through the code. For example most of the block_header_state should be const. But typically we create the empty struct and assign members after the fact (see here for example). Also the finish_next function.

Probably if we want to do this I should create another issue.

For the large refactor like block_header_state a diff issue makes sense. Any low-hanging fruit you can change? At least one would be nice and show a usefulness of the feature.

@ericpassmore
Copy link
Contributor

Note:start
category: Chores
component: Internal
summary: Update raw.hpp so that we can serialize and deserialize const types.
Note:end

@@ -184,7 +189,13 @@ namespace eosio::chain {

// for testing purposes only, not thread safe
const fsi_t& get_fsi(const bls_public_key& k) const { return finalizers.at(k).fsi; }
void set_fsi(const bls_public_key& k, const fsi_t& fsi) { finalizers[k].fsi = fsi; }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think remove this blank line or add another comment saying this is only for testing purposes and not thread safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed!

@greg7mdp
Copy link
Contributor Author

greg7mdp commented Oct 16, 2024

I tried to make thsome members of action const, but I hit the issue that I can't find how to regenerate the tests in unittests/wasm-spec-tests/generated-tests, so I gave up. Please review the PR as-is.

@greg7mdp greg7mdp merged commit dd0382b into main Oct 16, 2024
36 checks passed
@greg7mdp greg7mdp deleted the gh_796 branch October 16, 2024 20:30
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 this pull request may close these issues.

Update raw.hpp so that we can serialize and deserialize const types
4 participants