diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2cced9a --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/main.go b/cmd/centralized-sequencer/main.go similarity index 90% rename from main.go rename to cmd/centralized-sequencer/main.go index 852c730..0a8c38a 100644 --- a/main.go +++ b/cmd/centralized-sequencer/main.go @@ -27,6 +27,7 @@ func main() { host string port string listenAll bool + rollupId string batchTime time.Duration da_address string da_namespace string @@ -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") @@ -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) } diff --git a/sequencing/sequencer.go b/sequencing/sequencer.go index 8325a0d..a7e66ea 100644 --- a/sequencing/sequencer.go +++ b/sequencing/sequencer.go @@ -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 { @@ -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{}), diff --git a/sequencing/sequencer_test.go b/sequencing/sequencer_test.go index 4581c58..4d8525d 100644 --- a/sequencing/sequencer_test.go +++ b/sequencing/sequencer_test.go @@ -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() @@ -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()