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.

1515 lines
52 KiB

10 years ago
7 years ago
8 years ago
7 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 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
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
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
8 years ago
10 years ago
10 years ago
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
10 years ago
9 years ago
10 years ago
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
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
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
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
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
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
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
9 years ago
9 years ago
8 years ago
9 years ago
8 years ago
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
8 years ago
10 years ago
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
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 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
10 years ago
8 years ago
8 years ago
10 years ago
8 years ago
8 years ago
10 years ago
10 years ago
10 years ago
8 years ago
10 years ago
10 years ago
10 years ago
8 years ago
10 years ago
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
7 years ago
8 years ago
8 years ago
8 years ago
10 years ago
8 years ago
10 years ago
10 years ago
8 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
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
10 years ago
10 years ago
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
10 years ago
10 years ago
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
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
10 years ago
8 years ago
8 years ago
9 years ago
8 years ago
10 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
10 years ago
10 years ago
8 years ago
10 years ago
10 years ago
8 years ago
10 years ago
10 years ago
8 years ago
8 years ago
8 years ago
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
8 years ago
9 years ago
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
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
8 years ago
10 years ago
10 years ago
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
8 years ago
10 years ago
8 years ago
10 years ago
  1. package consensus
  2. import (
  3. "bytes"
  4. "errors"
  5. "fmt"
  6. "reflect"
  7. "runtime/debug"
  8. "sync"
  9. "time"
  10. fail "github.com/ebuchman/fail-test"
  11. wire "github.com/tendermint/go-wire"
  12. cmn "github.com/tendermint/tmlibs/common"
  13. "github.com/tendermint/tmlibs/log"
  14. cfg "github.com/tendermint/tendermint/config"
  15. cstypes "github.com/tendermint/tendermint/consensus/types"
  16. "github.com/tendermint/tendermint/proxy"
  17. sm "github.com/tendermint/tendermint/state"
  18. "github.com/tendermint/tendermint/types"
  19. )
  20. //-----------------------------------------------------------------------------
  21. // Config
  22. const (
  23. proposalHeartbeatIntervalSeconds = 2
  24. )
  25. //-----------------------------------------------------------------------------
  26. // Errors
  27. var (
  28. ErrInvalidProposalSignature = errors.New("Error invalid proposal signature")
  29. ErrInvalidProposalPOLRound = errors.New("Error invalid proposal POL round")
  30. ErrAddingVote = errors.New("Error adding vote")
  31. ErrVoteHeightMismatch = errors.New("Error vote height mismatch")
  32. )
  33. //-----------------------------------------------------------------------------
  34. var (
  35. msgQueueSize = 1000
  36. )
  37. // msgs from the reactor which may update the state
  38. type msgInfo struct {
  39. Msg ConsensusMessage `json:"msg"`
  40. PeerKey string `json:"peer_key"`
  41. }
  42. // internally generated messages which may update the state
  43. type timeoutInfo struct {
  44. Duration time.Duration `json:"duration"`
  45. Height int64 `json:"height"`
  46. Round int `json:"round"`
  47. Step cstypes.RoundStepType `json:"step"`
  48. }
  49. func (ti *timeoutInfo) String() string {
  50. return fmt.Sprintf("%v ; %d/%d %v", ti.Duration, ti.Height, ti.Round, ti.Step)
  51. }
  52. // ConsensusState handles execution of the consensus algorithm.
  53. // It processes votes and proposals, and upon reaching agreement,
  54. // commits blocks to the chain and executes them against the application.
  55. // The internal state machine receives input from peers, the internal validator, and from a timer.
  56. type ConsensusState struct {
  57. cmn.BaseService
  58. // config details
  59. config *cfg.ConsensusConfig
  60. privValidator types.PrivValidator // for signing votes
  61. // services for creating and executing blocks
  62. proxyAppConn proxy.AppConnConsensus
  63. blockStore types.BlockStore
  64. mempool types.Mempool
  65. // internal state
  66. mtx sync.Mutex
  67. cstypes.RoundState
  68. state *sm.State // State until height-1.
  69. // state changes may be triggered by msgs from peers,
  70. // msgs from ourself, or by timeouts
  71. peerMsgQueue chan msgInfo
  72. internalMsgQueue chan msgInfo
  73. timeoutTicker TimeoutTicker
  74. // we use eventBus to trigger msg broadcasts in the reactor,
  75. // and to notify external subscribers, eg. through a websocket
  76. eventBus *types.EventBus
  77. // a Write-Ahead Log ensures we can recover from any kind of crash
  78. // and helps us avoid signing conflicting votes
  79. wal WAL
  80. replayMode bool // so we don't log signing errors during replay
  81. doWALCatchup bool // determines if we even try to do the catchup
  82. // for tests where we want to limit the number of transitions the state makes
  83. nSteps int
  84. // some functions can be overwritten for testing
  85. decideProposal func(height int64, round int)
  86. doPrevote func(height int64, round int)
  87. setProposal func(proposal *types.Proposal) error
  88. // closed when we finish shutting down
  89. done chan struct{}
  90. }
  91. // NewConsensusState returns a new ConsensusState.
  92. func NewConsensusState(config *cfg.ConsensusConfig, state *sm.State, proxyAppConn proxy.AppConnConsensus, blockStore types.BlockStore, mempool types.Mempool) *ConsensusState {
  93. cs := &ConsensusState{
  94. config: config,
  95. proxyAppConn: proxyAppConn,
  96. blockStore: blockStore,
  97. mempool: mempool,
  98. peerMsgQueue: make(chan msgInfo, msgQueueSize),
  99. internalMsgQueue: make(chan msgInfo, msgQueueSize),
  100. timeoutTicker: NewTimeoutTicker(),
  101. done: make(chan struct{}),
  102. doWALCatchup: true,
  103. wal: nilWAL{},
  104. }
  105. // set function defaults (may be overwritten before calling Start)
  106. cs.decideProposal = cs.defaultDecideProposal
  107. cs.doPrevote = cs.defaultDoPrevote
  108. cs.setProposal = cs.defaultSetProposal
  109. cs.updateToState(state)
  110. // Don't call scheduleRound0 yet.
  111. // We do that upon Start().
  112. cs.reconstructLastCommit(state)
  113. cs.BaseService = *cmn.NewBaseService(nil, "ConsensusState", cs)
  114. return cs
  115. }
  116. //----------------------------------------
  117. // Public interface
  118. // SetLogger implements Service.
  119. func (cs *ConsensusState) SetLogger(l log.Logger) {
  120. cs.BaseService.Logger = l
  121. cs.timeoutTicker.SetLogger(l)
  122. }
  123. // SetEventBus sets event bus.
  124. func (cs *ConsensusState) SetEventBus(b *types.EventBus) {
  125. cs.eventBus = b
  126. }
  127. // String returns a string.
  128. func (cs *ConsensusState) String() string {
  129. // better not to access shared variables
  130. return cmn.Fmt("ConsensusState") //(H:%v R:%v S:%v", cs.Height, cs.Round, cs.Step)
  131. }
  132. // GetState returns a copy of the chain state.
  133. func (cs *ConsensusState) GetState() *sm.State {
  134. cs.mtx.Lock()
  135. defer cs.mtx.Unlock()
  136. return cs.state.Copy()
  137. }
  138. // GetRoundState returns a copy of the internal consensus state.
  139. func (cs *ConsensusState) GetRoundState() *cstypes.RoundState {
  140. cs.mtx.Lock()
  141. defer cs.mtx.Unlock()
  142. return cs.getRoundState()
  143. }
  144. func (cs *ConsensusState) getRoundState() *cstypes.RoundState {
  145. rs := cs.RoundState // copy
  146. return &rs
  147. }
  148. // GetValidators returns a copy of the current validators.
  149. func (cs *ConsensusState) GetValidators() (int64, []*types.Validator) {
  150. cs.mtx.Lock()
  151. defer cs.mtx.Unlock()
  152. return cs.state.LastBlockHeight, cs.state.Validators.Copy().Validators
  153. }
  154. // SetPrivValidator sets the private validator account for signing votes.
  155. func (cs *ConsensusState) SetPrivValidator(priv types.PrivValidator) {
  156. cs.mtx.Lock()
  157. defer cs.mtx.Unlock()
  158. cs.privValidator = priv
  159. }
  160. // SetTimeoutTicker sets the local timer. It may be useful to overwrite for testing.
  161. func (cs *ConsensusState) SetTimeoutTicker(timeoutTicker TimeoutTicker) {
  162. cs.mtx.Lock()
  163. defer cs.mtx.Unlock()
  164. cs.timeoutTicker = timeoutTicker
  165. }
  166. // LoadCommit loads the commit for a given height.
  167. func (cs *ConsensusState) LoadCommit(height int64) *types.Commit {
  168. cs.mtx.Lock()
  169. defer cs.mtx.Unlock()
  170. if height == cs.blockStore.Height() {
  171. return cs.blockStore.LoadSeenCommit(height)
  172. }
  173. return cs.blockStore.LoadBlockCommit(height)
  174. }
  175. // OnStart implements cmn.Service.
  176. // It loads the latest state via the WAL, and starts the timeout and receive routines.
  177. func (cs *ConsensusState) OnStart() error {
  178. // we may set the WAL in testing before calling Start,
  179. // so only OpenWAL if its still the nilWAL
  180. if _, ok := cs.wal.(nilWAL); ok {
  181. walFile := cs.config.WalFile()
  182. wal, err := cs.OpenWAL(walFile)
  183. if err != nil {
  184. cs.Logger.Error("Error loading ConsensusState wal", "err", err.Error())
  185. return err
  186. }
  187. cs.wal = wal
  188. }
  189. // we need the timeoutRoutine for replay so
  190. // we don't block on the tick chan.
  191. // NOTE: we will get a build up of garbage go routines
  192. // firing on the tockChan until the receiveRoutine is started
  193. // to deal with them (by that point, at most one will be valid)
  194. err := cs.timeoutTicker.Start()
  195. if err != nil {
  196. return err
  197. }
  198. // we may have lost some votes if the process crashed
  199. // reload from consensus log to catchup
  200. if cs.doWALCatchup {
  201. if err := cs.catchupReplay(cs.Height); err != nil {
  202. cs.Logger.Error("Error on catchup replay. Proceeding to start ConsensusState anyway", "err", err.Error())
  203. // NOTE: if we ever do return an error here,
  204. // make sure to stop the timeoutTicker
  205. }
  206. }
  207. // now start the receiveRoutine
  208. go cs.receiveRoutine(0)
  209. // schedule the first round!
  210. // use GetRoundState so we don't race the receiveRoutine for access
  211. cs.scheduleRound0(cs.GetRoundState())
  212. return nil
  213. }
  214. // timeoutRoutine: receive requests for timeouts on tickChan and fire timeouts on tockChan
  215. // receiveRoutine: serializes processing of proposoals, block parts, votes; coordinates state transitions
  216. func (cs *ConsensusState) startRoutines(maxSteps int) {
  217. err := cs.timeoutTicker.Start()
  218. if err != nil {
  219. cs.Logger.Error("Error starting timeout ticker", "err", err)
  220. return
  221. }
  222. go cs.receiveRoutine(maxSteps)
  223. }
  224. // OnStop implements cmn.Service. It stops all routines and waits for the WAL to finish.
  225. func (cs *ConsensusState) OnStop() {
  226. cs.BaseService.OnStop()
  227. cs.timeoutTicker.Stop()
  228. // Make BaseService.Wait() wait until cs.wal.Wait()
  229. if cs.IsRunning() {
  230. cs.wal.Wait()
  231. }
  232. }
  233. // Wait waits for the the main routine to return.
  234. // NOTE: be sure to Stop() the event switch and drain
  235. // any event channels or this may deadlock
  236. func (cs *ConsensusState) Wait() {
  237. <-cs.done
  238. }
  239. // OpenWAL opens a file to log all consensus messages and timeouts for deterministic accountability
  240. func (cs *ConsensusState) OpenWAL(walFile string) (WAL, error) {
  241. wal, err := NewWAL(walFile, cs.config.WalLight)
  242. if err != nil {
  243. cs.Logger.Error("Failed to open WAL for consensus state", "wal", walFile, "err", err)
  244. return nil, err
  245. }
  246. wal.SetLogger(cs.Logger.With("wal", walFile))
  247. if err := wal.Start(); err != nil {
  248. return nil, err
  249. }
  250. return wal, nil
  251. }
  252. //------------------------------------------------------------
  253. // Public interface for passing messages into the consensus state, possibly causing a state transition.
  254. // If peerKey == "", the msg is considered internal.
  255. // Messages are added to the appropriate queue (peer or internal).
  256. // If the queue is full, the function may block.
  257. // TODO: should these return anything or let callers just use events?
  258. // AddVote inputs a vote.
  259. func (cs *ConsensusState) AddVote(vote *types.Vote, peerKey string) (added bool, err error) {
  260. if peerKey == "" {
  261. cs.internalMsgQueue <- msgInfo{&VoteMessage{vote}, ""}
  262. } else {
  263. cs.peerMsgQueue <- msgInfo{&VoteMessage{vote}, peerKey}
  264. }
  265. // TODO: wait for event?!
  266. return false, nil
  267. }
  268. // SetProposal inputs a proposal.
  269. func (cs *ConsensusState) SetProposal(proposal *types.Proposal, peerKey string) error {
  270. if peerKey == "" {
  271. cs.internalMsgQueue <- msgInfo{&ProposalMessage{proposal}, ""}
  272. } else {
  273. cs.peerMsgQueue <- msgInfo{&ProposalMessage{proposal}, peerKey}
  274. }
  275. // TODO: wait for event?!
  276. return nil
  277. }
  278. // AddProposalBlockPart inputs a part of the proposal block.
  279. func (cs *ConsensusState) AddProposalBlockPart(height int64, round int, part *types.Part, peerKey string) error {
  280. if peerKey == "" {
  281. cs.internalMsgQueue <- msgInfo{&BlockPartMessage{height, round, part}, ""}
  282. } else {
  283. cs.peerMsgQueue <- msgInfo{&BlockPartMessage{height, round, part}, peerKey}
  284. }
  285. // TODO: wait for event?!
  286. return nil
  287. }
  288. // SetProposalAndBlock inputs the proposal and all block parts.
  289. func (cs *ConsensusState) SetProposalAndBlock(proposal *types.Proposal, block *types.Block, parts *types.PartSet, peerKey string) error {
  290. if err := cs.SetProposal(proposal, peerKey); err != nil {
  291. return err
  292. }
  293. for i := 0; i < parts.Total(); i++ {
  294. part := parts.GetPart(i)
  295. if err := cs.AddProposalBlockPart(proposal.Height, proposal.Round, part, peerKey); err != nil {
  296. return err
  297. }
  298. }
  299. return nil
  300. }
  301. //------------------------------------------------------------
  302. // internal functions for managing the state
  303. func (cs *ConsensusState) updateHeight(height int64) {
  304. cs.Height = height
  305. }
  306. func (cs *ConsensusState) updateRoundStep(round int, step cstypes.RoundStepType) {
  307. cs.Round = round
  308. cs.Step = step
  309. }
  310. // enterNewRound(height, 0) at cs.StartTime.
  311. func (cs *ConsensusState) scheduleRound0(rs *cstypes.RoundState) {
  312. //cs.Logger.Info("scheduleRound0", "now", time.Now(), "startTime", cs.StartTime)
  313. sleepDuration := rs.StartTime.Sub(time.Now()) // nolint: gotype, gosimple
  314. cs.scheduleTimeout(sleepDuration, rs.Height, 0, cstypes.RoundStepNewHeight)
  315. }
  316. // Attempt to schedule a timeout (by sending timeoutInfo on the tickChan)
  317. func (cs *ConsensusState) scheduleTimeout(duration time.Duration, height int64, round int, step cstypes.RoundStepType) {
  318. cs.timeoutTicker.ScheduleTimeout(timeoutInfo{duration, height, round, step})
  319. }
  320. // send a msg into the receiveRoutine regarding our own proposal, block part, or vote
  321. func (cs *ConsensusState) sendInternalMessage(mi msgInfo) {
  322. select {
  323. case cs.internalMsgQueue <- mi:
  324. default:
  325. // NOTE: using the go-routine means our votes can
  326. // be processed out of order.
  327. // TODO: use CList here for strict determinism and
  328. // attempt push to internalMsgQueue in receiveRoutine
  329. cs.Logger.Info("Internal msg queue is full. Using a go-routine")
  330. go func() { cs.internalMsgQueue <- mi }()
  331. }
  332. }
  333. // Reconstruct LastCommit from SeenCommit, which we saved along with the block,
  334. // (which happens even before saving the state)
  335. func (cs *ConsensusState) reconstructLastCommit(state *sm.State) {
  336. if state.LastBlockHeight == 0 {
  337. return
  338. }
  339. seenCommit := cs.blockStore.LoadSeenCommit(state.LastBlockHeight)
  340. lastPrecommits := types.NewVoteSet(state.ChainID, state.LastBlockHeight, seenCommit.Round(), types.VoteTypePrecommit, state.LastValidators)
  341. for _, precommit := range seenCommit.Precommits {
  342. if precommit == nil {
  343. continue
  344. }
  345. added, err := lastPrecommits.AddVote(precommit)
  346. if !added || err != nil {
  347. cmn.PanicCrisis(cmn.Fmt("Failed to reconstruct LastCommit: %v", err))
  348. }
  349. }
  350. if !lastPrecommits.HasTwoThirdsMajority() {
  351. cmn.PanicSanity("Failed to reconstruct LastCommit: Does not have +2/3 maj")
  352. }
  353. cs.LastCommit = lastPrecommits
  354. }
  355. // Updates ConsensusState and increments height to match that of state.
  356. // The round becomes 0 and cs.Step becomes cstypes.RoundStepNewHeight.
  357. func (cs *ConsensusState) updateToState(state *sm.State) {
  358. if cs.CommitRound > -1 && 0 < cs.Height && cs.Height != state.LastBlockHeight {
  359. cmn.PanicSanity(cmn.Fmt("updateToState() expected state height of %v but found %v",
  360. cs.Height, state.LastBlockHeight))
  361. }
  362. if cs.state != nil && cs.state.LastBlockHeight+1 != cs.Height {
  363. // This might happen when someone else is mutating cs.state.
  364. // Someone forgot to pass in state.Copy() somewhere?!
  365. cmn.PanicSanity(cmn.Fmt("Inconsistent cs.state.LastBlockHeight+1 %v vs cs.Height %v",
  366. cs.state.LastBlockHeight+1, cs.Height))
  367. }
  368. // If state isn't further out than cs.state, just ignore.
  369. // This happens when SwitchToConsensus() is called in the reactor.
  370. // We don't want to reset e.g. the Votes.
  371. if cs.state != nil && (state.LastBlockHeight <= cs.state.LastBlockHeight) {
  372. cs.Logger.Info("Ignoring updateToState()", "newHeight", state.LastBlockHeight+1, "oldHeight", cs.state.LastBlockHeight+1)
  373. return
  374. }
  375. // Reset fields based on state.
  376. validators := state.Validators
  377. lastPrecommits := (*types.VoteSet)(nil)
  378. if cs.CommitRound > -1 && cs.Votes != nil {
  379. if !cs.Votes.Precommits(cs.CommitRound).HasTwoThirdsMajority() {
  380. cmn.PanicSanity("updateToState(state) called but last Precommit round didn't have +2/3")
  381. }
  382. lastPrecommits = cs.Votes.Precommits(cs.CommitRound)
  383. }
  384. // Next desired block height
  385. height := state.LastBlockHeight + 1
  386. // RoundState fields
  387. cs.updateHeight(height)
  388. cs.updateRoundStep(0, cstypes.RoundStepNewHeight)
  389. if cs.CommitTime.IsZero() {
  390. // "Now" makes it easier to sync up dev nodes.
  391. // We add timeoutCommit to allow transactions
  392. // to be gathered for the first block.
  393. // And alternative solution that relies on clocks:
  394. // cs.StartTime = state.LastBlockTime.Add(timeoutCommit)
  395. cs.StartTime = cs.config.Commit(time.Now())
  396. } else {
  397. cs.StartTime = cs.config.Commit(cs.CommitTime)
  398. }
  399. cs.Validators = validators
  400. cs.Proposal = nil
  401. cs.ProposalBlock = nil
  402. cs.ProposalBlockParts = nil
  403. cs.LockedRound = 0
  404. cs.LockedBlock = nil
  405. cs.LockedBlockParts = nil
  406. cs.Votes = cstypes.NewHeightVoteSet(state.ChainID, height, validators)
  407. cs.CommitRound = -1
  408. cs.LastCommit = lastPrecommits
  409. cs.LastValidators = state.LastValidators
  410. cs.state = state
  411. // Finally, broadcast RoundState
  412. cs.newStep()
  413. }
  414. func (cs *ConsensusState) newStep() {
  415. rs := cs.RoundStateEvent()
  416. cs.wal.Save(rs)
  417. cs.nSteps += 1
  418. // newStep is called by updateToStep in NewConsensusState before the eventBus is set!
  419. if cs.eventBus != nil {
  420. cs.eventBus.PublishEventNewRoundStep(rs)
  421. }
  422. }
  423. //-----------------------------------------
  424. // the main go routines
  425. // receiveRoutine handles messages which may cause state transitions.
  426. // it's argument (n) is the number of messages to process before exiting - use 0 to run forever
  427. // It keeps the RoundState and is the only thing that updates it.
  428. // Updates (state transitions) happen on timeouts, complete proposals, and 2/3 majorities.
  429. // ConsensusState must be locked before any internal state is updated.
  430. func (cs *ConsensusState) receiveRoutine(maxSteps int) {
  431. defer func() {
  432. if r := recover(); r != nil {
  433. cs.Logger.Error("CONSENSUS FAILURE!!!", "err", r, "stack", string(debug.Stack()))
  434. }
  435. }()
  436. for {
  437. if maxSteps > 0 {
  438. if cs.nSteps >= maxSteps {
  439. cs.Logger.Info("reached max steps. exiting receive routine")
  440. cs.nSteps = 0
  441. return
  442. }
  443. }
  444. rs := cs.RoundState
  445. var mi msgInfo
  446. select {
  447. case height := <-cs.mempool.TxsAvailable():
  448. cs.handleTxsAvailable(height)
  449. case mi = <-cs.peerMsgQueue:
  450. cs.wal.Save(mi)
  451. // handles proposals, block parts, votes
  452. // may generate internal events (votes, complete proposals, 2/3 majorities)
  453. cs.handleMsg(mi)
  454. case mi = <-cs.internalMsgQueue:
  455. cs.wal.Save(mi)
  456. // handles proposals, block parts, votes
  457. cs.handleMsg(mi)
  458. case ti := <-cs.timeoutTicker.Chan(): // tockChan:
  459. cs.wal.Save(ti)
  460. // if the timeout is relevant to the rs
  461. // go to the next step
  462. cs.handleTimeout(ti, rs)
  463. case <-cs.Quit:
  464. // NOTE: the internalMsgQueue may have signed messages from our
  465. // priv_val that haven't hit the WAL, but its ok because
  466. // priv_val tracks LastSig
  467. // close wal now that we're done writing to it
  468. cs.wal.Stop()
  469. close(cs.done)
  470. return
  471. }
  472. }
  473. }
  474. // state transitions on complete-proposal, 2/3-any, 2/3-one
  475. func (cs *ConsensusState) handleMsg(mi msgInfo) {
  476. cs.mtx.Lock()
  477. defer cs.mtx.Unlock()
  478. var err error
  479. msg, peerKey := mi.Msg, mi.PeerKey
  480. switch msg := msg.(type) {
  481. case *ProposalMessage:
  482. // will not cause transition.
  483. // once proposal is set, we can receive block parts
  484. err = cs.setProposal(msg.Proposal)
  485. case *BlockPartMessage:
  486. // if the proposal is complete, we'll enterPrevote or tryFinalizeCommit
  487. _, err = cs.addProposalBlockPart(msg.Height, msg.Part, peerKey != "")
  488. if err != nil && msg.Round != cs.Round {
  489. err = nil
  490. }
  491. case *VoteMessage:
  492. // attempt to add the vote and dupeout the validator if its a duplicate signature
  493. // if the vote gives us a 2/3-any or 2/3-one, we transition
  494. err := cs.tryAddVote(msg.Vote, peerKey)
  495. if err == ErrAddingVote {
  496. // TODO: punish peer
  497. }
  498. // NOTE: the vote is broadcast to peers by the reactor listening
  499. // for vote events
  500. // TODO: If rs.Height == vote.Height && rs.Round < vote.Round,
  501. // the peer is sending us CatchupCommit precommits.
  502. // We could make note of this and help filter in broadcastHasVoteMessage().
  503. default:
  504. cs.Logger.Error("Unknown msg type", reflect.TypeOf(msg))
  505. }
  506. if err != nil {
  507. cs.Logger.Error("Error with msg", "type", reflect.TypeOf(msg), "peer", peerKey, "err", err, "msg", msg)
  508. }
  509. }
  510. func (cs *ConsensusState) handleTimeout(ti timeoutInfo, rs cstypes.RoundState) {
  511. cs.Logger.Debug("Received tock", "timeout", ti.Duration, "height", ti.Height, "round", ti.Round, "step", ti.Step)
  512. // timeouts must be for current height, round, step
  513. if ti.Height != rs.Height || ti.Round < rs.Round || (ti.Round == rs.Round && ti.Step < rs.Step) {
  514. cs.Logger.Debug("Ignoring tock because we're ahead", "height", rs.Height, "round", rs.Round, "step", rs.Step)
  515. return
  516. }
  517. // the timeout will now cause a state transition
  518. cs.mtx.Lock()
  519. defer cs.mtx.Unlock()
  520. switch ti.Step {
  521. case cstypes.RoundStepNewHeight:
  522. // NewRound event fired from enterNewRound.
  523. // XXX: should we fire timeout here (for timeout commit)?
  524. cs.enterNewRound(ti.Height, 0)
  525. case cstypes.RoundStepNewRound:
  526. cs.enterPropose(ti.Height, 0)
  527. case cstypes.RoundStepPropose:
  528. cs.eventBus.PublishEventTimeoutPropose(cs.RoundStateEvent())
  529. cs.enterPrevote(ti.Height, ti.Round)
  530. case cstypes.RoundStepPrevoteWait:
  531. cs.eventBus.PublishEventTimeoutWait(cs.RoundStateEvent())
  532. cs.enterPrecommit(ti.Height, ti.Round)
  533. case cstypes.RoundStepPrecommitWait:
  534. cs.eventBus.PublishEventTimeoutWait(cs.RoundStateEvent())
  535. cs.enterNewRound(ti.Height, ti.Round+1)
  536. default:
  537. panic(cmn.Fmt("Invalid timeout step: %v", ti.Step))
  538. }
  539. }
  540. func (cs *ConsensusState) handleTxsAvailable(height int64) {
  541. cs.mtx.Lock()
  542. defer cs.mtx.Unlock()
  543. // we only need to do this for round 0
  544. cs.enterPropose(height, 0)
  545. }
  546. //-----------------------------------------------------------------------------
  547. // State functions
  548. // Used internally by handleTimeout and handleMsg to make state transitions
  549. // Enter: `timeoutNewHeight` by startTime (commitTime+timeoutCommit),
  550. // or, if SkipTimeout==true, after receiving all precommits from (height,round-1)
  551. // Enter: `timeoutPrecommits` after any +2/3 precommits from (height,round-1)
  552. // Enter: +2/3 precommits for nil at (height,round-1)
  553. // Enter: +2/3 prevotes any or +2/3 precommits for block or any from (height, round)
  554. // NOTE: cs.StartTime was already set for height.
  555. func (cs *ConsensusState) enterNewRound(height int64, round int) {
  556. if cs.Height != height || round < cs.Round || (cs.Round == round && cs.Step != cstypes.RoundStepNewHeight) {
  557. cs.Logger.Debug(cmn.Fmt("enterNewRound(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))
  558. return
  559. }
  560. if now := time.Now(); cs.StartTime.After(now) {
  561. cs.Logger.Info("Need to set a buffer and log message here for sanity.", "startTime", cs.StartTime, "now", now)
  562. }
  563. cs.Logger.Info(cmn.Fmt("enterNewRound(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))
  564. // Increment validators if necessary
  565. validators := cs.Validators
  566. if cs.Round < round {
  567. validators = validators.Copy()
  568. validators.IncrementAccum(round - cs.Round)
  569. }
  570. // Setup new round
  571. // we don't fire newStep for this step,
  572. // but we fire an event, so update the round step first
  573. cs.updateRoundStep(round, cstypes.RoundStepNewRound)
  574. cs.Validators = validators
  575. if round == 0 {
  576. // We've already reset these upon new height,
  577. // and meanwhile we might have received a proposal
  578. // for round 0.
  579. } else {
  580. cs.Proposal = nil
  581. cs.ProposalBlock = nil
  582. cs.ProposalBlockParts = nil
  583. }
  584. cs.Votes.SetRound(round + 1) // also track next round (round+1) to allow round-skipping
  585. cs.eventBus.PublishEventNewRound(cs.RoundStateEvent())
  586. // Wait for txs to be available in the mempool
  587. // before we enterPropose in round 0. If the last block changed the app hash,
  588. // we may need an empty "proof" block, and enterPropose immediately.
  589. waitForTxs := cs.config.WaitForTxs() && round == 0 && !cs.needProofBlock(height)
  590. if waitForTxs {
  591. if cs.config.CreateEmptyBlocksInterval > 0 {
  592. cs.scheduleTimeout(cs.config.EmptyBlocksInterval(), height, round, cstypes.RoundStepNewRound)
  593. }
  594. go cs.proposalHeartbeat(height, round)
  595. } else {
  596. cs.enterPropose(height, round)
  597. }
  598. }
  599. // needProofBlock returns true on the first height (so the genesis app hash is signed right away)
  600. // and where the last block (height-1) caused the app hash to change
  601. // CONTRACT: height > 0
  602. func (cs *ConsensusState) needProofBlock(height int64) bool {
  603. if height == 1 {
  604. return true
  605. }
  606. lastBlockMeta := cs.blockStore.LoadBlockMeta(height - 1)
  607. return !bytes.Equal(cs.state.AppHash, lastBlockMeta.Header.AppHash)
  608. }
  609. func (cs *ConsensusState) proposalHeartbeat(height int64, round int) {
  610. counter := 0
  611. addr := cs.privValidator.GetAddress()
  612. valIndex, v := cs.Validators.GetByAddress(addr)
  613. if v == nil {
  614. // not a validator
  615. valIndex = -1
  616. }
  617. chainID := cs.state.ChainID
  618. for {
  619. rs := cs.GetRoundState()
  620. // if we've already moved on, no need to send more heartbeats
  621. if rs.Step > cstypes.RoundStepNewRound || rs.Round > round || rs.Height > height {
  622. return
  623. }
  624. heartbeat := &types.Heartbeat{
  625. Height: rs.Height,
  626. Round: rs.Round,
  627. Sequence: counter,
  628. ValidatorAddress: addr,
  629. ValidatorIndex: valIndex,
  630. }
  631. cs.privValidator.SignHeartbeat(chainID, heartbeat)
  632. cs.eventBus.PublishEventProposalHeartbeat(types.EventDataProposalHeartbeat{heartbeat})
  633. counter += 1
  634. time.Sleep(proposalHeartbeatIntervalSeconds * time.Second)
  635. }
  636. }
  637. // Enter (CreateEmptyBlocks): from enterNewRound(height,round)
  638. // Enter (CreateEmptyBlocks, CreateEmptyBlocksInterval > 0 ): after enterNewRound(height,round), after timeout of CreateEmptyBlocksInterval
  639. // Enter (!CreateEmptyBlocks) : after enterNewRound(height,round), once txs are in the mempool
  640. func (cs *ConsensusState) enterPropose(height int64, round int) {
  641. if cs.Height != height || round < cs.Round || (cs.Round == round && cstypes.RoundStepPropose <= cs.Step) {
  642. cs.Logger.Debug(cmn.Fmt("enterPropose(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))
  643. return
  644. }
  645. cs.Logger.Info(cmn.Fmt("enterPropose(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))
  646. defer func() {
  647. // Done enterPropose:
  648. cs.updateRoundStep(round, cstypes.RoundStepPropose)
  649. cs.newStep()
  650. // If we have the whole proposal + POL, then goto Prevote now.
  651. // else, we'll enterPrevote when the rest of the proposal is received (in AddProposalBlockPart),
  652. // or else after timeoutPropose
  653. if cs.isProposalComplete() {
  654. cs.enterPrevote(height, cs.Round)
  655. }
  656. }()
  657. // If we don't get the proposal and all block parts quick enough, enterPrevote
  658. cs.scheduleTimeout(cs.config.Propose(round), height, round, cstypes.RoundStepPropose)
  659. // Nothing more to do if we're not a validator
  660. if cs.privValidator == nil {
  661. cs.Logger.Debug("This node is not a validator")
  662. return
  663. }
  664. if !cs.isProposer() {
  665. cs.Logger.Info("enterPropose: Not our turn to propose", "proposer", cs.Validators.GetProposer().Address, "privValidator", cs.privValidator)
  666. if cs.Validators.HasAddress(cs.privValidator.GetAddress()) {
  667. cs.Logger.Debug("This node is a validator")
  668. } else {
  669. cs.Logger.Debug("This node is not a validator")
  670. }
  671. } else {
  672. cs.Logger.Info("enterPropose: Our turn to propose", "proposer", cs.Validators.GetProposer().Address, "privValidator", cs.privValidator)
  673. cs.Logger.Debug("This node is a validator")
  674. cs.decideProposal(height, round)
  675. }
  676. }
  677. func (cs *ConsensusState) isProposer() bool {
  678. return bytes.Equal(cs.Validators.GetProposer().Address, cs.privValidator.GetAddress())
  679. }
  680. func (cs *ConsensusState) defaultDecideProposal(height int64, round int) {
  681. var block *types.Block
  682. var blockParts *types.PartSet
  683. // Decide on block
  684. if cs.LockedBlock != nil {
  685. // If we're locked onto a block, just choose that.
  686. block, blockParts = cs.LockedBlock, cs.LockedBlockParts
  687. } else {
  688. // Create a new proposal block from state/txs from the mempool.
  689. block, blockParts = cs.createProposalBlock()
  690. if block == nil { // on error
  691. return
  692. }
  693. }
  694. // Make proposal
  695. polRound, polBlockID := cs.Votes.POLInfo()
  696. proposal := types.NewProposal(height, round, blockParts.Header(), polRound, polBlockID)
  697. if err := cs.privValidator.SignProposal(cs.state.ChainID, proposal); err == nil {
  698. // Set fields
  699. /* fields set by setProposal and addBlockPart
  700. cs.Proposal = proposal
  701. cs.ProposalBlock = block
  702. cs.ProposalBlockParts = blockParts
  703. */
  704. // send proposal and block parts on internal msg queue
  705. cs.sendInternalMessage(msgInfo{&ProposalMessage{proposal}, ""})
  706. for i := 0; i < blockParts.Total(); i++ {
  707. part := blockParts.GetPart(i)
  708. cs.sendInternalMessage(msgInfo{&BlockPartMessage{cs.Height, cs.Round, part}, ""})
  709. }
  710. cs.Logger.Info("Signed proposal", "height", height, "round", round, "proposal", proposal)
  711. cs.Logger.Debug(cmn.Fmt("Signed proposal block: %v", block))
  712. } else {
  713. if !cs.replayMode {
  714. cs.Logger.Error("enterPropose: Error signing proposal", "height", height, "round", round, "err", err)
  715. }
  716. }
  717. }
  718. // Returns true if the proposal block is complete &&
  719. // (if POLRound was proposed, we have +2/3 prevotes from there).
  720. func (cs *ConsensusState) isProposalComplete() bool {
  721. if cs.Proposal == nil || cs.ProposalBlock == nil {
  722. return false
  723. }
  724. // we have the proposal. if there's a POLRound,
  725. // make sure we have the prevotes from it too
  726. if cs.Proposal.POLRound < 0 {
  727. return true
  728. } else {
  729. // if this is false the proposer is lying or we haven't received the POL yet
  730. return cs.Votes.Prevotes(cs.Proposal.POLRound).HasTwoThirdsMajority()
  731. }
  732. }
  733. // Create the next block to propose and return it.
  734. // Returns nil block upon error.
  735. // NOTE: keep it side-effect free for clarity.
  736. func (cs *ConsensusState) createProposalBlock() (block *types.Block, blockParts *types.PartSet) {
  737. var commit *types.Commit
  738. if cs.Height == 1 {
  739. // We're creating a proposal for the first block.
  740. // The commit is empty, but not nil.
  741. commit = &types.Commit{}
  742. } else if cs.LastCommit.HasTwoThirdsMajority() {
  743. // Make the commit from LastCommit
  744. commit = cs.LastCommit.MakeCommit()
  745. } else {
  746. // This shouldn't happen.
  747. cs.Logger.Error("enterPropose: Cannot propose anything: No commit for the previous block.")
  748. return
  749. }
  750. // Mempool validated transactions
  751. txs := cs.mempool.Reap(cs.config.MaxBlockSizeTxs)
  752. return types.MakeBlock(cs.Height, cs.state.ChainID, txs, commit,
  753. cs.state.LastBlockID, cs.state.Validators.Hash(),
  754. cs.state.AppHash, cs.state.Params.BlockPartSizeBytes)
  755. }
  756. // Enter: `timeoutPropose` after entering Propose.
  757. // Enter: proposal block and POL is ready.
  758. // Enter: any +2/3 prevotes for future round.
  759. // Prevote for LockedBlock if we're locked, or ProposalBlock if valid.
  760. // Otherwise vote nil.
  761. func (cs *ConsensusState) enterPrevote(height int64, round int) {
  762. if cs.Height != height || round < cs.Round || (cs.Round == round && cstypes.RoundStepPrevote <= cs.Step) {
  763. cs.Logger.Debug(cmn.Fmt("enterPrevote(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))
  764. return
  765. }
  766. defer func() {
  767. // Done enterPrevote:
  768. cs.updateRoundStep(round, cstypes.RoundStepPrevote)
  769. cs.newStep()
  770. }()
  771. // fire event for how we got here
  772. if cs.isProposalComplete() {
  773. cs.eventBus.PublishEventCompleteProposal(cs.RoundStateEvent())
  774. } else {
  775. // we received +2/3 prevotes for a future round
  776. // TODO: catchup event?
  777. }
  778. cs.Logger.Info(cmn.Fmt("enterPrevote(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))
  779. // Sign and broadcast vote as necessary
  780. cs.doPrevote(height, round)
  781. // Once `addVote` hits any +2/3 prevotes, we will go to PrevoteWait
  782. // (so we have more time to try and collect +2/3 prevotes for a single block)
  783. }
  784. func (cs *ConsensusState) defaultDoPrevote(height int64, round int) {
  785. logger := cs.Logger.With("height", height, "round", round)
  786. // If a block is locked, prevote that.
  787. if cs.LockedBlock != nil {
  788. logger.Info("enterPrevote: Block was locked")
  789. cs.signAddVote(types.VoteTypePrevote, cs.LockedBlock.Hash(), cs.LockedBlockParts.Header())
  790. return
  791. }
  792. // If ProposalBlock is nil, prevote nil.
  793. if cs.ProposalBlock == nil {
  794. logger.Info("enterPrevote: ProposalBlock is nil")
  795. cs.signAddVote(types.VoteTypePrevote, nil, types.PartSetHeader{})
  796. return
  797. }
  798. // Validate proposal block
  799. err := cs.state.ValidateBlock(cs.ProposalBlock)
  800. if err != nil {
  801. // ProposalBlock is invalid, prevote nil.
  802. logger.Error("enterPrevote: ProposalBlock is invalid", "err", err)
  803. cs.signAddVote(types.VoteTypePrevote, nil, types.PartSetHeader{})
  804. return
  805. }
  806. // Prevote cs.ProposalBlock
  807. // NOTE: the proposal signature is validated when it is received,
  808. // and the proposal block parts are validated as they are received (against the merkle hash in the proposal)
  809. logger.Info("enterPrevote: ProposalBlock is valid")
  810. cs.signAddVote(types.VoteTypePrevote, cs.ProposalBlock.Hash(), cs.ProposalBlockParts.Header())
  811. }
  812. // Enter: any +2/3 prevotes at next round.
  813. func (cs *ConsensusState) enterPrevoteWait(height int64, round int) {
  814. if cs.Height != height || round < cs.Round || (cs.Round == round && cstypes.RoundStepPrevoteWait <= cs.Step) {
  815. cs.Logger.Debug(cmn.Fmt("enterPrevoteWait(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))
  816. return
  817. }
  818. if !cs.Votes.Prevotes(round).HasTwoThirdsAny() {
  819. cmn.PanicSanity(cmn.Fmt("enterPrevoteWait(%v/%v), but Prevotes does not have any +2/3 votes", height, round))
  820. }
  821. cs.Logger.Info(cmn.Fmt("enterPrevoteWait(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))
  822. defer func() {
  823. // Done enterPrevoteWait:
  824. cs.updateRoundStep(round, cstypes.RoundStepPrevoteWait)
  825. cs.newStep()
  826. }()
  827. // Wait for some more prevotes; enterPrecommit
  828. cs.scheduleTimeout(cs.config.Prevote(round), height, round, cstypes.RoundStepPrevoteWait)
  829. }
  830. // Enter: `timeoutPrevote` after any +2/3 prevotes.
  831. // Enter: +2/3 precomits for block or nil.
  832. // Enter: any +2/3 precommits for next round.
  833. // Lock & precommit the ProposalBlock if we have enough prevotes for it (a POL in this round)
  834. // else, unlock an existing lock and precommit nil if +2/3 of prevotes were nil,
  835. // else, precommit nil otherwise.
  836. func (cs *ConsensusState) enterPrecommit(height int64, round int) {
  837. if cs.Height != height || round < cs.Round || (cs.Round == round && cstypes.RoundStepPrecommit <= cs.Step) {
  838. cs.Logger.Debug(cmn.Fmt("enterPrecommit(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))
  839. return
  840. }
  841. cs.Logger.Info(cmn.Fmt("enterPrecommit(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))
  842. defer func() {
  843. // Done enterPrecommit:
  844. cs.updateRoundStep(round, cstypes.RoundStepPrecommit)
  845. cs.newStep()
  846. }()
  847. blockID, ok := cs.Votes.Prevotes(round).TwoThirdsMajority()
  848. // If we don't have a polka, we must precommit nil
  849. if !ok {
  850. if cs.LockedBlock != nil {
  851. cs.Logger.Info("enterPrecommit: No +2/3 prevotes during enterPrecommit while we're locked. Precommitting nil")
  852. } else {
  853. cs.Logger.Info("enterPrecommit: No +2/3 prevotes during enterPrecommit. Precommitting nil.")
  854. }
  855. cs.signAddVote(types.VoteTypePrecommit, nil, types.PartSetHeader{})
  856. return
  857. }
  858. // At this point +2/3 prevoted for a particular block or nil
  859. cs.eventBus.PublishEventPolka(cs.RoundStateEvent())
  860. // the latest POLRound should be this round
  861. polRound, _ := cs.Votes.POLInfo()
  862. if polRound < round {
  863. cmn.PanicSanity(cmn.Fmt("This POLRound should be %v but got %", round, polRound))
  864. }
  865. // +2/3 prevoted nil. Unlock and precommit nil.
  866. if len(blockID.Hash) == 0 {
  867. if cs.LockedBlock == nil {
  868. cs.Logger.Info("enterPrecommit: +2/3 prevoted for nil.")
  869. } else {
  870. cs.Logger.Info("enterPrecommit: +2/3 prevoted for nil. Unlocking")
  871. cs.LockedRound = 0
  872. cs.LockedBlock = nil
  873. cs.LockedBlockParts = nil
  874. cs.eventBus.PublishEventUnlock(cs.RoundStateEvent())
  875. }
  876. cs.signAddVote(types.VoteTypePrecommit, nil, types.PartSetHeader{})
  877. return
  878. }
  879. // At this point, +2/3 prevoted for a particular block.
  880. // If we're already locked on that block, precommit it, and update the LockedRound
  881. if cs.LockedBlock.HashesTo(blockID.Hash) {
  882. cs.Logger.Info("enterPrecommit: +2/3 prevoted locked block. Relocking")
  883. cs.LockedRound = round
  884. cs.eventBus.PublishEventRelock(cs.RoundStateEvent())
  885. cs.signAddVote(types.VoteTypePrecommit, blockID.Hash, blockID.PartsHeader)
  886. return
  887. }
  888. // If +2/3 prevoted for proposal block, stage and precommit it
  889. if cs.ProposalBlock.HashesTo(blockID.Hash) {
  890. cs.Logger.Info("enterPrecommit: +2/3 prevoted proposal block. Locking", "hash", blockID.Hash)
  891. // Validate the block.
  892. if err := cs.state.ValidateBlock(cs.ProposalBlock); err != nil {
  893. cmn.PanicConsensus(cmn.Fmt("enterPrecommit: +2/3 prevoted for an invalid block: %v", err))
  894. }
  895. cs.LockedRound = round
  896. cs.LockedBlock = cs.ProposalBlock
  897. cs.LockedBlockParts = cs.ProposalBlockParts
  898. cs.eventBus.PublishEventLock(cs.RoundStateEvent())
  899. cs.signAddVote(types.VoteTypePrecommit, blockID.Hash, blockID.PartsHeader)
  900. return
  901. }
  902. // There was a polka in this round for a block we don't have.
  903. // Fetch that block, unlock, and precommit nil.
  904. // The +2/3 prevotes for this round is the POL for our unlock.
  905. // TODO: In the future save the POL prevotes for justification.
  906. cs.LockedRound = 0
  907. cs.LockedBlock = nil
  908. cs.LockedBlockParts = nil
  909. if !cs.ProposalBlockParts.HasHeader(blockID.PartsHeader) {
  910. cs.ProposalBlock = nil
  911. cs.ProposalBlockParts = types.NewPartSetFromHeader(blockID.PartsHeader)
  912. }
  913. cs.eventBus.PublishEventUnlock(cs.RoundStateEvent())
  914. cs.signAddVote(types.VoteTypePrecommit, nil, types.PartSetHeader{})
  915. }
  916. // Enter: any +2/3 precommits for next round.
  917. func (cs *ConsensusState) enterPrecommitWait(height int64, round int) {
  918. if cs.Height != height || round < cs.Round || (cs.Round == round && cstypes.RoundStepPrecommitWait <= cs.Step) {
  919. cs.Logger.Debug(cmn.Fmt("enterPrecommitWait(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))
  920. return
  921. }
  922. if !cs.Votes.Precommits(round).HasTwoThirdsAny() {
  923. cmn.PanicSanity(cmn.Fmt("enterPrecommitWait(%v/%v), but Precommits does not have any +2/3 votes", height, round))
  924. }
  925. cs.Logger.Info(cmn.Fmt("enterPrecommitWait(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))
  926. defer func() {
  927. // Done enterPrecommitWait:
  928. cs.updateRoundStep(round, cstypes.RoundStepPrecommitWait)
  929. cs.newStep()
  930. }()
  931. // Wait for some more precommits; enterNewRound
  932. cs.scheduleTimeout(cs.config.Precommit(round), height, round, cstypes.RoundStepPrecommitWait)
  933. }
  934. // Enter: +2/3 precommits for block
  935. func (cs *ConsensusState) enterCommit(height int64, commitRound int) {
  936. if cs.Height != height || cstypes.RoundStepCommit <= cs.Step {
  937. cs.Logger.Debug(cmn.Fmt("enterCommit(%v/%v): Invalid args. Current step: %v/%v/%v", height, commitRound, cs.Height, cs.Round, cs.Step))
  938. return
  939. }
  940. cs.Logger.Info(cmn.Fmt("enterCommit(%v/%v). Current: %v/%v/%v", height, commitRound, cs.Height, cs.Round, cs.Step))
  941. defer func() {
  942. // Done enterCommit:
  943. // keep cs.Round the same, commitRound points to the right Precommits set.
  944. cs.updateRoundStep(cs.Round, cstypes.RoundStepCommit)
  945. cs.CommitRound = commitRound
  946. cs.CommitTime = time.Now()
  947. cs.newStep()
  948. // Maybe finalize immediately.
  949. cs.tryFinalizeCommit(height)
  950. }()
  951. blockID, ok := cs.Votes.Precommits(commitRound).TwoThirdsMajority()
  952. if !ok {
  953. cmn.PanicSanity("RunActionCommit() expects +2/3 precommits")
  954. }
  955. // The Locked* fields no longer matter.
  956. // Move them over to ProposalBlock if they match the commit hash,
  957. // otherwise they'll be cleared in updateToState.
  958. if cs.LockedBlock.HashesTo(blockID.Hash) {
  959. cs.ProposalBlock = cs.LockedBlock
  960. cs.ProposalBlockParts = cs.LockedBlockParts
  961. }
  962. // If we don't have the block being committed, set up to get it.
  963. if !cs.ProposalBlock.HashesTo(blockID.Hash) {
  964. if !cs.ProposalBlockParts.HasHeader(blockID.PartsHeader) {
  965. // We're getting the wrong block.
  966. // Set up ProposalBlockParts and keep waiting.
  967. cs.ProposalBlock = nil
  968. cs.ProposalBlockParts = types.NewPartSetFromHeader(blockID.PartsHeader)
  969. } else {
  970. // We just need to keep waiting.
  971. }
  972. }
  973. }
  974. // If we have the block AND +2/3 commits for it, finalize.
  975. func (cs *ConsensusState) tryFinalizeCommit(height int64) {
  976. if cs.Height != height {
  977. cmn.PanicSanity(cmn.Fmt("tryFinalizeCommit() cs.Height: %v vs height: %v", cs.Height, height))
  978. }
  979. blockID, ok := cs.Votes.Precommits(cs.CommitRound).TwoThirdsMajority()
  980. if !ok || len(blockID.Hash) == 0 {
  981. cs.Logger.Error("Attempt to finalize failed. There was no +2/3 majority, or +2/3 was for <nil>.", "height", height)
  982. return
  983. }
  984. if !cs.ProposalBlock.HashesTo(blockID.Hash) {
  985. // TODO: this happens every time if we're not a validator (ugly logs)
  986. // TODO: ^^ wait, why does it matter that we're a validator?
  987. cs.Logger.Info("Attempt to finalize failed. We don't have the commit block.", "height", height, "proposal-block", cs.ProposalBlock.Hash(), "commit-block", blockID.Hash)
  988. return
  989. }
  990. // go
  991. cs.finalizeCommit(height)
  992. }
  993. // Increment height and goto cstypes.RoundStepNewHeight
  994. func (cs *ConsensusState) finalizeCommit(height int64) {
  995. if cs.Height != height || cs.Step != cstypes.RoundStepCommit {
  996. cs.Logger.Debug(cmn.Fmt("finalizeCommit(%v): Invalid args. Current step: %v/%v/%v", height, cs.Height, cs.Round, cs.Step))
  997. return
  998. }
  999. blockID, ok := cs.Votes.Precommits(cs.CommitRound).TwoThirdsMajority()
  1000. block, blockParts := cs.ProposalBlock, cs.ProposalBlockParts
  1001. if !ok {
  1002. cmn.PanicSanity(cmn.Fmt("Cannot finalizeCommit, commit does not have two thirds majority"))
  1003. }
  1004. if !blockParts.HasHeader(blockID.PartsHeader) {
  1005. cmn.PanicSanity(cmn.Fmt("Expected ProposalBlockParts header to be commit header"))
  1006. }
  1007. if !block.HashesTo(blockID.Hash) {
  1008. cmn.PanicSanity(cmn.Fmt("Cannot finalizeCommit, ProposalBlock does not hash to commit hash"))
  1009. }
  1010. if err := cs.state.ValidateBlock(block); err != nil {
  1011. cmn.PanicConsensus(cmn.Fmt("+2/3 committed an invalid block: %v", err))
  1012. }
  1013. cs.Logger.Info(cmn.Fmt("Finalizing commit of block with %d txs", block.NumTxs),
  1014. "height", block.Height, "hash", block.Hash(), "root", block.AppHash)
  1015. cs.Logger.Info(cmn.Fmt("%v", block))
  1016. fail.Fail() // XXX
  1017. // Save to blockStore.
  1018. if cs.blockStore.Height() < block.Height {
  1019. // NOTE: the seenCommit is local justification to commit this block,
  1020. // but may differ from the LastCommit included in the next block
  1021. precommits := cs.Votes.Precommits(cs.CommitRound)
  1022. seenCommit := precommits.MakeCommit()
  1023. cs.blockStore.SaveBlock(block, blockParts, seenCommit)
  1024. } else {
  1025. // Happens during replay if we already saved the block but didn't commit
  1026. cs.Logger.Info("Calling finalizeCommit on already stored block", "height", block.Height)
  1027. }
  1028. fail.Fail() // XXX
  1029. // Finish writing to the WAL for this height.
  1030. // NOTE: If we fail before writing this, we'll never write it,
  1031. // and just recover by running ApplyBlock in the Handshake.
  1032. // If we moved it before persisting the block, we'd have to allow
  1033. // WAL replay for blocks with an #ENDHEIGHT
  1034. // As is, ConsensusState should not be started again
  1035. // until we successfully call ApplyBlock (ie. here or in Handshake after restart)
  1036. cs.wal.Save(EndHeightMessage{height})
  1037. fail.Fail() // XXX
  1038. // Create a copy of the state for staging
  1039. // and an event cache for txs
  1040. stateCopy := cs.state.Copy()
  1041. txEventBuffer := types.NewTxEventBuffer(cs.eventBus, block.NumTxs)
  1042. // Execute and commit the block, update and save the state, and update the mempool.
  1043. // All calls to the proxyAppConn come here.
  1044. // NOTE: the block.AppHash wont reflect these txs until the next block
  1045. err := stateCopy.ApplyBlock(txEventBuffer, cs.proxyAppConn, block, blockParts.Header(), cs.mempool)
  1046. if err != nil {
  1047. cs.Logger.Error("Error on ApplyBlock. Did the application crash? Please restart tendermint", "err", err)
  1048. err := cmn.Kill()
  1049. if err != nil {
  1050. cs.Logger.Error("Failed to kill this process - please do so manually", "err", err)
  1051. }
  1052. return
  1053. }
  1054. fail.Fail() // XXX
  1055. // Fire event for new block.
  1056. // NOTE: If we fail before firing, these events will never fire
  1057. //
  1058. // TODO: Either
  1059. // * Fire before persisting state, in ApplyBlock
  1060. // * Fire on start up if we haven't written any new WAL msgs
  1061. // Both options mean we may fire more than once. Is that fine ?
  1062. cs.eventBus.PublishEventNewBlock(types.EventDataNewBlock{block})
  1063. cs.eventBus.PublishEventNewBlockHeader(types.EventDataNewBlockHeader{block.Header})
  1064. err = txEventBuffer.Flush()
  1065. if err != nil {
  1066. cs.Logger.Error("Failed to flush event buffer", "err", err)
  1067. }
  1068. fail.Fail() // XXX
  1069. // NewHeightStep!
  1070. cs.updateToState(stateCopy)
  1071. fail.Fail() // XXX
  1072. // cs.StartTime is already set.
  1073. // Schedule Round0 to start soon.
  1074. cs.scheduleRound0(&cs.RoundState)
  1075. // By here,
  1076. // * cs.Height has been increment to height+1
  1077. // * cs.Step is now cstypes.RoundStepNewHeight
  1078. // * cs.StartTime is set to when we will start round0.
  1079. }
  1080. //-----------------------------------------------------------------------------
  1081. func (cs *ConsensusState) defaultSetProposal(proposal *types.Proposal) error {
  1082. // Already have one
  1083. // TODO: possibly catch double proposals
  1084. if cs.Proposal != nil {
  1085. return nil
  1086. }
  1087. // Does not apply
  1088. if proposal.Height != cs.Height || proposal.Round != cs.Round {
  1089. return nil
  1090. }
  1091. // We don't care about the proposal if we're already in cstypes.RoundStepCommit.
  1092. if cstypes.RoundStepCommit <= cs.Step {
  1093. return nil
  1094. }
  1095. // Verify POLRound, which must be -1 or between 0 and proposal.Round exclusive.
  1096. if proposal.POLRound != -1 &&
  1097. (proposal.POLRound < 0 || proposal.Round <= proposal.POLRound) {
  1098. return ErrInvalidProposalPOLRound
  1099. }
  1100. // Verify signature
  1101. if !cs.Validators.GetProposer().PubKey.VerifyBytes(types.SignBytes(cs.state.ChainID, proposal), proposal.Signature) {
  1102. return ErrInvalidProposalSignature
  1103. }
  1104. cs.Proposal = proposal
  1105. cs.ProposalBlockParts = types.NewPartSetFromHeader(proposal.BlockPartsHeader)
  1106. return nil
  1107. }
  1108. // NOTE: block is not necessarily valid.
  1109. // Asynchronously triggers either enterPrevote (before we timeout of propose) or tryFinalizeCommit, once we have the full block.
  1110. func (cs *ConsensusState) addProposalBlockPart(height int64, part *types.Part, verify bool) (added bool, err error) {
  1111. // Blocks might be reused, so round mismatch is OK
  1112. if cs.Height != height {
  1113. return false, nil
  1114. }
  1115. // We're not expecting a block part.
  1116. if cs.ProposalBlockParts == nil {
  1117. return false, nil // TODO: bad peer? Return error?
  1118. }
  1119. added, err = cs.ProposalBlockParts.AddPart(part, verify)
  1120. if err != nil {
  1121. return added, err
  1122. }
  1123. if added && cs.ProposalBlockParts.IsComplete() {
  1124. // Added and completed!
  1125. var n int
  1126. var err error
  1127. cs.ProposalBlock = wire.ReadBinary(&types.Block{}, cs.ProposalBlockParts.GetReader(),
  1128. cs.state.Params.BlockSizeParams.MaxBytes, &n, &err).(*types.Block)
  1129. // NOTE: it's possible to receive complete proposal blocks for future rounds without having the proposal
  1130. cs.Logger.Info("Received complete proposal block", "height", cs.ProposalBlock.Height, "hash", cs.ProposalBlock.Hash())
  1131. if cs.Step == cstypes.RoundStepPropose && cs.isProposalComplete() {
  1132. // Move onto the next step
  1133. cs.enterPrevote(height, cs.Round)
  1134. } else if cs.Step == cstypes.RoundStepCommit {
  1135. // If we're waiting on the proposal block...
  1136. cs.tryFinalizeCommit(height)
  1137. }
  1138. return true, err
  1139. }
  1140. return added, nil
  1141. }
  1142. // Attempt to add the vote. if its a duplicate signature, dupeout the validator
  1143. func (cs *ConsensusState) tryAddVote(vote *types.Vote, peerKey string) error {
  1144. _, err := cs.addVote(vote, peerKey)
  1145. if err != nil {
  1146. // If the vote height is off, we'll just ignore it,
  1147. // But if it's a conflicting sig, broadcast evidence tx for slashing.
  1148. // If it's otherwise invalid, punish peer.
  1149. if err == ErrVoteHeightMismatch {
  1150. return err
  1151. } else if _, ok := err.(*types.ErrVoteConflictingVotes); ok {
  1152. if bytes.Equal(vote.ValidatorAddress, cs.privValidator.GetAddress()) {
  1153. cs.Logger.Error("Found conflicting vote from ourselves. Did you unsafe_reset a validator?", "height", vote.Height, "round", vote.Round, "type", vote.Type)
  1154. return err
  1155. }
  1156. cs.Logger.Error("Found conflicting vote. Publish evidence (TODO)", "height", vote.Height, "round", vote.Round, "type", vote.Type, "valAddr", vote.ValidatorAddress, "valIndex", vote.ValidatorIndex)
  1157. // TODO: track evidence for inclusion in a block
  1158. return err
  1159. } else {
  1160. // Probably an invalid signature. Bad peer.
  1161. cs.Logger.Error("Error attempting to add vote", "err", err)
  1162. return ErrAddingVote
  1163. }
  1164. }
  1165. return nil
  1166. }
  1167. //-----------------------------------------------------------------------------
  1168. func (cs *ConsensusState) addVote(vote *types.Vote, peerKey string) (added bool, err error) {
  1169. cs.Logger.Debug("addVote", "voteHeight", vote.Height, "voteType", vote.Type, "valIndex", vote.ValidatorIndex, "csHeight", cs.Height)
  1170. // A precommit for the previous height?
  1171. // These come in while we wait timeoutCommit
  1172. if vote.Height+1 == cs.Height {
  1173. if !(cs.Step == cstypes.RoundStepNewHeight && vote.Type == types.VoteTypePrecommit) {
  1174. // TODO: give the reason ..
  1175. // fmt.Errorf("tryAddVote: Wrong height, not a LastCommit straggler commit.")
  1176. return added, ErrVoteHeightMismatch
  1177. }
  1178. added, err = cs.LastCommit.AddVote(vote)
  1179. if added {
  1180. cs.Logger.Info(cmn.Fmt("Added to lastPrecommits: %v", cs.LastCommit.StringShort()))
  1181. cs.eventBus.PublishEventVote(types.EventDataVote{vote})
  1182. // if we can skip timeoutCommit and have all the votes now,
  1183. if cs.config.SkipTimeoutCommit && cs.LastCommit.HasAll() {
  1184. // go straight to new round (skip timeout commit)
  1185. // cs.scheduleTimeout(time.Duration(0), cs.Height, 0, cstypes.RoundStepNewHeight)
  1186. cs.enterNewRound(cs.Height, 0)
  1187. }
  1188. }
  1189. return
  1190. }
  1191. // A prevote/precommit for this height?
  1192. if vote.Height == cs.Height {
  1193. height := cs.Height
  1194. added, err = cs.Votes.AddVote(vote, peerKey)
  1195. if added {
  1196. cs.eventBus.PublishEventVote(types.EventDataVote{vote})
  1197. switch vote.Type {
  1198. case types.VoteTypePrevote:
  1199. prevotes := cs.Votes.Prevotes(vote.Round)
  1200. cs.Logger.Info("Added to prevote", "vote", vote, "prevotes", prevotes.StringShort())
  1201. // First, unlock if prevotes is a valid POL.
  1202. // >> lockRound < POLRound <= unlockOrChangeLockRound (see spec)
  1203. // NOTE: If (lockRound < POLRound) but !(POLRound <= unlockOrChangeLockRound),
  1204. // we'll still enterNewRound(H,vote.R) and enterPrecommit(H,vote.R) to process it
  1205. // there.
  1206. if (cs.LockedBlock != nil) && (cs.LockedRound < vote.Round) && (vote.Round <= cs.Round) {
  1207. blockID, ok := prevotes.TwoThirdsMajority()
  1208. if ok && !cs.LockedBlock.HashesTo(blockID.Hash) {
  1209. cs.Logger.Info("Unlocking because of POL.", "lockedRound", cs.LockedRound, "POLRound", vote.Round)
  1210. cs.LockedRound = 0
  1211. cs.LockedBlock = nil
  1212. cs.LockedBlockParts = nil
  1213. cs.eventBus.PublishEventUnlock(cs.RoundStateEvent())
  1214. }
  1215. }
  1216. if cs.Round <= vote.Round && prevotes.HasTwoThirdsAny() {
  1217. // Round-skip over to PrevoteWait or goto Precommit.
  1218. cs.enterNewRound(height, vote.Round) // if the vote is ahead of us
  1219. if prevotes.HasTwoThirdsMajority() {
  1220. cs.enterPrecommit(height, vote.Round)
  1221. } else {
  1222. cs.enterPrevote(height, vote.Round) // if the vote is ahead of us
  1223. cs.enterPrevoteWait(height, vote.Round)
  1224. }
  1225. } else if cs.Proposal != nil && 0 <= cs.Proposal.POLRound && cs.Proposal.POLRound == vote.Round {
  1226. // If the proposal is now complete, enter prevote of cs.Round.
  1227. if cs.isProposalComplete() {
  1228. cs.enterPrevote(height, cs.Round)
  1229. }
  1230. }
  1231. case types.VoteTypePrecommit:
  1232. precommits := cs.Votes.Precommits(vote.Round)
  1233. cs.Logger.Info("Added to precommit", "vote", vote, "precommits", precommits.StringShort())
  1234. blockID, ok := precommits.TwoThirdsMajority()
  1235. if ok {
  1236. if len(blockID.Hash) == 0 {
  1237. cs.enterNewRound(height, vote.Round+1)
  1238. } else {
  1239. cs.enterNewRound(height, vote.Round)
  1240. cs.enterPrecommit(height, vote.Round)
  1241. cs.enterCommit(height, vote.Round)
  1242. if cs.config.SkipTimeoutCommit && precommits.HasAll() {
  1243. // if we have all the votes now,
  1244. // go straight to new round (skip timeout commit)
  1245. // cs.scheduleTimeout(time.Duration(0), cs.Height, 0, cstypes.RoundStepNewHeight)
  1246. cs.enterNewRound(cs.Height, 0)
  1247. }
  1248. }
  1249. } else if cs.Round <= vote.Round && precommits.HasTwoThirdsAny() {
  1250. cs.enterNewRound(height, vote.Round)
  1251. cs.enterPrecommit(height, vote.Round)
  1252. cs.enterPrecommitWait(height, vote.Round)
  1253. }
  1254. default:
  1255. cmn.PanicSanity(cmn.Fmt("Unexpected vote type %X", vote.Type)) // Should not happen.
  1256. }
  1257. }
  1258. // Either duplicate, or error upon cs.Votes.AddByIndex()
  1259. return
  1260. } else {
  1261. err = ErrVoteHeightMismatch
  1262. }
  1263. // Height mismatch, bad peer?
  1264. cs.Logger.Info("Vote ignored and not added", "voteHeight", vote.Height, "csHeight", cs.Height, "err", err)
  1265. return
  1266. }
  1267. func (cs *ConsensusState) signVote(type_ byte, hash []byte, header types.PartSetHeader) (*types.Vote, error) {
  1268. addr := cs.privValidator.GetAddress()
  1269. valIndex, _ := cs.Validators.GetByAddress(addr)
  1270. vote := &types.Vote{
  1271. ValidatorAddress: addr,
  1272. ValidatorIndex: valIndex,
  1273. Height: cs.Height,
  1274. Round: cs.Round,
  1275. Type: type_,
  1276. BlockID: types.BlockID{hash, header},
  1277. }
  1278. err := cs.privValidator.SignVote(cs.state.ChainID, vote)
  1279. return vote, err
  1280. }
  1281. // sign the vote and publish on internalMsgQueue
  1282. func (cs *ConsensusState) signAddVote(type_ byte, hash []byte, header types.PartSetHeader) *types.Vote {
  1283. // if we don't have a key or we're not in the validator set, do nothing
  1284. if cs.privValidator == nil || !cs.Validators.HasAddress(cs.privValidator.GetAddress()) {
  1285. return nil
  1286. }
  1287. vote, err := cs.signVote(type_, hash, header)
  1288. if err == nil {
  1289. cs.sendInternalMessage(msgInfo{&VoteMessage{vote}, ""})
  1290. cs.Logger.Info("Signed and pushed vote", "height", cs.Height, "round", cs.Round, "vote", vote, "err", err)
  1291. return vote
  1292. } else {
  1293. //if !cs.replayMode {
  1294. cs.Logger.Error("Error signing vote", "height", cs.Height, "round", cs.Round, "vote", vote, "err", err)
  1295. //}
  1296. return nil
  1297. }
  1298. }
  1299. //---------------------------------------------------------
  1300. func CompareHRS(h1 int64, r1 int, s1 cstypes.RoundStepType, h2 int64, r2 int, s2 cstypes.RoundStepType) int {
  1301. if h1 < h2 {
  1302. return -1
  1303. } else if h1 > h2 {
  1304. return 1
  1305. }
  1306. if r1 < r2 {
  1307. return -1
  1308. } else if r1 > r2 {
  1309. return 1
  1310. }
  1311. if s1 < s2 {
  1312. return -1
  1313. } else if s1 > s2 {
  1314. return 1
  1315. }
  1316. return 0
  1317. }