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