pokt-network / pocket-core

Official implementation of the Pocket Network Protocol
http://www.pokt.network
MIT License
210 stars 103 forks source link

Mesh rc 0.4.3 #1576

Closed nodiesBlade closed 1 year ago

nodiesBlade commented 1 year ago

Description

We should invalidate sessions based of some new errors before a relay / after a relay is handled in order to serve the least amount of free relays.

Here are all the invalid session errors we should account for

func (s Session) Validate(node sdk.Address, app appexported.ApplicationI, sessionNodeCount int) sdk.Error {
    // validate chain
    if len(s.SessionHeader.Chain) == 0 {
        return NewEmptyNonNativeChainError(ModuleName)
    }
    // validate sessionBlockHeight
    if s.SessionHeader.SessionBlockHeight < 1 {
        return NewInvalidBlockHeightError(ModuleName)
    }
    // validate the app public key
    if err := PubKeyVerification(s.SessionHeader.ApplicationPubKey); err != nil {
        return err
    }
    // validate app corresponds to appPubKey
    if app.GetPublicKey().RawString() != s.SessionHeader.ApplicationPubKey {
        return NewInvalidAppPubKeyError(ModuleName)
    }
    // validate app chains
    chains := app.GetChains()
    found := false
    for _, c := range chains {
        if c == s.SessionHeader.Chain {
            found = true
            break
        }
    }
    if !found {
        return NewUnsupportedBlockchainAppError(ModuleName)
    }
    // validate sessionNodes
    err := s.SessionNodes.Validate(sessionNodeCount)
    if err != nil {
        return err
    }
    // validate node is of the session
    if !s.SessionNodes.Contains(node) {
        return NewInvalidSessionError(ModuleName)
    }
    return nil
}

This was inspired after seeing portal send us relays with an invalid app and we were serving them for free (but not retrying to send to full node)