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.

210 lines
5.1 KiB

fix data race Closes #1442 ``` WARNING: DATA RACE Write at 0x00c4209de7c8 by goroutine 23: github.com/tendermint/tendermint/types.(*Block).fillHeader() /home/vagrant/go/src/github.com/tendermint/tendermint/types/block.go:88 +0x157 github.com/tendermint/tendermint/types.(*Block).Hash() /home/vagrant/go/src/github.com/tendermint/tendermint/types/block.go:104 +0x121 github.com/tendermint/tendermint/types.(*Block).HashesTo() /home/vagrant/go/src/github.com/tendermint/tendermint/types/block.go:135 +0x4f github.com/tendermint/tendermint/consensus.(*ConsensusState).enterPrecommit() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:1037 +0x182d github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:1425 +0x1a6c github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:1318 +0x77 github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:581 +0x7a9 github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:539 +0x6c3 Previous read at 0x00c4209de7c8 by goroutine 47: github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common.(*HexBytes).MarshalJSON() <autogenerated>:1 +0x52 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.invokeMarshalJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:433 +0x88 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec)._encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:82 +0x8d2 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:50 +0x10e github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSONStruct() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:348 +0x539 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec)._encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:119 +0x83f github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:50 +0x10e github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSONStruct() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:348 +0x539 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec)._encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:119 +0x83f github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:50 +0x10e github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSONStruct() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:348 +0x539 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec)._encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:119 +0x83f github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:50 +0x10e github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSONStruct() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:348 +0x539 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec)._encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:119 +0x83f github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:50 +0x10e github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).MarshalJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/amino.go:296 +0x182 github.com/tendermint/tendermint/rpc/lib/types.NewRPCSuccessResponse() /home/vagrant/go/src/github.com/tendermint/tendermint/rpc/lib/types/types.go:100 +0x12c github.com/tendermint/tendermint/rpc/lib/server.makeJSONRPCHandler.func1() /home/vagrant/go/src/github.com/tendermint/tendermint/rpc/lib/server/handlers.go:152 +0xab7 net/http.HandlerFunc.ServeHTTP() /usr/lib/go-1.9/src/net/http/server.go:1918 +0x51 net/http.(*ServeMux).ServeHTTP() /usr/lib/go-1.9/src/net/http/server.go:2254 +0xa2 github.com/tendermint/tendermint/rpc/lib/server.RecoverAndLogHandler.func1() /home/vagrant/go/src/github.com/tendermint/tendermint/rpc/lib/server/http_server.go:138 +0x4fa net/http.HandlerFunc.ServeHTTP() /usr/lib/go-1.9/src/net/http/server.go:1918 +0x51 net/http.serverHandler.ServeHTTP() /usr/lib/go-1.9/src/net/http/server.go:2619 +0xbc net/http.(*conn).serve() /usr/lib/go-1.9/src/net/http/server.go:1801 +0x83b Goroutine 23 (running) created at: github.com/tendermint/tendermint/consensus.(*ConsensusState).OnStart() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:250 +0x35b github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common.(*BaseService).Start() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common/service.go:130 +0x5fc github.com/tendermint/tendermint/consensus.(*ConsensusReactor).OnStart() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/reactor.go:69 +0x1b4 github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common.(*BaseService).Start() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common/service.go:130 +0x5fc github.com/tendermint/tendermint/consensus.(*ConsensusReactor).Start() <autogenerated>:1 +0x43 github.com/tendermint/tendermint/p2p.(*Switch).OnStart() /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch.go:177 +0x124 github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common.(*BaseService).Start() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common/service.go:130 +0x5fc github.com/tendermint/tendermint/node.(*Node).OnStart() /home/vagrant/go/src/github.com/tendermint/tendermint/node/node.go:416 +0xa1b github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common.(*BaseService).Start() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common/service.go:130 +0x5fc github.com/tendermint/tendermint/rpc/test.StartTendermint() /home/vagrant/go/src/github.com/tendermint/tendermint/rpc/test/helpers.go:100 +0x5b github.com/tendermint/tendermint/rpc/client_test.TestMain() /home/vagrant/go/src/github.com/tendermint/tendermint/rpc/client/main_test.go:17 +0x4c main.main() github.com/tendermint/tendermint/rpc/client/_test/_testmain.go:76 +0x1cd Goroutine 47 (running) created at: net/http.(*Server).Serve() /usr/lib/go-1.9/src/net/http/server.go:2720 +0x37c net/http.Serve() /usr/lib/go-1.9/src/net/http/server.go:2323 +0xe2 github.com/tendermint/tendermint/rpc/lib/server.StartHTTPServer.func1() /home/vagrant/go/src/github.com/tendermint/tendermint/rpc/lib/server/http_server.go:35 +0xb3 ```
7 years ago
[rpc] DumpConsensusState: output state as json rather than string Before: ``` { "jsonrpc": "2.0", "id": "", "result": { "round_state": "RoundState{\n H:10 R:0 S:RoundStepNewHeight\n StartTime: 2017-10-09 13:07:24.841134374 +0400 +04\n CommitTime: 2017-10-09 13:07:23.841134374 +0400 +04\n Validators: ValidatorSet{\n Proposer: Validator{EF243CC0E9B88D0161D24D733BDE9003518CEA27 {PubKeyEd25519{2E0B9301334FCDAB193D514022F81BA09BBEC028685C96602BE9DD0BD4F9E202}} VP:10 A:0}\n Validators:\n Validator{EF243CC0E9B88D0161D24D733BDE9003518CEA27 {PubKeyEd25519{2E0B9301334FCDAB193D514022F81BA09BBEC028685C96602BE9DD0BD4F9E202}} VP:10 A:0}\n }\n Proposal: \u003cnil\u003e\n ProposalBlock: nil-PartSet nil-Block\n LockedRound: 0\n LockedBlock: nil-PartSet nil-Block\n Votes: HeightVoteSet{H:10 R:0~0\n VoteSet{H:10 R:0 T:1 +2/3:\u003cnil\u003e BA{1:_} map[]}\n VoteSet{H:10 R:0 T:2 +2/3:\u003cnil\u003e BA{1:_} map[]}\n }\n LastCommit: VoteSet{H:9 R:0 T:2 +2/3:947F67A7B85439AF2CD5DFED376C51AC7BD67AEE:1:365E9983E466 BA{1:X} map[]}\n LastValidators: ValidatorSet{\n Proposer: Validator{EF243CC0E9B88D0161D24D733BDE9003518CEA27 {PubKeyEd25519{2E0B9301334FCDAB193D514022F81BA09BBEC028685C96602BE9DD0BD4F9E202}} VP:10 A:0}\n Validators:\n Validator{EF243CC0E9B88D0161D24D733BDE9003518CEA27 {PubKeyEd25519{2E0B9301334FCDAB193D514022F81BA09BBEC028685C96602BE9DD0BD4F9E202}} VP:10 A:0}\n }\n}", "peer_round_states": [] } } ``` After: ``` { "jsonrpc": "2.0", "id": "", "result": { "round_state": { "Height": 1691, "Round": 0, "Step": 1, "StartTime": "2017-10-09T14:08:09.129491764+04:00", "CommitTime": "2017-10-09T14:08:08.129491764+04:00", "Validators": { "validators": [ { "address": "EF243CC0E9B88D0161D24D733BDE9003518CEA27", "pub_key": { "type": "ed25519", "data": "2E0B9301334FCDAB193D514022F81BA09BBEC028685C96602BE9DD0BD4F9E202" }, "voting_power": 10, "accum": 0 } ], "proposer": { "address": "EF243CC0E9B88D0161D24D733BDE9003518CEA27", "pub_key": { "type": "ed25519", "data": "2E0B9301334FCDAB193D514022F81BA09BBEC028685C96602BE9DD0BD4F9E202" }, "voting_power": 10, "accum": 0 } }, "Proposal": null, "ProposalBlock": null, "ProposalBlockParts": null, "LockedRound": 0, "LockedBlock": null, "LockedBlockParts": null, "Votes": {}, "CommitRound": -1, "LastCommit": {}, "LastValidators": { "validators": [ { "address": "EF243CC0E9B88D0161D24D733BDE9003518CEA27", "pub_key": { "type": "ed25519", "data": "2E0B9301334FCDAB193D514022F81BA09BBEC028685C96602BE9DD0BD4F9E202" }, "voting_power": 10, "accum": 0 } ], "proposer": { "address": "EF243CC0E9B88D0161D24D733BDE9003518CEA27", "pub_key": { "type": "ed25519", "data": "2E0B9301334FCDAB193D514022F81BA09BBEC028685C96602BE9DD0BD4F9E202" }, "voting_power": 10, "accum": 0 } } }, "peer_round_states": { "75EC8F15D244A421202F9725CD4DE509EE50303670310CF7530EF25E2B7C524B": { "Height": 1691, "Round": 0, "Step": 1, "StartTime": "2017-10-09T14:08:08.563251997+04:00", "Proposal": false, "ProposalBlockPartsHeader": { "total": 0, "hash": "" }, "ProposalBlockParts": null, "ProposalPOLRound": -1, "ProposalPOL": null, "Prevotes": null, "Precommits": null, "LastCommitRound": 0, "LastCommit": null, "CatchupCommitRound": -1, "CatchupCommit": null } } } } ```
7 years ago
7 years ago
7 years ago
8 years ago
7 years ago
8 years ago
8 years ago
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
7 years ago
  1. package core_types
  2. import (
  3. "encoding/json"
  4. "strings"
  5. "time"
  6. abci "github.com/tendermint/abci/types"
  7. crypto "github.com/tendermint/go-crypto"
  8. cmn "github.com/tendermint/tmlibs/common"
  9. "github.com/tendermint/tendermint/p2p"
  10. "github.com/tendermint/tendermint/state"
  11. "github.com/tendermint/tendermint/types"
  12. )
  13. // List of blocks
  14. type ResultBlockchainInfo struct {
  15. LastHeight int64 `json:"last_height"`
  16. BlockMetas []*types.BlockMeta `json:"block_metas"`
  17. }
  18. // Genesis file
  19. type ResultGenesis struct {
  20. Genesis *types.GenesisDoc `json:"genesis"`
  21. }
  22. // Single block (with meta)
  23. type ResultBlock struct {
  24. BlockMeta *types.BlockMeta `json:"block_meta"`
  25. Block *types.Block `json:"block"`
  26. }
  27. // Commit and Header
  28. type ResultCommit struct {
  29. // SignedHeader is header and commit, embedded so we only have
  30. // one level in the json output
  31. types.SignedHeader
  32. CanonicalCommit bool `json:"canonical"`
  33. }
  34. // ABCI results from a block
  35. type ResultBlockResults struct {
  36. Height int64 `json:"height"`
  37. Results *state.ABCIResponses `json:"results"`
  38. }
  39. // NewResultCommit is a helper to initialize the ResultCommit with
  40. // the embedded struct
  41. func NewResultCommit(header *types.Header, commit *types.Commit,
  42. canonical bool) *ResultCommit {
  43. return &ResultCommit{
  44. SignedHeader: types.SignedHeader{
  45. Header: header,
  46. Commit: commit,
  47. },
  48. CanonicalCommit: canonical,
  49. }
  50. }
  51. // Info about the node's syncing state
  52. type SyncInfo struct {
  53. LatestBlockHash cmn.HexBytes `json:"latest_block_hash"`
  54. LatestAppHash cmn.HexBytes `json:"latest_app_hash"`
  55. LatestBlockHeight int64 `json:"latest_block_height"`
  56. LatestBlockTime time.Time `json:"latest_block_time"`
  57. Syncing bool `json:"syncing"`
  58. }
  59. // Info about the node's validator
  60. type ValidatorInfo struct {
  61. Address cmn.HexBytes `json:"address"`
  62. PubKey crypto.PubKey `json:"pub_key"`
  63. VotingPower int64 `json:"voting_power"`
  64. }
  65. // Node Status
  66. type ResultStatus struct {
  67. NodeInfo p2p.NodeInfo `json:"node_info"`
  68. SyncInfo SyncInfo `json:"sync_info"`
  69. ValidatorInfo ValidatorInfo `json:"validator_info"`
  70. }
  71. // Is TxIndexing enabled
  72. func (s *ResultStatus) TxIndexEnabled() bool {
  73. if s == nil {
  74. return false
  75. }
  76. for _, s := range s.NodeInfo.Other {
  77. info := strings.Split(s, "=")
  78. if len(info) == 2 && info[0] == "tx_index" {
  79. return info[1] == "on"
  80. }
  81. }
  82. return false
  83. }
  84. // Info about peer connections
  85. type ResultNetInfo struct {
  86. Listening bool `json:"listening"`
  87. Listeners []string `json:"listeners"`
  88. NPeers int `json:"n_peers"`
  89. Peers []Peer `json:"peers"`
  90. }
  91. // Log from dialing seeds
  92. type ResultDialSeeds struct {
  93. Log string `json:"log"`
  94. }
  95. // Log from dialing peers
  96. type ResultDialPeers struct {
  97. Log string `json:"log"`
  98. }
  99. // A peer
  100. type Peer struct {
  101. p2p.NodeInfo `json:"node_info"`
  102. IsOutbound bool `json:"is_outbound"`
  103. ConnectionStatus p2p.ConnectionStatus `json:"connection_status"`
  104. }
  105. // Validators for a height
  106. type ResultValidators struct {
  107. BlockHeight int64 `json:"block_height"`
  108. Validators []*types.Validator `json:"validators"`
  109. }
  110. // Info about the consensus state.
  111. // UNSTABLE
  112. type ResultDumpConsensusState struct {
  113. RoundState json.RawMessage `json:"round_state"`
  114. Peers []PeerStateInfo `json:"peers"`
  115. }
  116. // UNSTABLE
  117. type PeerStateInfo struct {
  118. NodeAddress string `json:"node_address"`
  119. PeerState json.RawMessage `json:"peer_state"`
  120. }
  121. // UNSTABLE
  122. type ResultConsensusState struct {
  123. RoundState json.RawMessage `json:"round_state"`
  124. }
  125. // CheckTx result
  126. type ResultBroadcastTx struct {
  127. Code uint32 `json:"code"`
  128. Data cmn.HexBytes `json:"data"`
  129. Log string `json:"log"`
  130. Hash cmn.HexBytes `json:"hash"`
  131. }
  132. // CheckTx and DeliverTx results
  133. type ResultBroadcastTxCommit struct {
  134. CheckTx abci.ResponseCheckTx `json:"check_tx"`
  135. DeliverTx abci.ResponseDeliverTx `json:"deliver_tx"`
  136. Hash cmn.HexBytes `json:"hash"`
  137. Height int64 `json:"height"`
  138. }
  139. // Result of querying for a tx
  140. type ResultTx struct {
  141. Hash cmn.HexBytes `json:"hash"`
  142. Height int64 `json:"height"`
  143. Index uint32 `json:"index"`
  144. TxResult abci.ResponseDeliverTx `json:"tx_result"`
  145. Tx types.Tx `json:"tx"`
  146. Proof types.TxProof `json:"proof,omitempty"`
  147. }
  148. // Result of searching for txs
  149. type ResultTxSearch struct {
  150. Txs []*ResultTx `json:"txs"`
  151. TotalCount int `json:"total_count"`
  152. }
  153. // List of mempool txs
  154. type ResultUnconfirmedTxs struct {
  155. N int `json:"n_txs"`
  156. Txs []types.Tx `json:"txs"`
  157. }
  158. // Info abci msg
  159. type ResultABCIInfo struct {
  160. Response abci.ResponseInfo `json:"response"`
  161. }
  162. // Query abci msg
  163. type ResultABCIQuery struct {
  164. Response abci.ResponseQuery `json:"response"`
  165. }
  166. // empty results
  167. type (
  168. ResultUnsafeFlushMempool struct{}
  169. ResultUnsafeProfile struct{}
  170. ResultSubscribe struct{}
  171. ResultUnsubscribe struct{}
  172. ResultHealth struct{}
  173. )
  174. // Event data from a subscription
  175. type ResultEvent struct {
  176. Query string `json:"query"`
  177. Data types.TMEventData `json:"data"`
  178. }