Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1626 from bandprotocol/no-begin-key
Browse files Browse the repository at this point in the history
chain: Remove request begin key
  • Loading branch information
sorawit authored May 18, 2020
2 parents e45edff + df6f463 commit b1673c3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
19 changes: 0 additions & 19 deletions chain/x/oracle/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,6 @@ func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
return params
}

// GetRequestBeginID TODO
func (k Keeper) GetRequestBeginID(ctx sdk.Context) types.RequestID {
var requestBeginID int64
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.RequestBeginStoreKey)
if bz == nil {
return types.RequestID(1)
}
k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &requestBeginID)
return types.RequestID(requestBeginID)
}

// SetRequestBeginID TODO
func (k Keeper) SetRequestBeginID(ctx sdk.Context, id types.RequestID) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshalBinaryLengthPrefixed(id)
store.Set(types.RequestBeginStoreKey, bz)
}

// GetRequestCount returns the current number of all requests ever exist.
func (k Keeper) GetRequestCount(ctx sdk.Context) int64 {
var requestNumber int64
Expand Down
8 changes: 5 additions & 3 deletions chain/x/oracle/keeper/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ func (k Keeper) ResolveRequest(
// ProcessExpiredRequests removes all expired data requests from the store, and sends oracle
// response packets for the ones that have never been resolved.
func (k Keeper) ProcessExpiredRequests(ctx sdk.Context) {
currentReqID := k.GetRequestBeginID(ctx)
iter := sdk.KVStorePrefixIterator(ctx.KVStore(k.storeKey), types.RequestStoreKeyPrefix)
if !iter.Valid() { // No request currently in the store.
return
}
currentReqID := types.RequestID(sdk.BigEndianToUint64(iter.Key()[1:])) // First available request ID
lastReqID := types.RequestID(k.GetRequestCount(ctx))
expirationBlockCount := int64(k.GetParam(ctx, types.KeyExpirationBlockCount))
// Loop through all data requests in chronological order. If a request reaches its
Expand Down Expand Up @@ -158,8 +162,6 @@ func (k Keeper) ProcessExpiredRequests(ctx sdk.Context) {
k.DeleteRawRequests(ctx, currentReqID)
k.DeleteReports(ctx, currentReqID)
}
// Lastly, we update RequestBeginID to reflect the most up-to-date ID for open requests.
k.SetRequestBeginID(ctx, currentReqID)
}

// AddPendingRequest adds the request to the pending list. DO NOT add same request more than once.
Expand Down
2 changes: 0 additions & 2 deletions chain/x/oracle/types/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ const (
var (
// GlobalStoreKeyPrefix is a prefix for global primitive state variable
GlobalStoreKeyPrefix = []byte{0x00}
// RequestBeginStoreKey TODO
RequestBeginStoreKey = append(GlobalStoreKeyPrefix, []byte("RequestBeginStoreKey")...)
// RequestsCountStoreKey is a key that help getting to current requests count state variable
RequestsCountStoreKey = append(GlobalStoreKeyPrefix, []byte("RequestsCount")...)
// PendingResolveListStoreKey is a key that help getting pending request
Expand Down

0 comments on commit b1673c3

Please sign in to comment.