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
eabe7fd3
Commit
eabe7fd3
authored
Jun 28, 2023
by
Joshua Gutow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-challenger: Add in memory orchestrator
parent
9989997c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
130 additions
and
2 deletions
+130
-2
full.go
op-challenger/fault/cmd/examples/full.go
+38
-0
main.go
op-challenger/fault/cmd/main.go
+2
-2
orchestrator.go
op-challenger/fault/orchestrator.go
+87
-0
solver.go
op-challenger/fault/solver.go
+3
-0
No files found.
op-challenger/fault/cmd/examples/full.go
0 → 100644
View file @
eabe7fd3
package
examples
import
(
"os"
"github.com/ethereum-optimism/optimism/op-challenger/fault"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
)
func
FullGame
()
{
log
.
Root
()
.
SetHandler
(
log
.
LvlFilterHandler
(
log
.
LvlInfo
,
log
.
StreamHandler
(
os
.
Stdout
,
log
.
TerminalFormat
(
true
))),
)
canonical
:=
"abcdefgh"
disputed
:=
"abcdexyz"
maxDepth
:=
uint64
(
3
)
canonicalProvider
:=
fault
.
NewAlphabetProvider
(
canonical
,
maxDepth
)
disputedProvider
:=
fault
.
NewAlphabetProvider
(
disputed
,
maxDepth
)
root
:=
fault
.
Claim
{
ClaimData
:
fault
.
ClaimData
{
Value
:
common
.
HexToHash
(
"0x000000000000000000000000000000000000000000000000000000000000077a"
),
Position
:
fault
.
NewPosition
(
0
,
0
),
},
}
counter
:=
fault
.
Claim
{
ClaimData
:
fault
.
ClaimData
{
Value
:
common
.
HexToHash
(
"0x0000000000000000000000000000000000000000000000000000000000000364"
),
Position
:
fault
.
NewPosition
(
1
,
0
),
},
Parent
:
root
.
ClaimData
,
}
o
:=
fault
.
NewOrchestrator
(
maxDepth
,
[]
fault
.
TraceProvider
{
canonicalProvider
,
disputedProvider
},
[]
string
{
"charlie"
,
"mallory"
},
root
,
counter
)
o
.
Start
()
}
op-challenger/fault/cmd/main.go
View file @
eabe7fd3
...
...
@@ -5,8 +5,8 @@ import (
)
func
main
()
{
examples
.
SolverExampleOn
e
()
examples
.
FullGam
e
()
// examples.SolverExampleOne()
// examples.PositionExampleOne()
// examples.PositionExampleTwo()
}
op-challenger/fault/orchestrator.go
0 → 100644
View file @
eabe7fd3
package
fault
import
(
"context"
"fmt"
"os"
"time"
"github.com/ethereum/go-ethereum/log"
)
type
Orchestrator
struct
{
agents
[]
Agent
outputChs
[]
chan
Claim
responses
chan
Claim
}
func
NewOrchestrator
(
maxDepth
uint64
,
traces
[]
TraceProvider
,
names
[]
string
,
root
,
counter
Claim
)
Orchestrator
{
o
:=
Orchestrator
{
responses
:
make
(
chan
Claim
,
100
),
outputChs
:
make
([]
chan
Claim
,
len
(
traces
)),
agents
:
make
([]
Agent
,
len
(
traces
)),
}
PrettyPrintAlphabetClaim
(
"init"
,
root
)
PrettyPrintAlphabetClaim
(
"init"
,
counter
)
for
i
,
trace
:=
range
traces
{
game
:=
NewGameState
(
root
)
_
=
game
.
Put
(
counter
)
o
.
agents
[
i
]
=
NewAgent
(
game
,
int
(
maxDepth
),
trace
,
&
o
,
log
.
New
(
"role"
,
names
[
i
]))
o
.
outputChs
[
i
]
=
make
(
chan
Claim
)
}
return
o
}
func
(
o
*
Orchestrator
)
Respond
(
_
context
.
Context
,
response
Claim
)
error
{
o
.
responses
<-
response
return
nil
}
func
(
o
*
Orchestrator
)
Start
()
{
for
i
:=
0
;
i
<
len
(
o
.
agents
);
i
++
{
go
runAgent
(
&
o
.
agents
[
i
],
o
.
outputChs
[
i
])
}
o
.
responderThread
()
}
func
runAgent
(
agent
*
Agent
,
claimCh
<-
chan
Claim
)
{
for
{
agent
.
PerformActions
()
// Note: Should drain the channel here
claim
:=
<-
claimCh
_
=
agent
.
AddClaim
(
claim
)
}
}
func
(
o
*
Orchestrator
)
responderThread
()
{
timer
:=
time
.
NewTimer
(
200
*
time
.
Millisecond
)
defer
timer
.
Stop
()
for
{
select
{
case
resp
:=
<-
o
.
responses
:
timer
.
Reset
(
200
*
time
.
Millisecond
)
for
_
,
ch
:=
range
o
.
outputChs
{
// Copy it. Should be immutable, but be sure.
resp
:=
resp
ch
<-
resp
}
case
<-
timer
.
C
:
os
.
Exit
(
0
)
}
}
}
func
PrettyPrintAlphabetClaim
(
name
string
,
claim
Claim
)
{
value
:=
claim
.
Value
idx
:=
value
[
30
]
letter
:=
value
[
31
]
par_letter
:=
claim
.
Parent
.
Value
[
31
]
if
claim
.
IsRoot
()
{
fmt
.
Printf
(
"%s
\t
trace %v letter %c
\n
"
,
name
,
idx
,
letter
)
}
else
{
fmt
.
Printf
(
"%s
\t
trace %v letter %c is attack %v parent letter %c
\n
"
,
name
,
idx
,
letter
,
!
claim
.
DefendsParent
(),
par_letter
)
}
}
op-challenger/fault/solver.go
View file @
eabe7fd3
...
...
@@ -31,6 +31,9 @@ func (s *Solver) NextMove(claim Claim) (*Claim, error) {
if
err
!=
nil
{
return
nil
,
err
}
if
claim
.
Depth
()
==
s
.
gameDepth
{
return
nil
,
errors
.
New
(
"game depth reached"
)
}
if
parentCorrect
&&
claimCorrect
{
// We agree with the parent, but the claim is disagreeing with it.
// Since we agree with the claim, the difference must be to the right of the claim
...
...
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