Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add dockerfile, add rollup id to cmd options #27

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Build stage
FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS build-env
gupadhyaya marked this conversation as resolved.
Show resolved Hide resolved

# 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
gupadhyaya marked this conversation as resolved.
Show resolved Hide resolved

# 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
gupadhyaya marked this conversation as resolved.
Show resolved Hide resolved

# 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"
gupadhyaya marked this conversation as resolved.
Show resolved Hide resolved

# 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"]
gupadhyaya marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -31,6 +31,7 @@ func main() {
host string
port string
listenAll bool
rollupId string
batchTime time.Duration
da_address string
da_namespace string
Expand All @@ -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")
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions sequencing/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{}),
Expand Down
4 changes: 2 additions & 2 deletions sequencing/sequencer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
Loading