-
Notifications
You must be signed in to change notification settings - Fork 41
/
abci.go
31 lines (27 loc) · 1.34 KB
/
abci.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package oracle
import (
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/bandprotocol/chain/x/oracle/types"
)
// handleBeginBlock re-calculates and saves the rolling seed value based on block hashes.
func handleBeginBlock(ctx sdk.Context, k Keeper, req abci.RequestBeginBlock) {
// Update rolling seed used for pseudorandom oracle provider selection.
rollingSeed := k.GetRollingSeed(ctx)
k.SetRollingSeed(ctx, append(rollingSeed[1:], req.GetHash()[0]))
// Reward a portion of block rewards (inflation + tx fee) to active oracle validators.
k.AllocateTokens(ctx, req.LastCommitInfo.GetVotes())
}
// handleEndBlock cleans up the state during end block. See comment in the implementation!
func handleEndBlock(ctx sdk.Context, k Keeper) {
// Loops through all requests in the resolvable list to resolve all of them!
for _, reqID := range k.GetPendingResolveList(ctx) {
k.ResolveRequest(ctx, reqID)
}
// Once all the requests are resolved, we can clear the list.
k.SetPendingResolveList(ctx, []types.RequestID{})
// Lastly, we clean up data requests that are supposed to be expired.
k.ProcessExpiredRequests(ctx)
// NOTE: We can remove old requests from state to optimize space, using `k.DeleteRequest`
// and `k.DeleteReports`. We don't do that now as it is premature optimization at this state.
}