Skip to content

Commit

Permalink
logging: better logging msgs in op handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
samlaf committed Oct 16, 2024
1 parent 06034ff commit a36001e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
28 changes: 14 additions & 14 deletions server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (svr *Server) handleGetOPKeccakCommitment(w http.ResponseWriter, r *http.Re
return fmt.Errorf("failed to decode commitment %s: %w", rawCommitmentHex, err)
}

svr.log.Info("Processing op keccak commitment", "commitment", rawCommitmentHex, "commitmentMeta", commitmentMeta)
svr.log.Info("Processing op keccak commitment GET", "commitment", rawCommitmentHex, "commitmentMeta", commitmentMeta)
return svr.handleGetShared(r.Context(), w, commitment, commitmentMeta)
}

Expand All @@ -93,7 +93,7 @@ func (svr *Server) handleGetOPGenericCommitment(w http.ResponseWriter, r *http.R
return fmt.Errorf("failed to decode commitment %s: %w", rawCommitmentHex, err)
}

svr.log.Info("Processing op keccak commitment", "commitment", rawCommitmentHex, "commitmentMeta", commitmentMeta)
svr.log.Info("Processing op generic commitment GET", "commitment", rawCommitmentHex, "commitmentMeta", commitmentMeta)
return svr.handleGetShared(r.Context(), w, commitment, commitmentMeta)
}

Expand All @@ -117,21 +117,21 @@ func (svr *Server) handleGetShared(ctx context.Context, w http.ResponseWriter, c
}

// =================================================================================================
// PUT ROUTES
// POST ROUTES
// =================================================================================================

// handlePutSimpleCommitment handles the POST request for simple commitments.
func (svr *Server) handlePutSimpleCommitment(w http.ResponseWriter, r *http.Request) error {
// handlePostSimpleCommitment handles the POST request for simple commitments.
func (svr *Server) handlePostSimpleCommitment(w http.ResponseWriter, r *http.Request) error {
svr.log.Info("Processing simple commitment")
commitmentMeta := commitments.CommitmentMeta{
Mode: commitments.SimpleCommitmentMode,
CertVersion: byte(commitments.CertV0), // TODO: hardcoded for now
}
return svr.handlePutShared(w, r, nil, commitmentMeta)
return svr.handlePostShared(w, r, nil, commitmentMeta)
}

// handlePutOPKeccakCommitment handles the POST request for optimism keccak commitments.
func (svr *Server) handlePutOPKeccakCommitment(w http.ResponseWriter, r *http.Request) error {
// handlePostOPKeccakCommitment handles the POST request for optimism keccak commitments.
func (svr *Server) handlePostOPKeccakCommitment(w http.ResponseWriter, r *http.Request) error {
// TODO: do we use a version byte in OPKeccak commitments? README seems to say so, but server_test didn't
// versionByte, err := parseVersionByte(r)
// if err != nil {
Expand All @@ -153,21 +153,21 @@ func (svr *Server) handlePutOPKeccakCommitment(w http.ResponseWriter, r *http.Re
return fmt.Errorf("failed to decode commitment %s: %w", rawCommitmentHex, err)
}

svr.log.Info("Processing op keccak commitment", "commitment", rawCommitmentHex, "commitmentMeta", commitmentMeta)
return svr.handlePutShared(w, r, commitment, commitmentMeta)
svr.log.Info("Processing op keccak commitment POST", "commitment", rawCommitmentHex, "commitmentMeta", commitmentMeta)
return svr.handlePostShared(w, r, commitment, commitmentMeta)
}

// handlePutOPGenericCommitment handles the POST request for optimism generic commitments.
func (svr *Server) handlePutOPGenericCommitment(w http.ResponseWriter, r *http.Request) error {
// handlePostOPGenericCommitment handles the POST request for optimism generic commitments.
func (svr *Server) handlePostOPGenericCommitment(w http.ResponseWriter, r *http.Request) error {
svr.log.Info("Processing simple commitment")
commitmentMeta := commitments.CommitmentMeta{
Mode: commitments.OptimismGeneric,
CertVersion: byte(commitments.CertV0), // TODO: hardcoded for now
}
return svr.handlePutShared(w, r, nil, commitmentMeta)
return svr.handlePostShared(w, r, nil, commitmentMeta)
}

func (svr *Server) handlePutShared(w http.ResponseWriter, r *http.Request, comm []byte, meta commitments.CommitmentMeta) error {
func (svr *Server) handlePostShared(w http.ResponseWriter, r *http.Request, comm []byte, meta commitments.CommitmentMeta) error {
input, err := io.ReadAll(r.Body)
if err != nil {
err = MetaError{
Expand Down
8 changes: 4 additions & 4 deletions server/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (svr *Server) registerRoutes(r *mux.Router) {
subrouterPOST := r.Methods("POST").PathPrefix("/put").Subrouter()
// simple commitments (for nitro)
subrouterPOST.HandleFunc("", // commitment is calculated by the server using the body data
withLogging(withMetrics(svr.handlePutSimpleCommitment, svr.m, commitments.SimpleCommitmentMode), svr.log),
withLogging(withMetrics(svr.handlePostSimpleCommitment, svr.m, commitments.SimpleCommitmentMode), svr.log),
).Queries("commitment_mode", "simple")
// op keccak256 commitments (write to S3)
subrouterPOST.HandleFunc("/"+
Expand All @@ -67,14 +67,14 @@ func (svr *Server) registerRoutes(r *mux.Router) {
// but perhaps we should (in case we want a v2 to use another hash for eg?)
// "{version_byte_hex:[0-9a-fA-F]{2}}"+ // should always be 0x00 for now but we let others through to return a 404
"{"+routingVarNameRawCommitmentHex+"}",
withLogging(withMetrics(svr.handlePutOPKeccakCommitment, svr.m, commitments.OptimismKeccak), svr.log),
withLogging(withMetrics(svr.handlePostOPKeccakCommitment, svr.m, commitments.OptimismKeccak), svr.log),
)
// op generic commitments (write to EigenDA)
subrouterPOST.HandleFunc("", // commitment is calculated by the server using the body data
withLogging(withMetrics(svr.handlePutOPGenericCommitment, svr.m, commitments.OptimismGeneric), svr.log),
withLogging(withMetrics(svr.handlePostOPGenericCommitment, svr.m, commitments.OptimismGeneric), svr.log),
)
subrouterPOST.HandleFunc("/", // commitment is calculated by the server using the body data
withLogging(withMetrics(svr.handlePutOPGenericCommitment, svr.m, commitments.OptimismGeneric), svr.log),
withLogging(withMetrics(svr.handlePostOPGenericCommitment, svr.m, commitments.OptimismGeneric), svr.log),
)

r.HandleFunc("/health", withLogging(svr.handleHealth, svr.log)).Methods("GET")
Expand Down

0 comments on commit a36001e

Please sign in to comment.