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.

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