-
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
feat(rfq-relayer): support FastBridgeV2 with arbitrary calls [SLT-320] #3258
base: master
Are you sure you want to change the base?
Changes from all commits
36a42bd
919a0a9
867d5d9
c93c403
9575246
7872f2a
ad7dd4c
5ca5ad1
e8355c3
eb2bbb8
c50042a
9fb4461
156e333
2b77b4a
271f59d
2317a58
c6a1fdc
e5e8646
ab63286
93d9b7d
e34a08b
1056ef1
1301270
1081e0a
467d5c7
f456bb7
de621a7
e3c1604
bff4f72
4ed813b
5b6ec12
d3dbeb0
0bc22c5
117ce59
6dee3d1
f57312b
4b8dc68
b24d31d
91a6b8f
b6a4609
05ab3dd
94ee810
337782c
8759318
f44c7ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,82 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
package fastbridgev2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"bytes" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"strings" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"github.com/ethereum/go-ethereum/accounts/abi" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"github.com/ethereum/go-ethereum/common" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// TODO: consider not exporting to avoid accidental mutation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
var ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// BridgeRequestedTopic is the event topic for a bridge request. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BridgeRequestedTopic common.Hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// BridgeRelayedTopic is the topic emitted by a bridge relay. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BridgeRelayedTopic common.Hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// BridgeProofProvidedTopic is the topic emitted by a bridge relay. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BridgeProofProvidedTopic common.Hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// BridgeDepositClaimedTopic is the topic emitted by a bridge relay. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BridgeDepositClaimedTopic common.Hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// BridgeProofDisputedTopic is the topic emitted by a bridge dispute. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BridgeProofDisputedTopic common.Hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// static checks to make sure topics actually exist. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func init() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
var err error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
parsedABI, err := abi.JSON(strings.NewReader(FastBridgeV2MetaData.ABI)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
panic(err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BridgeRequestedTopic = parsedABI.Events["BridgeRequested"].ID | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BridgeRelayedTopic = parsedABI.Events["BridgeRelayed"].ID | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BridgeProofProvidedTopic = parsedABI.Events["BridgeProofProvided"].ID | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BridgeDepositClaimedTopic = parsedABI.Events["BridgeDepositClaimed"].ID | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BridgeProofDisputedTopic = parsedABI.Events["BridgeProofDisputed"].ID | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_, err = parsedABI.EventByID(BridgeRequestedTopic) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
panic(err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_, err = parsedABI.EventByID(BridgeRelayedTopic) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
panic(err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_, err = parsedABI.EventByID(BridgeProofProvidedTopic) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
panic(err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_, err = parsedABI.EventByID(BridgeProofDisputedTopic) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
panic(err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+54
to
+59
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. Missing validation for The Apply this diff to include the missing validation: _, err = parsedABI.EventByID(BridgeProofProvidedTopic)
if err != nil {
panic(err)
}
+ // Validate BridgeDepositClaimedTopic
+ _, err = parsedABI.EventByID(BridgeDepositClaimedTopic)
+ if err != nil {
+ panic(err)
+ }
_, err = parsedABI.EventByID(BridgeProofDisputedTopic) 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// topicMap maps events to topics. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// this is returned as a function to assert immutability. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func topicMap() map[EventType]common.Hash { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return map[EventType]common.Hash{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BridgeRequestedEvent: BridgeRequestedTopic, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BridgeRelayedEvent: BridgeRelayedTopic, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BridgeProofProvidedEvent: BridgeProofProvidedTopic, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BridgeDepositClaimedEvent: BridgeDepositClaimedTopic, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BridgeDisputeEvent: BridgeProofDisputedTopic, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+61
to
+71
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. 🛠️ Refactor suggestion Ensure immutability of the map returned by The Consider returning a reference to a pre-defined, immutable map:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// eventTypeFromTopic gets the event type from the topic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// returns nil if the topic is not found. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func eventTypeFromTopic(ogTopic common.Hash) *EventType { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for eventType, topic := range topicMap() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if bytes.Equal(ogTopic.Bytes(), topic.Bytes()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return &eventType | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+75
to
+82
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. 🛠️ Refactor suggestion Optimize Currently, Apply this diff to use a cached topic map: +var cachedTopicMap = topicMap()
func eventTypeFromTopic(ogTopic common.Hash) *EventType {
- for eventType, topic := range topicMap() {
+ for eventType, topic := range cachedTopicMap {
if bytes.Equal(ogTopic.Bytes(), topic.Bytes()) {
return &eventType
}
}
return nil
} 📝 Committable suggestion
Suggested change
Comment on lines
+75
to
+82
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. 🛠️ Refactor suggestion Optimize Currently, Implement a reverse mapping from
Avoid returning the address of the loop variable In the Apply this diff to return the value instead of a pointer: -func eventTypeFromTopic(ogTopic common.Hash) *EventType {
+func eventTypeFromTopic(ogTopic common.Hash) EventType {
for eventType, topic := range topicMap() {
if bytes.Equal(ogTopic.Bytes(), topic.Bytes()) {
- return &eventType
+ return eventType
}
}
- return nil
+ return UnknownEventType
} Ensure that 📝 Committable suggestion
Suggested change
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package fastbridgev2 | ||
|
||
// GetAllBridgeStatuses exports all bridge statuses for testing. | ||
func GetAllBridgeStatuses() []BridgeStatus { | ||
return allBridgeStatuses | ||
} |
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.
Handle missing events to prevent potential runtime panics
When accessing events in
parsedABI.Events
, if an event key like"BridgeRequested"
does not exist, it will cause a runtime panic due to a nil pointer dereference. It's safer to check if the event exists before accessing itsID
.Apply this change to handle missing events gracefully:
This ensures that if an event is missing, a clear panic message is provided, aiding in debugging.