pokt-network / poktroll

The official Shannon upgrade implementation of the Pocket Network Protocol implemented using the Cosmos SDK
MIT License
15 stars 8 forks source link

[Client, Code Health] Refactor client packages #633

Open bryanchriswhite opened 4 months ago

bryanchriswhite commented 4 months ago

Objective

  1. Package re-org.
  2. Interface refactoring.

Origin Document

Packages - Before

./pkg/client/query
├── accquerier.go        ==>    ./pkg/client/auth/querier.go
├── appquerier.go        ==>    ./pkg/client/app/querier.go
├── codec.go
├── errors.go            ==>    ./pkt/client/<module>/errors.go (split)
├── godoc.go
├── sessionquerier.go    ==>    ./pkg/client/session/querier.go
├── supplierquerier.go   ==>    ./pkg/client/supplier/querier.go
└── types
    └── context.go

./pkg/client/supplier
├── client.go
├── client_integration_test.go
├── client_test.go
└── options.go

Packages - After

./pkg/client/query
├── godoc.go
└── types
    └── context.go

./pkg/client/auth
├── querier.go
└── querier_test.go

./pkg/client/supplier
├── client.go
├── client_integration_test.go
├── client_test.go
├── querier.go
├── querier_test.go
└── options.go

./pkg/client/proof
├── client.go
├── client_integration_test.go
├── client_test.go
├── querier.go
├── querier_test.go
└── options.go

./pkg/client/session
├── client.go
├── client_integration_test.go
├── client_test.go
├── querier.go
├── querier_test.go
└── options.go

SessionClient / SessionQueryClient Interfaces - Before

---
title: SessionClient Before
---

classDiagram

class SessionQueryClient {
    <<interface>>
    GetSession(appAddress, serviceId string, blockHeight int64) (*types.Session, error)

    %% GetSessionStartHeight(height int64) int64
    %% GetSessionEndHeight(height int64) int64
    %% GetSession(appAddress, serviceId string, height int64) (*types.Session, error)
    %% GetSessionId(appPubKey, serviceId string, blockHash []byte, height int64) (sessionId string, sessionIdBz []byte)
    %% GetSessionNumber(height int64) int64
    %% GetGracePeriodBlockCount() (int64, error)
    %% GetParams() types.Params
}

sessionQuerier --|> SessionQueryClient

namespace Off-Chain {
    class sessionQuerier {
        clientCon grpc.Connection
        sessionQuerier QueryClient
    }

    class QueryClient {
        <<interface>>
        Params(*QueryParamsRequest, ...grpc.CallOption) (*QueryParamsResponse, error)
        GetSession(*QueryGetSessionRequest, ...grpc.CallOption) (*QueryGetSessionResponse, error)
    }

    class RelayerSessionsManager {
        ...
    }
}

sessionQuerier --* QueryClient

QueryClient ..> SessionKeeper
%% SessionQueryClient ..> SessionKeeper

namespace On-Chain {
    class SessionKeeper {
        GetParams() (params types.Params)
        GetSession(req *types.QueryGetSessionRequest) (*types.QueryGetSessionResponse, error)
        Params(*types.QueryParamsRequest) (*types.QueryParamsResponse, error)
        ...
    }

    class x_session_keeper__static_functions {
        <<package>>
        GetSessionStartHeight(height int64) int64
        GetSessionEndHeight(height int64) int64
        GetSessionId(appPubKey, serviceId string, blockHash []byte, height int64) (sessionId string, sessionIdBz []byte)
        GetSessionNumber(height int64) int64
        GetGracePeriodBlockCount() (int64, error)
    }

    class ApplicationKeeper {
        UndelegateFromGateway(...)
    }
}

namespace pkg_crypto_rings {
    class RingClient {
        ...
    }

    class pkg_crypto_rings__static_functions {
        GetRingAddressesAtBlock(*types.Application, height int64) []string
    }
}

pkg_crypto_rings__static_functions --o x_session_keeper__static_functions

SessionKeeper --o x_session_keeper__static_functions

ApplicationKeeper --o x_session_keeper__static_functions

RelayerSessionsManager --o x_session_keeper__static_functions

SessionClient / SessionQueryClient Interfaces After

---
title: SessionClient After
---

classDiagram

sessionClient --|> SessionClient

namespace Off-Chain {
    class sessionClient {
        clientCon grpc.Connection
        sessionQuerier QueryClient
    }

    class QueryClient {
        <<interface>>
        Params(*QueryParamsRequest, ...grpc.CallOption) (*QueryParamsResponse, error)
        GetSession(*QueryGetSessionRequest, ...grpc.CallOption) (*QueryGetSessionResponse, error)
        ...
    }

    %% class RelayerSessionsManager {
    %%     ...
    %% }

    class SessionClient {
        <<interface>>
        SessionQueryClient
    }
}

%% RelayerSessionsManager --o SessionClient

class SessionQueryClient {
    <<interface>>
    GetSessionStartHeight(height int64) int64
    GetSessionEndHeight(height int64) int64
    GetSession(appAddress, serviceId string, height int64) (*types.Session, error)
    GetSessionId(appPubKey, serviceId string, blockHash []byte, height int64) (sessionId string, sessionIdBz []byte)
    GetSessionNumber(height int64) int64
    GetGracePeriodBlockCount() (int64, error)
    GetParams() types.Params
}

SessionClient --* SessionQueryClient

sessionClient --* QueryClient

SessionKeeperQueryClient --|> SessionQueryClient

SessionKeeperQueryClient --o SessionKeeper
QueryClient ..> SessionKeeper

namespace On-Chain {
    class SessionKeeper {
        GetParams() (params types.Params)
        GetSession(req *types.QueryGetSessionRequest) (*types.QueryGetSessionResponse, error)
        Params(*types.QueryParamsRequest) (*types.QueryParamsResponse, error)
        ...
    }

    %% class ApplicationKeeper {
    %%     UndelegateFromGateway(...)
    %% }

    class SessionKeeperQueryClient {
        SessionQueryClient
    }
}

namespace pkg_crypto_ring {
    class RingClient {
        GetRingAddressesAtBlock(*types.Application, height int64) []string
        ...
    }
}

RingClient --o SessionQueryClient

%% ApplicationKeeper --o SessionKeeperQueryClient
%% ApplicationKeeper ..> SessionKeeper: num_blocks_per_session param

SupplierClient / ProofClient

Before

---
title: Supplier/Proof Clients Before
---

classDiagram

class supplierClient {
    SupplierQueryClient
    CreateClaim(_ SessionHeader, rootHash []byte) error
  SubmitProof(_ SessionHeader, proof *smt.SparseMerkleClosestProof) error    
}

supplierClient --|> SupplierClient

class SupplierClient {
  <<interface>>
    CreateClaim(_ SessionHeader, rootHash []byte) error
    SubmitProof(_ SessionHeader, proof *smt.SparseMerkleClosestProof) error
}

class SupplierQueryClient {
    <<interface>>
    GetSupplier(supplierAddress string) (Supplier, error)   
}

supplierQuerier --|> SupplierQueryClient

class supplierQuerier {
    clientCon grpc.Connection
    sessionQuerier QueryClient
}

class SupplierKeeper {
    GetSupplier(supplierAddress string) Supplier   
}

supplierClient ..o supplierQuerier
supplierClient --|> SupplierQueryClient
supplierQuerier ..> SupplierKeeper
%% SupplierClient ..> SupplierKeeper
%% SupplierQueryClient ..> SupplierKeeper

After

---
title: Supplier/Proof Clients After
---

classDiagram

    proofClient --|> ProofClient

%% namespace Off-Chain{
    class proofClient {
        client.ProofQueryClient
        txClient client.TxClient
        txCtx client.TxContext
        CreateClaim(_ sessiontypes.SessionHeader, rootHash []byte) error
        SubmitProof(_ SessionHeader, proof *smt.SparseMerkleClosestProof) error
    }

    class supplierClient {
        SupplierQueryClient
    }

    class ProofClient {
        <<interface>>
        client.ProofQueryClient
        CreateClaim(_ sessiontypes.SessionHeader, rootHash []byte) error
        SubmitProof(_ SessionHeader, proof *smt.SparseMerkleClosestProof) error
    }

    class SupplierClient {
        <<interface>>
        SupplierQueryClient
        %% StakeSupplier(supplierAddr string, amount sdk.Coins)
        %% UnstakeSupplier(supplierAddr string, amount sdk.Coins)
    }

    class supplierQueryClient {
      clientConn      grpc.ClientConn
        supplierQueryClient suppliertypes.QueryClient
    }
    class proofQueryClient {
        GetParams() *prooftypes.Params
    }
%% }

ProofClient --|> ProofQueryClient

proofClient ..o proofQueryClient

class ProofQueryClient {
    <<interface>>
    GetParams() *prooftypes.Params
}

SupplierClient --|> SupplierQueryClient

class SupplierQueryClient {
    <<interface>>
    GetSupplier(supplierAddr string) (sharedtypes.Supplier, error)   
}

supplierClient ..o supplierQueryClient
supplierClient --|> SupplierClient

supplierQueryClient --|> SupplierQueryClient
proofQueryClient --|> ProofQueryClient

class SupplierKeeper {
    GetSupplier(supplierAddress string) Supplier
}

%% supplierClient --|> SupplierQueryClient
supplierQueryClient ..> SupplierKeeper

class ProofKeeper {
    GetParams() prooftypes.Params
    UpsertProof(proof prooftypes.Proof)
    UpsertClaim(claim prooftypes.Claim)
}

proofQueryClient ..> ProofKeeper
proofClient ..> ProofKeeper

Goals

Deliverables

Non-goals / Non-deliverables

General deliverables


Creator: @bryanchriswhite

Olshansk commented 2 hours ago

@bryanchriswhite Do you think we still need this?