Skip to content

Commit

Permalink
fix reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
Randy Grok committed Nov 28, 2024
1 parent 6791357 commit 05e8ee7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
8 changes: 3 additions & 5 deletions server/v2/cometbft/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cometbft

import (
"context"
"cosmossdk.io/server/v2/cometbft/oe"
"crypto/sha256"
"errors"
"fmt"
Expand All @@ -12,7 +11,7 @@ import (
abci "github.com/cometbft/cometbft/abci/types"
abciproto "github.com/cometbft/cometbft/api/cometbft/abci/v1"
gogoproto "github.com/cosmos/gogoproto/proto"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"

"cosmossdk.io/collections"
Expand All @@ -29,6 +28,7 @@ import (
"cosmossdk.io/server/v2/appmanager"
"cosmossdk.io/server/v2/cometbft/handlers"
"cosmossdk.io/server/v2/cometbft/mempool"
"cosmossdk.io/server/v2/cometbft/oe"
"cosmossdk.io/server/v2/cometbft/types"
cometerrors "cosmossdk.io/server/v2/cometbft/types/errors"
"cosmossdk.io/server/v2/streaming"
Expand Down Expand Up @@ -443,7 +443,6 @@ func (c *consensus[T]) ProcessProposal(
if req.Height > int64(c.initialHeight) {
// abort any running OE
c.optimisticExec.Abort()
//c.setState(execModeFinalize, header)
}

ciCtx := contextWithCometInfo(ctx, comet.Info{
Expand All @@ -468,7 +467,7 @@ func (c *consensus[T]) ProcessProposal(
// After the first block has been processed, the next blocks will get executed
// optimistically, so that when the ABCI client calls `FinalizeBlock` the app
// can have a response ready.
if c.optimisticExec.Enabled() && req.Height > int64(c.initialHeight) {
if req.Height > int64(c.initialHeight) {
c.optimisticExec.Execute(req)
}

Expand Down Expand Up @@ -508,7 +507,6 @@ func (c *consensus[T]) FinalizeBlock(
decodedTxs = res.DecodedTxs
}

// if it was aborted, we need to reset the state
c.optimisticExec.Reset()
}

Expand Down
15 changes: 8 additions & 7 deletions server/v2/cometbft/oe/optimistic_execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@ import (
"errors"
"testing"

"cosmossdk.io/core/server"
"cosmossdk.io/core/store"
"cosmossdk.io/core/transaction"
"cosmossdk.io/log"
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
"github.com/stretchr/testify/assert"

"cosmossdk.io/log"
)

func testFinalizeBlock(_ context.Context, _ *abci.FinalizeBlockRequest) (*abci.FinalizeBlockResponse, error) {
return nil, errors.New("test error")
func testFinalizeBlock[T transaction.Tx](context.Context, *abci.FinalizeBlockRequest) (*server.BlockResponse, store.WriterMap, []T, error) {
return nil, nil, nil, errors.New("test error")
}

func TestOptimisticExecution(t *testing.T) {
oe := NewOptimisticExecution(log.NewNopLogger(), testFinalizeBlock)
assert.True(t, oe.Enabled())
oe := NewOptimisticExecution[transaction.Tx](log.NewNopLogger(), testFinalizeBlock)
oe.Execute(&abci.ProcessProposalRequest{
Hash: []byte("test"),
})
assert.True(t, oe.Initialized())

resp, err := oe.WaitResult()
assert.Nil(t, resp)
assert.Equal(t, &FinalizeBlockResponse[transaction.Tx]{}, resp) // empty response
assert.EqualError(t, err, "test error")

assert.False(t, oe.AbortIfNeeded([]byte("test")))
Expand Down

0 comments on commit 05e8ee7

Please sign in to comment.