From 7a2c45589d7cf5a3006100e57542549b65c46604 Mon Sep 17 00:00:00 2001 From: Teddy Ding Date: Wed, 7 Aug 2024 16:45:01 -0400 Subject: [PATCH] Log the correct FinalizeBlock request height when OE aborts with mismatch (#54) fix OE log --- baseapp/abci.go | 2 +- baseapp/oe/optimistic_execution.go | 6 +++--- baseapp/oe/optimistic_execution_test.go | 13 ++++++++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 3f85eadd1d2..112a128c092 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -906,7 +906,7 @@ func (app *BaseApp) FinalizeBlock(req *abci.RequestFinalizeBlock) (res *abci.Res if app.optimisticExec.Initialized() { // check if the hash we got is the same as the one we are executing - aborted := app.optimisticExec.AbortIfNeeded(req.Hash) + aborted := app.optimisticExec.AbortIfNeeded(req) // Wait for the OE to finish, regardless of whether it was aborted or not res, err = app.optimisticExec.WaitResult() diff --git a/baseapp/oe/optimistic_execution.go b/baseapp/oe/optimistic_execution.go index c0c8e2575ac..63148bbc4a7 100644 --- a/baseapp/oe/optimistic_execution.go +++ b/baseapp/oe/optimistic_execution.go @@ -120,7 +120,7 @@ func (oe *OptimisticExecution) Execute(req *abci.RequestProcessProposal) { // AbortIfNeeded aborts the OE if the request hash is not the same as the one in // the running OE. Returns true if the OE was aborted. -func (oe *OptimisticExecution) AbortIfNeeded(reqHash []byte) bool { +func (oe *OptimisticExecution) AbortIfNeeded(req *abci.RequestFinalizeBlock) bool { if oe == nil { return false } @@ -128,8 +128,8 @@ func (oe *OptimisticExecution) AbortIfNeeded(reqHash []byte) bool { oe.mtx.Lock() defer oe.mtx.Unlock() - if !bytes.Equal(oe.request.Hash, reqHash) { - oe.logger.Error("OE aborted due to hash mismatch", "oe_hash", hex.EncodeToString(oe.request.Hash), "req_hash", hex.EncodeToString(reqHash), "oe_height", oe.request.Height, "req_height", oe.request.Height) + if !bytes.Equal(oe.request.Hash, req.Hash) { + oe.logger.Error("OE aborted due to hash mismatch", "oe_hash", hex.EncodeToString(oe.request.Hash), "req_hash", hex.EncodeToString(req.Hash), "oe_height", oe.request.Height, "req_height", req.Height) oe.cancelFunc() return true } else if oe.abortRate > 0 && rand.Intn(100) < oe.abortRate { diff --git a/baseapp/oe/optimistic_execution_test.go b/baseapp/oe/optimistic_execution_test.go index 0b92244783c..186db798d08 100644 --- a/baseapp/oe/optimistic_execution_test.go +++ b/baseapp/oe/optimistic_execution_test.go @@ -27,8 +27,15 @@ func TestOptimisticExecution(t *testing.T) { assert.Nil(t, resp) assert.EqualError(t, err, "test error") - assert.False(t, oe.AbortIfNeeded([]byte("test"))) - assert.True(t, oe.AbortIfNeeded([]byte("wrong_hash"))) - + assert.False(t, oe.AbortIfNeeded( + &abci.RequestFinalizeBlock{ + Hash: []byte("test"), + }, + )) + assert.True(t, oe.AbortIfNeeded( + &abci.RequestFinalizeBlock{ + Hash: []byte("wrong_hash"), + }, + )) oe.Reset() }