Commit 8a90222c authored by Andreas Bigger's avatar Andreas Bigger

Draft Responder Step interface func

parent a8e6061d
...@@ -34,6 +34,10 @@ func (o *Orchestrator) Respond(_ context.Context, response Claim) error { ...@@ -34,6 +34,10 @@ func (o *Orchestrator) Respond(_ context.Context, response Claim) error {
return nil return nil
} }
func (o *Orchestrator) Step(ctx context.Context, stepData StepCallData) error {
return nil
}
func (o *Orchestrator) Start() { func (o *Orchestrator) Start() {
for i := 0; i < len(o.agents); i++ { for i := 0; i < len(o.agents); i++ {
go runAgent(&o.agents[i], o.outputChs[i]) go runAgent(&o.agents[i], o.outputChs[i])
......
...@@ -74,17 +74,19 @@ func (r *faultResponder) BuildTx(ctx context.Context, response Claim) ([]byte, e ...@@ -74,17 +74,19 @@ func (r *faultResponder) BuildTx(ctx context.Context, response Claim) ([]byte, e
// Respond takes a [Claim] and executes the response action. // Respond takes a [Claim] and executes the response action.
func (r *faultResponder) Respond(ctx context.Context, response Claim) error { func (r *faultResponder) Respond(ctx context.Context, response Claim) error {
// Build the transaction data.
txData, err := r.BuildTx(ctx, response) txData, err := r.BuildTx(ctx, response)
if err != nil { if err != nil {
return err 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{ receipt, err := r.txMgr.Send(ctx, txmgr.TxCandidate{
To: &r.fdgAddr, To: &r.fdgAddr,
TxData: txData, TxData: txData,
// Setting GasLimit to 0 performs gas estimation online through the [txmgr].
GasLimit: 0, GasLimit: 0,
}) })
if err != nil { if err != nil {
...@@ -95,6 +97,26 @@ func (r *faultResponder) Respond(ctx context.Context, response Claim) error { ...@@ -95,6 +97,26 @@ func (r *faultResponder) Respond(ctx context.Context, response Claim) error {
} else { } else {
r.log.Info("responder tx successfully published", "tx_hash", receipt.TxHash) r.log.Info("responder tx successfully published", "tx_hash", receipt.TxHash)
} }
return nil 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)
}
...@@ -12,6 +12,15 @@ var ( ...@@ -12,6 +12,15 @@ var (
ErrIndexTooLarge = errors.New("index is larger than the maximum index") 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 // TraceProvider is a generic way to get a claim value at a specific
// step in the trace. // step in the trace.
// The [AlphabetProvider] is a minimal implementation of this interface. // The [AlphabetProvider] is a minimal implementation of this interface.
...@@ -60,4 +69,5 @@ func (c *Claim) DefendsParent() bool { ...@@ -60,4 +69,5 @@ func (c *Claim) DefendsParent() bool {
// For full op-challenger this means executing the transaction on chain. // For full op-challenger this means executing the transaction on chain.
type Responder interface { type Responder interface {
Respond(ctx context.Context, response Claim) error Respond(ctx context.Context, response Claim) error
Step(ctx context.Context, stepData StepCallData) error
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment