Commit 62211b63 authored by Loïck Bonniot's avatar Loïck Bonniot

[p] Fix ready sign timeout

parent be66c841
Pipeline #2290 passed with stage
......@@ -21,6 +21,11 @@ type readySignal struct {
sequence []uint32 // Only used to broadcast signature sequence
}
// ReadySignTimeout is the delay users have to confirm the signature.
// A high value is not recommended, as there is no way to create any other signature on the same contract before the timeout
// if a client has connection issues.
var ReadySignTimeout = time.Minute
// ReadySign is the last job of the platform before the signature can occur.
// When a new client is ready, it joins a waitingGroup and waits for a master broadcast announcing that everybody is ready.
//
......@@ -45,6 +50,7 @@ func ReadySign(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, ctx *contex
rooms.Broadcast(roomID, &readySignal{data: cn})
// Wait for ready signal
timeout := time.After(ReadySignTimeout)
for {
select {
case signal, ok := <-channel:
......@@ -67,7 +73,7 @@ func ReadySign(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, ctx *contex
case <-(*ctx).Done(): // Client's disconnection
rooms.Unjoin(roomID, channel)
return &api.LaunchSignature{ErrorCode: &api.ErrorCode{Code: api.ErrorCode_INVARG}}
case <-time.After(time.Minute): // Someone has not confirmed the signature within the delay
case <-timeout: // Someone has not confirmed the signature within the delay
rooms.Unjoin(roomID, channel)
return &api.LaunchSignature{ErrorCode: &api.ErrorCode{Code: api.ErrorCode_TIMEOUT, Message: "timeout for ready signal"}}
}
......@@ -102,6 +108,7 @@ func masterReadyRoutine(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, co
signersReady := make([]bool, len(contract.Signers))
work := true
timeout := time.After(ReadySignTimeout)
for work {
select {
case signal, ok := <-channel:
......@@ -120,7 +127,7 @@ func masterReadyRoutine(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, co
})
work = false
}
case <-time.After(10 * time.Minute):
case <-timeout:
work = false
}
}
......
......@@ -58,13 +58,13 @@ func startPlatform(tmpDir string) (platform, ttp, demo *exec.Cmd, stop func(), c
time.Sleep(time.Second)
// Start platform
platform = exec.Command(path, "--db", dbURI, "--path", dir, "-p", testPort, "--ttps", ttpsPath, "-d", "localhost:9099", "-v", "start")
platform = exec.Command(path, "--db", dbURI, "--path", dir, "-p", testPort, "--ttps", ttpsPath, "-d", "localhost:9099", "start")
platform.Stdout = os.Stdout
platform.Stderr = os.Stderr
err = platform.Start()
// Start TTP
ttp = exec.Command(ttpPath, "--db", dbURI, "--port", "9098", "-d", "localhost:9099", "-v", "start")
ttp = exec.Command(ttpPath, "--db", dbURI, "--port", "9098", "-d", "localhost:9099", "start")
ttp.Dir = filepath.Join(dir, "ttp")
ttp.Stdout = os.Stdout
ttp.Stderr = os.Stderr
......@@ -107,7 +107,7 @@ func createClient(tmpDir string, ca []byte, port int) (*exec.Cmd, error) {
// Prepare the client command.
// The last argument is up to you!
cmd := exec.Command(path, "--ca", caPath, "--cert", certPath, "--host", "127.0.0.1:"+testPort, "--key", keyPath, "--port", strconv.Itoa(port), "--timeout", "3s", "-v", "-d", "localhost:9099")
cmd := exec.Command(path, "--ca", caPath, "--cert", certPath, "--host", "127.0.0.1:"+testPort, "--key", keyPath, "--port", strconv.Itoa(port), "--timeout", "3s", "-d", "localhost:9099")
return cmd, nil
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment