diff --git a/proto/pocket/supplier/claim.proto b/proto/pocket/supplier/claim.proto index 5b8121855..25b188040 100644 --- a/proto/pocket/supplier/claim.proto +++ b/proto/pocket/supplier/claim.proto @@ -4,11 +4,13 @@ package pocket.supplier; option go_package = "github.com/pokt-network/poktroll/x/supplier/types"; import "cosmos_proto/cosmos.proto"; +import "pocket/session/session.proto"; // Claim is the serialized object stored on-chain for claims pending to be proven message Claim { string supplier_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // the address of the supplier that submitted this claim - string session_id = 2; // session id from the SessionHeader - uint64 session_end_block_height = 3; // session end block height from the SessionHeader - bytes root_hash = 4; // smt.SMST#Root() + // The session header of the session that this claim is for. + session.SessionHeader session_header = 2; + // Root hash returned from smt.SMST#Root(). + bytes root_hash = 3; } \ No newline at end of file diff --git a/proto/pocket/supplier/proof.proto b/proto/pocket/supplier/proof.proto index 26c1ab120..7ec927d05 100644 --- a/proto/pocket/supplier/proof.proto +++ b/proto/pocket/supplier/proof.proto @@ -1,14 +1,16 @@ syntax = "proto3"; package pocket.supplier; +import "cosmos_proto/cosmos.proto"; +import "pocket/session/session.proto"; + option go_package = "github.com/pokt-network/poktroll/x/supplier/types"; -// TODO_UPNEXT(@Olshansk): The structure below is the default (untouched) scaffolded type. Update -// and productionize it for our use case. message Proof { - string index = 1; - string supplier_address = 2; - string session_id = 3; - string merkle_proof = 4; + string supplier_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + // The session header of the session that this claim is for. + session.SessionHeader session_header = 2; + // The serialized SMST proof from the `#ClosestProof()` method. + bytes closest_merkle_proof = 3; } diff --git a/proto/pocket/supplier/query.proto b/proto/pocket/supplier/query.proto index b0d698d58..1af7fdb25 100644 --- a/proto/pocket/supplier/query.proto +++ b/proto/pocket/supplier/query.proto @@ -2,9 +2,10 @@ syntax = "proto3"; package pocket.supplier; +import "cosmos_proto/cosmos.proto"; +import "cosmos/base/query/v1beta1/pagination.proto"; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; -import "cosmos/base/query/v1beta1/pagination.proto"; import "pocket/supplier/params.proto"; import "pocket/shared/supplier.proto"; import "pocket/supplier/claim.proto"; @@ -76,7 +77,7 @@ message QueryAllSupplierResponse { message QueryGetClaimRequest { string session_id = 1; - string supplier_address = 2; + string supplier_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; } message QueryGetClaimResponse { diff --git a/x/supplier/client/cli/helpers_test.go b/x/supplier/client/cli/helpers_test.go index 9c8089868..e8a0753d0 100644 --- a/x/supplier/client/cli/helpers_test.go +++ b/x/supplier/client/cli/helpers_test.go @@ -214,10 +214,15 @@ func createClaim( // TODO_TECHDEBT: Forward the actual claim in the response once the response is updated to return it. return &types.Claim{ - SupplierAddress: supplierAddr, - SessionId: sessionId, - SessionEndBlockHeight: uint64(sessionEndHeight), - RootHash: rootHash, + SupplierAddress: supplierAddr, + SessionHeader: &sessiontypes.SessionHeader{ + ApplicationAddress: appAddress, + Service: &sharedtypes.Service{Id: testServiceId}, + SessionId: sessionId, + SessionStartBlockHeight: sessionStartHeight, + SessionEndBlockHeight: sessionEndHeight, + }, + RootHash: rootHash, } } diff --git a/x/supplier/client/cli/query_claim.go b/x/supplier/client/cli/query_claim.go index 26a667a3b..6d110c0fa 100644 --- a/x/supplier/client/cli/query_claim.go +++ b/x/supplier/client/cli/query_claim.go @@ -82,14 +82,18 @@ func CmdShowClaim() *cobra.Command { cmd := &cobra.Command{ Use: "show-claim ", Short: "shows a specific claim", - Long: `List a specific claim that the node being queried has access to (if it still exists) + Long: `List a specific claim that the node being queried has access to (if it still exists). -A unique claim can be defined via a session_id that a supplier participated in +A unique claim can be defined via a ` + "`session_id`" + ` that the given ` + "`supplier`" + ` participated in. + +` + "`Claims`" + ` are pruned, according to protocol parameters, some time after their respective ` + "`proof`" + ` has been submitted and any dispute window has elapsed. + +This is done to minimize the rate at which state accumulates by eliminating claims as a long-term factor to persistence requirements. Example: $ poktrolld --home=$(POKTROLLD_HOME) q claim show-claims --node $(POCKET_NODE)`, Args: cobra.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) (err error) { + RunE: func(cmd *cobra.Command, args []string) error { sessionId := args[0] supplierAddr := args[1] diff --git a/x/supplier/client/cli/query_claim_test.go b/x/supplier/client/cli/query_claim_test.go index ac18e94b7..795b9a592 100644 --- a/x/supplier/client/cli/query_claim_test.go +++ b/x/supplier/client/cli/query_claim_test.go @@ -36,29 +36,29 @@ func TestClaim_Show(t *testing.T) { sessionId string supplierAddr string - args []string - err error - obj types.Claim + args []string + err error + claim types.Claim }{ { desc: "claim found", - sessionId: claims[0].SessionId, - supplierAddr: claims[0].SupplierAddress, + sessionId: claims[0].GetSessionHeader().GetSessionId(), + supplierAddr: claims[0].GetSupplierAddress(), - args: common, - obj: claims[0], + args: common, + claim: claims[0], }, { desc: "claim not found (wrong session ID)", sessionId: "wrong_session_id", - supplierAddr: claims[0].SupplierAddress, + supplierAddr: claims[0].GetSupplierAddress(), args: common, err: status.Error(codes.NotFound, "not found"), }, { desc: "claim not found (wrong supplier address)", - sessionId: claims[0].SessionId, + sessionId: claims[0].GetSessionHeader().GetSessionId(), supplierAddr: "wrong_supplier_address", args: common, @@ -82,10 +82,10 @@ func TestClaim_Show(t *testing.T) { var resp types.QueryGetClaimResponse require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) require.NotNil(t, resp.Claim) - require.Equal(t, - nullify.Fill(&tc.obj), - nullify.Fill(&resp.Claim), - ) + + require.Equal(t, tc.claim.GetSupplierAddress(), resp.Claim.GetSupplierAddress()) + require.Equal(t, tc.claim.GetRootHash(), resp.Claim.GetRootHash()) + require.Equal(t, tc.claim.GetSessionHeader(), resp.Claim.GetSessionHeader()) } }) } @@ -187,13 +187,13 @@ func TestClaim_List(t *testing.T) { }) t.Run("BySession", func(t *testing.T) { - sessionId := claims[0].SessionId + sessionId := claims[0].GetSessionHeader().SessionId args := prepareArgs(nil, 0, uint64(totalClaims), true) args = append(args, fmt.Sprintf("--%s=%s", cli.FlagSessionId, sessionId)) expectedClaims := make([]types.Claim, 0) for _, claim := range claims { - if claim.SessionId == sessionId { + if claim.GetSessionHeader().SessionId == sessionId { expectedClaims = append(expectedClaims, claim) } } @@ -212,13 +212,13 @@ func TestClaim_List(t *testing.T) { }) t.Run("ByHeight", func(t *testing.T) { - sessionEndHeight := claims[0].SessionEndBlockHeight + sessionEndHeight := claims[0].GetSessionHeader().GetSessionEndBlockHeight() args := prepareArgs(nil, 0, uint64(totalClaims), true) args = append(args, fmt.Sprintf("--%s=%d", cli.FlagSessionEndHeight, sessionEndHeight)) expectedClaims := make([]types.Claim, 0) for _, claim := range claims { - if claim.SessionEndBlockHeight == sessionEndHeight { + if claim.GetSessionHeader().GetSessionEndBlockHeight() == sessionEndHeight { expectedClaims = append(expectedClaims, claim) } } diff --git a/x/supplier/keeper/claim.go b/x/supplier/keeper/claim.go index e635a95d6..97ae8e3c6 100644 --- a/x/supplier/keeper/claim.go +++ b/x/supplier/keeper/claim.go @@ -10,19 +10,20 @@ import ( "github.com/pokt-network/poktroll/x/supplier/types" ) -// InsertClaim adds a claim to the store -func (k Keeper) InsertClaim(ctx sdk.Context, claim types.Claim) { - logger := k.Logger(ctx).With("method", "InsertClaim") +// UpsertClaim inserts or updates a specific claim in the store by index. +func (k Keeper) UpsertClaim(ctx sdk.Context, claim types.Claim) { + logger := k.Logger(ctx).With("method", "UpsertClaim") claimBz := k.cdc.MustMarshal(&claim) parentStore := ctx.KVStore(k.storeKey) // Update the primary store: ClaimPrimaryKey -> ClaimObject primaryStore := prefix.NewStore(parentStore, types.KeyPrefix(types.ClaimPrimaryKeyPrefix)) - primaryKey := types.ClaimPrimaryKey(claim.SessionId, claim.SupplierAddress) + sessionId := claim.GetSessionHeader().GetSessionId() + primaryKey := types.ClaimPrimaryKey(sessionId, claim.SupplierAddress) primaryStore.Set(primaryKey, claimBz) - logger.Info(fmt.Sprintf("inserted claim for supplier %s with primaryKey %s", claim.SupplierAddress, primaryKey)) + logger.Info(fmt.Sprintf("upserted claim for supplier %s with primaryKey %s", claim.SupplierAddress, primaryKey)) // Update the address index: supplierAddress -> [ClaimPrimaryKey] addressStoreIndex := prefix.NewStore(parentStore, types.KeyPrefix(types.ClaimSupplierAddressPrefix)) @@ -33,10 +34,11 @@ func (k Keeper) InsertClaim(ctx sdk.Context, claim types.Claim) { // Update the session end height index: sessionEndHeight -> [ClaimPrimaryKey] sessionHeightStoreIndex := prefix.NewStore(parentStore, types.KeyPrefix(types.ClaimSessionEndHeightPrefix)) - heightKey := types.ClaimSupplierEndSessionHeightKey(claim.SessionEndBlockHeight, primaryKey) + sessionEndBlockHeight := uint64(claim.GetSessionHeader().GetSessionEndBlockHeight()) + heightKey := types.ClaimSupplierEndSessionHeightKey(sessionEndBlockHeight, primaryKey) sessionHeightStoreIndex.Set(heightKey, primaryKey) - logger.Info(fmt.Sprintf("indexed claim for supplier %s at session ending height %d", claim.SupplierAddress, claim.SessionEndBlockHeight)) + logger.Info(fmt.Sprintf("indexed claim for supplier %s at session ending height %d", claim.SupplierAddress, sessionEndBlockHeight)) } // RemoveClaim removes a claim from the store @@ -59,7 +61,8 @@ func (k Keeper) RemoveClaim(ctx sdk.Context, sessionId, supplierAddr string) { sessionHeightStoreIndex := prefix.NewStore(parentStore, types.KeyPrefix(types.ClaimSessionEndHeightPrefix)) addressKey := types.ClaimSupplierAddressKey(claim.SupplierAddress, primaryKey) - heightKey := types.ClaimSupplierEndSessionHeightKey(claim.SessionEndBlockHeight, primaryKey) + sessionEndBlockHeight := uint64(claim.GetSessionHeader().GetSessionEndBlockHeight()) + heightKey := types.ClaimSupplierEndSessionHeightKey(sessionEndBlockHeight, primaryKey) // Delete all the entries (primary store and secondary indices) primaryStore.Delete(primaryKey) diff --git a/x/supplier/keeper/claim_test.go b/x/supplier/keeper/claim_test.go index 4e38a43d0..475350752 100644 --- a/x/supplier/keeper/claim_test.go +++ b/x/supplier/keeper/claim_test.go @@ -11,6 +11,7 @@ import ( keepertest "github.com/pokt-network/poktroll/testutil/keeper" "github.com/pokt-network/poktroll/testutil/nullify" "github.com/pokt-network/poktroll/testutil/sample" + sessiontypes "github.com/pokt-network/poktroll/x/session/types" "github.com/pokt-network/poktroll/x/supplier/keeper" "github.com/pokt-network/poktroll/x/supplier/types" ) @@ -22,10 +23,12 @@ func createNClaims(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.Claim claims := make([]types.Claim, n) for i := range claims { claims[i].SupplierAddress = sample.AccAddress() - claims[i].SessionId = fmt.Sprintf("session-%d", i) - claims[i].SessionEndBlockHeight = uint64(i) + claims[i].SessionHeader = &sessiontypes.SessionHeader{ + SessionId: fmt.Sprintf("session-%d", i), + SessionEndBlockHeight: int64(i), + } claims[i].RootHash = []byte(fmt.Sprintf("rootHash-%d", i)) - keeper.InsertClaim(ctx, claims[i]) + keeper.UpsertClaim(ctx, claims[i]) } return claims } @@ -35,7 +38,7 @@ func TestClaim_Get(t *testing.T) { claims := createNClaims(keeper, ctx, 10) for _, claim := range claims { foundClaim, isClaimFound := keeper.GetClaim(ctx, - claim.SessionId, + claim.GetSessionHeader().GetSessionId(), claim.SupplierAddress, ) require.True(t, isClaimFound) @@ -49,12 +52,13 @@ func TestClaim_Remove(t *testing.T) { keeper, ctx := keepertest.SupplierKeeper(t, nil) claims := createNClaims(keeper, ctx, 10) for _, claim := range claims { + sessionId := claim.GetSessionHeader().GetSessionId() keeper.RemoveClaim(ctx, - claim.SessionId, + sessionId, claim.SupplierAddress, ) _, isClaimFound := keeper.GetClaim(ctx, - claim.SessionId, + sessionId, claim.SupplierAddress, ) require.False(t, isClaimFound) @@ -90,7 +94,8 @@ func TestClaim_GetAll_ByHeight(t *testing.T) { claims := createNClaims(keeper, ctx, 10) // Get all claims for a given ending session block height - allFoundClaimsEndingAtHeight := keeper.GetClaimsByHeight(ctx, claims[6].SessionEndBlockHeight) + sessionEndHeight := claims[6].GetSessionHeader().GetSessionEndBlockHeight() + allFoundClaimsEndingAtHeight := keeper.GetClaimsByHeight(ctx, uint64(sessionEndHeight)) require.ElementsMatch(t, nullify.Fill([]types.Claim{claims[6]}), nullify.Fill(allFoundClaimsEndingAtHeight), @@ -102,7 +107,8 @@ func TestClaim_GetAll_BySession(t *testing.T) { claims := createNClaims(keeper, ctx, 10) // Get all claims for a given ending session block height - allFoundClaimsForSession := keeper.GetClaimsBySession(ctx, claims[8].SessionId) + sessionId := claims[8].GetSessionHeader().GetSessionId() + allFoundClaimsForSession := keeper.GetClaimsBySession(ctx, sessionId) require.ElementsMatch(t, nullify.Fill([]types.Claim{claims[8]}), nullify.Fill(allFoundClaimsForSession), diff --git a/x/supplier/keeper/msg_server_create_claim.go b/x/supplier/keeper/msg_server_create_claim.go index 7d911f95a..05e21a2e4 100644 --- a/x/supplier/keeper/msg_server_create_claim.go +++ b/x/supplier/keeper/msg_server_create_claim.go @@ -10,6 +10,9 @@ import ( ) func (k msgServer) CreateClaim(goCtx context.Context, msg *suppliertypes.MsgCreateClaim) (*suppliertypes.MsgCreateClaimResponse, error) { + // TODO_BLOCKER: Prevent Claim upserts after the ClaimWindow is closed. + // TODO_BLOCKER: Validate the signature on the Claim message corresponds to the supplier before Upserting. + ctx := sdk.UnwrapSDKContext(goCtx) logger := k.Logger(ctx).With("method", "CreateClaim") @@ -79,19 +82,18 @@ func (k msgServer) CreateClaim(goCtx context.Context, msg *suppliertypes.MsgCrea 2. [ ] msg distribution validation */ - // Construct and insert claim after all validation. + // Construct and upsert claim after all validation. claim := suppliertypes.Claim{ - SupplierAddress: msg.GetSupplierAddress(), - SessionId: msg.GetSessionHeader().GetSessionId(), - SessionEndBlockHeight: uint64(msg.GetSessionHeader().GetSessionEndBlockHeight()), - RootHash: msg.RootHash, + SupplierAddress: msg.GetSupplierAddress(), + SessionHeader: msg.GetSessionHeader(), + RootHash: msg.RootHash, } - k.Keeper.InsertClaim(ctx, claim) + k.Keeper.UpsertClaim(ctx, claim) logger. With( - "session_id", claim.GetSessionId(), - "session_end_height", claim.GetSessionEndBlockHeight(), + "session_id", claim.GetSessionHeader().GetSessionId(), + "session_end_height", claim.GetSessionHeader().GetSessionEndBlockHeight(), "supplier", claim.GetSupplierAddress(), ). Debug("created claim") diff --git a/x/supplier/keeper/msg_server_create_claim_test.go b/x/supplier/keeper/msg_server_create_claim_test.go index 70ac48c79..93bd2b5b2 100644 --- a/x/supplier/keeper/msg_server_create_claim_test.go +++ b/x/supplier/keeper/msg_server_create_claim_test.go @@ -43,10 +43,10 @@ func TestMsgServer_CreateClaim_Success(t *testing.T) { claims := claimRes.GetClaim() require.Lenf(t, claims, 1, "expected 1 claim, got %d", len(claims)) - require.Equal(t, claimMsg.SessionHeader.SessionId, claims[0].SessionId) - require.Equal(t, claimMsg.SupplierAddress, claims[0].SupplierAddress) - require.Equal(t, uint64(claimMsg.SessionHeader.GetSessionEndBlockHeight()), claims[0].SessionEndBlockHeight) - require.Equal(t, claimMsg.RootHash, claims[0].RootHash) + require.Equal(t, claimMsg.SessionHeader.SessionId, claims[0].GetSessionHeader().GetSessionId()) + require.Equal(t, claimMsg.SupplierAddress, claims[0].GetSupplierAddress()) + require.Equal(t, claimMsg.SessionHeader.GetSessionEndBlockHeight(), claims[0].GetSessionHeader().GetSessionEndBlockHeight()) + require.Equal(t, claimMsg.RootHash, claims[0].GetRootHash()) } func TestMsgServer_CreateClaim_Error(t *testing.T) { diff --git a/x/supplier/keeper/msg_server_submit_proof.go b/x/supplier/keeper/msg_server_submit_proof.go index 2715b7c8d..7a764a12d 100644 --- a/x/supplier/keeper/msg_server_submit_proof.go +++ b/x/supplier/keeper/msg_server_submit_proof.go @@ -9,6 +9,9 @@ import ( ) func (k msgServer) SubmitProof(goCtx context.Context, msg *types.MsgSubmitProof) (*types.MsgSubmitProofResponse, error) { + // TODO_BLOCKER: Prevent Proof upserts after the tokenomics module has processes the respective session. + // TODO_BLOCKER: Validate the signature on the Proof message corresponds to the supplier before Upserting. + ctx := sdk.UnwrapSDKContext(goCtx) if err := msg.ValidateBasic(); err != nil { diff --git a/x/supplier/keeper/proof.go b/x/supplier/keeper/proof.go index bb9188a98..aec052d5b 100644 --- a/x/supplier/keeper/proof.go +++ b/x/supplier/keeper/proof.go @@ -7,25 +7,27 @@ import ( "github.com/pokt-network/poktroll/x/supplier/types" ) -// SetProof set a specific proof in the store from its index -func (k Keeper) SetProof(ctx sdk.Context, proof types.Proof) { +// UpsertProof inserts or updates a specific proof in the store by index. +func (k Keeper) UpsertProof(ctx sdk.Context, proof types.Proof) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ProofKeyPrefix)) b := k.cdc.MustMarshal(&proof) + // TODO_NEXT(@bryanchriswhite #141): Refactor keys to support multiple indices. store.Set(types.ProofKey( - proof.Index, + proof.GetSessionHeader().GetSessionId(), ), b) } // GetProof returns a proof from its index func (k Keeper) GetProof( ctx sdk.Context, - index string, + sessionId string, ) (val types.Proof, found bool) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ProofKeyPrefix)) + // TODO_NEXT(@bryanchriswhite #141): Refactor proof keys to support multiple indices. b := store.Get(types.ProofKey( - index, + sessionId, )) if b == nil { return val, false @@ -38,10 +40,12 @@ func (k Keeper) GetProof( // RemoveProof removes a proof from the store func (k Keeper) RemoveProof( ctx sdk.Context, + // TODO_NEXT(@bryanchriswhite #141): Refactor proof keys to support multiple indices. index string, ) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ProofKeyPrefix)) + // TODO_NEXT(@bryanchriswhite #141): Refactor proof keys to support multiple indices. store.Delete(types.ProofKey( index, )) diff --git a/x/supplier/keeper/proof_test.go b/x/supplier/keeper/proof_test.go index a082a05bf..28d73ca7f 100644 --- a/x/supplier/keeper/proof_test.go +++ b/x/supplier/keeper/proof_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "fmt" "strconv" "testing" @@ -9,6 +10,10 @@ import ( keepertest "github.com/pokt-network/poktroll/testutil/keeper" "github.com/pokt-network/poktroll/testutil/nullify" + "github.com/pokt-network/poktroll/testutil/sample" + sessionkeeper "github.com/pokt-network/poktroll/x/session/keeper" + sessiontypes "github.com/pokt-network/poktroll/x/session/types" + sharedtypes "github.com/pokt-network/poktroll/x/shared/types" "github.com/pokt-network/poktroll/x/supplier/keeper" "github.com/pokt-network/poktroll/x/supplier/types" ) @@ -17,25 +22,35 @@ import ( var _ = strconv.IntSize func createNProofs(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.Proof { - items := make([]types.Proof, n) - for i := range items { - items[i].Index = strconv.Itoa(i) + proofs := make([]types.Proof, n) + for i := range proofs { + proofs[i] = types.Proof{ + SupplierAddress: sample.AccAddress(), + SessionHeader: &sessiontypes.SessionHeader{ + ApplicationAddress: sample.AccAddress(), + Service: &sharedtypes.Service{Id: testServiceId}, + SessionId: fmt.Sprintf("session-%d", i), + SessionStartBlockHeight: 1, + SessionEndBlockHeight: 1 + sessionkeeper.NumBlocksPerSession, + }, + ClosestMerkleProof: nil, + } - keeper.SetProof(ctx, items[i]) + keeper.UpsertProof(ctx, proofs[i]) } - return items + return proofs } func TestProofGet(t *testing.T) { keeper, ctx := keepertest.SupplierKeeper(t, nil) - items := createNProofs(keeper, ctx, 10) - for _, item := range items { + proofs := createNProofs(keeper, ctx, 10) + for _, proof := range proofs { rst, found := keeper.GetProof(ctx, - item.Index, + proof.GetSessionHeader().GetSessionId(), ) require.True(t, found) require.Equal(t, - nullify.Fill(&item), + nullify.Fill(&proof), nullify.Fill(&rst), ) } @@ -45,10 +60,10 @@ func TestProofRemove(t *testing.T) { items := createNProofs(keeper, ctx, 10) for _, item := range items { keeper.RemoveProof(ctx, - item.Index, + item.GetSessionHeader().GetSessionId(), ) _, found := keeper.GetProof(ctx, - item.Index, + item.GetSessionHeader().GetSessionId(), ) require.False(t, found) } diff --git a/x/supplier/keeper/query_claim_test.go b/x/supplier/keeper/query_claim_test.go index 1957362fa..1650c3bdf 100644 --- a/x/supplier/keeper/query_claim_test.go +++ b/x/supplier/keeper/query_claim_test.go @@ -31,7 +31,7 @@ func TestClaim_QuerySingle(t *testing.T) { desc: "First Claim", request: &types.QueryGetClaimRequest{ - SessionId: claims[0].SessionId, + SessionId: claims[0].GetSessionHeader().GetSessionId(), SupplierAddress: claims[0].SupplierAddress, }, @@ -42,7 +42,7 @@ func TestClaim_QuerySingle(t *testing.T) { desc: "Second Claim", request: &types.QueryGetClaimRequest{ - SessionId: claims[1].SessionId, + SessionId: claims[1].GetSessionHeader().GetSessionId(), SupplierAddress: claims[1].SupplierAddress, }, @@ -63,7 +63,7 @@ func TestClaim_QuerySingle(t *testing.T) { desc: "Claim Not Found - Random Supplier Address", request: &types.QueryGetClaimRequest{ - SessionId: claims[0].SessionId, + SessionId: claims[0].GetSessionHeader().GetSessionId(), SupplierAddress: sample.AccAddress(), }, @@ -81,7 +81,7 @@ func TestClaim_QuerySingle(t *testing.T) { { desc: "InvalidRequest - Missing SupplierAddress", request: &types.QueryGetClaimRequest{ - SessionId: claims[0].SessionId, + SessionId: claims[0].GetSessionHeader().GetSessionId(), // SupplierAddress: Intentionally Omitted, }, @@ -172,7 +172,7 @@ func TestClaim_QueryPaginated(t *testing.T) { t.Run("BySessionId", func(t *testing.T) { req := request(nil, 0, 0, true) req.Filter = &types.QueryAllClaimsRequest_SessionId{ - SessionId: claims[0].SessionId, + SessionId: claims[0].GetSessionHeader().GetSessionId(), } resp, err := keeper.AllClaims(wctx, req) require.NoError(t, err) @@ -182,7 +182,7 @@ func TestClaim_QueryPaginated(t *testing.T) { t.Run("BySessionEndHeight", func(t *testing.T) { req := request(nil, 0, 0, true) req.Filter = &types.QueryAllClaimsRequest_SessionEndHeight{ - SessionEndHeight: claims[0].SessionEndBlockHeight, + SessionEndHeight: uint64(claims[0].GetSessionHeader().GetSessionEndBlockHeight()), } resp, err := keeper.AllClaims(wctx, req) require.NoError(t, err) diff --git a/x/supplier/keeper/query_proof_test.go b/x/supplier/keeper/query_proof_test.go index a082d6e10..dcdec4c4e 100644 --- a/x/supplier/keeper/query_proof_test.go +++ b/x/supplier/keeper/query_proof_test.go @@ -31,14 +31,14 @@ func TestProofQuerySingle(t *testing.T) { { desc: "First", request: &types.QueryGetProofRequest{ - Index: msgs[0].Index, + Index: msgs[0].GetSessionHeader().GetSessionId(), }, response: &types.QueryGetProofResponse{Proof: msgs[0]}, }, { desc: "Second", request: &types.QueryGetProofRequest{ - Index: msgs[1].Index, + Index: msgs[1].GetSessionHeader().GetSessionId(), }, response: &types.QueryGetProofResponse{Proof: msgs[1]}, }, diff --git a/x/supplier/types/query_get_claim.go b/x/supplier/types/query_validation.go similarity index 83% rename from x/supplier/types/query_get_claim.go rename to x/supplier/types/query_validation.go index 0b7e1623f..5264b6f79 100644 --- a/x/supplier/types/query_get_claim.go +++ b/x/supplier/types/query_validation.go @@ -1,10 +1,12 @@ package types import ( - fmt "fmt" + "context" sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/pokt-network/poktroll/pkg/polylog" ) // NOTE: Please note that these messages are not of type `sdk.Msg`, and are therefore not a message/request @@ -27,6 +29,9 @@ func (query *QueryGetClaimRequest) ValidateBasic() error { // ValidateBasic performs basic (non-state-dependant) validation on a QueryAllClaimsRequest. func (query *QueryAllClaimsRequest) ValidateBasic() error { + // TODO_TECHDEBT: update function signature to receive a context. + logger := polylog.Ctx(context.TODO()) + switch filter := query.Filter.(type) { case *QueryAllClaimsRequest_SupplierAddress: if _, err := sdk.AccAddressFromBech32(filter.SupplierAddress); err != nil { @@ -35,7 +40,9 @@ func (query *QueryAllClaimsRequest) ValidateBasic() error { case *QueryAllClaimsRequest_SessionId: // TODO_TECHDEBT: Validate the session ID once we have a deterministic way to generate it - fmt.Println("TODO: SessionID check is currently a noop: ", filter.SessionId) + logger.Warn(). + Str("session_id", filter.SessionId). + Msg("TODO: SessionID check in claim request validation is currently a noop") case *QueryAllClaimsRequest_SessionEndHeight: if filter.SessionEndHeight < 0 { @@ -44,7 +51,7 @@ func (query *QueryAllClaimsRequest) ValidateBasic() error { default: // No filter is set - fmt.Println("No specific filter set") + logger.Debug().Msg("No specific filter set when requesting claims") } return nil }