From 8f62ebe6ab68c1fa6463f1c2ac7c3916a8a94b43 Mon Sep 17 00:00:00 2001 From: arnaucube Date: Sat, 14 Jan 2023 23:31:21 +0100 Subject: [PATCH] Updt Sequencer errormsg on try_contr on 200ok code --- client/req.go | 17 +++++++++++++++-- cmd/cmd.go | 9 ++++++--- powersoftau.go | 3 ++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/client/req.go b/client/req.go index 903ff94..6a921d4 100644 --- a/client/req.go +++ b/client/req.go @@ -7,6 +7,7 @@ import ( "io" "io/ioutil" "net/http" + "strings" kzgceremony "github.com/arnaucube/eth-kzg-ceremony-alt" ) @@ -155,7 +156,6 @@ func (c *Client) PostTryContribute(sessionID string) (*kzgceremony.BatchContribu } if resp.StatusCode != http.StatusOK { - fmt.Println(string(body)) switch resp.StatusCode { case http.StatusBadRequest: return nil, StatusWait, fmt.Errorf("call came to early. rate limited") @@ -166,13 +166,26 @@ func (c *Client) PostTryContribute(sessionID string) (*kzgceremony.BatchContribu } } + // note: a 200 (Ok) code by the Sequencer on try_contribute doesn't + // mean that the contributor has been selected. It could mean that the + // Sequencer is returning the error AnotherContributionInProgress in a + // json msg (see + // https://github.com/ethereum/kzg-ceremony-sequencer/blob/2538f2f08d4db880d7f4608e964df0b695bc7d2f/src/api/v1/error_response.rs#L105 + // ) + + // check if body contains the error message of "another contribution in + // progress" (despite http statuscode being 200 (Ok)) + if strings.Contains(string(body), "another contribution in progress") { + return nil, StatusWait, fmt.Errorf("another contribution in progress") + } + err = ioutil.WriteFile("prevBatchContribution.json", body, 0600) if err != nil { return nil, StatusError, err } bc := &kzgceremony.BatchContribution{} err = json.Unmarshal(body, bc) - return bc, StatusError, err + return bc, StatusProceed, err } func (c *Client) PostAbortContribution(sessionID string) ([]byte, error) { diff --git a/cmd/cmd.go b/cmd/cmd.go index 93a6ce8..d27e676 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -16,6 +16,7 @@ import ( ) var ( + red = color.New(color.FgRed) redB = color.New(color.FgRed, color.Bold) cyan = color.New(color.FgCyan) cyanB = color.New(color.FgCyan, color.Bold) @@ -114,6 +115,7 @@ func main() { t0 := time.Now() newBatchContribution, err := prevBatchContribution.Contribute([]byte(randomness)) if err != nil { + fmt.Println("error on prevBatchContribution.Contribute") printErrAndExit(err) } fmt.Println("Contribution computed in", time.Since(t0)) @@ -122,11 +124,13 @@ func main() { fmt.Println("storing contribution.json") b, err := json.Marshal(newBatchContribution) if err != nil { - printErrAndExit(err) + // print error but do not exit + _, _ = red.Println(err) } err = ioutil.WriteFile("contribution.json", b, 0600) if err != nil { - printErrAndExit(err) + // print error but do not exit + _, _ = red.Println(err) } // send contribution @@ -174,7 +178,6 @@ func authGH(c *client.Client) client.MsgAuthCallback { } func printErrAndExit(err error) { - red := color.New(color.FgRed) _, _ = red.Println(err) os.Exit(1) } diff --git a/powersoftau.go b/powersoftau.go index e455904..ef20365 100644 --- a/powersoftau.go +++ b/powersoftau.go @@ -181,7 +181,8 @@ func genProof(toxicWaste *toxicWaste, prevSRS, newSRS *SRS) *Proof { // byte slice, and returns the new SRS together with the Proof func Contribute(prevSRS *SRS, round int, randomness []byte) (*SRS, *Proof, error) { if len(randomness) < MinRandomnessLen { - return nil, nil, fmt.Errorf("err randomness") // WIP + return nil, nil, fmt.Errorf("err: randomness length < %d", + MinRandomnessLen) } // set tau from randomness tw := tau(round, randomness)