-
Notifications
You must be signed in to change notification settings - Fork 33
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
[TECHDEBT] Consolidated PostgresContext and PostgresDB (#149) #219
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You didn't complete the original ask about consolidating txn
and tx
.
Let me add more detail:
type PostgresContext struct {
Height int64 // TODO(olshansky): `Height` is only externalized for testing purposes. Replace with helpers...
conn *pgx.Conn
tx pgx.Tx // This field is `tx`
blockstore kvstore.KVStore
}
// These functions use Txn()
func (pg *PostgresContext) GetCtxAndTxn() (context.Context, pgx.Tx, error) {
return context.TODO(), pg.GetTxn(), nil
}
func (pg *PostgresContext) GetTxn() pgx.Tx {
return pg.tx
}
Let's consolidate this terminology in order to lower cognitive load and increase readability
Also, please ensure that the structure field uses the GetTxn()
function instead of accessing the private field directly:
Ex.
if err := p.tx.Rollback(ctx); err != nil {
return err
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change this PR description to fill out the template provided
I don't believe it's as clear to the outsider.
Also, consider adding more detail to the changelog for tracking purposes
persistence/test/setup_test.go
Outdated
if strings.Contains(newActor.StakedTokens, "invalid") { | ||
fmt.Println("") | ||
} | ||
// if strings.Contains(newActor.StakedTokens, "invalid") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this commented out?
Also, if you're going to touch this code, it seems like you could easily satisfy that TODO there.
Perhaps it's out of scope?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was mainly to tend to require.NotContains(t, newActor.StakedTokens, "invalid")
given the require.NotContains
requirment above.
You're correct that it's out-of-scope so I reverted the changes and updated the comment
persistence/account.go
Outdated
@@ -23,7 +23,7 @@ func (p PostgresContext) GetAccountAmount(address []byte, height int64) (amount | |||
} | |||
|
|||
func (p PostgresContext) getAccountAmountStr(address string, height int64) (amount string, err error) { | |||
ctx, txn, err := p.DB.GetCtxAndTxn() | |||
ctx, txn, err := p.GetCtxAndTx() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to see txn
anywhere in this code anymore. Let's keep it consistent
Examples:
ctx, txn, err := p.GetCtxAndTx()
func (p *PostgresContext) GetChainsForActor(
ctx context.Context,
txn pgx.Tx,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it! Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolve conflicts then approve incoming!
@andrewnguyen22 Merged with main and pushed. |
Description
Tend to tech debt in the
persistence
module related to simplifying thePostgresContext
struct.Issue
Fixes #149
Type of change
Please mark the relevant option(s):
List of changes
PostgresContext
andPostgresDB
Tx
andBlockStore
NewFuzzTestPostgresContext
Testing
make test_all
README
Checklist