Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

optimize quorum #222

Closed
wants to merge 2 commits into from
Closed

optimize quorum #222

wants to merge 2 commits into from

Conversation

ZzzzHui
Copy link
Contributor

@ZzzzHui ZzzzHui commented Aug 21, 2023

No description provided.

@ZzzzHui ZzzzHui self-assigned this Aug 21, 2023
mapping(bytes => EnumerableSet.AddressSet) internal yeas;
// Quorum members
// Map an address to true if it's a validator
mapping(address => bool) public validators;
Copy link
Contributor

@guidanoli guidanoli Aug 21, 2023

Choose a reason for hiding this comment

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

This is very similar to how AccessControl is implemented. Maybe we should use it instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. The main idea is to reduce AccessControlEnumerable to only something like AccessControl. But the reason why I didn't use AccessControl is because AccessControl is most useful when there are different roles, while we only have one role, validator. So it doesn't make sense to me to do 1 extra storage read (through this variable) each time when we want to read the validators.

Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't imply an extra storage read.
It just adds a new keccak in the calculation of the storage slot where the value resides.
Either way, I think it is still worth it to use AccessControl because it has been tested thoroughly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right there's no extra storage read. Sorry about my mistake.
But you see, all we need is a mapping(address => bool), set some addresses map to true in the constructor, plus we used it for the modifier. This is simple enough that it doesn't make much of a difference using existing codes or not, since it's only 2 lines of codes plus a modifier.

Another advantage is that it can be more flexible if we want to optimize further. If the current version is ok, I'm creating another PR based on the current version for the last step of optimization. We can decide on this after the other PR, ok? If the other PR is not gonna be merged, then we can use AccessControl if you think it's better.

Copy link
Contributor

Choose a reason for hiding this comment

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

But you see, all we need is a mapping(address => bool), set some addresses map to true in the constructor, plus we used it for the modifier.

You're right, but this logic has already been implemented. There is no need to re-implement it. Besides, for anyone reading this code, they will need to understand what you're trying to achieve with this mapping, the modifier, etc. But if you use AccessControl (which many smart contract developers are already familiar with), the code will be much clearer, and, most importantly, more trustworthy.

Copy link
Contributor

Choose a reason for hiding this comment

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

Another advantage is that it can be more flexible if we want to optimize further.

That is true. But we need to find the balance between performance and simplicity.

Comment on lines -15 to -17
/// @dev This contract uses several OpenZeppelin contracts:
/// `AccessControlEnumerable`, `EnumerableSet`, and `PaymentSplitter`.
/// For more information on those, please consult OpenZeppelin's official documentation.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's good to mention that we're using OpenZeppelin's contracts, because they are trustworthy.

/// @dev Only validators can submit claims.
bytes32 public constant VALIDATOR_ROLE = keccak256("VALIDATOR_ROLE");

/// In this version, we assume the quorum doesn't change after the constructor.
Copy link
Contributor

Choose a reason for hiding this comment

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

It's more than just an assumption, it's a system limitation.
We could say, instead:

In this version, the validator set is immutable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree


/// @notice The validator role.
/// @dev Only validators can submit claims.
bytes32 public constant VALIDATOR_ROLE = keccak256("VALIDATOR_ROLE");
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use AccessControl, this variable would still be in use.

onchain/rollups/contracts/consensus/quorum/Quorum.sol Outdated Show resolved Hide resolved
@pedroargento
Copy link

pedroargento commented Aug 21, 2023 via email

@guidanoli
Copy link
Contributor

Maybe we could drop the "Submit", and instead keep "Vote for a claim to be submitted".

Just in the documentation, right? Because the function has to be
submitClaim to implement IConsensus.

Yes, I am referring to the documentation only. :-)

@guidanoli
Copy link
Contributor

I think, by default, we should seek good programming practices such as code reusability, and then, with proof of considerable improvements in gas costs, optimize the code for performance.

@guidanoli
Copy link
Contributor

guidanoli commented Sep 12, 2023

This has been migrated to cartesi/rollups-contracts#56.

@guidanoli guidanoli closed this Sep 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: 🚀 Done
Development

Successfully merging this pull request may close these issues.

3 participants