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.

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