-
Notifications
You must be signed in to change notification settings - Fork 4k
op-conductor: ensure a transparent proxy for miner_setMaxDASize #15772
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 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
27ba862
op-conductor: ensure a transparent proxy for miner_setMaxDASize
geoknee e5b50e9
noncomplicant sequencer returns an http 200 but with JSON-RPC error r…
geoknee 6276219
tidy up
geoknee efe2b4e
fix lint
geoknee 8d585d2
use op-service MockRPC to simplify test
geoknee bc34dee
switch on error and warn log if not an RPC err
geoknee 67cad3e
add test case for "sequencer down" and assert on logs
geoknee 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| package conductor | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "log/slog" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
|
|
||
| clientmocks "github.com/ethereum-optimism/optimism/op-conductor/client/mocks" | ||
| consensusmocks "github.com/ethereum-optimism/optimism/op-conductor/consensus/mocks" | ||
| healthmocks "github.com/ethereum-optimism/optimism/op-conductor/health/mocks" | ||
| "github.com/ethereum-optimism/optimism/op-conductor/metrics" | ||
| "github.com/ethereum-optimism/optimism/op-service/testlog" | ||
| "github.com/ethereum/go-ethereum/rpc" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // createHTTPHandler creates a mock HTTP handler for testing. If alwaysFails is true, | ||
| // the handler will return a JSON-RPC MethodNotFound error response for any vaild request. | ||
| func createHTTPHandler(t *testing.T, alwaysFails bool) http.HandlerFunc { | ||
| return func(w http.ResponseWriter, r *http.Request) { | ||
| if r.Method == "POST" { | ||
| var req struct { | ||
| JSONRPC string `json:"jsonrpc"` | ||
| Method string `json:"method"` | ||
| Params []interface{} `json:"params"` | ||
| ID interface{} `json:"id"` | ||
| } | ||
| if err := json.NewDecoder(r.Body).Decode(&req); err == nil { | ||
|
|
||
| if alwaysFails { | ||
| w.Header().Set("Content-Type", "application/json") | ||
| errorResp := struct { | ||
| JSONRPC string `json:"jsonrpc"` | ||
| ID interface{} `json:"id"` | ||
| Error struct { | ||
| Code int `json:"code"` | ||
| Message string `json:"message"` | ||
| } `json:"error"` | ||
| }{ | ||
| JSONRPC: "2.0", | ||
| ID: req.ID, | ||
| Error: struct { | ||
| Code int `json:"code"` | ||
| Message string `json:"message"` | ||
| }{ | ||
| Code: -32601, // Method not found error code | ||
| Message: "Method not found", | ||
| }, | ||
| } | ||
| if err := json.NewEncoder(w).Encode(errorResp); err != nil { | ||
| t.Logf("Error writing response: %v", err) | ||
| } | ||
| return | ||
| } | ||
| if req.Method == "miner_setMaxDASize" && len(req.Params) == 2 { | ||
| w.Header().Set("Content-Type", "application/json") | ||
| _, err := w.Write([]byte(`{"jsonrpc":"2.0","id":1,"result":true}`)) | ||
| if err != nil { | ||
| t.Logf("Error writing response: %v", err) | ||
| } | ||
| return | ||
| } | ||
| } | ||
| } | ||
| http.Error(w, "Unexpected request", http.StatusBadRequest) | ||
| } | ||
| } | ||
|
|
||
| // TestSetMaxDASize tests the SetMaxDASize method of the ExecutionMinerProxyBackend | ||
| // It ensures that the proxy is transparently proxying the call to the execution engine | ||
| func TestSetMaxDASize(t *testing.T) { | ||
| t.Run("compliant sequencer", func(t *testing.T) { | ||
| testSetMaxDASize(t, true) | ||
| }) | ||
| t.Run("non-compliant sequencer", func(t *testing.T) { | ||
| testSetMaxDASize(t, false) | ||
| }) | ||
| } | ||
|
|
||
| func testSetMaxDASize(t *testing.T, compliantSequencer bool) { | ||
| ctx := context.Background() | ||
| sequencer := httptest.NewServer(createHTTPHandler(t, !compliantSequencer)) | ||
| defer sequencer.Close() | ||
|
|
||
| config := mockConfig(t) | ||
| config.ExecutionRPC = sequencer.URL | ||
| config.NodeRPC = sequencer.URL // this won't be used but needs to be set to get the conductor to init properly | ||
| config.RPCEnableProxy = true | ||
| config.RPC.ListenAddr = "localhost" | ||
| config.RPC.ListenPort = 0 // Let the system pick a random port, which we will inspect later | ||
|
|
||
| conductor, err := NewOpConductor( | ||
| ctx, | ||
| &config, | ||
| testlog.Logger(t, slog.LevelDebug), | ||
| &metrics.NoopMetricsImpl{}, | ||
| "test-version", | ||
| &clientmocks.SequencerControl{}, // not used in this test | ||
| &consensusmocks.Consensus{}, // not used in this test | ||
| &healthmocks.HealthMonitor{}, // not used in this test | ||
| ) | ||
|
|
||
| require.NoError(t, err) | ||
|
|
||
| // Start the the RPC server part of the conductor | ||
| err = conductor.rpcServer.Start() | ||
| require.NoError(t, err) | ||
| defer func() { _ = conductor.rpcServer.Stop() }() | ||
|
|
||
| port, err := conductor.rpcServer.Port() | ||
| require.NoError(t, err) | ||
| t.Log("RPC server listening on port:", port) | ||
|
|
||
| url := fmt.Sprintf("http://localhost:%d", port) | ||
|
|
||
| rpcClient, err := rpc.Dial(url) | ||
| require.NoError(t, err) | ||
| defer rpcClient.Close() | ||
|
|
||
| var result bool | ||
| err = rpcClient.CallContext(ctx, &result, "miner_setMaxDASize", "0x1", "0x2") | ||
|
|
||
| if compliantSequencer { | ||
| require.NoError(t, err) | ||
| require.True(t, result) | ||
| t.Log("Proxied a successful miner_setMaxDASize call") | ||
| } else { | ||
| require.Error(t, err) | ||
| require.Contains(t, err.Error(), "Method not found") | ||
| t.Log("Proxied a failed miner_setMaxDASize call") | ||
| } | ||
| } | ||
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
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.