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

Commit

Permalink
Improve docs around signature publication delays
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-zimnoch committed Nov 23, 2020
1 parent 58bb77b commit 73cc0ff
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var logger = log.Logger("keep-ecdsa")

const (
// Determines the delay which should be preserved before retrying
// actions within the signing process.
// actions within the key generation and signing process.
retryDelay = 1 * time.Second

// Number of blocks which should elapse before confirming
Expand All @@ -39,7 +39,7 @@ const (
// Used to calculate the publication delay factor for the given signer index
// to avoid all signers publishing the same signature for given keep at the
// same time.
signerPublicationDelayStep = 5 * time.Minute
signaturePublicationDelayStep = 5 * time.Minute
)

// Node holds interfaces to interact with the blockchain and network messages
Expand Down Expand Up @@ -320,7 +320,7 @@ func (n *Node) publishSignature(
digest [32]byte,
signature *ecdsa.Signature,
) error {
n.waitSignerPublicationDelay(keepAddress)
n.waitSignaturePublicationDelay(keepAddress)

attemptCounter := 0
for {
Expand Down Expand Up @@ -433,14 +433,17 @@ func (n *Node) publishSignature(
}
}

func (n *Node) waitSignerPublicationDelay(
// waitSignaturePublicationDelay waits a certain amount of time appropriately
// for the given signer index to avoid all signers publishing the same signature
// for given keep at the same time.
func (n *Node) waitSignaturePublicationDelay(
keepAddress common.Address,
) {
signerIndex, err := n.getSignerIndex(keepAddress)
if err != nil {
logger.Error(
"could not determine signer publication delay for keep [%s]: "+
"[%v]; signer publication delay will not be preserved",
logger.Errorf(
"could not determine signature publication delay for keep [%s]: "+
"[%v]; the signature publication will not be delayed",
keepAddress.String(),
err,
)
Expand All @@ -449,17 +452,16 @@ func (n *Node) waitSignerPublicationDelay(

// just in case this function is not invoked in the right context
if signerIndex < 0 {
logger.Error(
"could not determine signer publication delay for keep [%s]: "+
"[signer index is less than zero]; "+
"signer publication delay will not be preserved",
logger.Errorf(
"could not determine signature publication delay for keep [%s], "+
"signer index is less than zero; the signature publication "+
"will not be delayed",
keepAddress.String(),
err,
)
return
}

delay := time.Duration(signerIndex) * signerPublicationDelayStep
delay := time.Duration(signerIndex) * signaturePublicationDelayStep

logger.Infof(
"waiting [%v] before publishing signature for keep [%s]",
Expand Down

0 comments on commit 73cc0ff

Please sign in to comment.