From 51bc0a2af6c3b2c5cd987946fd730f3b409921b2 Mon Sep 17 00:00:00 2001 From: Orlando Date: Tue, 27 Jun 2023 11:25:51 +0100 Subject: [PATCH 1/2] refactor: use PackedData struct in memory for reads --- src/utils/ActiveProposalsLimiter.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/ActiveProposalsLimiter.sol b/src/utils/ActiveProposalsLimiter.sol index 32981f84..3e64b972 100644 --- a/src/utils/ActiveProposalsLimiter.sol +++ b/src/utils/ActiveProposalsLimiter.sol @@ -21,7 +21,7 @@ abstract contract ActiveProposalsLimiter { if (maxActiveProposals == 0) revert MaxActiveProposalsCannotBeZero(); // The space calls the proposal validation strategy, therefore msg.sender corresponds to the space address. - PackedData storage packedData = usersPackedData[msg.sender][author]; + PackedData memory packedData = usersPackedData[msg.sender][author]; if (packedData.lastUpdate == 0) { // First time the user proposes, activeProposals is 1 no matter what. @@ -36,8 +36,8 @@ abstract contract ActiveProposalsLimiter { // Cooldown has not passed, user has not reached maximum active proposals: increase counter. packedData.activeProposals += 1; } - packedData.lastUpdate = uint32(block.timestamp); + usersPackedData[msg.sender][author] = packedData; return true; } } From 3742de0f69807c4e9d4949dffcf23801713c4e61 Mon Sep 17 00:00:00 2001 From: Orlando Date: Tue, 27 Jun 2023 11:32:04 +0100 Subject: [PATCH 2/2] chore: updated comments --- src/utils/ActiveProposalsLimiter.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/ActiveProposalsLimiter.sol b/src/utils/ActiveProposalsLimiter.sol index 3e64b972..2a80a3de 100644 --- a/src/utils/ActiveProposalsLimiter.sol +++ b/src/utils/ActiveProposalsLimiter.sol @@ -5,6 +5,7 @@ pragma solidity ^0.8.18; /// @title Active Proposals Limiter Proposal Validation Module /// @notice This module can be used to limit the number of active proposals per author. abstract contract ActiveProposalsLimiter { + /// @dev Active proposal data stored for each author in a space. struct PackedData { uint32 activeProposals; uint32 lastUpdate; @@ -13,7 +14,7 @@ abstract contract ActiveProposalsLimiter { /// @notice Thrown when the maximum number of active proposals per user is set to 0. error MaxActiveProposalsCannotBeZero(); - /// @dev Mapping that stores a data struct for each space. + /// @dev Mapping that stores a data struct for each author in a space. mapping(address space => mapping(address author => PackedData)) private usersPackedData; /// @dev Validates an author by checking if they have reached the maximum number of active proposals at the current timestamp.