fiz: correções da pool

This commit is contained in:
Júnior
2025-06-17 18:26:14 -03:00
parent 682027d517
commit 9259f36e9c
31 changed files with 373 additions and 269 deletions

View File

@ -16,8 +16,8 @@ const (
PhasePrevote = "PREVOTE"
PhasePrecommit = "PRECOMMIT"
rewardAmount = 5
MaxRoundTimeout = 10 * time.Second
rewardAmount = 5
MaxRoundTimeout = 10 * time.Second
)
func StartConsensusLoop(
@ -66,14 +66,13 @@ func StartConsensusLoop(
log.Println("🛑 Loop de consenso encerrado")
return
case <-ticker.C:
roundState.Mu.Lock()
currentRound := roundState.Round
if time.Since(roundState.LastRoundStart) > MaxRoundTimeout {
log.Println("⏰ Timeout! Reiniciando round", roundState.Round+1)
roundState.ResetRound(roundState.Round + 1)
log.Println("⏰ Timeout! Reiniciando round", currentRound+1)
roundState.ResetRound(currentRound + 1)
roundState.LastRoundStart = time.Now()
phase = PhaseProposal
roundState.Mu.Unlock()
continue
}
@ -95,7 +94,7 @@ func StartConsensusLoop(
BaseMsg: BaseMsg{
MsgType: ProposalType,
HeightVal: roundState.Height,
RoundVal: roundState.Round,
RoundVal: currentRound,
Validator: nodeID,
Time: time.Now(),
},
@ -107,15 +106,17 @@ func StartConsensusLoop(
case PhasePrevote:
log.Println("🗳️ Fase de PREVOTE")
proposalHash := roundState.Proposal
vote := PrevoteMsg{
BaseMsg: BaseMsg{
MsgType: PrevoteType,
HeightVal: roundState.Height,
RoundVal: roundState.Round,
RoundVal: currentRound,
Validator: nodeID,
Time: time.Now(),
},
BlockHash: roundState.Proposal,
BlockHash: proposalHash,
}
roundState.Prevotes[nodeID] = vote.BlockHash
broadcast(vote)
@ -123,15 +124,17 @@ func StartConsensusLoop(
case PhasePrecommit:
log.Println("🔐 Fase de PRECOMMIT")
proposalHash := roundState.Proposal
vote := PrecommitMsg{
BaseMsg: BaseMsg{
MsgType: PrecommitType,
HeightVal: roundState.Height,
RoundVal: roundState.Round,
RoundVal: currentRound,
Validator: nodeID,
Time: time.Now(),
},
BlockHash: roundState.Proposal,
BlockHash: proposalHash,
}
roundState.Precommits[nodeID] = vote.BlockHash
broadcast(vote)
@ -164,11 +167,10 @@ func StartConsensusLoop(
}
ApplySlash(roundState.Precommits, blockHash, stakingStore, validatorSet)
}
roundState.ResetRound(roundState.Round + 1)
roundState.ResetRound(currentRound + 1)
roundState.LastRoundStart = time.Now()
phase = PhaseProposal
}
roundState.Mu.Unlock()
}
}
}
}