Skip to content
This repository was archived by the owner on May 22, 2023. It is now read-only.

Commit a65145c

Browse files
Implement signer publication delays
Each signer should wait an amount of time before publishing the signature for given keep. The exact amount of time is determined basing on signer index. This should prevent signers to publish the signature in the same time and burn gas for transactions which will be reverted.
1 parent 52e1e6f commit a65145c

2 files changed

Lines changed: 65 additions & 3 deletions

File tree

pkg/extensions/tbtc/tbtc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,11 @@ func (t *tbtc) getSignerActionDelay(
879879
return 0, err
880880
}
881881

882+
// just in case this function is not invoked in the right context
883+
if signerIndex < 0 {
884+
return 0, fmt.Errorf("signer index is less than zero")
885+
}
886+
882887
return time.Duration(signerIndex) * t.signerActionDelayStep, nil
883888
}
884889

pkg/node/node.go

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,20 @@ import (
2727

2828
var logger = log.Logger("keep-ecdsa")
2929

30-
const monitorKeepPublicKeySubmissionTimeout = 30 * time.Minute
31-
const retryDelay = 1 * time.Second
32-
const blockConfirmations = uint64(12)
30+
const (
31+
// Determines the delay which should be preserved before retrying
32+
// actions within the signing process.
33+
retryDelay = 1 * time.Second
34+
35+
// Number of blocks which should elapse before confirming
36+
// the given chain state expectations.
37+
blockConfirmations = uint64(12)
38+
39+
// Used to calculate the publication delay factor for the given signer index
40+
// to avoid all signers publishing the same signature for given keep at the
41+
// same time.
42+
signerPublicationDelayStep = 5 * time.Minute
43+
)
3344

3445
// Node holds interfaces to interact with the blockchain and network messages
3546
// transport layer.
@@ -327,6 +338,8 @@ func (n *Node) publishSignature(
327338
digest [32]byte,
328339
signature *ecdsa.Signature,
329340
) error {
341+
n.waitSignerPublicationDelay(keepAddress)
342+
330343
attemptCounter := 0
331344
for {
332345
attemptCounter++
@@ -438,6 +451,50 @@ func (n *Node) publishSignature(
438451
}
439452
}
440453

454+
func (n *Node) waitSignerPublicationDelay(
455+
keepAddress common.Address,
456+
) {
457+
signerIndex, err := n.getSignerIndex(keepAddress)
458+
if err != nil {
459+
logger.Error(
460+
"could not determine signer publication delay: [%v]; "+
461+
"signer publication delay will not be preserved",
462+
err,
463+
)
464+
return
465+
}
466+
467+
// just in case this function is not invoked in the right context
468+
if signerIndex < 0 {
469+
logger.Error(
470+
"could not determine signer publication delay: "+
471+
"[signer index is less than zero]; "+
472+
"signer publication delay will not be preserved",
473+
err,
474+
)
475+
return
476+
}
477+
478+
delay := time.Duration(signerIndex) * signerPublicationDelayStep
479+
480+
time.Sleep(delay)
481+
}
482+
483+
func (n *Node) getSignerIndex(keepAddress common.Address) (int, error) {
484+
members, err := n.ethereumChain.GetMembers(keepAddress)
485+
if err != nil {
486+
return -1, err
487+
}
488+
489+
for index, member := range members {
490+
if member == n.ethereumChain.Address() {
491+
return index, nil
492+
}
493+
}
494+
495+
return -1, nil
496+
}
497+
441498
func (n *Node) waitForSignature(
442499
keepAddress common.Address,
443500
digest [32]byte,

0 commit comments

Comments
 (0)