-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat(taiko-client): latched ZK→SGX drain/resume for proof submitter #21795
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
Open
davidtaikocha
wants to merge
11
commits into
main
Choose a base branch
from
prover/zk-sgx-drain-resume
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+612
−64
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
35c1d10
feat(taiko-client): add raiko2 ZK backlog control-plane client
davidtaikocha 3549aa2
feat(taiko-client): add ZK-fallback latch state to proof submitter
davidtaikocha 16a839e
feat(taiko-client): add ZK drain/resume decision logic
davidtaikocha 8950bd7
feat(taiko-client): drive ZK/SGX selection via drain/resume machine
davidtaikocha 94ca3b0
refactor(taiko-client): address ZK drain/resume review follow-ups
davidtaikocha 053c4f0
refactor(taiko-client): simplify ZK backlog control-plane types
davidtaikocha 46369b7
docs(taiko-client): clarify ZK control-plane wiring is compile-time
davidtaikocha 0abeaf1
test(taiko-client): convert ZK drain/resume tests to testify suite
davidtaikocha ccd20d4
refactor(taiko-client): rename machineSaysZK to backlogAllowsZK
davidtaikocha 9434749
test(taiko-client): split zk_backlog suite subtests into methods
davidtaikocha f180065
refactor(taiko-client): use resty for raiko HTTP requests (#21796)
davidtaikocha 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
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,72 @@ | ||
| package producer | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/http" | ||
|
|
||
| "github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/rpc" | ||
| ) | ||
|
|
||
| // ZKBacklogController is implemented by proof producers whose backend exposes the | ||
| // raiko2 control-plane endpoints for draining the ZK (`zk_any`) task backlog and | ||
| // reporting when the backend is idle. See raiko2 issue #93. | ||
| type ZKBacklogController interface { | ||
| // ClearBacklog discards all non-terminal `zk_any` tasks on the ZK backend | ||
| // (POST /v3/prover/clear). | ||
| ClearBacklog(ctx context.Context) error | ||
| // StatusClean reports whether the ZK backend is fully idle, i.e. the | ||
| // `data.clean` field of GET /v3/prover/status is true. | ||
| StatusClean(ctx context.Context) (bool, error) | ||
| } | ||
|
|
||
| // raikoProverStatusResponse is the body returned by GET /v3/prover/status. Only | ||
| // `data.clean` is consumed; the remaining fields (`status`, `tasks`, `network`) | ||
| // are intentionally ignored. | ||
| type raikoProverStatusResponse struct { | ||
| Data struct { | ||
| Clean bool `json:"clean"` | ||
| } `json:"data"` | ||
| } | ||
|
|
||
| // ClearBacklog implements the ZKBacklogController interface. | ||
| func (s *ComposeProofProducer) ClearBacklog(ctx context.Context) error { | ||
| if s.Dummy { | ||
| return nil | ||
| } | ||
| ctx, cancel := rpc.CtxWithTimeoutOrDefault(ctx, s.RaikoRequestTimeout) | ||
| defer cancel() | ||
|
|
||
| // The clear endpoint only needs to return HTTP 200; its response body is unused. | ||
| if _, err := requestRaiko[struct{}]( | ||
| ctx, | ||
| http.MethodPost, | ||
| s.RaikoHostEndpoint+"/v3/prover/clear", | ||
| s.ApiKey, | ||
| nil, | ||
| ); err != nil { | ||
| return fmt.Errorf("failed to clear ZK backlog: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // StatusClean implements the ZKBacklogController interface. | ||
| func (s *ComposeProofProducer) StatusClean(ctx context.Context) (bool, error) { | ||
| if s.Dummy { | ||
| return true, nil | ||
| } | ||
| ctx, cancel := rpc.CtxWithTimeoutOrDefault(ctx, s.RaikoRequestTimeout) | ||
| defer cancel() | ||
|
|
||
| out, err := requestRaiko[raikoProverStatusResponse]( | ||
| ctx, | ||
| http.MethodGet, | ||
| s.RaikoHostEndpoint+"/v3/prover/status", | ||
| s.ApiKey, | ||
| nil, | ||
| ) | ||
| if err != nil { | ||
| return false, fmt.Errorf("failed to get ZK prover status: %w", err) | ||
| } | ||
| return out.Data.Clean, nil | ||
| } |
97 changes: 97 additions & 0 deletions
97
packages/taiko-client/prover/proof_producer/zk_backlog_test.go
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,97 @@ | ||
| package producer | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/suite" | ||
| ) | ||
|
|
||
| // Compile-time assertion that the ZK compose producer satisfies the interface. | ||
| var _ ZKBacklogController = (*ComposeProofProducer)(nil) | ||
|
|
||
| type ZKBacklogTestSuite struct { | ||
| suite.Suite | ||
| } | ||
|
|
||
| func TestZKBacklogTestSuite(t *testing.T) { | ||
| suite.Run(t, new(ZKBacklogTestSuite)) | ||
| } | ||
|
|
||
| func (s *ZKBacklogTestSuite) TestStatusCleanReturnsTrue() { | ||
| server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| s.Equal(http.MethodGet, r.Method) | ||
| s.Equal("/v3/prover/status", r.URL.Path) | ||
| _, _ = w.Write([]byte( | ||
| `{"status":"ok","data":{"clean":true,"tasks":{"pending":0},"network":{"risc0":{"inflight_orders":0}}}}`, | ||
| )) | ||
| })) | ||
| defer server.Close() | ||
|
|
||
| p := &ComposeProofProducer{RaikoHostEndpoint: server.URL, RaikoRequestTimeout: time.Second} | ||
| clean, err := p.StatusClean(s.T().Context()) | ||
| s.NoError(err) | ||
| s.True(clean) | ||
| } | ||
|
|
||
| func (s *ZKBacklogTestSuite) TestStatusCleanReturnsFalse() { | ||
| server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { | ||
| _, _ = w.Write([]byte(`{"status":"ok","data":{"clean":false}}`)) | ||
| })) | ||
| defer server.Close() | ||
|
|
||
| p := &ComposeProofProducer{RaikoHostEndpoint: server.URL, RaikoRequestTimeout: time.Second} | ||
| clean, err := p.StatusClean(s.T().Context()) | ||
| s.NoError(err) | ||
| s.False(clean) | ||
| } | ||
|
|
||
| func (s *ZKBacklogTestSuite) TestStatusCleanErrorsOnNon200() { | ||
| server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { | ||
| w.WriteHeader(http.StatusNotFound) | ||
| })) | ||
| defer server.Close() | ||
|
|
||
| p := &ComposeProofProducer{RaikoHostEndpoint: server.URL, RaikoRequestTimeout: time.Second} | ||
| _, err := p.StatusClean(s.T().Context()) | ||
| s.Error(err) | ||
| } | ||
|
|
||
| func (s *ZKBacklogTestSuite) TestStatusCleanDummyShortCircuits() { | ||
| p := &ComposeProofProducer{Dummy: true} | ||
| clean, err := p.StatusClean(s.T().Context()) | ||
| s.NoError(err) | ||
| s.True(clean) | ||
| } | ||
|
|
||
| func (s *ZKBacklogTestSuite) TestClearBacklogPostsToEndpoint() { | ||
| var called bool | ||
| server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| called = true | ||
| s.Equal(http.MethodPost, r.Method) | ||
| s.Equal("/v3/prover/clear", r.URL.Path) | ||
| _, _ = w.Write([]byte(`{"status":"ok"}`)) | ||
| })) | ||
| defer server.Close() | ||
|
|
||
| p := &ComposeProofProducer{RaikoHostEndpoint: server.URL, RaikoRequestTimeout: time.Second} | ||
| s.NoError(p.ClearBacklog(s.T().Context())) | ||
| s.True(called) | ||
| } | ||
|
|
||
| func (s *ZKBacklogTestSuite) TestClearBacklogErrorsOnNon200() { | ||
| server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { | ||
| w.WriteHeader(http.StatusInternalServerError) | ||
| })) | ||
| defer server.Close() | ||
|
|
||
| p := &ComposeProofProducer{RaikoHostEndpoint: server.URL, RaikoRequestTimeout: time.Second} | ||
| s.Error(p.ClearBacklog(s.T().Context())) | ||
| } | ||
|
|
||
| func (s *ZKBacklogTestSuite) TestClearBacklogDummyShortCircuits() { | ||
| p := &ComposeProofProducer{Dummy: true} | ||
| s.NoError(p.ClearBacklog(s.T().Context())) | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.