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

[Utility] Session Interface - GetSession Implementation (1st iteration) #683

Merged
merged 58 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
c473aea
session.proto added - good starting point
Olshansk Apr 11, 2023
c0f7269
Got session to almost generate
Olshansk Apr 11, 2023
11353f7
Merge branch 'main' into issues/569/session_impl
Olshansk Apr 12, 2023
363f4ac
Snapshot before changing how we manage chains
Olshansk Apr 12, 2023
fc0f1f5
Added fisherman_per_session_owner
Olshansk Apr 12, 2023
7eff6f1
Merge branch 'main' into issues/569/session_impl
Olshansk Apr 12, 2023
74f11be
All unit tests pasing again
Olshansk Apr 13, 2023
4f4cbbc
Added TestSession_SessionHeight
Olshansk Apr 13, 2023
4b096bf
Merge branch 'main' into issues/569/session_impl
Olshansk Apr 13, 2023
0bf2d75
Remove read ctx
Olshansk Apr 13, 2023
6c04122
Refactor some tests
Olshansk Apr 14, 2023
c913c6d
Merge branch 'main' into issues/569/session_impl
Olshansk Apr 14, 2023
bfceded
Added a test validating num of servicers and fisherman is correct
Olshansk Apr 15, 2023
96fe1a2
Merge branch 'main' into issues/569/session_impl
Olshansk Apr 17, 2023
2eb3c62
Unit tests passing before adding more complex ones
Olshansk Apr 17, 2023
42c59ec
Finished TestSession_GetSession_ServicersAndFishermenCounts_ChainAvai…
Olshansk Apr 17, 2023
ee5b3f4
Finished TestSession_GetSession_InvalidFutureSession
Olshansk Apr 18, 2023
50ccff3
Add tests for TestSession_GetSession_ServicersAndFishermanEntropy
Olshansk Apr 18, 2023
830c72a
Merge branch 'main' into issues/569/session_impl
Olshansk Apr 18, 2023
88a36b7
Changed getSessionHeight to hydrateSessionHeight
Olshansk Apr 18, 2023
99b25a3
Updated DefaultNumBlockPerSession=1 and tests passing again
Olshansk Apr 18, 2023
23f74dd
Self review
Olshansk Apr 19, 2023
3fa7ac3
Added some session application validation checks
Olshansk Apr 19, 2023
cc15ba1
Fix one of the broken tests
Olshansk Apr 19, 2023
42bc9f6
Merge branch 'main' into issues/569/session_impl
Olshansk Apr 20, 2023
ede4821
Replied to all comments
Olshansk Apr 20, 2023
4caac93
Code and documentation cleanup
Olshansk Apr 21, 2023
c723b33
Fix broken test
Olshansk Apr 21, 2023
e108e03
Merge with main
Olshansk Apr 21, 2023
32bf680
Checkpoint - replied to some of Bryan's comments
Olshansk Apr 21, 2023
8688645
Consolidated MarshalZerologArray() in logger/utils.go
Olshansk Apr 21, 2023
7df6c88
Replied to remaining review comments
Olshansk Apr 21, 2023
50d0c71
Merge branch 'main' into issues/569/session_impl
Olshansk Apr 24, 2023
424cd54
Update utility/session.go
Olshansk Apr 26, 2023
6c4d3ce
Apply suggestions from code review
Olshansk Apr 26, 2023
6f26138
Update utility/session_test.go
Olshansk Apr 27, 2023
547d4b2
[Makefile] fixes the localnet_db_cli target (#700)
dylanlott Apr 24, 2023
f3a545e
[E2E] adds in-cluster config for E2E tests (#689)
dylanlott Apr 24, 2023
efba9a6
[Docs] Update shared module creation (#693)
bryanchriswhite Apr 25, 2023
673fccb
s/actorsToAdds/actorsToAddrs
Olshansk Apr 26, 2023
565f0b7
Updated logger README
Olshansk Apr 26, 2023
5f072f2
Add clarifying comments
Olshansk Apr 27, 2023
aebd770
Reply to comments
Olshansk Apr 27, 2023
664abf7
Update TECHDEBT ticket
Olshansk Apr 27, 2023
4607f7e
Merge with main
Olshansk Apr 27, 2023
c824948
Apply demorgan's law
Olshansk Apr 27, 2023
cf2f6e0
Markdown nit
Olshansk Apr 27, 2023
d0d3463
Update Makefile
Olshansk Apr 28, 2023
2e92fd2
Update utility/session_test.go
Olshansk Apr 28, 2023
b83efc7
[P2P] chore: remove unnecessary `stdnetwork` package (#703)
bryanchriswhite Apr 28, 2023
c2e2c9a
[P2P] refactor: rename "network" to "router" (#704)
bryanchriswhite Apr 28, 2023
66a8940
MInor NIT comments
Olshansk Apr 28, 2023
e26608a
utility/module_test.go -> utility/main_test.go
Olshansk Apr 28, 2023
e4ac25e
Typo
Olshansk Apr 28, 2023
50b92e5
Fix changelogs
Olshansk Apr 28, 2023
d06787e
Update all the changelogs
Olshansk Apr 28, 2023
42d69bc
Merge with main
Olshansk Apr 28, 2023
e2864b8
Add t.Helper in session_test.go
Olshansk Apr 28, 2023
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ benchmark_p2p_addrbook: ## Benchmark all P2P addr book related tests
# TODO - General Purpose catch-all.
# TECHDEBT - Not a great implementation, but we need to fix it later.
# IMPROVE - A nice to have, but not a priority. It's okay if we never get to this.
# OPTIMIZE - An opportunity for performance improvement if/when it's necessary
# DISCUSS - Probably requires a lengthy offline discussion to understand next steps.
# INCOMPLETE - A change which was out of scope of a specific PR but needed to be documented.
# INVESTIGATE - TBD what was going on, but needed to continue moving and not get distracted.
Expand All @@ -453,7 +454,7 @@ benchmark_p2p_addrbook: ## Benchmark all P2P addr book related tests
# BUG - There is a known existing bug in this code
# DISCUSS_IN_THIS_COMMIT - SHOULD NEVER BE COMMITTED TO MASTER. It is a way for the reviewer of a PR to start / reply to a discussion.
# TODO_IN_THIS_COMMIT - SHOULD NEVER BE COMMITTED TO MASTER. It is a way to start the review process while non-critical changes are still in progress
TODO_KEYWORDS = -e "TODO" -e "TECHDEBT" -e "IMPROVE" -e "DISCUSS" -e "INCOMPLETE" -e "INVESTIGATE" -e "CLEANUP" -e "HACK" -e "REFACTOR" -e "CONSIDERATION" -e "TODO_IN_THIS_COMMIT" -e "DISCUSS_IN_THIS_COMMIT" -e "CONSOLIDATE" -e "DEPRECATE" -e "ADDTEST" -e "RESEARCH" -e "BUG"
TODO_KEYWORDS = -e "TODO" -e "TECHDEBT" -e "IMPROVE" -e "OPTIMIZE" -e "DISCUSS" -e "INCOMPLETE" -e "INVESTIGATE" -e "CLEANUP" -e "HACK" -e "REFACTOR" -e "CONSIDERATION" -e "TODO_IN_THIS_COMMIT" -e "DISCUSS_IN_THIS_COMMIT" -e "CONSOLIDATE" -e "DEPRECATE" -e "ADDTEST" -e "RESEARCH" -e "BUG"
Olshansk marked this conversation as resolved.
Show resolved Hide resolved

# How do I use TODOs?
# 1. <KEYWORD>: <Description of follow up work>;
Expand Down
2 changes: 2 additions & 0 deletions build/config/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -4138,6 +4138,7 @@
"fisherman_unstaking_blocks": 2016,
"fisherman_minimum_pause_blocks": 4,
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
"fisherman_max_pause_blocks": 672,
"fisherman_per_session": 1,
"validator_minimum_stake": "15000000000",
"validator_unstaking_blocks": 2016,
"validator_minimum_pause_blocks": 4,
Expand Down Expand Up @@ -4192,6 +4193,7 @@
"fisherman_unstaking_blocks_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"fisherman_minimum_pause_blocks_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"fisherman_max_paused_blocks_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"fisherman_per_session_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"validator_minimum_stake_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"validator_unstaking_blocks_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"validator_minimum_pause_blocks_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
Expand Down
2 changes: 2 additions & 0 deletions build/config/genesis_localhost.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
"fisherman_unstaking_blocks": 2016,
"fisherman_minimum_pause_blocks": 4,
"fisherman_max_pause_blocks": 672,
"fisherman_per_session": 1,
"validator_minimum_stake": "15000000000",
"validator_unstaking_blocks": 2016,
"validator_minimum_pause_blocks": 4,
Expand Down Expand Up @@ -214,6 +215,7 @@
"fisherman_unstaking_blocks_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"fisherman_minimum_pause_blocks_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"fisherman_max_paused_blocks_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"fisherman_per_session_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"validator_minimum_stake_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"validator_unstaking_blocks_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"validator_minimum_pause_blocks_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
Expand Down
2 changes: 2 additions & 0 deletions build/localnet/manifests/configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4142,6 +4142,7 @@ data:
"fisherman_unstaking_blocks": 2016,
"fisherman_minimum_pause_blocks": 4,
"fisherman_max_pause_blocks": 672,
"fisherman_per_session": 1,
"validator_minimum_stake": "15000000000",
"validator_unstaking_blocks": 2016,
"validator_minimum_pause_blocks": 4,
Expand Down Expand Up @@ -4196,6 +4197,7 @@ data:
"fisherman_unstaking_blocks_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"fisherman_minimum_pause_blocks_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"fisherman_max_paused_blocks_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"fisherman_per_session_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"validator_minimum_stake_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"validator_unstaking_blocks_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"validator_minimum_pause_blocks_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
Expand Down
22 changes: 21 additions & 1 deletion persistence/actor.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
package persistence

import (
"fmt"

"github.com/pokt-network/pocket/persistence/types"
coreTypes "github.com/pokt-network/pocket/shared/core/types"
)

// TODO_IN_THIS_COMMIT: Add tests for this function
func (p *PostgresContext) GetActor(actorType coreTypes.ActorType, address []byte, height int64) (*coreTypes.Actor, error) {
var schema types.ProtocolActorSchema
switch actorType {
case types.ApplicationActor.GetActorType():
schema = types.ApplicationActor
case types.ServicerActor.GetActorType():
schema = types.ServicerActor
case types.FishermanActor.GetActorType():
schema = types.FishermanActor
case types.ValidatorActor.GetActorType():
schema = types.FishermanActor
default:
return nil, fmt.Errorf("invalid actor type: %s", actorType)
}
return p.getActor(schema, address, height)
}

// TODO (#399): 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.
Expand Down Expand Up @@ -113,7 +133,7 @@ func (p *PostgresContext) GetAllFishermen(height int64) (f []*coreTypes.Actor, e
return
}

// IMPROVE: This is a proof of concept. Ideally we should have a single query that returns all actors.
// OPTIMIZE: Ideally we should have a single query that returns all actors.
func (p *PostgresContext) GetAllStakedActors(height int64) (allActors []*coreTypes.Actor, err error) {
type actorGetter func(height int64) ([]*coreTypes.Actor, error)
actorGetters := []actorGetter{p.GetAllValidators, p.GetAllServicers, p.GetAllFishermen, p.GetAllApps}
Expand Down
19 changes: 8 additions & 11 deletions persistence/test/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
)

func TestPersistenceContextParallelReadWrite(t *testing.T) {
prepareAndCleanContext(t)
clearAllState()
t.Cleanup(clearAllState)

// variables for testing
_, _, poolAddr := keygen.GetInstance().Next()
Expand Down Expand Up @@ -57,7 +58,8 @@ func TestPersistenceContextParallelReadWrite(t *testing.T) {
}

func TestPersistenceContextTwoWritesErrors(t *testing.T) {
prepareAndCleanContext(t)
clearAllState()
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
t.Cleanup(clearAllState)

// Opening up first write context succeeds
rwCtx1, err := testPersistenceMod.NewRWContext(0)
Expand All @@ -74,7 +76,8 @@ func TestPersistenceContextTwoWritesErrors(t *testing.T) {
}

func TestPersistenceContextSequentialWrites(t *testing.T) {
prepareAndCleanContext(t)
clearAllState()
t.Cleanup(clearAllState)

// Opening up first write context succeeds
writeContext1, err := testPersistenceMod.NewRWContext(0)
Expand All @@ -93,7 +96,8 @@ func TestPersistenceContextSequentialWrites(t *testing.T) {
}

func TestPersistenceContextMultipleParallelReads(t *testing.T) {
prepareAndCleanContext(t)
clearAllState()
t.Cleanup(clearAllState)

// Opening up first read context succeeds
readContext1, err := testPersistenceMod.NewReadContext(0)
Expand All @@ -111,10 +115,3 @@ func TestPersistenceContextMultipleParallelReads(t *testing.T) {
readContext2.Release()
readContext3.Release()
}

func prepareAndCleanContext(t *testing.T) {
// Cleanup context after the test
t.Cleanup(clearAllState)

clearAllState()
}
8 changes: 5 additions & 3 deletions persistence/test/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ var (
StakeToUpdate = utils.BigIntToString((&big.Int{}).Add(DefaultStakeBig, DefaultDeltaBig))

DefaultStakeStatus = int32(coreTypes.StakeStatus_Staked)
DefaultPauseHeight = int64(-1) // pauseHeight=-1 means not paused
DefaultUnstakingHeight = int64(-1) // pauseHeight=-1 means not unstaking
DefaultPauseHeight = int64(-1) // pauseHeight=-1 implies not paused
DefaultUnstakingHeight = int64(-1) // unstakingHeight=-1 implies not unstaking
Olshansk marked this conversation as resolved.
Show resolved Hide resolved

OlshanskyURL = "https://olshansky.info"
OlshanskyChains = []string{"OLSH"}
Expand All @@ -53,8 +53,10 @@ var (
genesisStateNumServicers = 1
genesisStateNumApplications = 1
genesisStateNumFishermen = 1

// Initialized in TestMain
testPersistenceMod modules.PersistenceModule
)
var testPersistenceMod modules.PersistenceModule // initialized in TestMain

// See https://github.com/ory/dockertest as reference for the template of this code
// Postgres example can be found here: https://github.com/ory/dockertest/blob/v3/examples/PostgreSQL.md
Expand Down
6 changes: 3 additions & 3 deletions persistence/test/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func TestStateHash_DeterministicStateWhenUpdatingAppStake(t *testing.T) {
// logic changes, these hashes will need to be updated based on the test output.
// TODO: Add an explicit updateSnapshots flag to the test to make this more clear.
stateHashes := []string{
dylanlott marked this conversation as resolved.
Show resolved Hide resolved
"3a9a33c4d6b106f656c859296cd5ac16b608980d1d921f6de77051a707f48cb5",
"ec3d62106f1ca61dfe9c1d80a16c4ee3923550db5175389777bd1ecd9d50136e",
"e440914fba03bbb5ff4fbb73f760e4e75c3635263bbf7c15ca649870ee865222",
"93be62191cbc09fea4cf2046bea8e55ccf5e4c6fa7b483a55470d1bca85c3732",
"c2ed842d32b099de26dba1fa6d14f367504daf6b914076004aa3df5f7858e5be",
"a60fef8fe1b3c5b208041f43cb14641167eeb67faee730ae7d0689765bb9d487",
}

stakeAmount := initialStakeAmount
Expand Down
2 changes: 2 additions & 0 deletions persistence/types/gov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestInsertParams(t *testing.T) {
"('fisherman_unstaking_blocks', -1, 'BIGINT', 2016)," +
"('fisherman_minimum_pause_blocks', -1, 'SMALLINT', 4)," +
"('fisherman_max_pause_blocks', -1, 'SMALLINT', 672)," +
"('fisherman_per_session', -1, 'SMALLINT', 1)," +
"('validator_minimum_stake', -1, 'STRING', '15000000000')," +
"('validator_unstaking_blocks', -1, 'BIGINT', 2016)," +
"('validator_minimum_pause_blocks', -1, 'SMALLINT', 4)," +
Expand Down Expand Up @@ -95,6 +96,7 @@ func TestInsertParams(t *testing.T) {
"('fisherman_unstaking_blocks_owner', -1, 'STRING', 'da034209758b78eaea06dd99c07909ab54c99b45')," +
"('fisherman_minimum_pause_blocks_owner', -1, 'STRING', 'da034209758b78eaea06dd99c07909ab54c99b45')," +
"('fisherman_max_paused_blocks_owner', -1, 'STRING', 'da034209758b78eaea06dd99c07909ab54c99b45')," +
"('fisherman_per_session_owner', -1, 'STRING', 'da034209758b78eaea06dd99c07909ab54c99b45')," +
"('validator_minimum_stake_owner', -1, 'STRING', 'da034209758b78eaea06dd99c07909ab54c99b45')," +
"('validator_unstaking_blocks_owner', -1, 'STRING', 'da034209758b78eaea06dd99c07909ab54c99b45')," +
"('validator_minimum_pause_blocks_owner', -1, 'STRING', 'da034209758b78eaea06dd99c07909ab54c99b45')," +
Expand Down
Loading