-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat(op-challenger): DisputeGameFactory Watcher #5842
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package challenger | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| "github.com/ethereum/go-ethereum" | ||
| "github.com/ethereum/go-ethereum/accounts/abi" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| ) | ||
|
|
||
| var ErrMissingFactoryEvent = errors.New("missing factory event") | ||
|
|
||
| // BuildDisputeGameLogFilter creates a filter query for the DisputeGameFactory contract. | ||
| // | ||
| // The `DisputeGameCreated` event is encoded as: | ||
| // 0: address indexed disputeProxy, | ||
| // 1: GameType indexed gameType, | ||
| // 2: Claim indexed rootClaim, | ||
| func BuildDisputeGameLogFilter(contract *abi.ABI) (ethereum.FilterQuery, error) { | ||
| event := contract.Events["DisputeGameCreated"] | ||
|
|
||
| if event.ID == (common.Hash{}) { | ||
| return ethereum.FilterQuery{}, ErrMissingFactoryEvent | ||
| } | ||
|
|
||
| query := ethereum.FilterQuery{ | ||
| Topics: [][]common.Hash{ | ||
| {event.ID}, | ||
| }, | ||
| } | ||
|
|
||
| return query, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package challenger | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| eth "github.com/ethereum/go-ethereum" | ||
| abi "github.com/ethereum/go-ethereum/accounts/abi" | ||
| common "github.com/ethereum/go-ethereum/common" | ||
| ) | ||
|
|
||
| // TestBuildDisputeGameLogFilter_Succeeds tests that the DisputeGame | ||
| // Log Filter is built correctly. | ||
| func TestBuildDisputeGameLogFilter_Succeeds(t *testing.T) { | ||
| event := abi.Event{ | ||
| ID: [32]byte{0x01}, | ||
| } | ||
|
|
||
| filterQuery := eth.FilterQuery{ | ||
| Topics: [][]common.Hash{ | ||
| {event.ID}, | ||
| }, | ||
| } | ||
|
|
||
| dgfABI := abi.ABI{ | ||
| Events: map[string]abi.Event{ | ||
| "DisputeGameCreated": event, | ||
| }, | ||
| } | ||
|
|
||
| query, err := BuildDisputeGameLogFilter(&dgfABI) | ||
| require.Equal(t, filterQuery, query) | ||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| // TestBuildDisputeGameLogFilter_Fails tests that the DisputeGame | ||
| // Log Filter fails when the event definition is missing. | ||
| func TestBuildDisputeGameLogFilter_Fails(t *testing.T) { | ||
| dgfABI := abi.ABI{ | ||
| Events: map[string]abi.Event{}, | ||
| } | ||
|
|
||
| _, err := BuildDisputeGameLogFilter(&dgfABI) | ||
| require.ErrorIs(t, ErrMissingFactoryEvent, err) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package watch | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "os/signal" | ||
| "syscall" | ||
|
|
||
| "github.com/ethereum/go-ethereum/log" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-challenger/challenger" | ||
| "github.com/ethereum-optimism/optimism/op-challenger/config" | ||
| "github.com/ethereum-optimism/optimism/op-challenger/metrics" | ||
| ) | ||
|
|
||
| // Factory listens to the DisputeGameFactory for newly created dispute games. | ||
| func Factory(logger log.Logger, cfg *config.Config) error { | ||
| if err := cfg.Check(); err != nil { | ||
| return fmt.Errorf("invalid config: %w", err) | ||
| } | ||
|
|
||
| m := metrics.NewMetrics("default") | ||
|
|
||
| service, err := challenger.NewChallenger(*cfg, logger, m) | ||
| if err != nil { | ||
| logger.Error("Unable to create the Challenger", "error", err) | ||
| return err | ||
| } | ||
|
|
||
| logger.Info("Listening for DisputeGameCreated events from the DisputeGameFactory contract", "dgf", cfg.DGFAddress.String()) | ||
|
|
||
| subscription, err := service.NewFactorySubscription() | ||
| if err != nil { | ||
| logger.Error("Unable to create the subscription", "error", err) | ||
| return err | ||
| } | ||
|
|
||
| err = subscription.Subscribe() | ||
| if err != nil { | ||
| logger.Error("Unable to subscribe to the DisputeGameFactory contract", "error", err) | ||
| return err | ||
| } | ||
|
|
||
| defer subscription.Quit() | ||
|
|
||
| interruptChannel := make(chan os.Signal, 1) | ||
| signal.Notify(interruptChannel, []os.Signal{ | ||
| os.Interrupt, | ||
| os.Kill, | ||
| syscall.SIGTERM, | ||
| syscall.SIGQUIT, | ||
| }...) | ||
|
|
||
| for { | ||
| select { | ||
| case log := <-subscription.Logs(): | ||
| logger.Info("Received log", "log", log) | ||
| case <-interruptChannel: | ||
| logger.Info("Received interrupt signal, exiting...") | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.