Skip to content

Commit

Permalink
update endblocker logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rbajollari committed Aug 10, 2023
1 parent d8856ef commit bf814b6
Show file tree
Hide file tree
Showing 9 changed files with 399 additions and 60 deletions.
2 changes: 1 addition & 1 deletion proto/ojo/oracle/v1/oracle.proto
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ message ValidatorRewardSet {
message ParamUpdatePlan {
option (gogoproto.equal) = true;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = true;
option (gogoproto.goproto_stringer) = false;

string title = 1;
string description = 2;
Expand Down
11 changes: 11 additions & 0 deletions proto/ojo/oracle/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,14 @@ message MsgGovUpdateParams {

// MsgGovUpdateParamsResponse defines the Msg/GovUpdateParams response type.
message MsgGovUpdateParamsResponse {}

// MsgGovCancelUpdateParams defines the Msg/GovCancelUpdateParams request type.
message MsgGovCancelUpdateParams {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MsgGovCancelUpdateParamsResponse defines the Msg/GovCancelUpdateParamsResponse response type.
message MsgGovCancelUpdateParamsResponse {}
5 changes: 3 additions & 2 deletions x/oracle/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import (
func EndBlocker(ctx sdk.Context, k keeper.Keeper) error {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)

// Check for Oracle parameter update plans and execute it if one is
// found and the update plan height is set to the current block.
plan, found := k.GetParamUpdatePlan(ctx)

if found {
if found && plan.ShouldExecute(ctx) {
err := k.ExecuteParamUpdatePlan(ctx, plan)
if err != nil {
ctx.Logger().Error("Error executing Oracle param update plan", "plan title", plan.Title, "err", err)
Expand Down
4 changes: 4 additions & 0 deletions x/oracle/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,10 @@ func (s *IntegrationTestSuite) TestEndblockerHistoracle() {
}
}

func (s *IntegrationTestSuite) TestUpdateOracleParams(

Check failure on line 500 in x/oracle/abci_test.go

View workflow job for this annotation

GitHub Actions / test-unit-cover

missing function body

)

func TestOracleTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}
4 changes: 2 additions & 2 deletions x/oracle/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,15 @@ func (k Keeper) ScheduleParamUpdatePlan(ctx sdk.Context, plan types.ParamUpdateP
store := ctx.KVStore(k.storeKey)

bz := k.cdc.MustMarshal(&plan)
store.Set(types.KeyParamUpdatePlan(uint64(plan.Height)), bz)
store.Set(types.KeyParamUpdatePlan(), bz)

return nil
}

//
func (k Keeper) GetParamUpdatePlan(ctx sdk.Context) (plan types.ParamUpdatePlan, havePlan bool) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.KeyParamUpdatePlan(uint64(ctx.BlockHeight())))
bz := store.Get(types.KeyParamUpdatePlan())
if bz == nil {
return plan, false
}
Expand Down
6 changes: 3 additions & 3 deletions x/oracle/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ func KeyValidatorRewardSet() (key []byte) {
return util.ConcatBytes(0, KeyPrefixValidatorRewardSet)
}

// KeyParamUpdatePlan - stored by *plan title*
func KeyParamUpdatePlan(blockNum uint64) (key []byte) {
return util.ConcatBytes(0, KeyPrefixValidatorRewardSet, util.UintWithNullPrefix(blockNum))
// KeyParamUpdatePlan
func KeyParamUpdatePlan() (key []byte) {
return util.ConcatBytes(0, KeyPrefixParamUpdatePlan)
}

// ParseDenomAndBlockFromKey returns the denom and block contained in the *key*
Expand Down
19 changes: 9 additions & 10 deletions x/oracle/types/oracle.pb.go

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

37 changes: 37 additions & 0 deletions x/oracle/types/plan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package types

import (
"fmt"

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

func (p ParamUpdatePlan) String() string {
due := p.DueAt()
return fmt.Sprintf(`Oracle Param Update Plan
Title: %s
%s
Description: %s.`, p.Title, due, p.Description)
}

// ValidateBasic does basic validation of a ParamUpdatePlan
func (p ParamUpdatePlan) ValidateBasic() error {
if len(p.Title) == 0 {
return ErrInvalidRequest.Wrap("name cannot be empty")
}
if p.Height <= 0 {
return ErrInvalidRequest.Wrap("height must be greater than 0")
}

return nil
}

// ShouldExecute returns true if the Plan is ready to execute given the current context
func (p ParamUpdatePlan) ShouldExecute(ctx sdk.Context) bool {
return p.Height == ctx.BlockHeight()
}

// DueAt is a string representation of when this plan is due to be executed
func (p ParamUpdatePlan) DueAt() string {
return fmt.Sprintf("height: %d", p.Height)
}
Loading

0 comments on commit bf814b6

Please sign in to comment.