From 938f8183b9ab1fd1f6b1bc5d8ff2bba7ab6e2a18 Mon Sep 17 00:00:00 2001 From: Redouane Lakrache Date: Thu, 12 Dec 2024 09:02:18 +0100 Subject: [PATCH 1/4] 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) From c888c1db22438e796cf3780579d50c7b3ca33325 Mon Sep 17 00:00:00 2001 From: Arthur Ariel Sabintsev Date: Thu, 12 Dec 2024 17:02:06 -0500 Subject: [PATCH 2/4] Updated cheat sheat docs with an example after installation (#1004) ## Summary Added test request/response at the end of installation allow the user to verify the installation worked ## Issue I needed to verify my installation worked, and the current guide did not work. I pulled the sample `curl` command from the full walkthrough. --------- Co-authored-by: Daniel Olshansky --- .../quickstart/full_node_cheatsheet.md | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/docusaurus/docs/operate/quickstart/full_node_cheatsheet.md b/docusaurus/docs/operate/quickstart/full_node_cheatsheet.md index 49d8beaf2..58161381a 100644 --- a/docusaurus/docs/operate/quickstart/full_node_cheatsheet.md +++ b/docusaurus/docs/operate/quickstart/full_node_cheatsheet.md @@ -19,6 +19,7 @@ step of the process, check out the [Full Node Walkthrough](../run_a_node/full_no - [Pre-Requisites](#pre-requisites) - [Install and Run a Full Node using Cosmovisor](#install-and-run-a-full-node-using-cosmovisor) - [Automatic Upgrades Out of the Box](#automatic-upgrades-out-of-the-box) + - [Verify successful installation (curl latest block)](#verify-successful-installation-curl-latest-block) - [FAQ \& Troubleshooting](#faq--troubleshooting) - [\[OPTIONAL\] Do you care to know what just happened?](#optional-do-you-care-to-know-what-just-happened) @@ -75,6 +76,86 @@ When a chain upgrade is proposed and approved: 3. Cosmovisor will switch to the new binary 4. The node will restart automatically +#### Verify successful installation (curl latest block) + +You can verify the installation was successful by querying the latest block (i.e. checking the node height). + +Running the following command: + +```bash +curl -X GET http://localhost:26657/block | jq +``` + +Should provide a response in this form: + +```json +{ + "jsonrpc": "2.0", + "id": -1, + "result": { + "block_id": { + "hash": "924904A2FB97327D2D91EB18225041B3DF82D1DBA5BA988AB79CD3EAC4A4960C", + "parts": { + "total": 1, + "hash": "90E8EDC6841779CF4BADE35CDB53AA1276153BD26690999C5E87EB0E49E91AC8" + } + }, + "block": { + "header": { + "version": { + "block": "11" + }, + "chain_id": "pocket-beta", + "height": "4971", + "time": "2024-11-25T21:33:54.785576474Z", + "last_block_id": { + "hash": "E1D9F26882FD28447063CC11D326331C4B7C4A6417B2B2E5E38C5484C6D98168", + "parts": { + "total": 1, + "hash": "85847883D9A34F345A2C3E610E1EC524B3C12F41DD2BDC49B36824D9A12EAB32" + } + }, + "last_commit_hash": "D49C2BF69F43658D63EF78487258DCA05F7239554E668CF9AE2502A5C6DB104E", + "data_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", + "validators_hash": "5DC32F6AF7A2B6BAF1738FC5ADC8760E3A1A33A98839071D6A6FE503AD3BD52E", + "next_validators_hash": "5DC32F6AF7A2B6BAF1738FC5ADC8760E3A1A33A98839071D6A6FE503AD3BD52E", + "consensus_hash": "048091BC7DDC283F77BFBF91D73C44DA58C3DF8A9CBC867405D8B7F3DAADA22F", + "app_hash": "DEACCBB96F23B7B58CADAFBE7894DDC2C5ACA0F29A68EA1C67407FA06C8D617C", + "last_results_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", + "evidence_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", + "proposer_address": "21FABB12F80DAFF6CB83BA0958B2509FC127C3BD" + }, + "data": { + "txs": [] + }, + "evidence": { + "evidence": [] + }, + "last_commit": { + "height": "4970", + "round": 0, + "block_id": { + "hash": "E1D9F26882FD28447063CC11D326331C4B7C4A6417B2B2E5E38C5484C6D98168", + "parts": { + "total": 1, + "hash": "85847883D9A34F345A2C3E610E1EC524B3C12F41DD2BDC49B36824D9A12EAB32" + } + }, + "signatures": [ + { + "block_id_flag": 2, + "validator_address": "21FABB12F80DAFF6CB83BA0958B2509FC127C3BD", + "timestamp": "2024-11-25T21:33:54.770507235Z", + "signature": "zQb3QPt032nIRTUc7kk4cSxgVF4hpMZycE6ZvpSSZM4Bj1XlOEcdFtHWiLsileVX9RkZHqChzGBstCnfCfK8Bg==" + }, + ... + ] + } + } + } +} +``` + ### FAQ & Troubleshooting See the [FAQ & Troubleshooting section in the Full Node Walkthrough](../run_a_node/full_node_walkthrough.md#faq--troubleshooting) From 8ea6c15b00a95c0778e28a8378c2dd9df69ea06e Mon Sep 17 00:00:00 2001 From: Bryan White Date: Fri, 13 Dec 2024 14:59:50 +0100 Subject: [PATCH 3/4] fix: E2E tests - RPC URL path (#1008) ## Summary Update the E2E step definition which queries the gateway. The path was `/v1`, and is now `/v1/` to avoid a redirect response. ## Issue E2E tests involving relays fail on `main`. Previously, `POST`ing to the `/v1` path returned a response directly; it now seems to redirect to `/v1/` which curl can't reliably handle on all platforms. ## 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 - [ ] **Documentation**: `make docusaurus_start`; only needed if you make doc changes - [ ] **Unit Tests**: `make go_develop_and_test` - [ ] **LocalNet E2E Tests**: `make test_e2e` - [ ] **DevNet E2E Tests**: Add the `devnet-test-e2e` label to the PR. ## Sanity Checklist - [ ] I have tested my changes using the available tooling - [ ] I have commented my code - [ ] I have performed a self-review of my own code; both comments & source code - [ ] I create and reference any new tickets, if applicable - [ ] I have left TODOs throughout the codebase, if applicable --- e2e/tests/node.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/e2e/tests/node.go b/e2e/tests/node.go index 4dc1726de..826b3ef71 100644 --- a/e2e/tests/node.go +++ b/e2e/tests/node.go @@ -213,6 +213,14 @@ func (p *pocketdBin) runCurlCmd(rpcBaseURL, service, method, path, appAddr, data } rpcUrl.Path = rpcUrl.Path + path + // Ensure that the path also ends with a "/" if it only contains the version. + // This is required because the server responds with a 301 redirect for "/v1" + // and curl binaries on some platforms MAY NOT support re-sending POST data + // while following a redirect (`-L` flag). + if strings.HasSuffix(rpcUrl.Path, "/v1") { + rpcUrl.Path = rpcUrl.Path + "/" + } + base := []string{ "-v", // verbose output "-sS", // silent with error From 91250b336b75f4f371ec45f1307510303d9beb70 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Fri, 13 Dec 2024 15:22:55 +0100 Subject: [PATCH 4/4] [Relayminer, Bug] fix: sessiontree logger never initialized (#993) ## Summary Fixes a nil pointer panic in the relayminer; the logger member is never initialized. ## Issue - N/A ## 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 - [ ] **Documentation**: `make docusaurus_start`; only needed if you make doc changes - [ ] **Unit Tests**: `make go_develop_and_test` - [ ] **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 - [ ] I have left TODOs throughout the codebase, if applicable --- pkg/relayer/session/sessiontree.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/relayer/session/sessiontree.go b/pkg/relayer/session/sessiontree.go index 566369968..df1bfde79 100644 --- a/pkg/relayer/session/sessiontree.go +++ b/pkg/relayer/session/sessiontree.go @@ -96,14 +96,20 @@ func NewSessionTree( // contain a non-hashed Relay that could be used to validate the proof on-chain. trie := smt.NewSparseMerkleSumTrie(treeStore, protocol.NewTrieHasher(), smt.WithValueHasher(nil)) + logger = logger.With( + "store_path", storePath, + "session_id", sessionHeader.SessionId, + "supplier_operator_address", supplierOperatorAddress, + ) + sessionTree := &sessionTree{ + logger: logger, sessionHeader: sessionHeader, storePath: storePath, treeStore: treeStore, sessionSMT: trie, sessionMu: &sync.Mutex{}, supplierOperatorAddress: supplierOperatorAddress, - logger: logger, } return sessionTree, nil @@ -270,7 +276,6 @@ func (st *sessionTree) Delete() error { } else { st.logger.With( "claim_root", fmt.Sprintf("%x", st.GetClaimRoot()), - "session_id", st.GetSessionHeader().SessionId, ).Info().Msg("KVStore is already stopped") }