Skip to content

Commit

Permalink
fix OE log
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyding committed Jul 26, 2024
1 parent 57faa86 commit 0af9594
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 3 additions & 3 deletions baseapp/oe/optimistic_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ 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
}

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 {
Expand Down
13 changes: 10 additions & 3 deletions baseapp/oe/optimistic_execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit 0af9594

Please sign in to comment.