Skip to content

Commit

Permalink
fix: Nil session tree logger (#1007)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
red-0ne authored Dec 12, 2024
1 parent 5d8c6dc commit 938f818
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/poktroll/application/tx.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/relayer/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions pkg/relayer/session/sessiontree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -102,6 +103,7 @@ func NewSessionTree(
sessionSMT: trie,
sessionMu: &sync.Mutex{},
supplierOperatorAddress: supplierOperatorAddress,
logger: logger,
}

return sessionTree, nil
Expand Down
7 changes: 6 additions & 1 deletion testutil/testtree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(
Expand All @@ -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 {
Expand All @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions x/proof/keeper/proof_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 938f818

Please sign in to comment.