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.

749 lines
20 KiB

cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
fix non deterministic test failures and race in privval socket (#3258) * node: decrease retry conn timeout in test Should fix #3256 The retry timeout was set to the default, which is the same as the accept timeout, so it's no wonder this would fail. Here we decrease the retry timeout so we can try many times before the accept timeout. * p2p: increase handshake timeout in test This fails sometimes, presumably because the handshake timeout is so low (only 50ms). So increase it to 1s. Should fix #3187 * privval: fix race with ping. closes #3237 Pings happen in a go-routine and can happen concurrently with other messages. Since we use a request/response protocol, we expect to send a request and get back the corresponding response. But with pings happening concurrently, this assumption could be violated. We were using a mutex, but only a RWMutex, where the RLock was being held for sending messages - this was to allow the underlying connection to be replaced if it fails. Turns out we actually need to use a full lock (not just a read lock) to prevent multiple requests from happening concurrently. * node: fix test name. DelayedStop -> DelayedStart * autofile: Wait() method In the TestWALTruncate in consensus/wal_test.go we remove the WAL directory at the end of the test. However the wal.Stop() does not properly wait for the autofile group to finish shutting down. Hence it was possible that the group's go-routine is still running when the cleanup happens, which causes a panic since the directory disappeared. Here we add a Wait() method to properly wait until the go-routine exits so we can safely clean up. This fixes #2852.
5 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
fix non deterministic test failures and race in privval socket (#3258) * node: decrease retry conn timeout in test Should fix #3256 The retry timeout was set to the default, which is the same as the accept timeout, so it's no wonder this would fail. Here we decrease the retry timeout so we can try many times before the accept timeout. * p2p: increase handshake timeout in test This fails sometimes, presumably because the handshake timeout is so low (only 50ms). So increase it to 1s. Should fix #3187 * privval: fix race with ping. closes #3237 Pings happen in a go-routine and can happen concurrently with other messages. Since we use a request/response protocol, we expect to send a request and get back the corresponding response. But with pings happening concurrently, this assumption could be violated. We were using a mutex, but only a RWMutex, where the RLock was being held for sending messages - this was to allow the underlying connection to be replaced if it fails. Turns out we actually need to use a full lock (not just a read lock) to prevent multiple requests from happening concurrently. * node: fix test name. DelayedStop -> DelayedStart * autofile: Wait() method In the TestWALTruncate in consensus/wal_test.go we remove the WAL directory at the end of the test. However the wal.Stop() does not properly wait for the autofile group to finish shutting down. Hence it was possible that the group's go-routine is still running when the cleanup happens, which causes a panic since the directory disappeared. Here we add a Wait() method to properly wait until the go-routine exits so we can safely clean up. This fixes #2852.
5 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 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
5 years ago
privval: refactor Remote signers (#3370) This PR is related to #3107 and a continuation of #3351 It is important to emphasise that in the privval original design, client/server and listening/dialing roles are inverted and do not follow a conventional interaction. Given two hosts A and B: Host A is listener/client Host B is dialer/server (contains the secret key) When A requires a signature, it needs to wait for B to dial in before it can issue a request. A only accepts a single connection and any failure leads to dropping the connection and waiting for B to reconnect. The original rationale behind this design was based on security. Host B only allows outbound connections to a list of whitelisted hosts. It is not possible to reach B unless B dials in. There are no listening/open ports in B. This PR results in the following changes: Refactors ping/heartbeat to avoid previously existing race conditions. Separates transport (dialer/listener) from signing (client/server) concerns to simplify workflow. Unifies and abstracts away the differences between unix and tcp sockets. A single signer endpoint implementation unifies connection handling code (read/write/close/connection obj) The signer request handler (server side) is customizable to increase testability. Updates and extends unit tests A high level overview of the classes is as follows: Transport (endpoints): The following classes take care of establishing a connection SignerDialerEndpoint SignerListeningEndpoint SignerEndpoint groups common functionality (read/write/timeouts/etc.) Signing (client/server): The following classes take care of exchanging request/responses SignerClient SignerServer This PR also closes #3601 Commits: * refactoring - work in progress * reworking unit tests * Encapsulating and fixing unit tests * Improve tests * Clean up * Fix/improve unit tests * clean up tests * Improving service endpoint * fixing unit test * fix linter issues * avoid invalid cache values (improve later?) * complete implementation * wip * improved connection loop * Improve reconnections + fixing unit tests * addressing comments * small formatting changes * clean up * Update node/node.go Co-Authored-By: jleni <juan.leni@zondax.ch> * Update privval/signer_client.go Co-Authored-By: jleni <juan.leni@zondax.ch> * Update privval/signer_client_test.go Co-Authored-By: jleni <juan.leni@zondax.ch> * check during initialization * dropping connecting when writing fails * removing break * use t.log instead * unifying and using cmn.GetFreePort() * review fixes * reordering and unifying drop connection * closing instead of signalling * refactored service loop * removed superfluous brackets * GetPubKey can return errors * Revert "GetPubKey can return errors" This reverts commit 68c06f19b4650389d7e5ab1659b318889028202c. * adding entry to changelog * Update CHANGELOG_PENDING.md Co-Authored-By: jleni <juan.leni@zondax.ch> * Update privval/signer_client.go Co-Authored-By: jleni <juan.leni@zondax.ch> * Update privval/signer_dialer_endpoint.go Co-Authored-By: jleni <juan.leni@zondax.ch> * Update privval/signer_dialer_endpoint.go Co-Authored-By: jleni <juan.leni@zondax.ch> * Update privval/signer_dialer_endpoint.go Co-Authored-By: jleni <juan.leni@zondax.ch> * Update privval/signer_dialer_endpoint.go Co-Authored-By: jleni <juan.leni@zondax.ch> * Update privval/signer_listener_endpoint_test.go Co-Authored-By: jleni <juan.leni@zondax.ch> * updating node.go * review fixes * fixes linter * fixing unit test * small fixes in comments * addressing review comments * addressing review comments 2 * reverting suggestion * Update privval/signer_client_test.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * Update privval/signer_client_test.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * Update privval/signer_listener_endpoint_test.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * do not expose brokenSignerDialerEndpoint * clean up logging * unifying methods shorten test time signer also drops * reenabling pings * improving testability + unit test * fixing go fmt + unit test * remove unused code * Addressing review comments * simplifying connection workflow * fix linter/go import issue * using base service quit * updating comment * Simplifying design + adjusting names * fixing linter issues * refactoring test harness + fixes * Addressing review comments * cleaning up * adding additional error check
5 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 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
5 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 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
5 years ago
privval: refactor Remote signers (#3370) This PR is related to #3107 and a continuation of #3351 It is important to emphasise that in the privval original design, client/server and listening/dialing roles are inverted and do not follow a conventional interaction. Given two hosts A and B: Host A is listener/client Host B is dialer/server (contains the secret key) When A requires a signature, it needs to wait for B to dial in before it can issue a request. A only accepts a single connection and any failure leads to dropping the connection and waiting for B to reconnect. The original rationale behind this design was based on security. Host B only allows outbound connections to a list of whitelisted hosts. It is not possible to reach B unless B dials in. There are no listening/open ports in B. This PR results in the following changes: Refactors ping/heartbeat to avoid previously existing race conditions. Separates transport (dialer/listener) from signing (client/server) concerns to simplify workflow. Unifies and abstracts away the differences between unix and tcp sockets. A single signer endpoint implementation unifies connection handling code (read/write/close/connection obj) The signer request handler (server side) is customizable to increase testability. Updates and extends unit tests A high level overview of the classes is as follows: Transport (endpoints): The following classes take care of establishing a connection SignerDialerEndpoint SignerListeningEndpoint SignerEndpoint groups common functionality (read/write/timeouts/etc.) Signing (client/server): The following classes take care of exchanging request/responses SignerClient SignerServer This PR also closes #3601 Commits: * refactoring - work in progress * reworking unit tests * Encapsulating and fixing unit tests * Improve tests * Clean up * Fix/improve unit tests * clean up tests * Improving service endpoint * fixing unit test * fix linter issues * avoid invalid cache values (improve later?) * complete implementation * wip * improved connection loop * Improve reconnections + fixing unit tests * addressing comments * small formatting changes * clean up * Update node/node.go Co-Authored-By: jleni <juan.leni@zondax.ch> * Update privval/signer_client.go Co-Authored-By: jleni <juan.leni@zondax.ch> * Update privval/signer_client_test.go Co-Authored-By: jleni <juan.leni@zondax.ch> * check during initialization * dropping connecting when writing fails * removing break * use t.log instead * unifying and using cmn.GetFreePort() * review fixes * reordering and unifying drop connection * closing instead of signalling * refactored service loop * removed superfluous brackets * GetPubKey can return errors * Revert "GetPubKey can return errors" This reverts commit 68c06f19b4650389d7e5ab1659b318889028202c. * adding entry to changelog * Update CHANGELOG_PENDING.md Co-Authored-By: jleni <juan.leni@zondax.ch> * Update privval/signer_client.go Co-Authored-By: jleni <juan.leni@zondax.ch> * Update privval/signer_dialer_endpoint.go Co-Authored-By: jleni <juan.leni@zondax.ch> * Update privval/signer_dialer_endpoint.go Co-Authored-By: jleni <juan.leni@zondax.ch> * Update privval/signer_dialer_endpoint.go Co-Authored-By: jleni <juan.leni@zondax.ch> * Update privval/signer_dialer_endpoint.go Co-Authored-By: jleni <juan.leni@zondax.ch> * Update privval/signer_listener_endpoint_test.go Co-Authored-By: jleni <juan.leni@zondax.ch> * updating node.go * review fixes * fixes linter * fixing unit test * small fixes in comments * addressing review comments * addressing review comments 2 * reverting suggestion * Update privval/signer_client_test.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * Update privval/signer_client_test.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * Update privval/signer_listener_endpoint_test.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * do not expose brokenSignerDialerEndpoint * clean up logging * unifying methods shorten test time signer also drops * reenabling pings * improving testability + unit test * fixing go fmt + unit test * remove unused code * Addressing review comments * simplifying connection workflow * fix linter/go import issue * using base service quit * updating comment * Simplifying design + adjusting names * fixing linter issues * refactoring test harness + fixes * Addressing review comments * cleaning up * adding additional error check
5 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
  1. package node
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "math"
  7. "net"
  8. "os"
  9. "testing"
  10. "time"
  11. "github.com/fortytw2/leaktest"
  12. "github.com/stretchr/testify/assert"
  13. "github.com/stretchr/testify/require"
  14. dbm "github.com/tendermint/tm-db"
  15. abciclient "github.com/tendermint/tendermint/abci/client"
  16. "github.com/tendermint/tendermint/abci/example/kvstore"
  17. "github.com/tendermint/tendermint/config"
  18. "github.com/tendermint/tendermint/crypto"
  19. "github.com/tendermint/tendermint/crypto/ed25519"
  20. "github.com/tendermint/tendermint/crypto/tmhash"
  21. "github.com/tendermint/tendermint/internal/eventbus"
  22. "github.com/tendermint/tendermint/internal/evidence"
  23. "github.com/tendermint/tendermint/internal/mempool"
  24. "github.com/tendermint/tendermint/internal/proxy"
  25. "github.com/tendermint/tendermint/internal/pubsub"
  26. sm "github.com/tendermint/tendermint/internal/state"
  27. "github.com/tendermint/tendermint/internal/state/indexer"
  28. "github.com/tendermint/tendermint/internal/store"
  29. "github.com/tendermint/tendermint/internal/test/factory"
  30. "github.com/tendermint/tendermint/libs/log"
  31. tmrand "github.com/tendermint/tendermint/libs/rand"
  32. "github.com/tendermint/tendermint/libs/service"
  33. tmtime "github.com/tendermint/tendermint/libs/time"
  34. "github.com/tendermint/tendermint/privval"
  35. "github.com/tendermint/tendermint/types"
  36. )
  37. func TestNodeStartStop(t *testing.T) {
  38. cfg, err := config.ResetTestRoot(t.TempDir(), "node_node_test")
  39. require.NoError(t, err)
  40. defer os.RemoveAll(cfg.RootDir)
  41. ctx, bcancel := context.WithCancel(context.Background())
  42. defer bcancel()
  43. logger := log.NewNopLogger()
  44. // create & start node
  45. ns, err := newDefaultNode(ctx, cfg, logger)
  46. require.NoError(t, err)
  47. n, ok := ns.(*nodeImpl)
  48. require.True(t, ok)
  49. t.Cleanup(func() {
  50. bcancel()
  51. n.Wait()
  52. })
  53. t.Cleanup(leaktest.CheckTimeout(t, time.Second))
  54. require.NoError(t, n.Start(ctx))
  55. // wait for the node to produce a block
  56. tctx, cancel := context.WithTimeout(ctx, time.Second)
  57. defer cancel()
  58. blocksSub, err := n.EventBus().SubscribeWithArgs(tctx, pubsub.SubscribeArgs{
  59. ClientID: "node_test",
  60. Query: types.EventQueryNewBlock,
  61. })
  62. require.NoError(t, err)
  63. _, err = blocksSub.Next(tctx)
  64. require.NoError(t, err, "waiting for event")
  65. cancel() // stop the subscription context
  66. bcancel() // stop the base context
  67. n.Wait()
  68. require.False(t, n.IsRunning(), "node must shut down")
  69. }
  70. func getTestNode(ctx context.Context, t *testing.T, conf *config.Config, logger log.Logger) *nodeImpl {
  71. t.Helper()
  72. ctx, cancel := context.WithCancel(ctx)
  73. defer cancel()
  74. ns, err := newDefaultNode(ctx, conf, logger)
  75. require.NoError(t, err)
  76. n, ok := ns.(*nodeImpl)
  77. require.True(t, ok)
  78. t.Cleanup(func() {
  79. cancel()
  80. if n.IsRunning() {
  81. ns.Wait()
  82. }
  83. })
  84. t.Cleanup(leaktest.CheckTimeout(t, time.Second))
  85. return n
  86. }
  87. func TestNodeDelayedStart(t *testing.T) {
  88. cfg, err := config.ResetTestRoot(t.TempDir(), "node_delayed_start_test")
  89. require.NoError(t, err)
  90. defer os.RemoveAll(cfg.RootDir)
  91. now := tmtime.Now()
  92. ctx, cancel := context.WithCancel(context.Background())
  93. defer cancel()
  94. logger := log.NewNopLogger()
  95. // create & start node
  96. n := getTestNode(ctx, t, cfg, logger)
  97. n.GenesisDoc().GenesisTime = now.Add(2 * time.Second)
  98. require.NoError(t, n.Start(ctx))
  99. startTime := tmtime.Now()
  100. assert.Equal(t, true, startTime.After(n.GenesisDoc().GenesisTime))
  101. }
  102. func TestNodeSetAppVersion(t *testing.T) {
  103. cfg, err := config.ResetTestRoot(t.TempDir(), "node_app_version_test")
  104. require.NoError(t, err)
  105. defer os.RemoveAll(cfg.RootDir)
  106. ctx, cancel := context.WithCancel(context.Background())
  107. defer cancel()
  108. logger := log.NewNopLogger()
  109. // create node
  110. n := getTestNode(ctx, t, cfg, logger)
  111. // default config uses the kvstore app
  112. appVersion := kvstore.ProtocolVersion
  113. // check version is set in state
  114. state, err := n.stateStore.Load()
  115. require.NoError(t, err)
  116. assert.Equal(t, state.Version.Consensus.App, appVersion)
  117. // check version is set in node info
  118. assert.Equal(t, n.nodeInfo.ProtocolVersion.App, appVersion)
  119. }
  120. func TestNodeSetPrivValTCP(t *testing.T) {
  121. addr := "tcp://" + testFreeAddr(t)
  122. t.Cleanup(leaktest.Check(t))
  123. ctx, cancel := context.WithCancel(context.Background())
  124. defer cancel()
  125. logger := log.NewNopLogger()
  126. cfg, err := config.ResetTestRoot(t.TempDir(), "node_priv_val_tcp_test")
  127. require.NoError(t, err)
  128. defer os.RemoveAll(cfg.RootDir)
  129. cfg.PrivValidator.ListenAddr = addr
  130. dialer := privval.DialTCPFn(addr, 100*time.Millisecond, ed25519.GenPrivKey())
  131. dialerEndpoint := privval.NewSignerDialerEndpoint(logger, dialer)
  132. privval.SignerDialerEndpointTimeoutReadWrite(100 * time.Millisecond)(dialerEndpoint)
  133. signerServer := privval.NewSignerServer(
  134. dialerEndpoint,
  135. cfg.ChainID(),
  136. types.NewMockPV(),
  137. )
  138. go func() {
  139. err := signerServer.Start(ctx)
  140. require.NoError(t, err)
  141. }()
  142. defer signerServer.Stop()
  143. genDoc, err := defaultGenesisDocProviderFunc(cfg)()
  144. require.NoError(t, err)
  145. pval, err := createPrivval(ctx, logger, cfg, genDoc, nil)
  146. require.NoError(t, err)
  147. assert.IsType(t, &privval.RetrySignerClient{}, pval)
  148. }
  149. // address without a protocol must result in error
  150. func TestPrivValidatorListenAddrNoProtocol(t *testing.T) {
  151. ctx, cancel := context.WithCancel(context.Background())
  152. defer cancel()
  153. addrNoPrefix := testFreeAddr(t)
  154. cfg, err := config.ResetTestRoot(t.TempDir(), "node_priv_val_tcp_test")
  155. require.NoError(t, err)
  156. defer os.RemoveAll(cfg.RootDir)
  157. cfg.PrivValidator.ListenAddr = addrNoPrefix
  158. logger := log.NewNopLogger()
  159. n, err := newDefaultNode(ctx, cfg, logger)
  160. assert.Error(t, err)
  161. if n != nil && n.IsRunning() {
  162. cancel()
  163. n.Wait()
  164. }
  165. }
  166. func TestNodeSetPrivValIPC(t *testing.T) {
  167. tmpfile := "/tmp/kms." + tmrand.Str(6) + ".sock"
  168. defer os.Remove(tmpfile) // clean up
  169. ctx, cancel := context.WithCancel(context.Background())
  170. defer cancel()
  171. cfg, err := config.ResetTestRoot(t.TempDir(), "node_priv_val_tcp_test")
  172. require.NoError(t, err)
  173. defer os.RemoveAll(cfg.RootDir)
  174. cfg.PrivValidator.ListenAddr = "unix://" + tmpfile
  175. logger := log.NewNopLogger()
  176. dialer := privval.DialUnixFn(tmpfile)
  177. dialerEndpoint := privval.NewSignerDialerEndpoint(logger, dialer)
  178. privval.SignerDialerEndpointTimeoutReadWrite(100 * time.Millisecond)(dialerEndpoint)
  179. pvsc := privval.NewSignerServer(
  180. dialerEndpoint,
  181. cfg.ChainID(),
  182. types.NewMockPV(),
  183. )
  184. go func() {
  185. err := pvsc.Start(ctx)
  186. require.NoError(t, err)
  187. }()
  188. defer pvsc.Stop()
  189. genDoc, err := defaultGenesisDocProviderFunc(cfg)()
  190. require.NoError(t, err)
  191. pval, err := createPrivval(ctx, logger, cfg, genDoc, nil)
  192. require.NoError(t, err)
  193. assert.IsType(t, &privval.RetrySignerClient{}, pval)
  194. }
  195. // testFreeAddr claims a free port so we don't block on listener being ready.
  196. func testFreeAddr(t *testing.T) string {
  197. ln, err := net.Listen("tcp", "127.0.0.1:0")
  198. require.NoError(t, err)
  199. defer ln.Close()
  200. return fmt.Sprintf("127.0.0.1:%d", ln.Addr().(*net.TCPAddr).Port)
  201. }
  202. // create a proposal block using real and full
  203. // mempool and evidence pool and validate it.
  204. func TestCreateProposalBlock(t *testing.T) {
  205. ctx, cancel := context.WithCancel(context.Background())
  206. defer cancel()
  207. cfg, err := config.ResetTestRoot(t.TempDir(), "node_create_proposal")
  208. require.NoError(t, err)
  209. defer os.RemoveAll(cfg.RootDir)
  210. logger := log.NewNopLogger()
  211. cc := abciclient.NewLocalCreator(kvstore.NewApplication())
  212. proxyApp := proxy.NewAppConns(cc, logger, proxy.NopMetrics())
  213. err = proxyApp.Start(ctx)
  214. require.NoError(t, err)
  215. const height int64 = 1
  216. state, stateDB, privVals := state(t, 1, height)
  217. stateStore := sm.NewStore(stateDB)
  218. maxBytes := 16384
  219. const partSize uint32 = 256
  220. maxEvidenceBytes := int64(maxBytes / 2)
  221. state.ConsensusParams.Block.MaxBytes = int64(maxBytes)
  222. state.ConsensusParams.Evidence.MaxBytes = maxEvidenceBytes
  223. proposerAddr, _ := state.Validators.GetByIndex(0)
  224. mp := mempool.NewTxMempool(
  225. logger.With("module", "mempool"),
  226. cfg.Mempool,
  227. proxyApp.Mempool(),
  228. state.LastBlockHeight,
  229. )
  230. // Make EvidencePool
  231. evidenceDB := dbm.NewMemDB()
  232. blockStore := store.NewBlockStore(dbm.NewMemDB())
  233. evidencePool, err := evidence.NewPool(logger, evidenceDB, stateStore, blockStore)
  234. require.NoError(t, err)
  235. // fill the evidence pool with more evidence
  236. // than can fit in a block
  237. var currentBytes int64
  238. for currentBytes <= maxEvidenceBytes {
  239. ev, err := types.NewMockDuplicateVoteEvidenceWithValidator(ctx, height, time.Now(), privVals[0], "test-chain")
  240. require.NoError(t, err)
  241. currentBytes += int64(len(ev.Bytes()))
  242. evidencePool.ReportConflictingVotes(ev.VoteA, ev.VoteB)
  243. }
  244. evList, size := evidencePool.PendingEvidence(state.ConsensusParams.Evidence.MaxBytes)
  245. require.Less(t, size, state.ConsensusParams.Evidence.MaxBytes+1)
  246. evData := types.EvidenceList(evList)
  247. require.EqualValues(t, size, evData.ByteSize())
  248. // fill the mempool with more txs
  249. // than can fit in a block
  250. txLength := 100
  251. for i := 0; i <= maxBytes/txLength; i++ {
  252. tx := tmrand.Bytes(txLength)
  253. err := mp.CheckTx(ctx, tx, nil, mempool.TxInfo{})
  254. assert.NoError(t, err)
  255. }
  256. blockExec := sm.NewBlockExecutor(
  257. stateStore,
  258. logger,
  259. proxyApp.Consensus(),
  260. mp,
  261. evidencePool,
  262. blockStore,
  263. )
  264. commit := types.NewCommit(height-1, 0, types.BlockID{}, nil)
  265. block, _, err := blockExec.CreateProposalBlock(
  266. ctx,
  267. height,
  268. state, commit,
  269. proposerAddr,
  270. nil,
  271. )
  272. require.NoError(t, err)
  273. // check that the part set does not exceed the maximum block size
  274. partSet, err := block.MakePartSet(partSize)
  275. require.NoError(t, err)
  276. assert.Less(t, partSet.ByteSize(), int64(maxBytes))
  277. partSetFromHeader := types.NewPartSetFromHeader(partSet.Header())
  278. for partSetFromHeader.Count() < partSetFromHeader.Total() {
  279. added, err := partSetFromHeader.AddPart(partSet.GetPart(int(partSetFromHeader.Count())))
  280. require.NoError(t, err)
  281. require.True(t, added)
  282. }
  283. assert.EqualValues(t, partSetFromHeader.ByteSize(), partSet.ByteSize())
  284. err = blockExec.ValidateBlock(state, block)
  285. assert.NoError(t, err)
  286. }
  287. func TestMaxTxsProposalBlockSize(t *testing.T) {
  288. ctx, cancel := context.WithCancel(context.Background())
  289. defer cancel()
  290. cfg, err := config.ResetTestRoot(t.TempDir(), "node_create_proposal")
  291. require.NoError(t, err)
  292. defer os.RemoveAll(cfg.RootDir)
  293. logger := log.NewNopLogger()
  294. cc := abciclient.NewLocalCreator(kvstore.NewApplication())
  295. proxyApp := proxy.NewAppConns(cc, logger, proxy.NopMetrics())
  296. err = proxyApp.Start(ctx)
  297. require.NoError(t, err)
  298. const height int64 = 1
  299. state, stateDB, _ := state(t, 1, height)
  300. stateStore := sm.NewStore(stateDB)
  301. blockStore := store.NewBlockStore(dbm.NewMemDB())
  302. const maxBytes int64 = 16384
  303. const partSize uint32 = 256
  304. state.ConsensusParams.Block.MaxBytes = maxBytes
  305. proposerAddr, _ := state.Validators.GetByIndex(0)
  306. // Make Mempool
  307. mp := mempool.NewTxMempool(
  308. logger.With("module", "mempool"),
  309. cfg.Mempool,
  310. proxyApp.Mempool(),
  311. state.LastBlockHeight,
  312. )
  313. // fill the mempool with one txs just below the maximum size
  314. txLength := int(types.MaxDataBytesNoEvidence(maxBytes, 1))
  315. tx := tmrand.Bytes(txLength - 4) // to account for the varint
  316. err = mp.CheckTx(ctx, tx, nil, mempool.TxInfo{})
  317. assert.NoError(t, err)
  318. blockExec := sm.NewBlockExecutor(
  319. stateStore,
  320. logger,
  321. proxyApp.Consensus(),
  322. mp,
  323. sm.EmptyEvidencePool{},
  324. blockStore,
  325. )
  326. commit := types.NewCommit(height-1, 0, types.BlockID{}, nil)
  327. block, _, err := blockExec.CreateProposalBlock(
  328. ctx,
  329. height,
  330. state, commit,
  331. proposerAddr,
  332. nil,
  333. )
  334. require.NoError(t, err)
  335. pb, err := block.ToProto()
  336. require.NoError(t, err)
  337. assert.Less(t, int64(pb.Size()), maxBytes)
  338. // check that the part set does not exceed the maximum block size
  339. partSet, err := block.MakePartSet(partSize)
  340. require.NoError(t, err)
  341. assert.EqualValues(t, partSet.ByteSize(), int64(pb.Size()))
  342. }
  343. func TestMaxProposalBlockSize(t *testing.T) {
  344. ctx, cancel := context.WithCancel(context.Background())
  345. defer cancel()
  346. cfg, err := config.ResetTestRoot(t.TempDir(), "node_create_proposal")
  347. require.NoError(t, err)
  348. defer os.RemoveAll(cfg.RootDir)
  349. logger := log.NewNopLogger()
  350. cc := abciclient.NewLocalCreator(kvstore.NewApplication())
  351. proxyApp := proxy.NewAppConns(cc, logger, proxy.NopMetrics())
  352. err = proxyApp.Start(ctx)
  353. require.NoError(t, err)
  354. state, stateDB, _ := state(t, types.MaxVotesCount, int64(1))
  355. stateStore := sm.NewStore(stateDB)
  356. blockStore := store.NewBlockStore(dbm.NewMemDB())
  357. const maxBytes int64 = 1024 * 1024 * 2
  358. state.ConsensusParams.Block.MaxBytes = maxBytes
  359. proposerAddr, _ := state.Validators.GetByIndex(0)
  360. // Make Mempool
  361. mp := mempool.NewTxMempool(
  362. logger.With("module", "mempool"),
  363. cfg.Mempool,
  364. proxyApp.Mempool(),
  365. state.LastBlockHeight,
  366. )
  367. // fill the mempool with one txs just below the maximum size
  368. txLength := int(types.MaxDataBytesNoEvidence(maxBytes, types.MaxVotesCount))
  369. tx := tmrand.Bytes(txLength - 6) // to account for the varint
  370. err = mp.CheckTx(ctx, tx, nil, mempool.TxInfo{})
  371. assert.NoError(t, err)
  372. // now produce more txs than what a normal block can hold with 10 smaller txs
  373. // At the end of the test, only the single big tx should be added
  374. for i := 0; i < 10; i++ {
  375. tx := tmrand.Bytes(10)
  376. err = mp.CheckTx(ctx, tx, nil, mempool.TxInfo{})
  377. assert.NoError(t, err)
  378. }
  379. blockExec := sm.NewBlockExecutor(
  380. stateStore,
  381. logger,
  382. proxyApp.Consensus(),
  383. mp,
  384. sm.EmptyEvidencePool{},
  385. blockStore,
  386. )
  387. blockID := types.BlockID{
  388. Hash: tmhash.Sum([]byte("blockID_hash")),
  389. PartSetHeader: types.PartSetHeader{
  390. Total: math.MaxInt32,
  391. Hash: tmhash.Sum([]byte("blockID_part_set_header_hash")),
  392. },
  393. }
  394. timestamp := time.Date(math.MaxInt64, 0, 0, 0, 0, 0, math.MaxInt64, time.UTC)
  395. // change state in order to produce the largest accepted header
  396. state.LastBlockID = blockID
  397. state.LastBlockHeight = math.MaxInt64 - 1
  398. state.LastBlockTime = timestamp
  399. state.LastResultsHash = tmhash.Sum([]byte("last_results_hash"))
  400. state.AppHash = tmhash.Sum([]byte("app_hash"))
  401. state.Version.Consensus.Block = math.MaxInt64
  402. state.Version.Consensus.App = math.MaxInt64
  403. maxChainID := ""
  404. for i := 0; i < types.MaxChainIDLen; i++ {
  405. maxChainID += "𠜎"
  406. }
  407. state.ChainID = maxChainID
  408. cs := types.CommitSig{
  409. BlockIDFlag: types.BlockIDFlagNil,
  410. ValidatorAddress: crypto.AddressHash([]byte("validator_address")),
  411. Timestamp: timestamp,
  412. Signature: crypto.CRandBytes(types.MaxSignatureSize),
  413. }
  414. commit := &types.Commit{
  415. Height: math.MaxInt64,
  416. Round: math.MaxInt32,
  417. BlockID: blockID,
  418. }
  419. // add maximum amount of signatures to a single commit
  420. for i := 0; i < types.MaxVotesCount; i++ {
  421. commit.Signatures = append(commit.Signatures, cs)
  422. }
  423. block, partSet, err := blockExec.CreateProposalBlock(
  424. ctx,
  425. math.MaxInt64,
  426. state, commit,
  427. proposerAddr,
  428. nil,
  429. )
  430. require.NoError(t, err)
  431. // this ensures that the header is at max size
  432. block.Header.Time = timestamp
  433. pb, err := block.ToProto()
  434. require.NoError(t, err)
  435. // require that the header and commit be the max possible size
  436. require.Equal(t, int64(pb.Header.Size()), types.MaxHeaderBytes)
  437. require.Equal(t, int64(pb.LastCommit.Size()), types.MaxCommitBytes(types.MaxVotesCount))
  438. // make sure that the block is less than the max possible size
  439. assert.Equal(t, int64(pb.Size()), maxBytes)
  440. // because of the proto overhead we expect the part set bytes to be equal or
  441. // less than the pb block size
  442. assert.LessOrEqual(t, partSet.ByteSize(), int64(pb.Size()))
  443. }
  444. func TestNodeNewSeedNode(t *testing.T) {
  445. cfg, err := config.ResetTestRoot(t.TempDir(), "node_new_node_custom_reactors_test")
  446. require.NoError(t, err)
  447. cfg.Mode = config.ModeSeed
  448. defer os.RemoveAll(cfg.RootDir)
  449. ctx, cancel := context.WithCancel(context.Background())
  450. defer cancel()
  451. nodeKey, err := types.LoadOrGenNodeKey(cfg.NodeKeyFile())
  452. require.NoError(t, err)
  453. logger := log.NewNopLogger()
  454. ns, err := makeSeedNode(ctx,
  455. cfg,
  456. config.DefaultDBProvider,
  457. nodeKey,
  458. defaultGenesisDocProviderFunc(cfg),
  459. logger,
  460. )
  461. t.Cleanup(ns.Wait)
  462. t.Cleanup(leaktest.CheckTimeout(t, time.Second))
  463. require.NoError(t, err)
  464. n, ok := ns.(*seedNodeImpl)
  465. require.True(t, ok)
  466. err = n.Start(ctx)
  467. require.NoError(t, err)
  468. assert.True(t, n.pexReactor.IsRunning())
  469. cancel()
  470. n.Wait()
  471. assert.False(t, n.pexReactor.IsRunning())
  472. }
  473. func TestNodeSetEventSink(t *testing.T) {
  474. cfg, err := config.ResetTestRoot(t.TempDir(), "node_app_version_test")
  475. require.NoError(t, err)
  476. defer os.RemoveAll(cfg.RootDir)
  477. ctx, cancel := context.WithCancel(context.Background())
  478. defer cancel()
  479. logger := log.NewNopLogger()
  480. setupTest := func(t *testing.T, conf *config.Config) []indexer.EventSink {
  481. eventBus := eventbus.NewDefault(logger.With("module", "events"))
  482. require.NoError(t, eventBus.Start(ctx))
  483. t.Cleanup(eventBus.Wait)
  484. genDoc, err := types.GenesisDocFromFile(cfg.GenesisFile())
  485. require.NoError(t, err)
  486. indexService, eventSinks, err := createAndStartIndexerService(ctx, cfg,
  487. config.DefaultDBProvider, eventBus, logger, genDoc.ChainID,
  488. indexer.NopMetrics())
  489. require.NoError(t, err)
  490. t.Cleanup(indexService.Wait)
  491. return eventSinks
  492. }
  493. cleanup := func(ns service.Service) func() {
  494. return func() {
  495. n, ok := ns.(*nodeImpl)
  496. if !ok {
  497. return
  498. }
  499. if n == nil {
  500. return
  501. }
  502. if !n.IsRunning() {
  503. return
  504. }
  505. cancel()
  506. n.Wait()
  507. }
  508. }
  509. eventSinks := setupTest(t, cfg)
  510. assert.Equal(t, 1, len(eventSinks))
  511. assert.Equal(t, indexer.KV, eventSinks[0].Type())
  512. cfg.TxIndex.Indexer = []string{"null"}
  513. eventSinks = setupTest(t, cfg)
  514. assert.Equal(t, 1, len(eventSinks))
  515. assert.Equal(t, indexer.NULL, eventSinks[0].Type())
  516. cfg.TxIndex.Indexer = []string{"null", "kv"}
  517. eventSinks = setupTest(t, cfg)
  518. assert.Equal(t, 1, len(eventSinks))
  519. assert.Equal(t, indexer.NULL, eventSinks[0].Type())
  520. cfg.TxIndex.Indexer = []string{"kvv"}
  521. ns, err := newDefaultNode(ctx, cfg, logger)
  522. assert.Nil(t, ns)
  523. assert.Contains(t, err.Error(), "unsupported event sink type")
  524. t.Cleanup(cleanup(ns))
  525. cfg.TxIndex.Indexer = []string{}
  526. eventSinks = setupTest(t, cfg)
  527. assert.Equal(t, 1, len(eventSinks))
  528. assert.Equal(t, indexer.NULL, eventSinks[0].Type())
  529. cfg.TxIndex.Indexer = []string{"psql"}
  530. ns, err = newDefaultNode(ctx, cfg, logger)
  531. assert.Nil(t, ns)
  532. assert.Contains(t, err.Error(), "the psql connection settings cannot be empty")
  533. t.Cleanup(cleanup(ns))
  534. // N.B. We can't create a PSQL event sink without starting a postgres
  535. // instance for it to talk to. The indexer service tests exercise that case.
  536. var e = errors.New("found duplicated sinks, please check the tx-index section in the config.toml")
  537. cfg.TxIndex.Indexer = []string{"null", "kv", "Kv"}
  538. ns, err = newDefaultNode(ctx, cfg, logger)
  539. require.Error(t, err)
  540. assert.Contains(t, err.Error(), e.Error())
  541. t.Cleanup(cleanup(ns))
  542. cfg.TxIndex.Indexer = []string{"Null", "kV", "kv", "nUlL"}
  543. ns, err = newDefaultNode(ctx, cfg, logger)
  544. require.Error(t, err)
  545. assert.Contains(t, err.Error(), e.Error())
  546. t.Cleanup(cleanup(ns))
  547. }
  548. func state(t *testing.T, nVals int, height int64) (sm.State, dbm.DB, []types.PrivValidator) {
  549. t.Helper()
  550. privVals := make([]types.PrivValidator, nVals)
  551. vals := make([]types.GenesisValidator, nVals)
  552. for i := 0; i < nVals; i++ {
  553. privVal := types.NewMockPV()
  554. privVals[i] = privVal
  555. vals[i] = types.GenesisValidator{
  556. Address: privVal.PrivKey.PubKey().Address(),
  557. PubKey: privVal.PrivKey.PubKey(),
  558. Power: 1000,
  559. Name: fmt.Sprintf("test%d", i),
  560. }
  561. }
  562. s, _ := sm.MakeGenesisState(&types.GenesisDoc{
  563. ChainID: "test-chain",
  564. Validators: vals,
  565. AppHash: nil,
  566. })
  567. // save validators to db for 2 heights
  568. stateDB := dbm.NewMemDB()
  569. t.Cleanup(func() { require.NoError(t, stateDB.Close()) })
  570. stateStore := sm.NewStore(stateDB)
  571. require.NoError(t, stateStore.Save(s))
  572. for i := 1; i < int(height); i++ {
  573. s.LastBlockHeight++
  574. s.LastValidators = s.Validators.Copy()
  575. require.NoError(t, stateStore.Save(s))
  576. }
  577. return s, stateDB, privVals
  578. }
  579. func TestLoadStateFromGenesis(t *testing.T) {
  580. ctx, cancel := context.WithCancel(context.Background())
  581. defer cancel()
  582. _ = loadStatefromGenesis(ctx, t)
  583. }
  584. func loadStatefromGenesis(ctx context.Context, t *testing.T) sm.State {
  585. t.Helper()
  586. stateDB := dbm.NewMemDB()
  587. stateStore := sm.NewStore(stateDB)
  588. cfg, err := config.ResetTestRoot(t.TempDir(), "load_state_from_genesis")
  589. require.NoError(t, err)
  590. loadedState, err := stateStore.Load()
  591. require.NoError(t, err)
  592. require.True(t, loadedState.IsEmpty())
  593. valSet, _ := factory.ValidatorSet(ctx, t, 0, 10)
  594. genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, nil)
  595. state, err := loadStateFromDBOrGenesisDocProvider(
  596. stateStore,
  597. genDoc,
  598. )
  599. require.NoError(t, err)
  600. require.NotNil(t, state)
  601. return state
  602. }