Commit aa3b147c authored by Adrian Sutton's avatar Adrian Sutton Committed by GitHub

dispute-mon: Disagree with output roots that are not found by the local node (#9553)

parent 81976a4d
...@@ -3,6 +3,7 @@ package mon ...@@ -3,6 +3,7 @@ package mon
import ( import (
"context" "context"
"fmt" "fmt"
"strings"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -27,6 +28,11 @@ func newOutputValidator(client OutputRollupClient) *outputValidator { ...@@ -27,6 +28,11 @@ func newOutputValidator(client OutputRollupClient) *outputValidator {
func (o *outputValidator) CheckRootAgreement(ctx context.Context, blockNum uint64, rootClaim common.Hash) (bool, common.Hash, error) { func (o *outputValidator) CheckRootAgreement(ctx context.Context, blockNum uint64, rootClaim common.Hash) (bool, common.Hash, error) {
output, err := o.client.OutputAtBlock(ctx, blockNum) output, err := o.client.OutputAtBlock(ctx, blockNum)
if err != nil { if err != nil {
// string match as the error comes from the remote server so we can't use Errors.Is sadly.
if strings.Contains(err.Error(), "not found") {
// Output root doesn't exist, so we must disagree with it.
return false, common.Hash{}, nil
}
return false, common.Hash{}, fmt.Errorf("failed to get output at block: %w", err) return false, common.Hash{}, fmt.Errorf("failed to get output at block: %w", err)
} }
expected := common.Hash(output.OutputRoot) expected := common.Hash(output.OutputRoot)
......
...@@ -41,6 +41,16 @@ func TestDetector_CheckRootAgreement(t *testing.T) { ...@@ -41,6 +41,16 @@ func TestDetector_CheckRootAgreement(t *testing.T) {
require.Equal(t, mockRootClaim, fetched) require.Equal(t, mockRootClaim, fetched)
require.True(t, agree) require.True(t, agree)
}) })
t.Run("OutputNotFound", func(t *testing.T) {
validator, rollup := setupOutputValidatorTest(t)
// This crazy error is what we actually get back from the API
rollup.err = errors.New("failed to get L2 block ref with sync status: failed to determine L2BlockRef of height 42984924, could not get payload: not found")
agree, fetched, err := validator.CheckRootAgreement(context.Background(), 42984924, mockRootClaim)
require.NoError(t, err)
require.Equal(t, common.Hash{}, fetched)
require.False(t, agree)
})
} }
func setupOutputValidatorTest(t *testing.T) (*outputValidator, *stubRollupClient) { func setupOutputValidatorTest(t *testing.T) (*outputValidator, *stubRollupClient) {
......
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