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.

606 lines
15 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. ) (*evidence.Reactor, *evidence.Pool, error) {
  194. evidenceDB, err := dbProvider(&config.DBContext{ID: "evidence", Config: cfg})
  195. if err != nil {
  196. return nil, nil, fmt.Errorf("unable to initialize evidence db: %w", err)
  197. }
  198. logger = logger.With("module", "evidence")
  199. evidencePool, err := evidence.NewPool(logger, evidenceDB, sm.NewStore(stateDB), blockStore)
  200. if err != nil {
  201. return nil, nil, fmt.Errorf("creating evidence pool: %w", err)
  202. }
  203. evidenceReactor, err := evidence.NewReactor(
  204. ctx,
  205. logger,
  206. router.OpenChannel,
  207. peerManager.Subscribe(ctx),
  208. evidencePool,
  209. )
  210. if err != nil {
  211. return nil, nil, fmt.Errorf("creating evidence reactor: %w", err)
  212. }
  213. return evidenceReactor, evidencePool, nil
  214. }
  215. func createConsensusReactor(
  216. ctx context.Context,
  217. cfg *config.Config,
  218. state sm.State,
  219. blockExec *sm.BlockExecutor,
  220. blockStore sm.BlockStore,
  221. mp mempool.Mempool,
  222. evidencePool *evidence.Pool,
  223. privValidator types.PrivValidator,
  224. csMetrics *consensus.Metrics,
  225. waitSync bool,
  226. eventBus *eventbus.EventBus,
  227. peerManager *p2p.PeerManager,
  228. router *p2p.Router,
  229. logger log.Logger,
  230. ) (*consensus.Reactor, *consensus.State, error) {
  231. logger = logger.With("module", "consensus")
  232. consensusState := consensus.NewState(ctx,
  233. logger,
  234. cfg.Consensus,
  235. state.Copy(),
  236. blockExec,
  237. blockStore,
  238. mp,
  239. evidencePool,
  240. consensus.StateMetrics(csMetrics),
  241. )
  242. if privValidator != nil && cfg.Mode == config.ModeValidator {
  243. consensusState.SetPrivValidator(ctx, privValidator)
  244. }
  245. reactor, err := consensus.NewReactor(
  246. ctx,
  247. logger,
  248. consensusState,
  249. router.OpenChannel,
  250. peerManager.Subscribe(ctx),
  251. waitSync,
  252. csMetrics,
  253. )
  254. if err != nil {
  255. return nil, nil, err
  256. }
  257. // Services which will be publishing and/or subscribing for messages (events)
  258. // consensusReactor will set it on consensusState and blockExecutor.
  259. reactor.SetEventBus(eventBus)
  260. return reactor, consensusState, nil
  261. }
  262. func createPeerManager(
  263. cfg *config.Config,
  264. dbProvider config.DBProvider,
  265. nodeID types.NodeID,
  266. ) (*p2p.PeerManager, closer, error) {
  267. selfAddr, err := p2p.ParseNodeAddress(nodeID.AddressString(cfg.P2P.ExternalAddress))
  268. if err != nil {
  269. return nil, func() error { return nil }, fmt.Errorf("couldn't parse ExternalAddress %q: %w", cfg.P2P.ExternalAddress, err)
  270. }
  271. privatePeerIDs := make(map[types.NodeID]struct{})
  272. for _, id := range tmstrings.SplitAndTrimEmpty(cfg.P2P.PrivatePeerIDs, ",", " ") {
  273. privatePeerIDs[types.NodeID(id)] = struct{}{}
  274. }
  275. var maxConns uint16
  276. switch {
  277. case cfg.P2P.MaxConnections > 0:
  278. maxConns = cfg.P2P.MaxConnections
  279. default:
  280. maxConns = 64
  281. }
  282. options := p2p.PeerManagerOptions{
  283. SelfAddress: selfAddr,
  284. MaxConnected: maxConns,
  285. MaxConnectedUpgrade: 4,
  286. MaxPeers: 1000,
  287. MinRetryTime: 100 * time.Millisecond,
  288. MaxRetryTime: 8 * time.Hour,
  289. MaxRetryTimePersistent: 5 * time.Minute,
  290. RetryTimeJitter: 3 * time.Second,
  291. PrivatePeers: privatePeerIDs,
  292. }
  293. peers := []p2p.NodeAddress{}
  294. for _, p := range tmstrings.SplitAndTrimEmpty(cfg.P2P.PersistentPeers, ",", " ") {
  295. address, err := p2p.ParseNodeAddress(p)
  296. if err != nil {
  297. return nil, func() error { return nil }, fmt.Errorf("invalid peer address %q: %w", p, err)
  298. }
  299. peers = append(peers, address)
  300. options.PersistentPeers = append(options.PersistentPeers, address.NodeID)
  301. }
  302. for _, p := range tmstrings.SplitAndTrimEmpty(cfg.P2P.BootstrapPeers, ",", " ") {
  303. address, err := p2p.ParseNodeAddress(p)
  304. if err != nil {
  305. return nil, func() error { return nil }, fmt.Errorf("invalid peer address %q: %w", p, err)
  306. }
  307. peers = append(peers, address)
  308. }
  309. peerDB, err := dbProvider(&config.DBContext{ID: "peerstore", Config: cfg})
  310. if err != nil {
  311. return nil, func() error { return nil }, fmt.Errorf("unable to initialize peer store: %w", err)
  312. }
  313. peerManager, err := p2p.NewPeerManager(nodeID, peerDB, options)
  314. if err != nil {
  315. return nil, peerDB.Close, fmt.Errorf("failed to create peer manager: %w", err)
  316. }
  317. for _, peer := range peers {
  318. if _, err := peerManager.Add(peer); err != nil {
  319. return nil, peerDB.Close, fmt.Errorf("failed to add peer %q: %w", peer, err)
  320. }
  321. }
  322. return peerManager, peerDB.Close, nil
  323. }
  324. func createRouter(
  325. ctx context.Context,
  326. logger log.Logger,
  327. p2pMetrics *p2p.Metrics,
  328. nodeInfo types.NodeInfo,
  329. nodeKey types.NodeKey,
  330. peerManager *p2p.PeerManager,
  331. cfg *config.Config,
  332. proxyApp proxy.AppConns,
  333. ) (*p2p.Router, error) {
  334. p2pLogger := logger.With("module", "p2p")
  335. transportConf := conn.DefaultMConnConfig()
  336. transportConf.FlushThrottle = cfg.P2P.FlushThrottleTimeout
  337. transportConf.SendRate = cfg.P2P.SendRate
  338. transportConf.RecvRate = cfg.P2P.RecvRate
  339. transportConf.MaxPacketMsgPayloadSize = cfg.P2P.MaxPacketMsgPayloadSize
  340. transport := p2p.NewMConnTransport(
  341. p2pLogger, transportConf, []*p2p.ChannelDescriptor{},
  342. p2p.MConnTransportOptions{
  343. MaxAcceptedConnections: uint32(cfg.P2P.MaxConnections),
  344. },
  345. )
  346. ep, err := p2p.NewEndpoint(nodeKey.ID.AddressString(cfg.P2P.ListenAddress))
  347. if err != nil {
  348. return nil, err
  349. }
  350. return p2p.NewRouter(
  351. ctx,
  352. p2pLogger,
  353. p2pMetrics,
  354. nodeInfo,
  355. nodeKey.PrivKey,
  356. peerManager,
  357. []p2p.Transport{transport},
  358. []p2p.Endpoint{ep},
  359. getRouterConfig(cfg, proxyApp),
  360. )
  361. }
  362. func makeNodeInfo(
  363. cfg *config.Config,
  364. nodeKey types.NodeKey,
  365. eventSinks []indexer.EventSink,
  366. genDoc *types.GenesisDoc,
  367. state sm.State,
  368. ) (types.NodeInfo, error) {
  369. txIndexerStatus := "off"
  370. if indexer.IndexingEnabled(eventSinks) {
  371. txIndexerStatus = "on"
  372. }
  373. nodeInfo := types.NodeInfo{
  374. ProtocolVersion: types.ProtocolVersion{
  375. P2P: version.P2PProtocol, // global
  376. Block: state.Version.Consensus.Block,
  377. App: state.Version.Consensus.App,
  378. },
  379. NodeID: nodeKey.ID,
  380. Network: genDoc.ChainID,
  381. Version: version.TMVersion,
  382. Channels: []byte{
  383. byte(blocksync.BlockSyncChannel),
  384. byte(consensus.StateChannel),
  385. byte(consensus.DataChannel),
  386. byte(consensus.VoteChannel),
  387. byte(consensus.VoteSetBitsChannel),
  388. byte(mempool.MempoolChannel),
  389. byte(evidence.EvidenceChannel),
  390. byte(statesync.SnapshotChannel),
  391. byte(statesync.ChunkChannel),
  392. byte(statesync.LightBlockChannel),
  393. byte(statesync.ParamsChannel),
  394. },
  395. Moniker: cfg.Moniker,
  396. Other: types.NodeInfoOther{
  397. TxIndex: txIndexerStatus,
  398. RPCAddress: cfg.RPC.ListenAddress,
  399. },
  400. }
  401. if cfg.P2P.PexReactor {
  402. nodeInfo.Channels = append(nodeInfo.Channels, pex.PexChannel)
  403. }
  404. nodeInfo.ListenAddr = cfg.P2P.ExternalAddress
  405. if nodeInfo.ListenAddr == "" {
  406. nodeInfo.ListenAddr = cfg.P2P.ListenAddress
  407. }
  408. return nodeInfo, nodeInfo.Validate()
  409. }
  410. func makeSeedNodeInfo(
  411. cfg *config.Config,
  412. nodeKey types.NodeKey,
  413. genDoc *types.GenesisDoc,
  414. state sm.State,
  415. ) (types.NodeInfo, error) {
  416. nodeInfo := types.NodeInfo{
  417. ProtocolVersion: types.ProtocolVersion{
  418. P2P: version.P2PProtocol, // global
  419. Block: state.Version.Consensus.Block,
  420. App: state.Version.Consensus.App,
  421. },
  422. NodeID: nodeKey.ID,
  423. Network: genDoc.ChainID,
  424. Version: version.TMVersion,
  425. Channels: []byte{
  426. pex.PexChannel,
  427. },
  428. Moniker: cfg.Moniker,
  429. Other: types.NodeInfoOther{
  430. TxIndex: "off",
  431. RPCAddress: cfg.RPC.ListenAddress,
  432. },
  433. }
  434. nodeInfo.ListenAddr = cfg.P2P.ExternalAddress
  435. if nodeInfo.ListenAddr == "" {
  436. nodeInfo.ListenAddr = cfg.P2P.ListenAddress
  437. }
  438. return nodeInfo, nodeInfo.Validate()
  439. }
  440. func createAndStartPrivValidatorSocketClient(
  441. ctx context.Context,
  442. listenAddr, chainID string,
  443. logger log.Logger,
  444. ) (types.PrivValidator, error) {
  445. pve, err := privval.NewSignerListener(listenAddr, logger)
  446. if err != nil {
  447. return nil, fmt.Errorf("starting validator listener: %w", err)
  448. }
  449. pvsc, err := privval.NewSignerClient(ctx, pve, chainID)
  450. if err != nil {
  451. return nil, fmt.Errorf("starting validator client: %w", err)
  452. }
  453. // try to get a pubkey from private validate first time
  454. _, err = pvsc.GetPubKey(ctx)
  455. if err != nil {
  456. return nil, fmt.Errorf("can't get pubkey: %w", err)
  457. }
  458. const (
  459. timeout = 100 * time.Millisecond
  460. maxTime = 5 * time.Second
  461. retries = int(maxTime / timeout)
  462. )
  463. pvscWithRetries := privval.NewRetrySignerClient(pvsc, retries, timeout)
  464. return pvscWithRetries, nil
  465. }
  466. func createAndStartPrivValidatorGRPCClient(
  467. ctx context.Context,
  468. cfg *config.Config,
  469. chainID string,
  470. logger log.Logger,
  471. ) (types.PrivValidator, error) {
  472. pvsc, err := tmgrpc.DialRemoteSigner(
  473. ctx,
  474. cfg.PrivValidator,
  475. chainID,
  476. logger,
  477. cfg.Instrumentation.Prometheus,
  478. )
  479. if err != nil {
  480. return nil, fmt.Errorf("failed to start private validator: %w", err)
  481. }
  482. // try to get a pubkey from private validate first time
  483. _, err = pvsc.GetPubKey(ctx)
  484. if err != nil {
  485. return nil, fmt.Errorf("can't get pubkey: %w", err)
  486. }
  487. return pvsc, nil
  488. }
  489. func makeDefaultPrivval(conf *config.Config) (*privval.FilePV, error) {
  490. if conf.Mode == config.ModeValidator {
  491. pval, err := privval.LoadOrGenFilePV(conf.PrivValidator.KeyFile(), conf.PrivValidator.StateFile())
  492. if err != nil {
  493. return nil, err
  494. }
  495. return pval, nil
  496. }
  497. return nil, nil
  498. }
  499. func createPrivval(ctx context.Context, logger log.Logger, conf *config.Config, genDoc *types.GenesisDoc, defaultPV *privval.FilePV) (types.PrivValidator, error) {
  500. if conf.PrivValidator.ListenAddr != "" {
  501. protocol, _ := tmnet.ProtocolAndAddress(conf.PrivValidator.ListenAddr)
  502. // FIXME: we should return un-started services and
  503. // then start them later.
  504. switch protocol {
  505. case "grpc":
  506. privValidator, err := createAndStartPrivValidatorGRPCClient(ctx, conf, genDoc.ChainID, logger)
  507. if err != nil {
  508. return nil, fmt.Errorf("error with private validator grpc client: %w", err)
  509. }
  510. return privValidator, nil
  511. default:
  512. privValidator, err := createAndStartPrivValidatorSocketClient(
  513. ctx,
  514. conf.PrivValidator.ListenAddr,
  515. genDoc.ChainID,
  516. logger,
  517. )
  518. if err != nil {
  519. return nil, fmt.Errorf("error with private validator socket client: %w", err)
  520. }
  521. return privValidator, nil
  522. }
  523. }
  524. return defaultPV, nil
  525. }