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.

562 lines
14 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
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
  1. package node
  2. import (
  3. "bytes"
  4. "context"
  5. "errors"
  6. "fmt"
  7. "strings"
  8. "time"
  9. dbm "github.com/tendermint/tm-db"
  10. "github.com/tendermint/tendermint/config"
  11. "github.com/tendermint/tendermint/crypto"
  12. "github.com/tendermint/tendermint/internal/blocksync"
  13. "github.com/tendermint/tendermint/internal/consensus"
  14. "github.com/tendermint/tendermint/internal/eventbus"
  15. "github.com/tendermint/tendermint/internal/evidence"
  16. "github.com/tendermint/tendermint/internal/mempool"
  17. "github.com/tendermint/tendermint/internal/p2p"
  18. "github.com/tendermint/tendermint/internal/p2p/conn"
  19. "github.com/tendermint/tendermint/internal/p2p/pex"
  20. "github.com/tendermint/tendermint/internal/proxy"
  21. sm "github.com/tendermint/tendermint/internal/state"
  22. "github.com/tendermint/tendermint/internal/state/indexer"
  23. "github.com/tendermint/tendermint/internal/state/indexer/sink"
  24. "github.com/tendermint/tendermint/internal/statesync"
  25. "github.com/tendermint/tendermint/internal/store"
  26. "github.com/tendermint/tendermint/libs/log"
  27. "github.com/tendermint/tendermint/libs/service"
  28. tmstrings "github.com/tendermint/tendermint/libs/strings"
  29. "github.com/tendermint/tendermint/types"
  30. "github.com/tendermint/tendermint/version"
  31. _ "net/http/pprof" // nolint: gosec // securely exposed on separate, optional port
  32. )
  33. type closer func() error
  34. func makeCloser(cs []closer) closer {
  35. return func() error {
  36. errs := make([]string, 0, len(cs))
  37. for _, cl := range cs {
  38. if err := cl(); err != nil {
  39. errs = append(errs, err.Error())
  40. }
  41. }
  42. if len(errs) >= 0 {
  43. return errors.New(strings.Join(errs, "; "))
  44. }
  45. return nil
  46. }
  47. }
  48. func convertCancelCloser(cancel context.CancelFunc) closer {
  49. return func() error { cancel(); return nil }
  50. }
  51. func combineCloseError(err error, cl closer) error {
  52. if err == nil {
  53. return cl()
  54. }
  55. clerr := cl()
  56. if clerr == nil {
  57. return err
  58. }
  59. return fmt.Errorf("error=%q closerError=%q", err.Error(), clerr.Error())
  60. }
  61. func initDBs(
  62. cfg *config.Config,
  63. dbProvider config.DBProvider,
  64. ) (*store.BlockStore, dbm.DB, closer, error) {
  65. blockStoreDB, err := dbProvider(&config.DBContext{ID: "blockstore", Config: cfg})
  66. if err != nil {
  67. return nil, nil, func() error { return nil }, fmt.Errorf("unable to initialize blockstore: %w", err)
  68. }
  69. closers := []closer{}
  70. blockStore := store.NewBlockStore(blockStoreDB)
  71. closers = append(closers, blockStoreDB.Close)
  72. stateDB, err := dbProvider(&config.DBContext{ID: "state", Config: cfg})
  73. if err != nil {
  74. return nil, nil, makeCloser(closers), fmt.Errorf("unable to initialize statestore: %w", err)
  75. }
  76. closers = append(closers, stateDB.Close)
  77. return blockStore, stateDB, makeCloser(closers), nil
  78. }
  79. func createAndStartIndexerService(
  80. ctx context.Context,
  81. cfg *config.Config,
  82. dbProvider config.DBProvider,
  83. eventBus *eventbus.EventBus,
  84. logger log.Logger,
  85. chainID string,
  86. metrics *indexer.Metrics,
  87. ) (*indexer.Service, []indexer.EventSink, error) {
  88. eventSinks, err := sink.EventSinksFromConfig(cfg, dbProvider, chainID)
  89. if err != nil {
  90. return nil, nil, err
  91. }
  92. indexerService := indexer.NewService(indexer.ServiceArgs{
  93. Sinks: eventSinks,
  94. EventBus: eventBus,
  95. Logger: logger.With("module", "txindex"),
  96. Metrics: metrics,
  97. })
  98. if err := indexerService.Start(ctx); err != nil {
  99. return nil, nil, err
  100. }
  101. return indexerService, eventSinks, nil
  102. }
  103. func logNodeStartupInfo(state sm.State, pubKey crypto.PubKey, logger log.Logger, mode string) {
  104. // Log the version info.
  105. logger.Info("Version info",
  106. "tmVersion", version.TMVersion,
  107. "block", version.BlockProtocol,
  108. "p2p", version.P2PProtocol,
  109. "mode", mode,
  110. )
  111. // If the state and software differ in block version, at least log it.
  112. if state.Version.Consensus.Block != version.BlockProtocol {
  113. logger.Info("Software and state have different block protocols",
  114. "software", version.BlockProtocol,
  115. "state", state.Version.Consensus.Block,
  116. )
  117. }
  118. switch mode {
  119. case config.ModeFull:
  120. logger.Info("This node is a fullnode")
  121. case config.ModeValidator:
  122. addr := pubKey.Address()
  123. // Log whether this node is a validator or an observer
  124. if state.Validators.HasAddress(addr) {
  125. logger.Info("This node is a validator",
  126. "addr", addr,
  127. "pubKey", pubKey.Bytes(),
  128. )
  129. } else {
  130. logger.Info("This node is a validator (NOT in the active validator set)",
  131. "addr", addr,
  132. "pubKey", pubKey.Bytes(),
  133. )
  134. }
  135. }
  136. }
  137. func onlyValidatorIsUs(state sm.State, pubKey crypto.PubKey) bool {
  138. if state.Validators.Size() > 1 {
  139. return false
  140. }
  141. addr, _ := state.Validators.GetByIndex(0)
  142. return pubKey != nil && bytes.Equal(pubKey.Address(), addr)
  143. }
  144. func createMempoolReactor(
  145. ctx context.Context,
  146. cfg *config.Config,
  147. proxyApp proxy.AppConns,
  148. state sm.State,
  149. memplMetrics *mempool.Metrics,
  150. peerManager *p2p.PeerManager,
  151. router *p2p.Router,
  152. logger log.Logger,
  153. ) (service.Service, mempool.Mempool, error) {
  154. logger = logger.With("module", "mempool")
  155. ch, err := router.OpenChannel(ctx, mempool.GetChannelDescriptor(cfg.Mempool))
  156. if err != nil {
  157. return nil, nil, err
  158. }
  159. mp := mempool.NewTxMempool(
  160. logger,
  161. cfg.Mempool,
  162. proxyApp.Mempool(),
  163. state.LastBlockHeight,
  164. mempool.WithMetrics(memplMetrics),
  165. mempool.WithPreCheck(sm.TxPreCheck(state)),
  166. mempool.WithPostCheck(sm.TxPostCheck(state)),
  167. )
  168. reactor := mempool.NewReactor(
  169. logger,
  170. cfg.Mempool,
  171. peerManager,
  172. mp,
  173. ch,
  174. peerManager.Subscribe(ctx),
  175. )
  176. if cfg.Consensus.WaitForTxs() {
  177. mp.EnableTxsAvailable()
  178. }
  179. return reactor, mp, nil
  180. }
  181. func createEvidenceReactor(
  182. ctx context.Context,
  183. cfg *config.Config,
  184. dbProvider config.DBProvider,
  185. stateDB dbm.DB,
  186. blockStore *store.BlockStore,
  187. peerManager *p2p.PeerManager,
  188. router *p2p.Router,
  189. logger log.Logger,
  190. ) (*evidence.Reactor, *evidence.Pool, error) {
  191. evidenceDB, err := dbProvider(&config.DBContext{ID: "evidence", Config: cfg})
  192. if err != nil {
  193. return nil, nil, fmt.Errorf("unable to initialize evidence db: %w", err)
  194. }
  195. logger = logger.With("module", "evidence")
  196. evidencePool, err := evidence.NewPool(logger, evidenceDB, sm.NewStore(stateDB), blockStore)
  197. if err != nil {
  198. return nil, nil, fmt.Errorf("creating evidence pool: %w", err)
  199. }
  200. ch, err := router.OpenChannel(ctx, evidence.GetChannelDescriptor())
  201. if err != nil {
  202. return nil, nil, fmt.Errorf("creating evidence channel: %w", err)
  203. }
  204. evidenceReactor := evidence.NewReactor(
  205. logger,
  206. ch,
  207. peerManager.Subscribe(ctx),
  208. evidencePool,
  209. )
  210. return evidenceReactor, evidencePool, nil
  211. }
  212. func createBlockchainReactor(
  213. ctx context.Context,
  214. logger log.Logger,
  215. state sm.State,
  216. blockExec *sm.BlockExecutor,
  217. blockStore *store.BlockStore,
  218. csReactor *consensus.Reactor,
  219. peerManager *p2p.PeerManager,
  220. router *p2p.Router,
  221. blockSync bool,
  222. metrics *consensus.Metrics,
  223. ) (service.Service, error) {
  224. logger = logger.With("module", "blockchain")
  225. ch, err := router.OpenChannel(ctx, blocksync.GetChannelDescriptor())
  226. if err != nil {
  227. return nil, err
  228. }
  229. peerUpdates := peerManager.Subscribe(ctx)
  230. reactor, err := blocksync.NewReactor(
  231. logger, state.Copy(), blockExec, blockStore, csReactor,
  232. ch, peerUpdates, blockSync,
  233. metrics,
  234. )
  235. if err != nil {
  236. return nil, err
  237. }
  238. return reactor, nil
  239. }
  240. func createConsensusReactor(
  241. ctx context.Context,
  242. cfg *config.Config,
  243. state sm.State,
  244. blockExec *sm.BlockExecutor,
  245. blockStore sm.BlockStore,
  246. mp mempool.Mempool,
  247. evidencePool *evidence.Pool,
  248. privValidator types.PrivValidator,
  249. csMetrics *consensus.Metrics,
  250. waitSync bool,
  251. eventBus *eventbus.EventBus,
  252. peerManager *p2p.PeerManager,
  253. router *p2p.Router,
  254. logger log.Logger,
  255. ) (*consensus.Reactor, *consensus.State, error) {
  256. logger = logger.With("module", "consensus")
  257. consensusState := consensus.NewState(ctx,
  258. logger,
  259. cfg.Consensus,
  260. state.Copy(),
  261. blockExec,
  262. blockStore,
  263. mp,
  264. evidencePool,
  265. consensus.StateMetrics(csMetrics),
  266. )
  267. if privValidator != nil && cfg.Mode == config.ModeValidator {
  268. consensusState.SetPrivValidator(ctx, privValidator)
  269. }
  270. csChDesc := consensus.GetChannelDescriptors()
  271. channels := make(map[p2p.ChannelID]*p2p.Channel, len(csChDesc))
  272. for idx := range csChDesc {
  273. chd := csChDesc[idx]
  274. ch, err := router.OpenChannel(ctx, chd)
  275. if err != nil {
  276. return nil, nil, err
  277. }
  278. channels[ch.ID] = ch
  279. }
  280. reactor := consensus.NewReactor(
  281. logger,
  282. consensusState,
  283. channels[consensus.StateChannel],
  284. channels[consensus.DataChannel],
  285. channels[consensus.VoteChannel],
  286. channels[consensus.VoteSetBitsChannel],
  287. peerManager.Subscribe(ctx),
  288. waitSync,
  289. consensus.ReactorMetrics(csMetrics),
  290. )
  291. // Services which will be publishing and/or subscribing for messages (events)
  292. // consensusReactor will set it on consensusState and blockExecutor.
  293. reactor.SetEventBus(eventBus)
  294. return reactor, consensusState, nil
  295. }
  296. func createPeerManager(
  297. cfg *config.Config,
  298. dbProvider config.DBProvider,
  299. nodeID types.NodeID,
  300. ) (*p2p.PeerManager, closer, error) {
  301. privatePeerIDs := make(map[types.NodeID]struct{})
  302. for _, id := range tmstrings.SplitAndTrimEmpty(cfg.P2P.PrivatePeerIDs, ",", " ") {
  303. privatePeerIDs[types.NodeID(id)] = struct{}{}
  304. }
  305. var maxConns uint16
  306. switch {
  307. case cfg.P2P.MaxConnections > 0:
  308. maxConns = cfg.P2P.MaxConnections
  309. default:
  310. maxConns = 64
  311. }
  312. options := p2p.PeerManagerOptions{
  313. MaxConnected: maxConns,
  314. MaxConnectedUpgrade: 4,
  315. MaxPeers: 1000,
  316. MinRetryTime: 100 * time.Millisecond,
  317. MaxRetryTime: 8 * time.Hour,
  318. MaxRetryTimePersistent: 5 * time.Minute,
  319. RetryTimeJitter: 3 * time.Second,
  320. PrivatePeers: privatePeerIDs,
  321. }
  322. peers := []p2p.NodeAddress{}
  323. for _, p := range tmstrings.SplitAndTrimEmpty(cfg.P2P.PersistentPeers, ",", " ") {
  324. address, err := p2p.ParseNodeAddress(p)
  325. if err != nil {
  326. return nil, func() error { return nil }, fmt.Errorf("invalid peer address %q: %w", p, err)
  327. }
  328. peers = append(peers, address)
  329. options.PersistentPeers = append(options.PersistentPeers, address.NodeID)
  330. }
  331. for _, p := range tmstrings.SplitAndTrimEmpty(cfg.P2P.BootstrapPeers, ",", " ") {
  332. address, err := p2p.ParseNodeAddress(p)
  333. if err != nil {
  334. return nil, func() error { return nil }, fmt.Errorf("invalid peer address %q: %w", p, err)
  335. }
  336. peers = append(peers, address)
  337. }
  338. peerDB, err := dbProvider(&config.DBContext{ID: "peerstore", Config: cfg})
  339. if err != nil {
  340. return nil, func() error { return nil }, fmt.Errorf("unable to initialize peer store: %w", err)
  341. }
  342. peerManager, err := p2p.NewPeerManager(nodeID, peerDB, options)
  343. if err != nil {
  344. return nil, peerDB.Close, fmt.Errorf("failed to create peer manager: %w", err)
  345. }
  346. for _, peer := range peers {
  347. if _, err := peerManager.Add(peer); err != nil {
  348. return nil, peerDB.Close, fmt.Errorf("failed to add peer %q: %w", peer, err)
  349. }
  350. }
  351. return peerManager, peerDB.Close, nil
  352. }
  353. func createRouter(
  354. ctx context.Context,
  355. logger log.Logger,
  356. p2pMetrics *p2p.Metrics,
  357. nodeInfo types.NodeInfo,
  358. nodeKey types.NodeKey,
  359. peerManager *p2p.PeerManager,
  360. cfg *config.Config,
  361. proxyApp proxy.AppConns,
  362. ) (*p2p.Router, error) {
  363. p2pLogger := logger.With("module", "p2p")
  364. transportConf := conn.DefaultMConnConfig()
  365. transportConf.FlushThrottle = cfg.P2P.FlushThrottleTimeout
  366. transportConf.SendRate = cfg.P2P.SendRate
  367. transportConf.RecvRate = cfg.P2P.RecvRate
  368. transportConf.MaxPacketMsgPayloadSize = cfg.P2P.MaxPacketMsgPayloadSize
  369. transport := p2p.NewMConnTransport(
  370. p2pLogger, transportConf, []*p2p.ChannelDescriptor{},
  371. p2p.MConnTransportOptions{
  372. MaxAcceptedConnections: uint32(cfg.P2P.MaxConnections),
  373. },
  374. )
  375. ep, err := p2p.NewEndpoint(nodeKey.ID.AddressString(cfg.P2P.ListenAddress))
  376. if err != nil {
  377. return nil, err
  378. }
  379. return p2p.NewRouter(
  380. ctx,
  381. p2pLogger,
  382. p2pMetrics,
  383. nodeInfo,
  384. nodeKey.PrivKey,
  385. peerManager,
  386. []p2p.Transport{transport},
  387. []p2p.Endpoint{ep},
  388. getRouterConfig(cfg, proxyApp),
  389. )
  390. }
  391. func createPEXReactor(
  392. ctx context.Context,
  393. logger log.Logger,
  394. peerManager *p2p.PeerManager,
  395. router *p2p.Router,
  396. ) (service.Service, error) {
  397. channel, err := router.OpenChannel(ctx, pex.ChannelDescriptor())
  398. if err != nil {
  399. return nil, err
  400. }
  401. return pex.NewReactor(logger, peerManager, channel, peerManager.Subscribe(ctx)), nil
  402. }
  403. func makeNodeInfo(
  404. cfg *config.Config,
  405. nodeKey types.NodeKey,
  406. eventSinks []indexer.EventSink,
  407. genDoc *types.GenesisDoc,
  408. state sm.State,
  409. ) (types.NodeInfo, error) {
  410. txIndexerStatus := "off"
  411. if indexer.IndexingEnabled(eventSinks) {
  412. txIndexerStatus = "on"
  413. }
  414. nodeInfo := types.NodeInfo{
  415. ProtocolVersion: types.ProtocolVersion{
  416. P2P: version.P2PProtocol, // global
  417. Block: state.Version.Consensus.Block,
  418. App: state.Version.Consensus.App,
  419. },
  420. NodeID: nodeKey.ID,
  421. Network: genDoc.ChainID,
  422. Version: version.TMVersion,
  423. Channels: []byte{
  424. byte(blocksync.BlockSyncChannel),
  425. byte(consensus.StateChannel),
  426. byte(consensus.DataChannel),
  427. byte(consensus.VoteChannel),
  428. byte(consensus.VoteSetBitsChannel),
  429. byte(mempool.MempoolChannel),
  430. byte(evidence.EvidenceChannel),
  431. byte(statesync.SnapshotChannel),
  432. byte(statesync.ChunkChannel),
  433. byte(statesync.LightBlockChannel),
  434. byte(statesync.ParamsChannel),
  435. },
  436. Moniker: cfg.Moniker,
  437. Other: types.NodeInfoOther{
  438. TxIndex: txIndexerStatus,
  439. RPCAddress: cfg.RPC.ListenAddress,
  440. },
  441. }
  442. if cfg.P2P.PexReactor {
  443. nodeInfo.Channels = append(nodeInfo.Channels, pex.PexChannel)
  444. }
  445. nodeInfo.ListenAddr = cfg.P2P.ExternalAddress
  446. if nodeInfo.ListenAddr == "" {
  447. nodeInfo.ListenAddr = cfg.P2P.ListenAddress
  448. }
  449. return nodeInfo, nodeInfo.Validate()
  450. }
  451. func makeSeedNodeInfo(
  452. cfg *config.Config,
  453. nodeKey types.NodeKey,
  454. genDoc *types.GenesisDoc,
  455. state sm.State,
  456. ) (types.NodeInfo, error) {
  457. nodeInfo := types.NodeInfo{
  458. ProtocolVersion: types.ProtocolVersion{
  459. P2P: version.P2PProtocol, // global
  460. Block: state.Version.Consensus.Block,
  461. App: state.Version.Consensus.App,
  462. },
  463. NodeID: nodeKey.ID,
  464. Network: genDoc.ChainID,
  465. Version: version.TMVersion,
  466. Channels: []byte{},
  467. Moniker: cfg.Moniker,
  468. Other: types.NodeInfoOther{
  469. TxIndex: "off",
  470. RPCAddress: cfg.RPC.ListenAddress,
  471. },
  472. }
  473. if cfg.P2P.PexReactor {
  474. nodeInfo.Channels = append(nodeInfo.Channels, pex.PexChannel)
  475. }
  476. nodeInfo.ListenAddr = cfg.P2P.ExternalAddress
  477. if nodeInfo.ListenAddr == "" {
  478. nodeInfo.ListenAddr = cfg.P2P.ListenAddress
  479. }
  480. return nodeInfo, nodeInfo.Validate()
  481. }