Skip to content

Commit

Permalink
update from release/v2.5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerKSI committed Sep 12, 2023
2 parents 919124e + 294da33 commit 87f2473
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 119 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [v2.5.3](https://github.com/bandprotocol/chain/releases/tag/v2.5.3)

- (bump) Use cometbft v0.34.29
- (yoda) Get information of requests through endpoint instead of events

## [v2.5.2](https://github.com/bandprotocol/chain/releases/tag/v2.5.2)

- (bump) Use cosmos-sdk v0.45.16 / ibc-go v4.3.1 / cometbft v0.34.28
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,6 @@ require (
replace (
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
// use cometbft
github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.28
github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.29
google.golang.org/grpc => google.golang.org/grpc v1.33.2
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcju
github.com/coinbase/kryptology v1.8.0/go.mod h1:RYXOAPdzOGUe3qlSFkMGn58i3xUA8hmxYHksuq+8ciI=
github.com/coinbase/rosetta-sdk-go v0.7.9 h1:lqllBjMnazTjIqYrOGv8h8jxjg9+hJazIGZr9ZvoCcA=
github.com/coinbase/rosetta-sdk-go v0.7.9/go.mod h1:0/knutI7XGVqXmmH4OQD8OckFrbQ8yMsUZTG7FXCR2M=
github.com/cometbft/cometbft v0.34.28 h1:gwryf55P1SWMUP4nOXpRVI2D0yPoYEzN+IBqmRBOsDc=
github.com/cometbft/cometbft v0.34.28/go.mod h1:L9shMfbkZ8B+7JlwANEr+NZbBcn+hBpwdbeYvA5rLCw=
github.com/cometbft/cometbft v0.34.29 h1:Q4FqMevP9du2pOgryZJHpDV2eA6jg/kMYxBj9ZTY6VQ=
github.com/cometbft/cometbft v0.34.29/go.mod h1:L9shMfbkZ8B+7JlwANEr+NZbBcn+hBpwdbeYvA5rLCw=
github.com/cometbft/cometbft-db v0.7.0 h1:uBjbrBx4QzU0zOEnU8KxoDl18dMNgDh+zZRUE0ucsbo=
github.com/cometbft/cometbft-db v0.7.0/go.mod h1:yiKJIm2WKrt6x8Cyxtq9YTEcIMPcEe4XPxhgX59Fzf0=
github.com/confio/ics23/go v0.9.0 h1:cWs+wdbS2KRPZezoaaj+qBleXgUk5WOQFMP3CQFGTr4=
Expand Down
37 changes: 0 additions & 37 deletions yoda/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package yoda

import (
"fmt"
"strconv"

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

Expand All @@ -16,42 +15,6 @@ type rawRequest struct {
calldata string
}

// GetRawRequests returns the list of all raw data requests in the given log.
func GetRawRequests(log sdk.ABCIMessageLog) ([]rawRequest, error) {
dataSourceIDs := GetEventValues(log, types.EventTypeRawRequest, types.AttributeKeyDataSourceID)
dataSourceHashList := GetEventValues(log, types.EventTypeRawRequest, types.AttributeKeyDataSourceHash)
externalIDs := GetEventValues(log, types.EventTypeRawRequest, types.AttributeKeyExternalID)
calldataList := GetEventValues(log, types.EventTypeRawRequest, types.AttributeKeyCalldata)

if len(dataSourceIDs) != len(externalIDs) {
return nil, fmt.Errorf("Inconsistent data source count and external ID count")
}
if len(dataSourceIDs) != len(calldataList) {
return nil, fmt.Errorf("Inconsistent data source count and calldata count")
}

var reqs []rawRequest
for idx := range dataSourceIDs {
dataSourceID, err := strconv.Atoi(dataSourceIDs[idx])
if err != nil {
return nil, fmt.Errorf("Failed to parse data source id: %s", err.Error())
}

externalID, err := strconv.Atoi(externalIDs[idx])
if err != nil {
return nil, fmt.Errorf("Failed to parse external id: %s", err.Error())
}

reqs = append(reqs, rawRequest{
dataSourceID: types.DataSourceID(dataSourceID),
dataSourceHash: dataSourceHashList[idx],
externalID: types.ExternalID(externalID),
calldata: calldataList[idx],
})
}
return reqs, nil
}

// GetEventValues returns the list of all values in the given log with the given type and key.
func GetEventValues(log sdk.ABCIMessageLog, evType string, evKey string) (res []string) {
for _, ev := range log.Events {
Expand Down
101 changes: 23 additions & 78 deletions yoda/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,102 +45,47 @@ func handleTransaction(c *Context, l *Logger, tx abci.TxResult) {
}

func handleRequestLog(c *Context, l *Logger, log sdk.ABCIMessageLog) {
idStr, err := GetEventValue(log, types.EventTypeRequest, types.AttributeKeyID)
if err != nil {
l.Debug(":cold_sweat: Failed to parse request id with error: %s", err.Error())
return
}
idStrs := GetEventValues(log, types.EventTypeRequest, types.AttributeKeyID)

id, err := strconv.Atoi(idStr)
if err != nil {
l.Error(":cold_sweat: Failed to convert %s to integer with error: %s", c, idStr, err.Error())
return
for _, idStr := range idStrs {
id, err := strconv.Atoi(idStr)
if err != nil {
l.Error(":cold_sweat: Failed to convert %s to integer with error: %s", c, idStr, err.Error())
return
}

// If id is in pending requests list, then skip it.
if c.pendingRequests[types.RequestID(id)] {
l.Debug(":eyes: Request is in pending list, then skip")
return
}

go handleRequest(c, l, types.RequestID(id))
}
}

func handleRequest(c *Context, l *Logger, id types.RequestID) {
l = l.With("rid", id)

// If id is in pending requests list, then skip it.
if c.pendingRequests[types.RequestID(id)] {
l.Debug(":eyes: Request is in pending list, then skip")
req, err := GetRequest(c, l, id)
if err != nil {
l.Error(":skull: Failed to get request with error: %s", c, err.Error())
return
}

// Skip if not related to this validator
validators := GetEventValues(log, types.EventTypeRequest, types.AttributeKeyValidator)
hasMe := false
for _, validator := range validators {
if validator == c.validator.String() {
for _, val := range req.RequestedValidators {
if val == c.validator.String() {
hasMe = true
break
}
}

if !hasMe {
l.Debug(":next_track_button: Skip request not related to this validator")
return
}

l.Info(":delivery_truck: Processing incoming request event")

reqs, err := GetRawRequests(log)
if err != nil {
l.Error(":skull: Failed to parse raw requests with error: %s", c, err.Error())
}

keyIndex := c.nextKeyIndex()
key := c.keys[keyIndex]

reports, execVersions := handleRawRequests(c, l, types.RequestID(id), reqs, key)

rawAskCount := GetEventValues(log, types.EventTypeRequest, types.AttributeKeyAskCount)
if len(rawAskCount) != 1 {
panic("Fail to get ask count")
}
askCount := MustAtoi(rawAskCount[0])

rawMinCount := GetEventValues(log, types.EventTypeRequest, types.AttributeKeyMinCount)
if len(rawMinCount) != 1 {
panic("Fail to get min count")
}
minCount := MustAtoi(rawMinCount[0])

rawCallData := GetEventValues(log, types.EventTypeRequest, types.AttributeKeyCalldata)
if len(rawCallData) != 1 {
panic("Fail to get call data")
}
callData, err := hex.DecodeString(rawCallData[0])
if err != nil {
l.Error(":skull: Fail to parse call data: %s", c, err.Error())
}

var clientID string
rawClientID := GetEventValues(log, types.EventTypeRequest, types.AttributeKeyClientID)
if len(rawClientID) > 0 {
clientID = rawClientID[0]
}

c.pendingMsgs <- ReportMsgWithKey{
msg: types.NewMsgReportData(types.RequestID(id), reports, c.validator),
execVersion: execVersions,
keyIndex: keyIndex,
feeEstimationData: FeeEstimationData{
askCount: askCount,
minCount: minCount,
callData: callData,
rawRequests: reqs,
clientID: clientID,
},
}
}

func handlePendingRequest(c *Context, l *Logger, id types.RequestID) {
req, err := GetRequest(c, l, id)
if err != nil {
l.Error(":skull: Failed to get request with error: %s", c, err.Error())
return
}

l.Info(":delivery_truck: Processing pending request")
l.Info(":delivery_truck: Processing request")

keyIndex := c.nextKeyIndex()
key := c.keys[keyIndex]
Expand Down
2 changes: 1 addition & 1 deletion yoda/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func runImpl(c *Context, l *Logger) error {
l.Info(":mag: Found %d pending requests", len(pendingRequests.RequestIDs))
for _, id := range pendingRequests.RequestIDs {
c.pendingRequests[types.RequestID(id)] = true
go handlePendingRequest(c, l.With("rid", id), types.RequestID(id))
go handleRequest(c, l, types.RequestID(id))
}

for {
Expand Down

0 comments on commit 87f2473

Please sign in to comment.