mirror of
https://github.com/arnaucube/eth-kzg-ceremony-alt.git
synced 2026-01-08 15:01:30 +01:00
Updt Sequencer errormsg on try_contr on 200ok code
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
kzgceremony "github.com/arnaucube/eth-kzg-ceremony-alt"
|
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 {
|
if resp.StatusCode != http.StatusOK {
|
||||||
fmt.Println(string(body))
|
|
||||||
switch resp.StatusCode {
|
switch resp.StatusCode {
|
||||||
case http.StatusBadRequest:
|
case http.StatusBadRequest:
|
||||||
return nil, StatusWait, fmt.Errorf("call came to early. rate limited")
|
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)
|
err = ioutil.WriteFile("prevBatchContribution.json", body, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, StatusError, err
|
return nil, StatusError, err
|
||||||
}
|
}
|
||||||
bc := &kzgceremony.BatchContribution{}
|
bc := &kzgceremony.BatchContribution{}
|
||||||
err = json.Unmarshal(body, bc)
|
err = json.Unmarshal(body, bc)
|
||||||
return bc, StatusError, err
|
return bc, StatusProceed, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) PostAbortContribution(sessionID string) ([]byte, error) {
|
func (c *Client) PostAbortContribution(sessionID string) ([]byte, error) {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
red = color.New(color.FgRed)
|
||||||
redB = color.New(color.FgRed, color.Bold)
|
redB = color.New(color.FgRed, color.Bold)
|
||||||
cyan = color.New(color.FgCyan)
|
cyan = color.New(color.FgCyan)
|
||||||
cyanB = color.New(color.FgCyan, color.Bold)
|
cyanB = color.New(color.FgCyan, color.Bold)
|
||||||
@@ -114,6 +115,7 @@ func main() {
|
|||||||
t0 := time.Now()
|
t0 := time.Now()
|
||||||
newBatchContribution, err := prevBatchContribution.Contribute([]byte(randomness))
|
newBatchContribution, err := prevBatchContribution.Contribute([]byte(randomness))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println("error on prevBatchContribution.Contribute")
|
||||||
printErrAndExit(err)
|
printErrAndExit(err)
|
||||||
}
|
}
|
||||||
fmt.Println("Contribution computed in", time.Since(t0))
|
fmt.Println("Contribution computed in", time.Since(t0))
|
||||||
@@ -122,11 +124,13 @@ func main() {
|
|||||||
fmt.Println("storing contribution.json")
|
fmt.Println("storing contribution.json")
|
||||||
b, err := json.Marshal(newBatchContribution)
|
b, err := json.Marshal(newBatchContribution)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printErrAndExit(err)
|
// print error but do not exit
|
||||||
|
_, _ = red.Println(err)
|
||||||
}
|
}
|
||||||
err = ioutil.WriteFile("contribution.json", b, 0600)
|
err = ioutil.WriteFile("contribution.json", b, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printErrAndExit(err)
|
// print error but do not exit
|
||||||
|
_, _ = red.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// send contribution
|
// send contribution
|
||||||
@@ -174,7 +178,6 @@ func authGH(c *client.Client) client.MsgAuthCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func printErrAndExit(err error) {
|
func printErrAndExit(err error) {
|
||||||
red := color.New(color.FgRed)
|
|
||||||
_, _ = red.Println(err)
|
_, _ = red.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ func newEmptySRS(nG1, nG2 int) *SRS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func tau(round int, randomness []byte) *toxicWaste {
|
func tau(round int, randomness []byte) *toxicWaste {
|
||||||
val := blake2b.Sum256(randomness)
|
val := blake2b.Sum256(append(randomness, byte(round)))
|
||||||
tau := new(big.Int).Mod(
|
tau := new(big.Int).Mod(
|
||||||
new(big.Int).SetBytes(val[:]),
|
new(big.Int).SetBytes(val[:]),
|
||||||
g2.Q())
|
g2.Q())
|
||||||
@@ -181,7 +181,8 @@ func genProof(toxicWaste *toxicWaste, prevSRS, newSRS *SRS) *Proof {
|
|||||||
// byte slice, and returns the new SRS together with the Proof
|
// byte slice, and returns the new SRS together with the Proof
|
||||||
func Contribute(prevSRS *SRS, round int, randomness []byte) (*SRS, *Proof, error) {
|
func Contribute(prevSRS *SRS, round int, randomness []byte) (*SRS, *Proof, error) {
|
||||||
if len(randomness) < MinRandomnessLen {
|
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
|
// set tau from randomness
|
||||||
tw := tau(round, randomness)
|
tw := tau(round, randomness)
|
||||||
|
|||||||
@@ -57,6 +57,11 @@ func TestBatchContribution(t *testing.T) {
|
|||||||
bc.Contribute([]byte("1111111111111111111111111111111111111111111111111111111111111111"))
|
bc.Contribute([]byte("1111111111111111111111111111111111111111111111111111111111111111"))
|
||||||
c.Assert(err, qt.IsNil)
|
c.Assert(err, qt.IsNil)
|
||||||
|
|
||||||
|
c.Assert(len(nb.Contributions), qt.Equals, 4)
|
||||||
|
c.Assert(g2.Equal(nb.Contributions[0].PotPubKey, nb.Contributions[1].PotPubKey), qt.IsFalse)
|
||||||
|
c.Assert(g2.Equal(nb.Contributions[0].PotPubKey, nb.Contributions[2].PotPubKey), qt.IsFalse)
|
||||||
|
c.Assert(g2.Equal(nb.Contributions[0].PotPubKey, nb.Contributions[3].PotPubKey), qt.IsFalse)
|
||||||
|
|
||||||
_, err = json.Marshal(nb)
|
_, err = json.Marshal(nb)
|
||||||
c.Assert(err, qt.IsNil)
|
c.Assert(err, qt.IsNil)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user