[TECHDEBT] Consolidated PostgresContext and PostgresDB (#149)#219
[TECHDEBT] Consolidated PostgresContext and PostgresDB (#149)#219
Conversation
There was a problem hiding this comment.
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
}
andrewnguyen22
left a comment
There was a problem hiding this comment.
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.
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.
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
|
|
||
| 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.
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,
andrewnguyen22
left a comment
There was a problem hiding this comment.
Resolve conflicts then approve incoming!
|
@andrewnguyen22 Merged with main and pushed. |



Description
Tend to tech debt in the
persistencemodule related to simplifying thePostgresContextstruct.Issue
Fixes #149
Type of change
Please mark the relevant option(s):
List of changes
PostgresContextandPostgresDBTxandBlockStoreNewFuzzTestPostgresContextTesting
make test_allREADMEChecklist