Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Supplier] refactor: proof store indices (2) #327

Merged
merged 12 commits into from
Jan 19, 2024
Next Next commit
refactor: off-chain session validation
bryanchriswhite committed Jan 17, 2024
commit 8ab21b6795da3734e6e9f07af72e098b20aa949b
28 changes: 5 additions & 23 deletions x/supplier/keeper/msg_server_create_claim.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

sessiontypes "github.com/pokt-network/poktroll/x/session/types"
suppliertypes "github.com/pokt-network/poktroll/x/supplier/types"
)

@@ -20,32 +19,15 @@ func (k msgServer) CreateClaim(goCtx context.Context, msg *suppliertypes.MsgCrea
return nil, err
}

sessionReq := &sessiontypes.QueryGetSessionRequest{
ApplicationAddress: msg.GetSessionHeader().GetApplicationAddress(),
Service: msg.GetSessionHeader().GetService(),
BlockHeight: msg.GetSessionHeader().GetSessionStartBlockHeight(),
}
sessionRes, err := k.Keeper.sessionKeeper.GetSession(goCtx, sessionReq)
sessionRes, err := k.ValidateSessionHeader(
goCtx,
msg.GetSessionHeader(),
msg.GetSupplierAddress(),
)
if err != nil {
return nil, err
}

logger.
With(
"session_id", sessionRes.GetSession().GetSessionId(),
"session_end_height", msg.GetSessionHeader().GetSessionEndBlockHeight(),
"supplier", msg.GetSupplierAddress(),
).
Debug("got sessionId for claim")

if sessionRes.Session.SessionId != msg.SessionHeader.SessionId {
return nil, suppliertypes.ErrSupplierInvalidSessionId.Wrapf(
"claimed sessionRes ID does not match on-chain sessionRes ID; expected %q, got %q",
sessionRes.Session.SessionId,
msg.SessionHeader.SessionId,
)
}

var found bool
for _, supplier := range sessionRes.GetSession().GetSuppliers() {
if supplier.Address == msg.GetSupplierAddress() {
46 changes: 46 additions & 0 deletions x/supplier/keeper/session.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"

sessiontypes "github.com/pokt-network/poktroll/x/session/types"
suppliertypes "github.com/pokt-network/poktroll/x/supplier/types"
)

func (k msgServer) ValidateSessionHeader(
goCtx context.Context,
sessionHeader *sessiontypes.SessionHeader,
supplierAddr string,
) (*sessiontypes.QueryGetSessionResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
logger := k.Logger(ctx).With("method", "SubmitProof")

sessionReq := &sessiontypes.QueryGetSessionRequest{
ApplicationAddress: sessionHeader.GetApplicationAddress(),
Service: sessionHeader.GetService(),
BlockHeight: sessionHeader.GetSessionStartBlockHeight(),
}

sessionRes, err := k.Keeper.sessionKeeper.GetSession(goCtx, sessionReq)
if err != nil {
return nil, err
}

logger.
With(
"session_id", sessionRes.GetSession().GetSessionId(),
"session_end_height", sessionHeader.GetSessionEndBlockHeight(),
"supplier", supplierAddr,
).
Debug("got sessionId for proof")
if sessionRes.Session.SessionId != sessionHeader.SessionId {
return nil, suppliertypes.ErrSupplierInvalidSessionId.Wrapf(
"claimed sessionRes ID does not match on-chain sessionRes ID; expected %q, got %q",
sessionRes.Session.SessionId,
sessionHeader.SessionId,
)
}
return sessionRes, nil
}