Skip to content

Commit

Permalink
release v0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jyc228 committed Aug 29, 2023
2 parents c5189ea + cbef5d0 commit 460de35
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions internal/ec2/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,4 @@ func (c *Controller) StopIfRunning() {
}

func (c *Controller) instanceIds() []*string { return []*string{&c.instanceId} }
func (c *Controller) Running() bool { return c.running }
17 changes: 17 additions & 0 deletions internal/proof/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ func NewServer(service *Service) *Server {
}

func (s *Server) ServeHTTP(writer http.ResponseWriter, httpRequest *http.Request) {
switch httpRequest.RequestURI {
case "/":
s.serveJsonRpc(writer, httpRequest)
case "/health":
response := map[string]interface{}{
"status": "ok",
"ec2Running": s.service.ec2.Running(),
"generatingProofCount": len(s.service.inProgressProof),
}
err := json.NewEncoder(writer).Encode(response)
if err != nil {
http.Error(writer, "Failed to encode JSON response", http.StatusInternalServerError)
}
}
}

func (s *Server) serveJsonRpc(writer http.ResponseWriter, httpRequest *http.Request) {
var request map[string]interface{}
err := json.NewDecoder(httpRequest.Body).Decode(&request)
if err != nil {
Expand Down
11 changes: 9 additions & 2 deletions internal/proof/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ func (s *Service) Prove(traceString string, proofType Type) (*ProveResponse, err
s.inProgressProof[id] = wg
go func(id, blockNumber string) {
defer wg.Done()
defer delete(s.inProgressProof, id)
defer func() {
s.mu.Lock()
delete(s.inProgressProof, id)
s.mu.Unlock()
if len(s.inProgressProof) == 0 {
s.ec2.StopIfRunning()
}
}()
log.Println("prove start.", "blockNumber:", blockNumber, "id:", id)
res, err := c.Prove(traceString, proofType)
log.Println("prove complete.", "blockNumber:", blockNumber, "id:", id)
log.Println("prove complete.", "blockNumber:", blockNumber, "id:", id, "err:", err)
proof := &FileProof{}
if res != nil {
proof.FinalPair = res.FinalPair
Expand Down

0 comments on commit 460de35

Please sign in to comment.