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.

756 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.
6 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.
6 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
6 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
6 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
6 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.NewLocalClient(logger, kvstore.NewApplication())
  212. proxyApp := proxy.New(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,
  228. )
  229. // Make EvidencePool
  230. evidenceDB := dbm.NewMemDB()
  231. blockStore := store.NewBlockStore(dbm.NewMemDB())
  232. evidencePool := evidence.NewPool(logger, evidenceDB, stateStore, blockStore, evidence.NopMetrics(), nil)
  233. // fill the evidence pool with more evidence
  234. // than can fit in a block
  235. var currentBytes int64
  236. for currentBytes <= maxEvidenceBytes {
  237. ev, err := types.NewMockDuplicateVoteEvidenceWithValidator(ctx, height, time.Now(), privVals[0], "test-chain")
  238. require.NoError(t, err)
  239. currentBytes += int64(len(ev.Bytes()))
  240. evidencePool.ReportConflictingVotes(ev.VoteA, ev.VoteB)
  241. }
  242. evList, size := evidencePool.PendingEvidence(state.ConsensusParams.Evidence.MaxBytes)
  243. require.Less(t, size, state.ConsensusParams.Evidence.MaxBytes+1)
  244. evData := types.EvidenceList(evList)
  245. require.EqualValues(t, size, evData.ByteSize())
  246. // fill the mempool with more txs
  247. // than can fit in a block
  248. txLength := 100
  249. for i := 0; i <= maxBytes/txLength; i++ {
  250. tx := tmrand.Bytes(txLength)
  251. err := mp.CheckTx(ctx, tx, nil, mempool.TxInfo{})
  252. assert.NoError(t, err)
  253. }
  254. eventBus := eventbus.NewDefault(logger)
  255. require.NoError(t, eventBus.Start(ctx))
  256. blockExec := sm.NewBlockExecutor(
  257. stateStore,
  258. logger,
  259. proxyApp,
  260. mp,
  261. evidencePool,
  262. blockStore,
  263. eventBus,
  264. )
  265. commit := types.NewCommit(height-1, 0, types.BlockID{}, nil)
  266. block, _, err := blockExec.CreateProposalBlock(
  267. ctx,
  268. height,
  269. state, commit,
  270. proposerAddr,
  271. nil,
  272. )
  273. require.NoError(t, err)
  274. // check that the part set does not exceed the maximum block size
  275. partSet, err := block.MakePartSet(partSize)
  276. require.NoError(t, err)
  277. assert.Less(t, partSet.ByteSize(), int64(maxBytes))
  278. partSetFromHeader := types.NewPartSetFromHeader(partSet.Header())
  279. for partSetFromHeader.Count() < partSetFromHeader.Total() {
  280. added, err := partSetFromHeader.AddPart(partSet.GetPart(int(partSetFromHeader.Count())))
  281. require.NoError(t, err)
  282. require.True(t, added)
  283. }
  284. assert.EqualValues(t, partSetFromHeader.ByteSize(), partSet.ByteSize())
  285. err = blockExec.ValidateBlock(ctx, state, block)
  286. assert.NoError(t, err)
  287. }
  288. func TestMaxTxsProposalBlockSize(t *testing.T) {
  289. ctx, cancel := context.WithCancel(context.Background())
  290. defer cancel()
  291. cfg, err := config.ResetTestRoot(t.TempDir(), "node_create_proposal")
  292. require.NoError(t, err)
  293. defer os.RemoveAll(cfg.RootDir)
  294. logger := log.NewNopLogger()
  295. cc := abciclient.NewLocalClient(logger, kvstore.NewApplication())
  296. proxyApp := proxy.New(cc, logger, proxy.NopMetrics())
  297. err = proxyApp.Start(ctx)
  298. require.NoError(t, err)
  299. const height int64 = 1
  300. state, stateDB, _ := state(t, 1, height)
  301. stateStore := sm.NewStore(stateDB)
  302. blockStore := store.NewBlockStore(dbm.NewMemDB())
  303. const maxBytes int64 = 16384
  304. const partSize uint32 = 256
  305. state.ConsensusParams.Block.MaxBytes = maxBytes
  306. proposerAddr, _ := state.Validators.GetByIndex(0)
  307. // Make Mempool
  308. mp := mempool.NewTxMempool(
  309. logger.With("module", "mempool"),
  310. cfg.Mempool,
  311. proxyApp,
  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. eventBus := eventbus.NewDefault(logger)
  319. require.NoError(t, eventBus.Start(ctx))
  320. blockExec := sm.NewBlockExecutor(
  321. stateStore,
  322. logger,
  323. proxyApp,
  324. mp,
  325. sm.EmptyEvidencePool{},
  326. blockStore,
  327. eventBus,
  328. )
  329. commit := types.NewCommit(height-1, 0, types.BlockID{}, nil)
  330. block, _, err := blockExec.CreateProposalBlock(
  331. ctx,
  332. height,
  333. state, commit,
  334. proposerAddr,
  335. nil,
  336. )
  337. require.NoError(t, err)
  338. pb, err := block.ToProto()
  339. require.NoError(t, err)
  340. assert.Less(t, int64(pb.Size()), maxBytes)
  341. // check that the part set does not exceed the maximum block size
  342. partSet, err := block.MakePartSet(partSize)
  343. require.NoError(t, err)
  344. assert.EqualValues(t, partSet.ByteSize(), int64(pb.Size()))
  345. }
  346. func TestMaxProposalBlockSize(t *testing.T) {
  347. ctx, cancel := context.WithCancel(context.Background())
  348. defer cancel()
  349. cfg, err := config.ResetTestRoot(t.TempDir(), "node_create_proposal")
  350. require.NoError(t, err)
  351. defer os.RemoveAll(cfg.RootDir)
  352. logger := log.NewNopLogger()
  353. cc := abciclient.NewLocalClient(logger, kvstore.NewApplication())
  354. proxyApp := proxy.New(cc, logger, proxy.NopMetrics())
  355. err = proxyApp.Start(ctx)
  356. require.NoError(t, err)
  357. state, stateDB, _ := state(t, types.MaxVotesCount, int64(1))
  358. stateStore := sm.NewStore(stateDB)
  359. blockStore := store.NewBlockStore(dbm.NewMemDB())
  360. const maxBytes int64 = 1024 * 1024 * 2
  361. state.ConsensusParams.Block.MaxBytes = maxBytes
  362. proposerAddr, _ := state.Validators.GetByIndex(0)
  363. // Make Mempool
  364. mp := mempool.NewTxMempool(
  365. logger.With("module", "mempool"),
  366. cfg.Mempool,
  367. proxyApp,
  368. )
  369. // fill the mempool with one txs just below the maximum size
  370. txLength := int(types.MaxDataBytesNoEvidence(maxBytes, types.MaxVotesCount))
  371. tx := tmrand.Bytes(txLength - 6) // to account for the varint
  372. err = mp.CheckTx(ctx, tx, nil, mempool.TxInfo{})
  373. assert.NoError(t, err)
  374. // now produce more txs than what a normal block can hold with 10 smaller txs
  375. // At the end of the test, only the single big tx should be added
  376. for i := 0; i < 10; i++ {
  377. tx := tmrand.Bytes(10)
  378. err = mp.CheckTx(ctx, tx, nil, mempool.TxInfo{})
  379. assert.NoError(t, err)
  380. }
  381. eventBus := eventbus.NewDefault(logger)
  382. require.NoError(t, eventBus.Start(ctx))
  383. blockExec := sm.NewBlockExecutor(
  384. stateStore,
  385. logger,
  386. proxyApp,
  387. mp,
  388. sm.EmptyEvidencePool{},
  389. blockStore,
  390. eventBus,
  391. )
  392. blockID := types.BlockID{
  393. Hash: tmhash.Sum([]byte("blockID_hash")),
  394. PartSetHeader: types.PartSetHeader{
  395. Total: math.MaxInt32,
  396. Hash: tmhash.Sum([]byte("blockID_part_set_header_hash")),
  397. },
  398. }
  399. timestamp := time.Date(math.MaxInt64, 0, 0, 0, 0, 0, math.MaxInt64, time.UTC)
  400. // change state in order to produce the largest accepted header
  401. state.LastBlockID = blockID
  402. state.LastBlockHeight = math.MaxInt64 - 1
  403. state.LastBlockTime = timestamp
  404. state.LastResultsHash = tmhash.Sum([]byte("last_results_hash"))
  405. state.AppHash = tmhash.Sum([]byte("app_hash"))
  406. state.Version.Consensus.Block = math.MaxInt64
  407. state.Version.Consensus.App = math.MaxInt64
  408. maxChainID := ""
  409. for i := 0; i < types.MaxChainIDLen; i++ {
  410. maxChainID += "𠜎"
  411. }
  412. state.ChainID = maxChainID
  413. cs := types.CommitSig{
  414. BlockIDFlag: types.BlockIDFlagNil,
  415. ValidatorAddress: crypto.AddressHash([]byte("validator_address")),
  416. Timestamp: timestamp,
  417. Signature: crypto.CRandBytes(types.MaxSignatureSize),
  418. }
  419. commit := &types.Commit{
  420. Height: math.MaxInt64,
  421. Round: math.MaxInt32,
  422. BlockID: blockID,
  423. }
  424. // add maximum amount of signatures to a single commit
  425. for i := 0; i < types.MaxVotesCount; i++ {
  426. commit.Signatures = append(commit.Signatures, cs)
  427. }
  428. block, partSet, err := blockExec.CreateProposalBlock(
  429. ctx,
  430. math.MaxInt64,
  431. state, commit,
  432. proposerAddr,
  433. nil,
  434. )
  435. require.NoError(t, err)
  436. // this ensures that the header is at max size
  437. block.Header.Time = timestamp
  438. pb, err := block.ToProto()
  439. require.NoError(t, err)
  440. // require that the header and commit be the max possible size
  441. require.Equal(t, int64(pb.Header.Size()), types.MaxHeaderBytes)
  442. require.Equal(t, int64(pb.LastCommit.Size()), types.MaxCommitBytes(types.MaxVotesCount))
  443. // make sure that the block is less than the max possible size
  444. assert.Equal(t, int64(pb.Size()), maxBytes)
  445. // because of the proto overhead we expect the part set bytes to be equal or
  446. // less than the pb block size
  447. assert.LessOrEqual(t, partSet.ByteSize(), int64(pb.Size()))
  448. }
  449. func TestNodeNewSeedNode(t *testing.T) {
  450. cfg, err := config.ResetTestRoot(t.TempDir(), "node_new_node_custom_reactors_test")
  451. require.NoError(t, err)
  452. cfg.Mode = config.ModeSeed
  453. defer os.RemoveAll(cfg.RootDir)
  454. ctx, cancel := context.WithCancel(context.Background())
  455. defer cancel()
  456. nodeKey, err := types.LoadOrGenNodeKey(cfg.NodeKeyFile())
  457. require.NoError(t, err)
  458. logger := log.NewNopLogger()
  459. ns, err := makeSeedNode(ctx,
  460. cfg,
  461. config.DefaultDBProvider,
  462. nodeKey,
  463. defaultGenesisDocProviderFunc(cfg),
  464. logger,
  465. )
  466. t.Cleanup(ns.Wait)
  467. t.Cleanup(leaktest.CheckTimeout(t, time.Second))
  468. require.NoError(t, err)
  469. n, ok := ns.(*seedNodeImpl)
  470. require.True(t, ok)
  471. err = n.Start(ctx)
  472. require.NoError(t, err)
  473. assert.True(t, n.pexReactor.IsRunning())
  474. cancel()
  475. n.Wait()
  476. assert.False(t, n.pexReactor.IsRunning())
  477. }
  478. func TestNodeSetEventSink(t *testing.T) {
  479. cfg, err := config.ResetTestRoot(t.TempDir(), "node_app_version_test")
  480. require.NoError(t, err)
  481. defer os.RemoveAll(cfg.RootDir)
  482. ctx, cancel := context.WithCancel(context.Background())
  483. defer cancel()
  484. logger := log.NewNopLogger()
  485. setupTest := func(t *testing.T, conf *config.Config) []indexer.EventSink {
  486. eventBus := eventbus.NewDefault(logger.With("module", "events"))
  487. require.NoError(t, eventBus.Start(ctx))
  488. t.Cleanup(eventBus.Wait)
  489. genDoc, err := types.GenesisDocFromFile(cfg.GenesisFile())
  490. require.NoError(t, err)
  491. indexService, eventSinks, err := createAndStartIndexerService(ctx, cfg,
  492. config.DefaultDBProvider, eventBus, logger, genDoc.ChainID,
  493. indexer.NopMetrics())
  494. require.NoError(t, err)
  495. t.Cleanup(indexService.Wait)
  496. return eventSinks
  497. }
  498. cleanup := func(ns service.Service) func() {
  499. return func() {
  500. n, ok := ns.(*nodeImpl)
  501. if !ok {
  502. return
  503. }
  504. if n == nil {
  505. return
  506. }
  507. if !n.IsRunning() {
  508. return
  509. }
  510. cancel()
  511. n.Wait()
  512. }
  513. }
  514. eventSinks := setupTest(t, cfg)
  515. assert.Equal(t, 1, len(eventSinks))
  516. assert.Equal(t, indexer.KV, eventSinks[0].Type())
  517. cfg.TxIndex.Indexer = []string{"null"}
  518. eventSinks = setupTest(t, cfg)
  519. assert.Equal(t, 1, len(eventSinks))
  520. assert.Equal(t, indexer.NULL, eventSinks[0].Type())
  521. cfg.TxIndex.Indexer = []string{"null", "kv"}
  522. eventSinks = setupTest(t, cfg)
  523. assert.Equal(t, 1, len(eventSinks))
  524. assert.Equal(t, indexer.NULL, eventSinks[0].Type())
  525. cfg.TxIndex.Indexer = []string{"kvv"}
  526. ns, err := newDefaultNode(ctx, cfg, logger)
  527. assert.Nil(t, ns)
  528. assert.Contains(t, err.Error(), "unsupported event sink type")
  529. t.Cleanup(cleanup(ns))
  530. cfg.TxIndex.Indexer = []string{}
  531. eventSinks = setupTest(t, cfg)
  532. assert.Equal(t, 1, len(eventSinks))
  533. assert.Equal(t, indexer.NULL, eventSinks[0].Type())
  534. cfg.TxIndex.Indexer = []string{"psql"}
  535. ns, err = newDefaultNode(ctx, cfg, logger)
  536. assert.Nil(t, ns)
  537. assert.Contains(t, err.Error(), "the psql connection settings cannot be empty")
  538. t.Cleanup(cleanup(ns))
  539. // N.B. We can't create a PSQL event sink without starting a postgres
  540. // instance for it to talk to. The indexer service tests exercise that case.
  541. var e = errors.New("found duplicated sinks, please check the tx-index section in the config.toml")
  542. cfg.TxIndex.Indexer = []string{"null", "kv", "Kv"}
  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. cfg.TxIndex.Indexer = []string{"Null", "kV", "kv", "nUlL"}
  548. ns, err = newDefaultNode(ctx, cfg, logger)
  549. require.Error(t, err)
  550. assert.Contains(t, err.Error(), e.Error())
  551. t.Cleanup(cleanup(ns))
  552. }
  553. func state(t *testing.T, nVals int, height int64) (sm.State, dbm.DB, []types.PrivValidator) {
  554. t.Helper()
  555. privVals := make([]types.PrivValidator, nVals)
  556. vals := make([]types.GenesisValidator, nVals)
  557. for i := 0; i < nVals; i++ {
  558. privVal := types.NewMockPV()
  559. privVals[i] = privVal
  560. vals[i] = types.GenesisValidator{
  561. Address: privVal.PrivKey.PubKey().Address(),
  562. PubKey: privVal.PrivKey.PubKey(),
  563. Power: 1000,
  564. Name: fmt.Sprintf("test%d", i),
  565. }
  566. }
  567. s, _ := sm.MakeGenesisState(&types.GenesisDoc{
  568. ChainID: "test-chain",
  569. Validators: vals,
  570. AppHash: nil,
  571. })
  572. // save validators to db for 2 heights
  573. stateDB := dbm.NewMemDB()
  574. t.Cleanup(func() { require.NoError(t, stateDB.Close()) })
  575. stateStore := sm.NewStore(stateDB)
  576. require.NoError(t, stateStore.Save(s))
  577. for i := 1; i < int(height); i++ {
  578. s.LastBlockHeight++
  579. s.LastValidators = s.Validators.Copy()
  580. require.NoError(t, stateStore.Save(s))
  581. }
  582. return s, stateDB, privVals
  583. }
  584. func TestLoadStateFromGenesis(t *testing.T) {
  585. ctx, cancel := context.WithCancel(context.Background())
  586. defer cancel()
  587. _ = loadStatefromGenesis(ctx, t)
  588. }
  589. func loadStatefromGenesis(ctx context.Context, t *testing.T) sm.State {
  590. t.Helper()
  591. stateDB := dbm.NewMemDB()
  592. stateStore := sm.NewStore(stateDB)
  593. cfg, err := config.ResetTestRoot(t.TempDir(), "load_state_from_genesis")
  594. require.NoError(t, err)
  595. loadedState, err := stateStore.Load()
  596. require.NoError(t, err)
  597. require.True(t, loadedState.IsEmpty())
  598. valSet, _ := factory.ValidatorSet(ctx, t, 0, 10)
  599. genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, nil)
  600. state, err := loadStateFromDBOrGenesisDocProvider(
  601. stateStore,
  602. genDoc,
  603. )
  604. require.NoError(t, err)
  605. require.NotNil(t, state)
  606. return state
  607. }