From 641bc23a76cda5f3ac6438dc94d6db16ffddd2e0 Mon Sep 17 00:00:00 2001 From: taobun Date: Fri, 7 Jul 2023 15:00:47 +0700 Subject: [PATCH 1/4] bumb cometbft to 0.34.29 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e2b1199f9..f967af877 100644 --- a/go.mod +++ b/go.mod @@ -151,6 +151,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 ) diff --git a/go.sum b/go.sum index 62e700d58..e499679d9 100644 --- a/go.sum +++ b/go.sum @@ -205,8 +205,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= From 3156c5dcb5f3d265fceb516167fc29fe9db020f2 Mon Sep 17 00:00:00 2001 From: Kitipong Sirirueangsakul Date: Tue, 12 Sep 2023 11:22:44 +0700 Subject: [PATCH 2/4] update yoda to rely on request_id instead of event --- yoda/event.go | 37 ------------------ yoda/handler.go | 101 +++++++++++------------------------------------- 2 files changed, 22 insertions(+), 116 deletions(-) diff --git a/yoda/event.go b/yoda/event.go index 41a306e6c..9c14b4bff 100644 --- a/yoda/event.go +++ b/yoda/event.go @@ -2,7 +2,6 @@ package yoda import ( "fmt" - "strconv" sdk "github.com/cosmos/cosmos-sdk/types" @@ -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 { diff --git a/yoda/handler.go b/yoda/handler.go index 30ee56d38..b12205bfc 100644 --- a/yoda/handler.go +++ b/yoda/handler.go @@ -45,101 +45,44 @@ 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 + } - 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") + return + } + + go handlePendingRequest(c, l, types.RequestID(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") +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 } - // 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") keyIndex := c.nextKeyIndex() From 20a04b6fb1efe1070973801b6e6251110fe42b1f Mon Sep 17 00:00:00 2001 From: Kitipong Sirirueangsakul Date: Tue, 12 Sep 2023 11:45:02 +0700 Subject: [PATCH 3/4] change function name, adjust log --- yoda/handler.go | 8 +++++--- yoda/run.go | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/yoda/handler.go b/yoda/handler.go index b12205bfc..ef6da75ec 100644 --- a/yoda/handler.go +++ b/yoda/handler.go @@ -60,11 +60,13 @@ func handleRequestLog(c *Context, l *Logger, log sdk.ABCIMessageLog) { return } - go handlePendingRequest(c, l, types.RequestID(id)) + go handleRequest(c, l, types.RequestID(id)) } } -func handlePendingRequest(c *Context, l *Logger, id types.RequestID) { +func handleRequest(c *Context, l *Logger, id types.RequestID) { + l = l.With("rid", id) + req, err := GetRequest(c, l, id) if err != nil { l.Error(":skull: Failed to get request with error: %s", c, err.Error()) @@ -83,7 +85,7 @@ func handlePendingRequest(c *Context, l *Logger, id types.RequestID) { return } - l.Info(":delivery_truck: Processing pending request") + l.Info(":delivery_truck: Processing request") keyIndex := c.nextKeyIndex() key := c.keys[keyIndex] diff --git a/yoda/run.go b/yoda/run.go index 40b5e445d..a40609688 100644 --- a/yoda/run.go +++ b/yoda/run.go @@ -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 { From fda08031b3583abde6878ae024bab0688cd434cc Mon Sep 17 00:00:00 2001 From: Kitipong Sirirueangsakul Date: Tue, 12 Sep 2023 13:37:34 +0700 Subject: [PATCH 4/4] add changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebfd9bfed..4db906cf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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