You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1047 lines
32 KiB

node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
limit number of /subscribe clients and queries per client (#3269) * limit number of /subscribe clients and queries per client Add the following config variables (under [rpc] section): * max_subscription_clients * max_subscriptions_per_client * timeout_broadcast_tx_commit Fixes #2826 new HTTPClient interface for subscriptions finalize HTTPClient events interface remove EventSubscriber fix data race ``` WARNING: DATA RACE Read at 0x00c000a36060 by goroutine 129: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe.func1() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:168 +0x1f0 Previous write at 0x00c000a36060 by goroutine 132: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:191 +0x4e0 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 129 (running) created at: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:164 +0x4b7 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 132 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:119 +0x186 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ================== ``` lite client works (tested manually) godoc comments httpclient: do not close the out channel use TimeoutBroadcastTxCommit no timeout for unsubscribe but 1s Local (5s HTTP) timeout for resubscribe format code change Subscribe#out cap to 1 and replace config vars with RPCConfig TimeoutBroadcastTxCommit can't be greater than rpcserver.WriteTimeout rpc: Context as first parameter to all functions reformat code fixes after my own review fixes after Ethan's review add test stubs fix config.toml * fixes after manual testing - rpc: do not recommend to use BroadcastTxCommit because it's slow and wastes Tendermint resources (pubsub) - rpc: better error in Subscribe and BroadcastTxCommit - HTTPClient: do not resubscribe if err = ErrAlreadySubscribed * fixes after Ismail's review * Update rpc/grpc/grpc_test.go Co-Authored-By: melekes <anton.kalyaev@gmail.com>
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
max-bytes PR follow-up (#2318) * ReapMaxTxs: return all txs if max is negative this mirrors ReapMaxBytes behavior See https://github.com/tendermint/tendermint/pull/2184#discussion_r214439950 * increase MaxAminoOverheadForBlock tested with: ``` func TestMaxAminoOverheadForBlock(t *testing.T) { maxChainID := "" for i := 0; i < MaxChainIDLen; i++ { maxChainID += "𠜎" } h := Header{ ChainID: maxChainID, Height: 10, Time: time.Now().UTC(), NumTxs: 100, TotalTxs: 200, LastBlockID: makeBlockID(make([]byte, 20), 300, make([]byte, 20)), LastCommitHash: tmhash.Sum([]byte("last_commit_hash")), DataHash: tmhash.Sum([]byte("data_hash")), ValidatorsHash: tmhash.Sum([]byte("validators_hash")), NextValidatorsHash: tmhash.Sum([]byte("next_validators_hash")), ConsensusHash: tmhash.Sum([]byte("consensus_hash")), AppHash: tmhash.Sum([]byte("app_hash")), LastResultsHash: tmhash.Sum([]byte("last_results_hash")), EvidenceHash: tmhash.Sum([]byte("evidence_hash")), ProposerAddress: tmhash.Sum([]byte("proposer_address")), } b := Block{ Header: h, Data: Data{Txs: makeTxs(10000, 100)}, Evidence: EvidenceData{}, LastCommit: &Commit{}, } bz, err := cdc.MarshalBinary(b) require.NoError(t, err) assert.Equal(t, MaxHeaderBytes+MaxAminoOverheadForBlock-2, len(bz)-1000000-20000-1) } ``` * fix MaxYYY constants calculation by using math.MaxInt64 See https://github.com/tendermint/tendermint/pull/2184#discussion_r214444244 * pass mempool filter as an option See https://github.com/tendermint/tendermint/pull/2184#discussion_r214445869 * fixes after Dev's comments
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
limit number of /subscribe clients and queries per client (#3269) * limit number of /subscribe clients and queries per client Add the following config variables (under [rpc] section): * max_subscription_clients * max_subscriptions_per_client * timeout_broadcast_tx_commit Fixes #2826 new HTTPClient interface for subscriptions finalize HTTPClient events interface remove EventSubscriber fix data race ``` WARNING: DATA RACE Read at 0x00c000a36060 by goroutine 129: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe.func1() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:168 +0x1f0 Previous write at 0x00c000a36060 by goroutine 132: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:191 +0x4e0 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 129 (running) created at: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:164 +0x4b7 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 132 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:119 +0x186 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ================== ``` lite client works (tested manually) godoc comments httpclient: do not close the out channel use TimeoutBroadcastTxCommit no timeout for unsubscribe but 1s Local (5s HTTP) timeout for resubscribe format code change Subscribe#out cap to 1 and replace config vars with RPCConfig TimeoutBroadcastTxCommit can't be greater than rpcserver.WriteTimeout rpc: Context as first parameter to all functions reformat code fixes after my own review fixes after Ethan's review add test stubs fix config.toml * fixes after manual testing - rpc: do not recommend to use BroadcastTxCommit because it's slow and wastes Tendermint resources (pubsub) - rpc: better error in Subscribe and BroadcastTxCommit - HTTPClient: do not resubscribe if err = ErrAlreadySubscribed * fixes after Ismail's review * Update rpc/grpc/grpc_test.go Co-Authored-By: melekes <anton.kalyaev@gmail.com>
6 years ago
limit number of /subscribe clients and queries per client (#3269) * limit number of /subscribe clients and queries per client Add the following config variables (under [rpc] section): * max_subscription_clients * max_subscriptions_per_client * timeout_broadcast_tx_commit Fixes #2826 new HTTPClient interface for subscriptions finalize HTTPClient events interface remove EventSubscriber fix data race ``` WARNING: DATA RACE Read at 0x00c000a36060 by goroutine 129: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe.func1() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:168 +0x1f0 Previous write at 0x00c000a36060 by goroutine 132: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:191 +0x4e0 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 129 (running) created at: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:164 +0x4b7 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 132 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:119 +0x186 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ================== ``` lite client works (tested manually) godoc comments httpclient: do not close the out channel use TimeoutBroadcastTxCommit no timeout for unsubscribe but 1s Local (5s HTTP) timeout for resubscribe format code change Subscribe#out cap to 1 and replace config vars with RPCConfig TimeoutBroadcastTxCommit can't be greater than rpcserver.WriteTimeout rpc: Context as first parameter to all functions reformat code fixes after my own review fixes after Ethan's review add test stubs fix config.toml * fixes after manual testing - rpc: do not recommend to use BroadcastTxCommit because it's slow and wastes Tendermint resources (pubsub) - rpc: better error in Subscribe and BroadcastTxCommit - HTTPClient: do not resubscribe if err = ErrAlreadySubscribed * fixes after Ismail's review * Update rpc/grpc/grpc_test.go Co-Authored-By: melekes <anton.kalyaev@gmail.com>
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
Close and retry a RemoteSigner on err (#2923) * Close and recreate a RemoteSigner on err * Update changelog * Address Anton's comments / suggestions: - update changelog - restart TCPVal - shut down on `ErrUnexpectedResponse` * re-init remote signer client with fresh connection if Ping fails - add/update TODOs in secret connection - rename tcp.go -> tcp_client.go, same with ipc to clarify their purpose * account for `conn returned by waitConnection can be `nil` - also add TODO about RemoteSigner conn field * Tests for retrying: IPC / TCP - shorter info log on success - set conn and use it in tests to close conn * Tests for retrying: IPC / TCP - shorter info log on success - set conn and use it in tests to close conn - add rwmutex for conn field in IPC * comments and doc.go * fix ipc tests. fixes #2677 * use constants for tests * cleanup some error statements * fixes #2784, race in tests * remove print statement * minor fixes from review * update comment on sts spec * cosmetics * p2p/conn: add failing tests * p2p/conn: make SecretConnection thread safe * changelog * IPCVal signer refactor - use a .reset() method - don't use embedded RemoteSignerClient - guard RemoteSignerClient with mutex - drop the .conn - expose Close() on RemoteSignerClient * apply IPCVal refactor to TCPVal * remove mtx from RemoteSignerClient * consolidate IPCVal and TCPVal, fixes #3104 - done in tcp_client.go - now called SocketVal - takes a listener in the constructor - make tcpListener and unixListener contain all the differences * delete ipc files * introduce unix and tcp dialer for RemoteSigner * rename files - drop tcp_ prefix - rename priv_validator.go to file.go * bring back listener options * fix node * fix priv_val_server * fix node test * minor cleanup and comments
6 years ago
Close and retry a RemoteSigner on err (#2923) * Close and recreate a RemoteSigner on err * Update changelog * Address Anton's comments / suggestions: - update changelog - restart TCPVal - shut down on `ErrUnexpectedResponse` * re-init remote signer client with fresh connection if Ping fails - add/update TODOs in secret connection - rename tcp.go -> tcp_client.go, same with ipc to clarify their purpose * account for `conn returned by waitConnection can be `nil` - also add TODO about RemoteSigner conn field * Tests for retrying: IPC / TCP - shorter info log on success - set conn and use it in tests to close conn * Tests for retrying: IPC / TCP - shorter info log on success - set conn and use it in tests to close conn - add rwmutex for conn field in IPC * comments and doc.go * fix ipc tests. fixes #2677 * use constants for tests * cleanup some error statements * fixes #2784, race in tests * remove print statement * minor fixes from review * update comment on sts spec * cosmetics * p2p/conn: add failing tests * p2p/conn: make SecretConnection thread safe * changelog * IPCVal signer refactor - use a .reset() method - don't use embedded RemoteSignerClient - guard RemoteSignerClient with mutex - drop the .conn - expose Close() on RemoteSignerClient * apply IPCVal refactor to TCPVal * remove mtx from RemoteSignerClient * consolidate IPCVal and TCPVal, fixes #3104 - done in tcp_client.go - now called SocketVal - takes a listener in the constructor - make tcpListener and unixListener contain all the differences * delete ipc files * introduce unix and tcp dialer for RemoteSigner * rename files - drop tcp_ prefix - rename priv_validator.go to file.go * bring back listener options * fix node * fix priv_val_server * fix node test * minor cleanup and comments
6 years ago
Close and retry a RemoteSigner on err (#2923) * Close and recreate a RemoteSigner on err * Update changelog * Address Anton's comments / suggestions: - update changelog - restart TCPVal - shut down on `ErrUnexpectedResponse` * re-init remote signer client with fresh connection if Ping fails - add/update TODOs in secret connection - rename tcp.go -> tcp_client.go, same with ipc to clarify their purpose * account for `conn returned by waitConnection can be `nil` - also add TODO about RemoteSigner conn field * Tests for retrying: IPC / TCP - shorter info log on success - set conn and use it in tests to close conn * Tests for retrying: IPC / TCP - shorter info log on success - set conn and use it in tests to close conn - add rwmutex for conn field in IPC * comments and doc.go * fix ipc tests. fixes #2677 * use constants for tests * cleanup some error statements * fixes #2784, race in tests * remove print statement * minor fixes from review * update comment on sts spec * cosmetics * p2p/conn: add failing tests * p2p/conn: make SecretConnection thread safe * changelog * IPCVal signer refactor - use a .reset() method - don't use embedded RemoteSignerClient - guard RemoteSignerClient with mutex - drop the .conn - expose Close() on RemoteSignerClient * apply IPCVal refactor to TCPVal * remove mtx from RemoteSignerClient * consolidate IPCVal and TCPVal, fixes #3104 - done in tcp_client.go - now called SocketVal - takes a listener in the constructor - make tcpListener and unixListener contain all the differences * delete ipc files * introduce unix and tcp dialer for RemoteSigner * rename files - drop tcp_ prefix - rename priv_validator.go to file.go * bring back listener options * fix node * fix priv_val_server * fix node test * minor cleanup and comments
6 years ago
Close and retry a RemoteSigner on err (#2923) * Close and recreate a RemoteSigner on err * Update changelog * Address Anton's comments / suggestions: - update changelog - restart TCPVal - shut down on `ErrUnexpectedResponse` * re-init remote signer client with fresh connection if Ping fails - add/update TODOs in secret connection - rename tcp.go -> tcp_client.go, same with ipc to clarify their purpose * account for `conn returned by waitConnection can be `nil` - also add TODO about RemoteSigner conn field * Tests for retrying: IPC / TCP - shorter info log on success - set conn and use it in tests to close conn * Tests for retrying: IPC / TCP - shorter info log on success - set conn and use it in tests to close conn - add rwmutex for conn field in IPC * comments and doc.go * fix ipc tests. fixes #2677 * use constants for tests * cleanup some error statements * fixes #2784, race in tests * remove print statement * minor fixes from review * update comment on sts spec * cosmetics * p2p/conn: add failing tests * p2p/conn: make SecretConnection thread safe * changelog * IPCVal signer refactor - use a .reset() method - don't use embedded RemoteSignerClient - guard RemoteSignerClient with mutex - drop the .conn - expose Close() on RemoteSignerClient * apply IPCVal refactor to TCPVal * remove mtx from RemoteSignerClient * consolidate IPCVal and TCPVal, fixes #3104 - done in tcp_client.go - now called SocketVal - takes a listener in the constructor - make tcpListener and unixListener contain all the differences * delete ipc files * introduce unix and tcp dialer for RemoteSigner * rename files - drop tcp_ prefix - rename priv_validator.go to file.go * bring back listener options * fix node * fix priv_val_server * fix node test * minor cleanup and comments
6 years ago
node: refactor node.NewNode (#3456) 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 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 #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
6 years ago
privval: improve Remote Signer implementation (#3351) This issue is related to #3107 This is a first renaming/refactoring step before reworking and removing heartbeats. As discussed with @Liamsi , we preferred to go for a couple of independent and separate PRs to simplify review work. The changes: Help to clarify the relation between the validator and remote signer endpoints Differentiate between timeouts and deadlines Prepare to encapsulate networking related code behind RemoteSigner in the next PR My intention is to separate and encapsulate the "network related" code from the actual signer. SignerRemote ---(uses/contains)--> SignerValidatorEndpoint <--(connects to)--> SignerServiceEndpoint ---> SignerService (future.. not here yet but would like to decouple too) All reconnection/heartbeat/whatever code goes in the endpoints. Signer[Remote/Service] do not need to know about that. I agree Endpoint may not be the perfect name. I tried to find something "Go-ish" enough. It is a common name in go-kit, kubernetes, etc. Right now: SignerValidatorEndpoint: handles the listener contains SignerRemote Implements the PrivValidator interface connects and sets a connection object in a contained SignerRemote delegates PrivValidator some calls to SignerRemote which in turn uses the conn object that was set externally SignerRemote: Implements the PrivValidator interface read/writes from a connection object directly handles heartbeats SignerServiceEndpoint: Does most things in a single place delegates to a PrivValidator IIRC. * cleanup * Refactoring step 1 * Refactoring step 2 * move messages to another file * mark for future work / next steps * mark deprecated classes in docs * Fix linter problems * additional linter fixes
6 years ago
Close and retry a RemoteSigner on err (#2923) * Close and recreate a RemoteSigner on err * Update changelog * Address Anton's comments / suggestions: - update changelog - restart TCPVal - shut down on `ErrUnexpectedResponse` * re-init remote signer client with fresh connection if Ping fails - add/update TODOs in secret connection - rename tcp.go -> tcp_client.go, same with ipc to clarify their purpose * account for `conn returned by waitConnection can be `nil` - also add TODO about RemoteSigner conn field * Tests for retrying: IPC / TCP - shorter info log on success - set conn and use it in tests to close conn * Tests for retrying: IPC / TCP - shorter info log on success - set conn and use it in tests to close conn - add rwmutex for conn field in IPC * comments and doc.go * fix ipc tests. fixes #2677 * use constants for tests * cleanup some error statements * fixes #2784, race in tests * remove print statement * minor fixes from review * update comment on sts spec * cosmetics * p2p/conn: add failing tests * p2p/conn: make SecretConnection thread safe * changelog * IPCVal signer refactor - use a .reset() method - don't use embedded RemoteSignerClient - guard RemoteSignerClient with mutex - drop the .conn - expose Close() on RemoteSignerClient * apply IPCVal refactor to TCPVal * remove mtx from RemoteSignerClient * consolidate IPCVal and TCPVal, fixes #3104 - done in tcp_client.go - now called SocketVal - takes a listener in the constructor - make tcpListener and unixListener contain all the differences * delete ipc files * introduce unix and tcp dialer for RemoteSigner * rename files - drop tcp_ prefix - rename priv_validator.go to file.go * bring back listener options * fix node * fix priv_val_server * fix node test * minor cleanup and comments
6 years ago
  1. package node
  2. import (
  3. "bytes"
  4. "context"
  5. "fmt"
  6. "net"
  7. "net/http"
  8. _ "net/http/pprof"
  9. "os"
  10. "strings"
  11. "time"
  12. "github.com/pkg/errors"
  13. "github.com/prometheus/client_golang/prometheus"
  14. "github.com/prometheus/client_golang/prometheus/promhttp"
  15. "github.com/rs/cors"
  16. amino "github.com/tendermint/go-amino"
  17. abci "github.com/tendermint/tendermint/abci/types"
  18. "github.com/tendermint/tendermint/blockchain"
  19. bc "github.com/tendermint/tendermint/blockchain"
  20. cfg "github.com/tendermint/tendermint/config"
  21. "github.com/tendermint/tendermint/consensus"
  22. cs "github.com/tendermint/tendermint/consensus"
  23. "github.com/tendermint/tendermint/crypto/ed25519"
  24. "github.com/tendermint/tendermint/evidence"
  25. cmn "github.com/tendermint/tendermint/libs/common"
  26. dbm "github.com/tendermint/tendermint/libs/db"
  27. "github.com/tendermint/tendermint/libs/log"
  28. tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
  29. mempl "github.com/tendermint/tendermint/mempool"
  30. "github.com/tendermint/tendermint/p2p"
  31. "github.com/tendermint/tendermint/p2p/pex"
  32. "github.com/tendermint/tendermint/privval"
  33. "github.com/tendermint/tendermint/proxy"
  34. rpccore "github.com/tendermint/tendermint/rpc/core"
  35. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  36. grpccore "github.com/tendermint/tendermint/rpc/grpc"
  37. rpcserver "github.com/tendermint/tendermint/rpc/lib/server"
  38. sm "github.com/tendermint/tendermint/state"
  39. "github.com/tendermint/tendermint/state/txindex"
  40. "github.com/tendermint/tendermint/state/txindex/kv"
  41. "github.com/tendermint/tendermint/state/txindex/null"
  42. "github.com/tendermint/tendermint/types"
  43. tmtime "github.com/tendermint/tendermint/types/time"
  44. "github.com/tendermint/tendermint/version"
  45. )
  46. //------------------------------------------------------------------------------
  47. // DBContext specifies config information for loading a new DB.
  48. type DBContext struct {
  49. ID string
  50. Config *cfg.Config
  51. }
  52. // DBProvider takes a DBContext and returns an instantiated DB.
  53. type DBProvider func(*DBContext) (dbm.DB, error)
  54. // DefaultDBProvider returns a database using the DBBackend and DBDir
  55. // specified in the ctx.Config.
  56. func DefaultDBProvider(ctx *DBContext) (dbm.DB, error) {
  57. dbType := dbm.DBBackendType(ctx.Config.DBBackend)
  58. return dbm.NewDB(ctx.ID, dbType, ctx.Config.DBDir()), nil
  59. }
  60. // NodeProvider takes a config and a logger and returns a ready to go Node.
  61. type NodeProvider func(*cfg.Config, log.Logger) (*Node, error)
  62. // DefaultNewNode returns a Tendermint node with default settings for the
  63. // PrivValidator, ClientCreator, GenesisDoc, and DBProvider.
  64. // It implements NodeProvider.
  65. func DefaultNewNode(config *cfg.Config, logger log.Logger) (*Node, error) {
  66. // Generate node PrivKey
  67. nodeKey, err := p2p.LoadOrGenNodeKey(config.NodeKeyFile())
  68. if err != nil {
  69. return nil, err
  70. }
  71. // Convert old PrivValidator if it exists.
  72. oldPrivVal := config.OldPrivValidatorFile()
  73. newPrivValKey := config.PrivValidatorKeyFile()
  74. newPrivValState := config.PrivValidatorStateFile()
  75. if _, err := os.Stat(oldPrivVal); !os.IsNotExist(err) {
  76. oldPV, err := privval.LoadOldFilePV(oldPrivVal)
  77. if err != nil {
  78. return nil, fmt.Errorf("error reading OldPrivValidator from %v: %v\n", oldPrivVal, err)
  79. }
  80. logger.Info("Upgrading PrivValidator file",
  81. "old", oldPrivVal,
  82. "newKey", newPrivValKey,
  83. "newState", newPrivValState,
  84. )
  85. oldPV.Upgrade(newPrivValKey, newPrivValState)
  86. }
  87. return NewNode(config,
  88. privval.LoadOrGenFilePV(newPrivValKey, newPrivValState),
  89. nodeKey,
  90. proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
  91. sm.DefaultGenesisDocProviderFunc(config),
  92. DefaultDBProvider,
  93. DefaultMetricsProvider(config.Instrumentation),
  94. logger,
  95. )
  96. }
  97. // MetricsProvider returns a consensus, p2p and mempool Metrics.
  98. type MetricsProvider func(chainID string) (*cs.Metrics, *p2p.Metrics, *mempl.Metrics, *sm.Metrics)
  99. // DefaultMetricsProvider returns Metrics build using Prometheus client library
  100. // if Prometheus is enabled. Otherwise, it returns no-op Metrics.
  101. func DefaultMetricsProvider(config *cfg.InstrumentationConfig) MetricsProvider {
  102. return func(chainID string) (*cs.Metrics, *p2p.Metrics, *mempl.Metrics, *sm.Metrics) {
  103. if config.Prometheus {
  104. return cs.PrometheusMetrics(config.Namespace, "chain_id", chainID),
  105. p2p.PrometheusMetrics(config.Namespace, "chain_id", chainID),
  106. mempl.PrometheusMetrics(config.Namespace, "chain_id", chainID),
  107. sm.PrometheusMetrics(config.Namespace, "chain_id", chainID)
  108. }
  109. return cs.NopMetrics(), p2p.NopMetrics(), mempl.NopMetrics(), sm.NopMetrics()
  110. }
  111. }
  112. //------------------------------------------------------------------------------
  113. // Node is the highest level interface to a full Tendermint node.
  114. // It includes all configuration information and running services.
  115. type Node struct {
  116. cmn.BaseService
  117. // config
  118. config *cfg.Config
  119. genesisDoc *types.GenesisDoc // initial validator set
  120. privValidator types.PrivValidator // local node's validator key
  121. // network
  122. transport *p2p.MultiplexTransport
  123. sw *p2p.Switch // p2p connections
  124. addrBook pex.AddrBook // known peers
  125. nodeInfo p2p.NodeInfo
  126. nodeKey *p2p.NodeKey // our node privkey
  127. isListening bool
  128. // services
  129. eventBus *types.EventBus // pub/sub for services
  130. stateDB dbm.DB
  131. blockStore *bc.BlockStore // store the blockchain to disk
  132. bcReactor *bc.BlockchainReactor // for fast-syncing
  133. mempoolReactor *mempl.MempoolReactor // for gossipping transactions
  134. consensusState *cs.ConsensusState // latest consensus state
  135. consensusReactor *cs.ConsensusReactor // for participating in the consensus
  136. pexReactor *pex.PEXReactor // for exchanging peer addresses
  137. evidencePool *evidence.EvidencePool // tracking evidence
  138. proxyApp proxy.AppConns // connection to the application
  139. rpcListeners []net.Listener // rpc servers
  140. txIndexer txindex.TxIndexer
  141. indexerService *txindex.IndexerService
  142. prometheusSrv *http.Server
  143. }
  144. func initDBs(config *cfg.Config, dbProvider DBProvider) (blockStore *bc.BlockStore, stateDB dbm.DB, err error) {
  145. var blockStoreDB dbm.DB
  146. blockStoreDB, err = dbProvider(&DBContext{"blockstore", config})
  147. if err != nil {
  148. return
  149. }
  150. blockStore = bc.NewBlockStore(blockStoreDB)
  151. stateDB, err = dbProvider(&DBContext{"state", config})
  152. if err != nil {
  153. return
  154. }
  155. return
  156. }
  157. func createAndStartProxyAppConns(clientCreator proxy.ClientCreator, logger log.Logger) (proxy.AppConns, error) {
  158. proxyApp := proxy.NewAppConns(clientCreator)
  159. proxyApp.SetLogger(logger.With("module", "proxy"))
  160. if err := proxyApp.Start(); err != nil {
  161. return nil, fmt.Errorf("error starting proxy app connections: %v", err)
  162. }
  163. return proxyApp, nil
  164. }
  165. func createAndStartEventBus(logger log.Logger) (*types.EventBus, error) {
  166. eventBus := types.NewEventBus()
  167. eventBus.SetLogger(logger.With("module", "events"))
  168. if err := eventBus.Start(); err != nil {
  169. return nil, err
  170. }
  171. return eventBus, nil
  172. }
  173. func createAndStartIndexerService(config *cfg.Config, dbProvider DBProvider,
  174. eventBus *types.EventBus, logger log.Logger) (*txindex.IndexerService, txindex.TxIndexer, error) {
  175. var txIndexer txindex.TxIndexer
  176. switch config.TxIndex.Indexer {
  177. case "kv":
  178. store, err := dbProvider(&DBContext{"tx_index", config})
  179. if err != nil {
  180. return nil, nil, err
  181. }
  182. if config.TxIndex.IndexTags != "" {
  183. txIndexer = kv.NewTxIndex(store, kv.IndexTags(splitAndTrimEmpty(config.TxIndex.IndexTags, ",", " ")))
  184. } else if config.TxIndex.IndexAllTags {
  185. txIndexer = kv.NewTxIndex(store, kv.IndexAllTags())
  186. } else {
  187. txIndexer = kv.NewTxIndex(store)
  188. }
  189. default:
  190. txIndexer = &null.TxIndex{}
  191. }
  192. indexerService := txindex.NewIndexerService(txIndexer, eventBus)
  193. indexerService.SetLogger(logger.With("module", "txindex"))
  194. if err := indexerService.Start(); err != nil {
  195. return nil, nil, err
  196. }
  197. return indexerService, txIndexer, nil
  198. }
  199. func doHandshake(stateDB dbm.DB, state sm.State, blockStore sm.BlockStore,
  200. genDoc *types.GenesisDoc, eventBus *types.EventBus, proxyApp proxy.AppConns, consensusLogger log.Logger) error {
  201. handshaker := cs.NewHandshaker(stateDB, state, blockStore, genDoc)
  202. handshaker.SetLogger(consensusLogger)
  203. handshaker.SetEventBus(eventBus)
  204. if err := handshaker.Handshake(proxyApp); err != nil {
  205. return fmt.Errorf("error during handshake: %v", err)
  206. }
  207. return nil
  208. }
  209. func logNodeStartupInfo(state sm.State, privValidator types.PrivValidator, logger,
  210. consensusLogger log.Logger) {
  211. // Log the version info.
  212. logger.Info("Version info",
  213. "software", version.TMCoreSemVer,
  214. "block", version.BlockProtocol,
  215. "p2p", version.P2PProtocol,
  216. )
  217. // If the state and software differ in block version, at least log it.
  218. if state.Version.Consensus.Block != version.BlockProtocol {
  219. logger.Info("Software and state have different block protocols",
  220. "software", version.BlockProtocol,
  221. "state", state.Version.Consensus.Block,
  222. )
  223. }
  224. pubKey := privValidator.GetPubKey()
  225. addr := pubKey.Address()
  226. // Log whether this node is a validator or an observer
  227. if state.Validators.HasAddress(addr) {
  228. consensusLogger.Info("This node is a validator", "addr", addr, "pubKey", pubKey)
  229. } else {
  230. consensusLogger.Info("This node is not a validator", "addr", addr, "pubKey", pubKey)
  231. }
  232. }
  233. func onlyValidatorIsUs(state sm.State, privVal types.PrivValidator) bool {
  234. if state.Validators.Size() > 1 {
  235. return false
  236. }
  237. addr, _ := state.Validators.GetByIndex(0)
  238. return bytes.Equal(privVal.GetPubKey().Address(), addr)
  239. }
  240. func createMempoolAndMempoolReactor(config *cfg.Config, proxyApp proxy.AppConns,
  241. state sm.State, memplMetrics *mempl.Metrics, logger log.Logger) (*mempl.MempoolReactor, *mempl.Mempool) {
  242. mempool := mempl.NewMempool(
  243. config.Mempool,
  244. proxyApp.Mempool(),
  245. state.LastBlockHeight,
  246. mempl.WithMetrics(memplMetrics),
  247. mempl.WithPreCheck(sm.TxPreCheck(state)),
  248. mempl.WithPostCheck(sm.TxPostCheck(state)),
  249. )
  250. mempoolLogger := logger.With("module", "mempool")
  251. mempool.SetLogger(mempoolLogger)
  252. if config.Mempool.WalEnabled() {
  253. mempool.InitWAL() // no need to have the mempool wal during tests
  254. }
  255. mempoolReactor := mempl.NewMempoolReactor(config.Mempool, mempool)
  256. mempoolReactor.SetLogger(mempoolLogger)
  257. if config.Consensus.WaitForTxs() {
  258. mempool.EnableTxsAvailable()
  259. }
  260. return mempoolReactor, mempool
  261. }
  262. func createEvidenceReactor(config *cfg.Config, dbProvider DBProvider,
  263. stateDB dbm.DB, logger log.Logger) (*evidence.EvidenceReactor, *evidence.EvidencePool, error) {
  264. evidenceDB, err := dbProvider(&DBContext{"evidence", config})
  265. if err != nil {
  266. return nil, nil, err
  267. }
  268. evidenceLogger := logger.With("module", "evidence")
  269. evidencePool := evidence.NewEvidencePool(stateDB, evidenceDB)
  270. evidencePool.SetLogger(evidenceLogger)
  271. evidenceReactor := evidence.NewEvidenceReactor(evidencePool)
  272. evidenceReactor.SetLogger(evidenceLogger)
  273. return evidenceReactor, evidencePool, nil
  274. }
  275. func createConsensusReactor(config *cfg.Config,
  276. state sm.State,
  277. blockExec *sm.BlockExecutor,
  278. blockStore sm.BlockStore,
  279. mempool *mempl.Mempool,
  280. evidencePool *evidence.EvidencePool,
  281. privValidator types.PrivValidator,
  282. csMetrics *cs.Metrics,
  283. fastSync bool,
  284. eventBus *types.EventBus,
  285. consensusLogger log.Logger) (*consensus.ConsensusReactor, *consensus.ConsensusState) {
  286. consensusState := cs.NewConsensusState(
  287. config.Consensus,
  288. state.Copy(),
  289. blockExec,
  290. blockStore,
  291. mempool,
  292. evidencePool,
  293. cs.StateMetrics(csMetrics),
  294. )
  295. consensusState.SetLogger(consensusLogger)
  296. if privValidator != nil {
  297. consensusState.SetPrivValidator(privValidator)
  298. }
  299. consensusReactor := cs.NewConsensusReactor(consensusState, fastSync, cs.ReactorMetrics(csMetrics))
  300. consensusReactor.SetLogger(consensusLogger)
  301. // services which will be publishing and/or subscribing for messages (events)
  302. // consensusReactor will set it on consensusState and blockExecutor
  303. consensusReactor.SetEventBus(eventBus)
  304. return consensusReactor, consensusState
  305. }
  306. func createTransport(config *cfg.Config, nodeInfo p2p.NodeInfo, nodeKey *p2p.NodeKey, proxyApp proxy.AppConns) (*p2p.MultiplexTransport, []p2p.PeerFilterFunc) {
  307. var (
  308. mConnConfig = p2p.MConnConfig(config.P2P)
  309. transport = p2p.NewMultiplexTransport(nodeInfo, *nodeKey, mConnConfig)
  310. connFilters = []p2p.ConnFilterFunc{}
  311. peerFilters = []p2p.PeerFilterFunc{}
  312. )
  313. if !config.P2P.AllowDuplicateIP {
  314. connFilters = append(connFilters, p2p.ConnDuplicateIPFilter())
  315. }
  316. // Filter peers by addr or pubkey with an ABCI query.
  317. // If the query return code is OK, add peer.
  318. if config.FilterPeers {
  319. connFilters = append(
  320. connFilters,
  321. // ABCI query for address filtering.
  322. func(_ p2p.ConnSet, c net.Conn, _ []net.IP) error {
  323. res, err := proxyApp.Query().QuerySync(abci.RequestQuery{
  324. Path: fmt.Sprintf("/p2p/filter/addr/%s", c.RemoteAddr().String()),
  325. })
  326. if err != nil {
  327. return err
  328. }
  329. if res.IsErr() {
  330. return fmt.Errorf("error querying abci app: %v", res)
  331. }
  332. return nil
  333. },
  334. )
  335. peerFilters = append(
  336. peerFilters,
  337. // ABCI query for ID filtering.
  338. func(_ p2p.IPeerSet, p p2p.Peer) error {
  339. res, err := proxyApp.Query().QuerySync(abci.RequestQuery{
  340. Path: fmt.Sprintf("/p2p/filter/id/%s", p.ID()),
  341. })
  342. if err != nil {
  343. return err
  344. }
  345. if res.IsErr() {
  346. return fmt.Errorf("error querying abci app: %v", res)
  347. }
  348. return nil
  349. },
  350. )
  351. }
  352. p2p.MultiplexTransportConnFilters(connFilters...)(transport)
  353. return transport, peerFilters
  354. }
  355. func createSwitch(config *cfg.Config,
  356. transport *p2p.MultiplexTransport,
  357. p2pMetrics *p2p.Metrics,
  358. peerFilters []p2p.PeerFilterFunc,
  359. mempoolReactor *mempl.MempoolReactor,
  360. bcReactor *blockchain.BlockchainReactor,
  361. consensusReactor *consensus.ConsensusReactor,
  362. evidenceReactor *evidence.EvidenceReactor,
  363. nodeInfo p2p.NodeInfo,
  364. nodeKey *p2p.NodeKey,
  365. p2pLogger log.Logger) *p2p.Switch {
  366. sw := p2p.NewSwitch(
  367. config.P2P,
  368. transport,
  369. p2p.WithMetrics(p2pMetrics),
  370. p2p.SwitchPeerFilters(peerFilters...),
  371. )
  372. sw.SetLogger(p2pLogger)
  373. sw.AddReactor("MEMPOOL", mempoolReactor)
  374. sw.AddReactor("BLOCKCHAIN", bcReactor)
  375. sw.AddReactor("CONSENSUS", consensusReactor)
  376. sw.AddReactor("EVIDENCE", evidenceReactor)
  377. sw.SetNodeInfo(nodeInfo)
  378. sw.SetNodeKey(nodeKey)
  379. p2pLogger.Info("P2P Node ID", "ID", nodeKey.ID(), "file", config.NodeKeyFile())
  380. return sw
  381. }
  382. func createAddrBookAndSetOnSwitch(config *cfg.Config, sw *p2p.Switch,
  383. p2pLogger log.Logger) pex.AddrBook {
  384. addrBook := pex.NewAddrBook(config.P2P.AddrBookFile(), config.P2P.AddrBookStrict)
  385. addrBook.SetLogger(p2pLogger.With("book", config.P2P.AddrBookFile()))
  386. // Add ourselves to addrbook to prevent dialing ourselves
  387. addrBook.AddOurAddress(sw.NetAddress())
  388. sw.SetAddrBook(addrBook)
  389. return addrBook
  390. }
  391. func createPEXReactorAndAddToSwitch(addrBook pex.AddrBook, config *cfg.Config,
  392. sw *p2p.Switch, logger log.Logger) *pex.PEXReactor {
  393. // TODO persistent peers ? so we can have their DNS addrs saved
  394. pexReactor := pex.NewPEXReactor(addrBook,
  395. &pex.PEXReactorConfig{
  396. Seeds: splitAndTrimEmpty(config.P2P.Seeds, ",", " "),
  397. SeedMode: config.P2P.SeedMode,
  398. // See consensus/reactor.go: blocksToContributeToBecomeGoodPeer 10000
  399. // blocks assuming 10s blocks ~ 28 hours.
  400. // TODO (melekes): make it dynamic based on the actual block latencies
  401. // from the live network.
  402. // https://github.com/tendermint/tendermint/issues/3523
  403. SeedDisconnectWaitPeriod: 28 * time.Hour,
  404. })
  405. pexReactor.SetLogger(logger.With("module", "pex"))
  406. sw.AddReactor("PEX", pexReactor)
  407. return pexReactor
  408. }
  409. // NewNode returns a new, ready to go, Tendermint Node.
  410. func NewNode(config *cfg.Config,
  411. privValidator types.PrivValidator,
  412. nodeKey *p2p.NodeKey,
  413. clientCreator proxy.ClientCreator,
  414. genesisDocProvider sm.GenesisDocProvider,
  415. dbProvider DBProvider,
  416. metricsProvider MetricsProvider,
  417. logger log.Logger) (*Node, error) {
  418. blockStore, stateDB, err := initDBs(config, dbProvider)
  419. if err != nil {
  420. return nil, err
  421. }
  422. state, genDoc, err := sm.LoadStateFromDBOrGenesisDocProvider(stateDB, genesisDocProvider)
  423. if err != nil {
  424. return nil, err
  425. }
  426. // Create the proxyApp and establish connections to the ABCI app (consensus, mempool, query).
  427. proxyApp, err := createAndStartProxyAppConns(clientCreator, logger)
  428. if err != nil {
  429. return nil, err
  430. }
  431. // EventBus and IndexerService must be started before the handshake because
  432. // we might need to index the txs of the replayed block as this might not have happened
  433. // when the node stopped last time (i.e. the node stopped after it saved the block
  434. // but before it indexed the txs, or, endblocker panicked)
  435. eventBus, err := createAndStartEventBus(logger)
  436. if err != nil {
  437. return nil, err
  438. }
  439. // Transaction indexing
  440. indexerService, txIndexer, err := createAndStartIndexerService(config, dbProvider, eventBus, logger)
  441. if err != nil {
  442. return nil, err
  443. }
  444. // Create the handshaker, which calls RequestInfo, sets the AppVersion on the state,
  445. // and replays any blocks as necessary to sync tendermint with the app.
  446. consensusLogger := logger.With("module", "consensus")
  447. if err := doHandshake(stateDB, state, blockStore, genDoc, eventBus, proxyApp, consensusLogger); err != nil {
  448. return nil, err
  449. }
  450. // Reload the state. It will have the Version.Consensus.App set by the
  451. // Handshake, and may have other modifications as well (ie. depending on
  452. // what happened during block replay).
  453. state = sm.LoadState(stateDB)
  454. // If an address is provided, listen on the socket for a connection from an
  455. // external signing process.
  456. if config.PrivValidatorListenAddr != "" {
  457. // FIXME: we should start services inside OnStart
  458. privValidator, err = createAndStartPrivValidatorSocketClient(config.PrivValidatorListenAddr, logger)
  459. if err != nil {
  460. return nil, errors.Wrap(err, "error with private validator socket client")
  461. }
  462. }
  463. logNodeStartupInfo(state, privValidator, logger, consensusLogger)
  464. // Decide whether to fast-sync or not
  465. // We don't fast-sync when the only validator is us.
  466. fastSync := config.FastSync && !onlyValidatorIsUs(state, privValidator)
  467. csMetrics, p2pMetrics, memplMetrics, smMetrics := metricsProvider(genDoc.ChainID)
  468. // Make MempoolReactor
  469. mempoolReactor, mempool := createMempoolAndMempoolReactor(config, proxyApp, state, memplMetrics, logger)
  470. // Make Evidence Reactor
  471. evidenceReactor, evidencePool, err := createEvidenceReactor(config, dbProvider, stateDB, logger)
  472. if err != nil {
  473. return nil, err
  474. }
  475. // make block executor for consensus and blockchain reactors to execute blocks
  476. blockExec := sm.NewBlockExecutor(
  477. stateDB,
  478. logger.With("module", "state"),
  479. proxyApp.Consensus(),
  480. mempool,
  481. evidencePool,
  482. sm.BlockExecutorWithMetrics(smMetrics),
  483. )
  484. // Make BlockchainReactor
  485. bcReactor := bc.NewBlockchainReactor(state.Copy(), blockExec, blockStore, fastSync)
  486. bcReactor.SetLogger(logger.With("module", "blockchain"))
  487. // Make ConsensusReactor
  488. consensusReactor, consensusState := createConsensusReactor(
  489. config, state, blockExec, blockStore, mempool, evidencePool,
  490. privValidator, csMetrics, fastSync, eventBus, consensusLogger,
  491. )
  492. nodeInfo, err := makeNodeInfo(config, nodeKey, txIndexer, genDoc, state)
  493. if err != nil {
  494. return nil, err
  495. }
  496. // Setup Transport.
  497. transport, peerFilters := createTransport(config, nodeInfo, nodeKey, proxyApp)
  498. // Setup Switch.
  499. p2pLogger := logger.With("module", "p2p")
  500. sw := createSwitch(
  501. config, transport, p2pMetrics, peerFilters, mempoolReactor, bcReactor,
  502. consensusReactor, evidenceReactor, nodeInfo, nodeKey, p2pLogger,
  503. )
  504. addrBook := createAddrBookAndSetOnSwitch(config, sw, p2pLogger)
  505. // Optionally, start the pex reactor
  506. //
  507. // TODO:
  508. //
  509. // We need to set Seeds and PersistentPeers on the switch,
  510. // since it needs to be able to use these (and their DNS names)
  511. // even if the PEX is off. We can include the DNS name in the NetAddress,
  512. // but it would still be nice to have a clear list of the current "PersistentPeers"
  513. // somewhere that we can return with net_info.
  514. //
  515. // If PEX is on, it should handle dialing the seeds. Otherwise the switch does it.
  516. // Note we currently use the addrBook regardless at least for AddOurAddress
  517. var pexReactor *pex.PEXReactor
  518. if config.P2P.PexReactor {
  519. pexReactor = createPEXReactorAndAddToSwitch(addrBook, config, sw, logger)
  520. }
  521. if config.ProfListenAddress != "" {
  522. go logger.Error("Profile server", "err", http.ListenAndServe(config.ProfListenAddress, nil))
  523. }
  524. node := &Node{
  525. config: config,
  526. genesisDoc: genDoc,
  527. privValidator: privValidator,
  528. transport: transport,
  529. sw: sw,
  530. addrBook: addrBook,
  531. nodeInfo: nodeInfo,
  532. nodeKey: nodeKey,
  533. stateDB: stateDB,
  534. blockStore: blockStore,
  535. bcReactor: bcReactor,
  536. mempoolReactor: mempoolReactor,
  537. consensusState: consensusState,
  538. consensusReactor: consensusReactor,
  539. pexReactor: pexReactor,
  540. evidencePool: evidencePool,
  541. proxyApp: proxyApp,
  542. txIndexer: txIndexer,
  543. indexerService: indexerService,
  544. eventBus: eventBus,
  545. }
  546. node.BaseService = *cmn.NewBaseService(logger, "Node", node)
  547. return node, nil
  548. }
  549. // OnStart starts the Node. It implements cmn.Service.
  550. func (n *Node) OnStart() error {
  551. now := tmtime.Now()
  552. genTime := n.genesisDoc.GenesisTime
  553. if genTime.After(now) {
  554. n.Logger.Info("Genesis time is in the future. Sleeping until then...", "genTime", genTime)
  555. time.Sleep(genTime.Sub(now))
  556. }
  557. // Add private IDs to addrbook to block those peers being added
  558. n.addrBook.AddPrivateIDs(splitAndTrimEmpty(n.config.P2P.PrivatePeerIDs, ",", " "))
  559. // Start the RPC server before the P2P server
  560. // so we can eg. receive txs for the first block
  561. if n.config.RPC.ListenAddress != "" {
  562. listeners, err := n.startRPC()
  563. if err != nil {
  564. return err
  565. }
  566. n.rpcListeners = listeners
  567. }
  568. if n.config.Instrumentation.Prometheus &&
  569. n.config.Instrumentation.PrometheusListenAddr != "" {
  570. n.prometheusSrv = n.startPrometheusServer(n.config.Instrumentation.PrometheusListenAddr)
  571. }
  572. // Start the transport.
  573. addr, err := p2p.NewNetAddressStringWithOptionalID(n.config.P2P.ListenAddress)
  574. if err != nil {
  575. return err
  576. }
  577. if err := n.transport.Listen(*addr); err != nil {
  578. return err
  579. }
  580. n.isListening = true
  581. // Start the switch (the P2P server).
  582. err = n.sw.Start()
  583. if err != nil {
  584. return err
  585. }
  586. // Always connect to persistent peers
  587. if n.config.P2P.PersistentPeers != "" {
  588. err = n.sw.DialPeersAsync(n.addrBook, splitAndTrimEmpty(n.config.P2P.PersistentPeers, ",", " "), true)
  589. if err != nil {
  590. return err
  591. }
  592. }
  593. return nil
  594. }
  595. // OnStop stops the Node. It implements cmn.Service.
  596. func (n *Node) OnStop() {
  597. n.BaseService.OnStop()
  598. n.Logger.Info("Stopping Node")
  599. // first stop the non-reactor services
  600. n.eventBus.Stop()
  601. n.indexerService.Stop()
  602. // now stop the reactors
  603. // TODO: gracefully disconnect from peers.
  604. n.sw.Stop()
  605. // stop mempool WAL
  606. if n.config.Mempool.WalEnabled() {
  607. n.mempoolReactor.Mempool.CloseWAL()
  608. }
  609. if err := n.transport.Close(); err != nil {
  610. n.Logger.Error("Error closing transport", "err", err)
  611. }
  612. n.isListening = false
  613. // finally stop the listeners / external services
  614. for _, l := range n.rpcListeners {
  615. n.Logger.Info("Closing rpc listener", "listener", l)
  616. if err := l.Close(); err != nil {
  617. n.Logger.Error("Error closing listener", "listener", l, "err", err)
  618. }
  619. }
  620. if pvsc, ok := n.privValidator.(cmn.Service); ok {
  621. pvsc.Stop()
  622. }
  623. if n.prometheusSrv != nil {
  624. if err := n.prometheusSrv.Shutdown(context.Background()); err != nil {
  625. // Error from closing listeners, or context timeout:
  626. n.Logger.Error("Prometheus HTTP server Shutdown", "err", err)
  627. }
  628. }
  629. }
  630. // ConfigureRPC sets all variables in rpccore so they will serve
  631. // rpc calls from this node
  632. func (n *Node) ConfigureRPC() {
  633. rpccore.SetStateDB(n.stateDB)
  634. rpccore.SetBlockStore(n.blockStore)
  635. rpccore.SetConsensusState(n.consensusState)
  636. rpccore.SetMempool(n.mempoolReactor.Mempool)
  637. rpccore.SetEvidencePool(n.evidencePool)
  638. rpccore.SetP2PPeers(n.sw)
  639. rpccore.SetP2PTransport(n)
  640. pubKey := n.privValidator.GetPubKey()
  641. rpccore.SetPubKey(pubKey)
  642. rpccore.SetGenesisDoc(n.genesisDoc)
  643. rpccore.SetAddrBook(n.addrBook)
  644. rpccore.SetProxyAppQuery(n.proxyApp.Query())
  645. rpccore.SetTxIndexer(n.txIndexer)
  646. rpccore.SetConsensusReactor(n.consensusReactor)
  647. rpccore.SetEventBus(n.eventBus)
  648. rpccore.SetLogger(n.Logger.With("module", "rpc"))
  649. rpccore.SetConfig(*n.config.RPC)
  650. }
  651. func (n *Node) startRPC() ([]net.Listener, error) {
  652. n.ConfigureRPC()
  653. listenAddrs := splitAndTrimEmpty(n.config.RPC.ListenAddress, ",", " ")
  654. coreCodec := amino.NewCodec()
  655. ctypes.RegisterAmino(coreCodec)
  656. if n.config.RPC.Unsafe {
  657. rpccore.AddUnsafeRoutes()
  658. }
  659. // we may expose the rpc over both a unix and tcp socket
  660. listeners := make([]net.Listener, len(listenAddrs))
  661. for i, listenAddr := range listenAddrs {
  662. mux := http.NewServeMux()
  663. rpcLogger := n.Logger.With("module", "rpc-server")
  664. wmLogger := rpcLogger.With("protocol", "websocket")
  665. wm := rpcserver.NewWebsocketManager(rpccore.Routes, coreCodec,
  666. rpcserver.OnDisconnect(func(remoteAddr string) {
  667. err := n.eventBus.UnsubscribeAll(context.Background(), remoteAddr)
  668. if err != nil && err != tmpubsub.ErrSubscriptionNotFound {
  669. wmLogger.Error("Failed to unsubscribe addr from events", "addr", remoteAddr, "err", err)
  670. }
  671. }))
  672. wm.SetLogger(wmLogger)
  673. mux.HandleFunc("/websocket", wm.WebsocketHandler)
  674. rpcserver.RegisterRPCFuncs(mux, rpccore.Routes, coreCodec, rpcLogger)
  675. config := rpcserver.DefaultConfig()
  676. config.MaxOpenConnections = n.config.RPC.MaxOpenConnections
  677. // If necessary adjust global WriteTimeout to ensure it's greater than
  678. // TimeoutBroadcastTxCommit.
  679. // See https://github.com/tendermint/tendermint/issues/3435
  680. if config.WriteTimeout <= n.config.RPC.TimeoutBroadcastTxCommit {
  681. config.WriteTimeout = n.config.RPC.TimeoutBroadcastTxCommit + 1*time.Second
  682. }
  683. listener, err := rpcserver.Listen(
  684. listenAddr,
  685. config,
  686. )
  687. if err != nil {
  688. return nil, err
  689. }
  690. var rootHandler http.Handler = mux
  691. if n.config.RPC.IsCorsEnabled() {
  692. corsMiddleware := cors.New(cors.Options{
  693. AllowedOrigins: n.config.RPC.CORSAllowedOrigins,
  694. AllowedMethods: n.config.RPC.CORSAllowedMethods,
  695. AllowedHeaders: n.config.RPC.CORSAllowedHeaders,
  696. })
  697. rootHandler = corsMiddleware.Handler(mux)
  698. }
  699. if n.config.RPC.IsTLSEnabled() {
  700. go rpcserver.StartHTTPAndTLSServer(
  701. listener,
  702. rootHandler,
  703. n.config.RPC.CertFile(),
  704. n.config.RPC.KeyFile(),
  705. rpcLogger,
  706. config,
  707. )
  708. } else {
  709. go rpcserver.StartHTTPServer(
  710. listener,
  711. rootHandler,
  712. rpcLogger,
  713. config,
  714. )
  715. }
  716. listeners[i] = listener
  717. }
  718. // we expose a simplified api over grpc for convenience to app devs
  719. grpcListenAddr := n.config.RPC.GRPCListenAddress
  720. if grpcListenAddr != "" {
  721. config := rpcserver.DefaultConfig()
  722. config.MaxOpenConnections = n.config.RPC.MaxOpenConnections
  723. listener, err := rpcserver.Listen(grpcListenAddr, config)
  724. if err != nil {
  725. return nil, err
  726. }
  727. go grpccore.StartGRPCServer(listener)
  728. listeners = append(listeners, listener)
  729. }
  730. return listeners, nil
  731. }
  732. // startPrometheusServer starts a Prometheus HTTP server, listening for metrics
  733. // collectors on addr.
  734. func (n *Node) startPrometheusServer(addr string) *http.Server {
  735. srv := &http.Server{
  736. Addr: addr,
  737. Handler: promhttp.InstrumentMetricHandler(
  738. prometheus.DefaultRegisterer, promhttp.HandlerFor(
  739. prometheus.DefaultGatherer,
  740. promhttp.HandlerOpts{MaxRequestsInFlight: n.config.Instrumentation.MaxOpenConnections},
  741. ),
  742. ),
  743. }
  744. go func() {
  745. if err := srv.ListenAndServe(); err != http.ErrServerClosed {
  746. // Error starting or closing listener:
  747. n.Logger.Error("Prometheus HTTP server ListenAndServe", "err", err)
  748. }
  749. }()
  750. return srv
  751. }
  752. // Switch returns the Node's Switch.
  753. func (n *Node) Switch() *p2p.Switch {
  754. return n.sw
  755. }
  756. // BlockStore returns the Node's BlockStore.
  757. func (n *Node) BlockStore() *bc.BlockStore {
  758. return n.blockStore
  759. }
  760. // ConsensusState returns the Node's ConsensusState.
  761. func (n *Node) ConsensusState() *cs.ConsensusState {
  762. return n.consensusState
  763. }
  764. // ConsensusReactor returns the Node's ConsensusReactor.
  765. func (n *Node) ConsensusReactor() *cs.ConsensusReactor {
  766. return n.consensusReactor
  767. }
  768. // MempoolReactor returns the Node's MempoolReactor.
  769. func (n *Node) MempoolReactor() *mempl.MempoolReactor {
  770. return n.mempoolReactor
  771. }
  772. // PEXReactor returns the Node's PEXReactor. It returns nil if PEX is disabled.
  773. func (n *Node) PEXReactor() *pex.PEXReactor {
  774. return n.pexReactor
  775. }
  776. // EvidencePool returns the Node's EvidencePool.
  777. func (n *Node) EvidencePool() *evidence.EvidencePool {
  778. return n.evidencePool
  779. }
  780. // EventBus returns the Node's EventBus.
  781. func (n *Node) EventBus() *types.EventBus {
  782. return n.eventBus
  783. }
  784. // PrivValidator returns the Node's PrivValidator.
  785. // XXX: for convenience only!
  786. func (n *Node) PrivValidator() types.PrivValidator {
  787. return n.privValidator
  788. }
  789. // GenesisDoc returns the Node's GenesisDoc.
  790. func (n *Node) GenesisDoc() *types.GenesisDoc {
  791. return n.genesisDoc
  792. }
  793. // ProxyApp returns the Node's AppConns, representing its connections to the ABCI application.
  794. func (n *Node) ProxyApp() proxy.AppConns {
  795. return n.proxyApp
  796. }
  797. // Config returns the Node's config.
  798. func (n *Node) Config() *cfg.Config {
  799. return n.config
  800. }
  801. //------------------------------------------------------------------------------
  802. func (n *Node) Listeners() []string {
  803. return []string{
  804. fmt.Sprintf("Listener(@%v)", n.config.P2P.ExternalAddress),
  805. }
  806. }
  807. func (n *Node) IsListening() bool {
  808. return n.isListening
  809. }
  810. // NodeInfo returns the Node's Info from the Switch.
  811. func (n *Node) NodeInfo() p2p.NodeInfo {
  812. return n.nodeInfo
  813. }
  814. func makeNodeInfo(
  815. config *cfg.Config,
  816. nodeKey *p2p.NodeKey,
  817. txIndexer txindex.TxIndexer,
  818. genDoc *types.GenesisDoc,
  819. state sm.State,
  820. ) (p2p.NodeInfo, error) {
  821. txIndexerStatus := "on"
  822. if _, ok := txIndexer.(*null.TxIndex); ok {
  823. txIndexerStatus = "off"
  824. }
  825. nodeInfo := p2p.DefaultNodeInfo{
  826. ProtocolVersion: p2p.NewProtocolVersion(
  827. version.P2PProtocol, // global
  828. state.Version.Consensus.Block,
  829. state.Version.Consensus.App,
  830. ),
  831. ID_: nodeKey.ID(),
  832. Network: genDoc.ChainID,
  833. Version: version.TMCoreSemVer,
  834. Channels: []byte{
  835. bc.BlockchainChannel,
  836. cs.StateChannel, cs.DataChannel, cs.VoteChannel, cs.VoteSetBitsChannel,
  837. mempl.MempoolChannel,
  838. evidence.EvidenceChannel,
  839. },
  840. Moniker: config.Moniker,
  841. Other: p2p.DefaultNodeInfoOther{
  842. TxIndex: txIndexerStatus,
  843. RPCAddress: config.RPC.ListenAddress,
  844. },
  845. }
  846. if config.P2P.PexReactor {
  847. nodeInfo.Channels = append(nodeInfo.Channels, pex.PexChannel)
  848. }
  849. lAddr := config.P2P.ExternalAddress
  850. if lAddr == "" {
  851. lAddr = config.P2P.ListenAddress
  852. }
  853. nodeInfo.ListenAddr = lAddr
  854. err := nodeInfo.Validate()
  855. return nodeInfo, err
  856. }
  857. //------------------------------------------------------------------------------
  858. func createAndStartPrivValidatorSocketClient(
  859. listenAddr string,
  860. logger log.Logger,
  861. ) (types.PrivValidator, error) {
  862. var listener net.Listener
  863. protocol, address := cmn.ProtocolAndAddress(listenAddr)
  864. ln, err := net.Listen(protocol, address)
  865. if err != nil {
  866. return nil, err
  867. }
  868. switch protocol {
  869. case "unix":
  870. listener = privval.NewUnixListener(ln)
  871. case "tcp":
  872. // TODO: persist this key so external signer
  873. // can actually authenticate us
  874. listener = privval.NewTCPListener(ln, ed25519.GenPrivKey())
  875. default:
  876. return nil, fmt.Errorf(
  877. "wrong listen address: expected either 'tcp' or 'unix' protocols, got %s",
  878. protocol,
  879. )
  880. }
  881. pvsc := privval.NewSignerValidatorEndpoint(logger.With("module", "privval"), listener)
  882. if err := pvsc.Start(); err != nil {
  883. return nil, errors.Wrap(err, "failed to start private validator")
  884. }
  885. return pvsc, nil
  886. }
  887. // splitAndTrimEmpty slices s into all subslices separated by sep and returns a
  888. // slice of the string s with all leading and trailing Unicode code points
  889. // contained in cutset removed. If sep is empty, SplitAndTrim splits after each
  890. // UTF-8 sequence. First part is equivalent to strings.SplitN with a count of
  891. // -1. also filter out empty strings, only return non-empty strings.
  892. func splitAndTrimEmpty(s, sep, cutset string) []string {
  893. if s == "" {
  894. return []string{}
  895. }
  896. spl := strings.Split(s, sep)
  897. nonEmptyStrings := make([]string, 0, len(spl))
  898. for i := 0; i < len(spl); i++ {
  899. element := strings.Trim(spl[i], cutset)
  900. if element != "" {
  901. nonEmptyStrings = append(nonEmptyStrings, element)
  902. }
  903. }
  904. return nonEmptyStrings
  905. }