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

[Client, Code Health] Refactor client packages #633

Open
4 tasks
bryanchriswhite opened this issue Jun 25, 2024 · 0 comments
Open
4 tasks

[Client, Code Health] Refactor client packages #633

bryanchriswhite opened this issue Jun 25, 2024 · 0 comments
Assignees
Labels
code health Cleans up some code off-chain Off-chain business logic

Comments

@bryanchriswhite
Copy link
Contributor

bryanchriswhite commented Jun 25, 2024

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
Loading

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

Loading

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
Loading

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
Loading

Goals

  • Improve maintainability and readability by reorganizing client packages to follow a holistic convention.

Deliverables

  • ...

Non-goals / Non-deliverables

  • ...

General deliverables

  • Comments: Add/update TODOs and comments alongside the source code so it is easier to follow.
  • Testing: Add new tests (unit and/or E2E) to the test suite.
  • Makefile: Add new targets to the Makefile to make the new functionality easier to use.
  • Documentation: Update architectural or development READMEs; use mermaid diagrams where appropriate.

Creator: @bryanchriswhite

@bryanchriswhite bryanchriswhite self-assigned this Jun 25, 2024
@bryanchriswhite bryanchriswhite added off-chain Off-chain business logic code health Cleans up some code labels Jul 8, 2024
@bryanchriswhite bryanchriswhite added this to the Shannon MainNet milestone Jul 8, 2024
@red-0ne red-0ne self-assigned this Jul 15, 2024
@bryanchriswhite bryanchriswhite linked a pull request Jul 18, 2024 that will close this issue
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code health Cleans up some code off-chain Off-chain business logic
Projects
Status: 📋 Backlog
Development

Successfully merging a pull request may close this issue.

2 participants