Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
c5732fc5
Unverified
Commit
c5732fc5
authored
Sep 20, 2023
by
OptimismBot
Committed by
GitHub
Sep 20, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7316 from ethereum-optimism/refcell/constant-time-parent-lookup
fix(op-challenger): Constant Time Parent Lookup
parents
d8501a7f
9267b85f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
8 deletions
+14
-8
game.go
op-challenger/game/fault/types/game.go
+14
-8
No files found.
op-challenger/game/fault/types/game.go
View file @
c5732fc5
...
@@ -51,23 +51,30 @@ type extendedClaim struct {
...
@@ -51,23 +51,30 @@ type extendedClaim struct {
type
gameState
struct
{
type
gameState
struct
{
agreeWithProposedOutput
bool
agreeWithProposedOutput
bool
root
claimEntry
root
claimEntry
claims
map
[
claimEntry
]
*
extendedClaim
// contractIndicies maps a contract index to it's extended claim.
depth
uint64
// This is used to perform O(1) parent lookups.
contractIndicies
map
[
int
]
*
extendedClaim
// claims maps a claim entry to it's extended claim.
claims
map
[
claimEntry
]
*
extendedClaim
depth
uint64
}
}
// NewGameState returns a new game state.
// NewGameState returns a new game state.
// The provided [Claim] is used as the root node.
// The provided [Claim] is used as the root node.
func
NewGameState
(
agreeWithProposedOutput
bool
,
root
Claim
,
depth
uint64
)
*
gameState
{
func
NewGameState
(
agreeWithProposedOutput
bool
,
root
Claim
,
depth
uint64
)
*
gameState
{
claims
:=
make
(
map
[
claimEntry
]
*
extendedClaim
)
claims
:=
make
(
map
[
claimEntry
]
*
extendedClaim
)
parents
:=
make
(
map
[
int
]
*
extendedClaim
)
rootClaimEntry
:=
makeClaimEntry
(
root
)
rootClaimEntry
:=
makeClaimEntry
(
root
)
claims
[
rootClaimEntry
]
=
&
extendedClaim
{
claims
[
rootClaimEntry
]
=
&
extendedClaim
{
self
:
root
,
self
:
root
,
children
:
make
([]
claimEntry
,
0
),
children
:
make
([]
claimEntry
,
0
),
}
}
parents
[
root
.
ContractIndex
]
=
claims
[
rootClaimEntry
]
return
&
gameState
{
return
&
gameState
{
agreeWithProposedOutput
:
agreeWithProposedOutput
,
agreeWithProposedOutput
:
agreeWithProposedOutput
,
root
:
rootClaimEntry
,
root
:
rootClaimEntry
,
claims
:
claims
,
claims
:
claims
,
contractIndicies
:
parents
,
depth
:
depth
,
depth
:
depth
,
}
}
}
}
...
@@ -106,10 +113,12 @@ func (g *gameState) Put(claim Claim) error {
...
@@ -106,10 +113,12 @@ func (g *gameState) Put(claim Claim) error {
return
errors
.
New
(
"no parent claim"
)
return
errors
.
New
(
"no parent claim"
)
}
}
parent
.
children
=
append
(
parent
.
children
,
makeClaimEntry
(
claim
))
parent
.
children
=
append
(
parent
.
children
,
makeClaimEntry
(
claim
))
g
.
claims
[
makeClaimEntry
(
claim
)]
=
&
extendedClaim
{
claimWithExtension
:
=
&
extendedClaim
{
self
:
claim
,
self
:
claim
,
children
:
make
([]
claimEntry
,
0
),
children
:
make
([]
claimEntry
,
0
),
}
}
g
.
claims
[
makeClaimEntry
(
claim
)]
=
claimWithExtension
g
.
contractIndicies
[
claim
.
ContractIndex
]
=
claimWithExtension
return
nil
return
nil
}
}
...
@@ -150,11 +159,8 @@ func (g *gameState) getParent(claim Claim) *extendedClaim {
...
@@ -150,11 +159,8 @@ func (g *gameState) getParent(claim Claim) *extendedClaim {
if
claim
.
IsRoot
()
{
if
claim
.
IsRoot
()
{
return
nil
return
nil
}
}
// TODO(inphi): refactor gameState for faster parent lookups
if
parent
,
ok
:=
g
.
contractIndicies
[
claim
.
ParentContractIndex
];
ok
{
for
_
,
c
:=
range
g
.
claims
{
return
parent
if
c
.
self
.
ContractIndex
==
claim
.
ParentContractIndex
{
return
c
}
}
}
return
nil
return
nil
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment