Skip to content

Commit

Permalink
add dockerfile, add rollup id to cmd options
Browse files Browse the repository at this point in the history
  • Loading branch information
gupadhyaya committed Nov 4, 2024
1 parent cdaefc7 commit 328bcca
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Build stage
FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS build-env

# Set environment variables
ENV GO111MODULE=on

# Set the working directory for the build
WORKDIR /src

# Copy Go modules and source code
COPY go.mod go.sum ./
RUN go mod download

# Copy the rest of the source code
COPY . .

# Build the Go program
RUN go mod tidy -compat=1.23 && \
go build -o centralized-sequencer /src/cmd/centralized-sequencer/main.go

# Final image
FROM alpine:3.18.3

# Set the working directory
WORKDIR /root

# Copy the binary from the build stage
COPY --from=build-env /src/centralized-sequencer /usr/bin/local-sequencer

# Expose the application's port
EXPOSE 50051

# Define arguments as environment variables, which can be set when running the container
ENV HOST=localhost
ENV PORT=50051
ENV LISTEN_ALL=false
ENV BATCH_TIME=2s
ENV DA_ADDRESS=http://localhost:26658
ENV DA_NAMESPACE=""
ENV DA_AUTH_TOKEN=""
ENV DB_PATH="~/.centralized-sequencer-db"
ENV ROLLUP_ID="rollupId"

# Run the application with environment variables passed as flags
CMD ["sh", "-c", "/usr/bin/local-sequencer -host $HOST -port $PORT -listen-all=$LISTEN_ALL -batch-time $BATCH_TIME -da_address $DA_ADDRESS -da_namespace $DA_NAMESPACE -da_auth_token $DA_AUTH_TOKEN -db_path $DB_PATH"]
6 changes: 4 additions & 2 deletions main.go → cmd/centralized-sequencer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func main() {
host string
port string
listenAll bool
rollupId string
batchTime time.Duration
da_address string
da_namespace string
Expand All @@ -36,6 +37,7 @@ func main() {
flag.StringVar(&host, "host", defaultHost, "centralized sequencer host")
flag.StringVar(&port, "port", defaultPort, "centralized sequencer port")
flag.BoolVar(&listenAll, "listen-all", false, "listen on all network interfaces (0.0.0.0) instead of just localhost")
flag.StringVar(&rollupId, "rollup-id", "rollupId", "rollup id")
flag.DurationVar(&batchTime, "batch-time", defaultBatchTime, "time in seconds to wait before generating a new batch")
flag.StringVar(&da_address, "da_address", defaultDA, "DA address")
flag.StringVar(&da_namespace, "da_namespace", "", "DA namespace where the sequencer submits transactions")
Expand All @@ -60,13 +62,13 @@ func main() {
log.Fatalf("Error decoding namespace: %v", err)
}

centralizedSeq, err := sequencing.NewSequencer(da_address, da_auth_token, namespace, batchTime, db_path)
centralizedSeq, err := sequencing.NewSequencer(da_address, da_auth_token, namespace, []byte(rollupId), batchTime, db_path)
if err != nil {
log.Fatalf("Failed to create centralized sequencer: %v", err)
}
grpcServer := sequencingGRPC.NewServer(centralizedSeq, centralizedSeq, centralizedSeq)

log.Println("Starting gRPC server on port 50051...")
log.Println("Starting centralized sequencing gRPC server on port 50051...")
if err := grpcServer.Serve(lis); err != nil {
log.Fatalf("Failed to serve: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions sequencing/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ type Sequencer struct {
}

// NewSequencer ...
func NewSequencer(daAddress, daAuthToken string, daNamespace []byte, batchTime time.Duration, dbPath string) (*Sequencer, error) {
func NewSequencer(daAddress, daAuthToken string, daNamespace []byte, rollupId []byte, batchTime time.Duration, dbPath string) (*Sequencer, error) {
ctx := context.Background()
dac, err := proxyda.NewClient(daAddress, daAuthToken)
if err != nil {
Expand Down Expand Up @@ -313,7 +313,7 @@ func NewSequencer(daAddress, daAuthToken string, daNamespace []byte, batchTime t
batchTime: batchTime,
ctx: ctx,
maxSize: maxBlobSize,
rollupId: daNamespace,
rollupId: rollupId,
tq: NewTransactionQueue(),
bq: NewBatchQueue(),
seenBatches: make(map[string]struct{}),
Expand Down
4 changes: 2 additions & 2 deletions sequencing/sequencer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func startMockDAServJSONRPC(ctx context.Context, da_address string) (*proxy.Serv

func TestNewSequencer(t *testing.T) {
// Create a new sequencer with mock DA client
seq, err := NewSequencer(MockDAAddressHTTP, "authToken", []byte("namespace"), 1*time.Second, "")
seq, err := NewSequencer(MockDAAddressHTTP, "authToken", []byte("namespace"), []byte("rollup1"), 1*time.Second, "")
require.NoError(t, err)
defer func() {
err := seq.Close()
Expand All @@ -67,7 +67,7 @@ func TestNewSequencer(t *testing.T) {

func TestSequencer_SubmitRollupTransaction(t *testing.T) {
// Initialize a new sequencer
seq, err := NewSequencer(MockDAAddressHTTP, "authToken", []byte("rollup1"), 1*time.Second, "")
seq, err := NewSequencer(MockDAAddressHTTP, "authToken", []byte("namespace"), []byte("rollup1"), 1*time.Second, "")
require.NoError(t, err)
defer func() {
err := seq.Close()
Expand Down

0 comments on commit 328bcca

Please sign in to comment.