mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 18:15:19 +00:00
36 lines
927 B
Go
36 lines
927 B
Go
package paychan
|
|
|
|
import (
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
func EndBlocker(ctx sdk.Context, k Keeper) sdk.Tags {
|
|
var err sdk.Error
|
|
var channelTags sdk.Tags
|
|
tags := sdk.EmptyTags()
|
|
|
|
// Iterate through submittedUpdatesQueue
|
|
// TODO optimise so it doesn't pull every channel update from DB every block
|
|
q := k.getSubmittedUpdatesQueue(ctx)
|
|
var sUpdate SubmittedUpdate
|
|
var found bool
|
|
|
|
for _, id := range q {
|
|
// close the channel if the update has reached its execution time.
|
|
// Using >= in case some are somehow missed.
|
|
sUpdate, found = k.getSubmittedUpdate(ctx, id)
|
|
if !found {
|
|
panic("can't find element in queue that should exist")
|
|
}
|
|
if ctx.BlockHeight() >= sUpdate.ExecutionTime {
|
|
k.removeFromSubmittedUpdatesQueue(ctx, sUpdate.ChannelID)
|
|
channelTags, err = k.closeChannel(ctx, sUpdate.Update)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
tags.AppendTags(channelTags)
|
|
}
|
|
}
|
|
return tags
|
|
}
|