commit inicial do projeto

This commit is contained in:
Júnior
2025-05-23 10:44:32 -03:00
commit 8f04473c0b
106 changed files with 5673 additions and 0 deletions

View File

@ -0,0 +1,28 @@
package consensus
import (
"dejo_node/internal/staking"
"log"
)
const SlashAmount = 50 // tokens penalizados
// ApplySlash penaliza validadores que não votaram corretamente.
func ApplySlash(precommits map[string]string, blockHash string, stakingStore *staking.StakingStore, validatorSet *ValidatorSet) {
for _, val := range validatorSet.Validators {
vote, voted := precommits[val.Address]
if !voted || vote != blockHash {
// Slashing
info, exists := stakingStore.GetStakeInfo(val.Address)
if exists && info.Amount >= SlashAmount {
newInfo := staking.StakeInfo{
Amount: info.Amount - SlashAmount,
Duration: uint64(info.Duration),
}
stakingStore.UpdateStakeInfo(val.Address, newInfo)
log.Printf("⚡ SLASH: Validador %s penalizado em %d tokens\n", val.Address, SlashAmount)
}
}
}
_ = stakingStore.SaveToDisk("data/staking.db")
}