-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Start epoch scheduler * Better error handling in scheduler * Register scheduled rebalance task for max limit contracts * Check contract exists before accepting any rebalance sudo callback * Better scheduler tests * Cover repeat setting
- Loading branch information
Showing
20 changed files
with
744 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ linters: | |
disable-all: true | ||
enable: | ||
- bodyclose | ||
- depguard | ||
- dogsled | ||
- errcheck | ||
- exportloopref | ||
|
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,38 @@ | ||
package meshsecurity | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/keeper" | ||
"github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/telemetry" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// EndBlocker is called after every block | ||
func EndBlocker(ctx sdk.Context, k *keeper.Keeper) { | ||
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) | ||
epochLength := k.GetRebalanceEpochLength(ctx) | ||
results, err := k.ExecScheduledTasks(ctx, types.SchedulerTaskRebalance, epochLength, func(ctx sdk.Context, addr sdk.AccAddress) error { | ||
return k.Rebalance(ctx, addr) | ||
}) | ||
if err != nil { | ||
panic(err) // todo: log or fail? | ||
} | ||
for _, r := range results { | ||
logger := keeper.ModuleLogger(ctx). | ||
With("contract", r.Contract.String()) | ||
switch { | ||
case r.ExecErr != nil: | ||
logger.Error("failed to execute scheduled task") | ||
case r.RescheduleErr != nil: // todo: log or fail? | ||
panic(fmt.Sprintf("failed to reschedule task for contract %s", r.Contract.String())) | ||
case r.DeleteTaskErr != nil: | ||
logger.Error("failed to delete scheduled task after completion") | ||
default: | ||
logger.Info("scheduled task executed successfully", "gas_used", r.GasUsed, "gas_limit", r.GasLimit) | ||
} | ||
} | ||
} |
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,5 @@ | ||
package contract | ||
|
||
type SudoMsg struct { | ||
Rebalance *struct{} `json:"rebalance"` | ||
} |
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,28 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/types" | ||
) | ||
|
||
var _ types.WasmKeeper = &MockWasmKeeper{} | ||
|
||
type MockWasmKeeper struct { | ||
SudoFn func(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error) | ||
HasContractInfoFn func(ctx sdk.Context, contractAddress sdk.AccAddress) bool | ||
} | ||
|
||
func (m MockWasmKeeper) Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error) { | ||
if m.SudoFn == nil { | ||
panic("not expected to be called") | ||
} | ||
return m.SudoFn(ctx, contractAddress, msg) | ||
} | ||
|
||
func (m MockWasmKeeper) HasContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress) bool { | ||
if m.HasContractInfoFn == nil { | ||
panic("not expected to be called") | ||
} | ||
return m.HasContractInfoFn(ctx, contractAddress) | ||
} |
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
Oops, something went wrong.