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

[P2P] KISS 4 - Basic nodes bootstrapping [Merge me after #522] - (Issue: #498) #523

Merged
merged 262 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
262 commits
Select commit Hold shift + click to select a range
cc95782
note about changing pocket-operator code
okdas Dec 10, 2022
5198b1d
Merge branch 'main' into dk-localnet-pocket-operator
okdas Dec 10, 2022
f0aa697
Update Makefile
okdas Dec 14, 2022
8b50310
Update Makefile
okdas Dec 14, 2022
52a44d7
Update Makefile
okdas Dec 14, 2022
846ba6c
requested changes so far
okdas Dec 14, 2022
558768e
more requested changes
okdas Dec 14, 2022
03f3ba3
Merge branch 'main' into dk-localnet-pocket-operator
okdas Dec 27, 2022
5b824af
some requested changes
okdas Dec 28, 2022
d53eded
Merge branch 'main' into dk-localnet-pocket-operator
okdas Jan 4, 2023
5225c3e
add mermaid diagram
okdas Jan 5, 2023
b2cb5af
clarify location of the config files
okdas Jan 5, 2023
80d790d
--wip-- [skip ci]
okdas Jan 5, 2023
c94cb4f
localnet without operator
okdas Jan 10, 2023
78f09da
Merge branch 'main' into dk-localnet-pocket-operator
okdas Jan 10, 2023
372bb6c
latest config
okdas Jan 11, 2023
b92bc03
Merge branch 'main' into dk-localnet-pocket-operator
okdas Jan 11, 2023
1b103d7
fully working operatorless localnet
okdas Jan 11, 2023
0f354d9
auto update now works too
okdas Jan 11, 2023
7631fd3
--wip-- [skip ci]
okdas Jan 12, 2023
1d57ceb
bump documentation
okdas Jan 14, 2023
ac40457
change config a bit
okdas Jan 14, 2023
06c8ef3
this is not needed anymore
okdas Jan 19, 2023
cba72f7
Merge branch 'main' into dk-localnet-pocket-operator
okdas Jan 19, 2023
a778f2c
can scale validators automatically
okdas Jan 20, 2023
2e47e2c
change keys
okdas Jan 28, 2023
fa24420
Merge branch 'main' into dk-localnet-pocket-operator
okdas Jan 28, 2023
ebd5dd8
also replace pubkeys
okdas Jan 28, 2023
defca3b
complete changing the keys // tests passed
okdas Jan 30, 2023
03e5a04
bring bck state hashes
okdas Jan 30, 2023
36b1e5f
Merge branch 'main' into dk-localnet-pocket-operator
okdas Jan 31, 2023
19d6ba4
wip
okdas Jan 31, 2023
fae2775
wip
okdas Jan 31, 2023
28c2ee0
add/change changelogs
okdas Jan 31, 2023
27d0daf
create localnet_config.yaml when it doesn exist
okdas Feb 1, 2023
294ae17
Updated gitinore for Tilt
Olshansk Jan 31, 2023
bc846f3
Made the Makefile help command work
Olshansk Feb 1, 2023
792f973
Renamed the readme file and fixed default formatting
Olshansk Feb 1, 2023
25a4a36
Update error messages
Olshansk Feb 1, 2023
cc96bf3
Update error messages
Olshansk Feb 1, 2023
8364117
WIP commit - review + removing $ everywhere
Olshansk Feb 1, 2023
1261079
Update all the documentation
Olshansk Feb 1, 2023
4c1fd86
feat(localnet): initcontainer to wait for postgres
deblasis Feb 2, 2023
f75fde2
feat(localnet): initcontainer to wait for postgres
deblasis Feb 2, 2023
cfca9c6
feat(localnet): cluster-manager POC
deblasis Feb 2, 2023
b46d2d3
also install helm
okdas Feb 2, 2023
f7e41fb
feat(crypto): ed25519
deblasis Feb 2, 2023
e0873d6
refactor(genesis): added accounts for all the validators in Localnet
deblasis Feb 2, 2023
e9689ab
refactor(localnet): renamed cluster-manager serviceAccount
deblasis Feb 2, 2023
23b2d9b
feat(localnet): cluster-manager validator keys from secret - WIP
deblasis Feb 2, 2023
2dc1bae
fix(utility): nil pointer fix
deblasis Feb 2, 2023
7188a2e
requested changes so far
okdas Feb 2, 2023
1bf5fd4
more requested changes
okdas Feb 3, 2023
54a7629
update links
okdas Feb 3, 2023
7ec2217
include demo
okdas Feb 3, 2023
1ac46b8
chore(docker-compose): renamed deployment to pocket-v1
deblasis Feb 3, 2023
e280594
feat(CLI): allowing non interactive stake and unstake
deblasis Feb 3, 2023
f0eaf43
feat(localnet): cluster-manager dogfoods the CLI to stake/unstake
deblasis Feb 3, 2023
fc7f167
feat(localnet): dogfooding CLI in cluster-manager
deblasis Feb 3, 2023
a920a5d
feat(makefile): localnet_db_cli
deblasis Feb 3, 2023
6237753
feat(utility): clearing mempool on resetToGenesis
deblasis Feb 3, 2023
841d90c
chore(go.mod): tidy
deblasis Feb 3, 2023
33a45cf
Update build/localnet/README.md
okdas Feb 3, 2023
469e67a
Update build/localnet/README.md
okdas Feb 3, 2023
a8df9d9
Update build/localnet/README.md
okdas Feb 3, 2023
5a5c042
Update build/localnet/README.md
okdas Feb 3, 2023
62561c6
Update build/localnet/Tiltfile
okdas Feb 3, 2023
46d3f74
Update build/localnet/README.md
okdas Feb 3, 2023
2135d26
Update build/localnet/README.md
okdas Feb 3, 2023
fe98bce
Update build/localnet/README.md
okdas Feb 3, 2023
1e59e9c
Update build/localnet/Tiltfile
okdas Feb 3, 2023
1c17e68
clarify postgres ports
okdas Feb 3, 2023
f3d083b
Merge branch 'main' into dk-localnet-pocket-operator
okdas Feb 3, 2023
8e864f3
fix changelogs
okdas Feb 3, 2023
93851be
oops, this got lost!
okdas Feb 3, 2023
4b8da0f
Merge remote-tracking branch 'upstream/dk-localnet-pocket-operator' i…
deblasis Feb 5, 2023
778c33d
refactor(localnet): updates from dima's branch
deblasis Feb 5, 2023
aea3359
feat(localnet): cli-client waits for v1-validator001 (target node)
deblasis Feb 5, 2023
61606f7
feat(localnet): accounts updated in genesis for localnet as well
deblasis Feb 5, 2023
104339a
fix(utility): logging error if ApplyTransaction fails...
deblasis Feb 5, 2023
18a6706
feat(consensus): NewHeightEvent
deblasis Feb 6, 2023
ce6b59a
Revert "feat(consensus): NewHeightEvent"
deblasis Feb 6, 2023
cc3c8c7
feat(consensus): NewHeightEvent
deblasis Feb 6, 2023
9a441a4
feat(consensus): resetToGenesis publishes NewHeightEvent
deblasis Feb 6, 2023
00d4d8c
feat(consensus): SetHeight publishes NewHeightEvent
deblasis Feb 6, 2023
d418dc5
refactor(shared): ModulesRegistry
deblasis Feb 6, 2023
347102e
fix(shared): module registration
deblasis Feb 6, 2023
cbd9213
fix(runtime): fixed tests
deblasis Feb 6, 2023
3f0aaeb
Merge remote-tracking branch 'upstream/main' into issue/416-kiss-peer…
deblasis Feb 6, 2023
c51fcfb
fix(utility): missing import
deblasis Feb 6, 2023
6e5e014
fix(bus): GetModulesRegistry implementation
deblasis Feb 7, 2023
ac8c3f9
refactor(rpc): github.com/deepmap/oapi-codegen/pkg/runtime import
deblasis Feb 7, 2023
0a9a7c7
feat(rpc): GET /v1/p2p/address_book implementation
deblasis Feb 7, 2023
0aaa652
feat(shared): baseModules -> DRY
deblasis Feb 7, 2023
e83dc10
fix(p2p): modulesRegistry mock config
deblasis Feb 7, 2023
8260e63
refactor(infra): passing RPC_HOST to debug client
deblasis Feb 7, 2023
fbf013e
feat(p2p): rpc addrbook_provider
deblasis Feb 7, 2023
3b74980
feat(p2p): rpc current_height_provider
deblasis Feb 7, 2023
7e2b809
feat(shared): generalized module options
deblasis Feb 7, 2023
e7b76fd
fix(p2p): raintree using currentHeightProvider
deblasis Feb 7, 2023
0aef8e2
fix(rpc): fixed openapi P2PStakedActorsResponse
deblasis Feb 7, 2023
596d754
refactor(runtime): exposed DefailtRPCPort
deblasis Feb 7, 2023
f840eed
fix(runtime): fixed bus in RuntimeManager
deblasis Feb 7, 2023
378e87b
refactor(cli): debug cli now sources addressbook remotely via RPC
deblasis Feb 7, 2023
00df050
Merge remote-tracking branch 'upstream/main' into issue/416-kiss-peer…
deblasis Feb 7, 2023
727b729
fix(cli): merge fix
deblasis Feb 7, 2023
de7c8c0
fix(rpc): merge fix
deblasis Feb 7, 2023
352c068
refactor(p2p): deprecated debugCurrentHeightProvider
deblasis Feb 7, 2023
18852ee
fix(p2p): fixed tests (mock config)
deblasis Feb 7, 2023
4331a9d
refactor(shared): simplified module registration
deblasis Feb 7, 2023
029fd17
chore(shared): linting
deblasis Feb 7, 2023
d1684cb
chore(shared): linting
deblasis Feb 7, 2023
00af4ac
refactor(cli): centralized not_interactive flag
deblasis Feb 7, 2023
9f5e35e
chore(cli): updated flag description
deblasis Feb 7, 2023
e84977b
refactor(cli): refactored broadcast
deblasis Feb 7, 2023
17137d2
feat(p2p): reacting to height changes => addrbook delta
deblasis Feb 7, 2023
59a0ea1
refactor(rpc): simplified module
deblasis Feb 7, 2023
7a89eec
feat(cluster-manager): wait for validator1
deblasis Feb 8, 2023
1a92565
feat(state_machine): node finite state machine WIP
deblasis Feb 8, 2023
0401e39
fix(state-machine): updated to consider serverMode as independent proc
deblasis Feb 8, 2023
36535ad
fix(cluster-manager): fix port
deblasis Feb 8, 2023
00adc0d
refactor(p2p): bootstrapping
deblasis Feb 8, 2023
a29c2bc
feat(pocket): override bootstrapnodes
deblasis Feb 8, 2023
e6cb404
refactor(rpc): rpcServer implements BaseIntegratableModule
deblasis Feb 8, 2023
3e2c538
fix(consensus): fixed tests (mock cfg)
deblasis Feb 8, 2023
622f4d3
fix(p2p): bus shadowing embed fix
deblasis Feb 8, 2023
8171a05
chore(state_machine): shadowing fix
deblasis Feb 8, 2023
7b4e7c4
fix(p2p): error checking on add/remove peer
deblasis Feb 8, 2023
d08082d
chore(shared): return err on HandleEvent
deblasis Feb 8, 2023
8eba0db
chore(shared): linting
deblasis Feb 8, 2023
4c92b09
docs(consensus): CHANGELOG + nit
deblasis Feb 8, 2023
3f37ba9
docs(p2p): CHANGELOG
deblasis Feb 8, 2023
41dd4a4
chore(p2p): typo
deblasis Feb 8, 2023
78eac4a
chore(cluster-manager): linting
deblasis Feb 9, 2023
a021202
chore(cluster-manager): linting exclusion for CLI
deblasis Feb 9, 2023
0ae1426
docs(shared): CHANGELOGs + nits
deblasis Feb 9, 2023
6d5ff55
docs(shared): CHANGELOGS + nits
deblasis Feb 9, 2023
d6a4a63
Merge remote-tracking branch 'upstream/main' into issue/416-kiss-peer…
deblasis Feb 9, 2023
aab3ecc
docs(state_machine): docs + nits
deblasis Feb 9, 2023
261b634
docs(shared): CHANGELOGs
deblasis Feb 9, 2023
4a7afd6
fix(state_machine): CHANGELOG version
deblasis Feb 9, 2023
e8ae3ad
docs(persistence): typo
deblasis Feb 9, 2023
2854dcb
chore(shared): linter nits
deblasis Feb 9, 2023
41b2bcf
chore(cluster-manager): nit
deblasis Feb 9, 2023
d4a63a8
Merge remote-tracking branch 'upstream/main' into issue/416-kiss-peer…
deblasis Feb 10, 2023
f488c35
fix(shared): processing module options
deblasis Feb 10, 2023
b8f67b6
refactor(shared): base modules in their own package
deblasis Feb 10, 2023
dcee5a8
docs(shared): dates in CHANGELOG
deblasis Feb 10, 2023
ad2e783
Update Makefile
deblasis Feb 12, 2023
ef818eb
Update app/client/cli/actor.go
deblasis Feb 12, 2023
11f8a7b
refactor(cli): injecting bus into CLI context
deblasis Feb 13, 2023
bcef6eb
refactor(cli): bus in cli context
deblasis Feb 13, 2023
143feaa
feat(shared): module Create with ModuleOptions
deblasis Feb 16, 2023
a046984
docs(shared): godoc for ModuleOption
deblasis Feb 16, 2023
82505e4
docs(shared): updated README
deblasis Feb 16, 2023
da9774b
feat(shared): base_modules
deblasis Feb 16, 2023
f784dab
fix(utility): logging error when ApplyTransaction fails
deblasis Feb 16, 2023
049023c
refactor(utility): implementing base_modules and options
deblasis Feb 16, 2023
a18ecf5
fix(utility): using logger in message_handler
deblasis Feb 16, 2023
e01c75c
docs(utility): changelog
deblasis Feb 16, 2023
142d53b
refactor(telemetry): implementing base_modules and options
deblasis Feb 16, 2023
3c84eae
docs(telemetry): changelog
deblasis Feb 16, 2023
4eed45a
feat(shared): ModulesRegistry interface
deblasis Feb 16, 2023
b094622
refactor(shared): updated bus interface to use ModuleRegistry
deblasis Feb 16, 2023
e6e8fe5
refactor(persistence): implementing base_modules and options
deblasis Feb 16, 2023
f8ed453
docs(persistence): changelog
deblasis Feb 16, 2023
2a21542
refactor(consensus): implementing base_modules and options
deblasis Feb 16, 2023
e70b308
refactor(logger): implementing base_modules and options
deblasis Feb 16, 2023
0d20ada
docs(logger): changelog
deblasis Feb 16, 2023
963212a
refactor(rpc): implementing base_modules and options
deblasis Feb 16, 2023
8871a3d
docs(rpc): changelog
deblasis Feb 16, 2023
8d50538
feat(runtime): ModulesRegistry implementation
deblasis Feb 16, 2023
5141f07
feat(p2p): implementing base_modules and options
deblasis Feb 16, 2023
1d98c9f
refactor(state_sync): implementing base_modules and options
deblasis Feb 16, 2023
f5f9777
refactor(runtime): bus uses ModulesRegistry and logger
deblasis Feb 16, 2023
4c5f50c
fix(runtime): StateMachine doesn't exist yet :)
deblasis Feb 16, 2023
7023ca0
refactor(runtime): errors referring ModulesRegistry
deblasis Feb 16, 2023
34f3d87
refactor(runtime): runtimeManager implements base IntegratableModule
deblasis Feb 16, 2023
74d012f
feat(state_machine): KISS FSM implementation
deblasis Feb 16, 2023
d697a7f
feat(shared): state_machine integration with node
deblasis Feb 16, 2023
8e89219
feat(shared): FSM states and events
deblasis Feb 16, 2023
c66a5c8
refactor(shared): messaging events
deblasis Feb 16, 2023
eb4174b
refactor(shared): state_machine interface
deblasis Feb 16, 2023
7b974a9
fix(runtime): removed bus from Manager, it's embedded
deblasis Feb 16, 2023
8a5de14
refactor(consensus): updated tests
deblasis Feb 16, 2023
3a71510
feat(consensus): publishing event on new height
deblasis Feb 16, 2023
a2e3348
refactor(leader_election): implementing base_modules and options
deblasis Feb 16, 2023
f006a1d
refactor(pacemaker): implementing base_modules and options
deblasis Feb 16, 2023
8cdc827
feat(consensus): sending events via SetHeight
deblasis Feb 16, 2023
5514fc3
docs(consensus): changelog
deblasis Feb 16, 2023
72f96d9
docs(shared): updated README
deblasis Feb 16, 2023
934fe00
chore(go.mod): tidy
deblasis Feb 16, 2023
9bf8b81
fix(p2p): fixes from backporting legacy functionality
deblasis Feb 16, 2023
724a326
docs(shared): changelogs
deblasis Feb 16, 2023
c0cdeac
feat(consensus): improved test resiliency
deblasis Feb 16, 2023
64bec6c
feat(Makefile): make localnet_db_cli
deblasis Feb 16, 2023
9bd11e3
fix(Makefile): fixed make go_lint
deblasis Feb 16, 2023
b02cdf1
feat(p2p): event handling
deblasis Feb 16, 2023
aa450db
refactor(p2p): refactored providers
deblasis Feb 16, 2023
9eddb29
feat(p2p): updated raintree to use currentHeightProvider
deblasis Feb 16, 2023
b96f60f
refactor(p2p): RemovePeerFromAddrBook
deblasis Feb 16, 2023
dfa80c6
refactor(p2p): providers from DI (bus)
deblasis Feb 16, 2023
e13f375
feat(p2p): addrbook_delta
deblasis Feb 16, 2023
dfabb4b
docs(p2p): changelog
deblasis Feb 16, 2023
0a78b70
feat(rpc): exposing staked_actors_addrbook via rpc
deblasis Feb 16, 2023
0a0ec29
feat(shared): crypto UnmarshalText for ed25519
deblasis Feb 16, 2023
1828aca
chore(runtime): GetRuntimeMgr last (grouping modules)
deblasis Feb 16, 2023
e5c93f7
chore(consensus): lint
deblasis Feb 16, 2023
312ba73
Merge remote-tracking branch 'upstream/issue/499-fsm' into issue/416-…
deblasis Feb 16, 2023
26d1b65
refactor(cli): using rpcprovider in debug commands
deblasis Feb 16, 2023
6c5444a
docs(cli): changelog
deblasis Feb 16, 2023
0c01bb4
refactor(runtime): updated defaults
deblasis Feb 16, 2023
91645e9
fix(runtime): configs
deblasis Feb 16, 2023
f160016
chore(go.mod): tidy
deblasis Feb 16, 2023
f9d9e68
fix(p2p): using defaults
deblasis Feb 16, 2023
464dca0
fix(p2p): event_handler return error fix
deblasis Feb 16, 2023
cfcee30
fix(cli): rpc host overriding
deblasis Feb 16, 2023
25910ab
refactor(cli): using cli context to pass the bus around
deblasis Feb 16, 2023
8af0a90
chore(cli): unused import 🧹
deblasis Feb 16, 2023
6baf43b
docs(shared): changelogs
deblasis Feb 16, 2023
a259049
feat(runtime): adding 999 validators accounts
deblasis Feb 16, 2023
2a4a616
refactor(docker-compose): renamed deployment to pocket-v1
deblasis Feb 16, 2023
08818cc
feat(docker-compose): setting RPC_HOST in client to point to validator1
deblasis Feb 16, 2023
21bc1aa
feat(cluster-manager): implementation
deblasis Feb 16, 2023
672121c
feat(k8s-localnet): refactored manifests and added cluster-manager
deblasis Feb 16, 2023
fcbed3a
docs(build): changelog
deblasis Feb 16, 2023
c004927
feat(cli): allowing non_interactive stake/unstake
deblasis Feb 16, 2023
aaf5d33
docs(cli): changelog
deblasis Feb 16, 2023
659b51d
chore(go.mod): tidy
deblasis Feb 16, 2023
57249d7
feat(cli): bootstrap nodes override via flag
deblasis Feb 17, 2023
7162e9d
feat(p2p): reacting to stateMachineTransitionEvents
deblasis Feb 17, 2023
778ef4c
feat(runtime): bootstrap_nodes_csv config
deblasis Feb 17, 2023
48ccab1
feat(p2p): handling bootstrapNodes
deblasis Feb 17, 2023
b48393b
feat(shared): fanning out stateTransitionEvent
deblasis Feb 17, 2023
28109ed
docs(p2p): changelog
deblasis Feb 17, 2023
359a083
docs(runtime): changelog
deblasis Feb 17, 2023
ab11371
chore(cluster-manager): renamed log->logger
deblasis Feb 17, 2023
a4e7d74
chore(cluster-manager): TODO
deblasis Feb 17, 2023
1131751
docs(cluster-manager): extractValidatorId godoc
deblasis Feb 17, 2023
d50bcf8
Merge branch 'issue/490-cluster-manager' into issue/498-kiss-bootstra…
deblasis Feb 17, 2023
4ec57cf
Update p2p/event_handler.go
deblasis Feb 17, 2023
ce61b56
chore(p2p): if err
deblasis Feb 17, 2023
2e81586
Merge branch 'issue/498-kiss-bootstrapping' of github.com:pokt-networ…
deblasis Feb 17, 2023
7ff9722
Merge remote-tracking branch 'upstream/main' into issue/498-kiss-boot…
deblasis Feb 20, 2023
bba86e4
chore(p2p): nits
deblasis Feb 20, 2023
a555dc9
fix(p2p): bootstrapping logic fix
deblasis Feb 20, 2023
12f1303
refactor(p2p): advertise regardless
deblasis Feb 20, 2023
aa67c5d
chore(consensus): merge fix
deblasis Feb 20, 2023
1aed78e
docs(shared): fix changelogs
deblasis Feb 20, 2023
1dc3f7d
chore(p2p): nits
deblasis Feb 20, 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
4 changes: 4 additions & 0 deletions app/pocket/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.0.6] - 2023-02-20

- Added the ability to override the default `BootstrapNodes` via flag

## [0.0.0.5] - 2023-02-17

- Removed unnecessary server mode enabling call via `EnableServerMode()` function
Expand Down
8 changes: 7 additions & 1 deletion app/pocket/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
func main() {
configFilename := flag.String("config", "", "Relative or absolute path to the config file.")
genesisFilename := flag.String("genesis", "", "Relative or absolute path to the genesis file.")
bootstrapNodes := flag.String("bootstrap-nodes", "", "Comma separated list of bootstrap nodes.")

v := flag.Bool("version", false, "")
flag.Parse()
Expand All @@ -21,7 +22,12 @@ func main() {
return
}

runtimeMgr := runtime.NewManagerFromFiles(*configFilename, *genesisFilename)
options := []func(*runtime.Manager){}
if bootstrapNodes != nil && *bootstrapNodes != "" {
options = append(options, runtime.WithBootstrapNodes(*bootstrapNodes))
}

runtimeMgr := runtime.NewManagerFromFiles(*configFilename, *genesisFilename, options...)
bus, err := runtime.CreateBus(runtimeMgr)
if err != nil {
logger.Global.Fatal().Err(err).Msg("Failed to create bus")
Expand Down
5 changes: 5 additions & 0 deletions p2p/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.0.28] - 2023-02-20

- Added basic `bootstrap` nodes support
- Reacting to `ConsensusNewHeightEventType` and `StateMachineTransitionEventType` to update the address book and current height and determine if a bootstrap is needed

## [0.0.0.27] - 2023-02-17

- Deprecated `debugAddressBookProvider`
Expand Down
105 changes: 105 additions & 0 deletions p2p/bootstrap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package p2p

import (
"context"
"encoding/csv"
"fmt"
"net/http"
"regexp"
"strconv"
"strings"

rpcABP "github.com/pokt-network/pocket/p2p/providers/addrbook_provider/rpc"
rpcCHP "github.com/pokt-network/pocket/p2p/providers/current_height_provider/rpc"
typesP2P "github.com/pokt-network/pocket/p2p/types"
"github.com/pokt-network/pocket/rpc"
"github.com/pokt-network/pocket/runtime/defaults"
)

// configureBootstrapNodes parses the bootstrap nodes from the config and validates them
func (m *p2pModule) configureBootstrapNodes() error {
p2pCfg := m.GetBus().GetRuntimeMgr().GetConfig().P2P

bootstrapNodesCsv := strings.Trim(p2pCfg.BootstrapNodesCsv, " ")
if bootstrapNodesCsv == "" {
bootstrapNodesCsv = defaults.DefaultP2PBootstrapNodesCsv
}
csvReader := csv.NewReader(strings.NewReader(bootstrapNodesCsv))
bootStrapNodes, err := csvReader.Read()
if err != nil {
return fmt.Errorf("error parsing bootstrap nodes: %w", err)
}

// validate the bootstrap nodes
for i, node := range bootStrapNodes {
bootStrapNodes[i] = strings.Trim(node, " ")
if !isValidHostnamePort(bootStrapNodes[i]) {
return fmt.Errorf("invalid bootstrap node: %s", bootStrapNodes[i])
}
}
m.bootstrapNodes = bootStrapNodes
return nil
}

// bootstrap attempts to bootstrap from a bootstrap node
func (m *p2pModule) bootstrap() error {
var addrBook typesP2P.AddrBook

for _, bootstrapNode := range m.bootstrapNodes {
m.logger.Info().Str("endpoint", bootstrapNode).Msg("Attempting to bootstrap from bootstrap node")

client, err := rpc.NewClientWithResponses(bootstrapNode)
if err != nil {
continue
}
healthCheck, err := client.GetV1Health(context.TODO())
if err != nil || healthCheck == nil || healthCheck.StatusCode != http.StatusOK {
m.logger.Warn().Str("bootstrapNode", bootstrapNode).Msg("Error getting a green health check from bootstrap node")
continue
}

addressBookProvider := rpcABP.NewRPCAddrBookProvider(
rpcABP.WithP2PConfig(
m.GetBus().GetRuntimeMgr().GetConfig().P2P,
),
rpcABP.WithCustomRPCUrl(bootstrapNode),
)

currentHeightProvider := rpcCHP.NewRPCCurrentHeightProvider(rpcCHP.WithCustomRPCUrl(bootstrapNode))

addrBook, err = addressBookProvider.GetStakedAddrBookAtHeight(currentHeightProvider.CurrentHeight())
if err != nil {
m.logger.Warn().Err(err).Str("endpoint", bootstrapNode).Msg("Error getting address book from bootstrap node")
continue
}
}

if len(addrBook) == 0 {
return fmt.Errorf("bootstrap failed")
}

for _, peer := range addrBook {
m.logger.Debug().Str("address", peer.Address.String()).Msg("Adding peer to addrBook")
if err := m.network.AddPeerToAddrBook(peer); err != nil {
return err
}
}
return nil
}

func isValidHostnamePort(str string) bool {
pattern := regexp.MustCompile(`^(https?)://([a-zA-Z0-9.-]+):(\d{1,5})$`)
matches := pattern.FindStringSubmatch(str)
if len(matches) != 4 {
return false
}
protocol := matches[1]
if protocol != "http" && protocol != "https" {
return false
}
port, err := strconv.Atoi(matches[3])
if err != nil || port < 0 || port > 65535 {
return false
}
return true
}
22 changes: 22 additions & 0 deletions p2p/event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/pokt-network/pocket/shared/codec"
coreTypes "github.com/pokt-network/pocket/shared/core/types"
"github.com/pokt-network/pocket/shared/messaging"
"google.golang.org/protobuf/types/known/anypb"
)
Expand Down Expand Up @@ -40,6 +41,27 @@ func (m *p2pModule) HandleEvent(event *anypb.Any) error {
}
}

case messaging.StateMachineTransitionEventType:
stateMachineTransitionEvent, ok := evt.(*messaging.StateMachineTransitionEvent)
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
if !ok {
return fmt.Errorf("failed to cast event to StateMachineTransitionEvent")
}

if stateMachineTransitionEvent.NewState == string(coreTypes.StateMachineState_P2P_Bootstrapping) {
addrBook := m.network.GetAddrBook()
if len(addrBook) == 0 {
m.logger.Warn().Msg("No peers in addrbook, bootstrapping")

if err := m.bootstrap(); err != nil {
return err
}
}
m.logger.Info().Bool("TODO", true).Msg("Advertise self to network")
if err := m.GetBus().GetStateMachineModule().SendEvent(coreTypes.StateMachineEvent_P2P_IsBootstrapped); err != nil {
return err
}
}

default:
return fmt.Errorf("unknown event type: %s", event.MessageName())
}
Expand Down
6 changes: 6 additions & 0 deletions p2p/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type p2pModule struct {

addrBookProvider providers.AddrBookProvider
currentHeightProvider providers.CurrentHeightProvider

bootstrapNodes []string
}

func Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) {
Expand All @@ -55,6 +57,10 @@ func (*p2pModule) Create(bus modules.Bus, options ...modules.ModuleOption) (modu
cfg := runtimeMgr.GetConfig()
p2pCfg := cfg.P2P

if err := m.configureBootstrapNodes(); err != nil {
return nil, err
}

privateKey, err := cryptoPocket.NewPrivateKey(p2pCfg.PrivateKey)
if err != nil {
return nil, err
Expand Down
129 changes: 129 additions & 0 deletions p2p/module_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package p2p

import (
"strings"
"testing"

"github.com/golang/mock/gomock"
"github.com/pokt-network/pocket/runtime/configs"
"github.com/pokt-network/pocket/runtime/defaults"
cryptoPocket "github.com/pokt-network/pocket/shared/crypto"
"github.com/pokt-network/pocket/shared/modules"
mockModules "github.com/pokt-network/pocket/shared/modules/mocks"
"github.com/stretchr/testify/require"
)

func Test_Create_configureBootstrapNodes(t *testing.T) {
defaultBootstrapNodes := strings.Split(defaults.DefaultP2PBootstrapNodesCsv, ",")
key := cryptoPocket.GetPrivKeySeed(1)

type args struct {
initialBootstrapNodesCsv string
}
tests := []struct {
name string
args args
wantBootstrapNodes []string
wantErr bool
}{
{
name: "unset boostrap nodes should yield no error and return DefaultP2PBootstrapNodes",
args: args{},
wantErr: false,
wantBootstrapNodes: defaultBootstrapNodes,
},
{
name: "empty string boostrap nodes should yield no error and return DefaultP2PBootstrapNodes",
args: args{
initialBootstrapNodesCsv: "",
},
wantErr: false,
wantBootstrapNodes: defaultBootstrapNodes,
},
{
name: "untrimmed empty string boostrap nodes should yield no error and return DefaultP2PBootstrapNodes",
args: args{
initialBootstrapNodesCsv: " ",
},
wantErr: false,
wantBootstrapNodes: defaultBootstrapNodes,
},
{
name: "untrimmed string boostrap nodes should yield no error and return the trimmed urls",
args: args{
initialBootstrapNodesCsv: " http://somenode:50832 , http://someothernode:50832 ",
},
wantErr: false,
wantBootstrapNodes: []string{"http://somenode:50832", "http://someothernode:50832"},
},
{
name: "custom bootstrap nodes should yield no error and return the custom bootstrap node",
args: args{
initialBootstrapNodesCsv: "http://somenode:50832,http://someothernode:50832",
},
wantBootstrapNodes: []string{"http://somenode:50832", "http://someothernode:50832"},
wantErr: false,
},
{
name: "malformed bootstrap nodes string should yield an error and return nil",
args: args{
initialBootstrapNodesCsv: "\n\n",
},
wantBootstrapNodes: []string(nil),
wantErr: true,
},
{
name: "port number too high yields an error and empty list of bootstrap nodes",
args: args{
initialBootstrapNodesCsv: "http://somenode:99999",
},
wantBootstrapNodes: []string(nil),
wantErr: true,
},
{
name: "negative port number yields an error and empty list of bootstrap nodes",
args: args{
initialBootstrapNodesCsv: "udp://somenode:-8080",
},
wantBootstrapNodes: []string(nil),
wantErr: true,
},
{
name: "wrong protocol yields an error and empty list of bootstrap nodes",
args: args{
initialBootstrapNodesCsv: "udp://somenode:58884",
},
wantBootstrapNodes: []string(nil),
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctrl := gomock.NewController(t)
mockRuntimeMgr := mockModules.NewMockRuntimeMgr(ctrl)
mockBus := createMockBus(t, mockRuntimeMgr)
mockConsensusModule := mockModules.NewMockConsensusModule(ctrl)
mockBus.EXPECT().GetConsensusModule().Return(mockConsensusModule).AnyTimes()
mockRuntimeMgr.EXPECT().GetConfig().Return(&configs.Config{
PrivateKey: key.String(),
P2P: &configs.P2PConfig{
BootstrapNodesCsv: tt.args.initialBootstrapNodesCsv,
PrivateKey: key.String(),
},
}).AnyTimes()
mockBus.EXPECT().GetRuntimeMgr().Return(mockRuntimeMgr).AnyTimes()

var p2pMod modules.Module
p2pMod, err := Create(mockBus)
if (err != nil) != tt.wantErr {
t.Errorf("p2pModule.Create() error = %v, wantErr %v", err, tt.wantErr)
}

if !tt.wantErr {
actualBootstrapNodes := p2pMod.(*p2pModule).bootstrapNodes
require.EqualValues(t, tt.wantBootstrapNodes, actualBootstrapNodes)
}
})
}
}
2 changes: 1 addition & 1 deletion p2p/providers/current_height_provider/rpc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (rchp *rpcCurrentHeightProvider) CurrentHeight() uint64 {

func NewRPCCurrentHeightProvider(options ...modules.ModuleOption) *rpcCurrentHeightProvider {
rchp := &rpcCurrentHeightProvider{
rpcUrl: fmt.Sprintf("http://%s:%s", rpcHost, defaults.DefaultRPCPort),
rpcUrl: fmt.Sprintf("http://%s:%s", rpcHost, defaults.DefaultRPCPort), // TODO: Make port configurable
}

for _, o := range options {
Expand Down
10 changes: 1 addition & 9 deletions p2p/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package p2p

import (
"crypto/ed25519"
"encoding/binary"
"fmt"
"log"
"sort"
Expand Down Expand Up @@ -50,13 +48,7 @@ func generateKeys(_ *testing.T, numValidators int) []cryptoPocket.PrivateKey {

for i := range keys {
seedInt := genesisConfigSeedStart + i
seed := make([]byte, ed25519.PrivateKeySize)
binary.LittleEndian.PutUint32(seed, uint32(seedInt))
pk, err := cryptoPocket.NewPrivateKeyFromSeed(seed)
if err != nil {
panic(err)
}
keys[i] = pk
keys[i] = cryptoPocket.GetPrivKeySeed(seedInt)
}
sort.Slice(keys, func(i, j int) bool {
return keys[i].Address().String() < keys[j].Address().String()
Expand Down
1 change: 1 addition & 0 deletions runtime/configs/proto/p2p_config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ message P2PConfig {
conn.ConnectionType connection_type = 4;
uint64 max_mempool_count = 5; // this is used to limit the number of nonces that can be stored in the mempool, after which a FIFO mechanism is used to remove the oldest nonces and make space for the new ones
bool is_client_only = 6;
string bootstrap_nodes_csv = 7; // string in the format "http://somenode:50832,http://someothernode:50832". Refer to `p2p/module_test.go` for additional details.
}
8 changes: 8 additions & 0 deletions runtime/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ var (
DefaultP2PUseRainTree = true
DefaultP2PConnectionType = types.ConnectionType_TCPConnection
DefaultP2PMaxMempoolCount = uint64(1e5)
// DefaultP2PBootstrapNodesCsv is a list of nodes to bootstrap the network with. By convention, for now, the first validator will provide bootstrapping facilities.
//
// In LocalNet, the developer will have only one of the two stack online, therefore this is also a poor's man way to simulate the scenario in which a boostrap node is offline.
DefaultP2PBootstrapNodesCsv = fmt.Sprintf("%s,%s",
fmt.Sprintf("http://%s:%s", Validator1EndpointDockerCompose, DefaultRPCPort),
fmt.Sprintf("http://%s:%s", Validator1EndpointK8S, DefaultRPCPort),
)

// telemetry
DefaultTelemetryEnabled = true
DefaultTelemetryAddress = "0.0.0.0:9000"
Expand Down
Loading