Skip to content

Commit

Permalink
Added a logic to self-heal StateSynced and StakeUpdate events (#837)
Browse files Browse the repository at this point in the history
  • Loading branch information
begmaroman authored Jun 20, 2022
1 parent 81722d2 commit 2324802
Show file tree
Hide file tree
Showing 19 changed files with 816 additions and 535 deletions.
3 changes: 1 addition & 2 deletions bor/beginblocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import (
hmTypes "github.com/maticnetwork/heimdall/types"
)

func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k Keeper) {

func BeginBlocker(ctx sdk.Context, _ abci.RequestBeginBlock, k Keeper) {
if ctx.BlockHeight() == int64(helper.SpanOverrideBlockHeight) {
k.Logger(ctx).Info("overriding span BeginBlocker", "height", ctx.BlockHeight())
j, ok := rest.SPAN_OVERRIDES[helper.GenesisDoc.ChainID]
Expand Down
2 changes: 1 addition & 1 deletion bor/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func HandleMsgProposeSpan(ctx sdk.Context, msg types.MsgProposeSpan, k Keeper) s
spanDuration := k.GetParams(ctx).SpanDuration
if spanDuration != (msg.EndBlock - msg.StartBlock + 1) {
k.Logger(ctx).Error("Span duration of proposed span is wrong",
"proposedSpanDuration", (msg.EndBlock - msg.StartBlock + 1),
"proposedSpanDuration", msg.EndBlock-msg.StartBlock+1,
"paramsSpanDuration", spanDuration,
)
return common.ErrInvalidSpanDuration(k.Codespace()).Result()
Expand Down
18 changes: 8 additions & 10 deletions bor/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/maticnetwork/bor/common"
"github.com/maticnetwork/heimdall/bor/types"
chainmanager "github.com/maticnetwork/heimdall/chainmanager"
"github.com/maticnetwork/heimdall/chainmanager"
"github.com/maticnetwork/heimdall/helper"
"github.com/maticnetwork/heimdall/params/subspace"
"github.com/maticnetwork/heimdall/staking"
Expand Down Expand Up @@ -45,7 +45,7 @@ type Keeper struct {
chainKeeper chainmanager.Keeper
}

// NewKeeper create new keeper
// NewKeeper is the constructor of Keeper
func NewKeeper(
cdc *codec.Codec,
storeKey sdk.StoreKey,
Expand All @@ -55,8 +55,7 @@ func NewKeeper(
stakingKeeper staking.Keeper,
caller helper.ContractCaller,
) Keeper {
// create keeper
keeper := Keeper{
return Keeper{
cdc: cdc,
storeKey: storeKey,
paramSpace: paramSpace.WithKeyTable(types.ParamKeyTable()),
Expand All @@ -65,7 +64,6 @@ func NewKeeper(
sk: stakingKeeper,
contractCaller: caller,
}
return keeper
}

// Codespace returns the codespace
Expand Down Expand Up @@ -152,9 +150,6 @@ func (k *Keeper) GetAllSpans(ctx sdk.Context) (spans []*hmTypes.Span) {
func (k *Keeper) GetSpanList(ctx sdk.Context, page uint64, limit uint64) ([]hmTypes.Span, error) {
store := ctx.KVStore(k.storeKey)

// create spans
var spans []hmTypes.Span

// have max limit
if limit > 20 {
limit = 20
Expand All @@ -164,6 +159,7 @@ func (k *Keeper) GetSpanList(ctx sdk.Context, page uint64, limit uint64) ([]hmTy
iterator := hmTypes.KVStorePrefixIteratorPaginated(store, SpanPrefixKey, uint(page), uint(limit))

// loop through validators to get valid validators
var spans []hmTypes.Span
for ; iterator.Valid(); iterator.Next() {
var span hmTypes.Span
if err := k.cdc.UnmarshalBinaryBare(iterator.Value(), &span); err == nil {
Expand Down Expand Up @@ -251,7 +247,9 @@ func (k *Keeper) SelectNextProducers(ctx sdk.Context, seed common.Hash) (vals []
val.VotingPower = int64(value)
vals = append(vals, val)
}
} // sort by address
}

// sort by address
vals = hmTypes.SortValidatorByAddress(vals)

return vals, nil
Expand Down Expand Up @@ -324,7 +322,7 @@ func (k *Keeper) GetParams(ctx sdk.Context) (params types.Params) {
// Utils
//

// IterateSpansAndApplyFn interate spans and apply the given function.
// IterateSpansAndApplyFn iterates spans and apply the given function.
func (k *Keeper) IterateSpansAndApplyFn(ctx sdk.Context, f func(span hmTypes.Span) error) {
store := ctx.KVStore(k.storeKey)

Expand Down
2 changes: 1 addition & 1 deletion bridge/setu/listener/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (bl *BaseListener) StartHeaderProcess(ctx context.Context) {
}
}

// startPolling starts polling
// StartPolling starts polling
func (bl *BaseListener) StartPolling(ctx context.Context, pollInterval time.Duration) {
// How often to fire the passed in function in second
interval := pollInterval
Expand Down
Loading

0 comments on commit 2324802

Please sign in to comment.