From 938f8183b9ab1fd1f6b1bc5d8ff2bba7ab6e2a18 Mon Sep 17 00:00:00 2001 From: Redouane Lakrache Date: Thu, 12 Dec 2024 09:02:18 +0100 Subject: [PATCH] fix: Nil session tree logger (#1007) ## Summary This PR initializes the logger of the `SessionTree` by updating the `ensureSessionTree` function to pass the logger, and modifying test utilities to support the new logger parameter. ## Issue - #1006 ## Type of change Select one or more from the following: - [ ] New feature, functionality or library - [ ] Consensus breaking; add the `consensus-breaking` label if so. See #791 for details - [x] Bug fix - [ ] Code health or cleanup - [ ] Documentation - [ ] Other (specify) ## Testing - [x] **Unit Tests**: `make go_develop_and_test` - [x] **LocalNet E2E Tests**: `make test_e2e` - [ ] **DevNet E2E Tests**: Add the `devnet-test-e2e` label to the PR. ## Sanity Checklist - [x] I have tested my changes using the available tooling - [ ] I have commented my code - [x] I have performed a self-review of my own code; both comments & source code - [ ] I create and reference any new tickets, if applicable - [x] I have left TODOs throughout the codebase, if applicable --- api/poktroll/application/tx.pulsar.go | 2 +- pkg/relayer/session/session.go | 3 ++- pkg/relayer/session/sessiontree.go | 2 ++ testutil/testtree/tree.go | 7 ++++++- x/proof/keeper/proof_validation_test.go | 6 +++--- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/api/poktroll/application/tx.pulsar.go b/api/poktroll/application/tx.pulsar.go index 58fc70aa6..0fd937521 100644 --- a/api/poktroll/application/tx.pulsar.go +++ b/api/poktroll/application/tx.pulsar.go @@ -5,11 +5,11 @@ import ( _ "cosmossdk.io/api/amino" v1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" _ "cosmossdk.io/api/cosmos/msg/v1" + shared "github.com/pokt-network/poktroll/api/poktroll/shared" fmt "fmt" _ "github.com/cosmos/cosmos-proto" runtime "github.com/cosmos/cosmos-proto/runtime" _ "github.com/cosmos/gogoproto/gogoproto" - shared "github.com/pokt-network/poktroll/api/poktroll/shared" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoiface "google.golang.org/protobuf/runtime/protoiface" protoimpl "google.golang.org/protobuf/runtime/protoimpl" diff --git a/pkg/relayer/session/session.go b/pkg/relayer/session/session.go index d3999f7d6..82594a0fd 100644 --- a/pkg/relayer/session/session.go +++ b/pkg/relayer/session/session.go @@ -192,7 +192,7 @@ func (rs *relayerSessionsManager) ensureSessionTree( // If the sessionTree does not exist, create and assign it to the // sessionTreeWithSessionId map for the given supplier operator address. if !ok { - sessionTree, err = NewSessionTree(sessionHeader, &supplierOperatorAccAddress, rs.storesDirectory) + sessionTree, err = NewSessionTree(sessionHeader, &supplierOperatorAccAddress, rs.storesDirectory, rs.logger) if err != nil { return nil, err } @@ -468,6 +468,7 @@ func (rs *relayerSessionsManager) deleteExpiredSessionTreesFn( return } + // TODO_TEST: Add tests that cover existing expired failed session trees. for _, sessionTree := range failedSessionTrees { sessionEndHeight := sessionTree.GetSessionHeader().GetSessionEndBlockHeight() proofWindowCloseHeight := expirationHeightFn(sharedParams, sessionEndHeight) diff --git a/pkg/relayer/session/sessiontree.go b/pkg/relayer/session/sessiontree.go index bf83cf0ad..566369968 100644 --- a/pkg/relayer/session/sessiontree.go +++ b/pkg/relayer/session/sessiontree.go @@ -72,6 +72,7 @@ func NewSessionTree( sessionHeader *sessiontypes.SessionHeader, supplierOperatorAddress *cosmostypes.AccAddress, storesDirectory string, + logger polylog.Logger, ) (relayer.SessionTree, error) { // Join the storePrefix and the session.sessionId and supplier's operator address to // create a unique storePath. @@ -102,6 +103,7 @@ func NewSessionTree( sessionSMT: trie, sessionMu: &sync.Mutex{}, supplierOperatorAddress: supplierOperatorAddress, + logger: logger, } return sessionTree, nil diff --git a/testutil/testtree/tree.go b/testutil/testtree/tree.go index 6743d753f..737e710d0 100644 --- a/testutil/testtree/tree.go +++ b/testutil/testtree/tree.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/pokt-network/poktroll/pkg/crypto" + "github.com/pokt-network/poktroll/pkg/polylog" "github.com/pokt-network/poktroll/pkg/relayer" "github.com/pokt-network/poktroll/pkg/relayer/session" "github.com/pokt-network/poktroll/testutil/testrelayer" @@ -31,7 +32,7 @@ func NewFilledSessionTree( t.Helper() // Initialize an empty session tree with the given session header. - sessionTree := NewEmptySessionTree(t, sessionTreeHeader, supplierOperatorAddr) + sessionTree := NewEmptySessionTree(t, ctx, sessionTreeHeader, supplierOperatorAddr) // Add numRelays of relays to the session tree. FillSessionTree( @@ -50,6 +51,7 @@ func NewFilledSessionTree( // NewEmptySessionTree creates a new empty session tree with for given session. func NewEmptySessionTree( t *testing.T, + ctx context.Context, sessionTreeHeader *sessiontypes.SessionHeader, supplierOperatorAddr string, ) relayer.SessionTree { @@ -66,11 +68,14 @@ func NewEmptySessionTree( accAddress := cosmostypes.MustAccAddressFromBech32(supplierOperatorAddr) + logger := polylog.Ctx(ctx) + // Construct a session tree to add relays to and generate a proof from. sessionTree, err := session.NewSessionTree( sessionTreeHeader, &accAddress, testSessionTreeStoreDir, + logger, ) require.NoError(t, err) diff --git a/x/proof/keeper/proof_validation_test.go b/x/proof/keeper/proof_validation_test.go index d3389f103..a3e6133ab 100644 --- a/x/proof/keeper/proof_validation_test.go +++ b/x/proof/keeper/proof_validation_test.go @@ -293,7 +293,7 @@ func TestEnsureValidProof_Error(t *testing.T) { desc: "relay must be deserializable", newProof: func(t *testing.T) *prooftypes.Proof { // Construct a session tree to which we'll add 1 unserializable relay. - mangledRelaySessionTree := testtree.NewEmptySessionTree(t, validSessionHeader, supplierOperatorAddr) + mangledRelaySessionTree := testtree.NewEmptySessionTree(t, ctx, validSessionHeader, supplierOperatorAddr) // Add the mangled relay to the session tree. err = mangledRelaySessionTree.Update([]byte{1}, mangledRelayBz, 1) @@ -444,7 +444,7 @@ func TestEnsureValidProof_Error(t *testing.T) { // Construct a session tree with 1 relay with a session header containing // a session ID that doesn't match the expected session ID. - invalidRequestSignatureSessionTree := testtree.NewEmptySessionTree(t, validSessionHeader, supplierOperatorAddr) + invalidRequestSignatureSessionTree := testtree.NewEmptySessionTree(t, ctx, validSessionHeader, supplierOperatorAddr) // Add the relay to the session tree. err = invalidRequestSignatureSessionTree.Update([]byte{1}, invalidRequestSignatureRelayBz, 1) @@ -505,7 +505,7 @@ func TestEnsureValidProof_Error(t *testing.T) { // Construct a session tree with 1 relay with a session header containing // a session ID that doesn't match the expected session ID. - invalidResponseSignatureSessionTree := testtree.NewEmptySessionTree(t, validSessionHeader, supplierOperatorAddr) + invalidResponseSignatureSessionTree := testtree.NewEmptySessionTree(t, ctx, validSessionHeader, supplierOperatorAddr) // Add the relay to the session tree. err = invalidResponseSignatureSessionTree.Update([]byte{1}, relayBz, 1)