Skip to content

Commit

Permalink
Fix Math Logic in Confirming Assertion By Challenge Win (#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
rauljordan authored Apr 2, 2024
1 parent 5bf006a commit f923fe0
Show file tree
Hide file tree
Showing 3 changed files with 324 additions and 270 deletions.
10 changes: 10 additions & 0 deletions challenge-manager/chain-watcher/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,14 @@ go_test(
name = "chain-watcher_test",
srcs = ["watcher_test.go"],
embed = [":chain-watcher"],
deps = [
"//chain-abstraction:protocol",
"//containers/option",
"//containers/threadsafe",
"//layer2-state-provider",
"//solgen/go/challengeV2gen",
"//testing/mocks",
"@com_github_ethereum_go_ethereum//common",
"@com_github_stretchr_testify//require",
],
)
24 changes: 19 additions & 5 deletions challenge-manager/chain-watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,11 +807,12 @@ func (w *Watcher) confirmAssertionByChallengeWinner(ctx context.Context, edge pr
log.Error("Could not get parent assertion creation info", log.Ctx{"error": err})
return
}
confirmableAtBlock := assertionCreationInfo.CreationBlock + parentCreationInfo.ConfirmPeriodBlocks
if edgeConfirmedAtBlock > confirmableAtBlock {
confirmableAtBlock = edgeConfirmedAtBlock
}
confirmableAtBlock += challengeGracePeriodBlocks
confirmableAtBlock := challengedAssertionConfirmableBlock(
parentCreationInfo,
edgeConfirmedAtBlock,
assertionCreationInfo,
challengeGracePeriodBlocks,
)

// Compute the number of blocks until we reach the assertion's
// deadline for confirmation.
Expand Down Expand Up @@ -845,6 +846,19 @@ func (w *Watcher) confirmAssertionByChallengeWinner(ctx context.Context, edge pr
}
}

func challengedAssertionConfirmableBlock(
parentInfo *protocol.AssertionCreatedInfo,
winningEdgeConfirmationBlock uint64,
info *protocol.AssertionCreatedInfo,
challengeGracePeriodBlocks uint64,
) uint64 {
confirmableAtBlock := info.CreationBlock + parentInfo.ConfirmPeriodBlocks
if winningEdgeConfirmationBlock+challengeGracePeriodBlocks > confirmableAtBlock {
confirmableAtBlock = winningEdgeConfirmationBlock + challengeGracePeriodBlocks
}
return confirmableAtBlock
}

type filterRange struct {
startBlockNum uint64
endBlockNum uint64
Expand Down
Loading

0 comments on commit f923fe0

Please sign in to comment.