-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DKG saga, part 4: On-chain integration for TBTC DKG #3427
Changes from 1 commit
91b0092
93a7b8a
0c671c7
6bfe7ad
f09b904
882ba38
67b3a70
eab2ec2
1539b48
169a8d4
622e8a9
3fa8fba
138775f
bf678e9
d65e3c5
8d48b64
dd172b5
b81ae58
5d252d7
0cb6d2e
da7d0f7
28e7d58
c1c920f
47a5ea1
0e55626
3f6dc83
9904287
8f30947
7c58a6b
bfd5cfb
0a8eef3
18429dc
436b114
07d4b58
cb19259
fdbd05f
d78aa84
4a8edfa
ca63930
d659537
d05c5c0
9ea6adf
b70ccb8
f9c0d1b
349bdfa
f341e4e
de2d182
a630a63
be0aac8
55d01d6
9536de6
70afe95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,11 @@ const ( | |
// respected by the given member to avoid all members approving the same | ||
// DKG result at the same time. | ||
dkgResultApprovalDelayStepBlocks = 5 | ||
pdyraga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// dkgResultChallengeConfirmationBlocks determines the block length of | ||
// the confirmation period that is preserved after a DKG result challenge | ||
// submission. Once the period elapses, the DKG state is checked to confirm | ||
// the challenge was accepted successfully. | ||
dkgResultChallengeConfirmationBlocks = 20 | ||
) | ||
|
||
// dkgExecutor is a component responsible for the full execution of ECDSA | ||
|
@@ -513,6 +518,8 @@ func (de *dkgExecutor) executeDkgValidation( | |
zap.String("resultHash", fmt.Sprintf("0x%x", resultHash)), | ||
) | ||
|
||
dkgLogger.Infof("starting DKG result validation") | ||
|
||
isValid, err := de.chain.IsDKGResultValid(result) | ||
if err != nil { | ||
dkgLogger.Errorf("cannot validate DKG result: [%v]", err) | ||
|
@@ -522,15 +529,61 @@ func (de *dkgExecutor) executeDkgValidation( | |
if !isValid { | ||
dkgLogger.Infof("DKG result is invalid") | ||
|
||
err = de.chain.ChallengeDKGResult(result) | ||
if err != nil { | ||
dkgLogger.Errorf("cannot challenge invalid DKG result: [%v]", err) | ||
return | ||
} | ||
i := uint64(0) | ||
|
||
dkgLogger.Infof("challenging invalid DKG result") | ||
// Challenges are done along with DKG state confirmations. This is | ||
// needed to handle chain reorgs that may wipe out the block holding | ||
// the challenge transaction. The state check done upon the confirmation | ||
// block makes sure the submitted challenge changed the DKG state | ||
// as expected. If the DKG state was not changed, the challenge is | ||
// re-submitted. | ||
for { | ||
i++ | ||
|
||
return | ||
err = de.chain.ChallengeDKGResult(result) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case we run this loop one more time, we do not know if the Captured it in a separate issue: #3462 |
||
if err != nil { | ||
dkgLogger.Errorf( | ||
"cannot challenge invalid DKG result: [%v]", | ||
err, | ||
) | ||
return | ||
} | ||
|
||
confirmationBlock := submissionBlock + | ||
(i * dkgResultChallengeConfirmationBlocks) | ||
|
||
dkgLogger.Infof( | ||
"challenging invalid DKG result; waiting for "+ | ||
"block [%v] to confirm DKG state", | ||
confirmationBlock, | ||
) | ||
|
||
err := de.waitForBlockFn(context.Background(), confirmationBlock) | ||
if err != nil { | ||
dkgLogger.Errorf( | ||
"error while waiting for challenge confirmation: [%v]", | ||
err, | ||
) | ||
return | ||
} | ||
|
||
state, err := de.chain.GetDKGState() | ||
if err != nil { | ||
dkgLogger.Errorf("cannot check DKG state: [%v]", err) | ||
return | ||
} | ||
|
||
if state != Challenge { | ||
dkgLogger.Infof( | ||
"invalid DKG result challenged successfully", | ||
) | ||
return | ||
} | ||
|
||
dkgLogger.Infof( | ||
"invalid DKG result still not challenged; retrying", | ||
) | ||
Comment on lines
+593
to
+595
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This log may not always be true. We could have another result submitted in the meantime and challenged. I think we should remove this log from here and move it to the beginning of the loop after we check that the result we are challenging is the last one submitted. Captured it in a separate issue: #3462 |
||
} | ||
} | ||
|
||
dkgLogger.Infof("DKG result is valid") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,20 +139,25 @@ func Initialize( | |
_ = chain.OnDKGResultSubmitted(func(event *DKGResultSubmittedEvent) { | ||
go func() { | ||
if ok := deduplicator.notifyDKGResultSubmitted( | ||
event.Seed, | ||
event.ResultHash, | ||
event.BlockNumber, | ||
); !ok { | ||
logger.Warnf( | ||
"DKG result with hash [0x%x] and starting "+ | ||
"block [%v] has been already processed", | ||
"Result with hash [0x%x] for DKG with seed [0x%x] "+ | ||
"and starting block [%v] has been already processed", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a starting block right? This is the block when the Should this log say |
||
event.ResultHash, | ||
event.Seed, | ||
event.BlockNumber, | ||
) | ||
return | ||
} | ||
|
||
logger.Infof( | ||
"DKG result with hash [0x%x] submitted at block [%v]", | ||
"Result with hash [0x%x] for DKG with seed [0x%x] "+ | ||
"submitted at block [%v]", | ||
event.ResultHash, | ||
event.Seed, | ||
event.BlockNumber, | ||
) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the current deduplication logic makes a lot of sense given the challenges but we should make it crystal-clear in the docs in case future-us will ever think about removing the result block from the hash. Something like: