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.

582 lines
21 KiB

new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
6 years ago
6 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
6 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
6 years ago
6 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
6 years ago
6 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
6 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
7 years ago
  1. package consensus
  2. import (
  3. "context"
  4. "fmt"
  5. "os"
  6. "path"
  7. "runtime"
  8. "runtime/pprof"
  9. "sync"
  10. "testing"
  11. "time"
  12. "github.com/stretchr/testify/assert"
  13. "github.com/stretchr/testify/require"
  14. abcicli "github.com/tendermint/tendermint/abci/client"
  15. "github.com/tendermint/tendermint/abci/example/kvstore"
  16. abci "github.com/tendermint/tendermint/abci/types"
  17. bc "github.com/tendermint/tendermint/blockchain"
  18. cfg "github.com/tendermint/tendermint/config"
  19. dbm "github.com/tendermint/tendermint/libs/db"
  20. "github.com/tendermint/tendermint/libs/log"
  21. mempl "github.com/tendermint/tendermint/mempool"
  22. "github.com/tendermint/tendermint/p2p"
  23. sm "github.com/tendermint/tendermint/state"
  24. "github.com/tendermint/tendermint/types"
  25. )
  26. func init() {
  27. config = ResetConfig("consensus_reactor_test")
  28. }
  29. //----------------------------------------------
  30. // in-process testnets
  31. func startConsensusNet(t *testing.T, css []*ConsensusState, N int) (
  32. []*ConsensusReactor,
  33. []types.Subscription,
  34. []*types.EventBus,
  35. ) {
  36. reactors := make([]*ConsensusReactor, N)
  37. blocksSubs := make([]types.Subscription, 0)
  38. eventBuses := make([]*types.EventBus, N)
  39. for i := 0; i < N; i++ {
  40. /*logger, err := tmflags.ParseLogLevel("consensus:info,*:error", logger, "info")
  41. if err != nil { t.Fatal(err)}*/
  42. reactors[i] = NewConsensusReactor(css[i], true) // so we dont start the consensus states
  43. reactors[i].SetLogger(css[i].Logger)
  44. // eventBus is already started with the cs
  45. eventBuses[i] = css[i].eventBus
  46. reactors[i].SetEventBus(eventBuses[i])
  47. blocksSub, err := eventBuses[i].Subscribe(context.Background(), testSubscriber, types.EventQueryNewBlock)
  48. require.NoError(t, err)
  49. blocksSubs = append(blocksSubs, blocksSub)
  50. }
  51. // make connected switches and start all reactors
  52. p2p.MakeConnectedSwitches(config.P2P, N, func(i int, s *p2p.Switch) *p2p.Switch {
  53. s.AddReactor("CONSENSUS", reactors[i])
  54. s.SetLogger(reactors[i].conS.Logger.With("module", "p2p"))
  55. return s
  56. }, p2p.Connect2Switches)
  57. // now that everyone is connected, start the state machines
  58. // If we started the state machines before everyone was connected,
  59. // we'd block when the cs fires NewBlockEvent and the peers are trying to start their reactors
  60. // TODO: is this still true with new pubsub?
  61. for i := 0; i < N; i++ {
  62. s := reactors[i].conS.GetState()
  63. reactors[i].SwitchToConsensus(s, 0)
  64. }
  65. return reactors, blocksSubs, eventBuses
  66. }
  67. func stopConsensusNet(logger log.Logger, reactors []*ConsensusReactor, eventBuses []*types.EventBus) {
  68. logger.Info("stopConsensusNet", "n", len(reactors))
  69. for i, r := range reactors {
  70. logger.Info("stopConsensusNet: Stopping ConsensusReactor", "i", i)
  71. r.Switch.Stop()
  72. }
  73. for i, b := range eventBuses {
  74. logger.Info("stopConsensusNet: Stopping eventBus", "i", i)
  75. b.Stop()
  76. }
  77. logger.Info("stopConsensusNet: DONE", "n", len(reactors))
  78. }
  79. // Ensure a testnet makes blocks
  80. func TestReactorBasic(t *testing.T) {
  81. N := 4
  82. css := randConsensusNet(N, "consensus_reactor_test", newMockTickerFunc(true), newCounter)
  83. reactors, eventSubs, eventBuses := startConsensusNet(t, css, N)
  84. defer stopConsensusNet(log.TestingLogger(), reactors, eventBuses)
  85. // wait till everyone makes the first new block
  86. timeoutWaitGroup(t, N, func(j int) {
  87. <-eventSubs[j].Out()
  88. }, css)
  89. }
  90. // Ensure we can process blocks with evidence
  91. func TestReactorWithEvidence(t *testing.T) {
  92. types.RegisterMockEvidences(cdc)
  93. types.RegisterMockEvidences(types.GetCodec())
  94. nValidators := 4
  95. testName := "consensus_reactor_test"
  96. tickerFunc := newMockTickerFunc(true)
  97. appFunc := newCounter
  98. // heed the advice from https://www.sandimetz.com/blog/2016/1/20/the-wrong-abstraction
  99. // to unroll unwieldy abstractions. Here we duplicate the code from:
  100. // css := randConsensusNet(N, "consensus_reactor_test", newMockTickerFunc(true), newCounter)
  101. genDoc, privVals := randGenesisDoc(nValidators, false, 30)
  102. css := make([]*ConsensusState, nValidators)
  103. logger := consensusLogger()
  104. for i := 0; i < nValidators; i++ {
  105. stateDB := dbm.NewMemDB() // each state needs its own db
  106. state, _ := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
  107. thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
  108. ensureDir(path.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal
  109. app := appFunc()
  110. vals := types.TM2PB.ValidatorUpdates(state.Validators)
  111. app.InitChain(abci.RequestInitChain{Validators: vals})
  112. pv := privVals[i]
  113. // duplicate code from:
  114. // css[i] = newConsensusStateWithConfig(thisConfig, state, privVals[i], app)
  115. blockDB := dbm.NewMemDB()
  116. blockStore := bc.NewBlockStore(blockDB)
  117. // one for mempool, one for consensus
  118. mtx := new(sync.Mutex)
  119. proxyAppConnMem := abcicli.NewLocalClient(mtx, app)
  120. proxyAppConnCon := abcicli.NewLocalClient(mtx, app)
  121. // Make Mempool
  122. mempool := mempl.NewMempool(thisConfig.Mempool, proxyAppConnMem, 0)
  123. mempool.SetLogger(log.TestingLogger().With("module", "mempool"))
  124. if thisConfig.Consensus.WaitForTxs() {
  125. mempool.EnableTxsAvailable()
  126. }
  127. // mock the evidence pool
  128. // everyone includes evidence of another double signing
  129. vIdx := (i + 1) % nValidators
  130. addr := privVals[vIdx].GetPubKey().Address()
  131. evpool := newMockEvidencePool(addr)
  132. // Make ConsensusState
  133. blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyAppConnCon, mempool, evpool)
  134. cs := NewConsensusState(thisConfig.Consensus, state, blockExec, blockStore, mempool, evpool)
  135. cs.SetLogger(log.TestingLogger().With("module", "consensus"))
  136. cs.SetPrivValidator(pv)
  137. eventBus := types.NewEventBus()
  138. eventBus.SetLogger(log.TestingLogger().With("module", "events"))
  139. eventBus.Start()
  140. cs.SetEventBus(eventBus)
  141. cs.SetTimeoutTicker(tickerFunc())
  142. cs.SetLogger(logger.With("validator", i, "module", "consensus"))
  143. css[i] = cs
  144. }
  145. reactors, eventSubs, eventBuses := startConsensusNet(t, css, nValidators)
  146. defer stopConsensusNet(log.TestingLogger(), reactors, eventBuses)
  147. // wait till everyone makes the first new block with no evidence
  148. timeoutWaitGroup(t, nValidators, func(j int) {
  149. msg := <-eventSubs[j].Out()
  150. block := msg.Data().(types.EventDataNewBlock).Block
  151. assert.True(t, len(block.Evidence.Evidence) == 0)
  152. }, css)
  153. // second block should have evidence
  154. timeoutWaitGroup(t, nValidators, func(j int) {
  155. msg := <-eventSubs[j].Out()
  156. block := msg.Data().(types.EventDataNewBlock).Block
  157. assert.True(t, len(block.Evidence.Evidence) > 0)
  158. }, css)
  159. }
  160. // mock evidence pool returns no evidence for block 1,
  161. // and returnes one piece for all higher blocks. The one piece
  162. // is for a given validator at block 1.
  163. type mockEvidencePool struct {
  164. height int
  165. ev []types.Evidence
  166. }
  167. func newMockEvidencePool(val []byte) *mockEvidencePool {
  168. return &mockEvidencePool{
  169. ev: []types.Evidence{types.NewMockGoodEvidence(1, 1, val)},
  170. }
  171. }
  172. // NOTE: maxBytes is ignored
  173. func (m *mockEvidencePool) PendingEvidence(maxBytes int64) []types.Evidence {
  174. if m.height > 0 {
  175. return m.ev
  176. }
  177. return nil
  178. }
  179. func (m *mockEvidencePool) AddEvidence(types.Evidence) error { return nil }
  180. func (m *mockEvidencePool) Update(block *types.Block, state sm.State) {
  181. if m.height > 0 {
  182. if len(block.Evidence.Evidence) == 0 {
  183. panic("block has no evidence")
  184. }
  185. }
  186. m.height++
  187. }
  188. //------------------------------------
  189. // Ensure a testnet makes blocks when there are txs
  190. func TestReactorCreatesBlockWhenEmptyBlocksFalse(t *testing.T) {
  191. N := 4
  192. css := randConsensusNet(N, "consensus_reactor_test", newMockTickerFunc(true), newCounter,
  193. func(c *cfg.Config) {
  194. c.Consensus.CreateEmptyBlocks = false
  195. })
  196. reactors, eventSubs, eventBuses := startConsensusNet(t, css, N)
  197. defer stopConsensusNet(log.TestingLogger(), reactors, eventBuses)
  198. // send a tx
  199. if err := assertMempool(css[3].txNotifier).CheckTx([]byte{1, 2, 3}, nil); err != nil {
  200. //t.Fatal(err)
  201. }
  202. // wait till everyone makes the first new block
  203. timeoutWaitGroup(t, N, func(j int) {
  204. <-eventSubs[j].Out()
  205. }, css)
  206. }
  207. // Test we record stats about votes and block parts from other peers.
  208. func TestReactorRecordsVotesAndBlockParts(t *testing.T) {
  209. N := 4
  210. css := randConsensusNet(N, "consensus_reactor_test", newMockTickerFunc(true), newCounter)
  211. reactors, eventSubs, eventBuses := startConsensusNet(t, css, N)
  212. defer stopConsensusNet(log.TestingLogger(), reactors, eventBuses)
  213. // wait till everyone makes the first new block
  214. timeoutWaitGroup(t, N, func(j int) {
  215. <-eventSubs[j].Out()
  216. }, css)
  217. // Get peer
  218. peer := reactors[1].Switch.Peers().List()[0]
  219. // Get peer state
  220. ps := peer.Get(types.PeerStateKey).(*PeerState)
  221. assert.Equal(t, true, ps.VotesSent() > 0, "number of votes sent should have increased")
  222. assert.Equal(t, true, ps.BlockPartsSent() > 0, "number of votes sent should have increased")
  223. }
  224. //-------------------------------------------------------------
  225. // ensure we can make blocks despite cycling a validator set
  226. func TestReactorVotingPowerChange(t *testing.T) {
  227. nVals := 4
  228. logger := log.TestingLogger()
  229. css := randConsensusNet(nVals, "consensus_voting_power_changes_test", newMockTickerFunc(true), newPersistentKVStore)
  230. reactors, eventSubs, eventBuses := startConsensusNet(t, css, nVals)
  231. defer stopConsensusNet(logger, reactors, eventBuses)
  232. // map of active validators
  233. activeVals := make(map[string]struct{})
  234. for i := 0; i < nVals; i++ {
  235. addr := css[i].privValidator.GetPubKey().Address()
  236. activeVals[string(addr)] = struct{}{}
  237. }
  238. // wait till everyone makes block 1
  239. timeoutWaitGroup(t, nVals, func(j int) {
  240. <-eventSubs[j].Out()
  241. }, css)
  242. //---------------------------------------------------------------------------
  243. logger.Debug("---------------------------- Testing changing the voting power of one validator a few times")
  244. val1PubKey := css[0].privValidator.GetPubKey()
  245. val1PubKeyABCI := types.TM2PB.PubKey(val1PubKey)
  246. updateValidatorTx := kvstore.MakeValSetChangeTx(val1PubKeyABCI, 25)
  247. previousTotalVotingPower := css[0].GetRoundState().LastValidators.TotalVotingPower()
  248. waitForAndValidateBlock(t, nVals, activeVals, eventSubs, css, updateValidatorTx)
  249. waitForAndValidateBlockWithTx(t, nVals, activeVals, eventSubs, css, updateValidatorTx)
  250. waitForAndValidateBlock(t, nVals, activeVals, eventSubs, css)
  251. waitForAndValidateBlock(t, nVals, activeVals, eventSubs, css)
  252. if css[0].GetRoundState().LastValidators.TotalVotingPower() == previousTotalVotingPower {
  253. t.Fatalf("expected voting power to change (before: %d, after: %d)", previousTotalVotingPower, css[0].GetRoundState().LastValidators.TotalVotingPower())
  254. }
  255. updateValidatorTx = kvstore.MakeValSetChangeTx(val1PubKeyABCI, 2)
  256. previousTotalVotingPower = css[0].GetRoundState().LastValidators.TotalVotingPower()
  257. waitForAndValidateBlock(t, nVals, activeVals, eventSubs, css, updateValidatorTx)
  258. waitForAndValidateBlockWithTx(t, nVals, activeVals, eventSubs, css, updateValidatorTx)
  259. waitForAndValidateBlock(t, nVals, activeVals, eventSubs, css)
  260. waitForAndValidateBlock(t, nVals, activeVals, eventSubs, css)
  261. if css[0].GetRoundState().LastValidators.TotalVotingPower() == previousTotalVotingPower {
  262. t.Fatalf("expected voting power to change (before: %d, after: %d)", previousTotalVotingPower, css[0].GetRoundState().LastValidators.TotalVotingPower())
  263. }
  264. updateValidatorTx = kvstore.MakeValSetChangeTx(val1PubKeyABCI, 26)
  265. previousTotalVotingPower = css[0].GetRoundState().LastValidators.TotalVotingPower()
  266. waitForAndValidateBlock(t, nVals, activeVals, eventSubs, css, updateValidatorTx)
  267. waitForAndValidateBlockWithTx(t, nVals, activeVals, eventSubs, css, updateValidatorTx)
  268. waitForAndValidateBlock(t, nVals, activeVals, eventSubs, css)
  269. waitForAndValidateBlock(t, nVals, activeVals, eventSubs, css)
  270. if css[0].GetRoundState().LastValidators.TotalVotingPower() == previousTotalVotingPower {
  271. t.Fatalf("expected voting power to change (before: %d, after: %d)", previousTotalVotingPower, css[0].GetRoundState().LastValidators.TotalVotingPower())
  272. }
  273. }
  274. func TestReactorValidatorSetChanges(t *testing.T) {
  275. nPeers := 7
  276. nVals := 4
  277. css := randConsensusNetWithPeers(nVals, nPeers, "consensus_val_set_changes_test", newMockTickerFunc(true), newPersistentKVStore)
  278. logger := log.TestingLogger()
  279. reactors, eventSubs, eventBuses := startConsensusNet(t, css, nPeers)
  280. defer stopConsensusNet(logger, reactors, eventBuses)
  281. // map of active validators
  282. activeVals := make(map[string]struct{})
  283. for i := 0; i < nVals; i++ {
  284. addr := css[i].privValidator.GetPubKey().Address()
  285. activeVals[string(addr)] = struct{}{}
  286. }
  287. // wait till everyone makes block 1
  288. timeoutWaitGroup(t, nPeers, func(j int) {
  289. <-eventSubs[j].Out()
  290. }, css)
  291. //---------------------------------------------------------------------------
  292. logger.Info("---------------------------- Testing adding one validator")
  293. newValidatorPubKey1 := css[nVals].privValidator.GetPubKey()
  294. valPubKey1ABCI := types.TM2PB.PubKey(newValidatorPubKey1)
  295. newValidatorTx1 := kvstore.MakeValSetChangeTx(valPubKey1ABCI, testMinPower)
  296. // wait till everyone makes block 2
  297. // ensure the commit includes all validators
  298. // send newValTx to change vals in block 3
  299. waitForAndValidateBlock(t, nPeers, activeVals, eventSubs, css, newValidatorTx1)
  300. // wait till everyone makes block 3.
  301. // it includes the commit for block 2, which is by the original validator set
  302. waitForAndValidateBlockWithTx(t, nPeers, activeVals, eventSubs, css, newValidatorTx1)
  303. // wait till everyone makes block 4.
  304. // it includes the commit for block 3, which is by the original validator set
  305. waitForAndValidateBlock(t, nPeers, activeVals, eventSubs, css)
  306. // the commits for block 4 should be with the updated validator set
  307. activeVals[string(newValidatorPubKey1.Address())] = struct{}{}
  308. // wait till everyone makes block 5
  309. // it includes the commit for block 4, which should have the updated validator set
  310. waitForBlockWithUpdatedValsAndValidateIt(t, nPeers, activeVals, eventSubs, css)
  311. //---------------------------------------------------------------------------
  312. logger.Info("---------------------------- Testing changing the voting power of one validator")
  313. updateValidatorPubKey1 := css[nVals].privValidator.GetPubKey()
  314. updatePubKey1ABCI := types.TM2PB.PubKey(updateValidatorPubKey1)
  315. updateValidatorTx1 := kvstore.MakeValSetChangeTx(updatePubKey1ABCI, 25)
  316. previousTotalVotingPower := css[nVals].GetRoundState().LastValidators.TotalVotingPower()
  317. waitForAndValidateBlock(t, nPeers, activeVals, eventSubs, css, updateValidatorTx1)
  318. waitForAndValidateBlockWithTx(t, nPeers, activeVals, eventSubs, css, updateValidatorTx1)
  319. waitForAndValidateBlock(t, nPeers, activeVals, eventSubs, css)
  320. waitForBlockWithUpdatedValsAndValidateIt(t, nPeers, activeVals, eventSubs, css)
  321. if css[nVals].GetRoundState().LastValidators.TotalVotingPower() == previousTotalVotingPower {
  322. t.Errorf("expected voting power to change (before: %d, after: %d)", previousTotalVotingPower, css[nVals].GetRoundState().LastValidators.TotalVotingPower())
  323. }
  324. //---------------------------------------------------------------------------
  325. logger.Info("---------------------------- Testing adding two validators at once")
  326. newValidatorPubKey2 := css[nVals+1].privValidator.GetPubKey()
  327. newVal2ABCI := types.TM2PB.PubKey(newValidatorPubKey2)
  328. newValidatorTx2 := kvstore.MakeValSetChangeTx(newVal2ABCI, testMinPower)
  329. newValidatorPubKey3 := css[nVals+2].privValidator.GetPubKey()
  330. newVal3ABCI := types.TM2PB.PubKey(newValidatorPubKey3)
  331. newValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, testMinPower)
  332. waitForAndValidateBlock(t, nPeers, activeVals, eventSubs, css, newValidatorTx2, newValidatorTx3)
  333. waitForAndValidateBlockWithTx(t, nPeers, activeVals, eventSubs, css, newValidatorTx2, newValidatorTx3)
  334. waitForAndValidateBlock(t, nPeers, activeVals, eventSubs, css)
  335. activeVals[string(newValidatorPubKey2.Address())] = struct{}{}
  336. activeVals[string(newValidatorPubKey3.Address())] = struct{}{}
  337. waitForBlockWithUpdatedValsAndValidateIt(t, nPeers, activeVals, eventSubs, css)
  338. //---------------------------------------------------------------------------
  339. logger.Info("---------------------------- Testing removing two validators at once")
  340. removeValidatorTx2 := kvstore.MakeValSetChangeTx(newVal2ABCI, 0)
  341. removeValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, 0)
  342. waitForAndValidateBlock(t, nPeers, activeVals, eventSubs, css, removeValidatorTx2, removeValidatorTx3)
  343. waitForAndValidateBlockWithTx(t, nPeers, activeVals, eventSubs, css, removeValidatorTx2, removeValidatorTx3)
  344. waitForAndValidateBlock(t, nPeers, activeVals, eventSubs, css)
  345. delete(activeVals, string(newValidatorPubKey2.Address()))
  346. delete(activeVals, string(newValidatorPubKey3.Address()))
  347. waitForBlockWithUpdatedValsAndValidateIt(t, nPeers, activeVals, eventSubs, css)
  348. }
  349. // Check we can make blocks with skip_timeout_commit=false
  350. func TestReactorWithTimeoutCommit(t *testing.T) {
  351. N := 4
  352. css := randConsensusNet(N, "consensus_reactor_with_timeout_commit_test", newMockTickerFunc(false), newCounter)
  353. // override default SkipTimeoutCommit == true for tests
  354. for i := 0; i < N; i++ {
  355. css[i].config.SkipTimeoutCommit = false
  356. }
  357. reactors, eventSubs, eventBuses := startConsensusNet(t, css, N-1)
  358. defer stopConsensusNet(log.TestingLogger(), reactors, eventBuses)
  359. // wait till everyone makes the first new block
  360. timeoutWaitGroup(t, N-1, func(j int) {
  361. <-eventSubs[j].Out()
  362. }, css)
  363. }
  364. func waitForAndValidateBlock(
  365. t *testing.T,
  366. n int,
  367. activeVals map[string]struct{},
  368. eventSubs []types.Subscription,
  369. css []*ConsensusState,
  370. txs ...[]byte,
  371. ) {
  372. timeoutWaitGroup(t, n, func(j int) {
  373. css[j].Logger.Debug("waitForAndValidateBlock")
  374. msg := <-eventSubs[j].Out()
  375. newBlock := msg.Data().(types.EventDataNewBlock).Block
  376. css[j].Logger.Debug("waitForAndValidateBlock: Got block", "height", newBlock.Height)
  377. err := validateBlock(newBlock, activeVals)
  378. assert.Nil(t, err)
  379. for _, tx := range txs {
  380. err := assertMempool(css[j].txNotifier).CheckTx(tx, nil)
  381. assert.Nil(t, err)
  382. }
  383. }, css)
  384. }
  385. func waitForAndValidateBlockWithTx(
  386. t *testing.T,
  387. n int,
  388. activeVals map[string]struct{},
  389. eventSubs []types.Subscription,
  390. css []*ConsensusState,
  391. txs ...[]byte,
  392. ) {
  393. timeoutWaitGroup(t, n, func(j int) {
  394. ntxs := 0
  395. BLOCK_TX_LOOP:
  396. for {
  397. css[j].Logger.Debug("waitForAndValidateBlockWithTx", "ntxs", ntxs)
  398. msg := <-eventSubs[j].Out()
  399. newBlock := msg.Data().(types.EventDataNewBlock).Block
  400. css[j].Logger.Debug("waitForAndValidateBlockWithTx: Got block", "height", newBlock.Height)
  401. err := validateBlock(newBlock, activeVals)
  402. assert.Nil(t, err)
  403. // check that txs match the txs we're waiting for.
  404. // note they could be spread over multiple blocks,
  405. // but they should be in order.
  406. for _, tx := range newBlock.Data.Txs {
  407. assert.EqualValues(t, txs[ntxs], tx)
  408. ntxs++
  409. }
  410. if ntxs == len(txs) {
  411. break BLOCK_TX_LOOP
  412. }
  413. }
  414. }, css)
  415. }
  416. func waitForBlockWithUpdatedValsAndValidateIt(
  417. t *testing.T,
  418. n int,
  419. updatedVals map[string]struct{},
  420. eventSubs []types.Subscription,
  421. css []*ConsensusState,
  422. ) {
  423. timeoutWaitGroup(t, n, func(j int) {
  424. var newBlock *types.Block
  425. LOOP:
  426. for {
  427. css[j].Logger.Debug("waitForBlockWithUpdatedValsAndValidateIt")
  428. msg := <-eventSubs[j].Out()
  429. newBlock = msg.Data().(types.EventDataNewBlock).Block
  430. if newBlock.LastCommit.Size() == len(updatedVals) {
  431. css[j].Logger.Debug("waitForBlockWithUpdatedValsAndValidateIt: Got block", "height", newBlock.Height)
  432. break LOOP
  433. } else {
  434. css[j].Logger.Debug("waitForBlockWithUpdatedValsAndValidateIt: Got block with no new validators. Skipping", "height", newBlock.Height)
  435. }
  436. }
  437. err := validateBlock(newBlock, updatedVals)
  438. assert.Nil(t, err)
  439. }, css)
  440. }
  441. // expects high synchrony!
  442. func validateBlock(block *types.Block, activeVals map[string]struct{}) error {
  443. if block.LastCommit.Size() != len(activeVals) {
  444. return fmt.Errorf("Commit size doesn't match number of active validators. Got %d, expected %d", block.LastCommit.Size(), len(activeVals))
  445. }
  446. for _, vote := range block.LastCommit.Precommits {
  447. if _, ok := activeVals[string(vote.ValidatorAddress)]; !ok {
  448. return fmt.Errorf("Found vote for unactive validator %X", vote.ValidatorAddress)
  449. }
  450. }
  451. return nil
  452. }
  453. func timeoutWaitGroup(t *testing.T, n int, f func(int), css []*ConsensusState) {
  454. wg := new(sync.WaitGroup)
  455. wg.Add(n)
  456. for i := 0; i < n; i++ {
  457. go func(j int) {
  458. f(j)
  459. wg.Done()
  460. }(i)
  461. }
  462. done := make(chan struct{})
  463. go func() {
  464. wg.Wait()
  465. close(done)
  466. }()
  467. // we're running many nodes in-process, possibly in in a virtual machine,
  468. // and spewing debug messages - making a block could take a while,
  469. timeout := time.Second * 300
  470. select {
  471. case <-done:
  472. case <-time.After(timeout):
  473. for i, cs := range css {
  474. t.Log("#################")
  475. t.Log("Validator", i)
  476. t.Log(cs.GetRoundState())
  477. t.Log("")
  478. }
  479. os.Stdout.Write([]byte("pprof.Lookup('goroutine'):\n"))
  480. pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
  481. capture()
  482. panic("Timed out waiting for all validators to commit a block")
  483. }
  484. }
  485. func capture() {
  486. trace := make([]byte, 10240000)
  487. count := runtime.Stack(trace, true)
  488. fmt.Printf("Stack of %d bytes: %s\n", count, trace)
  489. }