-
Notifications
You must be signed in to change notification settings - Fork 589
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
Add downtime detector module #3688
Changes from 18 commits
9435538
a9650fa
e41b22b
ec0a381
b67d35a
1b27c50
88cf818
eea657b
8451bfa
b0de43c
015a4a5
9b269f8
06983ab
dc14569
178c210
e3b4b83
fe3410d
b6dd237
148e4bd
b1e0910
4fe65e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,9 @@ import ( | |
ica "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts" | ||
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types" | ||
|
||
downtimemodule "github.com/osmosis-labs/osmosis/v13/x/downtime-detector/module" | ||
downtimetypes "github.com/osmosis-labs/osmosis/v13/x/downtime-detector/types" | ||
|
||
ibc_hooks "github.com/osmosis-labs/osmosis/v13/x/ibc-hooks" | ||
|
||
"github.com/cosmos/cosmos-sdk/types/module" | ||
|
@@ -125,6 +128,7 @@ func appModules( | |
mint.NewAppModule(appCodec, *app.MintKeeper, app.AccountKeeper, app.BankKeeper), | ||
slashing.NewAppModule(appCodec, *app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper), | ||
distr.NewAppModule(appCodec, *app.DistrKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper), | ||
downtimemodule.NewAppModule(*app.DowntimeKeeper), | ||
staking.NewAppModule(appCodec, *app.StakingKeeper, app.AccountKeeper, app.BankKeeper), | ||
upgrade.NewAppModule(*app.UpgradeKeeper), | ||
wasm.NewAppModule(appCodec, app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), | ||
|
@@ -175,6 +179,7 @@ func orderBeginBlockers(allModuleNames []string) []string { | |
// IBChost came after staking, before superfluid. | ||
// TODO: Come back and delete this line after testing the base change. | ||
ord.Sequence(stakingtypes.ModuleName, ibchost.ModuleName, superfluidtypes.ModuleName) | ||
// We leave downtime-detector un-constrained. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do we mean by un-constrained here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can go anywhere in the sequence of begin block runs |
||
// every remaining module's begin block is a no-op. | ||
return ord.TotalOrdering() | ||
} | ||
|
@@ -204,6 +209,7 @@ func OrderInitGenesis(allModuleNames []string) []string { | |
authtypes.ModuleName, | ||
banktypes.ModuleName, | ||
distrtypes.ModuleName, | ||
downtimetypes.ModuleName, | ||
stakingtypes.ModuleName, | ||
slashingtypes.ModuleName, | ||
govtypes.ModuleName, | ||
|
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 { | ||
ValarDragon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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; | ||
} |
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" |
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we get a gdoc here? |
||
// 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 | ||
}) | ||
} |
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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was needed to fix "QueryStateAltered" tests, because Commit would start a new block, which would cause a state write from downtime detector.