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

[Shared] Refactor all shared modules (Issue #163) #178

Merged
merged 55 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
fb3a6fc
[Persistence] First iteration of a PostgreSQL based Persistence Schem…
Jul 6, 2022
199b416
Merge with main and fix tests
Olshansk Jul 20, 2022
58bdbb9
only committing due to merge, wip
Jul 20, 2022
444f6b8
Merge remote-tracking branch 'origin/origin/104-persistence-v1-persis…
Jul 20, 2022
61c9178
issue-#111
Jul 22, 2022
e66cf87
merged into main
Jul 24, 2022
38684af
see pull request changes on #111
Jul 27, 2022
d7b3be6
using transaction architecture for persistence module, begin to swith…
Jul 28, 2022
8b3fcdb
deprecate pre-persistence
Aug 3, 2022
b05504d
merged with main
Aug 4, 2022
628b993
requested changes 1 for pull/140
Aug 9, 2022
6853095
merge with main
Aug 9, 2022
d2edd36
requested changes 2 for pull/140
Aug 9, 2022
8dbb9e0
Merge remote-tracking branch 'origin/main' into issue-#128
Aug 10, 2022
0983797
issue-#154
Aug 14, 2022
329f79b
Merge remote-tracking branch 'origin/main' into issue-#154
Aug 14, 2022
2d84eef
Merge remote-tracking branch 'origin/main' into issue-#128
Aug 14, 2022
7fc6dab
Merge branch 'issue-#128' into issue-#154
Aug 14, 2022
24db375
Interim commit for merge with main
Olshansk Aug 18, 2022
a40ca1e
Something compiled for the first time
Olshansk Aug 18, 2022
7372987
Account tests pass
Olshansk Aug 18, 2022
7f104c3
make test_persistence passes
Olshansk Aug 18, 2022
c1a2135
fixed consensus tests with config
Aug 18, 2022
89685c0
deleted shared/config
Aug 18, 2022
342a744
Checkpoint commit - test_utility_module passes
Olshansk Aug 18, 2022
dd9d001
make test_all passes
Olshansk Aug 18, 2022
70099e6
issue-#163 see changelogs
Aug 25, 2022
ece786e
merge with main
Aug 26, 2022
da62675
pr changes from olshansk; round 1
Aug 29, 2022
57a594d
ran config/genesis generator to replace the capitalized json
Aug 29, 2022
6ca0b34
arash review - round 1
Sep 2, 2022
60c2c74
Update a couple TODOs
Olshansk Sep 3, 2022
2f16888
Removed GOPATH from protobuf make target
Olshansk Sep 8, 2022
778e614
olshansk review round 2
Sep 9, 2022
ff0a7c8
removed comments
Sep 9, 2022
a40e1f0
s/TODO(TECHDEBT)/TECHDEBT
Olshansk Sep 11, 2022
ec59846
Updated a few TODOs
Olshansk Sep 11, 2022
7d9a560
Extract filePath creation in config/main.go
Olshansk Sep 11, 2022
b33d2a8
Added a TODO for createTestingGenesisAndConfigFiles
Olshansk Sep 11, 2022
e6ba31a
Replace No op with No-op
Olshansk Sep 11, 2022
8af39ef
Updated TODO in transaction_test.go
Olshansk Sep 11, 2022
c93f9d9
olshansk review round 3
Sep 12, 2022
27c5999
#147->#149
Sep 12, 2022
b811668
lowercase a couple constants
Olshansk Sep 12, 2022
4829c42
lowercased a few constants in build/config/main.go
Olshansk Sep 12, 2022
af7ba51
s/GenesisStatePostix/GenesisStatePostfix
Olshansk Sep 12, 2022
d05ccb5
Remove unnecessary const type
Olshansk Sep 12, 2022
7aedeb3
Centralize _genesis_state filename helper
Olshansk Sep 12, 2022
67215be
ClientI/IClient and ConfigI/IConfig
Olshansk Sep 12, 2022
ae1fae5
A few TODO updates and automated import modifications
Olshansk Sep 12, 2022
3637fcb
Remove commented code
Olshansk Sep 12, 2022
1eca9a5
Removed outdated code in persistence/proto/genesis
Olshansk Sep 12, 2022
370dd81
Updated instructions on how todo stuff
Olshansk Sep 12, 2022
d59b169
Shortened the code in utility/actor.go
Olshansk Sep 12, 2022
9350bef
Remove unnecessary loop
Olshansk Sep 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
21 changes: 12 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -218,22 +218,25 @@ protogen_clean:
.PHONY: protogen_local
## Generate go structures for all of the protobufs
protogen_local: go_protoc-go-inject-tag
$(eval proto_dir = "./shared/types/proto/")
protoc --go_opt=paths=source_relative -I=${proto_dir} -I=./shared/types/proto --go_out=./shared/types ./shared/types/proto/*.proto --experimental_allow_proto3_optional
protoc --go_opt=paths=source_relative -I=${proto_dir} -I=./utility/proto --go_out=./utility/types ./utility/proto/*.proto --experimental_allow_proto3_optional
protoc --go_opt=paths=source_relative -I=${proto_dir} -I=./shared/types/genesis/proto --go_out=./shared/types/genesis ./shared/types/genesis/proto/*.proto --experimental_allow_proto3_optional
protoc-go-inject-tag -input="./shared/types/genesis/*.pb.go"
protoc --go_opt=paths=source_relative -I=${proto_dir} -I=./consensus/types/proto --go_out=./consensus/types ./consensus/types/proto/*.proto --experimental_allow_proto3_optional
protoc --go_opt=paths=source_relative -I=${proto_dir} -I=./p2p/raintree/types/proto --go_out=./p2p/types ./p2p/raintree/types/proto/*.proto --experimental_allow_proto3_optional
$(eval proto_dir = ".")
protoc --go_opt=paths=source_relative -I=./shared/debug/proto --go_out=./shared/debug ./shared/debug/proto/*.proto --experimental_allow_proto3_optional
protoc --go_opt=paths=source_relative -I=./persistence/proto --go_out=./persistence/types ./persistence/proto/*.proto --experimental_allow_proto3_optional
protoc --go_opt=paths=source_relative -I=./persistence/proto --go_out=./persistence/types ./persistence/proto/genesis/*.proto --experimental_allow_proto3_optional
protoc-go-inject-tag -input="./persistence/types/*.pb.go"
protoc --go_opt=paths=source_relative -I=./utility/types/proto --go_out=./utility/types ./utility/types/proto/*.proto --experimental_allow_proto3_optional
protoc --go_opt=paths=source_relative -I=./consensus/types/proto --go_out=./consensus/types ./consensus/types/proto/*.proto --experimental_allow_proto3_optional
protoc --go_opt=paths=source_relative -I=./p2p/raintree/types/proto --go_out=./p2p/types ./p2p/raintree/types/proto/*.proto --experimental_allow_proto3_optional
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/types ./telemetry/proto/*.proto --experimental_allow_proto3_optional
echo "View generated proto files by running: make protogen_show"

.PHONY: protogen_docker_m1
## TODO(derrandz): Test, validate & update.
## TODO(TECHDEBT): Test, validate & update.
protogen_docker_m1: docker_check
docker build -t pocket/proto-generator -f ./build/Dockerfile.m1.proto . && docker run --platform=linux/amd64 -it -v $(CWD)/shared:/usr/src/app/shared pocket/proto-generator

.PHONY: protogen_docker
## TODO(derrandz): Test, validate & update.
## TODO(TECHDEBT): Test, validate & update.
protogen_docker: docker_check
docker build -t pocket/proto-generator -f ./build/Dockerfile.proto . && docker run -it -v $(CWD)/:/usr/src/app/ pocket/proto-generator

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ All the links you'll need are listed below. If you'd like to contribute to the P
- [Contribution Guide](docs/contributing/README.md)
- [Release Guide](docs/build/README.md)
- [Dependencies Guide](docs/deps/README.md)
- [Telemetry Guide](shared/telemetry/README.md)
- [Telemetry Guide](telemetry/README.md)

### Architectures

- [Shared Architecture](shared/README.md)
- [Utility Architecture](utility/doc/README.md)
- _Coming Soon: Consensus Architecture_
- _Coming Soon: Consensus Architecture_ // TODO(olshansky): needs a README file with proper code structure
- [Persistence Architecture](persistence/README.md)
- [P2P Architecture](p2p/README.md)

Expand Down
61 changes: 24 additions & 37 deletions app/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
// TODO(team): discuss & design the long-term solution to this client.

import (
"github.com/pokt-network/pocket/shared/debug"
"github.com/pokt-network/pocket/telemetry"
andrewnguyen22 marked this conversation as resolved.
Show resolved Hide resolved
"log"
"os"

Expand All @@ -12,9 +14,6 @@ import (
"github.com/pokt-network/pocket/shared"
pocketCrypto "github.com/pokt-network/pocket/shared/crypto"
"github.com/pokt-network/pocket/shared/modules"
"github.com/pokt-network/pocket/shared/telemetry"
"github.com/pokt-network/pocket/shared/types"
"github.com/pokt-network/pocket/shared/types/genesis/test_artifacts"
"google.golang.org/protobuf/types/known/anypb"
)

Expand All @@ -25,8 +24,8 @@ const (
PromptTogglePacemakerMode string = "TogglePacemakerMode"
PromptShowLatestBlockInStore string = "ShowLatestBlockInStore"

configPath string = "build/config/config1.json"
genesisPath string = "build/config/genesis.json"
DefaultConfigPath = "build/config/config1.json"
DefaultGenesisPath = "build/config/genesis.json"
)

var items = []string{
Expand All @@ -44,39 +43,27 @@ var p2pMod modules.P2PModule
var consensusMod modules.ConsensusModule

func main() {
// HACK: rain tree will detect if trying to send to addr=self and not send it
var err error
clientPrivateKey, err := pocketCrypto.GeneratePrivateKey()
if err != nil {
log.Fatalf(err.Error())
}

config, genesis := test_artifacts.ReadConfigAndGenesisFiles(configPath, genesisPath)
config.Base.PrivateKey = clientPrivateKey.String()

consensusMod, err = consensus.Create(config, genesis)
consensusMod, err = consensus.Create(DefaultConfigPath, DefaultGenesisPath, true) // TODO (TechDebt) extra param required for injecting private key hack for debug client
if err != nil {
log.Fatalf("[ERROR] Failed to create consensus module: %v", err.Error())
}

p2pMod, err = p2p.Create(config, genesis)
p2pMod, err = p2p.Create(DefaultConfigPath, DefaultGenesisPath, true) // TODO (TechDebt) extra param required for injecting private key hack for debug client
if err != nil {
log.Fatalf("[ERROR] Failed to create p2p module: %v", err.Error())
}

// This telemetry module instance is a NOOP because the 'enable_telemetry' flag in the `cfg` above is set to false.
// Since this client mimics partial - networking only - functionality of a full node, some of the telemetry-related
// code paths are executed. To avoid those messages interfering with the telemetry data collected, a non-nil telemetry
// module that NOOPs (per the configs above) is injected.
telemetryMod, err := telemetry.Create(config, genesis)
telemetryMod, err := telemetry.Create(DefaultConfigPath, DefaultGenesisPath)
if err != nil {
log.Fatalf("[ERROR] Failed to create NOOP telemetry module: " + err.Error())
}

_ = shared.CreateBusWithOptionalModules(nil, p2pMod, nil, consensusMod, telemetryMod, config, genesis)
_ = shared.CreateBusWithOptionalModules(nil, p2pMod, nil, consensusMod, telemetryMod)

p2pMod.Start()
// We are explicitly not calling `Start` on the consensus module

for {
selection, err := promptGetInput()
Expand Down Expand Up @@ -110,32 +97,32 @@ func promptGetInput() (string, error) {
func handleSelect(selection string) {
switch selection {
case PromptResetToGenesis:
m := &types.DebugMessage{
Action: types.DebugMessageAction_DEBUG_CONSENSUS_RESET_TO_GENESIS,
m := &debug.DebugMessage{
Action: debug.DebugMessageAction_DEBUG_CONSENSUS_RESET_TO_GENESIS,
Message: nil,
}
broadcastDebugMessage(m)
case PromptPrintNodeState:
m := &types.DebugMessage{
Action: types.DebugMessageAction_DEBUG_CONSENSUS_PRINT_NODE_STATE,
m := &debug.DebugMessage{
Action: debug.DebugMessageAction_DEBUG_CONSENSUS_PRINT_NODE_STATE,
Message: nil,
}
broadcastDebugMessage(m)
case PromptTriggerNextView:
m := &types.DebugMessage{
Action: types.DebugMessageAction_DEBUG_CONSENSUS_TRIGGER_NEXT_VIEW,
m := &debug.DebugMessage{
Action: debug.DebugMessageAction_DEBUG_CONSENSUS_TRIGGER_NEXT_VIEW,
Message: nil,
}
broadcastDebugMessage(m)
case PromptTogglePacemakerMode:
m := &types.DebugMessage{
Action: types.DebugMessageAction_DEBUG_CONSENSUS_TOGGLE_PACE_MAKER_MODE,
m := &debug.DebugMessage{
Action: debug.DebugMessageAction_DEBUG_CONSENSUS_TOGGLE_PACE_MAKER_MODE,
Message: nil,
}
broadcastDebugMessage(m)
case PromptShowLatestBlockInStore:
m := &types.DebugMessage{
Action: types.DebugMessageAction_DEBUG_SHOW_LATEST_BLOCK_IN_STORE,
m := &debug.DebugMessage{
Action: debug.DebugMessageAction_DEBUG_SHOW_LATEST_BLOCK_IN_STORE,
Message: nil,
}
sendDebugMessage(m)
Expand All @@ -145,7 +132,7 @@ func handleSelect(selection string) {
}

// Broadcast to the entire validator set
func broadcastDebugMessage(debugMsg *types.DebugMessage) {
func broadcastDebugMessage(debugMsg *debug.DebugMessage) {
anyProto, err := anypb.New(debugMsg)
if err != nil {
log.Fatalf("[ERROR] Failed to create Any proto: %v", err)
Expand All @@ -157,29 +144,29 @@ func broadcastDebugMessage(debugMsg *types.DebugMessage) {
// p2pMod.Broadcast(anyProto, types.PocketTopic_DEBUG_TOPIC)

for _, val := range consensusMod.ValidatorMap() {
addr, err := pocketCrypto.NewAddress(val.Address)
addr, err := pocketCrypto.NewAddress(val.GetAddress())
if err != nil {
log.Fatalf("[ERROR] Failed to convert validator address into pocketCrypto.Address: %v", err)
}
p2pMod.Send(addr, anyProto, types.PocketTopic_DEBUG_TOPIC)
p2pMod.Send(addr, anyProto, debug.PocketTopic_DEBUG_TOPIC)
}
}

// Send to just a single (i.e. first) validator in the set
func sendDebugMessage(debugMsg *types.DebugMessage) {
func sendDebugMessage(debugMsg *debug.DebugMessage) {
anyProto, err := anypb.New(debugMsg)
if err != nil {
log.Fatalf("[ERROR] Failed to create Any proto: %v", err)
}

var validatorAddress []byte
for _, val := range consensusMod.ValidatorMap() {
validatorAddress, err = pocketCrypto.NewAddress(val.Address)
validatorAddress, err = pocketCrypto.NewAddress(val.GetAddress())
if err != nil {
log.Fatalf("[ERROR] Failed to convert validator address into pocketCrypto.Address: %v", err)
}
break
}

p2pMod.Send(validatorAddress, anyProto, types.PocketTopic_DEBUG_TOPIC)
p2pMod.Send(validatorAddress, anyProto, debug.PocketTopic_DEBUG_TOPIC)
}
6 changes: 1 addition & 5 deletions app/pocket/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"log"

"github.com/pokt-network/pocket/shared"
"github.com/pokt-network/pocket/shared/types/genesis/test_artifacts"
)

// See `docs/build/README.md` for details on how this is injected via mage.
Expand All @@ -22,10 +21,7 @@ func main() {
log.Printf("Version flag currently unused %s\n", version)
return
}

cfg, genesis := test_artifacts.ReadConfigAndGenesisFiles(*configFilename, *genesisFilename)

pocketNode, err := shared.Create(cfg, genesis)
pocketNode, err := shared.Create(*configFilename, *genesisFilename)
if err != nil {
log.Fatalf("Failed to create pocket node: %s", err)
}
Expand Down
10 changes: 6 additions & 4 deletions build/config/config1.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"base": {
"root_directory": "/go/src/github.com/pocket-network",
"private_key": "ccec19df8fe866280e41da68d52d0ecdb07b01e85eeef45f400fd3a89b71c26a79254a4bc46bf1182826145b0b01b48bab4240cd30e23ba90e4e5e6b56961c6d"
"private_key": "f4f6d5a0001170bc61e3638dc68b5d1f54530e0923a0a1c70e0d39423a53104e030206dd1a85db222a5c641cba61921dfbb1fa6252b728bdcdedfc720f97e10c"
},
"consensus": {
"max_mempool_bytes": 500000000,
"pacemaker_config": {
"timeout_msec": 5000,
"manual": true,
"debug_time_between_steps_msec": 1000
}
},
"private_key": "f4f6d5a0001170bc61e3638dc68b5d1f54530e0923a0a1c70e0d39423a53104e030206dd1a85db222a5c641cba61921dfbb1fa6252b728bdcdedfc720f97e10c"
},
"utility": {},
"persistence": {
Expand All @@ -20,11 +21,12 @@
"p2p": {
"consensus_port": 8080,
"use_rain_tree": true,
"connection_type": 1
"is_empty_connection_type": false,
"private_key": "f4f6d5a0001170bc61e3638dc68b5d1f54530e0923a0a1c70e0d39423a53104e030206dd1a85db222a5c641cba61921dfbb1fa6252b728bdcdedfc720f97e10c"
},
"telemetry": {
"enabled": true,
"address": "0.0.0.0:9000",
"endpoint": "/metrics"
}
}
}
10 changes: 6 additions & 4 deletions build/config/config2.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
"base": {
"root_directory": "/go/src/github.com/pocket-network",
"private_key": "8a76f99e3bf132f1d61bb4a123f495e00c169ac7c55fa1a2aa1b34196020edb191dd4fd53e8e27020d62796fe68b469fad5fa5a7abc61d3eb2bd98ba16af1e29"
"private_key": "fdc3f9c7439aa09fbe757abf217c64eb649b4ddfe11a98e15879e77bdbc5f1ccf81c19830cb42fa65d216946f230b5ffdc939717db7eb9503bbff97df91aa6a2"
},
"consensus": {
"max_mempool_bytes": 500000000,
"pacemaker_config": {
"timeout_msec": 5000,
"manual": true,
"debug_time_between_steps_msec": 1000
}
},
"private_key": "fdc3f9c7439aa09fbe757abf217c64eb649b4ddfe11a98e15879e77bdbc5f1ccf81c19830cb42fa65d216946f230b5ffdc939717db7eb9503bbff97df91aa6a2"
},
"utility": {},
"persistence": {
Expand All @@ -20,11 +21,12 @@
"p2p": {
"consensus_port": 8080,
"use_rain_tree": true,
"connection_type": 1
"is_empty_connection_type": false,
"private_key": "fdc3f9c7439aa09fbe757abf217c64eb649b4ddfe11a98e15879e77bdbc5f1ccf81c19830cb42fa65d216946f230b5ffdc939717db7eb9503bbff97df91aa6a2"
},
"telemetry": {
"enabled": true,
"address": "0.0.0.0:9000",
"endpoint": "/metrics"
}
}
}
10 changes: 6 additions & 4 deletions build/config/config3.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"base": {
"root_directory": "/go/src/github.com/pocket-network",
"private_key": "c7bd1bd027e76b31534c3f5226c8e3c3f2a034ba9fa11017b65191f7f9ef0d253e5e4bbed5f98721163bb84445072a9202d213f1e348c5e9e0e2ea83bbb7e3aa"
"private_key": "10c7ab1eca545fbc43a45385b189f363d303a592b4e6d8333d08c8b4b9c5cbcf93f17a5b4afc924fdda6070701c455b4ee7eae43e29324ac9de0b957f031c9c0"
},
"consensus": {
"max_mempool_bytes": 500000000,
"pacemaker_config": {
"timeout_msec": 5000,
"manual": true,
"debug_time_between_steps_msec": 1000
}
},
"private_key": "10c7ab1eca545fbc43a45385b189f363d303a592b4e6d8333d08c8b4b9c5cbcf93f17a5b4afc924fdda6070701c455b4ee7eae43e29324ac9de0b957f031c9c0"
},
"utility": {},
"persistence": {
Expand All @@ -20,11 +21,12 @@
"p2p": {
"consensus_port": 8080,
"use_rain_tree": true,
"connection_type": 1
"is_empty_connection_type": false,
"private_key": "10c7ab1eca545fbc43a45385b189f363d303a592b4e6d8333d08c8b4b9c5cbcf93f17a5b4afc924fdda6070701c455b4ee7eae43e29324ac9de0b957f031c9c0"
},
"telemetry": {
"enabled": true,
"address": "0.0.0.0:9000",
"endpoint": "/metrics"
}
}
}
10 changes: 6 additions & 4 deletions build/config/config4.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"base": {
"root_directory": "/go/src/github.com/pocket-network",
"private_key": "ddff03df6c525e551c5e9cd0e31ac4ec99dd6aa5d62185ba969bbf2e62db7e2c6c207cea1b1bf45dad8f8973d57291d3da31855254d7f1ed83ec3e06cabfe6b7"
"private_key": "458e94c056e0163c72752ebbd6df92a35fb6b30958d824be54af694f8ede4c7e06cc58d8c3ee9e463b4cfe680696a0b3eeed786bc3de1fa0268dfb4e4e1e9c68"
},
"consensus": {
"max_mempool_bytes": 500000000,
"pacemaker_config": {
"timeout_msec": 5000,
"manual": true,
"debug_time_between_steps_msec": 1000
}
},
"private_key": "458e94c056e0163c72752ebbd6df92a35fb6b30958d824be54af694f8ede4c7e06cc58d8c3ee9e463b4cfe680696a0b3eeed786bc3de1fa0268dfb4e4e1e9c68"
},
"utility": {},
"persistence": {
Expand All @@ -20,11 +21,12 @@
"p2p": {
"consensus_port": 8080,
"use_rain_tree": true,
"connection_type": 1
"is_empty_connection_type": false,
"private_key": "458e94c056e0163c72752ebbd6df92a35fb6b30958d824be54af694f8ede4c7e06cc58d8c3ee9e463b4cfe680696a0b3eeed786bc3de1fa0268dfb4e4e1e9c68"
},
"telemetry": {
"enabled": true,
"address": "0.0.0.0:9000",
"endpoint": "/metrics"
}
}
}
Loading