Skip to content

Commit

Permalink
op-conductor
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaytonNorthey92 committed Nov 25, 2024
1 parent 754f2e0 commit 32fa2f8
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 2 deletions.
2 changes: 2 additions & 0 deletions heminetwork/api/bssapi/bssapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion heminetwork/e2e/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
103 changes: 103 additions & 0 deletions heminetwork/e2e/e2e_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 3 additions & 1 deletion op-node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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']

0 comments on commit 32fa2f8

Please sign in to comment.