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.

1518 lines
52 KiB

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