Commit 75133521 authored by Andreas Bigger's avatar Andreas Bigger

Fix agent stepping.

parent c07d67ab
...@@ -94,6 +94,17 @@ func (a *Agent) step(claim Claim, game Game) error { ...@@ -94,6 +94,17 @@ func (a *Agent) step(claim Claim, game Game) error {
if claim.Depth() != a.maxDepth { if claim.Depth() != a.maxDepth {
return nil return nil
} }
if game.AgreeWithClaimLevel(claim) {
a.log.Warn("Agree with leaf claim, skipping step", "claim_depth", claim.Depth(), "maxDepth", a.maxDepth)
return nil
}
if claim.Countered {
a.log.Info("Claim already stepped on", "claim_depth", claim.Depth(), "maxDepth", a.maxDepth)
return nil
}
a.log.Info("Attempting step", "claim_depth", claim.Depth(), "maxDepth", a.maxDepth) a.log.Info("Attempting step", "claim_depth", claim.Depth(), "maxDepth", a.maxDepth)
step, err := a.solver.AttemptStep(claim) step, err := a.solver.AttemptStep(claim)
if err != nil { if err != nil {
......
...@@ -56,6 +56,8 @@ func (l *loader) fetchClaim(ctx context.Context, arrIndex uint64) (Claim, error) ...@@ -56,6 +56,8 @@ func (l *loader) fetchClaim(ctx context.Context, arrIndex uint64) (Claim, error)
Value: fetchedClaim.Claim, Value: fetchedClaim.Claim,
Position: NewPositionFromGIndex(fetchedClaim.Position.Uint64()), Position: NewPositionFromGIndex(fetchedClaim.Position.Uint64()),
}, },
Countered: fetchedClaim.Countered,
Clock: fetchedClaim.Clock.Uint64(),
ContractIndex: int(arrIndex), ContractIndex: int(arrIndex),
ParentContractIndex: int(fetchedClaim.ParentIndex), ParentContractIndex: int(fetchedClaim.ParentIndex),
} }
......
...@@ -40,16 +40,22 @@ func newMockClaimFetcher() *mockClaimFetcher { ...@@ -40,16 +40,22 @@ func newMockClaimFetcher() *mockClaimFetcher {
Clock *big.Int Clock *big.Int
}{ }{
{ {
Claim: [32]byte{0x00}, Claim: [32]byte{0x00},
Position: big.NewInt(0), Position: big.NewInt(0),
Countered: false,
Clock: big.NewInt(0),
}, },
{ {
Claim: [32]byte{0x01}, Claim: [32]byte{0x01},
Position: big.NewInt(0), Position: big.NewInt(0),
Countered: false,
Clock: big.NewInt(0),
}, },
{ {
Claim: [32]byte{0x02}, Claim: [32]byte{0x02},
Position: big.NewInt(0), Position: big.NewInt(0),
Countered: false,
Clock: big.NewInt(0),
}, },
}, },
} }
...@@ -101,6 +107,8 @@ func TestLoader_FetchClaims_Succeeds(t *testing.T) { ...@@ -101,6 +107,8 @@ func TestLoader_FetchClaims_Succeeds(t *testing.T) {
Value: expectedClaims[0].Claim, Value: expectedClaims[0].Claim,
Position: NewPositionFromGIndex(expectedClaims[0].Position.Uint64()), Position: NewPositionFromGIndex(expectedClaims[0].Position.Uint64()),
}, },
Countered: false,
Clock: uint64(0),
ContractIndex: 0, ContractIndex: 0,
}, },
{ {
...@@ -112,6 +120,8 @@ func TestLoader_FetchClaims_Succeeds(t *testing.T) { ...@@ -112,6 +120,8 @@ func TestLoader_FetchClaims_Succeeds(t *testing.T) {
Value: expectedClaims[0].Claim, Value: expectedClaims[0].Claim,
Position: NewPositionFromGIndex(expectedClaims[1].Position.Uint64()), Position: NewPositionFromGIndex(expectedClaims[1].Position.Uint64()),
}, },
Countered: false,
Clock: uint64(0),
ContractIndex: 1, ContractIndex: 1,
}, },
{ {
...@@ -123,6 +133,8 @@ func TestLoader_FetchClaims_Succeeds(t *testing.T) { ...@@ -123,6 +133,8 @@ func TestLoader_FetchClaims_Succeeds(t *testing.T) {
Value: expectedClaims[0].Claim, Value: expectedClaims[0].Claim,
Position: NewPositionFromGIndex(expectedClaims[2].Position.Uint64()), Position: NewPositionFromGIndex(expectedClaims[2].Position.Uint64()),
}, },
Countered: false,
Clock: uint64(0),
ContractIndex: 2, ContractIndex: 2,
}, },
}, claims) }, claims)
......
...@@ -49,7 +49,13 @@ func (c *ClaimData) ValueBytes() [32]byte { ...@@ -49,7 +49,13 @@ func (c *ClaimData) ValueBytes() [32]byte {
// and the Parent field is empty & meaningless. // and the Parent field is empty & meaningless.
type Claim struct { type Claim struct {
ClaimData ClaimData
Parent ClaimData // WARN: Countered is a mutable field in the FaultDisputeGame contract
// and rely on it for determining whether to step on leaf claims.
// When caching is implemented for the Challenger, this will need
// to be changed/removed to avoid invalid/stale contract state.
Countered bool
Clock uint64
Parent ClaimData
// Location of the claim & it's parent inside the contract. Does not exist // Location of the claim & it's parent inside the contract. Does not exist
// for claims that have not made it to the contract. // for claims that have not made it to the contract.
ContractIndex int ContractIndex int
......
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