Skip to content

Commit

Permalink
Merge branch 'feature/upgrade-v1.0.7' into chains/mainnet-v1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
olegfomenko committed Oct 14, 2023
2 parents 3684665 + dfaf126 commit 543b50f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
4 changes: 2 additions & 2 deletions x/rarimocore/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (k Keeper) EndBlocker(ctx sdk.Context) {

party.Status = types.PartyStatus_Slashed
party.FreezeEndBlock = 0

k.SetParams(ctx, param)
}

k.SetParams(ctx, param)
}
35 changes: 31 additions & 4 deletions x/rarimocore/keeper/msg_server_report_violation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"strconv"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -58,14 +59,14 @@ func (t msgServer) ReportViolation(goCtx context.Context, msg *types.MsgCreateVi
alreadyIncremented = alreadyIncremented || (sessionReported == msg.SessionId)
}

// If party was not incremented then increment.
// If violations reaches threshold then party becomes frozen.
// Trying to apply new violation if was not applied yet.
if !alreadyIncremented {
// Check that already have enough reports to confirm violation
if uint64(len(reports)) >= params.Threshold {
party.ViolationsCount++
party.ReportedSessions = append(party.ReportedSessions, msg.SessionId)
confirmViolation(party, msg.SessionId)
}

// If violations reaches threshold then party becomes frozen.
if party.ViolationsCount == params.MaxViolationsCount {
party.Status = types.PartyStatus_Frozen
party.FreezeEndBlock = uint64(ctx.BlockHeight()) + params.FreezeBlocksPeriod
Expand All @@ -89,3 +90,29 @@ func (t msgServer) ReportViolation(goCtx context.Context, msg *types.MsgCreateVi

return &types.MsgCreateViolationReportResponse{}, nil
}

// confirmViolation updates party entry with:
// 1. increments violations counter
// 2. adds new sessionId to the reported sessions
// 3. removes old reports with corresponding decreasing of counter
func confirmViolation(party *types.Party, sessionId string) {
party.ReportedSessions = append(party.ReportedSessions, sessionId)

// we are assuming that session ids is an integer values encoded into string
sessionIdInt, _ := strconv.Atoi(sessionId)

// dropReportSessionDelta is an amount of sessions when report is considered to old and can be removed
const dropReportSessionDelta = 100

actualReportedSessions := make([]string, 0, len(party.ReportedSessions))

for _, ssi := range party.ReportedSessions {
ssiInt, _ := strconv.Atoi(ssi)
if ssiInt+dropReportSessionDelta > sessionIdInt {
actualReportedSessions = append(actualReportedSessions, ssi)
}
}

party.ReportedSessions = actualReportedSessions
party.ViolationsCount = uint64(len(party.ReportedSessions))
}

0 comments on commit 543b50f

Please sign in to comment.