-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add downtime detector module (#3688)
* WIP * Switch to enum * Remove params query * Add query * Add wiring, add import/export test * Start begin block test * Finish keeper tests * Add CLI * Wire downtime detector CLI + queries * more module wiring * add types test * Fix state alteration test * Fix superfluid test * Add stargate whitelist support * Apply code comment * Rename folder * Add requested godoc * Update x/downtime-detector/genesis.go Co-authored-by: Adam Tucker <[email protected]> * Apply adam suggestion for having a `-` * move genesis test to own file Co-authored-by: Adam Tucker <[email protected]>
- Loading branch information
1 parent
a942009
commit 68bae6b
Showing
33 changed files
with
984 additions
and
781 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
proto/osmosis/downtime-detector/v1beta1/downtime_duration.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
syntax = "proto3"; | ||
package osmosis.downtimedetector.v1beta1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "google/protobuf/any.proto"; | ||
import "cosmos_proto/cosmos.proto"; | ||
import "google/protobuf/duration.proto"; | ||
import "google/protobuf/timestamp.proto"; | ||
|
||
option go_package = "github.com/osmosis-labs/osmosis/v13/x/downtime-detector/types"; | ||
|
||
enum Downtime { | ||
DURATION_30S = 0; | ||
DURATION_1M = 1; | ||
DURATION_2M = 2; | ||
DURATION_3M = 3; | ||
DURATION_4M = 4; | ||
DURATION_5M = 5; | ||
DURATION_10M = 6; | ||
DURATION_20M = 7; | ||
DURATION_30M = 8; | ||
DURATION_40M = 9; | ||
DURATION_50M = 10; | ||
DURATION_1H = 11; | ||
DURATION_1_5H = 12; | ||
DURATION_2H = 13; | ||
DURATION_2_5H = 14; | ||
DURATION_3H = 15; | ||
DURATION_4H = 16; | ||
DURATION_5H = 17; | ||
DURATION_6H = 18; | ||
DURATION_9H = 19; | ||
DURATION_12H = 20; | ||
DURATION_18H = 21; | ||
DURATION_24H = 22; | ||
DURATION_36H = 23; | ||
DURATION_48H = 24; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
keeper: | ||
path: "github.com/osmosis-labs/osmosis/v13/x/downtime-detector" | ||
struct: "Keeper" | ||
client_path: "github.com/osmosis-labs/osmosis/v13/x/downtime-detector/client" | ||
queries: | ||
RecoveredSinceDowntimeOfLength: | ||
proto_wrapper: | ||
query_func: "k.RecoveredSinceDowntimeOfLength" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package downtimedetector | ||
|
||
import ( | ||
"time" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/osmosis-labs/osmosis/v13/x/downtime-detector/types" | ||
) | ||
|
||
func (k *Keeper) BeginBlock(ctx sdk.Context) { | ||
curTime := ctx.BlockTime() | ||
lastBlockTime, err := k.GetLastBlockTime(ctx) | ||
if err != nil { | ||
ctx.Logger().Error("Downtime-detector, could not get last block time, did initialization happen correctly. " + err.Error()) | ||
} | ||
downtime := curTime.Sub(lastBlockTime) | ||
k.saveDowntimeUpdates(ctx, downtime) | ||
k.StoreLastBlockTime(ctx, curTime) | ||
} | ||
|
||
// saveDowntimeUpdates saves the current block time as the | ||
// last time the chain was down for all downtime lengths that are LTE the provided downtime. | ||
func (k *Keeper) saveDowntimeUpdates(ctx sdk.Context, downtime time.Duration) { | ||
// minimum stored downtime is 30S, so if downtime is less than that, don't update anything. | ||
if downtime < 30*time.Second { | ||
return | ||
} | ||
types.DowntimeToDuration.Ascend(0, func(downType types.Downtime, duration time.Duration) bool { | ||
// if downtime < duration of this entry, stop iterating further, don't update this entry. | ||
if downtime < duration { | ||
return false | ||
} | ||
k.StoreLastDowntimeOfLength(ctx, downType, ctx.BlockTime()) | ||
return true | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cli | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
|
||
"github.com/osmosis-labs/osmosis/v13/osmoutils/osmocli" | ||
"github.com/osmosis-labs/osmosis/v13/x/downtime-detector/client/queryproto" | ||
"github.com/osmosis-labs/osmosis/v13/x/downtime-detector/types" | ||
) | ||
|
||
func GetQueryCmd() *cobra.Command { | ||
cmd := osmocli.QueryIndexCmd(types.ModuleName) | ||
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, RecoveredSinceQueryCmd) | ||
|
||
return cmd | ||
} | ||
|
||
func RecoveredSinceQueryCmd() (*osmocli.QueryDescriptor, *queryproto.RecoveredSinceDowntimeOfLengthRequest) { | ||
return &osmocli.QueryDescriptor{ | ||
Use: "recovered-since downtime-duration recovery-duration", | ||
Short: "Queries if it has been at least <recovery-duration> since the chain was down for <downtime-duration>", | ||
Long: `{{.Short}} | ||
downtime-duration is a duration, but is restricted to a smaller set. Heres a few from the set: 30s, 1m, 5m, 10m, 30m, 1h, 3 h, 6h, 12h, 24h, 36h, 48h] | ||
{{.ExampleHeader}} | ||
{{.CommandPrefix}} recovered-since 24h 30m`, | ||
CustomFieldParsers: map[string]osmocli.CustomFieldParserFn{"Downtime": parseDowntimeDuration}, | ||
}, &queryproto.RecoveredSinceDowntimeOfLengthRequest{} | ||
} | ||
|
||
func parseDowntimeDuration(arg string, _ *pflag.FlagSet) (any, osmocli.FieldReadLocation, error) { | ||
dur, err := time.ParseDuration(arg) | ||
if err != nil { | ||
return nil, osmocli.UsedArg, err | ||
} | ||
downtime, err := types.DowntimeByDuration(dur) | ||
return downtime, osmocli.UsedArg, err | ||
} |
Oops, something went wrong.