Conversation
The `node.NewNode` method is pretty complex at the moment, an in order to address issues like #3156, we need to simplify the interface for partial node instantiation. In some places, we don't need to build up a full node (like in the `node.TestCreateProposalBlock` test), but the complexity of such partial instantiation needs to be reduced. This PR aims to eventually make this easier/simpler.
|
What's left to do here? |
|
Ideally I wanted to find a way to better group the inner construction of the node to simplify it further (perhaps into higher-level constructs), but that's proven to be quite difficult. This might be the best I can do for now. |
node/node.go
Outdated
|
|
||
| func loadStateFromDBOrGenesisDoc(stateDB dbm.DB, genesisDocProvider GenesisDocProvider) (sm.State, *types.GenesisDoc, error) { | ||
| // Get genesis doc | ||
| // TODO: move to state package? |
There was a problem hiding this comment.
can we move this to state/store.go?
There was a problem hiding this comment.
We can. It does, however, involve moving the GenesisDocProvider-related code from node/node.go to state/store.go to prevent circular dependencies. This changes the Go API a bit. Do you think that'd be a problem?
Technically the genesis doc represents a form of state, so it would make sense to have it in the state package, right?
There was a problem hiding this comment.
Hmm.. will respond tomorrow
node/node.go
Outdated
|
|
||
| // If an address is provided, listen on the socket for a connection from an | ||
| // external signing process. | ||
| privValidator, err = optionallyCreateAndStartPrivValidator(config, privValidator, logger) |
There was a problem hiding this comment.
If we're going to use this optionally prefix, we should document the expected behavior. Like if the address is not provided, privValidator and err are both nil. Note this won't prevent developers from making a mistake where they would assume privValidator can't ever be nil later in the code.
There was a problem hiding this comment.
In the case when both are nil we just asking for unexpected panics. Better to encode this in an explicit error which the caller can react on.
Codecov Report
@@ Coverage Diff @@
## develop #3456 +/- ##
===========================================
- Coverage 64.29% 64.28% -0.01%
===========================================
Files 213 213
Lines 17447 17501 +54
===========================================
+ Hits 11217 11250 +33
- Misses 5308 5332 +24
+ Partials 922 919 -3
|
| // panics if failed to unmarshal bytes | ||
| func loadGenesisDoc(db dbm.DB) (*types.GenesisDoc, error) { | ||
| bytes := db.Get(genesisDocKey) | ||
| if len(bytes) == 0 { |
There was a problem hiding this comment.
| cmn.PanicCrisis(fmt.Sprintf("Failed to load genesis doc due to unmarshaling error: %v (bytes: %X)", err, bytes)) | |
| panic(fmt.Sprintf("Failed to load genesis doc due to unmarshaling error: %v (bytes: %X)", err, bytes)) |
There was a problem hiding this comment.
If we change this here, shouldn't we just replace it in the whole codebase and take out the deprecated functions altogether?
There was a problem hiding this comment.
I don't mind, but should probably be a separate PR
As per discussion over [here](#3456 (comment)), we need to remove these `PanicXXX` functions and eliminate our dependence on them. In this PR, each and every `PanicXXX` function call is replaced with a simple `panic` call.
* Remove deprecated PanicXXX functions from codebase As per discussion over [here](#3456 (comment)), we need to remove these `PanicXXX` functions and eliminate our dependence on them. In this PR, each and every `PanicXXX` function call is replaced with a simple `panic` call. * add a changelog entry
plus, expose PEXReactor on node
* Remove deprecated PanicXXX functions from codebase As per discussion over [here](tendermint#3456 (comment)), we need to remove these `PanicXXX` functions and eliminate our dependence on them. In this PR, each and every `PanicXXX` function call is replaced with a simple `panic` call. * add a changelog entry
The node.NewNode method is pretty complex at the moment, an in order to address issues like tendermint#3156, we need to simplify the interface for partial node instantiation. In some places, we don't need to build up a full node (like in the node.TestCreateProposalBlock test), but the complexity of such partial instantiation needs to be reduced. This PR aims to eventually make this easier/simpler. See also this gist https://gist.github.com/thanethomson/56e1640d057a26186e38ad678a1d114c for some background work done when starting to refactor here. ## Commits: * [WIP] Refactor node.NewNode to simplify The `node.NewNode` method is pretty complex at the moment, an in order to address issues like tendermint#3156, we need to simplify the interface for partial node instantiation. In some places, we don't need to build up a full node (like in the `node.TestCreateProposalBlock` test), but the complexity of such partial instantiation needs to be reduced. This PR aims to eventually make this easier/simpler. * Refactor state loading and genesis doc provider into state package * Refactor for clarity of return parameters * Fix incorrect capitalization of error messages * Simplify extracted functions' names * Document optionally-prefixed functions * Refactor optionallyFastSync for clarity of separation of concerns * Restructure function for early return * Restructure function for early return * Remove dependence on deprecated panic functions * refactor code a bit more plus, expose PEXReactor on node * align logger names * add a changelog entry * align logger names 2 * add a note about PEXReactor returning nil
…tendermint#3456) (tendermint#3461) Closes tendermint#3401 --- #### PR checklist - [x] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request tendermint#3456 done by [Mergify](https://mergify.com). --------- Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
The
node.NewNodemethod is pretty complex at the moment, an in order to address issues like #3156, we need to simplify the interface for partial node instantiation. In some places, we don't need to build up a full node (like in thenode.TestCreateProposalBlocktest), but the complexity of such partial instantiation needs to be reduced.This PR aims to eventually make this easier/simpler.
See also this gist for some background work done when starting to refactor here.