From 05e8ee7902ad8a5624269e579fc9ac5c290758d7 Mon Sep 17 00:00:00 2001 From: Randy Grok <@faulttolerance.net> Date: Thu, 28 Nov 2024 10:52:39 +0100 Subject: [PATCH] fix reviews --- server/v2/cometbft/abci.go | 8 +++----- .../v2/cometbft/oe/optimistic_execution_test.go | 15 ++++++++------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/server/v2/cometbft/abci.go b/server/v2/cometbft/abci.go index 746162d4ad6a..21567ee2be44 100644 --- a/server/v2/cometbft/abci.go +++ b/server/v2/cometbft/abci.go @@ -2,7 +2,6 @@ package cometbft import ( "context" - "cosmossdk.io/server/v2/cometbft/oe" "crypto/sha256" "errors" "fmt" @@ -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" @@ -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" @@ -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{ @@ -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) } @@ -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() } diff --git a/server/v2/cometbft/oe/optimistic_execution_test.go b/server/v2/cometbft/oe/optimistic_execution_test.go index 29643f4ee102..c0eb28c2a5e9 100644 --- a/server/v2/cometbft/oe/optimistic_execution_test.go +++ b/server/v2/cometbft/oe/optimistic_execution_test.go @@ -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")))