diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0cd52d2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +# Build stage +FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS build-env + +# 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 93% rename from main.go rename to cmd/centralized-sequencer/main.go index 470c637..29117f2 100644 --- a/main.go +++ b/cmd/centralized-sequencer/main.go @@ -31,6 +31,7 @@ func main() { host string port string listenAll bool + rollupId string batchTime time.Duration da_address string da_namespace string @@ -42,6 +43,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") @@ -89,13 +91,13 @@ func main() { if err != nil { log.Fatalf("Failed to create metrics: %v", err) } - centralizedSeq, err := sequencing.NewSequencer(da_address, da_auth_token, namespace, batchTime, metrics, db_path) + centralizedSeq, err := sequencing.NewSequencer(da_address, da_auth_token, namespace, []byte(rollupId), batchTime, metrics, 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 5796e6b..abf6e5e 100644 --- a/sequencing/sequencer.go +++ b/sequencing/sequencer.go @@ -286,7 +286,7 @@ type Sequencer struct { } // NewSequencer ... -func NewSequencer(daAddress, daAuthToken string, daNamespace []byte, batchTime time.Duration, metrics *Metrics, dbPath string) (*Sequencer, error) { +func NewSequencer(daAddress, daAuthToken string, daNamespace []byte, rollupId []byte, batchTime time.Duration, metrics *Metrics, dbPath string) (*Sequencer, error) { ctx := context.Background() dac, err := proxyda.NewClient(daAddress, daAuthToken) if err != nil { @@ -315,7 +315,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 ee42c57..58be4e5 100644 --- a/sequencing/sequencer_test.go +++ b/sequencing/sequencer_test.go @@ -52,7 +52,7 @@ func startMockDAServJSONRPC(ctx context.Context, da_address string) (*proxy.Serv func TestNewSequencer(t *testing.T) { // Create a new sequencer with mock DA client metrics, _ := NopMetrics() - seq, err := NewSequencer(MockDAAddressHTTP, "authToken", []byte("namespace"), 10*time.Second, metrics, "") + seq, err := NewSequencer(MockDAAddressHTTP, "authToken", []byte("namespace"), []byte("rollup1"), 10*time.Second, metrics, "") require.NoError(t, err) defer func() { err := seq.Close() @@ -69,7 +69,7 @@ func TestNewSequencer(t *testing.T) { func TestSequencer_SubmitRollupTransaction(t *testing.T) { // Initialize a new sequencer metrics, _ := NopMetrics() - seq, err := NewSequencer(MockDAAddressHTTP, "authToken", []byte("rollup1"), 10*time.Second, metrics, "") + seq, err := NewSequencer(MockDAAddressHTTP, "authToken", []byte("namespace"), []byte("rollup1"), 10*time.Second, metrics, "") require.NoError(t, err) defer func() { err := seq.Close()