Commit 5cc83a8e authored by Adrian Sutton's avatar Adrian Sutton Committed by GitHub

op-program: Run until all events are exhausted instead of running until the...

op-program: Run until all events are exhausted instead of running until the derivation is idle (#12804)

* op-e2e: Add action test for op-program trace extension behaviour.

* op-program: Run until all events are exhausted instead of running until the derivation is idle.
parent fcb462f9
......@@ -73,15 +73,14 @@ func (d *Driver) Emit(ev event.Event) {
d.events = append(d.events, ev)
}
var ExhaustErr = errors.New("exhausted events before completing program")
func (d *Driver) RunComplete() error {
// Initial reset
d.Emit(engine.ResetEngineRequestEvent{})
for !d.end.Closing() {
if len(d.events) == 0 {
return ExhaustErr
d.logger.Info("Derivation complete: no further data to process")
return d.end.Result()
}
if len(d.events) > 10000 { // sanity check, in case of bugs. Better than going OOM.
return errors.New("way too many events queued up, something is wrong")
......
......@@ -92,7 +92,8 @@ func TestDriver(t *testing.T) {
}
count += 1
})
require.ErrorIs(t, ExhaustErr, d.RunComplete())
// No further processing to be done so evaluate if the claims output root is correct.
require.NoError(t, d.RunComplete())
})
t.Run("queued events", func(t *testing.T) {
......@@ -104,7 +105,7 @@ func TestDriver(t *testing.T) {
}
count += 1
})
require.ErrorIs(t, ExhaustErr, d.RunComplete())
require.NoError(t, d.RunComplete())
// add 1 for initial event that RunComplete fires
require.Equal(t, 1+3*2, count, "must have queued up 2 events 3 times")
})
......
......@@ -62,10 +62,6 @@ func (d *ProgramDeriver) OnEvent(ev event.Event) bool {
d.logger.Info("Derivation complete: reached L2 block", "head", x.SafeL2Head)
d.closing = true
}
case derive.DeriverIdleEvent:
// Not enough data to reach target
d.closing = true
d.logger.Info("Derivation complete: no further data to process")
case rollup.ResetEvent:
d.closing = true
d.result = fmt.Errorf("unexpected reset error: %w", x.Err)
......
......@@ -104,12 +104,12 @@ func TestProgramDeriver(t *testing.T) {
require.NoError(t, p.result)
})
})
// on exhaustion of input data: stop without error
// Do not stop processing when the deriver is idle, the engine may still be busy and create further events.
t.Run("deriver idle", func(t *testing.T) {
p, m := newProgram(t, 1000)
p.OnEvent(derive.DeriverIdleEvent{})
m.AssertExpectations(t)
require.True(t, p.closing)
require.False(t, p.closing)
require.Nil(t, p.result)
})
// on inconsistent chain data: stop with 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