From 32fa2f87078c1c0656262b7242e3b2bcb7930a57 Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Mon, 25 Nov 2024 16:21:09 -0500 Subject: [PATCH] op-conductor --- heminetwork/api/bssapi/bssapi.go | 2 + heminetwork/e2e/docker-compose.yml | 2 +- heminetwork/e2e/e2e_ext_test.go | 103 +++++++++++++++++++++++++++++ op-node/Dockerfile | 4 +- 4 files changed, 109 insertions(+), 2 deletions(-) diff --git a/heminetwork/api/bssapi/bssapi.go b/heminetwork/api/bssapi/bssapi.go index 12026de083e4..0fa54d0e4372 100644 --- a/heminetwork/api/bssapi/bssapi.go +++ b/heminetwork/api/bssapi/bssapi.go @@ -81,6 +81,8 @@ type BTCFinalityByRecentKeystonesResponse struct { type BTCFinalityByKeystonesRequest struct { L2Keystones []hemi.L2Keystone `json:"l2_keystones"` + Page uint32 `json:"page,omitempty"` + Limit uint32 `json:"limit,omitempty"` } type BTCFinalityByKeystonesResponse struct { diff --git a/heminetwork/e2e/docker-compose.yml b/heminetwork/e2e/docker-compose.yml index 5a8b8a9b79b5..20414d448613 100644 --- a/heminetwork/e2e/docker-compose.yml +++ b/heminetwork/e2e/docker-compose.yml @@ -33,7 +33,7 @@ services: - "-rpcport=18443" - "-rpcconnect=bitcoind" - "generatetoaddress" - - "3000" # need to generate a lot for greater chance to not spend coinbase + - "1000" # need to generate a lot for greater chance to not spend coinbase - "$BTC_ADDRESS" restart: on-failure diff --git a/heminetwork/e2e/e2e_ext_test.go b/heminetwork/e2e/e2e_ext_test.go index 7766faac47e3..16752f421bc2 100644 --- a/heminetwork/e2e/e2e_ext_test.go +++ b/heminetwork/e2e/e2e_ext_test.go @@ -2448,6 +2448,109 @@ func TestGetFinalitiesByL2KeystoneBSS(t *testing.T) { } } +func TestGetFinalitiesByL2KeystoneBSSWithPagination(t *testing.T) { + db, pgUri, sdb, cleanup := createTestDB(context.Background(), t) + defer func() { + db.Close() + sdb.Close() + cleanup() + }() + + ctx, cancel := defaultTestContext() + defer cancel() + + _, _, bfgWsurl, _ := createBfgServer(ctx, t, pgUri, "", 1000) + + _, _, bssWsurl := createBssServer(ctx, t, bfgWsurl) + + btcBlock := createBtcBlock(ctx, t, db, 1, 998, []byte{}, 1) // finality should be 1000 - 998 - 9 + 1 = -6 + createBtcBlock(ctx, t, db, 1, -1, []byte{}, 2) // finality should be 1000 - 1000 - 9 + 1 = -8 (unpublished) + createBtcBlock(ctx, t, db, 1, 1000, btcBlock.Hash, 3) // finality should be 1000 - 1000 - 9 + 1 = -8 + expectedFinalitiesDesc := []int32{-8, -6} + + c, _, err := websocket.Dial(ctx, bssWsurl, nil) + if err != nil { + t.Fatal(err) + } + defer c.CloseNow() + + assertPing(ctx, t, c, bssapi.CmdPingRequest) + + bws := &bssWs{ + conn: protocol.NewWSConn(c), + } + + // first and second btcBlocks + recentFinalities, err := db.L2BTCFinalityMostRecent(ctx, 100) + if err != nil { + t.Fatal(err) + } + + l2Keystones := []hemi.L2Keystone{} + for _, r := range recentFinalities[1:] { + l, err := hemi.L2BTCFinalityFromBfgd(&r, 0, 0) + if err != nil { + t.Fatal(err) + } + l2Keystones = append(l2Keystones, l.L2Keystone) + } + + receivedFinalities := []hemi.L2BTCFinality{} + + panic("am I insance") + + for i := range 1 { + finalityRequest := bssapi.BTCFinalityByKeystonesRequest{ + L2Keystones: l2Keystones, + Page: i, + Limit: 1, + } + + err = bssapi.Write(ctx, bws.conn, "someid", finalityRequest) + if err != nil { + t.Fatal(err) + } + + var v protocol.Message + err = wsjson.Read(ctx, c, &v) + if err != nil { + t.Fatal(err) + } + + if v.Header.Command != bssapi.CmdBTCFinalityByKeystonesResponse { + t.Fatalf("received unexpected command: %s", v.Header.Command) + } + + finalityResponse := bssapi.BTCFinalityByRecentKeystonesResponse{} + err = json.Unmarshal(v.Payload, &finalityResponse) + if err != nil { + t.Fatal(err) + } + + if len(finalityResponse.L2BTCFinalities) != 1 { + t.Fatal("unexpected length %v", len(finalityResponse.L2BTCFinalities)) + } + + receivedFinalities = append(receivedFinalities, finalityResponse.L2BTCFinalities[0]) + } + + expectedResponse := []hemi.L2BTCFinality{} + for i, r := range recentFinalities[1:] { + f, err := hemi.L2BTCFinalityFromBfgd(&r, 0, 0) + if err != nil { + t.Fatal(err) + } + + f.BTCFinality = expectedFinalitiesDesc[i] + expectedResponse = append(expectedResponse, *f) + } + + diff := deep.Equal(expectedResponse, receivedFinalities) + if len(diff) > 0 { + t.Fatalf("unexpected diff %s", diff) + } +} + func TestGetFinalitiesByL2KeystoneBSSLowerServerHeight(t *testing.T) { db, pgUri, sdb, cleanup := createTestDB(context.Background(), t) defer func() { diff --git a/op-node/Dockerfile b/op-node/Dockerfile index 19688f28e4e5..07e6b328c17b 100644 --- a/op-node/Dockerfile +++ b/op-node/Dockerfile @@ -13,7 +13,7 @@ WORKDIR /optimism COPY . /optimism -RUN VERSION="$VERSION" GOOS=$TARGETOS GOARCH=$TARGETARCH make op-node op-batcher op-proposer +RUN VERSION="$VERSION" GOOS=$TARGETOS GOARCH=$TARGETARCH make op-node op-batcher op-proposer op-conductor FROM alpine:3.20@sha256:b89d9c93e9ed3597455c90a0b88a8bbb5cb7188438f70953fede212a0c4394e0 @@ -23,4 +23,6 @@ COPY --from=builder /optimism/op-batcher/bin/op-batcher /bin/op-batcher COPY --from=builder /optimism/op-proposer/bin/op-proposer /bin/op-proposer +COPY --from=builder /optimism/op-conductor/bin/op-conductor /bin/op-conductor + CMD ['op-node'] \ No newline at end of file