commit inicial do projeto
This commit is contained in:
28
internal/consensus/slash.go
Normal file
28
internal/consensus/slash.go
Normal 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")
|
||||
}
|
||||
Reference in New Issue
Block a user