-
Notifications
You must be signed in to change notification settings - Fork 33
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
[TECHDEBT] Consolidate & encapsulate ValidatorMap logic - (Issue #203) #402
Changes from all commits
79e988c
f925a1f
27859db
e19041b
550c47e
3dc5ffd
3c9cbc7
a4abab8
4d01838
12ee0ec
520b8b9
caaad9c
9506419
0cf393c
3fdc817
10a1bb6
5a7c14c
f3df734
1e14b35
3e5dd59
ec77c33
8e2866e
f54875f
8e5b367
53d496b
47540f6
dbb24d5
f9d2a04
09aa018
f773345
ea0b2a7
359648a
8e146a6
5c3d939
266b47a
4ce80bc
34c0e76
7ac25bb
8880c17
dd3020e
46e20db
d0aea4c
ceea403
8f83720
cf1ef0d
1ff01a2
f66c621
6bab7eb
f70466a
7c05196
d82b66a
644df90
d0437a1
b53f127
7b8d75b
90f4187
07a4b40
c74d34e
29d3322
e0eedd0
7d69837
ff1b66d
30e2cfb
964360b
1084944
36d7129
2195594
fe80633
3adc9a5
bcc96c9
f3717eb
8107177
cb58f21
604aa8e
0e45a5b
1fe30a3
005ecfb
adc2783
d4b5f7d
911d01b
9effbe9
d53f40a
0823894
86ae4d8
52ea911
11a41eb
7c9fe8c
1c65cb9
d8fbd35
b2fa44f
b71e350
908af80
da0e77c
cd8bffe
14e8d48
70b7a75
628b960
7b0eb8c
92c6050
30c18c5
4f43b5d
b62365a
0f18c5b
b41f5b1
3131e00
8954e86
9735b50
b5f2ef5
9eb0646
4e3d227
6d9e45c
5899337
ac11ed1
abcc7cd
9a32d51
96d00fa
a00761e
c7ac954
e5fd2ad
185b429
bc8d8ae
bd25a73
843f1b4
fe3418b
eff0afb
a4ea7df
2eea763
77586e4
7b3b7c5
6213789
3c026f7
c9b27ee
5e01b23
ec59138
981da2c
cc221b6
4a820dc
2abd96b
9efa129
21f182d
7972285
fc2a042
46d6fb1
59847fa
9a6d9ea
3eeef0d
0445cdb
bd9fc6b
2b8016c
d54634c
8a42941
79d668c
3d3d0b3
7c819d8
b32e865
ef5c8b9
cd1ff15
f33fa30
4f06f56
a1cba4f
307c137
9d0c61b
d7b9577
2e1dccb
c9e1940
4ca994b
c76a391
343dea3
90d331d
baa3aab
69d060c
01a609b
185b524
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,18 @@ | ||
//go:build debug | ||
// +build debug | ||
|
||
package cli | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"sync" | ||
|
||
"github.com/manifoldco/promptui" | ||
"github.com/pokt-network/pocket/consensus" | ||
"github.com/pokt-network/pocket/logger" | ||
"github.com/pokt-network/pocket/p2p" | ||
"github.com/pokt-network/pocket/rpc" | ||
debugABP "github.com/pokt-network/pocket/p2p/providers/addrbook_provider/debug" | ||
debugCHP "github.com/pokt-network/pocket/p2p/providers/current_height_provider/debug" | ||
"github.com/pokt-network/pocket/runtime" | ||
"github.com/pokt-network/pocket/shared" | ||
coreTypes "github.com/pokt-network/pocket/shared/core/types" | ||
pocketCrypto "github.com/pokt-network/pocket/shared/crypto" | ||
"github.com/pokt-network/pocket/shared/messaging" | ||
"github.com/pokt-network/pocket/shared/modules" | ||
"github.com/pokt-network/pocket/telemetry" | ||
"github.com/spf13/cobra" | ||
"google.golang.org/protobuf/types/known/anypb" | ||
) | ||
|
@@ -39,17 +33,18 @@ var ( | |
// A P2P module is initialized in order to broadcast a message to the local network | ||
p2pMod modules.P2PModule | ||
|
||
// A consensus module is initialized in order to get a list of the validator network | ||
consensusMod modules.ConsensusModule | ||
modInitOnce sync.Once | ||
|
||
items = []string{ | ||
PromptResetToGenesis, | ||
PromptPrintNodeState, | ||
PromptTriggerNextView, | ||
PromptTogglePacemakerMode, | ||
PromptShowLatestBlockInStore, | ||
} | ||
|
||
// validators holds the list of the validators at genesis time so that we can use it to create a debug address book provider. | ||
// Its purpose is to allow the CLI to "discover" the nodes in the network. Since currently we don't have churn and we run nodes only in LocalNet, we can rely on the genesis state. | ||
// HACK(#416): This is a temporary solution that guarantees backward compatibility while we implement peer discovery | ||
validators []*coreTypes.Actor | ||
deblasis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
func init() { | ||
|
@@ -62,7 +57,30 @@ func NewDebugCommand() *cobra.Command { | |
Short: "Debug utility for rapid development", | ||
Args: cobra.ExactArgs(0), | ||
PersistentPreRun: func(cmd *cobra.Command, args []string) { | ||
initDebug(remoteCLIURL) | ||
var err error | ||
runtimeMgr := runtime.NewManagerFromFiles(defaultConfigPath, defaultGenesisPath, runtime.WithRandomPK()) | ||
|
||
// HACK(#416): this is a temporary solution that guarantees backward compatibility while we implement peer discovery. | ||
validators = runtimeMgr.GetGenesis().Validators | ||
|
||
debugAddressBookProvider := debugABP.NewDebugAddrBookProvider( | ||
runtimeMgr.GetConfig().P2P, | ||
debugABP.WithActorsByHeight( | ||
map[int64][]*coreTypes.Actor{ | ||
debugABP.ANY_HEIGHT: validators, | ||
}, | ||
), | ||
) | ||
|
||
debugCurrentHeightProvider := debugCHP.NewDebugCurrentHeightProvider(0) | ||
|
||
p2pM, err := p2p.CreateWithProviders(runtimeMgr, debugAddressBookProvider, debugCurrentHeightProvider) | ||
if err != nil { | ||
log.Fatalf("[ERROR] Failed to create p2p module: %v", err.Error()) | ||
} | ||
p2pMod = p2pM.(modules.P2PModule) | ||
|
||
p2pMod.Start() | ||
}, | ||
RunE: runDebug, | ||
} | ||
|
@@ -148,8 +166,8 @@ func broadcastDebugMessage(debugMsg *messaging.DebugMessage) { | |
// address book of the actual validator nodes, so `node1.consensus` never receives the message. | ||
// p2pMod.Broadcast(anyProto, messaging.PocketTopic_DEBUG_TOPIC) | ||
|
||
for _, val := range consensusMod.ValidatorMap() { | ||
addr, err := pocketCrypto.NewAddress(val.GetAddress()) | ||
for _, valAddr := range validators { | ||
addr, err := pocketCrypto.NewAddress(valAddr.GetAddress()) | ||
if err != nil { | ||
log.Fatalf("[ERROR] Failed to convert validator address into pocketCrypto.Address: %v", err) | ||
} | ||
|
@@ -165,58 +183,15 @@ func sendDebugMessage(debugMsg *messaging.DebugMessage) { | |
} | ||
|
||
var validatorAddress []byte | ||
for _, val := range consensusMod.ValidatorMap() { | ||
validatorAddress, err = pocketCrypto.NewAddress(val.GetAddress()) | ||
if err != nil { | ||
log.Fatalf("[ERROR] Failed to convert validator address into pocketCrypto.Address: %v", err) | ||
} | ||
break | ||
if len(validators) == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than throwing a fatal error on every debug message, let's do this and the point of initialization in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 I disagree, at some point, hopefully VERY soon, we'll have dynamic node set and we could (also for testing purposes) just don't have any addressable node to connect to when we send. I would keep the guard here so that whoever touches this code is aware of that eventuality at runtime. |
||
log.Fatalf("[ERROR] No validators found") | ||
} | ||
|
||
p2pMod.Send(validatorAddress, anyProto) | ||
} | ||
|
||
func initDebug(remoteCLIURL string) { | ||
modInitOnce.Do(func() { | ||
var err error | ||
runtimeMgr := runtime.NewManagerFromFiles(defaultConfigPath, defaultGenesisPath, runtime.WithRandomPK()) | ||
|
||
consM, err := consensus.Create(runtimeMgr) | ||
if err != nil { | ||
logger.Global.Fatal().Err(err).Msg("Failed to create consensus module") | ||
} | ||
consensusMod = consM.(modules.ConsensusModule) | ||
|
||
p2pM, err := p2p.Create(runtimeMgr) | ||
if err != nil { | ||
log.Fatalf("[ERROR] Failed to create p2p module: %v", err.Error()) | ||
} | ||
p2pMod = p2pM.(modules.P2PModule) | ||
|
||
// 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. | ||
telemetryM, err := telemetry.Create(runtimeMgr) | ||
if err != nil { | ||
logger.Global.Fatal().Err(err).Msg("Failed to create telemetry module") | ||
} | ||
telemetryMod := telemetryM.(modules.TelemetryModule) | ||
|
||
loggerM, err := logger.Create(runtimeMgr) | ||
if err != nil { | ||
logger.Global.Fatal().Err(err).Msg("Failed to create logger module") | ||
} | ||
loggerMod := loggerM.(modules.LoggerModule) | ||
|
||
rpcM, err := rpc.Create(runtimeMgr) | ||
if err != nil { | ||
logger.Global.Fatal().Err(err).Msg("Failed to create rpc module") | ||
} | ||
rpcMod := rpcM.(modules.RPCModule) | ||
|
||
_ = shared.CreateBusWithOptionalModules(runtimeMgr, nil, p2pMod, nil, consensusMod, telemetryMod, loggerMod, rpcMod) // REFACTOR: use the `WithXXXModule()` pattern accepting a slice of IntegratableModule | ||
// if the message needs to be broadcast, it'll be handled by the business logic of the message handler | ||
validatorAddress, err = pocketCrypto.NewAddress(validators[0].GetAddress()) | ||
deblasis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
log.Fatalf("[ERROR] Failed to convert validator address into pocketCrypto.Address: %v", err) | ||
} | ||
|
||
p2pMod.Start() | ||
}) | ||
p2pMod.Send(validatorAddress, anyProto) | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we just rename
POCKET_P2P_IS_CLIENT_ONLY
toCLIENT_DEBUG_MODE
to capture this, and potentially other needs in the future?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to leverage
viper
it has to start withPOCKET_P2P
so how aboutPOCKET_P2P_CLIENT_DEBUG_MODE
?Otherwise I can put it at the root of the config and be
POCKET_CLIENT_DEBUG_MODE
(probably better if we think it can be useful for other purposes, I can't think about anything else currentlyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tackled this in the other PR here d313d97 because the implementation was just easier there (due to the improvements to module initialization) and doing it here would have required some extra work that than I would have had to refactor anyway.