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.

1522 lines
53 KiB

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