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

Ticket #211: finding unnecessary public functions in the Persistence Module #320

Merged
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5a8f9fe
#211 find unnecessary public func
Jasonyou1995 Oct 24, 2022
347ef7f
Keep the GetParameters for future implemenation
Jasonyou1995 Oct 27, 2022
edde382
Update application.go
Jasonyou1995 Oct 27, 2022
9a7a2ff
Update persistence_genesis.go
Jasonyou1995 Oct 27, 2022
9596ab0
Merge branch 'main' into issue/211/persistence-module-lowercase-funct…
Jasonyou1995 Oct 27, 2022
8df520c
merge to main
Jasonyou1995 Oct 27, 2022
0ccd1f1
update functions that can be private
Jasonyou1995 Oct 31, 2022
e8681ef
remove redundant files
Jasonyou1995 Nov 1, 2022
6ca5ff0
remote redundant proto files
Jasonyou1995 Nov 1, 2022
2fa470a
clean redundant files
Jasonyou1995 Nov 1, 2022
be0d5c8
Merge branch 'main' into issue/211/persistence-module-lowercase-funct…
Jasonyou1995 Nov 1, 2022
d1561f1
add to changelog and fix format issue
Jasonyou1995 Nov 3, 2022
e42b1f5
Adding FAQ document
Jasonyou1995 Nov 3, 2022
5149bac
clean code base in persistence/test/
Jasonyou1995 Nov 4, 2022
f218938
Update CHANGELOG
Jasonyou1995 Nov 4, 2022
92363fc
Clean persistence/types code base
Jasonyou1995 Nov 4, 2022
43602f0
Removing unnecessary space and newline in comments
Jasonyou1995 Nov 4, 2022
90bcd9d
Update docs/development/FAQ.md
Jasonyou1995 Nov 4, 2022
993dee4
Update docs/development/FAQ.md
Jasonyou1995 Nov 4, 2022
e0e2b91
Add consolidate TODO common for CHANGELOG
Jasonyou1995 Nov 4, 2022
d0da787
Remove unnecessary space in comments
Jasonyou1995 Nov 4, 2022
9fdfacd
Revert "clean code base in persistence/test/"
Jasonyou1995 Nov 4, 2022
3d1a95d
Apply suggestions from code review
Jasonyou1995 Nov 7, 2022
837f08d
Update CHANGELOG
Jasonyou1995 Nov 7, 2022
9db4b05
Update test
Jasonyou1995 Nov 7, 2022
936c544
Functions update in test package (non-test functions)
Jasonyou1995 Nov 7, 2022
198ce48
Revert "Functions update in test package (non-test functions)"
Jasonyou1995 Nov 7, 2022
e720e02
Test functions update
Jasonyou1995 Nov 7, 2022
b8b4ef0
rpc file added
Jasonyou1995 Nov 8, 2022
3c2c6d8
Update CHANGELOG
Jasonyou1995 Nov 8, 2022
51b2ed1
Merge branch 'main' into issue/211/persistence-module-lowercase-funct…
Jasonyou1995 Nov 11, 2022
4ef818b
Delete client.gen.go
Jasonyou1995 Nov 11, 2022
ebf05ed
Delete server.gen.go
Jasonyou1995 Nov 11, 2022
3dcfc8d
Update .gitignore
Jasonyou1995 Nov 11, 2022
636d550
Apply suggestions from code review
Jasonyou1995 Nov 11, 2022
258ecb4
Update .gitignore
Jasonyou1995 Nov 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/development/FAQ.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# FAQ
Olshansk marked this conversation as resolved.
Show resolved Hide resolved

A list of common issues & resolutions shared by the V1 contributors

## Avoid redundant files from iCloud backup

* **Issue**: when working on MacOS with iCloud backup turned on, redundant files could be generated in GitHub projects. (e.g. `file.go` and `file 2.go`) Details can be found here in [this link](https://stackoverflow.com/a/62387243).
* **Solution**: adding `.nosync` as suffix to the workspace folder, e.g. `pocket.nosync`. Alternative, working in a folder that iCloud doesn't touch also works.

Jasonyou1995 marked this conversation as resolved.
Show resolved Hide resolved
## Consider turning of the `gofmt` in your IDE to prevent unexpected formatting
Jasonyou1995 marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions persistence/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ All notable changes to this module will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

**TODO:** consolidate `persistence/docs/CHANGELOG` and `persistence/CHANGELOG.md`
Jasonyou1995 marked this conversation as resolved.
Show resolved Hide resolved

## [Unreleased]


## [0.0.0.6] - 2022-10-06

- Don't ignore the exit code of `m.Run()` in the unit tests
Expand Down
17 changes: 8 additions & 9 deletions persistence/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ const (

// --- Account Functions ---

//
func (p PostgresContext) GetAccountAmount(address []byte, height int64) (amount string, err error) {
return p.getAccountAmountStr(hex.EncodeToString(address), height)
}

func (p PostgresContext) getAccountAmountStr(address string, height int64) (amount string, err error) {
ctx, tx, err := p.GetCtxAndTx()
ctx, tx, err := p.getCtxAndTx()
if err != nil {
return
}
Expand Down Expand Up @@ -51,9 +50,9 @@ func (p PostgresContext) SubtractAccountAmount(address []byte, amount string) er
}

// DISCUSS(team): If we are okay with `GetAccountAmount` return 0 as a default, this function can leverage
// `operationAccountAmount` with `*orig = *delta` and make everything much simpler.
// `operationAccountAmount` with `*orig = *delta` and make everything much simpler.
func (p PostgresContext) SetAccountAmount(address []byte, amount string) error {
ctx, tx, err := p.GetCtxAndTx()
ctx, tx, err := p.getCtxAndTx()
if err != nil {
return err
}
Expand All @@ -76,7 +75,7 @@ func (p *PostgresContext) operationAccountAmount(address []byte, deltaAmount str

// TODO(andrew): remove address param
func (p PostgresContext) InsertPool(name string, address []byte, amount string) error {
ctx, tx, err := p.GetCtxAndTx()
ctx, tx, err := p.getCtxAndTx()
if err != nil {
return err
}
Expand All @@ -91,7 +90,7 @@ func (p PostgresContext) InsertPool(name string, address []byte, amount string)
}

func (p PostgresContext) GetPoolAmount(name string, height int64) (amount string, err error) {
ctx, tx, err := p.GetCtxAndTx()
ctx, tx, err := p.getCtxAndTx()
if err != nil {
return
}
Expand Down Expand Up @@ -119,10 +118,10 @@ func (p PostgresContext) SubtractPoolAmount(name string, amount string) error {
}

// DISCUSS(team): If we are okay with `GetPoolAmount` return 0 as a default, this function can leverage
// `operationPoolAmount` with `*orig = *delta` and make everything much simpler.
// `operationPoolAmount` with `*orig = *delta` and make everything much simpler.
// DISCUSS(team): Do we have a use-case for this function?
func (p PostgresContext) SetPoolAmount(name string, amount string) error {
ctx, tx, err := p.GetCtxAndTx()
ctx, tx, err := p.getCtxAndTx()
if err != nil {
return err
}
Expand All @@ -144,7 +143,7 @@ func (p *PostgresContext) operationPoolOrAccAmount(name, amount string,
op func(*big.Int, *big.Int) error,
getAmount func(string, int64) (string, error),
insert func(name, amount string, height int64) string) error {
ctx, tx, err := p.GetCtxAndTx()
ctx, tx, err := p.getCtxAndTx()
if err != nil {
return err
}
Expand Down
13 changes: 3 additions & 10 deletions persistence/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package persistence

import (
"encoding/hex"
"log"

"github.com/pokt-network/pocket/persistence/types"
"github.com/pokt-network/pocket/shared/modules"
)
Expand All @@ -13,7 +11,7 @@ func (p PostgresContext) GetAppExists(address []byte, height int64) (exists bool
}

func (p PostgresContext) GetApp(address []byte, height int64) (operator, publicKey, stakedTokens, maxRelays, outputAddress string, pauseHeight, unstakingHeight int64, chains []string, err error) {
actor, err := p.GetActor(types.ApplicationActor, address, height)
actor, err := p.getActor(types.ApplicationActor, address, height)
operator = actor.Address
publicKey = actor.PublicKey
stakedTokens = actor.StakedAmount
Expand Down Expand Up @@ -50,16 +48,11 @@ func (p PostgresContext) UpdateApp(address []byte, maxRelays string, stakedAmoun
}

func (p PostgresContext) GetAppStakeAmount(height int64, address []byte) (string, error) {
return p.GetActorStakeAmount(types.ApplicationActor, address, height)
return p.getActorStakeAmount(types.ApplicationActor, address, height)
}

func (p PostgresContext) SetAppStakeAmount(address []byte, stakeAmount string) error {
return p.SetActorStakeAmount(types.ApplicationActor, address, stakeAmount)
}

func (p PostgresContext) DeleteApp(_ []byte) error {
log.Println("[DEBUG] DeleteApp is a NOOP")
return nil
return p.setActorStakeAmount(types.ApplicationActor, address, stakeAmount)
}

func (p PostgresContext) GetAppsReadyToUnstake(height int64, _ int32) ([]modules.IUnstakingActor, error) {
Expand Down
6 changes: 3 additions & 3 deletions persistence/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// OPTIMIZE(team): get from blockstore or keep in memory
func (p PostgresContext) GetLatestBlockHeight() (latestHeight uint64, err error) {
ctx, tx, err := p.GetCtxAndTx()
ctx, tx, err := p.getCtxAndTx()
if err != nil {
return 0, err
}
Expand All @@ -21,7 +21,7 @@ func (p PostgresContext) GetLatestBlockHeight() (latestHeight uint64, err error)

// OPTIMIZE(team): get from blockstore or keep in cache/memory
func (p PostgresContext) GetBlockHash(height int64) ([]byte, error) {
ctx, tx, err := p.GetCtxAndTx()
ctx, tx, err := p.getCtxAndTx()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -67,7 +67,7 @@ func (p PostgresContext) StoreBlock(blockProtoBytes []byte) error {
}

func (p PostgresContext) InsertBlock(height uint64, hash string, proposerAddr []byte, quorumCert []byte) error {
ctx, tx, err := p.GetCtxAndTx()
ctx, tx, err := p.getCtxAndTx()
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions persistence/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ type PostgresContext struct {
txIndexer indexer.TxIndexer
}

func (pg *PostgresContext) GetCtxAndTx() (context.Context, pgx.Tx, error) {
func (pg *PostgresContext) getCtxAndTx() (context.Context, pgx.Tx, error) {
return context.TODO(), pg.GetTx(), nil
}

func (pg *PostgresContext) GetTx() pgx.Tx {
return pg.tx
}

func (pg *PostgresContext) GetCtx() (context.Context, error) {
func (pg *PostgresContext) getCtx() (context.Context, error) {
return context.TODO(), nil
}

Expand Down Expand Up @@ -187,7 +187,7 @@ func initializeBlockTables(ctx context.Context, db *pgx.Conn) error {

// Exposed for testing purposes only
func (p PostgresContext) DebugClearAll() error {
ctx, tx, err := p.GetCtxAndTx()
ctx, tx, err := p.getCtxAndTx()
if err != nil {
return err
}
Expand Down
34 changes: 34 additions & 0 deletions persistence/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,42 @@ All notable changes to this module will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

**TODO:** consolidate `persistence/docs/CHANGELOG` and `persistence/CHANGELOG.md`
Jasonyou1995 marked this conversation as resolved.
Show resolved Hide resolved

## [Unreleased]
Jasonyou1995 marked this conversation as resolved.
Show resolved Hide resolved

## [0.0.0.9] - 2022-11-04
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the date prior to commit


- Changed the following exposed functions to lowercase non-exported functions
Jasonyou1995 marked this conversation as resolved.
Show resolved Hide resolved
- [./pocket/persistence/]
- GetActor
- GetActorFromRow
- GetChainsForActor
- SetActorStakeAmount
- GetActorStakeAmount
- GetCtxAndTx
- GetCtx
- SetValidatorStakedTokens
- GetValidatorStakedTokens
- [./pocket/persistence/types]
- ProtocolActorTableSchema
- ProtocolActorChainsTableSchema
- SelectChains
- ReadyToUnstake
- InsertChains
- UpdateUnstakingHeight
- UpdateStakeAmount
- UpdatePausedHeight
- UpdateUnstakedHeightIfPausedBefore
- AccToAccInterface
- TestInsertParams
- AccountOrPoolSchema
- InsertAcc
- SelectBalance
- [./pocket/persistence/test]
- GetGenericActor
- NewTestGenericActor

## [0.0.0.8] - 2022-10-19

- Fixed `ToPersistenceActors()` by filling all structure fields
Expand Down
6 changes: 3 additions & 3 deletions persistence/fisherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func (p PostgresContext) GetFishermanExists(address []byte, height int64) (exist
}

func (p PostgresContext) GetFisherman(address []byte, height int64) (operator, publicKey, stakedTokens, serviceURL, outputAddress string, pausedHeight, unstakingHeight int64, chains []string, err error) {
actor, err := p.GetActor(types.FishermanActor, address, height)
actor, err := p.getActor(types.FishermanActor, address, height)
operator = actor.Address
publicKey = actor.PublicKey
stakedTokens = actor.StakedAmount
Expand Down Expand Up @@ -49,11 +49,11 @@ func (p PostgresContext) UpdateFisherman(address []byte, serviceURL string, stak
}

func (p PostgresContext) GetFishermanStakeAmount(height int64, address []byte) (string, error) {
return p.GetActorStakeAmount(types.FishermanActor, address, height)
return p.getActorStakeAmount(types.FishermanActor, address, height)
}

func (p PostgresContext) SetFishermanStakeAmount(address []byte, stakeAmount string) error {
return p.SetActorStakeAmount(types.FishermanActor, address, stakeAmount)
return p.setActorStakeAmount(types.FishermanActor, address, stakeAmount)
}

func (p PostgresContext) GetFishermenReadyToUnstake(height int64, status int32) ([]modules.IUnstakingActor, error) {
Expand Down
32 changes: 15 additions & 17 deletions persistence/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,10 @@ func (m *persistenceModule) populateGenesisState(state modules.PersistenceGenesi
}

// TODO(pocket/issues/149): All of the functions below following a structure similar to `GetAll<Actor>`
//
// can easily be refactored and condensed into a single function using a generic type or a common
//
// interface.
// interface.
func (p PostgresContext) GetAllAccounts(height int64) (accs []modules.Account, err error) {
ctx, tx, err := p.GetCtxAndTx()
ctx, tx, err := p.getCtxAndTx()
if err != nil {
return nil, err
}
Expand All @@ -184,7 +182,7 @@ func (p PostgresContext) GetAllAccounts(height int64) (accs []modules.Account, e

// CLEANUP: Consolidate with GetAllAccounts.
func (p PostgresContext) GetAllPools(height int64) (accs []modules.Account, err error) {
ctx, tx, err := p.GetCtxAndTx()
ctx, tx, err := p.getCtxAndTx()
if err != nil {
return nil, err
}
Expand All @@ -203,7 +201,7 @@ func (p PostgresContext) GetAllPools(height int64) (accs []modules.Account, err
}

func (p PostgresContext) GetAllApps(height int64) (apps []modules.Actor, err error) {
ctx, tx, err := p.GetCtxAndTx()
ctx, tx, err := p.getCtxAndTx()
if err != nil {
return nil, err
}
Expand All @@ -214,15 +212,15 @@ func (p PostgresContext) GetAllApps(height int64) (apps []modules.Actor, err err
var actors []*types.Actor
for rows.Next() {
var actor *types.Actor
actor, height, err = p.GetActorFromRow(rows)
actor, height, err = p.getActorFromRow(rows)
if err != nil {
return
}
actors = append(actors, actor)
}
rows.Close()
for _, actor := range actors {
actor, err = p.GetChainsForActor(ctx, tx, types.ApplicationActor, actor, height)
actor, err = p.getChainsForActor(ctx, tx, types.ApplicationActor, actor, height)
if err != nil {
return
}
Expand All @@ -232,7 +230,7 @@ func (p PostgresContext) GetAllApps(height int64) (apps []modules.Actor, err err
}

func (p PostgresContext) GetAllValidators(height int64) (vals []modules.Actor, err error) {
ctx, tx, err := p.GetCtxAndTx()
ctx, tx, err := p.getCtxAndTx()
if err != nil {
return nil, err
}
Expand All @@ -243,15 +241,15 @@ func (p PostgresContext) GetAllValidators(height int64) (vals []modules.Actor, e
var actors []*types.Actor
for rows.Next() {
var actor *types.Actor
actor, height, err = p.GetActorFromRow(rows)
actor, height, err = p.getActorFromRow(rows)
if err != nil {
return
}
actors = append(actors, actor)
}
rows.Close()
for _, actor := range actors {
actor, err = p.GetChainsForActor(ctx, tx, types.ApplicationActor, actor, height)
actor, err = p.getChainsForActor(ctx, tx, types.ApplicationActor, actor, height)
if err != nil {
return
}
Expand All @@ -261,7 +259,7 @@ func (p PostgresContext) GetAllValidators(height int64) (vals []modules.Actor, e
}

func (p PostgresContext) GetAllServiceNodes(height int64) (sn []modules.Actor, err error) {
ctx, tx, err := p.GetCtxAndTx()
ctx, tx, err := p.getCtxAndTx()
if err != nil {
return nil, err
}
Expand All @@ -272,15 +270,15 @@ func (p PostgresContext) GetAllServiceNodes(height int64) (sn []modules.Actor, e
var actors []*types.Actor
for rows.Next() {
var actor *types.Actor
actor, height, err = p.GetActorFromRow(rows)
actor, height, err = p.getActorFromRow(rows)
if err != nil {
return
}
actors = append(actors, actor)
}
rows.Close()
for _, actor := range actors {
actor, err = p.GetChainsForActor(ctx, tx, types.ServiceNodeActor, actor, height)
actor, err = p.getChainsForActor(ctx, tx, types.ServiceNodeActor, actor, height)
if err != nil {
return
}
Expand All @@ -290,7 +288,7 @@ func (p PostgresContext) GetAllServiceNodes(height int64) (sn []modules.Actor, e
}

func (p PostgresContext) GetAllFishermen(height int64) (f []modules.Actor, err error) {
ctx, tx, err := p.GetCtxAndTx()
ctx, tx, err := p.getCtxAndTx()
if err != nil {
return nil, err
}
Expand All @@ -301,15 +299,15 @@ func (p PostgresContext) GetAllFishermen(height int64) (f []modules.Actor, err e
var actors []*types.Actor
for rows.Next() {
var actor *types.Actor
actor, height, err = p.GetActorFromRow(rows)
actor, height, err = p.getActorFromRow(rows)
if err != nil {
return
}
actors = append(actors, actor)
}
rows.Close()
for _, actor := range actors {
actor, err = p.GetChainsForActor(ctx, tx, types.FishermanActor, actor, height)
actor, err = p.getChainsForActor(ctx, tx, types.FishermanActor, actor, height)
if err != nil {
return
}
Expand Down
Loading