Skip to content

Refactor node.NewNode to simplify#3456

Merged
melekes merged 18 commits intodevelopfrom
refactor/new-node
Apr 26, 2019
Merged

Refactor node.NewNode to simplify#3456
melekes merged 18 commits intodevelopfrom
refactor/new-node

Conversation

@thanethomson
Copy link
Contributor

@thanethomson thanethomson commented Mar 20, 2019

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.

See also this gist for some background work done when starting to refactor here.

  • Updated all relevant documentation in docs
  • Updated all code comments where relevant
  • Wrote tests
  • Updated CHANGELOG_PENDING.md

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.
@thanethomson thanethomson self-assigned this Mar 20, 2019
@melekes
Copy link
Contributor

melekes commented Apr 18, 2019

What's left to do here?

@thanethomson
Copy link
Contributor Author

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.

@thanethomson thanethomson changed the title [WIP] Refactor node.NewNode to simplify Refactor node.NewNode to simplify Apr 19, 2019
node/node.go Outdated

func loadStateFromDBOrGenesisDoc(stateDB dbm.DB, genesisDocProvider GenesisDocProvider) (sm.State, *types.GenesisDoc, error) {
// Get genesis doc
// TODO: move to state package?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this to state/store.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor

@melekes melekes Apr 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-io
Copy link

codecov-io commented Apr 24, 2019

Codecov Report

Merging #3456 into develop will decrease coverage by <.01%.
The diff coverage is 58.22%.

@@             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
Impacted Files Coverage Δ
state/store.go 59.77% <0%> (-11.47%) ⬇️
node/node.go 64.07% <70.76%> (+0.19%) ⬆️
privval/signer_service_endpoint.go 83.63% <0%> (-5.46%) ⬇️
p2p/pex/pex_reactor.go 80.64% <0%> (-1.76%) ⬇️
libs/clist/clist.go 66.66% <0%> (-1.52%) ⬇️
blockchain/reactor.go 70.56% <0%> (-0.94%) ⬇️
libs/db/remotedb/grpcdb/server.go 0% <0%> (ø) ⬆️
consensus/state.go 79.05% <0%> (+0.11%) ⬆️
consensus/reactor.go 72.25% <0%> (+1.41%) ⬆️
privval/socket_listeners.go 96.55% <0%> (+10.34%) ⬆️
... and 1 more

// panics if failed to unmarshal bytes
func loadGenesisDoc(db dbm.DB) (*types.GenesisDoc, error) {
bytes := db.Get(genesisDocKey)
if len(bytes) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we change this here, shouldn't we just replace it in the whole codebase and take out the deprecated functions altogether?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind, but should probably be a separate PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #3595

thanethomson added a commit that referenced this pull request Apr 25, 2019
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.
Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥑

melekes pushed a commit that referenced this pull request Apr 26, 2019
* 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
@melekes melekes merged commit 7b162f5 into develop Apr 26, 2019
@melekes melekes deleted the refactor/new-node branch April 26, 2019 12:05
@melekes melekes mentioned this pull request May 7, 2019
36 tasks
@melekes melekes mentioned this pull request May 30, 2019
44 tasks
brapse pushed a commit to brapse/tendermint that referenced this pull request Jun 5, 2019
* 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
brapse pushed a commit to brapse/tendermint that referenced this pull request Jun 5, 2019
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
iKapitonau pushed a commit to scrtlabs/tendermint that referenced this pull request Sep 30, 2024
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants