Skip to content

Commit

Permalink
Merge pull request #88 from tellor-io/jailReporter
Browse files Browse the repository at this point in the history
Jail
  • Loading branch information
themandalore authored Feb 24, 2024
2 parents d36e994 + 19dbff4 commit c9752ab
Show file tree
Hide file tree
Showing 12 changed files with 1,824 additions and 179 deletions.
224 changes: 193 additions & 31 deletions api/layer/reporter/oracle_reporter.pulsar.go

Large diffs are not rendered by default.

1,026 changes: 954 additions & 72 deletions api/layer/reporter/tx.pulsar.go

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions api/layer/reporter/tx_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,13 @@ paths:
description: >-
Commission defines commission parameters for a given
validator.
jailed:
type: boolean
title: jailed is a bool whether the reporter is jailed or not
jailed_until:
type: string
format: date-time
title: jailed_until is the time the reporter is jailed until
title: >-
OracleReporter is the struct that holds the data for a
reporter
Expand Down Expand Up @@ -1674,6 +1681,13 @@ paths:
description: >-
Commission defines commission parameters for a given
validator.
jailed:
type: boolean
title: jailed is a bool whether the reporter is jailed or not
jailed_until:
type: string
format: date-time
title: jailed_until is the time the reporter is jailed until
title: >-
OracleReporter is the struct that holds the data for a
reporter
Expand Down Expand Up @@ -4083,6 +4097,13 @@ definitions:
format: date-time
description: update_time is the last time the commission rate was changed.
description: Commission defines commission parameters for a given validator.
jailed:
type: boolean
title: jailed is a bool whether the reporter is jailed or not
jailed_until:
type: string
format: date-time
title: jailed_until is the time the reporter is jailed until
title: OracleReporter is the struct that holds the data for a reporter
layer.reporter.Params:
type: object
Expand Down Expand Up @@ -4243,6 +4264,13 @@ definitions:
format: date-time
description: update_time is the last time the commission rate was changed.
description: Commission defines commission parameters for a given validator.
jailed:
type: boolean
title: jailed is a bool whether the reporter is jailed or not
jailed_until:
type: string
format: date-time
title: jailed_until is the time the reporter is jailed until
title: OracleReporter is the struct that holds the data for a reporter
description: >-
QueryReporterResponse is the response type for the Query/Reporter RPC
Expand Down Expand Up @@ -4302,6 +4330,13 @@ definitions:
update_time is the last time the commission rate was
changed.
description: Commission defines commission parameters for a given validator.
jailed:
type: boolean
title: jailed is a bool whether the reporter is jailed or not
jailed_until:
type: string
format: date-time
title: jailed_until is the time the reporter is jailed until
title: OracleReporter is the struct that holds the data for a reporter
description: all the reporters.
description: >-
Expand Down Expand Up @@ -4358,6 +4393,9 @@ definitions:
MsgDelegateReporter message.
layer.reporter.MsgUndelegateReporterResponse:
type: object
layer.reporter.MsgUnjailReporterResponse:
type: object
description: MsgUnjailReporterResponse defines the Msg/UnjailReporter response type.
layer.reporter.MsgUpdateParamsResponse:
type: object
description: |-
Expand Down
9 changes: 9 additions & 0 deletions proto/layer/reporter/oracle_reporter.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "amino/amino.proto";
import "cosmos/staking/v1beta1/staking.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/tellor-io/layer/x/reporter/types";

Expand All @@ -20,4 +21,12 @@ message OracleReporter {
];
// commission for the reporter
cosmos.staking.v1beta1.Commission commission = 3;
// jailed is a bool whether the reporter is jailed or not
bool jailed = 4;
// jailed_until is the time the reporter is jailed until
google.protobuf.Timestamp jailed_until = 5 [
(gogoproto.stdtime) = true,
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
}
15 changes: 15 additions & 0 deletions proto/layer/reporter/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ service Msg {
// WithdrawDelegatorReward defines a method to withdraw rewards of delegator
// from a reporter.
rpc WithdrawDelegatorReward(MsgWithdrawDelegatorReward) returns (MsgWithdrawDelegatorRewardResponse);

// UnjailReporter defines a method to unjail a jailed reporter.
rpc UnjailReporter(MsgUnjailReporter) returns (MsgUnjailReporterResponse);
}

// MsgUpdateParams is the Msg/UpdateParams request type.
Expand Down Expand Up @@ -139,3 +142,15 @@ message MsgWithdrawDelegatorRewardResponse {
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}

// MsgUnjailReporter defines the Msg/UnjailReporter request type.
message MsgUnjailReporter {
option (cosmos.msg.v1.signer) = "reporter_address";
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string reporter_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MsgUnjailReporterResponse defines the Msg/UnjailReporter response type.
message MsgUnjailReporterResponse {}
49 changes: 49 additions & 0 deletions x/reporter/keeper/jail.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package keeper

import (
"context"
"strconv"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tellor-io/layer/x/reporter/types"
)

// send a reporter to jail
func (k Keeper) JailReporter(ctx context.Context, reporter types.OracleReporter, jailDuration int64) error {
if reporter.Jailed {
return types.ErrReporterJailed.Wrapf("cannot jail already jailed reporter, %v", reporter)
}
sdkctx := sdk.UnwrapSDKContext(ctx)
reporter.JailedUntil = sdkctx.BlockTime().Add(time.Second * time.Duration(jailDuration))
reporter.Jailed = true
reporterAddr := sdk.MustAccAddressFromBech32(reporter.GetReporter())
err := k.Reporters.Set(ctx, reporterAddr, reporter)
if err != nil {
return err
}
sdkctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
"jailed_reporter",
sdk.NewAttribute("reporter", reporterAddr.String()),
sdk.NewAttribute("duration", strconv.FormatInt(jailDuration, 10)),
),
})
return nil
}

// remove a reporter from jail
func (k Keeper) unjailReporter(ctx context.Context, reporterAddr sdk.AccAddress, reporter types.OracleReporter) error {
if !reporter.Jailed {
return types.ErrReporterNotJailed.Wrapf("cannot unjail already unjailed reporter, %v", reporter)
}

sdkctx := sdk.UnwrapSDKContext(ctx)
if sdkctx.BlockTime().Before(reporter.JailedUntil) {
return types.ErrReporterJailed.Wrapf("cannot unjail reporter before jail time is up, %v", reporter)
}

reporter.Jailed = false

return k.Reporters.Set(ctx, reporterAddr, reporter)
}
17 changes: 17 additions & 0 deletions x/reporter/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,20 @@ func (k msgServer) WithdrawReporterCommission(ctx context.Context, msg *types.Ms

return &types.MsgWithdrawReporterCommissionResponse{Amount: amount}, nil
}

func (k msgServer) UnjailReporter(goCtx context.Context, msg *types.MsgUnjailReporter) (*types.MsgUnjailReporterResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

reporterAddr := sdk.MustAccAddressFromBech32(msg.ReporterAddress)

reporter, err := k.Reporters.Get(ctx, reporterAddr)
if err != nil {
return nil, err
}

if err := k.Keeper.unjailReporter(ctx, reporterAddr, reporter); err != nil {
return nil, err
}

return &types.MsgUnjailReporterResponse{}, nil
}
6 changes: 6 additions & 0 deletions x/reporter/module/autocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
Short: "Execute the UndelegateReporter RPC method",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "token_origins"}},
},
{
RpcMethod: "UnjailReporter",
Use: "unjail-reporter [reporter-addr]",
Short: "Execute the UnjailReporter RPC method",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "reporter_address"}},
},
// this line is used by ignite scaffolding # autocli/tx
},
},
Expand Down
2 changes: 2 additions & 0 deletions x/reporter/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ var (
ErrEmptyDelegationDistInfo = sdkerrors.Register(ModuleName, 1109, "no delegation distribution info")
ErrNoReporterCommission = sdkerrors.Register(ModuleName, 1110, "no reporter commission to withdraw")
ErrReporterDoesNotExist = sdkerrors.Register(ModuleName, 1111, "reporter does not exist")
ErrReporterJailed = sdkerrors.Register(ModuleName, 1112, "reporter jailed")
ErrReporterNotJailed = sdkerrors.Register(ModuleName, 1113, "reporter not jailed")
)
Loading

0 comments on commit c9752ab

Please sign in to comment.