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.

1506 lines
45 KiB

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
8 years ago
10 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
8 years ago
10 years ago
8 years ago
10 years ago
10 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
8 years ago
8 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
7 years ago
7 years ago
10 years ago
7 years ago
10 years ago
10 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
10 years ago
7 years ago
10 years ago
8 years ago
7 years ago
7 years ago
10 years ago
10 years ago
10 years ago
10 years ago
8 years ago
8 years ago
8 years ago
10 years ago
10 years ago
10 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
8 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
10 years ago
10 years ago
8 years ago
10 years ago
10 years ago
7 years ago
10 years ago
8 years ago
10 years ago
7 years ago
7 years ago
10 years ago
10 years ago
10 years ago
7 years ago
7 years ago
8 years ago
10 years ago
8 years ago
10 years ago
10 years ago
8 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
8 years ago
7 years ago
8 years ago
8 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
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
7 years ago
7 years ago
7 years ago
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
7 years ago
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
10 years ago
10 years ago
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
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
10 years ago
10 years ago
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
protect Record* peerStateStats functions by mutex Fixes #1414 DATA RACE: ``` Read at 0x00c4214ee940 by goroutine 146: github.com/tendermint/tendermint/consensus.(*peerStateStats).String() <autogenerated>:1 +0x57 fmt.(*pp).handleMethods() /usr/local/go/src/fmt/print.go:596 +0x3f4 fmt.(*pp).printArg() /usr/local/go/src/fmt/print.go:679 +0x11f fmt.(*pp).doPrintf() /usr/local/go/src/fmt/print.go:996 +0x319 fmt.Sprintf() /usr/local/go/src/fmt/print.go:196 +0x73 github.com/tendermint/tendermint/consensus.(*PeerState).StringIndented() github.com/tendermint/tendermint/consensus/_test/_obj_test/reactor.go:1426 +0x573 github.com/tendermint/tendermint/consensus.(*PeerState).String() github.com/tendermint/tendermint/consensus/_test/_obj_test/reactor.go:1419 +0x66 github.com/go-logfmt/logfmt.safeString() /home/ubuntu/go/src/github.com/go-logfmt/logfmt/encode.go:299 +0x9d github.com/go-logfmt/logfmt.writeValue() /home/ubuntu/go/src/github.com/go-logfmt/logfmt/encode.go:217 +0x5a0 github.com/go-logfmt/logfmt.(*Encoder).EncodeKeyval() /home/ubuntu/go/src/github.com/go-logfmt/logfmt/encode.go:61 +0x1dd github.com/tendermint/tmlibs/log.tmfmtLogger.Log() /home/ubuntu/go/src/github.com/tendermint/tmlibs/log/tmfmt_logger.go:107 +0x1001 github.com/tendermint/tmlibs/log.(*tmfmtLogger).Log() <autogenerated>:1 +0x93 github.com/go-kit/kit/log.(*context).Log() /home/ubuntu/go/src/github.com/go-kit/kit/log/log.go:124 +0x248 github.com/tendermint/tmlibs/log.(*tmLogger).Debug() /home/ubuntu/go/src/github.com/tendermint/tmlibs/log/tm_logger.go:64 +0x1d0 github.com/tendermint/tendermint/consensus.(*PeerState).PickSendVote() github.com/tendermint/tendermint/consensus/_test/_obj_test/reactor.go:1059 +0x242 github.com/tendermint/tendermint/consensus.(*ConsensusReactor).gossipVotesForHeight() github.com/tendermint/tendermint/consensus/_test/_obj_test/reactor.go:789 +0x6ef github.com/tendermint/tendermint/consensus.(*ConsensusReactor).gossipVotesRoutine() github.com/tendermint/tendermint/consensus/_test/_obj_test/reactor.go:723 +0x1039 Previous write at 0x00c4214ee940 by goroutine 21: github.com/tendermint/tendermint/consensus.(*PeerState).RecordVote() github.com/tendermint/tendermint/consensus/_test/_obj_test/reactor.go:1242 +0x15a github.com/tendermint/tendermint/consensus.(*ConsensusReactor).Receive() github.com/tendermint/tendermint/consensus/_test/_obj_test/reactor.go:309 +0x32e6 github.com/tendermint/tendermint/p2p.createMConnection.func1() /home/ubuntu/go/src/github.com/tendermint/tendermint/p2p/peer.go:365 +0xea github.com/tendermint/tendermint/p2p/conn.(*MConnection).recvRoutine() /home/ubuntu/go/src/github.com/tendermint/tendermint/p2p/conn/connection.go:531 +0x779 ```
7 years ago
protect Record* peerStateStats functions by mutex Fixes #1414 DATA RACE: ``` Read at 0x00c4214ee940 by goroutine 146: github.com/tendermint/tendermint/consensus.(*peerStateStats).String() <autogenerated>:1 +0x57 fmt.(*pp).handleMethods() /usr/local/go/src/fmt/print.go:596 +0x3f4 fmt.(*pp).printArg() /usr/local/go/src/fmt/print.go:679 +0x11f fmt.(*pp).doPrintf() /usr/local/go/src/fmt/print.go:996 +0x319 fmt.Sprintf() /usr/local/go/src/fmt/print.go:196 +0x73 github.com/tendermint/tendermint/consensus.(*PeerState).StringIndented() github.com/tendermint/tendermint/consensus/_test/_obj_test/reactor.go:1426 +0x573 github.com/tendermint/tendermint/consensus.(*PeerState).String() github.com/tendermint/tendermint/consensus/_test/_obj_test/reactor.go:1419 +0x66 github.com/go-logfmt/logfmt.safeString() /home/ubuntu/go/src/github.com/go-logfmt/logfmt/encode.go:299 +0x9d github.com/go-logfmt/logfmt.writeValue() /home/ubuntu/go/src/github.com/go-logfmt/logfmt/encode.go:217 +0x5a0 github.com/go-logfmt/logfmt.(*Encoder).EncodeKeyval() /home/ubuntu/go/src/github.com/go-logfmt/logfmt/encode.go:61 +0x1dd github.com/tendermint/tmlibs/log.tmfmtLogger.Log() /home/ubuntu/go/src/github.com/tendermint/tmlibs/log/tmfmt_logger.go:107 +0x1001 github.com/tendermint/tmlibs/log.(*tmfmtLogger).Log() <autogenerated>:1 +0x93 github.com/go-kit/kit/log.(*context).Log() /home/ubuntu/go/src/github.com/go-kit/kit/log/log.go:124 +0x248 github.com/tendermint/tmlibs/log.(*tmLogger).Debug() /home/ubuntu/go/src/github.com/tendermint/tmlibs/log/tm_logger.go:64 +0x1d0 github.com/tendermint/tendermint/consensus.(*PeerState).PickSendVote() github.com/tendermint/tendermint/consensus/_test/_obj_test/reactor.go:1059 +0x242 github.com/tendermint/tendermint/consensus.(*ConsensusReactor).gossipVotesForHeight() github.com/tendermint/tendermint/consensus/_test/_obj_test/reactor.go:789 +0x6ef github.com/tendermint/tendermint/consensus.(*ConsensusReactor).gossipVotesRoutine() github.com/tendermint/tendermint/consensus/_test/_obj_test/reactor.go:723 +0x1039 Previous write at 0x00c4214ee940 by goroutine 21: github.com/tendermint/tendermint/consensus.(*PeerState).RecordVote() github.com/tendermint/tendermint/consensus/_test/_obj_test/reactor.go:1242 +0x15a github.com/tendermint/tendermint/consensus.(*ConsensusReactor).Receive() github.com/tendermint/tendermint/consensus/_test/_obj_test/reactor.go:309 +0x32e6 github.com/tendermint/tendermint/p2p.createMConnection.func1() /home/ubuntu/go/src/github.com/tendermint/tendermint/p2p/peer.go:365 +0xea github.com/tendermint/tendermint/p2p/conn.(*MConnection).recvRoutine() /home/ubuntu/go/src/github.com/tendermint/tendermint/p2p/conn/connection.go:531 +0x779 ```
7 years ago
10 years ago
10 years ago
10 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
10 years ago
10 years ago
10 years ago
7 years ago
  1. package consensus
  2. import (
  3. "fmt"
  4. "reflect"
  5. "sync"
  6. "time"
  7. "github.com/pkg/errors"
  8. "github.com/tendermint/go-amino"
  9. cstypes "github.com/tendermint/tendermint/consensus/types"
  10. cmn "github.com/tendermint/tendermint/libs/common"
  11. tmevents "github.com/tendermint/tendermint/libs/events"
  12. "github.com/tendermint/tendermint/libs/log"
  13. "github.com/tendermint/tendermint/p2p"
  14. sm "github.com/tendermint/tendermint/state"
  15. "github.com/tendermint/tendermint/types"
  16. tmtime "github.com/tendermint/tendermint/types/time"
  17. )
  18. const (
  19. StateChannel = byte(0x20)
  20. DataChannel = byte(0x21)
  21. VoteChannel = byte(0x22)
  22. VoteSetBitsChannel = byte(0x23)
  23. maxMsgSize = 1048576 // 1MB; NOTE/TODO: keep in sync with types.PartSet sizes.
  24. blocksToContributeToBecomeGoodPeer = 10000
  25. votesToContributeToBecomeGoodPeer = 10000
  26. )
  27. //-----------------------------------------------------------------------------
  28. // ConsensusReactor defines a reactor for the consensus service.
  29. type ConsensusReactor struct {
  30. p2p.BaseReactor // BaseService + p2p.Switch
  31. conS *ConsensusState
  32. mtx sync.RWMutex
  33. fastSync bool
  34. eventBus *types.EventBus
  35. metrics *Metrics
  36. }
  37. type ReactorOption func(*ConsensusReactor)
  38. // NewConsensusReactor returns a new ConsensusReactor with the given
  39. // consensusState.
  40. func NewConsensusReactor(consensusState *ConsensusState, fastSync bool, options ...ReactorOption) *ConsensusReactor {
  41. conR := &ConsensusReactor{
  42. conS: consensusState,
  43. fastSync: fastSync,
  44. metrics: NopMetrics(),
  45. }
  46. conR.updateFastSyncingMetric()
  47. conR.BaseReactor = *p2p.NewBaseReactor("ConsensusReactor", conR)
  48. for _, option := range options {
  49. option(conR)
  50. }
  51. return conR
  52. }
  53. // OnStart implements BaseService by subscribing to events, which later will be
  54. // broadcasted to other peers and starting state if we're not in fast sync.
  55. func (conR *ConsensusReactor) OnStart() error {
  56. conR.Logger.Info("ConsensusReactor ", "fastSync", conR.FastSync())
  57. // start routine that computes peer statistics for evaluating peer quality
  58. go conR.peerStatsRoutine()
  59. conR.subscribeToBroadcastEvents()
  60. if !conR.FastSync() {
  61. err := conR.conS.Start()
  62. if err != nil {
  63. return err
  64. }
  65. }
  66. return nil
  67. }
  68. // OnStop implements BaseService by unsubscribing from events and stopping
  69. // state.
  70. func (conR *ConsensusReactor) OnStop() {
  71. conR.unsubscribeFromBroadcastEvents()
  72. conR.conS.Stop()
  73. if !conR.FastSync() {
  74. conR.conS.Wait()
  75. }
  76. }
  77. // SwitchToConsensus switches from fast_sync mode to consensus mode.
  78. // It resets the state, turns off fast_sync, and starts the consensus state-machine
  79. func (conR *ConsensusReactor) SwitchToConsensus(state sm.State, blocksSynced int) {
  80. conR.Logger.Info("SwitchToConsensus")
  81. conR.conS.reconstructLastCommit(state)
  82. // NOTE: The line below causes broadcastNewRoundStepRoutine() to
  83. // broadcast a NewRoundStepMessage.
  84. conR.conS.updateToState(state)
  85. conR.mtx.Lock()
  86. conR.fastSync = false
  87. conR.mtx.Unlock()
  88. conR.metrics.FastSyncing.Set(0)
  89. if blocksSynced > 0 {
  90. // dont bother with the WAL if we fast synced
  91. conR.conS.doWALCatchup = false
  92. }
  93. err := conR.conS.Start()
  94. if err != nil {
  95. conR.Logger.Error("Error starting conS", "err", err)
  96. return
  97. }
  98. }
  99. // GetChannels implements Reactor
  100. func (conR *ConsensusReactor) GetChannels() []*p2p.ChannelDescriptor {
  101. // TODO optimize
  102. return []*p2p.ChannelDescriptor{
  103. {
  104. ID: StateChannel,
  105. Priority: 5,
  106. SendQueueCapacity: 100,
  107. RecvMessageCapacity: maxMsgSize,
  108. },
  109. {
  110. ID: DataChannel, // maybe split between gossiping current block and catchup stuff
  111. Priority: 10, // once we gossip the whole block there's nothing left to send until next height or round
  112. SendQueueCapacity: 100,
  113. RecvBufferCapacity: 50 * 4096,
  114. RecvMessageCapacity: maxMsgSize,
  115. },
  116. {
  117. ID: VoteChannel,
  118. Priority: 5,
  119. SendQueueCapacity: 100,
  120. RecvBufferCapacity: 100 * 100,
  121. RecvMessageCapacity: maxMsgSize,
  122. },
  123. {
  124. ID: VoteSetBitsChannel,
  125. Priority: 1,
  126. SendQueueCapacity: 2,
  127. RecvBufferCapacity: 1024,
  128. RecvMessageCapacity: maxMsgSize,
  129. },
  130. }
  131. }
  132. // AddPeer implements Reactor
  133. func (conR *ConsensusReactor) AddPeer(peer p2p.Peer) {
  134. if !conR.IsRunning() {
  135. return
  136. }
  137. // Create peerState for peer
  138. peerState := NewPeerState(peer).SetLogger(conR.Logger)
  139. peer.Set(types.PeerStateKey, peerState)
  140. // Begin routines for this peer.
  141. go conR.gossipDataRoutine(peer, peerState)
  142. go conR.gossipVotesRoutine(peer, peerState)
  143. go conR.queryMaj23Routine(peer, peerState)
  144. // Send our state to peer.
  145. // If we're fast_syncing, broadcast a RoundStepMessage later upon SwitchToConsensus().
  146. if !conR.FastSync() {
  147. conR.sendNewRoundStepMessages(peer)
  148. }
  149. }
  150. // RemovePeer implements Reactor
  151. func (conR *ConsensusReactor) RemovePeer(peer p2p.Peer, reason interface{}) {
  152. if !conR.IsRunning() {
  153. return
  154. }
  155. // TODO
  156. //peer.Get(PeerStateKey).(*PeerState).Disconnect()
  157. }
  158. // Receive implements Reactor
  159. // NOTE: We process these messages even when we're fast_syncing.
  160. // Messages affect either a peer state or the consensus state.
  161. // Peer state updates can happen in parallel, but processing of
  162. // proposals, block parts, and votes are ordered by the receiveRoutine
  163. // NOTE: blocks on consensus state for proposals, block parts, and votes
  164. func (conR *ConsensusReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte) {
  165. if !conR.IsRunning() {
  166. conR.Logger.Debug("Receive", "src", src, "chId", chID, "bytes", msgBytes)
  167. return
  168. }
  169. msg, err := decodeMsg(msgBytes)
  170. if err != nil {
  171. conR.Logger.Error("Error decoding message", "src", src, "chId", chID, "msg", msg, "err", err, "bytes", msgBytes)
  172. conR.Switch.StopPeerForError(src, err)
  173. return
  174. }
  175. conR.Logger.Debug("Receive", "src", src, "chId", chID, "msg", msg)
  176. // Get peer states
  177. ps := src.Get(types.PeerStateKey).(*PeerState)
  178. switch chID {
  179. case StateChannel:
  180. switch msg := msg.(type) {
  181. case *NewRoundStepMessage:
  182. ps.ApplyNewRoundStepMessage(msg)
  183. case *CommitStepMessage:
  184. ps.ApplyCommitStepMessage(msg)
  185. case *HasVoteMessage:
  186. ps.ApplyHasVoteMessage(msg)
  187. case *VoteSetMaj23Message:
  188. cs := conR.conS
  189. cs.mtx.Lock()
  190. height, votes := cs.Height, cs.Votes
  191. cs.mtx.Unlock()
  192. if height != msg.Height {
  193. return
  194. }
  195. // Peer claims to have a maj23 for some BlockID at H,R,S,
  196. err := votes.SetPeerMaj23(msg.Round, msg.Type, ps.peer.ID(), msg.BlockID)
  197. if err != nil {
  198. conR.Switch.StopPeerForError(src, err)
  199. return
  200. }
  201. // Respond with a VoteSetBitsMessage showing which votes we have.
  202. // (and consequently shows which we don't have)
  203. var ourVotes *cmn.BitArray
  204. switch msg.Type {
  205. case types.PrevoteType:
  206. ourVotes = votes.Prevotes(msg.Round).BitArrayByBlockID(msg.BlockID)
  207. case types.PrecommitType:
  208. ourVotes = votes.Precommits(msg.Round).BitArrayByBlockID(msg.BlockID)
  209. default:
  210. conR.Logger.Error("Bad VoteSetBitsMessage field Type")
  211. return
  212. }
  213. src.TrySend(VoteSetBitsChannel, cdc.MustMarshalBinaryBare(&VoteSetBitsMessage{
  214. Height: msg.Height,
  215. Round: msg.Round,
  216. Type: msg.Type,
  217. BlockID: msg.BlockID,
  218. Votes: ourVotes,
  219. }))
  220. case *ProposalHeartbeatMessage:
  221. hb := msg.Heartbeat
  222. conR.Logger.Debug("Received proposal heartbeat message",
  223. "height", hb.Height, "round", hb.Round, "sequence", hb.Sequence,
  224. "valIdx", hb.ValidatorIndex, "valAddr", hb.ValidatorAddress)
  225. default:
  226. conR.Logger.Error(fmt.Sprintf("Unknown message type %v", reflect.TypeOf(msg)))
  227. }
  228. case DataChannel:
  229. if conR.FastSync() {
  230. conR.Logger.Info("Ignoring message received during fastSync", "msg", msg)
  231. return
  232. }
  233. switch msg := msg.(type) {
  234. case *ProposalMessage:
  235. ps.SetHasProposal(msg.Proposal)
  236. conR.conS.peerMsgQueue <- msgInfo{msg, src.ID()}
  237. case *ProposalPOLMessage:
  238. ps.ApplyProposalPOLMessage(msg)
  239. case *BlockPartMessage:
  240. ps.SetHasProposalBlockPart(msg.Height, msg.Round, msg.Part.Index)
  241. conR.metrics.BlockParts.With("peer_id", string(src.ID())).Add(1)
  242. conR.conS.peerMsgQueue <- msgInfo{msg, src.ID()}
  243. default:
  244. conR.Logger.Error(fmt.Sprintf("Unknown message type %v", reflect.TypeOf(msg)))
  245. }
  246. case VoteChannel:
  247. if conR.FastSync() {
  248. conR.Logger.Info("Ignoring message received during fastSync", "msg", msg)
  249. return
  250. }
  251. switch msg := msg.(type) {
  252. case *VoteMessage:
  253. cs := conR.conS
  254. cs.mtx.Lock()
  255. height, valSize, lastCommitSize := cs.Height, cs.Validators.Size(), cs.LastCommit.Size()
  256. cs.mtx.Unlock()
  257. ps.EnsureVoteBitArrays(height, valSize)
  258. ps.EnsureVoteBitArrays(height-1, lastCommitSize)
  259. ps.SetHasVote(msg.Vote)
  260. cs.peerMsgQueue <- msgInfo{msg, src.ID()}
  261. default:
  262. // don't punish (leave room for soft upgrades)
  263. conR.Logger.Error(fmt.Sprintf("Unknown message type %v", reflect.TypeOf(msg)))
  264. }
  265. case VoteSetBitsChannel:
  266. if conR.FastSync() {
  267. conR.Logger.Info("Ignoring message received during fastSync", "msg", msg)
  268. return
  269. }
  270. switch msg := msg.(type) {
  271. case *VoteSetBitsMessage:
  272. cs := conR.conS
  273. cs.mtx.Lock()
  274. height, votes := cs.Height, cs.Votes
  275. cs.mtx.Unlock()
  276. if height == msg.Height {
  277. var ourVotes *cmn.BitArray
  278. switch msg.Type {
  279. case types.PrevoteType:
  280. ourVotes = votes.Prevotes(msg.Round).BitArrayByBlockID(msg.BlockID)
  281. case types.PrecommitType:
  282. ourVotes = votes.Precommits(msg.Round).BitArrayByBlockID(msg.BlockID)
  283. default:
  284. conR.Logger.Error("Bad VoteSetBitsMessage field Type")
  285. return
  286. }
  287. ps.ApplyVoteSetBitsMessage(msg, ourVotes)
  288. } else {
  289. ps.ApplyVoteSetBitsMessage(msg, nil)
  290. }
  291. default:
  292. // don't punish (leave room for soft upgrades)
  293. conR.Logger.Error(fmt.Sprintf("Unknown message type %v", reflect.TypeOf(msg)))
  294. }
  295. default:
  296. conR.Logger.Error(fmt.Sprintf("Unknown chId %X", chID))
  297. }
  298. if err != nil {
  299. conR.Logger.Error("Error in Receive()", "err", err)
  300. }
  301. }
  302. // SetEventBus sets event bus.
  303. func (conR *ConsensusReactor) SetEventBus(b *types.EventBus) {
  304. conR.eventBus = b
  305. conR.conS.SetEventBus(b)
  306. }
  307. // FastSync returns whether the consensus reactor is in fast-sync mode.
  308. func (conR *ConsensusReactor) FastSync() bool {
  309. conR.mtx.RLock()
  310. defer conR.mtx.RUnlock()
  311. return conR.fastSync
  312. }
  313. //--------------------------------------
  314. // subscribeToBroadcastEvents subscribes for new round steps, votes and
  315. // proposal heartbeats using internal pubsub defined on state to broadcast
  316. // them to peers upon receiving.
  317. func (conR *ConsensusReactor) subscribeToBroadcastEvents() {
  318. const subscriber = "consensus-reactor"
  319. conR.conS.evsw.AddListenerForEvent(subscriber, types.EventNewRoundStep,
  320. func(data tmevents.EventData) {
  321. conR.broadcastNewRoundStepMessages(data.(*cstypes.RoundState))
  322. })
  323. conR.conS.evsw.AddListenerForEvent(subscriber, types.EventVote,
  324. func(data tmevents.EventData) {
  325. conR.broadcastHasVoteMessage(data.(*types.Vote))
  326. })
  327. conR.conS.evsw.AddListenerForEvent(subscriber, types.EventProposalHeartbeat,
  328. func(data tmevents.EventData) {
  329. conR.broadcastProposalHeartbeatMessage(data.(*types.Heartbeat))
  330. })
  331. }
  332. func (conR *ConsensusReactor) unsubscribeFromBroadcastEvents() {
  333. const subscriber = "consensus-reactor"
  334. conR.conS.evsw.RemoveListener(subscriber)
  335. }
  336. func (conR *ConsensusReactor) broadcastProposalHeartbeatMessage(hb *types.Heartbeat) {
  337. conR.Logger.Debug("Broadcasting proposal heartbeat message",
  338. "height", hb.Height, "round", hb.Round, "sequence", hb.Sequence)
  339. msg := &ProposalHeartbeatMessage{hb}
  340. conR.Switch.Broadcast(StateChannel, cdc.MustMarshalBinaryBare(msg))
  341. }
  342. func (conR *ConsensusReactor) broadcastNewRoundStepMessages(rs *cstypes.RoundState) {
  343. nrsMsg, csMsg := makeRoundStepMessages(rs)
  344. if nrsMsg != nil {
  345. conR.Switch.Broadcast(StateChannel, cdc.MustMarshalBinaryBare(nrsMsg))
  346. }
  347. if csMsg != nil {
  348. conR.Switch.Broadcast(StateChannel, cdc.MustMarshalBinaryBare(csMsg))
  349. }
  350. }
  351. // Broadcasts HasVoteMessage to peers that care.
  352. func (conR *ConsensusReactor) broadcastHasVoteMessage(vote *types.Vote) {
  353. msg := &HasVoteMessage{
  354. Height: vote.Height,
  355. Round: vote.Round,
  356. Type: vote.Type,
  357. Index: vote.ValidatorIndex,
  358. }
  359. conR.Switch.Broadcast(StateChannel, cdc.MustMarshalBinaryBare(msg))
  360. /*
  361. // TODO: Make this broadcast more selective.
  362. for _, peer := range conR.Switch.Peers().List() {
  363. ps := peer.Get(PeerStateKey).(*PeerState)
  364. prs := ps.GetRoundState()
  365. if prs.Height == vote.Height {
  366. // TODO: Also filter on round?
  367. peer.TrySend(StateChannel, struct{ ConsensusMessage }{msg})
  368. } else {
  369. // Height doesn't match
  370. // TODO: check a field, maybe CatchupCommitRound?
  371. // TODO: But that requires changing the struct field comment.
  372. }
  373. }
  374. */
  375. }
  376. func makeRoundStepMessages(rs *cstypes.RoundState) (nrsMsg *NewRoundStepMessage, csMsg *CommitStepMessage) {
  377. nrsMsg = &NewRoundStepMessage{
  378. Height: rs.Height,
  379. Round: rs.Round,
  380. Step: rs.Step,
  381. SecondsSinceStartTime: int(time.Since(rs.StartTime).Seconds()),
  382. LastCommitRound: rs.LastCommit.Round(),
  383. }
  384. if rs.Step == cstypes.RoundStepCommit {
  385. csMsg = &CommitStepMessage{
  386. Height: rs.Height,
  387. BlockPartsHeader: rs.ProposalBlockParts.Header(),
  388. BlockParts: rs.ProposalBlockParts.BitArray(),
  389. }
  390. }
  391. return
  392. }
  393. func (conR *ConsensusReactor) sendNewRoundStepMessages(peer p2p.Peer) {
  394. rs := conR.conS.GetRoundState()
  395. nrsMsg, csMsg := makeRoundStepMessages(rs)
  396. if nrsMsg != nil {
  397. peer.Send(StateChannel, cdc.MustMarshalBinaryBare(nrsMsg))
  398. }
  399. if csMsg != nil {
  400. peer.Send(StateChannel, cdc.MustMarshalBinaryBare(csMsg))
  401. }
  402. }
  403. func (conR *ConsensusReactor) gossipDataRoutine(peer p2p.Peer, ps *PeerState) {
  404. logger := conR.Logger.With("peer", peer)
  405. OUTER_LOOP:
  406. for {
  407. // Manage disconnects from self or peer.
  408. if !peer.IsRunning() || !conR.IsRunning() {
  409. logger.Info("Stopping gossipDataRoutine for peer")
  410. return
  411. }
  412. rs := conR.conS.GetRoundState()
  413. prs := ps.GetRoundState()
  414. // Send proposal Block parts?
  415. if rs.ProposalBlockParts.HasHeader(prs.ProposalBlockPartsHeader) {
  416. if index, ok := rs.ProposalBlockParts.BitArray().Sub(prs.ProposalBlockParts.Copy()).PickRandom(); ok {
  417. part := rs.ProposalBlockParts.GetPart(index)
  418. msg := &BlockPartMessage{
  419. Height: rs.Height, // This tells peer that this part applies to us.
  420. Round: rs.Round, // This tells peer that this part applies to us.
  421. Part: part,
  422. }
  423. logger.Debug("Sending block part", "height", prs.Height, "round", prs.Round)
  424. if peer.Send(DataChannel, cdc.MustMarshalBinaryBare(msg)) {
  425. ps.SetHasProposalBlockPart(prs.Height, prs.Round, index)
  426. }
  427. continue OUTER_LOOP
  428. }
  429. }
  430. // If the peer is on a previous height, help catch up.
  431. if (0 < prs.Height) && (prs.Height < rs.Height) {
  432. heightLogger := logger.With("height", prs.Height)
  433. // if we never received the commit message from the peer, the block parts wont be initialized
  434. if prs.ProposalBlockParts == nil {
  435. blockMeta := conR.conS.blockStore.LoadBlockMeta(prs.Height)
  436. if blockMeta == nil {
  437. cmn.PanicCrisis(fmt.Sprintf("Failed to load block %d when blockStore is at %d",
  438. prs.Height, conR.conS.blockStore.Height()))
  439. }
  440. ps.InitProposalBlockParts(blockMeta.BlockID.PartsHeader)
  441. // continue the loop since prs is a copy and not effected by this initialization
  442. continue OUTER_LOOP
  443. }
  444. conR.gossipDataForCatchup(heightLogger, rs, prs, ps, peer)
  445. continue OUTER_LOOP
  446. }
  447. // If height and round don't match, sleep.
  448. if (rs.Height != prs.Height) || (rs.Round != prs.Round) {
  449. //logger.Info("Peer Height|Round mismatch, sleeping", "peerHeight", prs.Height, "peerRound", prs.Round, "peer", peer)
  450. time.Sleep(conR.conS.config.PeerGossipSleepDuration)
  451. continue OUTER_LOOP
  452. }
  453. // By here, height and round match.
  454. // Proposal block parts were already matched and sent if any were wanted.
  455. // (These can match on hash so the round doesn't matter)
  456. // Now consider sending other things, like the Proposal itself.
  457. // Send Proposal && ProposalPOL BitArray?
  458. if rs.Proposal != nil && !prs.Proposal {
  459. // Proposal: share the proposal metadata with peer.
  460. {
  461. msg := &ProposalMessage{Proposal: rs.Proposal}
  462. logger.Debug("Sending proposal", "height", prs.Height, "round", prs.Round)
  463. if peer.Send(DataChannel, cdc.MustMarshalBinaryBare(msg)) {
  464. ps.SetHasProposal(rs.Proposal)
  465. }
  466. }
  467. // ProposalPOL: lets peer know which POL votes we have so far.
  468. // Peer must receive ProposalMessage first.
  469. // rs.Proposal was validated, so rs.Proposal.POLRound <= rs.Round,
  470. // so we definitely have rs.Votes.Prevotes(rs.Proposal.POLRound).
  471. if 0 <= rs.Proposal.POLRound {
  472. msg := &ProposalPOLMessage{
  473. Height: rs.Height,
  474. ProposalPOLRound: rs.Proposal.POLRound,
  475. ProposalPOL: rs.Votes.Prevotes(rs.Proposal.POLRound).BitArray(),
  476. }
  477. logger.Debug("Sending POL", "height", prs.Height, "round", prs.Round)
  478. peer.Send(DataChannel, cdc.MustMarshalBinaryBare(msg))
  479. }
  480. continue OUTER_LOOP
  481. }
  482. // Nothing to do. Sleep.
  483. time.Sleep(conR.conS.config.PeerGossipSleepDuration)
  484. continue OUTER_LOOP
  485. }
  486. }
  487. func (conR *ConsensusReactor) gossipDataForCatchup(logger log.Logger, rs *cstypes.RoundState,
  488. prs *cstypes.PeerRoundState, ps *PeerState, peer p2p.Peer) {
  489. if index, ok := prs.ProposalBlockParts.Not().PickRandom(); ok {
  490. // Ensure that the peer's PartSetHeader is correct
  491. blockMeta := conR.conS.blockStore.LoadBlockMeta(prs.Height)
  492. if blockMeta == nil {
  493. logger.Error("Failed to load block meta",
  494. "ourHeight", rs.Height, "blockstoreHeight", conR.conS.blockStore.Height())
  495. time.Sleep(conR.conS.config.PeerGossipSleepDuration)
  496. return
  497. } else if !blockMeta.BlockID.PartsHeader.Equals(prs.ProposalBlockPartsHeader) {
  498. logger.Info("Peer ProposalBlockPartsHeader mismatch, sleeping",
  499. "blockPartsHeader", blockMeta.BlockID.PartsHeader, "peerBlockPartsHeader", prs.ProposalBlockPartsHeader)
  500. time.Sleep(conR.conS.config.PeerGossipSleepDuration)
  501. return
  502. }
  503. // Load the part
  504. part := conR.conS.blockStore.LoadBlockPart(prs.Height, index)
  505. if part == nil {
  506. logger.Error("Could not load part", "index", index,
  507. "blockPartsHeader", blockMeta.BlockID.PartsHeader, "peerBlockPartsHeader", prs.ProposalBlockPartsHeader)
  508. time.Sleep(conR.conS.config.PeerGossipSleepDuration)
  509. return
  510. }
  511. // Send the part
  512. msg := &BlockPartMessage{
  513. Height: prs.Height, // Not our height, so it doesn't matter.
  514. Round: prs.Round, // Not our height, so it doesn't matter.
  515. Part: part,
  516. }
  517. logger.Debug("Sending block part for catchup", "round", prs.Round, "index", index)
  518. if peer.Send(DataChannel, cdc.MustMarshalBinaryBare(msg)) {
  519. ps.SetHasProposalBlockPart(prs.Height, prs.Round, index)
  520. } else {
  521. logger.Debug("Sending block part for catchup failed")
  522. }
  523. return
  524. }
  525. //logger.Info("No parts to send in catch-up, sleeping")
  526. time.Sleep(conR.conS.config.PeerGossipSleepDuration)
  527. }
  528. func (conR *ConsensusReactor) gossipVotesRoutine(peer p2p.Peer, ps *PeerState) {
  529. logger := conR.Logger.With("peer", peer)
  530. // Simple hack to throttle logs upon sleep.
  531. var sleeping = 0
  532. OUTER_LOOP:
  533. for {
  534. // Manage disconnects from self or peer.
  535. if !peer.IsRunning() || !conR.IsRunning() {
  536. logger.Info("Stopping gossipVotesRoutine for peer")
  537. return
  538. }
  539. rs := conR.conS.GetRoundState()
  540. prs := ps.GetRoundState()
  541. switch sleeping {
  542. case 1: // First sleep
  543. sleeping = 2
  544. case 2: // No more sleep
  545. sleeping = 0
  546. }
  547. //logger.Debug("gossipVotesRoutine", "rsHeight", rs.Height, "rsRound", rs.Round,
  548. // "prsHeight", prs.Height, "prsRound", prs.Round, "prsStep", prs.Step)
  549. // If height matches, then send LastCommit, Prevotes, Precommits.
  550. if rs.Height == prs.Height {
  551. heightLogger := logger.With("height", prs.Height)
  552. if conR.gossipVotesForHeight(heightLogger, rs, prs, ps) {
  553. continue OUTER_LOOP
  554. }
  555. }
  556. // Special catchup logic.
  557. // If peer is lagging by height 1, send LastCommit.
  558. if prs.Height != 0 && rs.Height == prs.Height+1 {
  559. if ps.PickSendVote(rs.LastCommit) {
  560. logger.Debug("Picked rs.LastCommit to send", "height", prs.Height)
  561. continue OUTER_LOOP
  562. }
  563. }
  564. // Catchup logic
  565. // If peer is lagging by more than 1, send Commit.
  566. if prs.Height != 0 && rs.Height >= prs.Height+2 {
  567. // Load the block commit for prs.Height,
  568. // which contains precommit signatures for prs.Height.
  569. commit := conR.conS.blockStore.LoadBlockCommit(prs.Height)
  570. if ps.PickSendVote(commit) {
  571. logger.Debug("Picked Catchup commit to send", "height", prs.Height)
  572. continue OUTER_LOOP
  573. }
  574. }
  575. if sleeping == 0 {
  576. // We sent nothing. Sleep...
  577. sleeping = 1
  578. logger.Debug("No votes to send, sleeping", "rs.Height", rs.Height, "prs.Height", prs.Height,
  579. "localPV", rs.Votes.Prevotes(rs.Round).BitArray(), "peerPV", prs.Prevotes,
  580. "localPC", rs.Votes.Precommits(rs.Round).BitArray(), "peerPC", prs.Precommits)
  581. } else if sleeping == 2 {
  582. // Continued sleep...
  583. sleeping = 1
  584. }
  585. time.Sleep(conR.conS.config.PeerGossipSleepDuration)
  586. continue OUTER_LOOP
  587. }
  588. }
  589. func (conR *ConsensusReactor) gossipVotesForHeight(logger log.Logger, rs *cstypes.RoundState, prs *cstypes.PeerRoundState, ps *PeerState) bool {
  590. // If there are lastCommits to send...
  591. if prs.Step == cstypes.RoundStepNewHeight {
  592. if ps.PickSendVote(rs.LastCommit) {
  593. logger.Debug("Picked rs.LastCommit to send")
  594. return true
  595. }
  596. }
  597. // If there are POL prevotes to send...
  598. if prs.Step <= cstypes.RoundStepPropose && prs.Round != -1 && prs.Round <= rs.Round && prs.ProposalPOLRound != -1 {
  599. if polPrevotes := rs.Votes.Prevotes(prs.ProposalPOLRound); polPrevotes != nil {
  600. if ps.PickSendVote(polPrevotes) {
  601. logger.Debug("Picked rs.Prevotes(prs.ProposalPOLRound) to send",
  602. "round", prs.ProposalPOLRound)
  603. return true
  604. }
  605. }
  606. }
  607. // If there are prevotes to send...
  608. if prs.Step <= cstypes.RoundStepPrevoteWait && prs.Round != -1 && prs.Round <= rs.Round {
  609. if ps.PickSendVote(rs.Votes.Prevotes(prs.Round)) {
  610. logger.Debug("Picked rs.Prevotes(prs.Round) to send", "round", prs.Round)
  611. return true
  612. }
  613. }
  614. // If there are precommits to send...
  615. if prs.Step <= cstypes.RoundStepPrecommitWait && prs.Round != -1 && prs.Round <= rs.Round {
  616. if ps.PickSendVote(rs.Votes.Precommits(prs.Round)) {
  617. logger.Debug("Picked rs.Precommits(prs.Round) to send", "round", prs.Round)
  618. return true
  619. }
  620. }
  621. // If there are prevotes to send...Needed because of validBlock mechanism
  622. if prs.Round != -1 && prs.Round <= rs.Round {
  623. if ps.PickSendVote(rs.Votes.Prevotes(prs.Round)) {
  624. logger.Debug("Picked rs.Prevotes(prs.Round) to send", "round", prs.Round)
  625. return true
  626. }
  627. }
  628. // If there are POLPrevotes to send...
  629. if prs.ProposalPOLRound != -1 {
  630. if polPrevotes := rs.Votes.Prevotes(prs.ProposalPOLRound); polPrevotes != nil {
  631. if ps.PickSendVote(polPrevotes) {
  632. logger.Debug("Picked rs.Prevotes(prs.ProposalPOLRound) to send",
  633. "round", prs.ProposalPOLRound)
  634. return true
  635. }
  636. }
  637. }
  638. return false
  639. }
  640. // NOTE: `queryMaj23Routine` has a simple crude design since it only comes
  641. // into play for liveness when there's a signature DDoS attack happening.
  642. func (conR *ConsensusReactor) queryMaj23Routine(peer p2p.Peer, ps *PeerState) {
  643. logger := conR.Logger.With("peer", peer)
  644. OUTER_LOOP:
  645. for {
  646. // Manage disconnects from self or peer.
  647. if !peer.IsRunning() || !conR.IsRunning() {
  648. logger.Info("Stopping queryMaj23Routine for peer")
  649. return
  650. }
  651. // Maybe send Height/Round/Prevotes
  652. {
  653. rs := conR.conS.GetRoundState()
  654. prs := ps.GetRoundState()
  655. if rs.Height == prs.Height {
  656. if maj23, ok := rs.Votes.Prevotes(prs.Round).TwoThirdsMajority(); ok {
  657. peer.TrySend(StateChannel, cdc.MustMarshalBinaryBare(&VoteSetMaj23Message{
  658. Height: prs.Height,
  659. Round: prs.Round,
  660. Type: types.PrevoteType,
  661. BlockID: maj23,
  662. }))
  663. time.Sleep(conR.conS.config.PeerQueryMaj23SleepDuration)
  664. }
  665. }
  666. }
  667. // Maybe send Height/Round/Precommits
  668. {
  669. rs := conR.conS.GetRoundState()
  670. prs := ps.GetRoundState()
  671. if rs.Height == prs.Height {
  672. if maj23, ok := rs.Votes.Precommits(prs.Round).TwoThirdsMajority(); ok {
  673. peer.TrySend(StateChannel, cdc.MustMarshalBinaryBare(&VoteSetMaj23Message{
  674. Height: prs.Height,
  675. Round: prs.Round,
  676. Type: types.PrecommitType,
  677. BlockID: maj23,
  678. }))
  679. time.Sleep(conR.conS.config.PeerQueryMaj23SleepDuration)
  680. }
  681. }
  682. }
  683. // Maybe send Height/Round/ProposalPOL
  684. {
  685. rs := conR.conS.GetRoundState()
  686. prs := ps.GetRoundState()
  687. if rs.Height == prs.Height && prs.ProposalPOLRound >= 0 {
  688. if maj23, ok := rs.Votes.Prevotes(prs.ProposalPOLRound).TwoThirdsMajority(); ok {
  689. peer.TrySend(StateChannel, cdc.MustMarshalBinaryBare(&VoteSetMaj23Message{
  690. Height: prs.Height,
  691. Round: prs.ProposalPOLRound,
  692. Type: types.PrevoteType,
  693. BlockID: maj23,
  694. }))
  695. time.Sleep(conR.conS.config.PeerQueryMaj23SleepDuration)
  696. }
  697. }
  698. }
  699. // Little point sending LastCommitRound/LastCommit,
  700. // These are fleeting and non-blocking.
  701. // Maybe send Height/CatchupCommitRound/CatchupCommit.
  702. {
  703. prs := ps.GetRoundState()
  704. if prs.CatchupCommitRound != -1 && 0 < prs.Height && prs.Height <= conR.conS.blockStore.Height() {
  705. commit := conR.conS.LoadCommit(prs.Height)
  706. peer.TrySend(StateChannel, cdc.MustMarshalBinaryBare(&VoteSetMaj23Message{
  707. Height: prs.Height,
  708. Round: commit.Round(),
  709. Type: types.PrecommitType,
  710. BlockID: commit.BlockID,
  711. }))
  712. time.Sleep(conR.conS.config.PeerQueryMaj23SleepDuration)
  713. }
  714. }
  715. time.Sleep(conR.conS.config.PeerQueryMaj23SleepDuration)
  716. continue OUTER_LOOP
  717. }
  718. }
  719. func (conR *ConsensusReactor) peerStatsRoutine() {
  720. for {
  721. if !conR.IsRunning() {
  722. conR.Logger.Info("Stopping peerStatsRoutine")
  723. return
  724. }
  725. select {
  726. case msg := <-conR.conS.statsMsgQueue:
  727. // Get peer
  728. peer := conR.Switch.Peers().Get(msg.PeerID)
  729. if peer == nil {
  730. conR.Logger.Debug("Attempt to update stats for non-existent peer",
  731. "peer", msg.PeerID)
  732. continue
  733. }
  734. // Get peer state
  735. ps := peer.Get(types.PeerStateKey).(*PeerState)
  736. switch msg.Msg.(type) {
  737. case *VoteMessage:
  738. if numVotes := ps.RecordVote(); numVotes%votesToContributeToBecomeGoodPeer == 0 {
  739. conR.Switch.MarkPeerAsGood(peer)
  740. }
  741. case *BlockPartMessage:
  742. if numParts := ps.RecordBlockPart(); numParts%blocksToContributeToBecomeGoodPeer == 0 {
  743. conR.Switch.MarkPeerAsGood(peer)
  744. }
  745. }
  746. case <-conR.conS.Quit():
  747. return
  748. case <-conR.Quit():
  749. return
  750. }
  751. }
  752. }
  753. // String returns a string representation of the ConsensusReactor.
  754. // NOTE: For now, it is just a hard-coded string to avoid accessing unprotected shared variables.
  755. // TODO: improve!
  756. func (conR *ConsensusReactor) String() string {
  757. // better not to access shared variables
  758. return "ConsensusReactor" // conR.StringIndented("")
  759. }
  760. // StringIndented returns an indented string representation of the ConsensusReactor
  761. func (conR *ConsensusReactor) StringIndented(indent string) string {
  762. s := "ConsensusReactor{\n"
  763. s += indent + " " + conR.conS.StringIndented(indent+" ") + "\n"
  764. for _, peer := range conR.Switch.Peers().List() {
  765. ps := peer.Get(types.PeerStateKey).(*PeerState)
  766. s += indent + " " + ps.StringIndented(indent+" ") + "\n"
  767. }
  768. s += indent + "}"
  769. return s
  770. }
  771. func (conR *ConsensusReactor) updateFastSyncingMetric() {
  772. var fastSyncing float64
  773. if conR.fastSync {
  774. fastSyncing = 1
  775. } else {
  776. fastSyncing = 0
  777. }
  778. conR.metrics.FastSyncing.Set(fastSyncing)
  779. }
  780. // ReactorMetrics sets the metrics
  781. func ReactorMetrics(metrics *Metrics) ReactorOption {
  782. return func(conR *ConsensusReactor) { conR.metrics = metrics }
  783. }
  784. //-----------------------------------------------------------------------------
  785. var (
  786. ErrPeerStateHeightRegression = errors.New("Error peer state height regression")
  787. ErrPeerStateInvalidStartTime = errors.New("Error peer state invalid startTime")
  788. )
  789. // PeerState contains the known state of a peer, including its connection and
  790. // threadsafe access to its PeerRoundState.
  791. // NOTE: THIS GETS DUMPED WITH rpc/core/consensus.go.
  792. // Be mindful of what you Expose.
  793. type PeerState struct {
  794. peer p2p.Peer
  795. logger log.Logger
  796. mtx sync.Mutex `json:"-"` // NOTE: Modify below using setters, never directly.
  797. PRS cstypes.PeerRoundState `json:"round_state"` // Exposed.
  798. Stats *peerStateStats `json:"stats"` // Exposed.
  799. }
  800. // peerStateStats holds internal statistics for a peer.
  801. type peerStateStats struct {
  802. Votes int `json:"votes"`
  803. BlockParts int `json:"block_parts"`
  804. }
  805. func (pss peerStateStats) String() string {
  806. return fmt.Sprintf("peerStateStats{votes: %d, blockParts: %d}",
  807. pss.Votes, pss.BlockParts)
  808. }
  809. // NewPeerState returns a new PeerState for the given Peer
  810. func NewPeerState(peer p2p.Peer) *PeerState {
  811. return &PeerState{
  812. peer: peer,
  813. logger: log.NewNopLogger(),
  814. PRS: cstypes.PeerRoundState{
  815. Round: -1,
  816. ProposalPOLRound: -1,
  817. LastCommitRound: -1,
  818. CatchupCommitRound: -1,
  819. },
  820. Stats: &peerStateStats{},
  821. }
  822. }
  823. // SetLogger allows to set a logger on the peer state. Returns the peer state
  824. // itself.
  825. func (ps *PeerState) SetLogger(logger log.Logger) *PeerState {
  826. ps.logger = logger
  827. return ps
  828. }
  829. // GetRoundState returns an shallow copy of the PeerRoundState.
  830. // There's no point in mutating it since it won't change PeerState.
  831. func (ps *PeerState) GetRoundState() *cstypes.PeerRoundState {
  832. ps.mtx.Lock()
  833. defer ps.mtx.Unlock()
  834. prs := ps.PRS // copy
  835. return &prs
  836. }
  837. // ToJSON returns a json of PeerState, marshalled using go-amino.
  838. func (ps *PeerState) ToJSON() ([]byte, error) {
  839. ps.mtx.Lock()
  840. defer ps.mtx.Unlock()
  841. return cdc.MarshalJSON(ps)
  842. }
  843. // GetHeight returns an atomic snapshot of the PeerRoundState's height
  844. // used by the mempool to ensure peers are caught up before broadcasting new txs
  845. func (ps *PeerState) GetHeight() int64 {
  846. ps.mtx.Lock()
  847. defer ps.mtx.Unlock()
  848. return ps.PRS.Height
  849. }
  850. // SetHasProposal sets the given proposal as known for the peer.
  851. func (ps *PeerState) SetHasProposal(proposal *types.Proposal) {
  852. ps.mtx.Lock()
  853. defer ps.mtx.Unlock()
  854. if ps.PRS.Height != proposal.Height || ps.PRS.Round != proposal.Round {
  855. return
  856. }
  857. if ps.PRS.Proposal {
  858. return
  859. }
  860. ps.PRS.Proposal = true
  861. ps.PRS.ProposalBlockPartsHeader = proposal.BlockPartsHeader
  862. ps.PRS.ProposalBlockParts = cmn.NewBitArray(proposal.BlockPartsHeader.Total)
  863. ps.PRS.ProposalPOLRound = proposal.POLRound
  864. ps.PRS.ProposalPOL = nil // Nil until ProposalPOLMessage received.
  865. }
  866. // InitProposalBlockParts initializes the peer's proposal block parts header and bit array.
  867. func (ps *PeerState) InitProposalBlockParts(partsHeader types.PartSetHeader) {
  868. ps.mtx.Lock()
  869. defer ps.mtx.Unlock()
  870. if ps.PRS.ProposalBlockParts != nil {
  871. return
  872. }
  873. ps.PRS.ProposalBlockPartsHeader = partsHeader
  874. ps.PRS.ProposalBlockParts = cmn.NewBitArray(partsHeader.Total)
  875. }
  876. // SetHasProposalBlockPart sets the given block part index as known for the peer.
  877. func (ps *PeerState) SetHasProposalBlockPart(height int64, round int, index int) {
  878. ps.mtx.Lock()
  879. defer ps.mtx.Unlock()
  880. if ps.PRS.Height != height || ps.PRS.Round != round {
  881. return
  882. }
  883. ps.PRS.ProposalBlockParts.SetIndex(index, true)
  884. }
  885. // PickSendVote picks a vote and sends it to the peer.
  886. // Returns true if vote was sent.
  887. func (ps *PeerState) PickSendVote(votes types.VoteSetReader) bool {
  888. if vote, ok := ps.PickVoteToSend(votes); ok {
  889. msg := &VoteMessage{vote}
  890. ps.logger.Debug("Sending vote message", "ps", ps, "vote", vote)
  891. return ps.peer.Send(VoteChannel, cdc.MustMarshalBinaryBare(msg))
  892. }
  893. return false
  894. }
  895. // PickVoteToSend picks a vote to send to the peer.
  896. // Returns true if a vote was picked.
  897. // NOTE: `votes` must be the correct Size() for the Height().
  898. func (ps *PeerState) PickVoteToSend(votes types.VoteSetReader) (vote *types.Vote, ok bool) {
  899. ps.mtx.Lock()
  900. defer ps.mtx.Unlock()
  901. if votes.Size() == 0 {
  902. return nil, false
  903. }
  904. height, round, type_, size := votes.Height(), votes.Round(), types.SignedMsgType(votes.Type()), votes.Size()
  905. // Lazily set data using 'votes'.
  906. if votes.IsCommit() {
  907. ps.ensureCatchupCommitRound(height, round, size)
  908. }
  909. ps.ensureVoteBitArrays(height, size)
  910. psVotes := ps.getVoteBitArray(height, round, type_)
  911. if psVotes == nil {
  912. return nil, false // Not something worth sending
  913. }
  914. if index, ok := votes.BitArray().Sub(psVotes).PickRandom(); ok {
  915. ps.setHasVote(height, round, type_, index)
  916. return votes.GetByIndex(index), true
  917. }
  918. return nil, false
  919. }
  920. func (ps *PeerState) getVoteBitArray(height int64, round int, type_ types.SignedMsgType) *cmn.BitArray {
  921. if !types.IsVoteTypeValid(type_) {
  922. return nil
  923. }
  924. if ps.PRS.Height == height {
  925. if ps.PRS.Round == round {
  926. switch type_ {
  927. case types.PrevoteType:
  928. return ps.PRS.Prevotes
  929. case types.PrecommitType:
  930. return ps.PRS.Precommits
  931. }
  932. }
  933. if ps.PRS.CatchupCommitRound == round {
  934. switch type_ {
  935. case types.PrevoteType:
  936. return nil
  937. case types.PrecommitType:
  938. return ps.PRS.CatchupCommit
  939. }
  940. }
  941. if ps.PRS.ProposalPOLRound == round {
  942. switch type_ {
  943. case types.PrevoteType:
  944. return ps.PRS.ProposalPOL
  945. case types.PrecommitType:
  946. return nil
  947. }
  948. }
  949. return nil
  950. }
  951. if ps.PRS.Height == height+1 {
  952. if ps.PRS.LastCommitRound == round {
  953. switch type_ {
  954. case types.PrevoteType:
  955. return nil
  956. case types.PrecommitType:
  957. return ps.PRS.LastCommit
  958. }
  959. }
  960. return nil
  961. }
  962. return nil
  963. }
  964. // 'round': A round for which we have a +2/3 commit.
  965. func (ps *PeerState) ensureCatchupCommitRound(height int64, round int, numValidators int) {
  966. if ps.PRS.Height != height {
  967. return
  968. }
  969. /*
  970. NOTE: This is wrong, 'round' could change.
  971. e.g. if orig round is not the same as block LastCommit round.
  972. if ps.CatchupCommitRound != -1 && ps.CatchupCommitRound != round {
  973. cmn.PanicSanity(fmt.Sprintf("Conflicting CatchupCommitRound. Height: %v, Orig: %v, New: %v", height, ps.CatchupCommitRound, round))
  974. }
  975. */
  976. if ps.PRS.CatchupCommitRound == round {
  977. return // Nothing to do!
  978. }
  979. ps.PRS.CatchupCommitRound = round
  980. if round == ps.PRS.Round {
  981. ps.PRS.CatchupCommit = ps.PRS.Precommits
  982. } else {
  983. ps.PRS.CatchupCommit = cmn.NewBitArray(numValidators)
  984. }
  985. }
  986. // EnsureVoteBitArrays ensures the bit-arrays have been allocated for tracking
  987. // what votes this peer has received.
  988. // NOTE: It's important to make sure that numValidators actually matches
  989. // what the node sees as the number of validators for height.
  990. func (ps *PeerState) EnsureVoteBitArrays(height int64, numValidators int) {
  991. ps.mtx.Lock()
  992. defer ps.mtx.Unlock()
  993. ps.ensureVoteBitArrays(height, numValidators)
  994. }
  995. func (ps *PeerState) ensureVoteBitArrays(height int64, numValidators int) {
  996. if ps.PRS.Height == height {
  997. if ps.PRS.Prevotes == nil {
  998. ps.PRS.Prevotes = cmn.NewBitArray(numValidators)
  999. }
  1000. if ps.PRS.Precommits == nil {
  1001. ps.PRS.Precommits = cmn.NewBitArray(numValidators)
  1002. }
  1003. if ps.PRS.CatchupCommit == nil {
  1004. ps.PRS.CatchupCommit = cmn.NewBitArray(numValidators)
  1005. }
  1006. if ps.PRS.ProposalPOL == nil {
  1007. ps.PRS.ProposalPOL = cmn.NewBitArray(numValidators)
  1008. }
  1009. } else if ps.PRS.Height == height+1 {
  1010. if ps.PRS.LastCommit == nil {
  1011. ps.PRS.LastCommit = cmn.NewBitArray(numValidators)
  1012. }
  1013. }
  1014. }
  1015. // RecordVote increments internal votes related statistics for this peer.
  1016. // It returns the total number of added votes.
  1017. func (ps *PeerState) RecordVote() int {
  1018. ps.mtx.Lock()
  1019. defer ps.mtx.Unlock()
  1020. ps.Stats.Votes++
  1021. return ps.Stats.Votes
  1022. }
  1023. // VotesSent returns the number of blocks for which peer has been sending us
  1024. // votes.
  1025. func (ps *PeerState) VotesSent() int {
  1026. ps.mtx.Lock()
  1027. defer ps.mtx.Unlock()
  1028. return ps.Stats.Votes
  1029. }
  1030. // RecordBlockPart increments internal block part related statistics for this peer.
  1031. // It returns the total number of added block parts.
  1032. func (ps *PeerState) RecordBlockPart() int {
  1033. ps.mtx.Lock()
  1034. defer ps.mtx.Unlock()
  1035. ps.Stats.BlockParts++
  1036. return ps.Stats.BlockParts
  1037. }
  1038. // BlockPartsSent returns the number of useful block parts the peer has sent us.
  1039. func (ps *PeerState) BlockPartsSent() int {
  1040. ps.mtx.Lock()
  1041. defer ps.mtx.Unlock()
  1042. return ps.Stats.BlockParts
  1043. }
  1044. // SetHasVote sets the given vote as known by the peer
  1045. func (ps *PeerState) SetHasVote(vote *types.Vote) {
  1046. ps.mtx.Lock()
  1047. defer ps.mtx.Unlock()
  1048. ps.setHasVote(vote.Height, vote.Round, vote.Type, vote.ValidatorIndex)
  1049. }
  1050. func (ps *PeerState) setHasVote(height int64, round int, type_ types.SignedMsgType, index int) {
  1051. logger := ps.logger.With("peerH/R", fmt.Sprintf("%d/%d", ps.PRS.Height, ps.PRS.Round), "H/R", fmt.Sprintf("%d/%d", height, round))
  1052. logger.Debug("setHasVote", "type", type_, "index", index)
  1053. // NOTE: some may be nil BitArrays -> no side effects.
  1054. psVotes := ps.getVoteBitArray(height, round, type_)
  1055. if psVotes != nil {
  1056. psVotes.SetIndex(index, true)
  1057. }
  1058. }
  1059. // ApplyNewRoundStepMessage updates the peer state for the new round.
  1060. func (ps *PeerState) ApplyNewRoundStepMessage(msg *NewRoundStepMessage) {
  1061. ps.mtx.Lock()
  1062. defer ps.mtx.Unlock()
  1063. // Ignore duplicates or decreases
  1064. if CompareHRS(msg.Height, msg.Round, msg.Step, ps.PRS.Height, ps.PRS.Round, ps.PRS.Step) <= 0 {
  1065. return
  1066. }
  1067. // Just remember these values.
  1068. psHeight := ps.PRS.Height
  1069. psRound := ps.PRS.Round
  1070. //psStep := ps.PRS.Step
  1071. psCatchupCommitRound := ps.PRS.CatchupCommitRound
  1072. psCatchupCommit := ps.PRS.CatchupCommit
  1073. startTime := tmtime.Now().Add(-1 * time.Duration(msg.SecondsSinceStartTime) * time.Second)
  1074. ps.PRS.Height = msg.Height
  1075. ps.PRS.Round = msg.Round
  1076. ps.PRS.Step = msg.Step
  1077. ps.PRS.StartTime = startTime
  1078. if psHeight != msg.Height || psRound != msg.Round {
  1079. ps.PRS.Proposal = false
  1080. ps.PRS.ProposalBlockPartsHeader = types.PartSetHeader{}
  1081. ps.PRS.ProposalBlockParts = nil
  1082. ps.PRS.ProposalPOLRound = -1
  1083. ps.PRS.ProposalPOL = nil
  1084. // We'll update the BitArray capacity later.
  1085. ps.PRS.Prevotes = nil
  1086. ps.PRS.Precommits = nil
  1087. }
  1088. if psHeight == msg.Height && psRound != msg.Round && msg.Round == psCatchupCommitRound {
  1089. // Peer caught up to CatchupCommitRound.
  1090. // Preserve psCatchupCommit!
  1091. // NOTE: We prefer to use prs.Precommits if
  1092. // pr.Round matches pr.CatchupCommitRound.
  1093. ps.PRS.Precommits = psCatchupCommit
  1094. }
  1095. if psHeight != msg.Height {
  1096. // Shift Precommits to LastCommit.
  1097. if psHeight+1 == msg.Height && psRound == msg.LastCommitRound {
  1098. ps.PRS.LastCommitRound = msg.LastCommitRound
  1099. ps.PRS.LastCommit = ps.PRS.Precommits
  1100. } else {
  1101. ps.PRS.LastCommitRound = msg.LastCommitRound
  1102. ps.PRS.LastCommit = nil
  1103. }
  1104. // We'll update the BitArray capacity later.
  1105. ps.PRS.CatchupCommitRound = -1
  1106. ps.PRS.CatchupCommit = nil
  1107. }
  1108. }
  1109. // ApplyCommitStepMessage updates the peer state for the new commit.
  1110. func (ps *PeerState) ApplyCommitStepMessage(msg *CommitStepMessage) {
  1111. ps.mtx.Lock()
  1112. defer ps.mtx.Unlock()
  1113. if ps.PRS.Height != msg.Height {
  1114. return
  1115. }
  1116. ps.PRS.ProposalBlockPartsHeader = msg.BlockPartsHeader
  1117. ps.PRS.ProposalBlockParts = msg.BlockParts
  1118. }
  1119. // ApplyProposalPOLMessage updates the peer state for the new proposal POL.
  1120. func (ps *PeerState) ApplyProposalPOLMessage(msg *ProposalPOLMessage) {
  1121. ps.mtx.Lock()
  1122. defer ps.mtx.Unlock()
  1123. if ps.PRS.Height != msg.Height {
  1124. return
  1125. }
  1126. if ps.PRS.ProposalPOLRound != msg.ProposalPOLRound {
  1127. return
  1128. }
  1129. // TODO: Merge onto existing ps.PRS.ProposalPOL?
  1130. // We might have sent some prevotes in the meantime.
  1131. ps.PRS.ProposalPOL = msg.ProposalPOL
  1132. }
  1133. // ApplyHasVoteMessage updates the peer state for the new vote.
  1134. func (ps *PeerState) ApplyHasVoteMessage(msg *HasVoteMessage) {
  1135. ps.mtx.Lock()
  1136. defer ps.mtx.Unlock()
  1137. if ps.PRS.Height != msg.Height {
  1138. return
  1139. }
  1140. ps.setHasVote(msg.Height, msg.Round, msg.Type, msg.Index)
  1141. }
  1142. // ApplyVoteSetBitsMessage updates the peer state for the bit-array of votes
  1143. // it claims to have for the corresponding BlockID.
  1144. // `ourVotes` is a BitArray of votes we have for msg.BlockID
  1145. // NOTE: if ourVotes is nil (e.g. msg.Height < rs.Height),
  1146. // we conservatively overwrite ps's votes w/ msg.Votes.
  1147. func (ps *PeerState) ApplyVoteSetBitsMessage(msg *VoteSetBitsMessage, ourVotes *cmn.BitArray) {
  1148. ps.mtx.Lock()
  1149. defer ps.mtx.Unlock()
  1150. votes := ps.getVoteBitArray(msg.Height, msg.Round, msg.Type)
  1151. if votes != nil {
  1152. if ourVotes == nil {
  1153. votes.Update(msg.Votes)
  1154. } else {
  1155. otherVotes := votes.Sub(ourVotes)
  1156. hasVotes := otherVotes.Or(msg.Votes)
  1157. votes.Update(hasVotes)
  1158. }
  1159. }
  1160. }
  1161. // String returns a string representation of the PeerState
  1162. func (ps *PeerState) String() string {
  1163. return ps.StringIndented("")
  1164. }
  1165. // StringIndented returns a string representation of the PeerState
  1166. func (ps *PeerState) StringIndented(indent string) string {
  1167. ps.mtx.Lock()
  1168. defer ps.mtx.Unlock()
  1169. return fmt.Sprintf(`PeerState{
  1170. %s Key %v
  1171. %s RoundState %v
  1172. %s Stats %v
  1173. %s}`,
  1174. indent, ps.peer.ID(),
  1175. indent, ps.PRS.StringIndented(indent+" "),
  1176. indent, ps.Stats,
  1177. indent)
  1178. }
  1179. //-----------------------------------------------------------------------------
  1180. // Messages
  1181. // ConsensusMessage is a message that can be sent and received on the ConsensusReactor
  1182. type ConsensusMessage interface{}
  1183. func RegisterConsensusMessages(cdc *amino.Codec) {
  1184. cdc.RegisterInterface((*ConsensusMessage)(nil), nil)
  1185. cdc.RegisterConcrete(&NewRoundStepMessage{}, "tendermint/NewRoundStepMessage", nil)
  1186. cdc.RegisterConcrete(&CommitStepMessage{}, "tendermint/CommitStep", nil)
  1187. cdc.RegisterConcrete(&ProposalMessage{}, "tendermint/Proposal", nil)
  1188. cdc.RegisterConcrete(&ProposalPOLMessage{}, "tendermint/ProposalPOL", nil)
  1189. cdc.RegisterConcrete(&BlockPartMessage{}, "tendermint/BlockPart", nil)
  1190. cdc.RegisterConcrete(&VoteMessage{}, "tendermint/Vote", nil)
  1191. cdc.RegisterConcrete(&HasVoteMessage{}, "tendermint/HasVote", nil)
  1192. cdc.RegisterConcrete(&VoteSetMaj23Message{}, "tendermint/VoteSetMaj23", nil)
  1193. cdc.RegisterConcrete(&VoteSetBitsMessage{}, "tendermint/VoteSetBits", nil)
  1194. cdc.RegisterConcrete(&ProposalHeartbeatMessage{}, "tendermint/ProposalHeartbeat", nil)
  1195. }
  1196. func decodeMsg(bz []byte) (msg ConsensusMessage, err error) {
  1197. if len(bz) > maxMsgSize {
  1198. return msg, fmt.Errorf("Msg exceeds max size (%d > %d)", len(bz), maxMsgSize)
  1199. }
  1200. err = cdc.UnmarshalBinaryBare(bz, &msg)
  1201. return
  1202. }
  1203. //-------------------------------------
  1204. // NewRoundStepMessage is sent for every step taken in the ConsensusState.
  1205. // For every height/round/step transition
  1206. type NewRoundStepMessage struct {
  1207. Height int64
  1208. Round int
  1209. Step cstypes.RoundStepType
  1210. SecondsSinceStartTime int
  1211. LastCommitRound int
  1212. }
  1213. // String returns a string representation.
  1214. func (m *NewRoundStepMessage) String() string {
  1215. return fmt.Sprintf("[NewRoundStep H:%v R:%v S:%v LCR:%v]",
  1216. m.Height, m.Round, m.Step, m.LastCommitRound)
  1217. }
  1218. //-------------------------------------
  1219. // CommitStepMessage is sent when a block is committed.
  1220. type CommitStepMessage struct {
  1221. Height int64
  1222. BlockPartsHeader types.PartSetHeader
  1223. BlockParts *cmn.BitArray
  1224. }
  1225. // String returns a string representation.
  1226. func (m *CommitStepMessage) String() string {
  1227. return fmt.Sprintf("[CommitStep H:%v BP:%v BA:%v]", m.Height, m.BlockPartsHeader, m.BlockParts)
  1228. }
  1229. //-------------------------------------
  1230. // ProposalMessage is sent when a new block is proposed.
  1231. type ProposalMessage struct {
  1232. Proposal *types.Proposal
  1233. }
  1234. // String returns a string representation.
  1235. func (m *ProposalMessage) String() string {
  1236. return fmt.Sprintf("[Proposal %v]", m.Proposal)
  1237. }
  1238. //-------------------------------------
  1239. // ProposalPOLMessage is sent when a previous proposal is re-proposed.
  1240. type ProposalPOLMessage struct {
  1241. Height int64
  1242. ProposalPOLRound int
  1243. ProposalPOL *cmn.BitArray
  1244. }
  1245. // String returns a string representation.
  1246. func (m *ProposalPOLMessage) String() string {
  1247. return fmt.Sprintf("[ProposalPOL H:%v POLR:%v POL:%v]", m.Height, m.ProposalPOLRound, m.ProposalPOL)
  1248. }
  1249. //-------------------------------------
  1250. // BlockPartMessage is sent when gossipping a piece of the proposed block.
  1251. type BlockPartMessage struct {
  1252. Height int64
  1253. Round int
  1254. Part *types.Part
  1255. }
  1256. // String returns a string representation.
  1257. func (m *BlockPartMessage) String() string {
  1258. return fmt.Sprintf("[BlockPart H:%v R:%v P:%v]", m.Height, m.Round, m.Part)
  1259. }
  1260. //-------------------------------------
  1261. // VoteMessage is sent when voting for a proposal (or lack thereof).
  1262. type VoteMessage struct {
  1263. Vote *types.Vote
  1264. }
  1265. // String returns a string representation.
  1266. func (m *VoteMessage) String() string {
  1267. return fmt.Sprintf("[Vote %v]", m.Vote)
  1268. }
  1269. //-------------------------------------
  1270. // HasVoteMessage is sent to indicate that a particular vote has been received.
  1271. type HasVoteMessage struct {
  1272. Height int64
  1273. Round int
  1274. Type types.SignedMsgType
  1275. Index int
  1276. }
  1277. // String returns a string representation.
  1278. func (m *HasVoteMessage) String() string {
  1279. return fmt.Sprintf("[HasVote VI:%v V:{%v/%02d/%v}]", m.Index, m.Height, m.Round, m.Type)
  1280. }
  1281. //-------------------------------------
  1282. // VoteSetMaj23Message is sent to indicate that a given BlockID has seen +2/3 votes.
  1283. type VoteSetMaj23Message struct {
  1284. Height int64
  1285. Round int
  1286. Type types.SignedMsgType
  1287. BlockID types.BlockID
  1288. }
  1289. // String returns a string representation.
  1290. func (m *VoteSetMaj23Message) String() string {
  1291. return fmt.Sprintf("[VSM23 %v/%02d/%v %v]", m.Height, m.Round, m.Type, m.BlockID)
  1292. }
  1293. //-------------------------------------
  1294. // VoteSetBitsMessage is sent to communicate the bit-array of votes seen for the BlockID.
  1295. type VoteSetBitsMessage struct {
  1296. Height int64
  1297. Round int
  1298. Type types.SignedMsgType
  1299. BlockID types.BlockID
  1300. Votes *cmn.BitArray
  1301. }
  1302. // String returns a string representation.
  1303. func (m *VoteSetBitsMessage) String() string {
  1304. return fmt.Sprintf("[VSB %v/%02d/%v %v %v]", m.Height, m.Round, m.Type, m.BlockID, m.Votes)
  1305. }
  1306. //-------------------------------------
  1307. // ProposalHeartbeatMessage is sent to signal that a node is alive and waiting for transactions for a proposal.
  1308. type ProposalHeartbeatMessage struct {
  1309. Heartbeat *types.Heartbeat
  1310. }
  1311. // String returns a string representation.
  1312. func (m *ProposalHeartbeatMessage) String() string {
  1313. return fmt.Sprintf("[HEARTBEAT %v]", m.Heartbeat)
  1314. }