Skip to content

Commit

Permalink
Merge pull request #1 from rarimo/feature/upgrade-v1.0.7
Browse files Browse the repository at this point in the history
Upgrade v1.0.7: Adding feature for removing old records about party violation
  • Loading branch information
olegfomenko authored Oct 15, 2023
2 parents 95fadd1 + d7182f4 commit 36de84c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
12 changes: 12 additions & 0 deletions docs/common/mainnet/002-upgrades.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Mainnet upgrades

## V1.0.7
Core binary: (alpine-linux/amd64): "<https://storage.googleapis.com/rarimo-mainnet/1.0.7/rarimo-core>".

Also, you can build core from sources by yourself: Use <"https://github.com/rarimo/rarimo-core"> repo and `chains/mainnet` branch.

Upgrade will perform automatically if you are using `cosmovisor` under Alpine linux.
Also, if you are using Ubuntu linux, please install `musl-dev` using `sudo apt install musl-dev` command to be able to use Alpine binary on your machine.

Upgrade v1.0.7 introduces fixes to the `rarimocore` module:
- Adding feature to clear old TSS violation reports.
- Manual unfreeze of all TSS parties without necessity to reshare keys.

## V1.0.6

Core binary: (alpine-linux/amd64): "<https://storage.googleapis.com/rarimo-mainnet/1.0.6/rarimo-core>"
Expand Down
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 36de84c

Please sign in to comment.