You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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