11// SPDX-License-Identifier: MIT
2- pragma solidity ^ 0.8.22 ;
2+ pragma solidity ^ 0.8.24 ;
33
44import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol " ;
55import {ISmartnodesCore} from "./interfaces/ISmartnodesCore.sol " ;
@@ -59,10 +59,7 @@ contract SmartnodesCoordinator is ReentrancyGuard {
5959 mapping (address => uint256 ) public validatorVote;
6060 mapping (address => uint8 ) public hasSubmittedProposal;
6161 mapping (address => uint256 ) public validatorLastActiveRound; // Track validator activity
62-
63- // Enhanced round management
64- uint256 public currentRoundNumber;
65- uint256 private roundSeed; // Used for deterministic but unpredictable validator selection
62+ uint256 private roundSeed;
6663
6764 // ============= Events ==============
6865 event ProposalCreated (
@@ -150,7 +147,6 @@ contract SmartnodesCoordinator is ReentrancyGuard {
150147 }
151148
152149 // Initialize round management
153- currentRoundNumber = 1 ;
154150 roundSeed = uint256 (
155151 keccak256 (
156152 abi.encode (block .timestamp , block .prevrandao , _genesisNodes)
@@ -206,7 +202,7 @@ contract SmartnodesCoordinator is ReentrancyGuard {
206202
207203 // mark as active
208204 hasSubmittedProposal[sender] = proposalNum;
209- validatorLastActiveRound[sender] = currentRoundNumber ;
205+ validatorLastActiveRound[sender] = nextProposalId ;
210206
211207 emit ProposalCreated (proposalNum, proposalHash, sender);
212208 }
@@ -228,7 +224,7 @@ contract SmartnodesCoordinator is ReentrancyGuard {
228224
229225 Proposal storage proposal = currentProposals[proposalId - 1 ];
230226 validatorVote[msg .sender ] = proposalId;
231- validatorLastActiveRound[msg .sender ] = currentRoundNumber ; // Mark as active
227+ validatorLastActiveRound[msg .sender ] = nextProposalId ; // Mark as active
232228 proposal.votes++ ;
233229 }
234230
@@ -281,7 +277,7 @@ contract SmartnodesCoordinator is ReentrancyGuard {
281277 }
282278
283279 // Mark executor as active
284- validatorLastActiveRound[msg .sender ] = currentRoundNumber ;
280+ validatorLastActiveRound[msg .sender ] = nextProposalId ;
285281
286282 // Optimized batch validator removal
287283 if (validatorsToRemove.length > 0 ) {
@@ -341,7 +337,7 @@ contract SmartnodesCoordinator is ReentrancyGuard {
341337
342338 validators.push (validator);
343339 isValidator[validator] = true ;
344- validatorLastActiveRound[validator] = currentRoundNumber ; // Mark as active from start
340+ validatorLastActiveRound[validator] = nextProposalId ; // Mark as active from start
345341 emit ValidatorAdded (validator);
346342 }
347343
@@ -438,7 +434,6 @@ contract SmartnodesCoordinator is ReentrancyGuard {
438434
439435 function _updateRound () internal {
440436 _resetValidatorStates ();
441- currentRoundNumber++ ;
442437 _selectNewRoundValidators ();
443438 delete currentProposals; // Clear proposals for new round
444439 timeConfig.lastExecutionTime = uint128 (block .timestamp );
@@ -492,7 +487,7 @@ contract SmartnodesCoordinator is ReentrancyGuard {
492487 roundSeed,
493488 block .timestamp ,
494489 block .prevrandao ,
495- currentRoundNumber ,
490+ nextProposalId ,
496491 blockhash (block .number - 1 )
497492 )
498493 )
@@ -511,8 +506,8 @@ contract SmartnodesCoordinator is ReentrancyGuard {
511506
512507 // Prioritize active validators (those who participated in recent rounds)
513508 uint256 selectedCount = 0 ;
514- uint256 inactivityThreshold = currentRoundNumber > 3
515- ? currentRoundNumber - 3
509+ uint256 inactivityThreshold = nextProposalId > 3
510+ ? nextProposalId - 3
516511 : 0 ;
517512
518513 // First, try to select active validators
@@ -552,7 +547,7 @@ contract SmartnodesCoordinator is ReentrancyGuard {
552547 }
553548 }
554549
555- emit NewRoundStarted (currentRoundNumber , currentRoundValidators);
550+ emit NewRoundStarted (nextProposalId , currentRoundValidators);
556551 }
557552
558553 function _computeProposalHash (
@@ -628,7 +623,8 @@ contract SmartnodesCoordinator is ReentrancyGuard {
628623
629624 function _isCurrentRoundExpired () internal view returns (bool ) {
630625 TimeConfig memory tc = timeConfig;
631- return block .timestamp > tc.lastExecutionTime + (tc.updateTime << 1 );
626+ return
627+ block .timestamp > tc.lastExecutionTime + ((tc.updateTime * 5 ) / 4 );
632628 }
633629
634630 // ============= View Functions =============
@@ -726,7 +722,7 @@ contract SmartnodesCoordinator is ReentrancyGuard {
726722 )
727723 {
728724 return (
729- currentRoundNumber ,
725+ nextProposalId ,
730726 currentRoundValidators.length ,
731727 _calculateRoundValidatorCount (),
732728 _calculateRequiredVotes ()
0 commit comments