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
4acb210e
Unverified
Commit
4acb210e
authored
Jun 28, 2023
by
OptimismBot
Committed by
GitHub
Jun 28, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6177 from ethereum-optimism/jg/orchestrator
op-challenger: Add in memory orchestrator
parents
7aaa3da7
0a3220ee
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 @
4acb210e
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 @
4acb210e
...
@@ -5,8 +5,8 @@ import (
...
@@ -5,8 +5,8 @@ import (
)
)
func
main
()
{
func
main
()
{
examples
.
SolverExampleOn
e
()
examples
.
FullGam
e
()
// examples.SolverExampleOne()
// examples.PositionExampleOne()
// examples.PositionExampleOne()
// examples.PositionExampleTwo()
// examples.PositionExampleTwo()
}
}
op-challenger/fault/orchestrator.go
0 → 100644
View file @
4acb210e
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 @
4acb210e
...
@@ -31,6 +31,9 @@ func (s *Solver) NextMove(claim Claim) (*Claim, error) {
...
@@ -31,6 +31,9 @@ func (s *Solver) NextMove(claim Claim) (*Claim, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
claim
.
Depth
()
==
s
.
gameDepth
{
return
nil
,
errors
.
New
(
"game depth reached"
)
}
if
parentCorrect
&&
claimCorrect
{
if
parentCorrect
&&
claimCorrect
{
// We agree with the parent, but the claim is disagreeing with it.
// 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
// 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