Skip to content

Commit 2b348b9

Browse files
authored
fix: add per process timeouts (#112)
<!--- Provide a general summary of your changes in the Title above --> ## Description <!--- Describe your changes in detail --> ## Related Issue Or Context <!--- If suggesting a new feature or change, please discuss it in an issue first --> <!--- If fixing a bug, there should be an issue describing it with steps to reproduce --> <!--- Otherwise, describe context and motivation for change herre --> Closes: #<issue> ## How Has This Been Tested? Testing details. <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation ## Checklist: <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have ensured that all acceptance criteria (or expected behavior) from issue are met - [ ] I have updated the documentation locally and in docs. - [ ] I have added tests to cover my changes. - [ ] I have ensured that all the checks are passing and green, I've signed the CLA bot
1 parent 34c2600 commit 2b348b9

File tree

7 files changed

+15
-6
lines changed

7 files changed

+15
-6
lines changed

tss/coordinator.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
var (
2626
initiatePeriod = 1 * time.Second
27-
tssTimeout = 30 * time.Second
2827
)
2928

3029
type TssProcess interface {
@@ -35,6 +34,7 @@ type TssProcess interface {
3534
StartParams(readyPeers []peer.ID) []byte
3635
SessionID() string
3736
ValidCoordinators() []peer.ID
37+
Timeout() time.Duration
3838
}
3939

4040
type Coordinator struct {
@@ -46,7 +46,6 @@ type Coordinator struct {
4646
processLock sync.Mutex
4747

4848
CoordinatorTimeout time.Duration
49-
TssTimeout time.Duration
5049
InitiatePeriod time.Duration
5150
}
5251

@@ -62,7 +61,6 @@ func NewCoordinator(
6261

6362
pendingProcesses: make(map[string]bool),
6463

65-
TssTimeout: tssTimeout,
6664
InitiatePeriod: initiatePeriod,
6765
}
6866
}
@@ -162,7 +160,7 @@ func (c *Coordinator) handleError(ctx context.Context, err error, tssProcesses [
162160
func (c *Coordinator) watchExecution(ctx context.Context, tssProcess TssProcess, coordinator peer.ID, cancel context.CancelFunc) error {
163161
failChn := make(chan *comm.WrappedMessage)
164162
subscriptionID := c.communication.Subscribe(tssProcess.SessionID(), comm.TssFailMsg, failChn)
165-
ticker := time.NewTicker(c.TssTimeout)
163+
ticker := time.NewTicker(tssProcess.Timeout())
166164
defer func() {
167165
ticker.Stop()
168166
c.communication.UnSubscribe(subscriptionID)

tss/ecdsa/common/base.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"math/big"
1010
"runtime/debug"
11+
"time"
1112

1213
"github.com/binance-chain/tss-lib/tss"
1314
"github.com/libp2p/go-libp2p/core/host"
@@ -33,6 +34,7 @@ type BaseTss struct {
3334
Communication comm.Communication
3435
Peers []peer.ID
3536
Log zerolog.Logger
37+
TssTimeout time.Duration
3638

3739
Cancel context.CancelFunc
3840
}
@@ -128,3 +130,7 @@ func (b *BaseTss) BroadcastPeers(msg tss.Message) ([]peer.ID, error) {
128130
func (b *BaseTss) SessionID() string {
129131
return b.SID
130132
}
133+
134+
func (b *BaseTss) Timeout() time.Duration {
135+
return b.TssTimeout
136+
}

tss/ecdsa/keygen/keygen.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"errors"
99
"math/big"
10+
"time"
1011

1112
"github.com/binance-chain/tss-lib/ecdsa/keygen"
1213
"github.com/binance-chain/tss-lib/tss"
@@ -51,6 +52,7 @@ func NewKeygen(
5152
SID: sessionID,
5253
Log: log.With().Str("SessionID", sessionID).Str("Process", "keygen").Logger(),
5354
Cancel: func() {},
55+
TssTimeout: time.Minute * 10,
5456
},
5557
storer: storer,
5658
threshold: threshold,

tss/ecdsa/keygen/keygen_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (s *KeygenTestSuite) Test_KeygenTimeout() {
7777
keygen := keygen.NewKeygen("keygen2", s.Threshold, host, &communication, s.MockECDSAStorer)
7878
electorFactory := elector.NewCoordinatorElectorFactory(host, s.BullyConfig)
7979
coordinator := tss.NewCoordinator(host, &communication, electorFactory)
80-
coordinator.TssTimeout = time.Millisecond
80+
keygen.TssTimeout = time.Millisecond
8181
coordinators = append(coordinators, coordinator)
8282
processes = append(processes, keygen)
8383
}

tss/ecdsa/resharing/resharing.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"encoding/json"
99
"errors"
1010
"math/big"
11+
"time"
1112

1213
"github.com/binance-chain/tss-lib/ecdsa/keygen"
1314
"github.com/binance-chain/tss-lib/ecdsa/resharing"
@@ -68,6 +69,7 @@ func NewResharing(
6869
SID: sessionID,
6970
Log: log.With().Str("SessionID", sessionID).Str("Process", "resharing").Logger(),
7071
Cancel: func() {},
72+
TssTimeout: time.Minute * 10,
7173
},
7274
key: key,
7375
storer: storer,

tss/ecdsa/signing/signing.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func NewSigning(
7474
SID: sessionID,
7575
Log: log.With().Str("SessionID", sessionID).Str("messageID", messageID).Str("Process", "signing").Logger(),
7676
Cancel: func() {},
77+
TssTimeout: time.Second * 30,
7778
},
7879
key: key,
7980
msg: msg,

tss/ecdsa/signing/signing_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (s *SigningTestSuite) Test_SigningTimeout() {
156156
}
157157
electorFactory := elector.NewCoordinatorElectorFactory(host, s.BullyConfig)
158158
coordinator := tss.NewCoordinator(host, &communication, electorFactory)
159-
coordinator.TssTimeout = time.Nanosecond
159+
signing.TssTimeout = time.Nanosecond
160160
coordinators = append(coordinators, coordinator)
161161
processes = append(processes, signing)
162162
}

0 commit comments

Comments
 (0)