Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update code from v2.5.3 (bump cometbft version, yoda handling request logic) #326

Merged
merged 7 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
- (chain) Update proof to support newly added module
- (chain) Migrate REST Endpoint to GRPC

## [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 @@ -170,6 +170,6 @@ require (
replace (
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
// use informal system fork of tendermint
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.53.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,8 @@ github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE
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