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.

605 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, error) {
  195. evidenceDB, err := dbProvider(&config.DBContext{ID: "evidence", Config: cfg})
  196. if err != nil {
  197. return nil, nil, fmt.Errorf("unable to initialize evidence db: %w", err)
  198. }
  199. logger = logger.With("module", "evidence")
  200. evidencePool := evidence.NewPool(logger, evidenceDB, store, blockStore, metrics, eventBus)
  201. evidenceReactor, err := evidence.NewReactor(
  202. ctx,
  203. logger,
  204. router.OpenChannel,
  205. peerManager.Subscribe(ctx),
  206. evidencePool,
  207. )
  208. if err != nil {
  209. return nil, nil, fmt.Errorf("creating evidence reactor: %w", err)
  210. }
  211. return evidenceReactor, evidencePool, nil
  212. }
  213. func createConsensusReactor(
  214. ctx context.Context,
  215. cfg *config.Config,
  216. store sm.Store,
  217. blockExec *sm.BlockExecutor,
  218. blockStore sm.BlockStore,
  219. mp mempool.Mempool,
  220. evidencePool *evidence.Pool,
  221. privValidator types.PrivValidator,
  222. csMetrics *consensus.Metrics,
  223. waitSync bool,
  224. eventBus *eventbus.EventBus,
  225. peerManager *p2p.PeerManager,
  226. router *p2p.Router,
  227. logger log.Logger,
  228. ) (*consensus.Reactor, *consensus.State, error) {
  229. logger = logger.With("module", "consensus")
  230. consensusState, err := consensus.NewState(ctx,
  231. logger,
  232. cfg.Consensus,
  233. store,
  234. blockExec,
  235. blockStore,
  236. mp,
  237. evidencePool,
  238. eventBus,
  239. consensus.StateMetrics(csMetrics),
  240. )
  241. if err != nil {
  242. return nil, nil, err
  243. }
  244. if privValidator != nil && cfg.Mode == config.ModeValidator {
  245. consensusState.SetPrivValidator(ctx, privValidator)
  246. }
  247. reactor, err := consensus.NewReactor(
  248. ctx,
  249. logger,
  250. consensusState,
  251. router.OpenChannel,
  252. peerManager.Subscribe(ctx),
  253. eventBus,
  254. waitSync,
  255. csMetrics,
  256. )
  257. if err != nil {
  258. return nil, nil, err
  259. }
  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: 250 * time.Millisecond,
  288. MaxRetryTime: 30 * time.Minute,
  289. MaxRetryTimePersistent: 5 * time.Minute,
  290. RetryTimeJitter: 5 * 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. appClient abciclient.Client,
  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, appClient),
  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. }