Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(inactivity): Rename inactive flag to sluggish, add queries, events, and metrics #714

Merged
merged 18 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions proto/babylon/btcstaking/v1/btcstaking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ message FinalityProvider {
// the finality provider is slashed.
// if it's 0 then the finality provider is not slashed
uint64 slashed_btc_height = 7;
// inactive defines whether the finality provider is detected inactive
bool inactive = 8;
// sluggish defines whether the finality provider is detected sluggish
bool sluggish = 8;
}

// FinalityProviderWithMeta wraps the FinalityProvider with metadata.
Expand All @@ -54,8 +54,8 @@ message FinalityProviderWithMeta {
// the finality provider is slashed.
// if it's 0 then the finality provider is not slashed
uint64 slashed_btc_height = 5;
// inactive defines whether the finality provider is detected inactive
bool inactive = 6;
// sluggish defines whether the finality provider is detected sluggish
bool sluggish = 6;
}

// BTCDelegation defines a BTC delegation
Expand Down
4 changes: 2 additions & 2 deletions proto/babylon/btcstaking/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,6 @@ message FinalityProviderResponse {
uint64 height = 8;
// voting_power is the voting power of this finality provider at the given height
uint64 voting_power = 9;
// inactive defines whether the finality provider is detected inactive
bool inactive = 10;
// sluggish defines whether the finality provider is detected sluggish
bool sluggish = 10;
}
14 changes: 14 additions & 0 deletions proto/babylon/finality/v1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,17 @@ message EventSlashedFinalityProvider {
// evidence is the evidence that the finality provider double signs
Evidence evidence = 1;
}

// EventSluggishFinalityProviderDetected is the event emitted when a finality provider is
// detected as sluggish
message EventSluggishFinalityProviderDetected {
// public_key is the BTC public key of the finality provider
string public_key = 1;
}

// EventSluggishFinalityProviderReverted is the event emitted when a sluggish finality
// provider is no longer considered sluggish
message EventSluggishFinalityProviderReverted {
// public_key is the BTC public key of the finality provider
string public_key = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also add the bbn address of the fp to the events

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I woudn't mind but what would be the use case?

}
2 changes: 1 addition & 1 deletion proto/babylon/finality/v1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ message Params {
// vote before being judged as missing their voting turn on the given block
int64 finality_sig_timeout = 2;
// min_signed_per_window defines the minimum number of blocks that a finality provider is required to sign
// within the sliding window to avoid being detected as inactive
// within the sliding window to avoid being detected as sluggish
bytes min_signed_per_window = 3 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
Expand Down
39 changes: 39 additions & 0 deletions proto/babylon/finality/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ service Query {
rpc ListEvidences(QueryListEvidencesRequest) returns (QueryListEvidencesResponse) {
option (google.api.http).get = "/babylon/finality/v1/evidences";
}

// SigningInfo queries the signing info of given finality provider BTC public key
rpc SigningInfo(QuerySigningInfoRequest) returns (QuerySigningInfoResponse) {
option (google.api.http).get = "/babylon/finality/v1/signing_infos/{fp_btc_pk_hex}";
}

// SigningInfos queries the signing info of all the active finality providers
rpc SigningInfos(QuerySigningInfosRequest) returns (QuerySigningInfosResponse) {
option (google.api.http).get = "/babylon/finality/v1/signing_infos";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
Expand Down Expand Up @@ -208,3 +218,32 @@ message QueryListEvidencesResponse {
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QuerySigningInfoRequest is the request type for the Query/SigningInfo RPC
// method
message QuerySigningInfoRequest {
// fp_btc_pk_hex is the hex str of Bitcoin secp256k1 PK
// (in BIP340 format) of the finality provider
string fp_btc_pk_hex = 1;
}

// QuerySigningInfoResponse is the response type for the Query/SigningInfo RPC
// method
message QuerySigningInfoResponse {
// fp_signing_info is the signing info of requested finality provider BTC public key
FinalityProviderSigningInfo fp_signing_info = 1 [(gogoproto.nullable) = false];
}

// QuerySigningInfosRequest is the request type for the Query/SigningInfos RPC
// method
message QuerySigningInfosRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

// QuerySigningInfosResponse is the response type for the Query/SigningInfos RPC
// method
message QuerySigningInfosResponse {
// info is the signing info of all finality providers with signing info
repeated FinalityProviderSigningInfo fp_signing_infos = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
10 changes: 5 additions & 5 deletions x/btcstaking/keeper/finality_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ func (k Keeper) SlashFinalityProvider(ctx context.Context, fpBTCPK []byte) error
return nil
}

// RevertInactiveFinalityProvider sets the Inactive flag of the given finality provider
// RevertSluggishFinalityProvider sets the Sluggish flag of the given finality provider
// to false
func (k Keeper) RevertInactiveFinalityProvider(ctx context.Context, fpBTCPK []byte) error {
func (k Keeper) RevertSluggishFinalityProvider(ctx context.Context, fpBTCPK []byte) error {
// ensure finality provider exists
fp, err := k.GetFinalityProvider(ctx, fpBTCPK)
if err != nil {
return err
}

// ignore the finality provider is already slashed
// or detected as inactive
if fp.IsSlashed() || fp.IsInactive() {
// or detected as sluggish
if fp.IsSlashed() || fp.IsSluggish() {
return nil
}

fp.Inactive = false
fp.Sluggish = false
k.SetFinalityProvider(ctx, fp)

return nil
Expand Down
10 changes: 5 additions & 5 deletions x/btcstaking/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ func (k Keeper) Hooks() Hooks {
return Hooks{k}
}

// AfterInactiveFinalityProviderDetected updates the status of the given finality provider to `inactive`
func (h Hooks) AfterInactiveFinalityProviderDetected(ctx context.Context, fpPk *bbntypes.BIP340PubKey) error {
// AfterSluggishFinalityProviderDetected updates the status of the given finality provider to `sluggish`
func (h Hooks) AfterSluggishFinalityProviderDetected(ctx context.Context, fpPk *bbntypes.BIP340PubKey) error {
fp, err := h.k.GetFinalityProvider(ctx, fpPk.MustMarshal())
if err != nil {
return err
}

if fp.IsInactive() {
return fmt.Errorf("the finality provider %s is already detected as inactive", fpPk.MarshalHex())
if fp.IsSluggish() {
return fmt.Errorf("the finality provider %s is already detected as sluggish", fpPk.MarshalHex())
}

fp.Inactive = true
fp.Sluggish = true

h.k.SetFinalityProvider(ctx, fp)

Expand Down
7 changes: 4 additions & 3 deletions x/btcstaking/types/btcstaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ import (

"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"

asig "github.com/babylonchain/babylon/crypto/schnorr-adaptor-signature"
bbn "github.com/babylonchain/babylon/types"
btcctypes "github.com/babylonchain/babylon/x/btccheckpoint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func (fp *FinalityProvider) IsSlashed() bool {
return fp.SlashedBabylonHeight > 0
}

func (fp *FinalityProvider) IsInactive() bool {
return fp.Inactive
func (fp *FinalityProvider) IsSluggish() bool {
return fp.Sluggish
}

func (fp *FinalityProvider) ValidateBasic() error {
Expand Down
Loading