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.

609 lines
16 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
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
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. "bytes"
  4. "context"
  5. "errors"
  6. "fmt"
  7. "strings"
  8. "time"
  9. dbm "github.com/tendermint/tm-db"
  10. "github.com/tendermint/tendermint/config"
  11. "github.com/tendermint/tendermint/crypto"
  12. "github.com/tendermint/tendermint/internal/blocksync"
  13. "github.com/tendermint/tendermint/internal/consensus"
  14. "github.com/tendermint/tendermint/internal/eventbus"
  15. "github.com/tendermint/tendermint/internal/evidence"
  16. "github.com/tendermint/tendermint/internal/mempool"
  17. "github.com/tendermint/tendermint/internal/p2p"
  18. "github.com/tendermint/tendermint/internal/p2p/conn"
  19. "github.com/tendermint/tendermint/internal/p2p/pex"
  20. "github.com/tendermint/tendermint/internal/proxy"
  21. sm "github.com/tendermint/tendermint/internal/state"
  22. "github.com/tendermint/tendermint/internal/state/indexer"
  23. "github.com/tendermint/tendermint/internal/state/indexer/sink"
  24. "github.com/tendermint/tendermint/internal/statesync"
  25. "github.com/tendermint/tendermint/internal/store"
  26. "github.com/tendermint/tendermint/libs/log"
  27. tmnet "github.com/tendermint/tendermint/libs/net"
  28. "github.com/tendermint/tendermint/libs/service"
  29. tmstrings "github.com/tendermint/tendermint/libs/strings"
  30. "github.com/tendermint/tendermint/privval"
  31. tmgrpc "github.com/tendermint/tendermint/privval/grpc"
  32. "github.com/tendermint/tendermint/types"
  33. "github.com/tendermint/tendermint/version"
  34. _ "net/http/pprof" // nolint: gosec // securely exposed on separate, optional port
  35. )
  36. type closer func() error
  37. func makeCloser(cs []closer) closer {
  38. return func() error {
  39. errs := make([]string, 0, len(cs))
  40. for _, cl := range cs {
  41. if err := cl(); err != nil {
  42. errs = append(errs, err.Error())
  43. }
  44. }
  45. if len(errs) >= 0 {
  46. return errors.New(strings.Join(errs, "; "))
  47. }
  48. return nil
  49. }
  50. }
  51. func convertCancelCloser(cancel context.CancelFunc) closer {
  52. return func() error { cancel(); return nil }
  53. }
  54. func combineCloseError(err error, cl closer) error {
  55. if err == nil {
  56. return cl()
  57. }
  58. clerr := cl()
  59. if clerr == nil {
  60. return err
  61. }
  62. return fmt.Errorf("error=%q closerError=%q", err.Error(), clerr.Error())
  63. }
  64. func initDBs(
  65. cfg *config.Config,
  66. dbProvider config.DBProvider,
  67. ) (*store.BlockStore, dbm.DB, closer, error) {
  68. blockStoreDB, err := dbProvider(&config.DBContext{ID: "blockstore", Config: cfg})
  69. if err != nil {
  70. return nil, nil, func() error { return nil }, fmt.Errorf("unable to initialize blockstore: %w", err)
  71. }
  72. closers := []closer{}
  73. blockStore := store.NewBlockStore(blockStoreDB)
  74. closers = append(closers, blockStoreDB.Close)
  75. stateDB, err := dbProvider(&config.DBContext{ID: "state", Config: cfg})
  76. if err != nil {
  77. return nil, nil, makeCloser(closers), fmt.Errorf("unable to initialize statestore: %w", err)
  78. }
  79. closers = append(closers, stateDB.Close)
  80. return blockStore, stateDB, makeCloser(closers), nil
  81. }
  82. func createAndStartIndexerService(
  83. ctx context.Context,
  84. cfg *config.Config,
  85. dbProvider config.DBProvider,
  86. eventBus *eventbus.EventBus,
  87. logger log.Logger,
  88. chainID string,
  89. metrics *indexer.Metrics,
  90. ) (*indexer.Service, []indexer.EventSink, error) {
  91. eventSinks, err := sink.EventSinksFromConfig(cfg, dbProvider, chainID)
  92. if err != nil {
  93. return nil, nil, err
  94. }
  95. indexerService := indexer.NewService(indexer.ServiceArgs{
  96. Sinks: eventSinks,
  97. EventBus: eventBus,
  98. Logger: logger.With("module", "txindex"),
  99. Metrics: metrics,
  100. })
  101. if err := indexerService.Start(ctx); err != nil {
  102. return nil, nil, err
  103. }
  104. return indexerService, eventSinks, nil
  105. }
  106. func logNodeStartupInfo(state sm.State, pubKey crypto.PubKey, logger log.Logger, mode string) {
  107. // Log the version info.
  108. logger.Info("Version info",
  109. "tmVersion", version.TMVersion,
  110. "block", version.BlockProtocol,
  111. "p2p", version.P2PProtocol,
  112. "mode", mode,
  113. )
  114. // If the state and software differ in block version, at least log it.
  115. if state.Version.Consensus.Block != version.BlockProtocol {
  116. logger.Info("Software and state have different block protocols",
  117. "software", version.BlockProtocol,
  118. "state", state.Version.Consensus.Block,
  119. )
  120. }
  121. switch mode {
  122. case config.ModeFull:
  123. logger.Info("This node is a fullnode")
  124. case config.ModeValidator:
  125. addr := pubKey.Address()
  126. // Log whether this node is a validator or an observer
  127. if state.Validators.HasAddress(addr) {
  128. logger.Info("This node is a validator",
  129. "addr", addr,
  130. "pubKey", pubKey.Bytes(),
  131. )
  132. } else {
  133. logger.Info("This node is a validator (NOT in the active validator set)",
  134. "addr", addr,
  135. "pubKey", pubKey.Bytes(),
  136. )
  137. }
  138. }
  139. }
  140. func onlyValidatorIsUs(state sm.State, pubKey crypto.PubKey) bool {
  141. if state.Validators.Size() > 1 {
  142. return false
  143. }
  144. addr, _ := state.Validators.GetByIndex(0)
  145. return pubKey != nil && bytes.Equal(pubKey.Address(), addr)
  146. }
  147. func createMempoolReactor(
  148. ctx context.Context,
  149. cfg *config.Config,
  150. proxyApp proxy.AppConns,
  151. state sm.State,
  152. memplMetrics *mempool.Metrics,
  153. peerManager *p2p.PeerManager,
  154. router *p2p.Router,
  155. logger log.Logger,
  156. ) (service.Service, mempool.Mempool, error) {
  157. logger = logger.With("module", "mempool")
  158. mp := mempool.NewTxMempool(
  159. logger,
  160. cfg.Mempool,
  161. proxyApp.Mempool(),
  162. state.LastBlockHeight,
  163. mempool.WithMetrics(memplMetrics),
  164. mempool.WithPreCheck(sm.TxPreCheck(state)),
  165. mempool.WithPostCheck(sm.TxPostCheck(state)),
  166. )
  167. reactor, err := mempool.NewReactor(
  168. ctx,
  169. logger,
  170. cfg.Mempool,
  171. peerManager,
  172. mp,
  173. router.OpenChannel,
  174. peerManager.Subscribe(ctx),
  175. )
  176. if err != nil {
  177. return nil, nil, err
  178. }
  179. if cfg.Consensus.WaitForTxs() {
  180. mp.EnableTxsAvailable()
  181. }
  182. return reactor, mp, nil
  183. }
  184. func createEvidenceReactor(
  185. ctx context.Context,
  186. cfg *config.Config,
  187. dbProvider config.DBProvider,
  188. stateDB dbm.DB,
  189. blockStore *store.BlockStore,
  190. peerManager *p2p.PeerManager,
  191. router *p2p.Router,
  192. logger log.Logger,
  193. metrics *evidence.Metrics,
  194. eventBus *eventbus.EventBus,
  195. ) (*evidence.Reactor, *evidence.Pool, error) {
  196. evidenceDB, err := dbProvider(&config.DBContext{ID: "evidence", Config: cfg})
  197. if err != nil {
  198. return nil, nil, fmt.Errorf("unable to initialize evidence db: %w", err)
  199. }
  200. logger = logger.With("module", "evidence")
  201. evidencePool, err := evidence.NewPool(logger, evidenceDB, sm.NewStore(stateDB), blockStore, metrics)
  202. if err != nil {
  203. return nil, nil, fmt.Errorf("creating evidence pool: %w", err)
  204. }
  205. evidencePool.SetEventBus(eventBus)
  206. evidenceReactor, err := evidence.NewReactor(
  207. ctx,
  208. logger,
  209. router.OpenChannel,
  210. peerManager.Subscribe(ctx),
  211. evidencePool,
  212. )
  213. if err != nil {
  214. return nil, nil, fmt.Errorf("creating evidence reactor: %w", err)
  215. }
  216. return evidenceReactor, evidencePool, nil
  217. }
  218. func createConsensusReactor(
  219. ctx context.Context,
  220. cfg *config.Config,
  221. state sm.State,
  222. blockExec *sm.BlockExecutor,
  223. blockStore sm.BlockStore,
  224. mp mempool.Mempool,
  225. evidencePool *evidence.Pool,
  226. privValidator types.PrivValidator,
  227. csMetrics *consensus.Metrics,
  228. waitSync bool,
  229. eventBus *eventbus.EventBus,
  230. peerManager *p2p.PeerManager,
  231. router *p2p.Router,
  232. logger log.Logger,
  233. ) (*consensus.Reactor, *consensus.State, error) {
  234. logger = logger.With("module", "consensus")
  235. consensusState := consensus.NewState(ctx,
  236. logger,
  237. cfg.Consensus,
  238. state.Copy(),
  239. blockExec,
  240. blockStore,
  241. mp,
  242. evidencePool,
  243. consensus.StateMetrics(csMetrics),
  244. )
  245. if privValidator != nil && cfg.Mode == config.ModeValidator {
  246. consensusState.SetPrivValidator(ctx, privValidator)
  247. }
  248. reactor, err := consensus.NewReactor(
  249. ctx,
  250. logger,
  251. consensusState,
  252. router.OpenChannel,
  253. peerManager.Subscribe(ctx),
  254. waitSync,
  255. csMetrics,
  256. )
  257. if err != nil {
  258. return nil, nil, err
  259. }
  260. // Services which will be publishing and/or subscribing for messages (events)
  261. // consensusReactor will set it on consensusState and blockExecutor.
  262. reactor.SetEventBus(eventBus)
  263. return reactor, consensusState, nil
  264. }
  265. func createPeerManager(
  266. cfg *config.Config,
  267. dbProvider config.DBProvider,
  268. nodeID types.NodeID,
  269. ) (*p2p.PeerManager, closer, error) {
  270. selfAddr, err := p2p.ParseNodeAddress(nodeID.AddressString(cfg.P2P.ExternalAddress))
  271. if err != nil {
  272. return nil, func() error { return nil }, fmt.Errorf("couldn't parse ExternalAddress %q: %w", cfg.P2P.ExternalAddress, err)
  273. }
  274. privatePeerIDs := make(map[types.NodeID]struct{})
  275. for _, id := range tmstrings.SplitAndTrimEmpty(cfg.P2P.PrivatePeerIDs, ",", " ") {
  276. privatePeerIDs[types.NodeID(id)] = struct{}{}
  277. }
  278. var maxConns uint16
  279. switch {
  280. case cfg.P2P.MaxConnections > 0:
  281. maxConns = cfg.P2P.MaxConnections
  282. default:
  283. maxConns = 64
  284. }
  285. options := p2p.PeerManagerOptions{
  286. SelfAddress: selfAddr,
  287. MaxConnected: maxConns,
  288. MaxConnectedUpgrade: 4,
  289. MaxPeers: 1000,
  290. MinRetryTime: 250 * time.Millisecond,
  291. MaxRetryTime: 30 * time.Minute,
  292. MaxRetryTimePersistent: 5 * time.Minute,
  293. RetryTimeJitter: 5 * time.Second,
  294. PrivatePeers: privatePeerIDs,
  295. }
  296. peers := []p2p.NodeAddress{}
  297. for _, p := range tmstrings.SplitAndTrimEmpty(cfg.P2P.PersistentPeers, ",", " ") {
  298. address, err := p2p.ParseNodeAddress(p)
  299. if err != nil {
  300. return nil, func() error { return nil }, fmt.Errorf("invalid peer address %q: %w", p, err)
  301. }
  302. peers = append(peers, address)
  303. options.PersistentPeers = append(options.PersistentPeers, address.NodeID)
  304. }
  305. for _, p := range tmstrings.SplitAndTrimEmpty(cfg.P2P.BootstrapPeers, ",", " ") {
  306. address, err := p2p.ParseNodeAddress(p)
  307. if err != nil {
  308. return nil, func() error { return nil }, fmt.Errorf("invalid peer address %q: %w", p, err)
  309. }
  310. peers = append(peers, address)
  311. }
  312. peerDB, err := dbProvider(&config.DBContext{ID: "peerstore", Config: cfg})
  313. if err != nil {
  314. return nil, func() error { return nil }, fmt.Errorf("unable to initialize peer store: %w", err)
  315. }
  316. peerManager, err := p2p.NewPeerManager(nodeID, peerDB, options)
  317. if err != nil {
  318. return nil, peerDB.Close, fmt.Errorf("failed to create peer manager: %w", err)
  319. }
  320. for _, peer := range peers {
  321. if _, err := peerManager.Add(peer); err != nil {
  322. return nil, peerDB.Close, fmt.Errorf("failed to add peer %q: %w", peer, err)
  323. }
  324. }
  325. return peerManager, peerDB.Close, nil
  326. }
  327. func createRouter(
  328. ctx context.Context,
  329. logger log.Logger,
  330. p2pMetrics *p2p.Metrics,
  331. nodeInfo types.NodeInfo,
  332. nodeKey types.NodeKey,
  333. peerManager *p2p.PeerManager,
  334. cfg *config.Config,
  335. proxyApp proxy.AppConns,
  336. ) (*p2p.Router, error) {
  337. p2pLogger := logger.With("module", "p2p")
  338. transportConf := conn.DefaultMConnConfig()
  339. transportConf.FlushThrottle = cfg.P2P.FlushThrottleTimeout
  340. transportConf.SendRate = cfg.P2P.SendRate
  341. transportConf.RecvRate = cfg.P2P.RecvRate
  342. transportConf.MaxPacketMsgPayloadSize = cfg.P2P.MaxPacketMsgPayloadSize
  343. transport := p2p.NewMConnTransport(
  344. p2pLogger, transportConf, []*p2p.ChannelDescriptor{},
  345. p2p.MConnTransportOptions{
  346. MaxAcceptedConnections: uint32(cfg.P2P.MaxConnections),
  347. },
  348. )
  349. ep, err := p2p.NewEndpoint(nodeKey.ID.AddressString(cfg.P2P.ListenAddress))
  350. if err != nil {
  351. return nil, err
  352. }
  353. return p2p.NewRouter(
  354. ctx,
  355. p2pLogger,
  356. p2pMetrics,
  357. nodeInfo,
  358. nodeKey.PrivKey,
  359. peerManager,
  360. []p2p.Transport{transport},
  361. []p2p.Endpoint{ep},
  362. getRouterConfig(cfg, proxyApp),
  363. )
  364. }
  365. func makeNodeInfo(
  366. cfg *config.Config,
  367. nodeKey types.NodeKey,
  368. eventSinks []indexer.EventSink,
  369. genDoc *types.GenesisDoc,
  370. state sm.State,
  371. ) (types.NodeInfo, error) {
  372. txIndexerStatus := "off"
  373. if indexer.IndexingEnabled(eventSinks) {
  374. txIndexerStatus = "on"
  375. }
  376. nodeInfo := types.NodeInfo{
  377. ProtocolVersion: types.ProtocolVersion{
  378. P2P: version.P2PProtocol, // global
  379. Block: state.Version.Consensus.Block,
  380. App: state.Version.Consensus.App,
  381. },
  382. NodeID: nodeKey.ID,
  383. Network: genDoc.ChainID,
  384. Version: version.TMVersion,
  385. Channels: []byte{
  386. byte(blocksync.BlockSyncChannel),
  387. byte(consensus.StateChannel),
  388. byte(consensus.DataChannel),
  389. byte(consensus.VoteChannel),
  390. byte(consensus.VoteSetBitsChannel),
  391. byte(mempool.MempoolChannel),
  392. byte(evidence.EvidenceChannel),
  393. byte(statesync.SnapshotChannel),
  394. byte(statesync.ChunkChannel),
  395. byte(statesync.LightBlockChannel),
  396. byte(statesync.ParamsChannel),
  397. },
  398. Moniker: cfg.Moniker,
  399. Other: types.NodeInfoOther{
  400. TxIndex: txIndexerStatus,
  401. RPCAddress: cfg.RPC.ListenAddress,
  402. },
  403. }
  404. if cfg.P2P.PexReactor {
  405. nodeInfo.Channels = append(nodeInfo.Channels, pex.PexChannel)
  406. }
  407. nodeInfo.ListenAddr = cfg.P2P.ExternalAddress
  408. if nodeInfo.ListenAddr == "" {
  409. nodeInfo.ListenAddr = cfg.P2P.ListenAddress
  410. }
  411. return nodeInfo, nodeInfo.Validate()
  412. }
  413. func makeSeedNodeInfo(
  414. cfg *config.Config,
  415. nodeKey types.NodeKey,
  416. genDoc *types.GenesisDoc,
  417. state sm.State,
  418. ) (types.NodeInfo, error) {
  419. nodeInfo := types.NodeInfo{
  420. ProtocolVersion: types.ProtocolVersion{
  421. P2P: version.P2PProtocol, // global
  422. Block: state.Version.Consensus.Block,
  423. App: state.Version.Consensus.App,
  424. },
  425. NodeID: nodeKey.ID,
  426. Network: genDoc.ChainID,
  427. Version: version.TMVersion,
  428. Channels: []byte{
  429. pex.PexChannel,
  430. },
  431. Moniker: cfg.Moniker,
  432. Other: types.NodeInfoOther{
  433. TxIndex: "off",
  434. RPCAddress: cfg.RPC.ListenAddress,
  435. },
  436. }
  437. nodeInfo.ListenAddr = cfg.P2P.ExternalAddress
  438. if nodeInfo.ListenAddr == "" {
  439. nodeInfo.ListenAddr = cfg.P2P.ListenAddress
  440. }
  441. return nodeInfo, nodeInfo.Validate()
  442. }
  443. func createAndStartPrivValidatorSocketClient(
  444. ctx context.Context,
  445. listenAddr, chainID string,
  446. logger log.Logger,
  447. ) (types.PrivValidator, error) {
  448. pve, err := privval.NewSignerListener(listenAddr, logger)
  449. if err != nil {
  450. return nil, fmt.Errorf("starting validator listener: %w", err)
  451. }
  452. pvsc, err := privval.NewSignerClient(ctx, pve, chainID)
  453. if err != nil {
  454. return nil, fmt.Errorf("starting validator client: %w", err)
  455. }
  456. // try to get a pubkey from private validate first time
  457. _, err = pvsc.GetPubKey(ctx)
  458. if err != nil {
  459. return nil, fmt.Errorf("can't get pubkey: %w", err)
  460. }
  461. const (
  462. timeout = 100 * time.Millisecond
  463. maxTime = 5 * time.Second
  464. retries = int(maxTime / timeout)
  465. )
  466. pvscWithRetries := privval.NewRetrySignerClient(pvsc, retries, timeout)
  467. return pvscWithRetries, nil
  468. }
  469. func createAndStartPrivValidatorGRPCClient(
  470. ctx context.Context,
  471. cfg *config.Config,
  472. chainID string,
  473. logger log.Logger,
  474. ) (types.PrivValidator, error) {
  475. pvsc, err := tmgrpc.DialRemoteSigner(
  476. ctx,
  477. cfg.PrivValidator,
  478. chainID,
  479. logger,
  480. cfg.Instrumentation.Prometheus,
  481. )
  482. if err != nil {
  483. return nil, fmt.Errorf("failed to start private validator: %w", err)
  484. }
  485. // try to get a pubkey from private validate first time
  486. _, err = pvsc.GetPubKey(ctx)
  487. if err != nil {
  488. return nil, fmt.Errorf("can't get pubkey: %w", err)
  489. }
  490. return pvsc, nil
  491. }
  492. func makeDefaultPrivval(conf *config.Config) (*privval.FilePV, error) {
  493. if conf.Mode == config.ModeValidator {
  494. pval, err := privval.LoadOrGenFilePV(conf.PrivValidator.KeyFile(), conf.PrivValidator.StateFile())
  495. if err != nil {
  496. return nil, err
  497. }
  498. return pval, nil
  499. }
  500. return nil, nil
  501. }
  502. func createPrivval(ctx context.Context, logger log.Logger, conf *config.Config, genDoc *types.GenesisDoc, defaultPV *privval.FilePV) (types.PrivValidator, error) {
  503. if conf.PrivValidator.ListenAddr != "" {
  504. protocol, _ := tmnet.ProtocolAndAddress(conf.PrivValidator.ListenAddr)
  505. // FIXME: we should return un-started services and
  506. // then start them later.
  507. switch protocol {
  508. case "grpc":
  509. privValidator, err := createAndStartPrivValidatorGRPCClient(ctx, conf, genDoc.ChainID, logger)
  510. if err != nil {
  511. return nil, fmt.Errorf("error with private validator grpc client: %w", err)
  512. }
  513. return privValidator, nil
  514. default:
  515. privValidator, err := createAndStartPrivValidatorSocketClient(
  516. ctx,
  517. conf.PrivValidator.ListenAddr,
  518. genDoc.ChainID,
  519. logger,
  520. )
  521. if err != nil {
  522. return nil, fmt.Errorf("error with private validator socket client: %w", err)
  523. }
  524. return privValidator, nil
  525. }
  526. }
  527. return defaultPV, nil
  528. }