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
a29932f8
Unverified
Commit
a29932f8
authored
Jun 30, 2023
by
mergify[bot]
Committed by
GitHub
Jun 30, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into refcell/step-interfaces
parents
caed6a3d
bf04d9e4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
111 additions
and
16 deletions
+111
-16
orchestrator.go
op-challenger/fault/orchestrator.go
+4
-0
responder.go
op-challenger/fault/responder.go
+28
-6
solver.go
op-challenger/fault/solver.go
+49
-10
solver_test.go
op-challenger/fault/solver_test.go
+20
-0
types.go
op-challenger/fault/types.go
+10
-0
No files found.
op-challenger/fault/orchestrator.go
View file @
a29932f8
...
...
@@ -34,6 +34,10 @@ func (o *Orchestrator) Respond(_ context.Context, response Claim) error {
return
nil
}
func
(
o
*
Orchestrator
)
Step
(
ctx
context
.
Context
,
stepData
StepCallData
)
error
{
return
nil
}
func
(
o
*
Orchestrator
)
Start
()
{
for
i
:=
0
;
i
<
len
(
o
.
agents
);
i
++
{
go
runAgent
(
&
o
.
agents
[
i
],
o
.
outputChs
[
i
])
...
...
op-challenger/fault/responder.go
View file @
a29932f8
...
...
@@ -74,17 +74,19 @@ func (r *faultResponder) BuildTx(ctx context.Context, response Claim) ([]byte, e
// Respond takes a [Claim] and executes the response action.
func
(
r
*
faultResponder
)
Respond
(
ctx
context
.
Context
,
response
Claim
)
error
{
// Build the transaction data.
txData
,
err
:=
r
.
BuildTx
(
ctx
,
response
)
if
err
!=
nil
{
return
err
}
return
r
.
sendTxAndWait
(
ctx
,
txData
)
}
// Send the transaction through the [txmgr].
// sendTxAndWait sends a transaction through the [txmgr] and waits for a receipt.
// This sets the tx GasLimit to 0, performing gas estimation online through the [txmgr].
func
(
r
*
faultResponder
)
sendTxAndWait
(
ctx
context
.
Context
,
txData
[]
byte
)
error
{
receipt
,
err
:=
r
.
txMgr
.
Send
(
ctx
,
txmgr
.
TxCandidate
{
To
:
&
r
.
fdgAddr
,
TxData
:
txData
,
// Setting GasLimit to 0 performs gas estimation online through the [txmgr].
To
:
&
r
.
fdgAddr
,
TxData
:
txData
,
GasLimit
:
0
,
})
if
err
!=
nil
{
...
...
@@ -95,6 +97,26 @@ func (r *faultResponder) Respond(ctx context.Context, response Claim) error {
}
else
{
r
.
log
.
Info
(
"responder tx successfully published"
,
"tx_hash"
,
receipt
.
TxHash
)
}
return
nil
}
// buildStepTxData creates the transaction data for the step function.
func
(
r
*
faultResponder
)
buildStepTxData
(
stepData
StepCallData
)
([]
byte
,
error
)
{
return
r
.
fdgAbi
.
Pack
(
"step"
,
big
.
NewInt
(
int64
(
stepData
.
StateIndex
)),
big
.
NewInt
(
int64
(
stepData
.
ClaimIndex
)),
stepData
.
IsAttack
,
stepData
.
StateData
,
stepData
.
Proof
,
)
}
// Step accepts step data and executes the step on the fault dispute game contract.
func
(
r
*
faultResponder
)
Step
(
ctx
context
.
Context
,
stepData
StepCallData
)
error
{
txData
,
err
:=
r
.
buildStepTxData
(
stepData
)
if
err
!=
nil
{
return
err
}
return
r
.
sendTxAndWait
(
ctx
,
txData
)
}
op-challenger/fault/solver.go
View file @
a29932f8
...
...
@@ -25,19 +25,58 @@ func NewSolver(gameDepth int, traceProvider TraceProvider) *Solver {
func
(
s
*
Solver
)
NextMove
(
claim
Claim
)
(
*
Claim
,
error
)
{
// Special case of the root claim
if
claim
.
IsRoot
()
{
agree
,
err
:=
s
.
agreeWithClaim
(
claim
.
ClaimData
)
if
err
!=
nil
{
return
nil
,
err
}
// Attack the root claim if we do not agree with it
if
!
agree
{
return
s
.
attack
(
claim
)
}
else
{
return
nil
,
nil
}
return
s
.
handleRoot
(
claim
)
}
return
s
.
handleMiddle
(
claim
)
}
type
StepData
struct
{
LeafClaim
Claim
StateClaim
Claim
IsAttack
bool
}
// AttemptStep determines what step should occur for a given leaf claim.
// An error will be returned if the claim is not at the max depth.
func
(
s
*
Solver
)
AttemptStep
(
claim
Claim
,
state
Game
)
(
StepData
,
error
)
{
if
claim
.
Depth
()
!=
s
.
gameDepth
{
return
StepData
{},
errors
.
New
(
"cannot step on non-leaf claims"
)
}
claimCorrect
,
err
:=
s
.
agreeWithClaim
(
claim
.
ClaimData
)
if
err
!=
nil
{
return
StepData
{},
err
}
var
selectorFn
func
(
Claim
)
(
Claim
,
error
)
if
claimCorrect
{
selectorFn
=
state
.
PostStateClaim
}
else
{
selectorFn
=
state
.
PreStateClaim
}
stateClaim
,
err
:=
selectorFn
(
claim
)
if
err
!=
nil
{
return
StepData
{},
err
}
return
StepData
{
LeafClaim
:
claim
,
StateClaim
:
stateClaim
,
IsAttack
:
claimCorrect
,
},
nil
}
func
(
s
*
Solver
)
handleRoot
(
claim
Claim
)
(
*
Claim
,
error
)
{
agree
,
err
:=
s
.
agreeWithClaim
(
claim
.
ClaimData
)
if
err
!=
nil
{
return
nil
,
err
}
// Attack the root claim if we do not agree with it
if
!
agree
{
return
s
.
attack
(
claim
)
}
else
{
return
nil
,
nil
}
}
func
(
s
*
Solver
)
handleMiddle
(
claim
Claim
)
(
*
Claim
,
error
)
{
parentCorrect
,
err
:=
s
.
agreeWithClaim
(
claim
.
Parent
)
if
err
!=
nil
{
return
nil
,
err
...
...
op-challenger/fault/solver_test.go
View file @
a29932f8
...
...
@@ -78,3 +78,23 @@ func TestSolver_NextMove_Opponent(t *testing.T) {
require
.
Equal
(
t
,
test
.
response
,
res
.
ClaimData
)
}
}
func
TestAttemptStep
(
t
*
testing
.
T
)
{
maxDepth
:=
3
canonicalProvider
:=
NewAlphabetProvider
(
"abcdefgh"
,
uint64
(
maxDepth
))
solver
:=
NewSolver
(
maxDepth
,
canonicalProvider
)
root
,
top
,
middle
,
bottom
:=
createTestClaims
()
g
:=
NewGameState
(
root
,
testMaxDepth
)
require
.
NoError
(
t
,
g
.
Put
(
top
))
require
.
NoError
(
t
,
g
.
Put
(
middle
))
require
.
NoError
(
t
,
g
.
Put
(
bottom
))
step
,
err
:=
solver
.
AttemptStep
(
bottom
,
g
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
bottom
,
step
.
LeafClaim
)
require
.
Equal
(
t
,
middle
,
step
.
StateClaim
)
require
.
True
(
t
,
step
.
IsAttack
)
_
,
err
=
solver
.
AttemptStep
(
middle
,
g
)
require
.
Error
(
t
,
err
)
}
op-challenger/fault/types.go
View file @
a29932f8
...
...
@@ -12,6 +12,15 @@ var (
ErrIndexTooLarge
=
errors
.
New
(
"index is larger than the maximum index"
)
)
// StepCallData encapsulates the data needed to perform a step.
type
StepCallData
struct
{
StateIndex
uint64
ClaimIndex
uint64
IsAttack
bool
StateData
[]
byte
Proof
[]
byte
}
// TraceProvider is a generic way to get a claim value at a specific
// step in the trace.
// The [AlphabetProvider] is a minimal implementation of this interface.
...
...
@@ -61,4 +70,5 @@ func (c *Claim) DefendsParent() bool {
// For full op-challenger this means executing the transaction on chain.
type
Responder
interface
{
Respond
(
ctx
context
.
Context
,
response
Claim
)
error
Step
(
ctx
context
.
Context
,
stepData
StepCallData
)
error
}
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