-
Notifications
You must be signed in to change notification settings - Fork 30
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
add minimal rfq relayer query interface #2772
Changes from 6 commits
93a3c92
103156d
be8d074
6e4e5b2
4ba86bd
b3faae2
4e3a1b6
c1a5473
567455b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,11 +27,17 @@ | |
|
||
bot.signozClient = signoz.NewClientFromUser(handler, cfg.SignozBaseURL, cfg.SignozEmail, cfg.SignozPassword) | ||
|
||
server.AddCommand(bot.traceCommand()) | ||
bot.addCommands(bot.traceCommand(), bot.rfqLookupCommand()) | ||
|
||
return bot | ||
} | ||
|
||
func (b *Bot) addCommands(commands ...*slacker.CommandDefinition) { | ||
for _, command := range commands { | ||
b.server.AddCommand(command) | ||
} | ||
Comment on lines
+35
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure test coverage for the The ToolsGitHub Check: codecov/patch
|
||
} | ||
|
||
// Start starts the bot server. | ||
// nolint: wrapcheck | ||
func (b *Bot) Start(ctx context.Context) error { | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,12 +4,16 @@ | |||||
|
||||||
import ( | ||||||
"fmt" | ||||||
"github.com/ethereum/go-ethereum/common" | ||||||
"github.com/hako/durafmt" | ||||||
"github.com/slack-go/slack" | ||||||
"github.com/slack-io/slacker" | ||||||
"github.com/synapsecns/sanguine/contrib/opbot/signoz" | ||||||
"github.com/synapsecns/sanguine/ethergo/chaindata" | ||||||
"github.com/synapsecns/sanguine/services/rfq/relayer/relapi" | ||||||
"log" | ||||||
"strings" | ||||||
"sync" | ||||||
"time" | ||||||
) | ||||||
|
||||||
|
@@ -73,7 +77,7 @@ | |||||
return | ||||||
} | ||||||
|
||||||
slackBlocks := []slack.Block{slack.NewHeaderBlock(slack.NewTextBlockObject(slack.PlainTextType, "Traces", false, false))} | ||||||
slackBlocks := []slack.Block{slack.NewHeaderBlock(slack.NewTextBlockObject(slack.PlainTextType, fmt.Sprintf("Traces for %s", tags), false, false))} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure Test Coverage for the Modified The modified line 80, which formats the Slack message header, was not covered by tests according to the static analysis report. Consider adding unit tests to cover this functionality. ToolsGitHub Check: codecov/patch
|
||||||
|
||||||
for _, results := range traceList { | ||||||
trace := results.Data["traceID"].(string) | ||||||
|
@@ -109,3 +113,132 @@ | |||||
}, | ||||||
} | ||||||
} | ||||||
|
||||||
func (b *Bot) rfqLookupCommand() *slacker.CommandDefinition { | ||||||
return &slacker.CommandDefinition{ | ||||||
Command: "rfq <tx>", | ||||||
Description: "find a rfq transaction by either tx hash or txid on all configured relayers", | ||||||
Examples: []string{ | ||||||
"rfq 0x30f96b45ba689c809f7e936c140609eb31c99b182bef54fccf49778716a7e1ca", | ||||||
}, | ||||||
Handler: func(ctx *slacker.CommandContext) { | ||||||
type Status struct { | ||||||
relayer string | ||||||
*relapi.GetQuoteRequestStatusResponse | ||||||
} | ||||||
|
||||||
var statuses []Status | ||||||
var sliceMux sync.Mutex | ||||||
|
||||||
if len(b.cfg.RelayerURLS) == 0 { | ||||||
_, err := ctx.Response().Reply("no relayer urls configured") | ||||||
if err != nil { | ||||||
log.Println(err) | ||||||
} | ||||||
return | ||||||
trajan0x marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
tx := ctx.Request().Param("tx") | ||||||
|
||||||
var wg sync.WaitGroup | ||||||
// 2 routines per relayer, one for tx hashh one for tx id | ||||||
wg.Add(len(b.cfg.RelayerURLS) * 2) | ||||||
for _, relayer := range b.cfg.RelayerURLS { | ||||||
client := relapi.NewRelayerClient(b.handler, relayer) | ||||||
go func() { | ||||||
defer wg.Done() | ||||||
res, err := client.GetQuoteRequestStatusByTxHash(ctx.Context(), tx) | ||||||
if err != nil { | ||||||
log.Printf("error fetching quote request status by tx hash: %v\n", err) | ||||||
return | ||||||
} | ||||||
sliceMux.Lock() | ||||||
defer sliceMux.Unlock() | ||||||
statuses = append(statuses, Status{relayer: relayer, GetQuoteRequestStatusResponse: res}) | ||||||
Comment on lines
+155
to
+157
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using a more efficient way to handle concurrent writes to the statuses slice. |
||||||
}() | ||||||
|
||||||
go func() { | ||||||
defer wg.Done() | ||||||
res, err := client.GetQuoteRequestStatusByTxID(ctx.Context(), tx) | ||||||
if err != nil { | ||||||
log.Printf("error fetching quote request status by tx id: %v\n", err) | ||||||
return | ||||||
} | ||||||
sliceMux.Lock() | ||||||
defer sliceMux.Unlock() | ||||||
statuses = append(statuses, Status{relayer: relayer, GetQuoteRequestStatusResponse: res}) | ||||||
}() | ||||||
} | ||||||
wg.Wait() | ||||||
|
||||||
if len(statuses) == 0 { | ||||||
_, err := ctx.Response().Reply("no quote request found") | ||||||
if err != nil { | ||||||
log.Println(err) | ||||||
} | ||||||
return | ||||||
} | ||||||
|
||||||
var slackBlocks []slack.Block | ||||||
for _, status := range statuses { | ||||||
objects := []*slack.TextBlockObject{ | ||||||
{ | ||||||
Type: slack.MarkdownType, | ||||||
Text: fmt.Sprintf("*Relayer*: %s", status.relayer), | ||||||
}, | ||||||
{ | ||||||
Type: slack.MarkdownType, | ||||||
Text: fmt.Sprintf("*Status*: %s", status.Status), | ||||||
}, | ||||||
{ | ||||||
Type: slack.MarkdownType, | ||||||
Text: fmt.Sprintf("*TxID*: %s", toExplorerSlackLink(status.TxID)), | ||||||
}, | ||||||
{ | ||||||
Type: slack.MarkdownType, | ||||||
Text: fmt.Sprintf("*OriginTxHash*: %s", toTXSlackLink(status.OriginTxHash, status.OriginChainID)), | ||||||
}, | ||||||
} | ||||||
|
||||||
if status.DestTxHash == (common.Hash{}).String() { | ||||||
objects = append(objects, &slack.TextBlockObject{ | ||||||
Type: slack.MarkdownType, | ||||||
Text: "*DestTxHash*: not available", | ||||||
}) | ||||||
} else { | ||||||
objects = append(objects, &slack.TextBlockObject{ | ||||||
Type: slack.MarkdownType, | ||||||
Text: fmt.Sprintf("*DestTxHash*: %s", toTXSlackLink(status.DestTxHash, status.DestChainID)), | ||||||
}) | ||||||
} | ||||||
|
||||||
slackBlocks = append(slackBlocks, slack.NewSectionBlock(nil, objects, nil)) | ||||||
} | ||||||
|
||||||
_, err := ctx.Response().ReplyBlocks(slackBlocks) | ||||||
if err != nil { | ||||||
log.Println(err) | ||||||
} | ||||||
}} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove Unnecessary Trailing Newline. There is an unnecessary trailing newline at the end of the file. - Committable suggestion
Suggested change
ToolsGitHub Check: Lint (contrib/opbot)
|
||||||
} | ||||||
|
||||||
func toExplorerSlackLink(ogHash string) string { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo in function name: 'toExplorerSlackLink' should be 'toExplorerSlackLink'. |
||||||
rfqHash := strings.ToUpper(ogHash) | ||||||
// cut off 0x | ||||||
if len(rfqHash) > 0 { | ||||||
rfqHash = strings.ToUpper(rfqHash[2:]) | ||||||
} | ||||||
trajan0x marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
return fmt.Sprintf("<https://anon.to/?https://explorer.synapseprotocol.com/tx/%s|%s>", rfqHash, ogHash) | ||||||
} | ||||||
|
||||||
// produce a salck link if the explorer exists. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo in comment: 'salck' should be 'slack'. |
||||||
func toTXSlackLink(txHash string, chainID uint32) string { | ||||||
url := chaindata.ToTXLink(int64(chainID), txHash) | ||||||
if url == "" { | ||||||
return txHash | ||||||
} | ||||||
|
||||||
// TODO: remove when we can contorl unfurl | ||||||
return fmt.Sprintf("<https://anon.to/?%s|%s>", url, txHash) | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add test coverage for the new commands in
NewBot
.The addition of new commands in the
NewBot
method is crucial for the bot's functionality. However, these changes are not covered by tests, which is a significant oversight given the importance of this functionality.Tools
GitHub Check: codecov/patch