-
Notifications
You must be signed in to change notification settings - Fork 103
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
Add Proof tx submission enhancement/bug #1574
Changes from 4 commits
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 |
---|---|---|
|
@@ -50,13 +50,19 @@ func (k Keeper) SendProofTx(ctx sdk.Ctx, n client.Client, node *pc.PocketNode, p | |
ctx.Logger().Error(fmt.Sprintf("could not delete evidence is not sealed, could cause a relay leak: %s", err.Error())) | ||
} | ||
} | ||
if evidence.NumOfProofs != claim.TotalProofs { | ||
|
||
// In the case of evidence.NumOfProofs < claim.TotalProofs, we don't submit a proof because we cannot generate a valid merkle proof with a smaller number of relays. | ||
nodiesBlade marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// In the case of evidence.NumOfProofs > claim.TotalProofs, we truncate proofs of the evidence (that happens inside GenerateMerkleProof) and submit a proof. | ||
if evidence.NumOfProofs < claim.TotalProofs { | ||
Olshansk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
err := pc.DeleteEvidence(claim.SessionHeader, claim.EvidenceType, node.EvidenceStore) | ||
ctx.Logger().Error(fmt.Sprintf("evidence num of proofs does not equal claim total proofs... possible relay leak")) | ||
ctx.Logger().Error(fmt.Sprintf("evidence num of proofs is less than submitted claim's total proofs, can't generate merkle proof")) | ||
if err != nil { | ||
ctx.Logger().Error(fmt.Sprintf("evidence num of proofs does not equal claim total proofs... possible relay leak: %s", err.Error())) | ||
ctx.Logger().Error(fmt.Sprintf("evidence num of proofs is less than submitted claim's total proofs, can't generate merkle proof: %s", err.Error())) | ||
} | ||
// If this is the case, delete the evidence and continue iterating through the claims to submit. | ||
nodiesBlade marked this conversation as resolved.
Show resolved
Hide resolved
|
||
continue | ||
} | ||
|
||
// get the session context | ||
sessionCtx, err := ctx.PrevCtx(claim.SessionHeader.SessionBlockHeight) | ||
if err != nil { | ||
|
@@ -73,8 +79,24 @@ func (k Keeper) SendProofTx(ctx sdk.Ctx, n client.Client, node *pc.PocketNode, p | |
if !found { | ||
ctx.Logger().Error(fmt.Sprintf("an error occurred creating the proof transaction with app %s not found with evidence %v", evidence.ApplicationPubKey, evidence)) | ||
} | ||
|
||
// There is a potential race condition where the evidence is not sealed while submitting a claim | ||
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. Do you have any idea why this wasn't a major concern in the past? 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. Generally whenever the claim is sealed, relays stop coming in and so there is some non deterministic timing in which the race condition could happen. If relays keep coming in (i.e session rollover), the problem becomes more prominent. We did find some on chain tx's to show that this did periodically happen even without session rollover though. 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.
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. Was running into some issues but reached out to poktscan here: https://discord.com/channels/854406364931686400/950799595171086377/1131367539667107872 |
||
// Allowing for more relays to enter the evidence claim, and whenever a proof is generated, it will | ||
// result in an incorrect merkle proof from being generated. | ||
nodiesBlade marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// In order to allow for best-effort process to submit a proof for the claim the service submitted | ||
nodiesBlade marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// 1. Generate a merkle proof for claim's total proof if proof count doesn't exceed max relays per session | ||
// 2. Otherwise, fall back to max relays per session | ||
relaysCompleted := claim.TotalProofs | ||
|
||
maxSessionRelays := pc.MaxPossibleRelays(app, k.SessionNodeCount(sessionCtx)).Int64() | ||
|
||
// If the relays completed is more than what protocol will allow, set it to the max. | ||
if relaysCompleted > maxSessionRelays { | ||
relaysCompleted = maxSessionRelays | ||
} | ||
|
||
// get the merkle proof object for the pseudorandom index | ||
mProof, leaf := evidence.GenerateMerkleProof(claim.SessionHeader.SessionBlockHeight, int(index), pc.MaxPossibleRelays(app, k.SessionNodeCount(sessionCtx)).Int64()) | ||
mProof, leaf := evidence.GenerateMerkleProof(claim.SessionHeader.SessionBlockHeight, int(index), relaysCompleted) | ||
// if prevalidation on, then pre-validate | ||
if pc.GlobalPocketConfig.ProofPrevalidation { | ||
// validate level count on claim by total relays | ||
|
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.
@PoktBlade Have you looked into the difficulty of adding a unit test for this? I realize it's not easy, but just wanted to make sure that we at least put effort into it.
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 can look into it some more for sanity purposes.
In regards to some other testing, @jorgecuesta did run it live in his fleet, and saw that there weren't any invalid proofs being submitted on chain. This was a dramatic decrease (0 invalid proofs) vs what he saw before the changes.
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.
Update: I wrote some integration tests last night based off
TestClaimProtoTx
, but it turns out the test for this was already broken.. The reason why we don't see them when running tests, these tests are skipped whenever -s flag is passed.Anyhow.. will see if I can fix the initial broken tests (seems like a crashing error when submitting proofs, due to AIOB)
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.
@PoktBlade Bump on existing tests and/or new tests.