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

[Persistence] First Implementation of the StateHash (#284) #285

Merged
merged 275 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
275 commits
Select commit Hold shift + click to select a range
1d5486c
Merged with main and resolve conflicts
Olshansk Sep 26, 2022
d9a1cf5
Remove test_persistence_state_hash
Olshansk Sep 26, 2022
798ea1f
Removed explicit MaxBlockBytes variable
Olshansk Sep 26, 2022
7cdc008
Update block.go
Olshansk Sep 26, 2022
e4a63a8
Fix typo in consensus proto
Olshansk Sep 26, 2022
b219468
Updated interface to findHighQC
Olshansk Sep 26, 2022
fa3a051
Reverted changes to the utility module to simplify the PR
Olshansk Sep 26, 2022
752992b
Reverted changes to the utility module interface
Olshansk Sep 26, 2022
844688f
Reverted changes to the persistence module interface
Olshansk Sep 26, 2022
d5a8a1f
Reverted changes to the persistence module files
Olshansk Sep 26, 2022
6245080
Using GetCodec().Marshal() where appropriate
Olshansk Sep 26, 2022
4672e65
Removed additional persistence related code
Olshansk Sep 26, 2022
5c83fd5
Added initialization flow for AppHash
Olshansk Sep 26, 2022
8c6a923
make develop_test passed
Olshansk Sep 26, 2022
62a51ea
Added call to StoreBlock back
Olshansk Sep 27, 2022
8f61b6f
Avoiding anypb in a few places in the consensus code
Olshansk Sep 27, 2022
1200203
Fixed unit tests
Olshansk Sep 27, 2022
0e03976
Add back stateHash implementation
Olshansk Sep 27, 2022
f2777a1
Isolate interface changes only
Olshansk Sep 27, 2022
242565c
Undo more change
Olshansk Sep 27, 2022
55df6cf
Update the interfaces
Olshansk Sep 27, 2022
3dab12f
Merge branch 'main' into issues/249/consensus_techdebt
Olshansk Sep 28, 2022
6370922
Added shouldElectNextLeader
Olshansk Sep 28, 2022
05e0118
Added a comment for getSignableBytes
Olshansk Sep 29, 2022
45da822
Check for nil in CreateProposeMessage
Olshansk Sep 29, 2022
2410521
Revert order of pacemaker defer and telemetry event emitting
Olshansk Sep 29, 2022
a478516
s/IdToValAddrMap/idToValAddrMap
Olshansk Sep 29, 2022
8faaf21
s/ValAddrToIdMap/valAddrToIdMap
Olshansk Sep 29, 2022
25971b7
s/NodeId/nodeId
Olshansk Sep 29, 2022
472473c
s/LeaderId/leaderId
Olshansk Sep 29, 2022
a5edce5
s/MessagePool/messagePool
Olshansk Sep 29, 2022
28f1ba0
Only a few remaining exported fields in ConsensusModule based on refl…
Olshansk Sep 29, 2022
a7207b9
Add TODO in sequence diagram flow
Olshansk Sep 29, 2022
a8e5f3d
Added isNodeLockedOnPastQC
Olshansk Sep 29, 2022
e39f0f8
Logging error when refreshUtilityContext fails
Olshansk Sep 29, 2022
a6990d2
Added shouldLogHotstuffDiscardMessage
Olshansk Sep 29, 2022
8a41361
Added shouldPrepareNewBlock
Olshansk Sep 29, 2022
7493dd3
Added TODO for 256
Olshansk Sep 29, 2022
4ce5792
Merge with main
Olshansk Sep 29, 2022
d30fbf5
Merge with main
Olshansk Oct 4, 2022
3f413bd
Added SetUtilityMod and made utilityContext private
Olshansk Oct 4, 2022
317e677
Updated a comment
Olshansk Oct 4, 2022
a576229
Merge branch 'main' into issues/249/consensus_techdebt
Olshansk Oct 4, 2022
070ba2a
Added a TODO for 283
Olshansk Oct 4, 2022
9902357
Merge with issues/249/consensus_techdebt
Olshansk Oct 5, 2022
6dafdea
Revert all changes back to main
Olshansk Oct 5, 2022
66bd483
Updated base to main for simplicity
Olshansk Oct 5, 2022
655d5d5
Updated shared changelog
Olshansk Oct 5, 2022
2d864be
Merge with issues/249/consensus_techdebt
Olshansk Oct 5, 2022
9ff0ddb
Checkout main again
Olshansk Oct 5, 2022
0ca02aa
Merge with interface changes
Olshansk Oct 5, 2022
aaffb79
Uplied diffs back
Olshansk Oct 5, 2022
342de6a
Temp checkout commit
Olshansk Oct 5, 2022
81837cf
Reapplied all changes from diff
Olshansk Oct 5, 2022
5e8ae53
Merge with interface changes
Olshansk Oct 5, 2022
185919c
another merge
Olshansk Oct 5, 2022
f909103
Tests failing but running
Olshansk Oct 5, 2022
593dac7
Commented out the business logic in storeBlock
Olshansk Oct 5, 2022
4f85c49
Merge with interface changes
Olshansk Oct 5, 2022
52ae666
Tests running and mostly passing
Olshansk Oct 5, 2022
c795b00
Merge with main
Olshansk Oct 6, 2022
35f1311
Made things work again
Olshansk Oct 6, 2022
b984c65
Consensus tests passing again
Olshansk Oct 6, 2022
5530241
Reverted files that shouldn't be part of the interface change
Olshansk Oct 6, 2022
ab42525
Cleaning up the interface
Olshansk Oct 6, 2022
f9a80ff
make develop_test passed
Olshansk Oct 6, 2022
6ead8ce
Replace data | ok with result, err_code
Olshansk Oct 6, 2022
bf27e10
Split and update the sequence diagrams
Olshansk Oct 6, 2022
1e2f758
Merge with interface changes
Olshansk Oct 6, 2022
e69456a
Update TODO keyword
Olshansk Oct 6, 2022
67c1cb5
Merge branch 'issues/251/statehash_interface' into issues/284/stateha…
Olshansk Oct 6, 2022
2760dc4
make develop_test passed
Olshansk Oct 6, 2022
c35f9db
Things kind of linking together
Olshansk Oct 6, 2022
5171d2d
Almost got a deterministic state hash
Olshansk Oct 7, 2022
ffcb91f
Test passed
Olshansk Oct 7, 2022
6317a84
Quick self review
Olshansk Oct 7, 2022
eacde91
Resolve merge conflicts
Olshansk Oct 17, 2022
3002911
Update shared/docs/flows/AppHash.md
Olshansk Oct 17, 2022
7ea5969
Update shared/docs/flows/AppHash.md
Olshansk Oct 17, 2022
ea2b201
Update shared/docs/flows/AppHash.md
Olshansk Oct 17, 2022
02f2a6b
Remove merge conflict file
Olshansk Oct 17, 2022
68ef680
Update changelog
Olshansk Oct 17, 2022
41c01a7
Minor changelog update
Olshansk Oct 17, 2022
558965c
Added activations and deactivations
Olshansk Oct 17, 2022
1f49dfb
Merge with main
Olshansk Oct 17, 2022
0d5df3a
Fix tests
Olshansk Oct 17, 2022
b1a9be1
Merge branch 'main' into issues/251/statehash_interface
Olshansk Oct 20, 2022
4c05a2c
Add call to tx exists
Olshansk Oct 20, 2022
6f97b56
Merge with main
Olshansk Oct 21, 2022
36aee3f
Fix up changelog
Olshansk Oct 21, 2022
8c5f71b
Merge with main - non fully functional
Olshansk Oct 22, 2022
79bba7d
Interim commit
Olshansk Oct 22, 2022
49453fe
Merge branch 'main' into issues/251/statehash_interface
Olshansk Oct 23, 2022
a1e9fe7
Merge branch 'issues/251/statehash_interface' into issues/284/stateha…
Olshansk Oct 23, 2022
ff0ed30
Merge branch 'main' into issues/251/statehash_interface
Olshansk Oct 25, 2022
5ad8135
Merge branch 'issues/251/statehash_interface' into issues/284/stateha…
Olshansk Oct 25, 2022
843d509
Replied to most comments
Olshansk Oct 25, 2022
27890a5
Tests passing
Olshansk Oct 25, 2022
5c10c72
Merge with issues/251
Olshansk Oct 25, 2022
f27bc50
Interim commit while utility tests are failing
Olshansk Oct 25, 2022
244318b
Make test_utility works
Olshansk Oct 26, 2022
dabfb0b
Most tests except for persistence pass
Olshansk Oct 26, 2022
a68e15e
Merge branch 'main' into issues/251/statehash_interface
Olshansk Oct 28, 2022
979b57c
Merge branch 'issues/251/statehash_interface' into issues/284/stateha…
Olshansk Oct 28, 2022
65cd81a
All tests finally passing except for deterministic hash
Olshansk Oct 28, 2022
6e953a1
Deterministic hash working with TxResult
Olshansk Oct 29, 2022
d21d5dc
Finished self review of all the simple code
Olshansk Oct 29, 2022
ade27af
Implemented Account trees
Olshansk Oct 30, 2022
1746268
WIP benchmarking
Olshansk Oct 30, 2022
91c2e68
Interim work on benchmarking
Olshansk Oct 31, 2022
158e2b7
Tests pass
Olshansk Oct 31, 2022
26eed85
Add configs & all tests pass
Olshansk Oct 31, 2022
6fb1ab7
Don't clear context
Olshansk Nov 1, 2022
46e050a
Fucking finally printing what's in my trees
Olshansk Nov 2, 2022
2100975
Made some progress on benchmarking
Olshansk Nov 3, 2022
82f0fd4
Exporting state correctly
Olshansk Nov 4, 2022
0d22faa
Added tx indexer
Olshansk Nov 4, 2022
a6333d9
Updated db_export_trees
Olshansk Nov 4, 2022
dbcb980
Self review upto consensus/block.go
Olshansk Nov 4, 2022
20b71ed
Merge with main
Olshansk Nov 4, 2022
5108240
WIP
Olshansk Nov 6, 2022
4152c14
Unit tests passing
Olshansk Nov 6, 2022
6e0259e
Updated some comments
Olshansk Nov 6, 2022
51e7ebe
Update most of the external interfaces
Olshansk Nov 6, 2022
e60e22a
Update comment
Olshansk Nov 6, 2022
51d1401
Self review of most parts of the code
Olshansk Nov 6, 2022
6bf28d5
Small commit
Olshansk Nov 6, 2022
d7deb63
First attempt at fixing things
Olshansk Nov 6, 2022
6e3f6c5
Merged with localnet fixes
Olshansk Nov 6, 2022
a9de397
Made things kind of work
Olshansk Nov 7, 2022
b72173e
Make code easier to understand
Olshansk Nov 7, 2022
8011f8d
Improve logging for p2p
Olshansk Nov 7, 2022
d0c68a8
Merge branch 'localnet_fixes' into issues/251/statehash_interface
Olshansk Nov 7, 2022
1686001
Removed persistence/docs/PROTOCOL_STATE_HASH.md from this commit
Olshansk Nov 7, 2022
6b7f556
Almost code random but determinstic test going
Olshansk Nov 8, 2022
3d86e23
Update persistence/module.go
Olshansk Nov 8, 2022
878501c
Update persistence/module.go
Olshansk Nov 8, 2022
dd13813
Merge branch 'localnet_fixes' into issues/251/statehash_interface
Olshansk Nov 8, 2022
03c4bc7
Minor release fixes
Olshansk Nov 8, 2022
27f803d
Finally got TestStateHash_RandomButDeterministic to pass
Olshansk Nov 8, 2022
ea4fb4a
Merge with main - tests pass but not done yet
Olshansk Nov 8, 2022
ccf240e
Minor code cleanup - about to remove SetLatestTxResults
Olshansk Nov 8, 2022
432d55b
Added comments
Olshansk Nov 8, 2022
e166e3b
Propogating proper QC in consensus
Olshansk Nov 9, 2022
cab5e63
Added QC back to SetProposalBlock
Olshansk Nov 9, 2022
a588240
StateHash test passing
Olshansk Nov 9, 2022
23df0cb
Removed export tree related work
Olshansk Nov 9, 2022
e3785f3
Moved persistence debug helpers into appropriate file
Olshansk Nov 9, 2022
353d4b0
Halfway through self review
Olshansk Nov 9, 2022
0ebbf52
Reverted unrelated changes
Olshansk Nov 9, 2022
7566bce
Got TestStateHash_ReplayingRandomTransactionsIsDeterministic working
Olshansk Nov 9, 2022
3336af6
Removed unnecessary merkleTreeToProtoSchema
Olshansk Nov 9, 2022
054b93a
make test_persistence passes
Olshansk Nov 9, 2022
60924aa
Merge with main
Olshansk Nov 11, 2022
300c8cb
Merge branch 'issues/251/statehash_interface' into issues/284/stateha…
Olshansk Nov 11, 2022
4dae396
Added TODO for #344R
Olshansk Nov 11, 2022
991fe30
Update persistence/test/benchmark_state_test.go
Olshansk Nov 11, 2022
898f4a7
Update persistence/account.go
Olshansk Nov 11, 2022
05db304
Tend to minor comments
Olshansk Nov 11, 2022
f5ca864
Remove height from callRandomDatabaseModifierFunc
Olshansk Nov 11, 2022
fa7a392
minor improvements to benchmarking code
Olshansk Nov 11, 2022
3f52358
Updated comments in persistence/HandleDebugMessage
Olshansk Nov 11, 2022
bb1069c
Append to nil slice
Olshansk Nov 11, 2022
4f9f87d
Update persistence/debug.go
Olshansk Nov 11, 2022
e442648
Update persistence/state.go
Olshansk Nov 11, 2022
4b86e6f
Remove unused height var when getting all accounts updated
Olshansk Nov 11, 2022
c353335
Removed unnecessary height param
Olshansk Nov 11, 2022
4ec2421
Added txsOrderInBlockHashDescending constant
Olshansk Nov 11, 2022
ca658f0
A few minor edits
Olshansk Nov 11, 2022
85078f3
Updated documentation for ComputeAppHash
Olshansk Nov 11, 2022
10c1acb
Merge branch 'main' into issues/251/statehash_interface
Olshansk Nov 11, 2022
b48e6e1
Merge with issues/251
Olshansk Nov 11, 2022
25439db
Added db_cli_node
Olshansk Nov 11, 2022
4e81e6a
Update utility/block.go
Olshansk Nov 11, 2022
e7c3455
Added unit tests for GetPoolsUpdated and GetAccountsUpdated
Olshansk Nov 11, 2022
8a9b130
Proper implementation of GetPrevHash
Olshansk Nov 11, 2022
93b94b1
Removed GetBlockHash
Olshansk Nov 11, 2022
f3164af
Update comment
Olshansk Nov 11, 2022
d0dc9c1
Minor code cleanup throughout
Olshansk Nov 12, 2022
741949f
Added TODO for #346
Olshansk Nov 12, 2022
e10b147
Consensus fixes
Olshansk Nov 15, 2022
b4e8007
Update shared/docs/PROTOCOL_STATE_HASH.md
Olshansk Nov 15, 2022
e413576
[Utility] Local Proof of Stake CLI - RPC server [part 2/2] - Issue #…
deblasis Nov 11, 2022
14c2ae3
[Utility] Local Proof of Stake CLI - Issue #112 (#169)
deblasis Nov 11, 2022
92897bf
Updated txResults comment
Olshansk Nov 14, 2022
0551bbc
Ticket #211: finding unnecessary public functions in the Persistence …
Jasonyou1995 Nov 14, 2022
131d08f
Remove unnecessary critical sections
Olshansk Nov 15, 2022
bc92358
Minor updates in documentation
Olshansk Nov 15, 2022
53e7dfc
Removed Latest from function names
Olshansk Nov 16, 2022
1afbc78
Updating references documents
Olshansk Nov 16, 2022
7e93272
Replace true | false with just false to simplify diagram
Olshansk Nov 16, 2022
ad042ba
Merge with main
Olshansk Nov 16, 2022
c1f5151
Updated the consensus changelog
Olshansk Nov 16, 2022
00c5378
Updated the persistence changelog
Olshansk Nov 16, 2022
6c41701
Fix numbering in the README
Olshansk Nov 16, 2022
8353e70
Updated shared/modules changelog
Olshansk Nov 16, 2022
4564c32
Updated utility changelog
Olshansk Nov 16, 2022
9ce3f4f
Merged with main
Olshansk Nov 16, 2022
d1f8086
Merge with issues/251
Olshansk Nov 16, 2022
c134b82
Added a weird bug related to errors in the non main thread
Olshansk Nov 16, 2022
9ff13ea
Updated the consensus changelog
Olshansk Nov 16, 2022
5468ccf
self review + test for TestGetValidatorUpdateAtHeigh
Olshansk Nov 16, 2022
069084c
Added unit tests for all the actor retriverals
Olshansk Nov 16, 2022
609c47f
Fixed ShowLatestBlockInStore
Olshansk Nov 16, 2022
dcb99e8
Temp changes
Olshansk Nov 22, 2022
5aa5ef5
Merge with main
Olshansk Nov 22, 2022
aca2b23
Improve diagram for high vs locked QC
Olshansk Nov 22, 2022
8b81f28
Merge with main and tests are passing
Olshansk Nov 22, 2022
f72aae7
Merge branch 'main' into issues/251/statehash_interface
Olshansk Nov 27, 2022
0aedd43
Merge with main and tests are passing
Olshansk Nov 27, 2022
e7f624e
Olshansky self-review; round 3
Olshansk Nov 27, 2022
f23651d
Update persistence/docs/PROTOCOL_STATE_HASH.md
Olshansk Nov 27, 2022
2d4717b
Rename finalQC to commitQC
Olshansk Nov 27, 2022
55a12ba
Merge branch 'issues/251/statehash_interface' into issues/284/stateha…
Olshansk Nov 27, 2022
365abe1
Merge branch 'main' into issues/284/statehash_impl
Olshansk Nov 28, 2022
9bdadb0
Import fix
Olshansk Nov 28, 2022
4225cee
Documentation clarifications per code review
Olshansk Nov 29, 2022
1943737
Try fixing CleanupTest for remote tests
Olshansk Nov 29, 2022
1e382c6
Do not merge this - testing workflow
Olshansk Nov 29, 2022
cc362e4
Update make test_all_with_coverage
Olshansk Nov 29, 2022
f959553
Test all TestUtilityContext
Olshansk Nov 29, 2022
fcd54ff
Fix temporary test_all_with_coverage
Olshansk Nov 29, 2022
e3f32a0
Only test TestUtilityContext_HandleMessage
Olshansk Nov 29, 2022
bc36d30
Added IMPROVE
Olshansk Nov 29, 2022
f7065bc
Update expiration to 20 mins
Olshansk Nov 29, 2022
1953ad4
Don't run fisherman tests
Olshansk Nov 30, 2022
5a22570
Cleanup whitespace while inspecting tests
Olshansk Nov 30, 2022
14ee5b1
Only keep 1 actor type in utility tests
Olshansk Nov 30, 2022
dbd2a90
Add back service node during testing
Olshansk Nov 30, 2022
f56a10a
Adding back the validator
Olshansk Nov 30, 2022
2eea86b
[Quick CI change] Run tests once (#365)
okdas Nov 30, 2022
7a732d3
Add back fisherman tests
Olshansk Nov 30, 2022
7422aa5
Fisherman tests only
Olshansk Nov 30, 2022
7dbc3bc
make test_all_with_json_coverage
Olshansk Nov 30, 2022
c7eba2d
Alternative method to loading genesis state
Olshansk Nov 30, 2022
ec05e05
Remove TestUtilityContext_HandleMessage
Olshansk Nov 30, 2022
efe028e
Merge with main and tests are passing
Olshansk Nov 30, 2022
6742174
Revert makefile use in workflow
Olshansk Nov 30, 2022
bfc30db
Update main.yml
okdas Nov 30, 2022
8c93f56
Merge pull request #367 from pokt-network/build-images-main-only
okdas Nov 30, 2022
a8ff143
Fix comment
Olshansk Nov 30, 2022
a211022
Only 2 protocol actors being tested
Olshansk Nov 30, 2022
dbb8c18
Update main.yml
Olshansk Nov 30, 2022
a2d401d
Test TestUtilityContext remote
Olshansk Nov 30, 2022
30b1156
Trying out this solution: https://stackoverflow.com/a/73561510/768439
Olshansk Nov 30, 2022
d9fbe74
Update main.yml
okdas Nov 30, 2022
97d4fda
Update main.yml
okdas Nov 30, 2022
7da547b
Only create one persistence mod in all utility tests
Olshansk Nov 30, 2022
00986d0
Run :all_the_tests:
Olshansk Nov 30, 2022
5df8756
Removing shitty code
Olshansk Nov 30, 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
33 changes: 25 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,50 @@ jobs:
run: make install_cli_deps
- name: generate protobufs, RPC server, RPC client and mocks
run: make protogen_local && make mockgen && make generate_rpc_openapi
- name: run all tests
run: make test_all_with_json
- name: Create coverage report and run tests
# Not utilizing makefile target here to make use of pipefail bash feature.
run: |
set -euo pipefail
go test -p 1 -json ./... -covermode=count -coverprofile=coverage.out 2>&1 | tee test_results.json
- name: Output test failures
# Makes it easier to find failed tests so no need to scroll through the whole log.
if: ${{ failure() && env.TARGET_GOLANG_VERSION == matrix.go }}
run: cat test_results.json | jq 'select(.Action == "fail")'
- name: Upload test results
if: ${{ always() && env.TARGET_GOLANG_VERSION == matrix.go }}
uses: actions/upload-artifact@v3
with:
name: test-results
path: |
test_results.json
- name: Annotate tests on GitHub
# Only annotate if the test failed on target version to avoid duplicated annotations on GitHub.
if: ${{ always() && env.TARGET_GOLANG_VERSION == matrix.go }}
uses: guyarb/[email protected]
with:
test-results: test_results.json
- name: Prepare code coverage report
if: ${{ always() && env.TARGET_GOLANG_VERSION == matrix.go }}
run: go tool cover -func=coverage.out -o=coverage.out
- name: Upload coverage to Codecov
if: ${{ always() && env.TARGET_GOLANG_VERSION == matrix.go }}
uses: codecov/codecov-action@v3
- name: Run golangci-lint
# Only run if the test failed on target version to avoid duplicated annotations on GitHub.
if: ${{ always() && env.TARGET_GOLANG_VERSION == matrix.go }}
uses: golangci/golangci-lint-action@v3
with:
# only-new-issues: true
args: --issues-exit-code=0 # TODO: Remove this once we fix all the issues.
- name: create coverage report
if: ${{ always() && env.TARGET_GOLANG_VERSION == matrix.go }}
run: make test_all_with_coverage
- name: Upload coverage to Codecov
if: ${{ always() && env.TARGET_GOLANG_VERSION == matrix.go }}
uses: codecov/codecov-action@v3

# TODO(@okdas): reuse artifacts built by the previous job instead
# of going through the build process in container build job again
# - figure out how to handle musl/alpine case if we want to support it
build-images:
runs-on: ubuntu-latest
needs: test-multiple-go-versions
# Until we have developer environments, we don't need the images built on other that main branches.
if: github.ref == 'refs/heads/main'
strategy:
matrix:
# Build dev & prod images
Expand Down
58 changes: 40 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ CWD ?= CURRENT_WORKING_DIRECTIONRY_NOT_SUPPLIED
# seconds, and fail if any additional messages are received.
EXTRA_MSG_FAIL ?= false

# IMPROVE: Add `-shuffle=on` to the `go test` command to randomize the order in which tests are run.

# An easy way to turn off verbose test output for some of the test targets. For example
# `$ make test_persistence` by default enables verbose testing
# `VERBOSE_TEST="" make test_persistence` is an easy way to run the same tests without verbose output
Expand Down Expand Up @@ -162,6 +164,14 @@ db_cli:
echo "View schema by running 'SELECT schema_name FROM information_schema.schemata;'"
docker exec -it pocket-db bash -c "psql -U postgres"

psqlSchema ?= node1

.PHONY: db_cli_node
## Open a CLI to the local containerized postgres instance for a specific node
db_cli_node:
echo "View all avialable tables by running \dt"
docker exec -it pocket-db bash -c "PGOPTIONS=--search_path=${psqlSchema} psql -U postgres"

.PHONY: db_drop
## Drop all schemas used for LocalNet development matching `node%`
db_drop: docker_check
Expand All @@ -177,6 +187,11 @@ db_bench_init: docker_check
db_bench: docker_check
docker exec -it pocket-db bash -c "pgbench -U postgres -d postgres"

.PHONY: db_show_schemas
## Show all the node schemas in the local SQL DB
db_show_schemas: docker_check
docker exec -it pocket-db bash -c "psql -U postgres -d postgres -a -f /tmp/scripts/show_all_schemas.sql"

.PHONY: db_admin
## Helper to access to postgres admin GUI interface
db_admin:
Expand Down Expand Up @@ -252,7 +267,7 @@ protogen_local: go_protoc-go-inject-tag
protoc --go_opt=paths=source_relative -I=./p2p/types/proto --go_out=./p2p/types ./p2p/types/proto/*.proto --experimental_allow_proto3_optional
protoc --go_opt=paths=source_relative -I=./telemetry/proto --go_out=./telemetry ./telemetry/proto/*.proto --experimental_allow_proto3_optional
protoc --go_opt=paths=source_relative -I=./logger/proto --go_out=./logger ./logger/proto/*.proto --experimental_allow_proto3_optional
protoc --go_opt=paths=source_relative -I=./rpc/types/proto --go_out=./rpc/types ./rpc/types/proto/*.proto --experimental_allow_proto3_optional
protoc --go_opt=paths=source_relative -I=./rpc/types/proto --go_out=./rpc/types ./rpc/types/proto/*.proto --experimental_allow_proto3_optional
echo "View generated proto files by running: make protogen_show"

.PHONY: protogen_docker_m1
Expand Down Expand Up @@ -290,16 +305,10 @@ generate_cli_commands_docs:
test_all: # generate_mocks
go test -p 1 -count=1 ./...

.PHONY: test_all_with_json
## Run all go unit tests, output results in json file
test_all_with_json: generate_rpc_openapi # generate_mocks
go test -p 1 -json ./... > test_results.json

.PHONY: test_all_with_coverage
## Run all go unit tests, output results & coverage into files
test_all_with_coverage: generate_rpc_openapi # generate_mocks
go test -p 1 -v ./... -covermode=count -coverprofile=coverage.out
go tool cover -func=coverage.out -o=coverage.out
.PHONY: test_all_with_json_coverage
## Run all go unit tests, output results & coverage into json & coverage files
test_all_with_json_coverage: generate_rpc_openapi # generate_mocks
go test -p 1 -json ./... -covermode=count -coverprofile=coverage.out | tee test_results.json | jq

.PHONY: test_race
## Identify all unit tests that may result in race conditions
Expand All @@ -317,9 +326,9 @@ test_shared: # generate_mocks
go test ${VERBOSE_TEST} -p 1 ./shared/...

.PHONY: test_consensus
## Run all go unit tests in the Consensus module
## Run all go unit tests in the consensus module
test_consensus: # mockgen
go test ${VERBOSE_TEST} ./consensus/...
go test ${VERBOSE_TEST} -count=1 ./consensus/...

.PHONY: test_consensus_concurrent_tests
## Run unit tests in the consensus module that could be prone to race conditions (#192)
Expand Down Expand Up @@ -354,6 +363,11 @@ test_sortition:
test_persistence:
go test ${VERBOSE_TEST} -p 1 -count=1 ./persistence/...

.PHONY: test_persistence_state_hash
## Run all go unit tests in the Persistence module related to the state hash
test_persistence_state_hash:
go test ${VERBOSE_TEST} -run TestStateHash -count=1 ./persistence/...

.PHONY: test_p2p
## Run all p2p
test_p2p:
Expand All @@ -362,22 +376,29 @@ test_p2p:
.PHONY: test_p2p_raintree
## Run all p2p raintree related tests
test_p2p_raintree:
go test -run RainTreeNetwork -v -count=1 ./p2p/...
go test ${VERBOSE_TEST} -run RainTreeNetwork -count=1 ./p2p/...

.PHONY: test_p2p_raintree_addrbook
## Run all p2p raintree addr book related tests
test_p2p_raintree_addrbook:
go test -run RainTreeAddrBook -v -count=1 ./p2p/...
go test ${VERBOSE_TEST} -run RainTreeAddrBook -count=1 ./p2p/...

# TIP: For benchmarks, consider appending `-run=^#` to avoid running unit tests in the same package

.PHONY: benchmark_persistence_state_hash
## Benchmark the state hash computation
benchmark_persistence_state_hash:
go test ${VERBOSE_TEST} -cpu 1,2 -benchtime=1s -benchmem -bench=. -run BenchmarkStateHash -count=1 ./persistence/...

.PHONY: benchmark_sortition
## Benchmark the Sortition library
benchmark_sortition:
go test ${VERBOSE_TEST} ./consensus/leader_election/sortition -bench=.
go test ${VERBOSE_TEST} -bench=. -run ^# ./consensus/leader_election/sortition

.PHONY: benchmark_p2p_addrbook
## Benchmark all P2P addr book related tests
benchmark_p2p_addrbook:
go test -bench=. -run BenchmarkAddrBook -v -count=1 ./p2p/...
go test ${VERBOSE_TEST} -bench=. -run BenchmarkAddrBook -count=1 ./p2p/...

### Inspired by @goldinguy_ in this post: https://goldin.io/blog/stop-using-todo ###
# TODO - General Purpose catch-all.
Expand All @@ -391,10 +412,11 @@ benchmark_p2p_addrbook:
# REFACTOR - Similar to TECHDEBT, but will require a substantial rewrite and change across the codebase
# CONSIDERATION - A comment that involves extra work but was thoughts / considered as part of some implementation
# CONSOLIDATE - We likely have similar implementations/types of the same thing, and we should consolidate them.
# ADDTEST - Add more tests for a specific code section
# DEPRECATE - Code that should be removed in the future
# 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"
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"

# How do I use TODOs?
# 1. <KEYWORD>: <Description of follow up work>;
Expand Down
7 changes: 4 additions & 3 deletions app/client/cli/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"google.golang.org/protobuf/types/known/anypb"
)

// TECHDEBT: Lowercase variables / constants that do not need to be exported.
const (
PromptResetToGenesis string = "ResetToGenesis"
PromptPrintNodeState string = "PrintNodeState"
Expand Down Expand Up @@ -207,10 +208,10 @@ func initDebug(remoteCLIURL string) {
logger.Global.Fatal().Err(err).Msg("Failed to create logger module")
}
loggerMod := loggerM.(modules.LoggerModule)
rpcM, err := rpc.Create(runtimeMgr)

rpcM, err := rpc.Create(runtimeMgr)
if err != nil {
logger.Global.Fatal().Err(err).Msg("Failed to create rpc module")
logger.Global.Fatal().Err(err).Msg("Failed to create rpc module")
}
rpcMod := rpcM.(modules.RPCModule)

Expand Down
4 changes: 3 additions & 1 deletion build/config/config1.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"persistence": {
"postgres_url": "postgres://postgres:postgres@pocket-db:5432/postgres",
"node_schema": "node1",
"block_store_path": "/var/blockstore"
"block_store_path": "/var/blockstore",
"tx_indexer_path": "",
"trees_store_dir": "/var/trees"
},
"p2p": {
"consensus_port": 8080,
Expand Down
4 changes: 3 additions & 1 deletion build/config/config2.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"persistence": {
"postgres_url": "postgres://postgres:postgres@pocket-db:5432/postgres",
"node_schema": "node2",
"block_store_path": "/var/blockstore"
"block_store_path": "/var/blockstore",
"tx_indexer_path": "",
"trees_store_dir": "/var/trees"
},
"p2p": {
"consensus_port": 8080,
Expand Down
4 changes: 3 additions & 1 deletion build/config/config3.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"persistence": {
"postgres_url": "postgres://postgres:postgres@pocket-db:5432/postgres",
"node_schema": "node3",
"block_store_path": "/var/blockstore"
"block_store_path": "/var/blockstore",
"tx_indexer_path": "",
"trees_store_dir": "/var/trees"
},
"p2p": {
"consensus_port": 8080,
Expand Down
4 changes: 3 additions & 1 deletion build/config/config4.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"persistence": {
"postgres_url": "postgres://postgres:postgres@pocket-db:5432/postgres",
"node_schema": "node4",
"block_store_path": "/var/blockstore"
"block_store_path": "/var/blockstore",
"tx_indexer_path": "",
"trees_store_dir": "/var/trees"
},
"p2p": {
"consensus_port": 8080,
Expand Down
1 change: 1 addition & 0 deletions build/sql/show_all_schemas.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT schema_name FROM information_schema.schemata;
6 changes: 6 additions & 0 deletions consensus/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ func (m *consensusModule) refreshUtilityContext() error {
m.utilityContext = nil
}

// Only one write context can exist at a time, and the utility context needs to instantiate
// a new one to modify the state.
if err := m.GetBus().GetPersistenceModule().ReleaseWriteContext(); err != nil {
log.Printf("[WARN] Error releasing persistence write context: %v\n", err)
}

utilityContext, err := m.GetBus().GetUtilityModule().NewContext(int64(m.Height))
if err != nil {
return err
Expand Down
10 changes: 7 additions & 3 deletions consensus/consensus_tests/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func CreateTestConsensusPocketNode(
utilityMock := baseUtilityMock(t, testChannel)
telemetryMock := baseTelemetryMock(t, testChannel)
loggerMock := baseLoggerMock(t, testChannel)
rpcMock := baseRpcMock(t, testChannel)
rpcMock := baseRpcMock(t, testChannel)
Olshansk marked this conversation as resolved.
Show resolved Hide resolved

bus, err := shared.CreateBus(runtimeMgr, persistenceMock, p2pMock, utilityMock, consensusMod.(modules.ConsensusModule), telemetryMock, loggerMock, rpcMock)

require.NoError(t, err)
Expand All @@ -157,6 +157,7 @@ func CreateTestConsensusPocketNode(
return pocketNode
}

// CLEANUP: Reduce package scope visibility in the consensus test module
func StartAllTestPocketNodes(t *testing.T, pocketNodes IdToNodeMapping) {
for _, pocketNode := range pocketNodes {
go pocketNode.Start()
Expand Down Expand Up @@ -307,6 +308,7 @@ func basePersistenceMock(t *testing.T, _ modules.EventsChannel) *modulesMock.Moc
persistenceMock.EXPECT().Start().Return(nil).AnyTimes()
persistenceMock.EXPECT().SetBus(gomock.Any()).Return().AnyTimes()
persistenceMock.EXPECT().NewReadContext(int64(-1)).Return(persistenceContextMock, nil).AnyTimes()
persistenceMock.EXPECT().ReleaseWriteContext().Return(nil).AnyTimes()

// The persistence context should usually be accessed via the utility module within the context
// of the consensus module. This one is only used when loading the initial consensus module
Expand Down Expand Up @@ -363,7 +365,7 @@ func baseUtilityContextMock(t *testing.T) *modulesMock.MockUtilityContext {
utilityContextMock := modulesMock.NewMockUtilityContext(ctrl)
persistenceContextMock := modulesMock.NewMockPersistenceRWContext(ctrl)
persistenceContextMock.EXPECT().SetProposalBlock(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
persistenceContextMock.EXPECT().GetPrevAppHash().Return("", nil).AnyTimes()
persistenceContextMock.EXPECT().GetBlockHash(gomock.Any()).Return([]byte(""), nil).AnyTimes()

utilityContextMock.EXPECT().
CreateAndApplyProposalBlock(gomock.Any(), maxTxBytes).
Expand All @@ -377,6 +379,8 @@ func baseUtilityContextMock(t *testing.T) *modulesMock.MockUtilityContext {
utilityContextMock.EXPECT().Release().Return(nil).AnyTimes()
utilityContextMock.EXPECT().GetPersistenceContext().Return(persistenceContextMock).AnyTimes()

persistenceContextMock.EXPECT().Release().Return(nil).AnyTimes()

return utilityContextMock
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/debugging.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (m *consensusModule) resetToGenesis(_ *messaging.DebugMessage) {
m.clearLeader()
m.clearMessagesPool()
m.GetBus().GetPersistenceModule().HandleDebugMessage(&messaging.DebugMessage{
Action: messaging.DebugMessageAction_DEBUG_CLEAR_STATE,
Action: messaging.DebugMessageAction_DEBUG_PERSISTENCE_RESET_TO_GENESIS,
Message: nil,
})
m.GetBus().GetPersistenceModule().Start() // reload genesis state
Expand Down
9 changes: 9 additions & 0 deletions consensus/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.0.10] - 2022-11-30

- Propagate `highPrepareQC` if available to the block being created
- Remove `blockProtoBytes` from propagation in `SetProposalBlock`
- Guarantee that write context is released when refreshing the utility context
- Use `GetBlockHash(height)` instead of `GetPrevAppHash` to be more explicit
- Use the real `quorumCert` when preparing a new block

## [0.0.0.9] - 2022-11-30

- Added state sync interfaces and diagrams

## [0.0.0.8] - 2022-11-15
Expand Down
6 changes: 2 additions & 4 deletions consensus/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import (
"encoding/base64"
"log"

"github.com/pokt-network/pocket/shared/codec"

"google.golang.org/protobuf/proto"

typesCons "github.com/pokt-network/pocket/consensus/types"
"github.com/pokt-network/pocket/shared/codec"
cryptoPocket "github.com/pokt-network/pocket/shared/crypto"
"google.golang.org/protobuf/proto"
)

// These constants and variables are wrappers around the autogenerated protobuf types and were
Expand Down
Loading