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.

101 lines
3.0 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
abci: Synchronize FinalizeBlock with the updated specification (#7983) This change set implements the most recent version of `FinalizeBlock`. # What does this change actually contain? * This change set is rather large but fear not! The majority of the files touched and changes are renaming `ResponseDeliverTx` to `ExecTxResult`. This should be a pretty inoffensive change since they're effectively the same type but with a different name. * The `execBlockOnProxyApp` was totally removed since it served as just a wrapper around the logic that is now mostly encapsulated within `FinalizeBlock` * The `updateState` helper function has been made a public method on `State`. It was being exposed as a shim through the testing infrastructure, so this seemed innocuous. * Tests already existed to ensure that the application received the `ByzantineValidators` and the `ValidatorUpdates`, but one was fixed up to ensure that `LastCommitInfo` was being sent across. * Tests were removed from the `psql` indexer that seemed to search for an event in the indexer that was not being created. # Questions for reviewers * We store this [ABCIResponses](https://github.com/tendermint/tendermint/blob/5721a13ab1f4479f9807f449f0bf5c536b9a05f2/proto/tendermint/state/types.pb.go#L37) type in the data base as the block results. This type has changed since v0.35 to contain the `FinalizeBlock` response. I'm wondering if we need to do any shimming to keep the old data retrieveable? * Similarly, this change is exposed via the RPC through [ResultBlockResults](https://github.com/tendermint/tendermint/blob/5721a13ab1f4479f9807f449f0bf5c536b9a05f2/rpc/coretypes/responses.go#L69) changing. Should we somehow shim or notify for this change? closes: #7658
2 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 consensus
  2. import (
  3. "context"
  4. abciclient "github.com/tendermint/tendermint/abci/client"
  5. abci "github.com/tendermint/tendermint/abci/types"
  6. "github.com/tendermint/tendermint/internal/libs/clist"
  7. "github.com/tendermint/tendermint/internal/mempool"
  8. "github.com/tendermint/tendermint/internal/proxy"
  9. "github.com/tendermint/tendermint/libs/log"
  10. tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
  11. "github.com/tendermint/tendermint/types"
  12. )
  13. //-----------------------------------------------------------------------------
  14. type emptyMempool struct{}
  15. var _ mempool.Mempool = emptyMempool{}
  16. func (emptyMempool) Lock() {}
  17. func (emptyMempool) Unlock() {}
  18. func (emptyMempool) Size() int { return 0 }
  19. func (emptyMempool) CheckTx(context.Context, types.Tx, func(*abci.ResponseCheckTx), mempool.TxInfo) error {
  20. return nil
  21. }
  22. func (emptyMempool) RemoveTxByKey(txKey types.TxKey) error { return nil }
  23. func (emptyMempool) ReapMaxBytesMaxGas(_, _ int64) types.Txs { return types.Txs{} }
  24. func (emptyMempool) ReapMaxTxs(n int) types.Txs { return types.Txs{} }
  25. func (emptyMempool) Update(
  26. _ context.Context,
  27. _ int64,
  28. _ types.Txs,
  29. _ []*abci.ExecTxResult,
  30. _ mempool.PreCheckFunc,
  31. _ mempool.PostCheckFunc,
  32. ) error {
  33. return nil
  34. }
  35. func (emptyMempool) Flush() {}
  36. func (emptyMempool) FlushAppConn(ctx context.Context) error { return nil }
  37. func (emptyMempool) TxsAvailable() <-chan struct{} { return make(chan struct{}) }
  38. func (emptyMempool) EnableTxsAvailable() {}
  39. func (emptyMempool) SizeBytes() int64 { return 0 }
  40. func (emptyMempool) TxsFront() *clist.CElement { return nil }
  41. func (emptyMempool) TxsWaitChan() <-chan struct{} { return nil }
  42. func (emptyMempool) InitWAL() error { return nil }
  43. func (emptyMempool) CloseWAL() {}
  44. //-----------------------------------------------------------------------------
  45. // mockProxyApp uses ABCIResponses to give the right results.
  46. //
  47. // Useful because we don't want to call Commit() twice for the same block on
  48. // the real app.
  49. func newMockProxyApp(
  50. ctx context.Context,
  51. logger log.Logger,
  52. appHash []byte,
  53. abciResponses *tmstate.ABCIResponses,
  54. ) (proxy.AppConnConsensus, error) {
  55. clientCreator := abciclient.NewLocalCreator(&mockProxyApp{
  56. appHash: appHash,
  57. abciResponses: abciResponses,
  58. })
  59. cli, err := clientCreator(logger)
  60. if err != nil {
  61. return nil, err
  62. }
  63. if err = cli.Start(ctx); err != nil {
  64. return nil, err
  65. }
  66. return proxy.NewAppConnConsensus(cli, proxy.NopMetrics()), nil
  67. }
  68. type mockProxyApp struct {
  69. abci.BaseApplication
  70. appHash []byte
  71. txCount int
  72. abciResponses *tmstate.ABCIResponses
  73. }
  74. func (mock *mockProxyApp) FinalizeBlock(req abci.RequestFinalizeBlock) abci.ResponseFinalizeBlock {
  75. r := mock.abciResponses.FinalizeBlock
  76. mock.txCount++
  77. if r == nil {
  78. return abci.ResponseFinalizeBlock{}
  79. }
  80. return *r
  81. }
  82. func (mock *mockProxyApp) Commit() abci.ResponseCommit {
  83. return abci.ResponseCommit{Data: mock.appHash}
  84. }