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.

495 lines
15 KiB

new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
8 years ago
7 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
8 years ago
7 years ago
7 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
7 years ago
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
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
7 years ago
8 years ago
8 years ago
7 years ago
9 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
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
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
  1. package consensus
  2. import (
  3. "bytes"
  4. "context"
  5. "fmt"
  6. "io/ioutil"
  7. "os"
  8. "path"
  9. "sort"
  10. "sync"
  11. "testing"
  12. "time"
  13. abcicli "github.com/tendermint/abci/client"
  14. abci "github.com/tendermint/abci/types"
  15. bc "github.com/tendermint/tendermint/blockchain"
  16. cfg "github.com/tendermint/tendermint/config"
  17. cstypes "github.com/tendermint/tendermint/consensus/types"
  18. mempl "github.com/tendermint/tendermint/mempool"
  19. "github.com/tendermint/tendermint/p2p"
  20. sm "github.com/tendermint/tendermint/state"
  21. "github.com/tendermint/tendermint/types"
  22. privval "github.com/tendermint/tendermint/types/priv_validator"
  23. cmn "github.com/tendermint/tmlibs/common"
  24. dbm "github.com/tendermint/tmlibs/db"
  25. "github.com/tendermint/tmlibs/log"
  26. "github.com/tendermint/abci/example/counter"
  27. "github.com/tendermint/abci/example/kvstore"
  28. "github.com/go-kit/kit/log/term"
  29. )
  30. const (
  31. testSubscriber = "test-client"
  32. )
  33. // genesis, chain_id, priv_val
  34. var config *cfg.Config // NOTE: must be reset for each _test.go file
  35. var ensureTimeout = time.Second * 1 // must be in seconds because CreateEmptyBlocksInterval is
  36. func ensureDir(dir string, mode os.FileMode) {
  37. if err := cmn.EnsureDir(dir, mode); err != nil {
  38. panic(err)
  39. }
  40. }
  41. func ResetConfig(name string) *cfg.Config {
  42. return cfg.ResetTestRoot(name)
  43. }
  44. //-------------------------------------------------------------------------------
  45. // validator stub (a kvstore consensus peer we control)
  46. type validatorStub struct {
  47. Index int // Validator index. NOTE: we don't assume validator set changes.
  48. Height int64
  49. Round int
  50. types.PrivValidator
  51. }
  52. var testMinPower int64 = 10
  53. func NewValidatorStub(privValidator types.PrivValidator, valIndex int) *validatorStub {
  54. return &validatorStub{
  55. Index: valIndex,
  56. PrivValidator: privValidator,
  57. }
  58. }
  59. func (vs *validatorStub) signVote(voteType byte, hash []byte, header types.PartSetHeader) (*types.Vote, error) {
  60. vote := &types.Vote{
  61. ValidatorIndex: vs.Index,
  62. ValidatorAddress: vs.PrivValidator.GetAddress(),
  63. Height: vs.Height,
  64. Round: vs.Round,
  65. Timestamp: time.Now().UTC(),
  66. Type: voteType,
  67. BlockID: types.BlockID{hash, header},
  68. }
  69. err := vs.PrivValidator.SignVote(config.ChainID(), vote)
  70. return vote, err
  71. }
  72. // Sign vote for type/hash/header
  73. func signVote(vs *validatorStub, voteType byte, hash []byte, header types.PartSetHeader) *types.Vote {
  74. v, err := vs.signVote(voteType, hash, header)
  75. if err != nil {
  76. panic(fmt.Errorf("failed to sign vote: %v", err))
  77. }
  78. return v
  79. }
  80. func signVotes(voteType byte, hash []byte, header types.PartSetHeader, vss ...*validatorStub) []*types.Vote {
  81. votes := make([]*types.Vote, len(vss))
  82. for i, vs := range vss {
  83. votes[i] = signVote(vs, voteType, hash, header)
  84. }
  85. return votes
  86. }
  87. func incrementHeight(vss ...*validatorStub) {
  88. for _, vs := range vss {
  89. vs.Height += 1
  90. }
  91. }
  92. func incrementRound(vss ...*validatorStub) {
  93. for _, vs := range vss {
  94. vs.Round += 1
  95. }
  96. }
  97. //-------------------------------------------------------------------------------
  98. // Functions for transitioning the consensus state
  99. func startTestRound(cs *ConsensusState, height int64, round int) {
  100. cs.enterNewRound(height, round)
  101. cs.startRoutines(0)
  102. }
  103. // Create proposal block from cs1 but sign it with vs
  104. func decideProposal(cs1 *ConsensusState, vs *validatorStub, height int64, round int) (proposal *types.Proposal, block *types.Block) {
  105. block, blockParts := cs1.createProposalBlock()
  106. if block == nil { // on error
  107. panic("error creating proposal block")
  108. }
  109. // Make proposal
  110. polRound, polBlockID := cs1.Votes.POLInfo()
  111. proposal = types.NewProposal(height, round, blockParts.Header(), polRound, polBlockID)
  112. if err := vs.SignProposal(cs1.state.ChainID, proposal); err != nil {
  113. panic(err)
  114. }
  115. return
  116. }
  117. func addVotes(to *ConsensusState, votes ...*types.Vote) {
  118. for _, vote := range votes {
  119. to.peerMsgQueue <- msgInfo{Msg: &VoteMessage{vote}}
  120. }
  121. }
  122. func signAddVotes(to *ConsensusState, voteType byte, hash []byte, header types.PartSetHeader, vss ...*validatorStub) {
  123. votes := signVotes(voteType, hash, header, vss...)
  124. addVotes(to, votes...)
  125. }
  126. func validatePrevote(t *testing.T, cs *ConsensusState, round int, privVal *validatorStub, blockHash []byte) {
  127. prevotes := cs.Votes.Prevotes(round)
  128. var vote *types.Vote
  129. if vote = prevotes.GetByAddress(privVal.GetAddress()); vote == nil {
  130. panic("Failed to find prevote from validator")
  131. }
  132. if blockHash == nil {
  133. if vote.BlockID.Hash != nil {
  134. panic(fmt.Sprintf("Expected prevote to be for nil, got %X", vote.BlockID.Hash))
  135. }
  136. } else {
  137. if !bytes.Equal(vote.BlockID.Hash, blockHash) {
  138. panic(fmt.Sprintf("Expected prevote to be for %X, got %X", blockHash, vote.BlockID.Hash))
  139. }
  140. }
  141. }
  142. func validateLastPrecommit(t *testing.T, cs *ConsensusState, privVal *validatorStub, blockHash []byte) {
  143. votes := cs.LastCommit
  144. var vote *types.Vote
  145. if vote = votes.GetByAddress(privVal.GetAddress()); vote == nil {
  146. panic("Failed to find precommit from validator")
  147. }
  148. if !bytes.Equal(vote.BlockID.Hash, blockHash) {
  149. panic(fmt.Sprintf("Expected precommit to be for %X, got %X", blockHash, vote.BlockID.Hash))
  150. }
  151. }
  152. func validatePrecommit(t *testing.T, cs *ConsensusState, thisRound, lockRound int, privVal *validatorStub, votedBlockHash, lockedBlockHash []byte) {
  153. precommits := cs.Votes.Precommits(thisRound)
  154. var vote *types.Vote
  155. if vote = precommits.GetByAddress(privVal.GetAddress()); vote == nil {
  156. panic("Failed to find precommit from validator")
  157. }
  158. if votedBlockHash == nil {
  159. if vote.BlockID.Hash != nil {
  160. panic("Expected precommit to be for nil")
  161. }
  162. } else {
  163. if !bytes.Equal(vote.BlockID.Hash, votedBlockHash) {
  164. panic("Expected precommit to be for proposal block")
  165. }
  166. }
  167. if lockedBlockHash == nil {
  168. if cs.LockedRound != lockRound || cs.LockedBlock != nil {
  169. panic(fmt.Sprintf("Expected to be locked on nil at round %d. Got locked at round %d with block %v", lockRound, cs.LockedRound, cs.LockedBlock))
  170. }
  171. } else {
  172. if cs.LockedRound != lockRound || !bytes.Equal(cs.LockedBlock.Hash(), lockedBlockHash) {
  173. panic(fmt.Sprintf("Expected block to be locked on round %d, got %d. Got locked block %X, expected %X", lockRound, cs.LockedRound, cs.LockedBlock.Hash(), lockedBlockHash))
  174. }
  175. }
  176. }
  177. func validatePrevoteAndPrecommit(t *testing.T, cs *ConsensusState, thisRound, lockRound int, privVal *validatorStub, votedBlockHash, lockedBlockHash []byte) {
  178. // verify the prevote
  179. validatePrevote(t, cs, thisRound, privVal, votedBlockHash)
  180. // verify precommit
  181. cs.mtx.Lock()
  182. validatePrecommit(t, cs, thisRound, lockRound, privVal, votedBlockHash, lockedBlockHash)
  183. cs.mtx.Unlock()
  184. }
  185. // genesis
  186. func subscribeToVoter(cs *ConsensusState, addr []byte) chan interface{} {
  187. voteCh0 := make(chan interface{})
  188. err := cs.eventBus.Subscribe(context.Background(), testSubscriber, types.EventQueryVote, voteCh0)
  189. if err != nil {
  190. panic(fmt.Sprintf("failed to subscribe %s to %v", testSubscriber, types.EventQueryVote))
  191. }
  192. voteCh := make(chan interface{})
  193. go func() {
  194. for v := range voteCh0 {
  195. vote := v.(types.EventDataVote)
  196. // we only fire for our own votes
  197. if bytes.Equal(addr, vote.Vote.ValidatorAddress) {
  198. voteCh <- v
  199. }
  200. }
  201. }()
  202. return voteCh
  203. }
  204. //-------------------------------------------------------------------------------
  205. // consensus states
  206. func newConsensusState(state sm.State, pv types.PrivValidator, app abci.Application) *ConsensusState {
  207. return newConsensusStateWithConfig(config, state, pv, app)
  208. }
  209. func newConsensusStateWithConfig(thisConfig *cfg.Config, state sm.State, pv types.PrivValidator, app abci.Application) *ConsensusState {
  210. blockDB := dbm.NewMemDB()
  211. return newConsensusStateWithConfigAndBlockStore(thisConfig, state, pv, app, blockDB)
  212. }
  213. func newConsensusStateWithConfigAndBlockStore(thisConfig *cfg.Config, state sm.State, pv types.PrivValidator, app abci.Application, blockDB dbm.DB) *ConsensusState {
  214. // Get BlockStore
  215. blockStore := bc.NewBlockStore(blockDB)
  216. // one for mempool, one for consensus
  217. mtx := new(sync.Mutex)
  218. proxyAppConnMem := abcicli.NewLocalClient(mtx, app)
  219. proxyAppConnCon := abcicli.NewLocalClient(mtx, app)
  220. // Make Mempool
  221. mempool := mempl.NewMempool(thisConfig.Mempool, proxyAppConnMem, 0)
  222. mempool.SetLogger(log.TestingLogger().With("module", "mempool"))
  223. if thisConfig.Consensus.WaitForTxs() {
  224. mempool.EnableTxsAvailable()
  225. }
  226. // mock the evidence pool
  227. evpool := types.MockEvidencePool{}
  228. // Make ConsensusReactor
  229. stateDB := dbm.NewMemDB()
  230. blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyAppConnCon, mempool, evpool)
  231. cs := NewConsensusState(thisConfig.Consensus, state, blockExec, blockStore, mempool, evpool)
  232. cs.SetLogger(log.TestingLogger().With("module", "consensus"))
  233. cs.SetPrivValidator(pv)
  234. eventBus := types.NewEventBus()
  235. eventBus.SetLogger(log.TestingLogger().With("module", "events"))
  236. eventBus.Start()
  237. cs.SetEventBus(eventBus)
  238. return cs
  239. }
  240. func loadPrivValidator(config *cfg.Config) *privval.FilePV {
  241. privValidatorFile := config.PrivValidatorFile()
  242. ensureDir(path.Dir(privValidatorFile), 0700)
  243. privValidator := privval.LoadOrGenFilePV(privValidatorFile)
  244. privValidator.Reset()
  245. return privValidator
  246. }
  247. func randConsensusState(nValidators int) (*ConsensusState, []*validatorStub) {
  248. // Get State
  249. state, privVals := randGenesisState(nValidators, false, 10)
  250. vss := make([]*validatorStub, nValidators)
  251. cs := newConsensusState(state, privVals[0], counter.NewCounterApplication(true))
  252. for i := 0; i < nValidators; i++ {
  253. vss[i] = NewValidatorStub(privVals[i], i)
  254. }
  255. // since cs1 starts at 1
  256. incrementHeight(vss[1:]...)
  257. return cs, vss
  258. }
  259. //-------------------------------------------------------------------------------
  260. func ensureNoNewStep(stepCh <-chan interface{}) {
  261. timer := time.NewTimer(ensureTimeout)
  262. select {
  263. case <-timer.C:
  264. break
  265. case <-stepCh:
  266. panic("We should be stuck waiting, not moving to the next step")
  267. }
  268. }
  269. func ensureNewStep(stepCh <-chan interface{}) {
  270. timer := time.NewTimer(ensureTimeout)
  271. select {
  272. case <-timer.C:
  273. panic("We shouldnt be stuck waiting")
  274. case <-stepCh:
  275. break
  276. }
  277. }
  278. //-------------------------------------------------------------------------------
  279. // consensus nets
  280. // consensusLogger is a TestingLogger which uses a different
  281. // color for each validator ("validator" key must exist).
  282. func consensusLogger() log.Logger {
  283. return log.TestingLoggerWithColorFn(func(keyvals ...interface{}) term.FgBgColor {
  284. for i := 0; i < len(keyvals)-1; i += 2 {
  285. if keyvals[i] == "validator" {
  286. return term.FgBgColor{Fg: term.Color(uint8(keyvals[i+1].(int) + 1))}
  287. }
  288. }
  289. return term.FgBgColor{}
  290. }).With("module", "consensus")
  291. }
  292. func randConsensusNet(nValidators int, testName string, tickerFunc func() TimeoutTicker, appFunc func() abci.Application, configOpts ...func(*cfg.Config)) []*ConsensusState {
  293. genDoc, privVals := randGenesisDoc(nValidators, false, 30)
  294. css := make([]*ConsensusState, nValidators)
  295. logger := consensusLogger()
  296. for i := 0; i < nValidators; i++ {
  297. stateDB := dbm.NewMemDB() // each state needs its own db
  298. state, _ := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
  299. thisConfig := ResetConfig(cmn.Fmt("%s_%d", testName, i))
  300. for _, opt := range configOpts {
  301. opt(thisConfig)
  302. }
  303. ensureDir(path.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal
  304. app := appFunc()
  305. vals := types.TM2PB.Validators(state.Validators)
  306. app.InitChain(abci.RequestInitChain{Validators: vals})
  307. css[i] = newConsensusStateWithConfig(thisConfig, state, privVals[i], app)
  308. css[i].SetTimeoutTicker(tickerFunc())
  309. css[i].SetLogger(logger.With("validator", i, "module", "consensus"))
  310. }
  311. return css
  312. }
  313. // nPeers = nValidators + nNotValidator
  314. func randConsensusNetWithPeers(nValidators, nPeers int, testName string, tickerFunc func() TimeoutTicker, appFunc func() abci.Application) []*ConsensusState {
  315. genDoc, privVals := randGenesisDoc(nValidators, false, testMinPower)
  316. css := make([]*ConsensusState, nPeers)
  317. logger := consensusLogger()
  318. for i := 0; i < nPeers; i++ {
  319. stateDB := dbm.NewMemDB() // each state needs its own db
  320. state, _ := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
  321. thisConfig := ResetConfig(cmn.Fmt("%s_%d", testName, i))
  322. ensureDir(path.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal
  323. var privVal types.PrivValidator
  324. if i < nValidators {
  325. privVal = privVals[i]
  326. } else {
  327. _, tempFilePath := cmn.Tempfile("priv_validator_")
  328. privVal = privval.GenFilePV(tempFilePath)
  329. }
  330. app := appFunc()
  331. vals := types.TM2PB.Validators(state.Validators)
  332. app.InitChain(abci.RequestInitChain{Validators: vals})
  333. css[i] = newConsensusStateWithConfig(thisConfig, state, privVal, app)
  334. css[i].SetTimeoutTicker(tickerFunc())
  335. css[i].SetLogger(logger.With("validator", i, "module", "consensus"))
  336. }
  337. return css
  338. }
  339. func getSwitchIndex(switches []*p2p.Switch, peer p2p.Peer) int {
  340. for i, s := range switches {
  341. if bytes.Equal(peer.NodeInfo().PubKey.Address(), s.NodeInfo().PubKey.Address()) {
  342. return i
  343. }
  344. }
  345. panic("didnt find peer in switches")
  346. return -1
  347. }
  348. //-------------------------------------------------------------------------------
  349. // genesis
  350. func randGenesisDoc(numValidators int, randPower bool, minPower int64) (*types.GenesisDoc, []types.PrivValidator) {
  351. validators := make([]types.GenesisValidator, numValidators)
  352. privValidators := make([]types.PrivValidator, numValidators)
  353. for i := 0; i < numValidators; i++ {
  354. val, privVal := types.RandValidator(randPower, minPower)
  355. validators[i] = types.GenesisValidator{
  356. PubKey: val.PubKey,
  357. Power: val.VotingPower,
  358. }
  359. privValidators[i] = privVal
  360. }
  361. sort.Sort(types.PrivValidatorsByAddress(privValidators))
  362. return &types.GenesisDoc{
  363. GenesisTime: time.Now(),
  364. ChainID: config.ChainID(),
  365. Validators: validators,
  366. }, privValidators
  367. }
  368. func randGenesisState(numValidators int, randPower bool, minPower int64) (sm.State, []types.PrivValidator) {
  369. genDoc, privValidators := randGenesisDoc(numValidators, randPower, minPower)
  370. s0, _ := sm.MakeGenesisState(genDoc)
  371. db := dbm.NewMemDB()
  372. sm.SaveState(db, s0)
  373. return s0, privValidators
  374. }
  375. //------------------------------------
  376. // mock ticker
  377. func newMockTickerFunc(onlyOnce bool) func() TimeoutTicker {
  378. return func() TimeoutTicker {
  379. return &mockTicker{
  380. c: make(chan timeoutInfo, 10),
  381. onlyOnce: onlyOnce,
  382. }
  383. }
  384. }
  385. // mock ticker only fires on RoundStepNewHeight
  386. // and only once if onlyOnce=true
  387. type mockTicker struct {
  388. c chan timeoutInfo
  389. mtx sync.Mutex
  390. onlyOnce bool
  391. fired bool
  392. }
  393. func (m *mockTicker) Start() error {
  394. return nil
  395. }
  396. func (m *mockTicker) Stop() error {
  397. return nil
  398. }
  399. func (m *mockTicker) ScheduleTimeout(ti timeoutInfo) {
  400. m.mtx.Lock()
  401. defer m.mtx.Unlock()
  402. if m.onlyOnce && m.fired {
  403. return
  404. }
  405. if ti.Step == cstypes.RoundStepNewHeight {
  406. m.c <- ti
  407. m.fired = true
  408. }
  409. }
  410. func (m *mockTicker) Chan() <-chan timeoutInfo {
  411. return m.c
  412. }
  413. func (mockTicker) SetLogger(log.Logger) {
  414. }
  415. //------------------------------------
  416. func newCounter() abci.Application {
  417. return counter.NewCounterApplication(true)
  418. }
  419. func newPersistentKVStore() abci.Application {
  420. dir, _ := ioutil.TempDir("/tmp", "persistent-kvstore")
  421. return kvstore.NewPersistentKVStoreApplication(dir)
  422. }