@@ -91,9 +91,21 @@ contract VotingReputation is ColonyExtension, PatriciaTreeProofs, BasicMetaTrans
9191 uint256 submitPeriod; // Length of time for submitting votes
9292 uint256 revealPeriod; // Length of time for revealing votes
9393 uint256 escalationPeriod; // Length of time for escalating after a vote
94+
95+ uint256 motionCount;
96+ mapping (uint256 => Motion) motions;
97+ mapping (uint256 => mapping (address => mapping (uint256 => uint256 ))) stakes;
98+ mapping (uint256 => mapping (address => bytes32 )) voteSecrets;
99+
100+ mapping (bytes32 => uint256 ) expenditurePastVotes; // expenditure slot signature => voting power
101+ mapping (bytes32 => uint256 ) expenditureMotionCounts; // expenditure struct signature => count
102+
94103 mapping (address => uint256 ) metatransactionNonces;
95104 function getMetatransactionNonce (address userAddress ) override public view returns (uint256 nonce ){
96- return metatransactionNonces[userAddress];
105+ // This offset is a result of fixing the storage layout, and having to prevent metatransactions being able to be replayed as a result
106+ // of the nonce resetting. The broadcaster has made ~3000 transactions in total at time of commit, so we definitely won't have a single
107+ // account at 1 million nonce by then.
108+ return metatransactionNonces[userAddress] + 1000000 ;
97109 }
98110
99111 function incrementMetatransactionNonce (address user ) override internal {
@@ -117,7 +129,7 @@ contract VotingReputation is ColonyExtension, PatriciaTreeProofs, BasicMetaTrans
117129 /// @notice Return the version number
118130 /// @return The version number
119131 function version () public pure override returns (uint256 ) {
120- return 4 ;
132+ return 5 ;
121133 }
122134
123135 /// @notice Install the extension
@@ -183,7 +195,21 @@ contract VotingReputation is ColonyExtension, PatriciaTreeProofs, BasicMetaTrans
183195 }
184196
185197 /// @notice Called when upgrading the extension
186- function finishUpgrade () public override auth {} // solhint-disable-line no-empty-blocks
198+ function finishUpgrade () public override auth {
199+ // For colonies that have been made since this the previous version's deployment,
200+ // or have done the majority of their motions since, let's at least avoid double-emitting events for motions with
201+ // the same id where we can, going forward.
202+
203+ // Load the value from the wrong storage slot in the previous version
204+ uint256 wrongSlotValue;
205+ assembly {
206+ wrongSlotValue := sload (add (motionCount.slot, 1 ))
207+ }
208+ // Set the correct storage slot to the larger of the two values.
209+ if (wrongSlotValue > motionCount){
210+ motionCount = wrongSlotValue;
211+ }
212+ } // solhint-disable-line no-empty-blocks
187213
188214 /// @notice Called when deprecating (or undeprecating) the extension
189215 function deprecate (bool _deprecated ) public override auth {
@@ -215,15 +241,6 @@ contract VotingReputation is ColonyExtension, PatriciaTreeProofs, BasicMetaTrans
215241 bytes action;
216242 }
217243
218- // Storage
219- uint256 motionCount;
220- mapping (uint256 => Motion) motions;
221- mapping (uint256 => mapping (address => mapping (uint256 => uint256 ))) stakes;
222- mapping (uint256 => mapping (address => bytes32 )) voteSecrets;
223-
224- mapping (bytes32 => uint256 ) expenditurePastVotes; // expenditure slot signature => voting power
225- mapping (bytes32 => uint256 ) expenditureMotionCounts; // expenditure struct signature => count
226-
227244 // Public functions (interface)
228245
229246 /// @notice Create a motion
@@ -774,8 +791,8 @@ contract VotingReputation is ColonyExtension, PatriciaTreeProofs, BasicMetaTrans
774791 Motion storage motion = motions[_motionId];
775792 uint256 requiredStake = getRequiredStake (_motionId);
776793
777- // Check for valid motion Id
778- if (_motionId == 0 || _motionId > motionCount) {
794+ // Check for valid motion Id / motion
795+ if (_motionId == 0 || _motionId > motionCount || motion.action. length == 0 ) {
779796
780797 return MotionState.Null;
781798
0 commit comments