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.

2402 lines
74 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 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
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 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
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 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
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 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
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
abci: localClient improvements & bugfixes & pubsub Unsubscribe issues (#2748) * use READ lock/unlock in ConsensusState#GetLastHeight Refs #2721 * do not use defers when there's no need * fix peer formatting (output its address instead of the pointer) ``` [54310]: E[11-02|11:59:39.851] Connection failed @ sendRoutine module=p2p peer=0xb78f00 conn=MConn{74.207.236.148:26656} err="pong timeout" ``` https://github.com/tendermint/tendermint/issues/2721#issuecomment-435326581 * panic if peer has no state https://github.com/tendermint/tendermint/issues/2721#issuecomment-435347165 It's confusing that sometimes we check if peer has a state, but most of the times we expect it to be there 1. https://github.com/tendermint/tendermint/blob/add79700b5fe84417538202b6c927c8cc5383672/mempool/reactor.go#L138 2. https://github.com/tendermint/tendermint/blob/add79700b5fe84417538202b6c927c8cc5383672/rpc/core/consensus.go#L196 (edited) I will change everything to always assume peer has a state and panic otherwise that should help identify issues earlier * abci/localclient: extend lock on app callback App callback should be protected by lock as well (note this was already done for InitChainAsync, why not for others???). Otherwise, when we execute the block, tx might come in and call the callback in the same time we're updating it in execBlockOnProxyApp => DATA RACE Fixes #2721 Consensus state is locked ``` goroutine 113333 [semacquire, 309 minutes]: sync.runtime_SemacquireMutex(0xc00180009c, 0xc0000c7e00) /usr/local/go/src/runtime/sema.go:71 +0x3d sync.(*RWMutex).RLock(0xc001800090) /usr/local/go/src/sync/rwmutex.go:50 +0x4e github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).GetRoundState(0xc001800000, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:218 +0x46 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusReactor).queryMaj23Routine(0xc0017def80, 0x11104a0, 0xc0072488f0, 0xc007248 9c0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/reactor.go:735 +0x16d created by github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusReactor).AddPeer /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/reactor.go:172 +0x236 ``` because localClient is locked ``` goroutine 1899 [semacquire, 309 minutes]: sync.runtime_SemacquireMutex(0xc00003363c, 0xc0000cb500) /usr/local/go/src/runtime/sema.go:71 +0x3d sync.(*Mutex).Lock(0xc000033638) /usr/local/go/src/sync/mutex.go:134 +0xff github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/abci/client.(*localClient).SetResponseCallback(0xc0001fb560, 0xc007868540) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/abci/client/local_client.go:32 +0x33 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/proxy.(*appConnConsensus).SetResponseCallback(0xc00002f750, 0xc007868540) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/proxy/app_conn.go:57 +0x40 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/state.execBlockOnProxyApp(0x1104e20, 0xc002ca0ba0, 0x11092a0, 0xc00002f750, 0xc0001fe960, 0xc000bfc660, 0x110cfe0, 0xc000090330, 0xc9d12, 0xc000d9d5a0, ...) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/state/execution.go:230 +0x1fd github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/state.(*BlockExecutor).ApplyBlock(0xc002c2a230, 0x7, 0x0, 0xc000eae880, 0x6, 0xc002e52c60, 0x16, 0x1f927, 0xc9d12, 0xc000d9d5a0, ...) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/state/execution.go:96 +0x142 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).finalizeCommit(0xc001800000, 0x1f928) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1339 +0xa3e github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).tryFinalizeCommit(0xc001800000, 0x1f928) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1270 +0x451 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).enterCommit.func1(0xc001800000, 0x0, 0x1f928) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1218 +0x90 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).enterCommit(0xc001800000, 0x1f928, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1247 +0x6b8 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote(0xc001800000, 0xc003d8dea0, 0xc000cf4cc0, 0x28, 0xf1, 0xc003bc7ad0, 0xc003bc7b10) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1659 +0xbad github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote(0xc001800000, 0xc003d8dea0, 0xc000cf4cc0, 0x28, 0xf1, 0xf1, 0xf1) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1517 +0x59 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg(0xc001800000, 0xd98200, 0xc0070dbed0, 0xc000cf4cc0, 0x28) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:660 +0x64b github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine(0xc001800000, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:617 +0x670 created by github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).OnStart /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:311 +0x132 ``` tx comes in and CheckTx is executed right when we execute the block ``` goroutine 111044 [semacquire, 309 minutes]: sync.runtime_SemacquireMutex(0xc00003363c, 0x0) /usr/local/go/src/runtime/sema.go:71 +0x3d sync.(*Mutex).Lock(0xc000033638) /usr/local/go/src/sync/mutex.go:134 +0xff github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/abci/client.(*localClient).CheckTxAsync(0xc0001fb0e0, 0xc002d94500, 0x13f, 0x280, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/abci/client/local_client.go:85 +0x47 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/proxy.(*appConnMempool).CheckTxAsync(0xc00002f720, 0xc002d94500, 0x13f, 0x280, 0x1) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/proxy/app_conn.go:114 +0x51 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/mempool.(*Mempool).CheckTx(0xc002d3a320, 0xc002d94500, 0x13f, 0x280, 0xc0072355f0, 0x0, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/mempool/mempool.go:316 +0x17b github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/core.BroadcastTxSync(0xc002d94500, 0x13f, 0x280, 0x0, 0x0, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/core/mempool.go:93 +0xb8 reflect.Value.call(0xd85560, 0x10326c0, 0x13, 0xec7b8b, 0x4, 0xc00663f180, 0x1, 0x1, 0xc00663f180, 0xc00663f188, ...) /usr/local/go/src/reflect/value.go:447 +0x449 reflect.Value.Call(0xd85560, 0x10326c0, 0x13, 0xc00663f180, 0x1, 0x1, 0x0, 0x0, 0xc005cc9344) /usr/local/go/src/reflect/value.go:308 +0xa4 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server.makeHTTPHandler.func2(0x1102060, 0xc00663f100, 0xc0082d7900) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server/handlers.go:269 +0x188 net/http.HandlerFunc.ServeHTTP(0xc002c81f20, 0x1102060, 0xc00663f100, 0xc0082d7900) /usr/local/go/src/net/http/server.go:1964 +0x44 net/http.(*ServeMux).ServeHTTP(0xc002c81b60, 0x1102060, 0xc00663f100, 0xc0082d7900) /usr/local/go/src/net/http/server.go:2361 +0x127 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server.maxBytesHandler.ServeHTTP(0x10f8a40, 0xc002c81b60, 0xf4240, 0x1102060, 0xc00663f100, 0xc0082d7900) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server/http_server.go:219 +0xcf github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server.RecoverAndLogHandler.func1(0x1103220, 0xc00121e620, 0xc0082d7900) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server/http_server.go:192 +0x394 net/http.HandlerFunc.ServeHTTP(0xc002c06ea0, 0x1103220, 0xc00121e620, 0xc0082d7900) /usr/local/go/src/net/http/server.go:1964 +0x44 net/http.serverHandler.ServeHTTP(0xc001a1aa90, 0x1103220, 0xc00121e620, 0xc0082d7900) /usr/local/go/src/net/http/server.go:2741 +0xab net/http.(*conn).serve(0xc00785a3c0, 0x11041a0, 0xc000f844c0) /usr/local/go/src/net/http/server.go:1847 +0x646 created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:2851 +0x2f5 ``` * consensus: use read lock in Receive#VoteMessage * use defer to unlock mutex because application might panic * use defer in every method of the localClient * add a changelog entry * drain channels before Unsubscribe(All) Read https://github.com/tendermint/tendermint/blob/55362ed76630f3e1ebec159a598f6a9fb5892cb1/libs/pubsub/pubsub.go#L13 for the detailed explanation of the issue. We'll need to fix it someday. Make sure to keep an eye on https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-033-pubsub.md * retry instead of panic when peer has no state in reactors other than consensus in /dump_consensus_state RPC endpoint, skip a peer with no state * rpc/core/mempool: simplify error messages * rpc/core/mempool: use time.After instead of timer also, do not log DeliverTx result (to be consistent with other memthods) * unlock before calling the callback in reqRes#SetCallback
6 years ago
fix data race Closes #1442 ``` WARNING: DATA RACE Write at 0x00c4209de7c8 by goroutine 23: github.com/tendermint/tendermint/types.(*Block).fillHeader() /home/vagrant/go/src/github.com/tendermint/tendermint/types/block.go:88 +0x157 github.com/tendermint/tendermint/types.(*Block).Hash() /home/vagrant/go/src/github.com/tendermint/tendermint/types/block.go:104 +0x121 github.com/tendermint/tendermint/types.(*Block).HashesTo() /home/vagrant/go/src/github.com/tendermint/tendermint/types/block.go:135 +0x4f github.com/tendermint/tendermint/consensus.(*ConsensusState).enterPrecommit() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:1037 +0x182d github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:1425 +0x1a6c github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:1318 +0x77 github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:581 +0x7a9 github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:539 +0x6c3 Previous read at 0x00c4209de7c8 by goroutine 47: github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common.(*HexBytes).MarshalJSON() <autogenerated>:1 +0x52 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.invokeMarshalJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:433 +0x88 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec)._encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:82 +0x8d2 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:50 +0x10e github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSONStruct() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:348 +0x539 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec)._encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:119 +0x83f github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:50 +0x10e github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSONStruct() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:348 +0x539 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec)._encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:119 +0x83f github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:50 +0x10e github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSONStruct() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:348 +0x539 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec)._encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:119 +0x83f github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:50 +0x10e github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSONStruct() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:348 +0x539 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec)._encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:119 +0x83f github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:50 +0x10e github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).MarshalJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/amino.go:296 +0x182 github.com/tendermint/tendermint/rpc/lib/types.NewRPCSuccessResponse() /home/vagrant/go/src/github.com/tendermint/tendermint/rpc/lib/types/types.go:100 +0x12c github.com/tendermint/tendermint/rpc/lib/server.makeJSONRPCHandler.func1() /home/vagrant/go/src/github.com/tendermint/tendermint/rpc/lib/server/handlers.go:152 +0xab7 net/http.HandlerFunc.ServeHTTP() /usr/lib/go-1.9/src/net/http/server.go:1918 +0x51 net/http.(*ServeMux).ServeHTTP() /usr/lib/go-1.9/src/net/http/server.go:2254 +0xa2 github.com/tendermint/tendermint/rpc/lib/server.RecoverAndLogHandler.func1() /home/vagrant/go/src/github.com/tendermint/tendermint/rpc/lib/server/http_server.go:138 +0x4fa net/http.HandlerFunc.ServeHTTP() /usr/lib/go-1.9/src/net/http/server.go:1918 +0x51 net/http.serverHandler.ServeHTTP() /usr/lib/go-1.9/src/net/http/server.go:2619 +0xbc net/http.(*conn).serve() /usr/lib/go-1.9/src/net/http/server.go:1801 +0x83b Goroutine 23 (running) created at: github.com/tendermint/tendermint/consensus.(*ConsensusState).OnStart() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:250 +0x35b github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common.(*BaseService).Start() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common/service.go:130 +0x5fc github.com/tendermint/tendermint/consensus.(*ConsensusReactor).OnStart() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/reactor.go:69 +0x1b4 github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common.(*BaseService).Start() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common/service.go:130 +0x5fc github.com/tendermint/tendermint/consensus.(*ConsensusReactor).Start() <autogenerated>:1 +0x43 github.com/tendermint/tendermint/p2p.(*Switch).OnStart() /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch.go:177 +0x124 github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common.(*BaseService).Start() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common/service.go:130 +0x5fc github.com/tendermint/tendermint/node.(*Node).OnStart() /home/vagrant/go/src/github.com/tendermint/tendermint/node/node.go:416 +0xa1b github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common.(*BaseService).Start() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common/service.go:130 +0x5fc github.com/tendermint/tendermint/rpc/test.StartTendermint() /home/vagrant/go/src/github.com/tendermint/tendermint/rpc/test/helpers.go:100 +0x5b github.com/tendermint/tendermint/rpc/client_test.TestMain() /home/vagrant/go/src/github.com/tendermint/tendermint/rpc/client/main_test.go:17 +0x4c main.main() github.com/tendermint/tendermint/rpc/client/_test/_testmain.go:76 +0x1cd Goroutine 47 (running) created at: net/http.(*Server).Serve() /usr/lib/go-1.9/src/net/http/server.go:2720 +0x37c net/http.Serve() /usr/lib/go-1.9/src/net/http/server.go:2323 +0xe2 github.com/tendermint/tendermint/rpc/lib/server.StartHTTPServer.func1() /home/vagrant/go/src/github.com/tendermint/tendermint/rpc/lib/server/http_server.go:35 +0xb3 ```
7 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
10 years ago
abci: localClient improvements & bugfixes & pubsub Unsubscribe issues (#2748) * use READ lock/unlock in ConsensusState#GetLastHeight Refs #2721 * do not use defers when there's no need * fix peer formatting (output its address instead of the pointer) ``` [54310]: E[11-02|11:59:39.851] Connection failed @ sendRoutine module=p2p peer=0xb78f00 conn=MConn{74.207.236.148:26656} err="pong timeout" ``` https://github.com/tendermint/tendermint/issues/2721#issuecomment-435326581 * panic if peer has no state https://github.com/tendermint/tendermint/issues/2721#issuecomment-435347165 It's confusing that sometimes we check if peer has a state, but most of the times we expect it to be there 1. https://github.com/tendermint/tendermint/blob/add79700b5fe84417538202b6c927c8cc5383672/mempool/reactor.go#L138 2. https://github.com/tendermint/tendermint/blob/add79700b5fe84417538202b6c927c8cc5383672/rpc/core/consensus.go#L196 (edited) I will change everything to always assume peer has a state and panic otherwise that should help identify issues earlier * abci/localclient: extend lock on app callback App callback should be protected by lock as well (note this was already done for InitChainAsync, why not for others???). Otherwise, when we execute the block, tx might come in and call the callback in the same time we're updating it in execBlockOnProxyApp => DATA RACE Fixes #2721 Consensus state is locked ``` goroutine 113333 [semacquire, 309 minutes]: sync.runtime_SemacquireMutex(0xc00180009c, 0xc0000c7e00) /usr/local/go/src/runtime/sema.go:71 +0x3d sync.(*RWMutex).RLock(0xc001800090) /usr/local/go/src/sync/rwmutex.go:50 +0x4e github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).GetRoundState(0xc001800000, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:218 +0x46 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusReactor).queryMaj23Routine(0xc0017def80, 0x11104a0, 0xc0072488f0, 0xc007248 9c0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/reactor.go:735 +0x16d created by github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusReactor).AddPeer /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/reactor.go:172 +0x236 ``` because localClient is locked ``` goroutine 1899 [semacquire, 309 minutes]: sync.runtime_SemacquireMutex(0xc00003363c, 0xc0000cb500) /usr/local/go/src/runtime/sema.go:71 +0x3d sync.(*Mutex).Lock(0xc000033638) /usr/local/go/src/sync/mutex.go:134 +0xff github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/abci/client.(*localClient).SetResponseCallback(0xc0001fb560, 0xc007868540) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/abci/client/local_client.go:32 +0x33 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/proxy.(*appConnConsensus).SetResponseCallback(0xc00002f750, 0xc007868540) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/proxy/app_conn.go:57 +0x40 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/state.execBlockOnProxyApp(0x1104e20, 0xc002ca0ba0, 0x11092a0, 0xc00002f750, 0xc0001fe960, 0xc000bfc660, 0x110cfe0, 0xc000090330, 0xc9d12, 0xc000d9d5a0, ...) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/state/execution.go:230 +0x1fd github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/state.(*BlockExecutor).ApplyBlock(0xc002c2a230, 0x7, 0x0, 0xc000eae880, 0x6, 0xc002e52c60, 0x16, 0x1f927, 0xc9d12, 0xc000d9d5a0, ...) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/state/execution.go:96 +0x142 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).finalizeCommit(0xc001800000, 0x1f928) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1339 +0xa3e github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).tryFinalizeCommit(0xc001800000, 0x1f928) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1270 +0x451 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).enterCommit.func1(0xc001800000, 0x0, 0x1f928) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1218 +0x90 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).enterCommit(0xc001800000, 0x1f928, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1247 +0x6b8 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote(0xc001800000, 0xc003d8dea0, 0xc000cf4cc0, 0x28, 0xf1, 0xc003bc7ad0, 0xc003bc7b10) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1659 +0xbad github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote(0xc001800000, 0xc003d8dea0, 0xc000cf4cc0, 0x28, 0xf1, 0xf1, 0xf1) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1517 +0x59 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg(0xc001800000, 0xd98200, 0xc0070dbed0, 0xc000cf4cc0, 0x28) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:660 +0x64b github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine(0xc001800000, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:617 +0x670 created by github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).OnStart /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:311 +0x132 ``` tx comes in and CheckTx is executed right when we execute the block ``` goroutine 111044 [semacquire, 309 minutes]: sync.runtime_SemacquireMutex(0xc00003363c, 0x0) /usr/local/go/src/runtime/sema.go:71 +0x3d sync.(*Mutex).Lock(0xc000033638) /usr/local/go/src/sync/mutex.go:134 +0xff github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/abci/client.(*localClient).CheckTxAsync(0xc0001fb0e0, 0xc002d94500, 0x13f, 0x280, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/abci/client/local_client.go:85 +0x47 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/proxy.(*appConnMempool).CheckTxAsync(0xc00002f720, 0xc002d94500, 0x13f, 0x280, 0x1) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/proxy/app_conn.go:114 +0x51 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/mempool.(*Mempool).CheckTx(0xc002d3a320, 0xc002d94500, 0x13f, 0x280, 0xc0072355f0, 0x0, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/mempool/mempool.go:316 +0x17b github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/core.BroadcastTxSync(0xc002d94500, 0x13f, 0x280, 0x0, 0x0, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/core/mempool.go:93 +0xb8 reflect.Value.call(0xd85560, 0x10326c0, 0x13, 0xec7b8b, 0x4, 0xc00663f180, 0x1, 0x1, 0xc00663f180, 0xc00663f188, ...) /usr/local/go/src/reflect/value.go:447 +0x449 reflect.Value.Call(0xd85560, 0x10326c0, 0x13, 0xc00663f180, 0x1, 0x1, 0x0, 0x0, 0xc005cc9344) /usr/local/go/src/reflect/value.go:308 +0xa4 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server.makeHTTPHandler.func2(0x1102060, 0xc00663f100, 0xc0082d7900) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server/handlers.go:269 +0x188 net/http.HandlerFunc.ServeHTTP(0xc002c81f20, 0x1102060, 0xc00663f100, 0xc0082d7900) /usr/local/go/src/net/http/server.go:1964 +0x44 net/http.(*ServeMux).ServeHTTP(0xc002c81b60, 0x1102060, 0xc00663f100, 0xc0082d7900) /usr/local/go/src/net/http/server.go:2361 +0x127 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server.maxBytesHandler.ServeHTTP(0x10f8a40, 0xc002c81b60, 0xf4240, 0x1102060, 0xc00663f100, 0xc0082d7900) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server/http_server.go:219 +0xcf github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server.RecoverAndLogHandler.func1(0x1103220, 0xc00121e620, 0xc0082d7900) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server/http_server.go:192 +0x394 net/http.HandlerFunc.ServeHTTP(0xc002c06ea0, 0x1103220, 0xc00121e620, 0xc0082d7900) /usr/local/go/src/net/http/server.go:1964 +0x44 net/http.serverHandler.ServeHTTP(0xc001a1aa90, 0x1103220, 0xc00121e620, 0xc0082d7900) /usr/local/go/src/net/http/server.go:2741 +0xab net/http.(*conn).serve(0xc00785a3c0, 0x11041a0, 0xc000f844c0) /usr/local/go/src/net/http/server.go:1847 +0x646 created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:2851 +0x2f5 ``` * consensus: use read lock in Receive#VoteMessage * use defer to unlock mutex because application might panic * use defer in every method of the localClient * add a changelog entry * drain channels before Unsubscribe(All) Read https://github.com/tendermint/tendermint/blob/55362ed76630f3e1ebec159a598f6a9fb5892cb1/libs/pubsub/pubsub.go#L13 for the detailed explanation of the issue. We'll need to fix it someday. Make sure to keep an eye on https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-033-pubsub.md * retry instead of panic when peer has no state in reactors other than consensus in /dump_consensus_state RPC endpoint, skip a peer with no state * rpc/core/mempool: simplify error messages * rpc/core/mempool: use time.After instead of timer also, do not log DeliverTx result (to be consistent with other memthods) * unlock before calling the callback in reqRes#SetCallback
6 years ago
10 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
fix data race Closes #1442 ``` WARNING: DATA RACE Write at 0x00c4209de7c8 by goroutine 23: github.com/tendermint/tendermint/types.(*Block).fillHeader() /home/vagrant/go/src/github.com/tendermint/tendermint/types/block.go:88 +0x157 github.com/tendermint/tendermint/types.(*Block).Hash() /home/vagrant/go/src/github.com/tendermint/tendermint/types/block.go:104 +0x121 github.com/tendermint/tendermint/types.(*Block).HashesTo() /home/vagrant/go/src/github.com/tendermint/tendermint/types/block.go:135 +0x4f github.com/tendermint/tendermint/consensus.(*ConsensusState).enterPrecommit() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:1037 +0x182d github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:1425 +0x1a6c github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:1318 +0x77 github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:581 +0x7a9 github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:539 +0x6c3 Previous read at 0x00c4209de7c8 by goroutine 47: github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common.(*HexBytes).MarshalJSON() <autogenerated>:1 +0x52 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.invokeMarshalJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:433 +0x88 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec)._encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:82 +0x8d2 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:50 +0x10e github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSONStruct() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:348 +0x539 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec)._encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:119 +0x83f github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:50 +0x10e github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSONStruct() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:348 +0x539 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec)._encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:119 +0x83f github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:50 +0x10e github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSONStruct() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:348 +0x539 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec)._encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:119 +0x83f github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:50 +0x10e github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSONStruct() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:348 +0x539 github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec)._encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:119 +0x83f github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).encodeReflectJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/json-encode.go:50 +0x10e github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino.(*Codec).MarshalJSON() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/go-amino/amino.go:296 +0x182 github.com/tendermint/tendermint/rpc/lib/types.NewRPCSuccessResponse() /home/vagrant/go/src/github.com/tendermint/tendermint/rpc/lib/types/types.go:100 +0x12c github.com/tendermint/tendermint/rpc/lib/server.makeJSONRPCHandler.func1() /home/vagrant/go/src/github.com/tendermint/tendermint/rpc/lib/server/handlers.go:152 +0xab7 net/http.HandlerFunc.ServeHTTP() /usr/lib/go-1.9/src/net/http/server.go:1918 +0x51 net/http.(*ServeMux).ServeHTTP() /usr/lib/go-1.9/src/net/http/server.go:2254 +0xa2 github.com/tendermint/tendermint/rpc/lib/server.RecoverAndLogHandler.func1() /home/vagrant/go/src/github.com/tendermint/tendermint/rpc/lib/server/http_server.go:138 +0x4fa net/http.HandlerFunc.ServeHTTP() /usr/lib/go-1.9/src/net/http/server.go:1918 +0x51 net/http.serverHandler.ServeHTTP() /usr/lib/go-1.9/src/net/http/server.go:2619 +0xbc net/http.(*conn).serve() /usr/lib/go-1.9/src/net/http/server.go:1801 +0x83b Goroutine 23 (running) created at: github.com/tendermint/tendermint/consensus.(*ConsensusState).OnStart() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:250 +0x35b github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common.(*BaseService).Start() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common/service.go:130 +0x5fc github.com/tendermint/tendermint/consensus.(*ConsensusReactor).OnStart() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/reactor.go:69 +0x1b4 github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common.(*BaseService).Start() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common/service.go:130 +0x5fc github.com/tendermint/tendermint/consensus.(*ConsensusReactor).Start() <autogenerated>:1 +0x43 github.com/tendermint/tendermint/p2p.(*Switch).OnStart() /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch.go:177 +0x124 github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common.(*BaseService).Start() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common/service.go:130 +0x5fc github.com/tendermint/tendermint/node.(*Node).OnStart() /home/vagrant/go/src/github.com/tendermint/tendermint/node/node.go:416 +0xa1b github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common.(*BaseService).Start() /home/vagrant/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common/service.go:130 +0x5fc github.com/tendermint/tendermint/rpc/test.StartTendermint() /home/vagrant/go/src/github.com/tendermint/tendermint/rpc/test/helpers.go:100 +0x5b github.com/tendermint/tendermint/rpc/client_test.TestMain() /home/vagrant/go/src/github.com/tendermint/tendermint/rpc/client/main_test.go:17 +0x4c main.main() github.com/tendermint/tendermint/rpc/client/_test/_testmain.go:76 +0x1cd Goroutine 47 (running) created at: net/http.(*Server).Serve() /usr/lib/go-1.9/src/net/http/server.go:2720 +0x37c net/http.Serve() /usr/lib/go-1.9/src/net/http/server.go:2323 +0xe2 github.com/tendermint/tendermint/rpc/lib/server.StartHTTPServer.func1() /home/vagrant/go/src/github.com/tendermint/tendermint/rpc/lib/server/http_server.go:35 +0xb3 ```
7 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
abci: localClient improvements & bugfixes & pubsub Unsubscribe issues (#2748) * use READ lock/unlock in ConsensusState#GetLastHeight Refs #2721 * do not use defers when there's no need * fix peer formatting (output its address instead of the pointer) ``` [54310]: E[11-02|11:59:39.851] Connection failed @ sendRoutine module=p2p peer=0xb78f00 conn=MConn{74.207.236.148:26656} err="pong timeout" ``` https://github.com/tendermint/tendermint/issues/2721#issuecomment-435326581 * panic if peer has no state https://github.com/tendermint/tendermint/issues/2721#issuecomment-435347165 It's confusing that sometimes we check if peer has a state, but most of the times we expect it to be there 1. https://github.com/tendermint/tendermint/blob/add79700b5fe84417538202b6c927c8cc5383672/mempool/reactor.go#L138 2. https://github.com/tendermint/tendermint/blob/add79700b5fe84417538202b6c927c8cc5383672/rpc/core/consensus.go#L196 (edited) I will change everything to always assume peer has a state and panic otherwise that should help identify issues earlier * abci/localclient: extend lock on app callback App callback should be protected by lock as well (note this was already done for InitChainAsync, why not for others???). Otherwise, when we execute the block, tx might come in and call the callback in the same time we're updating it in execBlockOnProxyApp => DATA RACE Fixes #2721 Consensus state is locked ``` goroutine 113333 [semacquire, 309 minutes]: sync.runtime_SemacquireMutex(0xc00180009c, 0xc0000c7e00) /usr/local/go/src/runtime/sema.go:71 +0x3d sync.(*RWMutex).RLock(0xc001800090) /usr/local/go/src/sync/rwmutex.go:50 +0x4e github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).GetRoundState(0xc001800000, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:218 +0x46 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusReactor).queryMaj23Routine(0xc0017def80, 0x11104a0, 0xc0072488f0, 0xc007248 9c0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/reactor.go:735 +0x16d created by github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusReactor).AddPeer /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/reactor.go:172 +0x236 ``` because localClient is locked ``` goroutine 1899 [semacquire, 309 minutes]: sync.runtime_SemacquireMutex(0xc00003363c, 0xc0000cb500) /usr/local/go/src/runtime/sema.go:71 +0x3d sync.(*Mutex).Lock(0xc000033638) /usr/local/go/src/sync/mutex.go:134 +0xff github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/abci/client.(*localClient).SetResponseCallback(0xc0001fb560, 0xc007868540) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/abci/client/local_client.go:32 +0x33 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/proxy.(*appConnConsensus).SetResponseCallback(0xc00002f750, 0xc007868540) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/proxy/app_conn.go:57 +0x40 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/state.execBlockOnProxyApp(0x1104e20, 0xc002ca0ba0, 0x11092a0, 0xc00002f750, 0xc0001fe960, 0xc000bfc660, 0x110cfe0, 0xc000090330, 0xc9d12, 0xc000d9d5a0, ...) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/state/execution.go:230 +0x1fd github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/state.(*BlockExecutor).ApplyBlock(0xc002c2a230, 0x7, 0x0, 0xc000eae880, 0x6, 0xc002e52c60, 0x16, 0x1f927, 0xc9d12, 0xc000d9d5a0, ...) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/state/execution.go:96 +0x142 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).finalizeCommit(0xc001800000, 0x1f928) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1339 +0xa3e github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).tryFinalizeCommit(0xc001800000, 0x1f928) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1270 +0x451 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).enterCommit.func1(0xc001800000, 0x0, 0x1f928) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1218 +0x90 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).enterCommit(0xc001800000, 0x1f928, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1247 +0x6b8 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote(0xc001800000, 0xc003d8dea0, 0xc000cf4cc0, 0x28, 0xf1, 0xc003bc7ad0, 0xc003bc7b10) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1659 +0xbad github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote(0xc001800000, 0xc003d8dea0, 0xc000cf4cc0, 0x28, 0xf1, 0xf1, 0xf1) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1517 +0x59 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg(0xc001800000, 0xd98200, 0xc0070dbed0, 0xc000cf4cc0, 0x28) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:660 +0x64b github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine(0xc001800000, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:617 +0x670 created by github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).OnStart /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:311 +0x132 ``` tx comes in and CheckTx is executed right when we execute the block ``` goroutine 111044 [semacquire, 309 minutes]: sync.runtime_SemacquireMutex(0xc00003363c, 0x0) /usr/local/go/src/runtime/sema.go:71 +0x3d sync.(*Mutex).Lock(0xc000033638) /usr/local/go/src/sync/mutex.go:134 +0xff github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/abci/client.(*localClient).CheckTxAsync(0xc0001fb0e0, 0xc002d94500, 0x13f, 0x280, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/abci/client/local_client.go:85 +0x47 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/proxy.(*appConnMempool).CheckTxAsync(0xc00002f720, 0xc002d94500, 0x13f, 0x280, 0x1) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/proxy/app_conn.go:114 +0x51 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/mempool.(*Mempool).CheckTx(0xc002d3a320, 0xc002d94500, 0x13f, 0x280, 0xc0072355f0, 0x0, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/mempool/mempool.go:316 +0x17b github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/core.BroadcastTxSync(0xc002d94500, 0x13f, 0x280, 0x0, 0x0, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/core/mempool.go:93 +0xb8 reflect.Value.call(0xd85560, 0x10326c0, 0x13, 0xec7b8b, 0x4, 0xc00663f180, 0x1, 0x1, 0xc00663f180, 0xc00663f188, ...) /usr/local/go/src/reflect/value.go:447 +0x449 reflect.Value.Call(0xd85560, 0x10326c0, 0x13, 0xc00663f180, 0x1, 0x1, 0x0, 0x0, 0xc005cc9344) /usr/local/go/src/reflect/value.go:308 +0xa4 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server.makeHTTPHandler.func2(0x1102060, 0xc00663f100, 0xc0082d7900) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server/handlers.go:269 +0x188 net/http.HandlerFunc.ServeHTTP(0xc002c81f20, 0x1102060, 0xc00663f100, 0xc0082d7900) /usr/local/go/src/net/http/server.go:1964 +0x44 net/http.(*ServeMux).ServeHTTP(0xc002c81b60, 0x1102060, 0xc00663f100, 0xc0082d7900) /usr/local/go/src/net/http/server.go:2361 +0x127 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server.maxBytesHandler.ServeHTTP(0x10f8a40, 0xc002c81b60, 0xf4240, 0x1102060, 0xc00663f100, 0xc0082d7900) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server/http_server.go:219 +0xcf github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server.RecoverAndLogHandler.func1(0x1103220, 0xc00121e620, 0xc0082d7900) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server/http_server.go:192 +0x394 net/http.HandlerFunc.ServeHTTP(0xc002c06ea0, 0x1103220, 0xc00121e620, 0xc0082d7900) /usr/local/go/src/net/http/server.go:1964 +0x44 net/http.serverHandler.ServeHTTP(0xc001a1aa90, 0x1103220, 0xc00121e620, 0xc0082d7900) /usr/local/go/src/net/http/server.go:2741 +0xab net/http.(*conn).serve(0xc00785a3c0, 0x11041a0, 0xc000f844c0) /usr/local/go/src/net/http/server.go:1847 +0x646 created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:2851 +0x2f5 ``` * consensus: use read lock in Receive#VoteMessage * use defer to unlock mutex because application might panic * use defer in every method of the localClient * add a changelog entry * drain channels before Unsubscribe(All) Read https://github.com/tendermint/tendermint/blob/55362ed76630f3e1ebec159a598f6a9fb5892cb1/libs/pubsub/pubsub.go#L13 for the detailed explanation of the issue. We'll need to fix it someday. Make sure to keep an eye on https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-033-pubsub.md * retry instead of panic when peer has no state in reactors other than consensus in /dump_consensus_state RPC endpoint, skip a peer with no state * rpc/core/mempool: simplify error messages * rpc/core/mempool: use time.After instead of timer also, do not log DeliverTx result (to be consistent with other memthods) * unlock before calling the callback in reqRes#SetCallback
6 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 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
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
10 years ago
8 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
8 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 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
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
9 years ago
9 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
9 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
cs: check for SkipTimeoutCommit or wait timeout in handleTxsAvailable (#3928) * cs: check for SkipTimeoutCommit or wait timeout in handleTxsAvailable Previously, if create_empty_blocks was set to false, TM sometimes could create 2 consecutive blocks without actually waiting for timeoutCommit (1 sec. by default). ``` I[2019-08-29|07:32:43.874] Executed block module=state height=47 validTxs=10 invalidTxs=0 I[2019-08-29|07:32:43.876] Committed state module=state height=47 txs=10 appHash=F88C010000000000 I[2019-08-29|07:32:44.885] Executed block module=state height=48 validTxs=2 invalidTxs=0 I[2019-08-29|07:32:44.887] Committed state module=state height=48 txs=2 appHash=FC8C010000000000 I[2019-08-29|07:32:44.908] Executed block module=state height=49 validTxs=8 invalidTxs=0 I[2019-08-29|07:32:44.909] Committed state module=state height=49 txs=8 appHash=8C8D010000000000 I[2019-08-29|07:32:45.886] Executed block module=state height=50 validTxs=2 invalidTxs=0 I[2019-08-29|07:32:45.895] Committed state module=state height=50 txs=2 appHash=908D010000000000 I[2019-08-29|07:32:45.908] Executed block module=state height=51 validTxs=8 invalidTxs=0 I[2019-08-29|07:32:45.909] Committed state module=state height=51 txs=8 appHash=A08D010000000000 ``` This commit fixes that by adding a check to handleTxsAvailable. Fixes #3908 * update changelog * schedule timeoutCommit if StartTime is in the future or SkipTimeoutCommit=true && we DON'T have all the votes * fix TestReactorCreatesBlockWhenEmptyBlocksFalse by checking if we have LastCommit or not * address Ethan's comments
5 years ago
cs: reset triggered timeout precommit (#3310) * Reset TriggeredTimeoutPrecommit as part of updateToState * Add failing test and fix * fix DATA RACE in TestResetTimeoutPrecommitUponNewHeight ``` WARNING: DATA RACE Read at 0x00c001691d28 by goroutine 691: github.com/tendermint/tendermint/consensus.decideProposal() /go/src/github.com/tendermint/tendermint/consensus/common_test.go:133 +0x121 github.com/tendermint/tendermint/consensus.TestResetTimeoutPrecommitUponNewHeight() /go/src/github.com/tendermint/tendermint/consensus/state_test.go:1389 +0x958 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Previous write at 0x00c001691d28 by goroutine 931: github.com/tendermint/tendermint/consensus.(*ConsensusState).updateToState() /go/src/github.com/tendermint/tendermint/consensus/state.go:562 +0x5b2 github.com/tendermint/tendermint/consensus.(*ConsensusState).finalizeCommit() /go/src/github.com/tendermint/tendermint/consensus/state.go:1340 +0x141e github.com/tendermint/tendermint/consensus.(*ConsensusState).tryFinalizeCommit() /go/src/github.com/tendermint/tendermint/consensus/state.go:1255 +0x66e github.com/tendermint/tendermint/consensus.(*ConsensusState).enterCommit.func1() /go/src/github.com/tendermint/tendermint/consensus/state.go:1201 +0x135 github.com/tendermint/tendermint/consensus.(*ConsensusState).enterCommit() /go/src/github.com/tendermint/tendermint/consensus/state.go:1232 +0x94b github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1657 +0x132e github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1503 +0x8f github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg() /go/src/github.com/tendermint/tendermint/consensus/state.go:694 +0xa1e github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:642 +0x948 github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:642 +0x948 github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:642 +0x948 github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:655 +0x7dd github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:642 +0x948 github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:655 +0x7dd Goroutine 691 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 testing.runTests.func1() /usr/local/go/src/testing/testing.go:1119 +0xa8 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 testing.runTests() testing.(*M).Run() /usr/local/go/src/testing/testing.go:1034 +0x2ee main.main() _testmain.go:216 +0x332 ``` * fix another DATA RACE by locking consensus ``` WARNING: DATA RACE Read at 0x00c009b835a8 by goroutine 871: github.com/tendermint/tendermint/consensus.(*ConsensusState).createProposalBlock() /go/src/github.com/tendermint/tendermint/consensus/state.go:955 +0x7c github.com/tendermint/tendermint/consensus.decideProposal() /go/src/github.com/tendermint/tendermint/consensus/common_test.go:127 +0x53 github.com/tendermint/tendermint/consensus.TestResetTimeoutPrecommitUponNewHeight() /go/src/github.com/tendermint/tendermint/consensus/state_test.go:1389 +0x958 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Previous write at 0x00c009b835a8 by goroutine 931: github.com/tendermint/tendermint/consensus.(*ConsensusState).updateHeight() /go/src/github.com/tendermint/tendermint/consensus/state.go:446 +0xb7 github.com/tendermint/tendermint/consensus.(*ConsensusState).updateToState() /go/src/github.com/tendermint/tendermint/consensus/state.go:542 +0x22f github.com/tendermint/tendermint/consensus.(*ConsensusState).finalizeCommit() /go/src/github.com/tendermint/tendermint/consensus/state.go:1340 +0x141e github.com/tendermint/tendermint/consensus.(*ConsensusState).tryFinalizeCommit() /go/src/github.com/tendermint/tendermint/consensus/state.go:1255 +0x66e github.com/tendermint/tendermint/consensus.(*ConsensusState).enterCommit.func1() /go/src/github.com/tendermint/tendermint/consensus/state.go:1201 +0x135 github.com/tendermint/tendermint/consensus.(*ConsensusState).enterCommit() /go/src/github.com/tendermint/tendermint/consensus/state.go:1232 +0x94b github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1657 +0x132e github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1503 +0x8f github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg() /go/src/github.com/tendermint/tendermint/consensus/state.go:694 +0xa1e github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:642 +0x948 github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:642 +0x948 github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:642 +0x948 github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:655 +0x7dd github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:642 +0x948 github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:655 +0x7dd ``` * Fix failing test * Delete profile.out * fix data races
6 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 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
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
WAL: better errors and new fail point (#3246) * privval: more info in errors * wal: change Debug logs to Info * wal: log and return error on corrupted wal instead of panicing * fail: Exit right away instead of sending interupt * consensus: FAIL before handling our own vote allows to replicate #3089: - run using `FAIL_TEST_INDEX=0` - delete some bytes from the end of the WAL - start normally Results in logs like: ``` I[2019-02-03|18:12:58.225] Searching for height module=consensus wal=/Users/ethanbuchman/.tendermint/data/cs.wal/wal height=1 min=0 max=0 E[2019-02-03|18:12:58.225] Error on catchup replay. Proceeding to start ConsensusState anyway module=consensus err="failed to read data: EOF" I[2019-02-03|18:12:58.225] Started node module=main nodeInfo="{ProtocolVersion:{P2P:6 Block:9 App:1} ID_:35e87e93f2e31f305b65a5517fd2102331b56002 ListenAddr:tcp://0.0.0.0:26656 Network:test-chain-J8JvJH Version:0.29.1 Channels:4020212223303800 Moniker:Ethans-MacBook-Pro.local Other:{TxIndex:on RPCAddress:tcp://0.0.0.0:26657}}" E[2019-02-03|18:12:58.226] Couldn't connect to any seeds module=p2p I[2019-02-03|18:12:59.229] Timed out module=consensus dur=998.568ms height=1 round=0 step=RoundStepNewHeight I[2019-02-03|18:12:59.230] enterNewRound(1/0). Current: 1/0/RoundStepNewHeight module=consensus height=1 round=0 I[2019-02-03|18:12:59.230] enterPropose(1/0). Current: 1/0/RoundStepNewRound module=consensus height=1 round=0 I[2019-02-03|18:12:59.230] enterPropose: Our turn to propose module=consensus height=1 round=0 proposer=AD278B7767B05D7FBEB76207024C650988FA77D5 privValidator="PrivValidator{AD278B7767B05D7FBEB76207024C650988FA77D5 LH:1, LR:0, LS:2}" E[2019-02-03|18:12:59.230] enterPropose: Error signing proposal module=consensus height=1 round=0 err="Error signing proposal: Step regression at height 1 round 0. Got 1, last step 2" I[2019-02-03|18:13:02.233] Timed out module=consensus dur=3s height=1 round=0 step=RoundStepPropose I[2019-02-03|18:13:02.233] enterPrevote(1/0). Current: 1/0/RoundStepPropose module=consensus I[2019-02-03|18:13:02.233] enterPrevote: ProposalBlock is nil module=consensus height=1 round=0 E[2019-02-03|18:13:02.234] Error signing vote module=consensus height=1 round=0 vote="Vote{0:AD278B7767B0 1/00/1(Prevote) 000000000000 000000000000 @ 2019-02-04T02:13:02.233897Z}" err="Error signing vote: Conflicting data" ``` Notice the EOF, the step regression, and the conflicting data. * wal: change errors to be DataCorruptionError * exit on corrupt WAL * fix log * fix new line
6 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
cs: check for SkipTimeoutCommit or wait timeout in handleTxsAvailable (#3928) * cs: check for SkipTimeoutCommit or wait timeout in handleTxsAvailable Previously, if create_empty_blocks was set to false, TM sometimes could create 2 consecutive blocks without actually waiting for timeoutCommit (1 sec. by default). ``` I[2019-08-29|07:32:43.874] Executed block module=state height=47 validTxs=10 invalidTxs=0 I[2019-08-29|07:32:43.876] Committed state module=state height=47 txs=10 appHash=F88C010000000000 I[2019-08-29|07:32:44.885] Executed block module=state height=48 validTxs=2 invalidTxs=0 I[2019-08-29|07:32:44.887] Committed state module=state height=48 txs=2 appHash=FC8C010000000000 I[2019-08-29|07:32:44.908] Executed block module=state height=49 validTxs=8 invalidTxs=0 I[2019-08-29|07:32:44.909] Committed state module=state height=49 txs=8 appHash=8C8D010000000000 I[2019-08-29|07:32:45.886] Executed block module=state height=50 validTxs=2 invalidTxs=0 I[2019-08-29|07:32:45.895] Committed state module=state height=50 txs=2 appHash=908D010000000000 I[2019-08-29|07:32:45.908] Executed block module=state height=51 validTxs=8 invalidTxs=0 I[2019-08-29|07:32:45.909] Committed state module=state height=51 txs=8 appHash=A08D010000000000 ``` This commit fixes that by adding a check to handleTxsAvailable. Fixes #3908 * update changelog * schedule timeoutCommit if StartTime is in the future or SkipTimeoutCommit=true && we DON'T have all the votes * fix TestReactorCreatesBlockWhenEmptyBlocksFalse by checking if we have LastCommit or not * address Ethan's comments
5 years ago
cs: check for SkipTimeoutCommit or wait timeout in handleTxsAvailable (#3928) * cs: check for SkipTimeoutCommit or wait timeout in handleTxsAvailable Previously, if create_empty_blocks was set to false, TM sometimes could create 2 consecutive blocks without actually waiting for timeoutCommit (1 sec. by default). ``` I[2019-08-29|07:32:43.874] Executed block module=state height=47 validTxs=10 invalidTxs=0 I[2019-08-29|07:32:43.876] Committed state module=state height=47 txs=10 appHash=F88C010000000000 I[2019-08-29|07:32:44.885] Executed block module=state height=48 validTxs=2 invalidTxs=0 I[2019-08-29|07:32:44.887] Committed state module=state height=48 txs=2 appHash=FC8C010000000000 I[2019-08-29|07:32:44.908] Executed block module=state height=49 validTxs=8 invalidTxs=0 I[2019-08-29|07:32:44.909] Committed state module=state height=49 txs=8 appHash=8C8D010000000000 I[2019-08-29|07:32:45.886] Executed block module=state height=50 validTxs=2 invalidTxs=0 I[2019-08-29|07:32:45.895] Committed state module=state height=50 txs=2 appHash=908D010000000000 I[2019-08-29|07:32:45.908] Executed block module=state height=51 validTxs=8 invalidTxs=0 I[2019-08-29|07:32:45.909] Committed state module=state height=51 txs=8 appHash=A08D010000000000 ``` This commit fixes that by adding a check to handleTxsAvailable. Fixes #3908 * update changelog * schedule timeoutCommit if StartTime is in the future or SkipTimeoutCommit=true && we DON'T have all the votes * fix TestReactorCreatesBlockWhenEmptyBlocksFalse by checking if we have LastCommit or not * address Ethan's comments
5 years ago
cs: check for SkipTimeoutCommit or wait timeout in handleTxsAvailable (#3928) * cs: check for SkipTimeoutCommit or wait timeout in handleTxsAvailable Previously, if create_empty_blocks was set to false, TM sometimes could create 2 consecutive blocks without actually waiting for timeoutCommit (1 sec. by default). ``` I[2019-08-29|07:32:43.874] Executed block module=state height=47 validTxs=10 invalidTxs=0 I[2019-08-29|07:32:43.876] Committed state module=state height=47 txs=10 appHash=F88C010000000000 I[2019-08-29|07:32:44.885] Executed block module=state height=48 validTxs=2 invalidTxs=0 I[2019-08-29|07:32:44.887] Committed state module=state height=48 txs=2 appHash=FC8C010000000000 I[2019-08-29|07:32:44.908] Executed block module=state height=49 validTxs=8 invalidTxs=0 I[2019-08-29|07:32:44.909] Committed state module=state height=49 txs=8 appHash=8C8D010000000000 I[2019-08-29|07:32:45.886] Executed block module=state height=50 validTxs=2 invalidTxs=0 I[2019-08-29|07:32:45.895] Committed state module=state height=50 txs=2 appHash=908D010000000000 I[2019-08-29|07:32:45.908] Executed block module=state height=51 validTxs=8 invalidTxs=0 I[2019-08-29|07:32:45.909] Committed state module=state height=51 txs=8 appHash=A08D010000000000 ``` This commit fixes that by adding a check to handleTxsAvailable. Fixes #3908 * update changelog * schedule timeoutCommit if StartTime is in the future or SkipTimeoutCommit=true && we DON'T have all the votes * fix TestReactorCreatesBlockWhenEmptyBlocksFalse by checking if we have LastCommit or not * address Ethan's comments
5 years ago
10 years ago
10 years ago
10 years ago
10 years ago
7 years ago
7 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
10 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
10 years ago
cs: sync WAL more frequently (#3300) As per #3043, this adds a ticker to sync the WAL every 2s while the WAL is running. * Flush WAL every 2s This adds a ticker that flushes the WAL every 2s while the WAL is running. This is related to #3043. * Fix spelling * Increase timeout to 2mins for slower build environments * Make WAL sync interval configurable * Add TODO to replace testChan with more comprehensive testBus * Remove extraneous debug statement * Remove testChan in favour of using system time As per https://github.com/tendermint/tendermint/pull/3300#discussion_r255886586, this removes the `testChan` WAL member and replaces the approach with a system time-oriented one. In this new approach, we keep track of the system time at which each flush and periodic flush successfully occurred. The naming of the various functions is also updated here to be more consistent with "flushing" as opposed to "sync'ing". * Update naming convention and ensure lock for timestamp update * Add Flush method as part of WAL interface Adds a `Flush` method as part of the WAL interface to enforce the idea that we can manually trigger a WAL flush from outside of the WAL. This is employed in the consensus state management to flush the WAL prior to signing votes/proposals, as per https://github.com/tendermint/tendermint/issues/3043#issuecomment-453853630 * Update CHANGELOG_PENDING * Remove mutex approach and replace with DI The dependency injection approach to dealing with testing concerns could allow similar effects to some kind of "testing bus"-based approach. This commit introduces an example of this, where instead of relying on (potentially fragile) timing of things between the code and the test, we inject code into the function under test that can signal the test through a channel. This allows us to avoid the `time.Sleep()`-based approach previously employed. * Update comment on WAL flushing during vote signing Co-Authored-By: thanethomson <connect@thanethomson.com> * Simplify flush interval definition Co-Authored-By: thanethomson <connect@thanethomson.com> * Expand commentary on WAL disk flushing Co-Authored-By: thanethomson <connect@thanethomson.com> * Add broken test to illustrate WAL sync test problem Removes test-related state (dependency injection code) from the WAL data structure and adds test code to illustrate the problem with using `WALGenerateNBlocks` and `wal.SearchForEndHeight` to test periodic sync'ing. * Fix test error messages * Use WAL group buffer size to check for flush A function is added to `libs/autofile/group.go#Group` in order to return the size of the buffered data (i.e. data that has not yet been flushed to disk). The test now checks that, prior to a `time.Sleep`, the group buffer has data in it. After the `time.Sleep` (during which time the periodic flush should have been called), the buffer should be empty. * Remove config root dir removal from #3291 * Add godoc for NewWAL mentioning periodic sync
6 years ago
10 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
10 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
10 years ago
10 years ago
10 years ago
10 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
10 years ago
10 years ago
8 years ago
7 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
7 years ago
7 years ago
7 years ago
10 years ago
10 years ago
add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
7 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
10 years ago
10 years ago
9 years ago
9 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
10 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
cs: sync WAL more frequently (#3300) As per #3043, this adds a ticker to sync the WAL every 2s while the WAL is running. * Flush WAL every 2s This adds a ticker that flushes the WAL every 2s while the WAL is running. This is related to #3043. * Fix spelling * Increase timeout to 2mins for slower build environments * Make WAL sync interval configurable * Add TODO to replace testChan with more comprehensive testBus * Remove extraneous debug statement * Remove testChan in favour of using system time As per https://github.com/tendermint/tendermint/pull/3300#discussion_r255886586, this removes the `testChan` WAL member and replaces the approach with a system time-oriented one. In this new approach, we keep track of the system time at which each flush and periodic flush successfully occurred. The naming of the various functions is also updated here to be more consistent with "flushing" as opposed to "sync'ing". * Update naming convention and ensure lock for timestamp update * Add Flush method as part of WAL interface Adds a `Flush` method as part of the WAL interface to enforce the idea that we can manually trigger a WAL flush from outside of the WAL. This is employed in the consensus state management to flush the WAL prior to signing votes/proposals, as per https://github.com/tendermint/tendermint/issues/3043#issuecomment-453853630 * Update CHANGELOG_PENDING * Remove mutex approach and replace with DI The dependency injection approach to dealing with testing concerns could allow similar effects to some kind of "testing bus"-based approach. This commit introduces an example of this, where instead of relying on (potentially fragile) timing of things between the code and the test, we inject code into the function under test that can signal the test through a channel. This allows us to avoid the `time.Sleep()`-based approach previously employed. * Update comment on WAL flushing during vote signing Co-Authored-By: thanethomson <connect@thanethomson.com> * Simplify flush interval definition Co-Authored-By: thanethomson <connect@thanethomson.com> * Expand commentary on WAL disk flushing Co-Authored-By: thanethomson <connect@thanethomson.com> * Add broken test to illustrate WAL sync test problem Removes test-related state (dependency injection code) from the WAL data structure and adds test code to illustrate the problem with using `WALGenerateNBlocks` and `wal.SearchForEndHeight` to test periodic sync'ing. * Fix test error messages * Use WAL group buffer size to check for flush A function is added to `libs/autofile/group.go#Group` in order to return the size of the buffered data (i.e. data that has not yet been flushed to disk). The test now checks that, prior to a `time.Sleep`, the group buffer has data in it. After the `time.Sleep` (during which time the periodic flush should have been called), the buffer should be empty. * Remove config root dir removal from #3291 * Add godoc for NewWAL mentioning periodic sync
6 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
10 years ago
  1. package consensus
  2. import (
  3. "bytes"
  4. "context"
  5. "errors"
  6. "fmt"
  7. "io/ioutil"
  8. "os"
  9. "runtime/debug"
  10. "time"
  11. "github.com/gogo/protobuf/proto"
  12. cfg "github.com/tendermint/tendermint/config"
  13. "github.com/tendermint/tendermint/crypto"
  14. cstypes "github.com/tendermint/tendermint/internal/consensus/types"
  15. "github.com/tendermint/tendermint/internal/libs/fail"
  16. tmsync "github.com/tendermint/tendermint/internal/libs/sync"
  17. tmevents "github.com/tendermint/tendermint/libs/events"
  18. tmjson "github.com/tendermint/tendermint/libs/json"
  19. "github.com/tendermint/tendermint/libs/log"
  20. tmmath "github.com/tendermint/tendermint/libs/math"
  21. tmos "github.com/tendermint/tendermint/libs/os"
  22. "github.com/tendermint/tendermint/libs/service"
  23. tmtime "github.com/tendermint/tendermint/libs/time"
  24. "github.com/tendermint/tendermint/privval"
  25. tmgrpc "github.com/tendermint/tendermint/privval/grpc"
  26. tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
  27. sm "github.com/tendermint/tendermint/state"
  28. "github.com/tendermint/tendermint/types"
  29. )
  30. // Consensus sentinel errors
  31. var (
  32. ErrInvalidProposalSignature = errors.New("error invalid proposal signature")
  33. ErrInvalidProposalPOLRound = errors.New("error invalid proposal POL round")
  34. ErrAddingVote = errors.New("error adding vote")
  35. ErrSignatureFoundInPastBlocks = errors.New("found signature from the same key")
  36. errPubKeyIsNotSet = errors.New("pubkey is not set. Look for \"Can't get private validator pubkey\" errors")
  37. )
  38. var msgQueueSize = 1000
  39. // msgs from the reactor which may update the state
  40. type msgInfo struct {
  41. Msg Message `json:"msg"`
  42. PeerID types.NodeID `json:"peer_key"`
  43. }
  44. // internally generated messages which may update the state
  45. type timeoutInfo struct {
  46. Duration time.Duration `json:"duration"`
  47. Height int64 `json:"height"`
  48. Round int32 `json:"round"`
  49. Step cstypes.RoundStepType `json:"step"`
  50. }
  51. func (ti *timeoutInfo) String() string {
  52. return fmt.Sprintf("%v ; %d/%d %v", ti.Duration, ti.Height, ti.Round, ti.Step)
  53. }
  54. // interface to the mempool
  55. type txNotifier interface {
  56. TxsAvailable() <-chan struct{}
  57. }
  58. // interface to the evidence pool
  59. type evidencePool interface {
  60. // reports conflicting votes to the evidence pool to be processed into evidence
  61. ReportConflictingVotes(voteA, voteB *types.Vote)
  62. }
  63. // State handles execution of the consensus algorithm.
  64. // It processes votes and proposals, and upon reaching agreement,
  65. // commits blocks to the chain and executes them against the application.
  66. // The internal state machine receives input from peers, the internal validator, and from a timer.
  67. type State struct {
  68. service.BaseService
  69. // config details
  70. config *cfg.ConsensusConfig
  71. privValidator types.PrivValidator // for signing votes
  72. privValidatorType types.PrivValidatorType
  73. // store blocks and commits
  74. blockStore sm.BlockStore
  75. // create and execute blocks
  76. blockExec *sm.BlockExecutor
  77. // notify us if txs are available
  78. txNotifier txNotifier
  79. // add evidence to the pool
  80. // when it's detected
  81. evpool evidencePool
  82. // internal state
  83. mtx tmsync.RWMutex
  84. cstypes.RoundState
  85. state sm.State // State until height-1.
  86. // privValidator pubkey, memoized for the duration of one block
  87. // to avoid extra requests to HSM
  88. privValidatorPubKey crypto.PubKey
  89. // state changes may be triggered by: msgs from peers,
  90. // msgs from ourself, or by timeouts
  91. peerMsgQueue chan msgInfo
  92. internalMsgQueue chan msgInfo
  93. timeoutTicker TimeoutTicker
  94. // information about about added votes and block parts are written on this channel
  95. // so statistics can be computed by reactor
  96. statsMsgQueue chan msgInfo
  97. // we use eventBus to trigger msg broadcasts in the reactor,
  98. // and to notify external subscribers, eg. through a websocket
  99. eventBus *types.EventBus
  100. // a Write-Ahead Log ensures we can recover from any kind of crash
  101. // and helps us avoid signing conflicting votes
  102. wal WAL
  103. replayMode bool // so we don't log signing errors during replay
  104. doWALCatchup bool // determines if we even try to do the catchup
  105. // for tests where we want to limit the number of transitions the state makes
  106. nSteps int
  107. // some functions can be overwritten for testing
  108. decideProposal func(height int64, round int32)
  109. doPrevote func(height int64, round int32)
  110. setProposal func(proposal *types.Proposal) error
  111. // closed when we finish shutting down
  112. done chan struct{}
  113. // synchronous pubsub between consensus state and reactor.
  114. // state only emits EventNewRoundStep and EventVote
  115. evsw tmevents.EventSwitch
  116. // for reporting metrics
  117. metrics *Metrics
  118. // wait the channel event happening for shutting down the state gracefully
  119. onStopCh chan *cstypes.RoundState
  120. }
  121. // StateOption sets an optional parameter on the State.
  122. type StateOption func(*State)
  123. // NewState returns a new State.
  124. func NewState(
  125. config *cfg.ConsensusConfig,
  126. state sm.State,
  127. blockExec *sm.BlockExecutor,
  128. blockStore sm.BlockStore,
  129. txNotifier txNotifier,
  130. evpool evidencePool,
  131. options ...StateOption,
  132. ) *State {
  133. cs := &State{
  134. config: config,
  135. blockExec: blockExec,
  136. blockStore: blockStore,
  137. txNotifier: txNotifier,
  138. peerMsgQueue: make(chan msgInfo, msgQueueSize),
  139. internalMsgQueue: make(chan msgInfo, msgQueueSize),
  140. timeoutTicker: NewTimeoutTicker(),
  141. statsMsgQueue: make(chan msgInfo, msgQueueSize),
  142. done: make(chan struct{}),
  143. doWALCatchup: true,
  144. wal: nilWAL{},
  145. evpool: evpool,
  146. evsw: tmevents.NewEventSwitch(),
  147. metrics: NopMetrics(),
  148. onStopCh: make(chan *cstypes.RoundState),
  149. }
  150. // set function defaults (may be overwritten before calling Start)
  151. cs.decideProposal = cs.defaultDecideProposal
  152. cs.doPrevote = cs.defaultDoPrevote
  153. cs.setProposal = cs.defaultSetProposal
  154. // We have no votes, so reconstruct LastCommit from SeenCommit.
  155. if state.LastBlockHeight > 0 {
  156. cs.reconstructLastCommit(state)
  157. }
  158. cs.updateToState(state)
  159. // NOTE: we do not call scheduleRound0 yet, we do that upon Start()
  160. cs.BaseService = *service.NewBaseService(nil, "State", cs)
  161. for _, option := range options {
  162. option(cs)
  163. }
  164. return cs
  165. }
  166. // SetLogger implements Service.
  167. func (cs *State) SetLogger(l log.Logger) {
  168. cs.BaseService.Logger = l
  169. cs.timeoutTicker.SetLogger(l)
  170. }
  171. // SetEventBus sets event bus.
  172. func (cs *State) SetEventBus(b *types.EventBus) {
  173. cs.eventBus = b
  174. cs.blockExec.SetEventBus(b)
  175. }
  176. // StateMetrics sets the metrics.
  177. func StateMetrics(metrics *Metrics) StateOption {
  178. return func(cs *State) { cs.metrics = metrics }
  179. }
  180. // String returns a string.
  181. func (cs *State) String() string {
  182. // better not to access shared variables
  183. return "ConsensusState"
  184. }
  185. // GetState returns a copy of the chain state.
  186. func (cs *State) GetState() sm.State {
  187. cs.mtx.RLock()
  188. defer cs.mtx.RUnlock()
  189. return cs.state.Copy()
  190. }
  191. // GetLastHeight returns the last height committed.
  192. // If there were no blocks, returns 0.
  193. func (cs *State) GetLastHeight() int64 {
  194. cs.mtx.RLock()
  195. defer cs.mtx.RUnlock()
  196. return cs.RoundState.Height - 1
  197. }
  198. // GetRoundState returns a shallow copy of the internal consensus state.
  199. func (cs *State) GetRoundState() *cstypes.RoundState {
  200. cs.mtx.RLock()
  201. rs := cs.RoundState // copy
  202. cs.mtx.RUnlock()
  203. return &rs
  204. }
  205. // GetRoundStateJSON returns a json of RoundState.
  206. func (cs *State) GetRoundStateJSON() ([]byte, error) {
  207. cs.mtx.RLock()
  208. defer cs.mtx.RUnlock()
  209. return tmjson.Marshal(cs.RoundState)
  210. }
  211. // GetRoundStateSimpleJSON returns a json of RoundStateSimple
  212. func (cs *State) GetRoundStateSimpleJSON() ([]byte, error) {
  213. cs.mtx.RLock()
  214. defer cs.mtx.RUnlock()
  215. return tmjson.Marshal(cs.RoundState.RoundStateSimple())
  216. }
  217. // GetValidators returns a copy of the current validators.
  218. func (cs *State) GetValidators() (int64, []*types.Validator) {
  219. cs.mtx.RLock()
  220. defer cs.mtx.RUnlock()
  221. return cs.state.LastBlockHeight, cs.state.Validators.Copy().Validators
  222. }
  223. // SetPrivValidator sets the private validator account for signing votes. It
  224. // immediately requests pubkey and caches it.
  225. func (cs *State) SetPrivValidator(priv types.PrivValidator) {
  226. cs.mtx.Lock()
  227. defer cs.mtx.Unlock()
  228. cs.privValidator = priv
  229. if priv != nil {
  230. switch t := priv.(type) {
  231. case *privval.RetrySignerClient:
  232. cs.privValidatorType = types.RetrySignerClient
  233. case *privval.FilePV:
  234. cs.privValidatorType = types.FileSignerClient
  235. case *privval.SignerClient:
  236. cs.privValidatorType = types.SignerSocketClient
  237. case *tmgrpc.SignerClient:
  238. cs.privValidatorType = types.SignerGRPCClient
  239. case types.MockPV:
  240. cs.privValidatorType = types.MockSignerClient
  241. case *types.ErroringMockPV:
  242. cs.privValidatorType = types.ErrorMockSignerClient
  243. default:
  244. cs.Logger.Error("unsupported priv validator type", "err",
  245. fmt.Errorf("error privValidatorType %s", t))
  246. }
  247. }
  248. if err := cs.updatePrivValidatorPubKey(); err != nil {
  249. cs.Logger.Error("failed to get private validator pubkey", "err", err)
  250. }
  251. }
  252. // SetTimeoutTicker sets the local timer. It may be useful to overwrite for
  253. // testing.
  254. func (cs *State) SetTimeoutTicker(timeoutTicker TimeoutTicker) {
  255. cs.mtx.Lock()
  256. cs.timeoutTicker = timeoutTicker
  257. cs.mtx.Unlock()
  258. }
  259. // LoadCommit loads the commit for a given height.
  260. func (cs *State) LoadCommit(height int64) *types.Commit {
  261. cs.mtx.RLock()
  262. defer cs.mtx.RUnlock()
  263. if height == cs.blockStore.Height() {
  264. commit := cs.blockStore.LoadSeenCommit()
  265. // NOTE: Retrieving the height of the most recent block and retrieving
  266. // the most recent commit does not currently occur as an atomic
  267. // operation. We check the height and commit here in case a more recent
  268. // commit has arrived since retrieving the latest height.
  269. if commit != nil && commit.Height == height {
  270. return commit
  271. }
  272. }
  273. return cs.blockStore.LoadBlockCommit(height)
  274. }
  275. // OnStart loads the latest state via the WAL, and starts the timeout and
  276. // receive routines.
  277. func (cs *State) OnStart() error {
  278. // We may set the WAL in testing before calling Start, so only OpenWAL if its
  279. // still the nilWAL.
  280. if _, ok := cs.wal.(nilWAL); ok {
  281. if err := cs.loadWalFile(); err != nil {
  282. return err
  283. }
  284. }
  285. // We may have lost some votes if the process crashed reload from consensus
  286. // log to catchup.
  287. if cs.doWALCatchup {
  288. repairAttempted := false
  289. LOOP:
  290. for {
  291. err := cs.catchupReplay(cs.Height)
  292. switch {
  293. case err == nil:
  294. break LOOP
  295. case !IsDataCorruptionError(err):
  296. cs.Logger.Error("error on catchup replay; proceeding to start state anyway", "err", err)
  297. break LOOP
  298. case repairAttempted:
  299. return err
  300. }
  301. cs.Logger.Error("the WAL file is corrupted; attempting repair", "err", err)
  302. // 1) prep work
  303. if err := cs.wal.Stop(); err != nil {
  304. return err
  305. }
  306. repairAttempted = true
  307. // 2) backup original WAL file
  308. corruptedFile := fmt.Sprintf("%s.CORRUPTED", cs.config.WalFile())
  309. if err := tmos.CopyFile(cs.config.WalFile(), corruptedFile); err != nil {
  310. return err
  311. }
  312. cs.Logger.Debug("backed up WAL file", "src", cs.config.WalFile(), "dst", corruptedFile)
  313. // 3) try to repair (WAL file will be overwritten!)
  314. if err := repairWalFile(corruptedFile, cs.config.WalFile()); err != nil {
  315. cs.Logger.Error("the WAL repair failed", "err", err)
  316. return err
  317. }
  318. cs.Logger.Info("successful WAL repair")
  319. // reload WAL file
  320. if err := cs.loadWalFile(); err != nil {
  321. return err
  322. }
  323. }
  324. }
  325. if err := cs.evsw.Start(); err != nil {
  326. return err
  327. }
  328. // we need the timeoutRoutine for replay so
  329. // we don't block on the tick chan.
  330. // NOTE: we will get a build up of garbage go routines
  331. // firing on the tockChan until the receiveRoutine is started
  332. // to deal with them (by that point, at most one will be valid)
  333. if err := cs.timeoutTicker.Start(); err != nil {
  334. return err
  335. }
  336. // Double Signing Risk Reduction
  337. if err := cs.checkDoubleSigningRisk(cs.Height); err != nil {
  338. return err
  339. }
  340. // now start the receiveRoutine
  341. go cs.receiveRoutine(0)
  342. // schedule the first round!
  343. // use GetRoundState so we don't race the receiveRoutine for access
  344. cs.scheduleRound0(cs.GetRoundState())
  345. return nil
  346. }
  347. // timeoutRoutine: receive requests for timeouts on tickChan and fire timeouts on tockChan
  348. // receiveRoutine: serializes processing of proposoals, block parts, votes; coordinates state transitions
  349. func (cs *State) startRoutines(maxSteps int) {
  350. err := cs.timeoutTicker.Start()
  351. if err != nil {
  352. cs.Logger.Error("failed to start timeout ticker", "err", err)
  353. return
  354. }
  355. go cs.receiveRoutine(maxSteps)
  356. }
  357. // loadWalFile loads WAL data from file. It overwrites cs.wal.
  358. func (cs *State) loadWalFile() error {
  359. wal, err := cs.OpenWAL(cs.config.WalFile())
  360. if err != nil {
  361. cs.Logger.Error("failed to load state WAL", "err", err)
  362. return err
  363. }
  364. cs.wal = wal
  365. return nil
  366. }
  367. // OnStop implements service.Service.
  368. func (cs *State) OnStop() {
  369. // If the node is committing a new block, wait until it is finished!
  370. if cs.GetRoundState().Step == cstypes.RoundStepCommit {
  371. select {
  372. case <-cs.onStopCh:
  373. case <-time.After(cs.config.TimeoutCommit):
  374. cs.Logger.Error("OnStop: timeout waiting for commit to finish", "time", cs.config.TimeoutCommit)
  375. }
  376. }
  377. close(cs.onStopCh)
  378. if err := cs.evsw.Stop(); err != nil {
  379. cs.Logger.Error("failed trying to stop eventSwitch", "error", err)
  380. }
  381. if err := cs.timeoutTicker.Stop(); err != nil {
  382. cs.Logger.Error("failed trying to stop timeoutTicket", "error", err)
  383. }
  384. // WAL is stopped in receiveRoutine.
  385. }
  386. // Wait waits for the the main routine to return.
  387. // NOTE: be sure to Stop() the event switch and drain
  388. // any event channels or this may deadlock
  389. func (cs *State) Wait() {
  390. <-cs.done
  391. }
  392. // OpenWAL opens a file to log all consensus messages and timeouts for
  393. // deterministic accountability.
  394. func (cs *State) OpenWAL(walFile string) (WAL, error) {
  395. wal, err := NewWAL(walFile)
  396. if err != nil {
  397. cs.Logger.Error("failed to open WAL", "file", walFile, "err", err)
  398. return nil, err
  399. }
  400. wal.SetLogger(cs.Logger.With("wal", walFile))
  401. if err := wal.Start(); err != nil {
  402. cs.Logger.Error("failed to start WAL", "err", err)
  403. return nil, err
  404. }
  405. return wal, nil
  406. }
  407. //------------------------------------------------------------
  408. // Public interface for passing messages into the consensus state, possibly causing a state transition.
  409. // If peerID == "", the msg is considered internal.
  410. // Messages are added to the appropriate queue (peer or internal).
  411. // If the queue is full, the function may block.
  412. // TODO: should these return anything or let callers just use events?
  413. // AddVote inputs a vote.
  414. func (cs *State) AddVote(vote *types.Vote, peerID types.NodeID) (added bool, err error) {
  415. if peerID == "" {
  416. cs.internalMsgQueue <- msgInfo{&VoteMessage{vote}, ""}
  417. } else {
  418. cs.peerMsgQueue <- msgInfo{&VoteMessage{vote}, peerID}
  419. }
  420. // TODO: wait for event?!
  421. return false, nil
  422. }
  423. // SetProposal inputs a proposal.
  424. func (cs *State) SetProposal(proposal *types.Proposal, peerID types.NodeID) error {
  425. if peerID == "" {
  426. cs.internalMsgQueue <- msgInfo{&ProposalMessage{proposal}, ""}
  427. } else {
  428. cs.peerMsgQueue <- msgInfo{&ProposalMessage{proposal}, peerID}
  429. }
  430. // TODO: wait for event?!
  431. return nil
  432. }
  433. // AddProposalBlockPart inputs a part of the proposal block.
  434. func (cs *State) AddProposalBlockPart(height int64, round int32, part *types.Part, peerID types.NodeID) error {
  435. if peerID == "" {
  436. cs.internalMsgQueue <- msgInfo{&BlockPartMessage{height, round, part}, ""}
  437. } else {
  438. cs.peerMsgQueue <- msgInfo{&BlockPartMessage{height, round, part}, peerID}
  439. }
  440. // TODO: wait for event?!
  441. return nil
  442. }
  443. // SetProposalAndBlock inputs the proposal and all block parts.
  444. func (cs *State) SetProposalAndBlock(
  445. proposal *types.Proposal,
  446. block *types.Block,
  447. parts *types.PartSet,
  448. peerID types.NodeID,
  449. ) error {
  450. if err := cs.SetProposal(proposal, peerID); err != nil {
  451. return err
  452. }
  453. for i := 0; i < int(parts.Total()); i++ {
  454. part := parts.GetPart(i)
  455. if err := cs.AddProposalBlockPart(proposal.Height, proposal.Round, part, peerID); err != nil {
  456. return err
  457. }
  458. }
  459. return nil
  460. }
  461. //------------------------------------------------------------
  462. // internal functions for managing the state
  463. func (cs *State) updateHeight(height int64) {
  464. cs.metrics.Height.Set(float64(height))
  465. cs.Height = height
  466. }
  467. func (cs *State) updateRoundStep(round int32, step cstypes.RoundStepType) {
  468. cs.Round = round
  469. cs.Step = step
  470. }
  471. // enterNewRound(height, 0) at cs.StartTime.
  472. func (cs *State) scheduleRound0(rs *cstypes.RoundState) {
  473. // cs.Logger.Info("scheduleRound0", "now", tmtime.Now(), "startTime", cs.StartTime)
  474. sleepDuration := rs.StartTime.Sub(tmtime.Now())
  475. cs.scheduleTimeout(sleepDuration, rs.Height, 0, cstypes.RoundStepNewHeight)
  476. }
  477. // Attempt to schedule a timeout (by sending timeoutInfo on the tickChan)
  478. func (cs *State) scheduleTimeout(duration time.Duration, height int64, round int32, step cstypes.RoundStepType) {
  479. cs.timeoutTicker.ScheduleTimeout(timeoutInfo{duration, height, round, step})
  480. }
  481. // send a msg into the receiveRoutine regarding our own proposal, block part, or vote
  482. func (cs *State) sendInternalMessage(mi msgInfo) {
  483. select {
  484. case cs.internalMsgQueue <- mi:
  485. default:
  486. // NOTE: using the go-routine means our votes can
  487. // be processed out of order.
  488. // TODO: use CList here for strict determinism and
  489. // attempt push to internalMsgQueue in receiveRoutine
  490. cs.Logger.Debug("internal msg queue is full; using a go-routine")
  491. go func() { cs.internalMsgQueue <- mi }()
  492. }
  493. }
  494. // Reconstruct LastCommit from SeenCommit, which we saved along with the block,
  495. // (which happens even before saving the state)
  496. func (cs *State) reconstructLastCommit(state sm.State) {
  497. commit := cs.blockStore.LoadSeenCommit()
  498. if commit == nil || commit.Height != state.LastBlockHeight {
  499. commit = cs.blockStore.LoadBlockCommit(state.LastBlockHeight)
  500. }
  501. if commit == nil {
  502. panic(fmt.Sprintf(
  503. "failed to reconstruct last commit; commit for height %v not found",
  504. state.LastBlockHeight,
  505. ))
  506. }
  507. lastPrecommits := types.CommitToVoteSet(state.ChainID, commit, state.LastValidators)
  508. if !lastPrecommits.HasTwoThirdsMajority() {
  509. panic("failed to reconstruct last commit; does not have +2/3 maj")
  510. }
  511. cs.LastCommit = lastPrecommits
  512. }
  513. // Updates State and increments height to match that of state.
  514. // The round becomes 0 and cs.Step becomes cstypes.RoundStepNewHeight.
  515. func (cs *State) updateToState(state sm.State) {
  516. if cs.CommitRound > -1 && 0 < cs.Height && cs.Height != state.LastBlockHeight {
  517. panic(fmt.Sprintf(
  518. "updateToState() expected state height of %v but found %v",
  519. cs.Height, state.LastBlockHeight,
  520. ))
  521. }
  522. if !cs.state.IsEmpty() {
  523. if cs.state.LastBlockHeight > 0 && cs.state.LastBlockHeight+1 != cs.Height {
  524. // This might happen when someone else is mutating cs.state.
  525. // Someone forgot to pass in state.Copy() somewhere?!
  526. panic(fmt.Sprintf(
  527. "inconsistent cs.state.LastBlockHeight+1 %v vs cs.Height %v",
  528. cs.state.LastBlockHeight+1, cs.Height,
  529. ))
  530. }
  531. if cs.state.LastBlockHeight > 0 && cs.Height == cs.state.InitialHeight {
  532. panic(fmt.Sprintf(
  533. "inconsistent cs.state.LastBlockHeight %v, expected 0 for initial height %v",
  534. cs.state.LastBlockHeight, cs.state.InitialHeight,
  535. ))
  536. }
  537. // If state isn't further out than cs.state, just ignore.
  538. // This happens when SwitchToConsensus() is called in the reactor.
  539. // We don't want to reset e.g. the Votes, but we still want to
  540. // signal the new round step, because other services (eg. txNotifier)
  541. // depend on having an up-to-date peer state!
  542. if state.LastBlockHeight <= cs.state.LastBlockHeight {
  543. cs.Logger.Debug(
  544. "ignoring updateToState()",
  545. "new_height", state.LastBlockHeight+1,
  546. "old_height", cs.state.LastBlockHeight+1,
  547. )
  548. cs.newStep()
  549. return
  550. }
  551. }
  552. // Reset fields based on state.
  553. validators := state.Validators
  554. switch {
  555. case state.LastBlockHeight == 0: // Very first commit should be empty.
  556. cs.LastCommit = (*types.VoteSet)(nil)
  557. case cs.CommitRound > -1 && cs.Votes != nil: // Otherwise, use cs.Votes
  558. if !cs.Votes.Precommits(cs.CommitRound).HasTwoThirdsMajority() {
  559. panic(fmt.Sprintf(
  560. "wanted to form a commit, but precommits (H/R: %d/%d) didn't have 2/3+: %v",
  561. state.LastBlockHeight, cs.CommitRound, cs.Votes.Precommits(cs.CommitRound),
  562. ))
  563. }
  564. cs.LastCommit = cs.Votes.Precommits(cs.CommitRound)
  565. case cs.LastCommit == nil:
  566. // NOTE: when Tendermint starts, it has no votes. reconstructLastCommit
  567. // must be called to reconstruct LastCommit from SeenCommit.
  568. panic(fmt.Sprintf(
  569. "last commit cannot be empty after initial block (H:%d)",
  570. state.LastBlockHeight+1,
  571. ))
  572. }
  573. // Next desired block height
  574. height := state.LastBlockHeight + 1
  575. if height == 1 {
  576. height = state.InitialHeight
  577. }
  578. // RoundState fields
  579. cs.updateHeight(height)
  580. cs.updateRoundStep(0, cstypes.RoundStepNewHeight)
  581. if cs.CommitTime.IsZero() {
  582. // "Now" makes it easier to sync up dev nodes.
  583. // We add timeoutCommit to allow transactions
  584. // to be gathered for the first block.
  585. // And alternative solution that relies on clocks:
  586. // cs.StartTime = state.LastBlockTime.Add(timeoutCommit)
  587. cs.StartTime = cs.config.Commit(tmtime.Now())
  588. } else {
  589. cs.StartTime = cs.config.Commit(cs.CommitTime)
  590. }
  591. cs.Validators = validators
  592. cs.Proposal = nil
  593. cs.ProposalBlock = nil
  594. cs.ProposalBlockParts = nil
  595. cs.LockedRound = -1
  596. cs.LockedBlock = nil
  597. cs.LockedBlockParts = nil
  598. cs.ValidRound = -1
  599. cs.ValidBlock = nil
  600. cs.ValidBlockParts = nil
  601. cs.Votes = cstypes.NewHeightVoteSet(state.ChainID, height, validators)
  602. cs.CommitRound = -1
  603. cs.LastValidators = state.LastValidators
  604. cs.TriggeredTimeoutPrecommit = false
  605. cs.state = state
  606. // Finally, broadcast RoundState
  607. cs.newStep()
  608. }
  609. func (cs *State) newStep() {
  610. rs := cs.RoundStateEvent()
  611. if err := cs.wal.Write(rs); err != nil {
  612. cs.Logger.Error("failed writing to WAL", "err", err)
  613. }
  614. cs.nSteps++
  615. // newStep is called by updateToState in NewState before the eventBus is set!
  616. if cs.eventBus != nil {
  617. if err := cs.eventBus.PublishEventNewRoundStep(rs); err != nil {
  618. cs.Logger.Error("failed publishing new round step", "err", err)
  619. }
  620. cs.evsw.FireEvent(types.EventNewRoundStepValue, &cs.RoundState)
  621. }
  622. }
  623. //-----------------------------------------
  624. // the main go routines
  625. // receiveRoutine handles messages which may cause state transitions.
  626. // it's argument (n) is the number of messages to process before exiting - use 0 to run forever
  627. // It keeps the RoundState and is the only thing that updates it.
  628. // Updates (state transitions) happen on timeouts, complete proposals, and 2/3 majorities.
  629. // State must be locked before any internal state is updated.
  630. func (cs *State) receiveRoutine(maxSteps int) {
  631. onExit := func(cs *State) {
  632. // NOTE: the internalMsgQueue may have signed messages from our
  633. // priv_val that haven't hit the WAL, but its ok because
  634. // priv_val tracks LastSig
  635. // close wal now that we're done writing to it
  636. if err := cs.wal.Stop(); err != nil {
  637. cs.Logger.Error("failed trying to stop WAL", "error", err)
  638. }
  639. cs.wal.Wait()
  640. close(cs.done)
  641. }
  642. defer func() {
  643. if r := recover(); r != nil {
  644. cs.Logger.Error("CONSENSUS FAILURE!!!", "err", r, "stack", string(debug.Stack()))
  645. // stop gracefully
  646. //
  647. // NOTE: We most probably shouldn't be running any further when there is
  648. // some unexpected panic. Some unknown error happened, and so we don't
  649. // know if that will result in the validator signing an invalid thing. It
  650. // might be worthwhile to explore a mechanism for manual resuming via
  651. // some console or secure RPC system, but for now, halting the chain upon
  652. // unexpected consensus bugs sounds like the better option.
  653. onExit(cs)
  654. }
  655. }()
  656. for {
  657. if maxSteps > 0 {
  658. if cs.nSteps >= maxSteps {
  659. cs.Logger.Debug("reached max steps; exiting receive routine")
  660. cs.nSteps = 0
  661. return
  662. }
  663. }
  664. rs := cs.RoundState
  665. var mi msgInfo
  666. select {
  667. case <-cs.txNotifier.TxsAvailable():
  668. cs.handleTxsAvailable()
  669. case mi = <-cs.peerMsgQueue:
  670. if err := cs.wal.Write(mi); err != nil {
  671. cs.Logger.Error("failed writing to WAL", "err", err)
  672. }
  673. // handles proposals, block parts, votes
  674. // may generate internal events (votes, complete proposals, 2/3 majorities)
  675. cs.handleMsg(mi)
  676. case mi = <-cs.internalMsgQueue:
  677. err := cs.wal.WriteSync(mi) // NOTE: fsync
  678. if err != nil {
  679. panic(fmt.Sprintf(
  680. "failed to write %v msg to consensus WAL due to %v; check your file system and restart the node",
  681. mi, err,
  682. ))
  683. }
  684. if _, ok := mi.Msg.(*VoteMessage); ok {
  685. // we actually want to simulate failing during
  686. // the previous WriteSync, but this isn't easy to do.
  687. // Equivalent would be to fail here and manually remove
  688. // some bytes from the end of the wal.
  689. fail.Fail() // XXX
  690. }
  691. // handles proposals, block parts, votes
  692. cs.handleMsg(mi)
  693. case ti := <-cs.timeoutTicker.Chan(): // tockChan:
  694. if err := cs.wal.Write(ti); err != nil {
  695. cs.Logger.Error("failed writing to WAL", "err", err)
  696. }
  697. // if the timeout is relevant to the rs
  698. // go to the next step
  699. cs.handleTimeout(ti, rs)
  700. case <-cs.Quit():
  701. onExit(cs)
  702. return
  703. }
  704. }
  705. }
  706. // state transitions on complete-proposal, 2/3-any, 2/3-one
  707. func (cs *State) handleMsg(mi msgInfo) {
  708. cs.mtx.Lock()
  709. defer cs.mtx.Unlock()
  710. var (
  711. added bool
  712. err error
  713. )
  714. msg, peerID := mi.Msg, mi.PeerID
  715. switch msg := msg.(type) {
  716. case *ProposalMessage:
  717. // will not cause transition.
  718. // once proposal is set, we can receive block parts
  719. err = cs.setProposal(msg.Proposal)
  720. case *BlockPartMessage:
  721. // if the proposal is complete, we'll enterPrevote or tryFinalizeCommit
  722. added, err = cs.addProposalBlockPart(msg, peerID)
  723. if added {
  724. cs.statsMsgQueue <- mi
  725. }
  726. if err != nil && msg.Round != cs.Round {
  727. cs.Logger.Debug(
  728. "received block part from wrong round",
  729. "height", cs.Height,
  730. "cs_round", cs.Round,
  731. "block_round", msg.Round,
  732. )
  733. err = nil
  734. }
  735. case *VoteMessage:
  736. // attempt to add the vote and dupeout the validator if its a duplicate signature
  737. // if the vote gives us a 2/3-any or 2/3-one, we transition
  738. added, err = cs.tryAddVote(msg.Vote, peerID)
  739. if added {
  740. cs.statsMsgQueue <- mi
  741. }
  742. // if err == ErrAddingVote {
  743. // TODO: punish peer
  744. // We probably don't want to stop the peer here. The vote does not
  745. // necessarily comes from a malicious peer but can be just broadcasted by
  746. // a typical peer.
  747. // https://github.com/tendermint/tendermint/issues/1281
  748. // }
  749. // NOTE: the vote is broadcast to peers by the reactor listening
  750. // for vote events
  751. // TODO: If rs.Height == vote.Height && rs.Round < vote.Round,
  752. // the peer is sending us CatchupCommit precommits.
  753. // We could make note of this and help filter in broadcastHasVoteMessage().
  754. default:
  755. cs.Logger.Error("unknown msg type", "type", fmt.Sprintf("%T", msg))
  756. return
  757. }
  758. if err != nil {
  759. cs.Logger.Error(
  760. "failed to process message",
  761. "height", cs.Height,
  762. "round", cs.Round,
  763. "peer", peerID,
  764. "err", err,
  765. "msg", msg,
  766. )
  767. }
  768. }
  769. func (cs *State) handleTimeout(ti timeoutInfo, rs cstypes.RoundState) {
  770. cs.Logger.Debug("received tock", "timeout", ti.Duration, "height", ti.Height, "round", ti.Round, "step", ti.Step)
  771. // timeouts must be for current height, round, step
  772. if ti.Height != rs.Height || ti.Round < rs.Round || (ti.Round == rs.Round && ti.Step < rs.Step) {
  773. cs.Logger.Debug("ignoring tock because we are ahead", "height", rs.Height, "round", rs.Round, "step", rs.Step)
  774. return
  775. }
  776. // the timeout will now cause a state transition
  777. cs.mtx.Lock()
  778. defer cs.mtx.Unlock()
  779. switch ti.Step {
  780. case cstypes.RoundStepNewHeight:
  781. // NewRound event fired from enterNewRound.
  782. // XXX: should we fire timeout here (for timeout commit)?
  783. cs.enterNewRound(ti.Height, 0)
  784. case cstypes.RoundStepNewRound:
  785. cs.enterPropose(ti.Height, 0)
  786. case cstypes.RoundStepPropose:
  787. if err := cs.eventBus.PublishEventTimeoutPropose(cs.RoundStateEvent()); err != nil {
  788. cs.Logger.Error("failed publishing timeout propose", "err", err)
  789. }
  790. cs.enterPrevote(ti.Height, ti.Round)
  791. case cstypes.RoundStepPrevoteWait:
  792. if err := cs.eventBus.PublishEventTimeoutWait(cs.RoundStateEvent()); err != nil {
  793. cs.Logger.Error("failed publishing timeout wait", "err", err)
  794. }
  795. cs.enterPrecommit(ti.Height, ti.Round)
  796. case cstypes.RoundStepPrecommitWait:
  797. if err := cs.eventBus.PublishEventTimeoutWait(cs.RoundStateEvent()); err != nil {
  798. cs.Logger.Error("failed publishing timeout wait", "err", err)
  799. }
  800. cs.enterPrecommit(ti.Height, ti.Round)
  801. cs.enterNewRound(ti.Height, ti.Round+1)
  802. default:
  803. panic(fmt.Sprintf("invalid timeout step: %v", ti.Step))
  804. }
  805. }
  806. func (cs *State) handleTxsAvailable() {
  807. cs.mtx.Lock()
  808. defer cs.mtx.Unlock()
  809. // We only need to do this for round 0.
  810. if cs.Round != 0 {
  811. return
  812. }
  813. switch cs.Step {
  814. case cstypes.RoundStepNewHeight: // timeoutCommit phase
  815. if cs.needProofBlock(cs.Height) {
  816. // enterPropose will be called by enterNewRound
  817. return
  818. }
  819. // +1ms to ensure RoundStepNewRound timeout always happens after RoundStepNewHeight
  820. timeoutCommit := cs.StartTime.Sub(tmtime.Now()) + 1*time.Millisecond
  821. cs.scheduleTimeout(timeoutCommit, cs.Height, 0, cstypes.RoundStepNewRound)
  822. case cstypes.RoundStepNewRound: // after timeoutCommit
  823. cs.enterPropose(cs.Height, 0)
  824. }
  825. }
  826. //-----------------------------------------------------------------------------
  827. // State functions
  828. // Used internally by handleTimeout and handleMsg to make state transitions
  829. // Enter: `timeoutNewHeight` by startTime (commitTime+timeoutCommit),
  830. // or, if SkipTimeoutCommit==true, after receiving all precommits from (height,round-1)
  831. // Enter: `timeoutPrecommits` after any +2/3 precommits from (height,round-1)
  832. // Enter: +2/3 precommits for nil at (height,round-1)
  833. // Enter: +2/3 prevotes any or +2/3 precommits for block or any from (height, round)
  834. // NOTE: cs.StartTime was already set for height.
  835. func (cs *State) enterNewRound(height int64, round int32) {
  836. logger := cs.Logger.With("height", height, "round", round)
  837. if cs.Height != height || round < cs.Round || (cs.Round == round && cs.Step != cstypes.RoundStepNewHeight) {
  838. logger.Debug(
  839. "entering new round with invalid args",
  840. "current", fmt.Sprintf("%v/%v/%v", cs.Height, cs.Round, cs.Step),
  841. )
  842. return
  843. }
  844. if now := tmtime.Now(); cs.StartTime.After(now) {
  845. logger.Debug("need to set a buffer and log message here for sanity", "start_time", cs.StartTime, "now", now)
  846. }
  847. logger.Debug("entering new round", "current", fmt.Sprintf("%v/%v/%v", cs.Height, cs.Round, cs.Step))
  848. // increment validators if necessary
  849. validators := cs.Validators
  850. if cs.Round < round {
  851. validators = validators.Copy()
  852. validators.IncrementProposerPriority(tmmath.SafeSubInt32(round, cs.Round))
  853. }
  854. // Setup new round
  855. // we don't fire newStep for this step,
  856. // but we fire an event, so update the round step first
  857. cs.updateRoundStep(round, cstypes.RoundStepNewRound)
  858. cs.Validators = validators
  859. if round == 0 {
  860. // We've already reset these upon new height,
  861. // and meanwhile we might have received a proposal
  862. // for round 0.
  863. } else {
  864. logger.Debug("resetting proposal info")
  865. cs.Proposal = nil
  866. cs.ProposalBlock = nil
  867. cs.ProposalBlockParts = nil
  868. }
  869. cs.Votes.SetRound(tmmath.SafeAddInt32(round, 1)) // also track next round (round+1) to allow round-skipping
  870. cs.TriggeredTimeoutPrecommit = false
  871. if err := cs.eventBus.PublishEventNewRound(cs.NewRoundEvent()); err != nil {
  872. cs.Logger.Error("failed publishing new round", "err", err)
  873. }
  874. cs.metrics.Rounds.Set(float64(round))
  875. // Wait for txs to be available in the mempool
  876. // before we enterPropose in round 0. If the last block changed the app hash,
  877. // we may need an empty "proof" block, and enterPropose immediately.
  878. waitForTxs := cs.config.WaitForTxs() && round == 0 && !cs.needProofBlock(height)
  879. if waitForTxs {
  880. if cs.config.CreateEmptyBlocksInterval > 0 {
  881. cs.scheduleTimeout(cs.config.CreateEmptyBlocksInterval, height, round,
  882. cstypes.RoundStepNewRound)
  883. }
  884. } else {
  885. cs.enterPropose(height, round)
  886. }
  887. }
  888. // needProofBlock returns true on the first height (so the genesis app hash is signed right away)
  889. // and where the last block (height-1) caused the app hash to change
  890. func (cs *State) needProofBlock(height int64) bool {
  891. if height == cs.state.InitialHeight {
  892. return true
  893. }
  894. lastBlockMeta := cs.blockStore.LoadBlockMeta(height - 1)
  895. if lastBlockMeta == nil {
  896. panic(fmt.Sprintf("needProofBlock: last block meta for height %d not found", height-1))
  897. }
  898. return !bytes.Equal(cs.state.AppHash, lastBlockMeta.Header.AppHash)
  899. }
  900. // Enter (CreateEmptyBlocks): from enterNewRound(height,round)
  901. // Enter (CreateEmptyBlocks, CreateEmptyBlocksInterval > 0 ):
  902. // after enterNewRound(height,round), after timeout of CreateEmptyBlocksInterval
  903. // Enter (!CreateEmptyBlocks) : after enterNewRound(height,round), once txs are in the mempool
  904. func (cs *State) enterPropose(height int64, round int32) {
  905. logger := cs.Logger.With("height", height, "round", round)
  906. if cs.Height != height || round < cs.Round || (cs.Round == round && cstypes.RoundStepPropose <= cs.Step) {
  907. logger.Debug(
  908. "entering propose step with invalid args",
  909. "current", fmt.Sprintf("%v/%v/%v", cs.Height, cs.Round, cs.Step),
  910. )
  911. return
  912. }
  913. logger.Debug("entering propose step", "current", fmt.Sprintf("%v/%v/%v", cs.Height, cs.Round, cs.Step))
  914. defer func() {
  915. // Done enterPropose:
  916. cs.updateRoundStep(round, cstypes.RoundStepPropose)
  917. cs.newStep()
  918. // If we have the whole proposal + POL, then goto Prevote now.
  919. // else, we'll enterPrevote when the rest of the proposal is received (in AddProposalBlockPart),
  920. // or else after timeoutPropose
  921. if cs.isProposalComplete() {
  922. cs.enterPrevote(height, cs.Round)
  923. }
  924. }()
  925. // If we don't get the proposal and all block parts quick enough, enterPrevote
  926. cs.scheduleTimeout(cs.config.Propose(round), height, round, cstypes.RoundStepPropose)
  927. // Nothing more to do if we're not a validator
  928. if cs.privValidator == nil {
  929. logger.Debug("node is not a validator")
  930. return
  931. }
  932. logger.Debug("node is a validator")
  933. if cs.privValidatorPubKey == nil {
  934. // If this node is a validator & proposer in the current round, it will
  935. // miss the opportunity to create a block.
  936. logger.Error("propose step; empty priv validator public key", "err", errPubKeyIsNotSet)
  937. return
  938. }
  939. address := cs.privValidatorPubKey.Address()
  940. // if not a validator, we're done
  941. if !cs.Validators.HasAddress(address) {
  942. logger.Debug("node is not a validator", "addr", address, "vals", cs.Validators)
  943. return
  944. }
  945. if cs.isProposer(address) {
  946. logger.Debug(
  947. "propose step; our turn to propose",
  948. "proposer", address,
  949. )
  950. cs.decideProposal(height, round)
  951. } else {
  952. logger.Debug(
  953. "propose step; not our turn to propose",
  954. "proposer", cs.Validators.GetProposer().Address,
  955. )
  956. }
  957. }
  958. func (cs *State) isProposer(address []byte) bool {
  959. return bytes.Equal(cs.Validators.GetProposer().Address, address)
  960. }
  961. func (cs *State) defaultDecideProposal(height int64, round int32) {
  962. var block *types.Block
  963. var blockParts *types.PartSet
  964. // Decide on block
  965. if cs.ValidBlock != nil {
  966. // If there is valid block, choose that.
  967. block, blockParts = cs.ValidBlock, cs.ValidBlockParts
  968. } else {
  969. // Create a new proposal block from state/txs from the mempool.
  970. block, blockParts = cs.createProposalBlock()
  971. if block == nil {
  972. return
  973. }
  974. }
  975. // Flush the WAL. Otherwise, we may not recompute the same proposal to sign,
  976. // and the privValidator will refuse to sign anything.
  977. if err := cs.wal.FlushAndSync(); err != nil {
  978. cs.Logger.Error("failed flushing WAL to disk")
  979. }
  980. // Make proposal
  981. propBlockID := types.BlockID{Hash: block.Hash(), PartSetHeader: blockParts.Header()}
  982. proposal := types.NewProposal(height, round, cs.ValidRound, propBlockID)
  983. p := proposal.ToProto()
  984. // wait the max amount we would wait for a proposal
  985. ctx, cancel := context.WithTimeout(context.TODO(), cs.config.TimeoutPropose)
  986. defer cancel()
  987. if err := cs.privValidator.SignProposal(ctx, cs.state.ChainID, p); err == nil {
  988. proposal.Signature = p.Signature
  989. // send proposal and block parts on internal msg queue
  990. cs.sendInternalMessage(msgInfo{&ProposalMessage{proposal}, ""})
  991. for i := 0; i < int(blockParts.Total()); i++ {
  992. part := blockParts.GetPart(i)
  993. cs.sendInternalMessage(msgInfo{&BlockPartMessage{cs.Height, cs.Round, part}, ""})
  994. }
  995. cs.Logger.Debug("signed proposal", "height", height, "round", round, "proposal", proposal)
  996. } else if !cs.replayMode {
  997. cs.Logger.Error("propose step; failed signing proposal", "height", height, "round", round, "err", err)
  998. }
  999. }
  1000. // Returns true if the proposal block is complete &&
  1001. // (if POLRound was proposed, we have +2/3 prevotes from there).
  1002. func (cs *State) isProposalComplete() bool {
  1003. if cs.Proposal == nil || cs.ProposalBlock == nil {
  1004. return false
  1005. }
  1006. // we have the proposal. if there's a POLRound,
  1007. // make sure we have the prevotes from it too
  1008. if cs.Proposal.POLRound < 0 {
  1009. return true
  1010. }
  1011. // if this is false the proposer is lying or we haven't received the POL yet
  1012. return cs.Votes.Prevotes(cs.Proposal.POLRound).HasTwoThirdsMajority()
  1013. }
  1014. // Create the next block to propose and return it. Returns nil block upon error.
  1015. //
  1016. // We really only need to return the parts, but the block is returned for
  1017. // convenience so we can log the proposal block.
  1018. //
  1019. // NOTE: keep it side-effect free for clarity.
  1020. // CONTRACT: cs.privValidator is not nil.
  1021. func (cs *State) createProposalBlock() (block *types.Block, blockParts *types.PartSet) {
  1022. if cs.privValidator == nil {
  1023. panic("entered createProposalBlock with privValidator being nil")
  1024. }
  1025. var commit *types.Commit
  1026. switch {
  1027. case cs.Height == cs.state.InitialHeight:
  1028. // We're creating a proposal for the first block.
  1029. // The commit is empty, but not nil.
  1030. commit = types.NewCommit(0, 0, types.BlockID{}, nil)
  1031. case cs.LastCommit.HasTwoThirdsMajority():
  1032. // Make the commit from LastCommit
  1033. commit = cs.LastCommit.MakeCommit()
  1034. default: // This shouldn't happen.
  1035. cs.Logger.Error("propose step; cannot propose anything without commit for the previous block")
  1036. return
  1037. }
  1038. if cs.privValidatorPubKey == nil {
  1039. // If this node is a validator & proposer in the current round, it will
  1040. // miss the opportunity to create a block.
  1041. cs.Logger.Error("propose step; empty priv validator public key", "err", errPubKeyIsNotSet)
  1042. return
  1043. }
  1044. proposerAddr := cs.privValidatorPubKey.Address()
  1045. return cs.blockExec.CreateProposalBlock(cs.Height, cs.state, commit, proposerAddr)
  1046. }
  1047. // Enter: `timeoutPropose` after entering Propose.
  1048. // Enter: proposal block and POL is ready.
  1049. // Prevote for LockedBlock if we're locked, or ProposalBlock if valid.
  1050. // Otherwise vote nil.
  1051. func (cs *State) enterPrevote(height int64, round int32) {
  1052. logger := cs.Logger.With("height", height, "round", round)
  1053. if cs.Height != height || round < cs.Round || (cs.Round == round && cstypes.RoundStepPrevote <= cs.Step) {
  1054. logger.Debug(
  1055. "entering prevote step with invalid args",
  1056. "current", fmt.Sprintf("%v/%v/%v", cs.Height, cs.Round, cs.Step),
  1057. )
  1058. return
  1059. }
  1060. defer func() {
  1061. // Done enterPrevote:
  1062. cs.updateRoundStep(round, cstypes.RoundStepPrevote)
  1063. cs.newStep()
  1064. }()
  1065. logger.Debug("entering prevote step", "current", fmt.Sprintf("%v/%v/%v", cs.Height, cs.Round, cs.Step))
  1066. // Sign and broadcast vote as necessary
  1067. cs.doPrevote(height, round)
  1068. // Once `addVote` hits any +2/3 prevotes, we will go to PrevoteWait
  1069. // (so we have more time to try and collect +2/3 prevotes for a single block)
  1070. }
  1071. func (cs *State) defaultDoPrevote(height int64, round int32) {
  1072. logger := cs.Logger.With("height", height, "round", round)
  1073. // If a block is locked, prevote that.
  1074. if cs.LockedBlock != nil {
  1075. logger.Debug("prevote step; already locked on a block; prevoting locked block")
  1076. cs.signAddVote(tmproto.PrevoteType, cs.LockedBlock.Hash(), cs.LockedBlockParts.Header())
  1077. return
  1078. }
  1079. // If ProposalBlock is nil, prevote nil.
  1080. if cs.ProposalBlock == nil {
  1081. logger.Debug("prevote step: ProposalBlock is nil")
  1082. cs.signAddVote(tmproto.PrevoteType, nil, types.PartSetHeader{})
  1083. return
  1084. }
  1085. // Validate proposal block
  1086. err := cs.blockExec.ValidateBlock(cs.state, cs.ProposalBlock)
  1087. if err != nil {
  1088. // ProposalBlock is invalid, prevote nil.
  1089. logger.Error("prevote step: ProposalBlock is invalid", "err", err)
  1090. cs.signAddVote(tmproto.PrevoteType, nil, types.PartSetHeader{})
  1091. return
  1092. }
  1093. // Prevote cs.ProposalBlock
  1094. // NOTE: the proposal signature is validated when it is received,
  1095. // and the proposal block parts are validated as they are received (against the merkle hash in the proposal)
  1096. logger.Debug("prevote step: ProposalBlock is valid")
  1097. cs.signAddVote(tmproto.PrevoteType, cs.ProposalBlock.Hash(), cs.ProposalBlockParts.Header())
  1098. }
  1099. // Enter: any +2/3 prevotes at next round.
  1100. func (cs *State) enterPrevoteWait(height int64, round int32) {
  1101. logger := cs.Logger.With("height", height, "round", round)
  1102. if cs.Height != height || round < cs.Round || (cs.Round == round && cstypes.RoundStepPrevoteWait <= cs.Step) {
  1103. logger.Debug(
  1104. "entering prevote wait step with invalid args",
  1105. "current", fmt.Sprintf("%v/%v/%v", cs.Height, cs.Round, cs.Step),
  1106. )
  1107. return
  1108. }
  1109. if !cs.Votes.Prevotes(round).HasTwoThirdsAny() {
  1110. panic(fmt.Sprintf(
  1111. "entering prevote wait step (%v/%v), but prevotes does not have any +2/3 votes",
  1112. height, round,
  1113. ))
  1114. }
  1115. logger.Debug("entering prevote wait step", "current", fmt.Sprintf("%v/%v/%v", cs.Height, cs.Round, cs.Step))
  1116. defer func() {
  1117. // Done enterPrevoteWait:
  1118. cs.updateRoundStep(round, cstypes.RoundStepPrevoteWait)
  1119. cs.newStep()
  1120. }()
  1121. // Wait for some more prevotes; enterPrecommit
  1122. cs.scheduleTimeout(cs.config.Prevote(round), height, round, cstypes.RoundStepPrevoteWait)
  1123. }
  1124. // Enter: `timeoutPrevote` after any +2/3 prevotes.
  1125. // Enter: `timeoutPrecommit` after any +2/3 precommits.
  1126. // Enter: +2/3 precomits for block or nil.
  1127. // Lock & precommit the ProposalBlock if we have enough prevotes for it (a POL in this round)
  1128. // else, unlock an existing lock and precommit nil if +2/3 of prevotes were nil,
  1129. // else, precommit nil otherwise.
  1130. func (cs *State) enterPrecommit(height int64, round int32) {
  1131. logger := cs.Logger.With("height", height, "round", round)
  1132. if cs.Height != height || round < cs.Round || (cs.Round == round && cstypes.RoundStepPrecommit <= cs.Step) {
  1133. logger.Debug(
  1134. "entering precommit step with invalid args",
  1135. "current", fmt.Sprintf("%v/%v/%v", cs.Height, cs.Round, cs.Step),
  1136. )
  1137. return
  1138. }
  1139. logger.Debug("entering precommit step", "current", fmt.Sprintf("%v/%v/%v", cs.Height, cs.Round, cs.Step))
  1140. defer func() {
  1141. // Done enterPrecommit:
  1142. cs.updateRoundStep(round, cstypes.RoundStepPrecommit)
  1143. cs.newStep()
  1144. }()
  1145. // check for a polka
  1146. blockID, ok := cs.Votes.Prevotes(round).TwoThirdsMajority()
  1147. // If we don't have a polka, we must precommit nil.
  1148. if !ok {
  1149. if cs.LockedBlock != nil {
  1150. logger.Debug("precommit step; no +2/3 prevotes during enterPrecommit while we are locked; precommitting nil")
  1151. } else {
  1152. logger.Debug("precommit step; no +2/3 prevotes during enterPrecommit; precommitting nil")
  1153. }
  1154. cs.signAddVote(tmproto.PrecommitType, nil, types.PartSetHeader{})
  1155. return
  1156. }
  1157. // At this point +2/3 prevoted for a particular block or nil.
  1158. if err := cs.eventBus.PublishEventPolka(cs.RoundStateEvent()); err != nil {
  1159. logger.Error("failed publishing polka", "err", err)
  1160. }
  1161. // the latest POLRound should be this round.
  1162. polRound, _ := cs.Votes.POLInfo()
  1163. if polRound < round {
  1164. panic(fmt.Sprintf("this POLRound should be %v but got %v", round, polRound))
  1165. }
  1166. // +2/3 prevoted nil. Unlock and precommit nil.
  1167. if len(blockID.Hash) == 0 {
  1168. if cs.LockedBlock == nil {
  1169. logger.Debug("precommit step; +2/3 prevoted for nil")
  1170. } else {
  1171. logger.Debug("precommit step; +2/3 prevoted for nil; unlocking")
  1172. cs.LockedRound = -1
  1173. cs.LockedBlock = nil
  1174. cs.LockedBlockParts = nil
  1175. if err := cs.eventBus.PublishEventUnlock(cs.RoundStateEvent()); err != nil {
  1176. logger.Error("failed publishing event unlock", "err", err)
  1177. }
  1178. }
  1179. cs.signAddVote(tmproto.PrecommitType, nil, types.PartSetHeader{})
  1180. return
  1181. }
  1182. // At this point, +2/3 prevoted for a particular block.
  1183. // If we're already locked on that block, precommit it, and update the LockedRound
  1184. if cs.LockedBlock.HashesTo(blockID.Hash) {
  1185. logger.Debug("precommit step; +2/3 prevoted locked block; relocking")
  1186. cs.LockedRound = round
  1187. if err := cs.eventBus.PublishEventRelock(cs.RoundStateEvent()); err != nil {
  1188. logger.Error("failed publishing event relock", "err", err)
  1189. }
  1190. cs.signAddVote(tmproto.PrecommitType, blockID.Hash, blockID.PartSetHeader)
  1191. return
  1192. }
  1193. // If +2/3 prevoted for proposal block, stage and precommit it
  1194. if cs.ProposalBlock.HashesTo(blockID.Hash) {
  1195. logger.Debug("precommit step; +2/3 prevoted proposal block; locking", "hash", blockID.Hash)
  1196. // Validate the block.
  1197. if err := cs.blockExec.ValidateBlock(cs.state, cs.ProposalBlock); err != nil {
  1198. panic(fmt.Sprintf("precommit step; +2/3 prevoted for an invalid block: %v", err))
  1199. }
  1200. cs.LockedRound = round
  1201. cs.LockedBlock = cs.ProposalBlock
  1202. cs.LockedBlockParts = cs.ProposalBlockParts
  1203. if err := cs.eventBus.PublishEventLock(cs.RoundStateEvent()); err != nil {
  1204. logger.Error("failed publishing event lock", "err", err)
  1205. }
  1206. cs.signAddVote(tmproto.PrecommitType, blockID.Hash, blockID.PartSetHeader)
  1207. return
  1208. }
  1209. // There was a polka in this round for a block we don't have.
  1210. // Fetch that block, unlock, and precommit nil.
  1211. // The +2/3 prevotes for this round is the POL for our unlock.
  1212. logger.Debug("precommit step; +2/3 prevotes for a block we do not have; voting nil", "block_id", blockID)
  1213. cs.LockedRound = -1
  1214. cs.LockedBlock = nil
  1215. cs.LockedBlockParts = nil
  1216. if !cs.ProposalBlockParts.HasHeader(blockID.PartSetHeader) {
  1217. cs.ProposalBlock = nil
  1218. cs.ProposalBlockParts = types.NewPartSetFromHeader(blockID.PartSetHeader)
  1219. }
  1220. if err := cs.eventBus.PublishEventUnlock(cs.RoundStateEvent()); err != nil {
  1221. logger.Error("failed publishing event unlock", "err", err)
  1222. }
  1223. cs.signAddVote(tmproto.PrecommitType, nil, types.PartSetHeader{})
  1224. }
  1225. // Enter: any +2/3 precommits for next round.
  1226. func (cs *State) enterPrecommitWait(height int64, round int32) {
  1227. logger := cs.Logger.With("height", height, "round", round)
  1228. if cs.Height != height || round < cs.Round || (cs.Round == round && cs.TriggeredTimeoutPrecommit) {
  1229. logger.Debug(
  1230. "entering precommit wait step with invalid args",
  1231. "triggered_timeout", cs.TriggeredTimeoutPrecommit,
  1232. "current", fmt.Sprintf("%v/%v", cs.Height, cs.Round),
  1233. )
  1234. return
  1235. }
  1236. if !cs.Votes.Precommits(round).HasTwoThirdsAny() {
  1237. panic(fmt.Sprintf(
  1238. "entering precommit wait step (%v/%v), but precommits does not have any +2/3 votes",
  1239. height, round,
  1240. ))
  1241. }
  1242. logger.Debug("entering precommit wait step", "current", fmt.Sprintf("%v/%v/%v", cs.Height, cs.Round, cs.Step))
  1243. defer func() {
  1244. // Done enterPrecommitWait:
  1245. cs.TriggeredTimeoutPrecommit = true
  1246. cs.newStep()
  1247. }()
  1248. // wait for some more precommits; enterNewRound
  1249. cs.scheduleTimeout(cs.config.Precommit(round), height, round, cstypes.RoundStepPrecommitWait)
  1250. }
  1251. // Enter: +2/3 precommits for block
  1252. func (cs *State) enterCommit(height int64, commitRound int32) {
  1253. logger := cs.Logger.With("height", height, "commit_round", commitRound)
  1254. if cs.Height != height || cstypes.RoundStepCommit <= cs.Step {
  1255. logger.Debug(
  1256. "entering commit step with invalid args",
  1257. "current", fmt.Sprintf("%v/%v/%v", cs.Height, cs.Round, cs.Step),
  1258. )
  1259. return
  1260. }
  1261. logger.Debug("entering commit step", "current", fmt.Sprintf("%v/%v/%v", cs.Height, cs.Round, cs.Step))
  1262. defer func() {
  1263. // Done enterCommit:
  1264. // keep cs.Round the same, commitRound points to the right Precommits set.
  1265. cs.updateRoundStep(cs.Round, cstypes.RoundStepCommit)
  1266. cs.CommitRound = commitRound
  1267. cs.CommitTime = tmtime.Now()
  1268. cs.newStep()
  1269. // Maybe finalize immediately.
  1270. cs.tryFinalizeCommit(height)
  1271. }()
  1272. blockID, ok := cs.Votes.Precommits(commitRound).TwoThirdsMajority()
  1273. if !ok {
  1274. panic("RunActionCommit() expects +2/3 precommits")
  1275. }
  1276. // The Locked* fields no longer matter.
  1277. // Move them over to ProposalBlock if they match the commit hash,
  1278. // otherwise they'll be cleared in updateToState.
  1279. if cs.LockedBlock.HashesTo(blockID.Hash) {
  1280. logger.Debug("commit is for a locked block; set ProposalBlock=LockedBlock", "block_hash", blockID.Hash)
  1281. cs.ProposalBlock = cs.LockedBlock
  1282. cs.ProposalBlockParts = cs.LockedBlockParts
  1283. }
  1284. // If we don't have the block being committed, set up to get it.
  1285. if !cs.ProposalBlock.HashesTo(blockID.Hash) {
  1286. if !cs.ProposalBlockParts.HasHeader(blockID.PartSetHeader) {
  1287. logger.Info(
  1288. "commit is for a block we do not know about; set ProposalBlock=nil",
  1289. "proposal", cs.ProposalBlock.Hash(),
  1290. "commit", blockID.Hash,
  1291. )
  1292. // We're getting the wrong block.
  1293. // Set up ProposalBlockParts and keep waiting.
  1294. cs.ProposalBlock = nil
  1295. cs.ProposalBlockParts = types.NewPartSetFromHeader(blockID.PartSetHeader)
  1296. if err := cs.eventBus.PublishEventValidBlock(cs.RoundStateEvent()); err != nil {
  1297. logger.Error("failed publishing valid block", "err", err)
  1298. }
  1299. cs.evsw.FireEvent(types.EventValidBlockValue, &cs.RoundState)
  1300. }
  1301. }
  1302. }
  1303. // If we have the block AND +2/3 commits for it, finalize.
  1304. func (cs *State) tryFinalizeCommit(height int64) {
  1305. logger := cs.Logger.With("height", height)
  1306. if cs.Height != height {
  1307. panic(fmt.Sprintf("tryFinalizeCommit() cs.Height: %v vs height: %v", cs.Height, height))
  1308. }
  1309. blockID, ok := cs.Votes.Precommits(cs.CommitRound).TwoThirdsMajority()
  1310. if !ok || len(blockID.Hash) == 0 {
  1311. logger.Error("failed attempt to finalize commit; there was no +2/3 majority or +2/3 was for nil")
  1312. return
  1313. }
  1314. if !cs.ProposalBlock.HashesTo(blockID.Hash) {
  1315. // TODO: this happens every time if we're not a validator (ugly logs)
  1316. // TODO: ^^ wait, why does it matter that we're a validator?
  1317. logger.Debug(
  1318. "failed attempt to finalize commit; we do not have the commit block",
  1319. "proposal_block", cs.ProposalBlock.Hash(),
  1320. "commit_block", blockID.Hash,
  1321. )
  1322. return
  1323. }
  1324. cs.finalizeCommit(height)
  1325. }
  1326. // Increment height and goto cstypes.RoundStepNewHeight
  1327. func (cs *State) finalizeCommit(height int64) {
  1328. logger := cs.Logger.With("height", height)
  1329. if cs.Height != height || cs.Step != cstypes.RoundStepCommit {
  1330. logger.Debug(
  1331. "entering finalize commit step",
  1332. "current", fmt.Sprintf("%v/%v/%v", cs.Height, cs.Round, cs.Step),
  1333. )
  1334. return
  1335. }
  1336. blockID, ok := cs.Votes.Precommits(cs.CommitRound).TwoThirdsMajority()
  1337. block, blockParts := cs.ProposalBlock, cs.ProposalBlockParts
  1338. if !ok {
  1339. panic("cannot finalize commit; commit does not have 2/3 majority")
  1340. }
  1341. if !blockParts.HasHeader(blockID.PartSetHeader) {
  1342. panic("expected ProposalBlockParts header to be commit header")
  1343. }
  1344. if !block.HashesTo(blockID.Hash) {
  1345. panic("cannot finalize commit; proposal block does not hash to commit hash")
  1346. }
  1347. if err := cs.blockExec.ValidateBlock(cs.state, block); err != nil {
  1348. panic(fmt.Errorf("+2/3 committed an invalid block: %w", err))
  1349. }
  1350. logger.Info(
  1351. "finalizing commit of block",
  1352. "hash", block.Hash(),
  1353. "root", block.AppHash,
  1354. "num_txs", len(block.Txs),
  1355. )
  1356. logger.Debug(fmt.Sprintf("%v", block))
  1357. fail.Fail() // XXX
  1358. // Save to blockStore.
  1359. if cs.blockStore.Height() < block.Height {
  1360. // NOTE: the seenCommit is local justification to commit this block,
  1361. // but may differ from the LastCommit included in the next block
  1362. precommits := cs.Votes.Precommits(cs.CommitRound)
  1363. seenCommit := precommits.MakeCommit()
  1364. cs.blockStore.SaveBlock(block, blockParts, seenCommit)
  1365. } else {
  1366. // Happens during replay if we already saved the block but didn't commit
  1367. logger.Debug("calling finalizeCommit on already stored block", "height", block.Height)
  1368. }
  1369. fail.Fail() // XXX
  1370. // Write EndHeightMessage{} for this height, implying that the blockstore
  1371. // has saved the block.
  1372. //
  1373. // If we crash before writing this EndHeightMessage{}, we will recover by
  1374. // running ApplyBlock during the ABCI handshake when we restart. If we
  1375. // didn't save the block to the blockstore before writing
  1376. // EndHeightMessage{}, we'd have to change WAL replay -- currently it
  1377. // complains about replaying for heights where an #ENDHEIGHT entry already
  1378. // exists.
  1379. //
  1380. // Either way, the State should not be resumed until we
  1381. // successfully call ApplyBlock (ie. later here, or in Handshake after
  1382. // restart).
  1383. endMsg := EndHeightMessage{height}
  1384. if err := cs.wal.WriteSync(endMsg); err != nil { // NOTE: fsync
  1385. panic(fmt.Sprintf(
  1386. "failed to write %v msg to consensus WAL due to %v; check your file system and restart the node",
  1387. endMsg, err,
  1388. ))
  1389. }
  1390. fail.Fail() // XXX
  1391. // Create a copy of the state for staging and an event cache for txs.
  1392. stateCopy := cs.state.Copy()
  1393. // Execute and commit the block, update and save the state, and update the mempool.
  1394. // NOTE The block.AppHash wont reflect these txs until the next block.
  1395. stateCopy, err := cs.blockExec.ApplyBlock(
  1396. stateCopy,
  1397. types.BlockID{
  1398. Hash: block.Hash(),
  1399. PartSetHeader: blockParts.Header(),
  1400. },
  1401. block,
  1402. )
  1403. if err != nil {
  1404. logger.Error("failed to apply block", "err", err)
  1405. return
  1406. }
  1407. fail.Fail() // XXX
  1408. // must be called before we update state
  1409. cs.RecordMetrics(height, block)
  1410. // NewHeightStep!
  1411. cs.updateToState(stateCopy)
  1412. fail.Fail() // XXX
  1413. // Private validator might have changed it's key pair => refetch pubkey.
  1414. if err := cs.updatePrivValidatorPubKey(); err != nil {
  1415. logger.Error("failed to get private validator pubkey", "err", err)
  1416. }
  1417. // cs.StartTime is already set.
  1418. // Schedule Round0 to start soon.
  1419. cs.scheduleRound0(&cs.RoundState)
  1420. // By here,
  1421. // * cs.Height has been increment to height+1
  1422. // * cs.Step is now cstypes.RoundStepNewHeight
  1423. // * cs.StartTime is set to when we will start round0.
  1424. }
  1425. func (cs *State) RecordMetrics(height int64, block *types.Block) {
  1426. cs.metrics.Validators.Set(float64(cs.Validators.Size()))
  1427. cs.metrics.ValidatorsPower.Set(float64(cs.Validators.TotalVotingPower()))
  1428. var (
  1429. missingValidators int
  1430. missingValidatorsPower int64
  1431. )
  1432. // height=0 -> MissingValidators and MissingValidatorsPower are both 0.
  1433. // Remember that the first LastCommit is intentionally empty, so it's not
  1434. // fair to increment missing validators number.
  1435. if height > cs.state.InitialHeight {
  1436. // Sanity check that commit size matches validator set size - only applies
  1437. // after first block.
  1438. var (
  1439. commitSize = block.LastCommit.Size()
  1440. valSetLen = len(cs.LastValidators.Validators)
  1441. address types.Address
  1442. )
  1443. if commitSize != valSetLen {
  1444. cs.Logger.Error(fmt.Sprintf("commit size (%d) doesn't match valset length (%d) at height %d\n\n%v\n\n%v",
  1445. commitSize, valSetLen, block.Height, block.LastCommit.Signatures, cs.LastValidators.Validators))
  1446. return
  1447. }
  1448. if cs.privValidator != nil {
  1449. if cs.privValidatorPubKey == nil {
  1450. // Metrics won't be updated, but it's not critical.
  1451. cs.Logger.Error(fmt.Sprintf("recordMetrics: %v", errPubKeyIsNotSet))
  1452. } else {
  1453. address = cs.privValidatorPubKey.Address()
  1454. }
  1455. }
  1456. for i, val := range cs.LastValidators.Validators {
  1457. commitSig := block.LastCommit.Signatures[i]
  1458. if commitSig.Absent() {
  1459. missingValidators++
  1460. missingValidatorsPower += val.VotingPower
  1461. }
  1462. if bytes.Equal(val.Address, address) {
  1463. label := []string{
  1464. "validator_address", val.Address.String(),
  1465. }
  1466. cs.metrics.ValidatorPower.With(label...).Set(float64(val.VotingPower))
  1467. if commitSig.ForBlock() {
  1468. cs.metrics.ValidatorLastSignedHeight.With(label...).Set(float64(height))
  1469. } else {
  1470. cs.metrics.ValidatorMissedBlocks.With(label...).Add(float64(1))
  1471. }
  1472. }
  1473. }
  1474. }
  1475. cs.metrics.MissingValidators.Set(float64(missingValidators))
  1476. cs.metrics.MissingValidatorsPower.Set(float64(missingValidatorsPower))
  1477. // NOTE: byzantine validators power and count is only for consensus evidence i.e. duplicate vote
  1478. var (
  1479. byzantineValidatorsPower int64
  1480. byzantineValidatorsCount int64
  1481. )
  1482. for _, ev := range block.Evidence.Evidence {
  1483. if dve, ok := ev.(*types.DuplicateVoteEvidence); ok {
  1484. if _, val := cs.Validators.GetByAddress(dve.VoteA.ValidatorAddress); val != nil {
  1485. byzantineValidatorsCount++
  1486. byzantineValidatorsPower += val.VotingPower
  1487. }
  1488. }
  1489. }
  1490. cs.metrics.ByzantineValidators.Set(float64(byzantineValidatorsCount))
  1491. cs.metrics.ByzantineValidatorsPower.Set(float64(byzantineValidatorsPower))
  1492. if height > 1 {
  1493. lastBlockMeta := cs.blockStore.LoadBlockMeta(height - 1)
  1494. if lastBlockMeta != nil {
  1495. cs.metrics.BlockIntervalSeconds.Observe(
  1496. block.Time.Sub(lastBlockMeta.Header.Time).Seconds(),
  1497. )
  1498. }
  1499. }
  1500. cs.metrics.NumTxs.Set(float64(len(block.Data.Txs)))
  1501. cs.metrics.TotalTxs.Add(float64(len(block.Data.Txs)))
  1502. cs.metrics.BlockSizeBytes.Observe(float64(block.Size()))
  1503. cs.metrics.CommittedHeight.Set(float64(block.Height))
  1504. }
  1505. //-----------------------------------------------------------------------------
  1506. func (cs *State) defaultSetProposal(proposal *types.Proposal) error {
  1507. // Already have one
  1508. // TODO: possibly catch double proposals
  1509. if cs.Proposal != nil {
  1510. return nil
  1511. }
  1512. // Does not apply
  1513. if proposal.Height != cs.Height || proposal.Round != cs.Round {
  1514. return nil
  1515. }
  1516. // Verify POLRound, which must be -1 or in range [0, proposal.Round).
  1517. if proposal.POLRound < -1 ||
  1518. (proposal.POLRound >= 0 && proposal.POLRound >= proposal.Round) {
  1519. return ErrInvalidProposalPOLRound
  1520. }
  1521. p := proposal.ToProto()
  1522. // Verify signature
  1523. if !cs.Validators.GetProposer().PubKey.VerifySignature(
  1524. types.ProposalSignBytes(cs.state.ChainID, p), proposal.Signature,
  1525. ) {
  1526. return ErrInvalidProposalSignature
  1527. }
  1528. proposal.Signature = p.Signature
  1529. cs.Proposal = proposal
  1530. // We don't update cs.ProposalBlockParts if it is already set.
  1531. // This happens if we're already in cstypes.RoundStepCommit or if there is a valid block in the current round.
  1532. // TODO: We can check if Proposal is for a different block as this is a sign of misbehavior!
  1533. if cs.ProposalBlockParts == nil {
  1534. cs.ProposalBlockParts = types.NewPartSetFromHeader(proposal.BlockID.PartSetHeader)
  1535. }
  1536. cs.Logger.Info("received proposal", "proposal", proposal)
  1537. return nil
  1538. }
  1539. // NOTE: block is not necessarily valid.
  1540. // Asynchronously triggers either enterPrevote (before we timeout of propose) or tryFinalizeCommit,
  1541. // once we have the full block.
  1542. func (cs *State) addProposalBlockPart(msg *BlockPartMessage, peerID types.NodeID) (added bool, err error) {
  1543. height, round, part := msg.Height, msg.Round, msg.Part
  1544. // Blocks might be reused, so round mismatch is OK
  1545. if cs.Height != height {
  1546. cs.Logger.Debug("received block part from wrong height", "height", height, "round", round)
  1547. return false, nil
  1548. }
  1549. // We're not expecting a block part.
  1550. if cs.ProposalBlockParts == nil {
  1551. // NOTE: this can happen when we've gone to a higher round and
  1552. // then receive parts from the previous round - not necessarily a bad peer.
  1553. cs.Logger.Debug(
  1554. "received a block part when we are not expecting any",
  1555. "height", height,
  1556. "round", round,
  1557. "index", part.Index,
  1558. "peer", peerID,
  1559. )
  1560. return false, nil
  1561. }
  1562. added, err = cs.ProposalBlockParts.AddPart(part)
  1563. if err != nil {
  1564. return added, err
  1565. }
  1566. if cs.ProposalBlockParts.ByteSize() > cs.state.ConsensusParams.Block.MaxBytes {
  1567. return added, fmt.Errorf("total size of proposal block parts exceeds maximum block bytes (%d > %d)",
  1568. cs.ProposalBlockParts.ByteSize(), cs.state.ConsensusParams.Block.MaxBytes,
  1569. )
  1570. }
  1571. if added && cs.ProposalBlockParts.IsComplete() {
  1572. bz, err := ioutil.ReadAll(cs.ProposalBlockParts.GetReader())
  1573. if err != nil {
  1574. return added, err
  1575. }
  1576. var pbb = new(tmproto.Block)
  1577. err = proto.Unmarshal(bz, pbb)
  1578. if err != nil {
  1579. return added, err
  1580. }
  1581. block, err := types.BlockFromProto(pbb)
  1582. if err != nil {
  1583. return added, err
  1584. }
  1585. cs.ProposalBlock = block
  1586. // NOTE: it's possible to receive complete proposal blocks for future rounds without having the proposal
  1587. cs.Logger.Info("received complete proposal block", "height", cs.ProposalBlock.Height, "hash", cs.ProposalBlock.Hash())
  1588. if err := cs.eventBus.PublishEventCompleteProposal(cs.CompleteProposalEvent()); err != nil {
  1589. cs.Logger.Error("failed publishing event complete proposal", "err", err)
  1590. }
  1591. // Update Valid* if we can.
  1592. prevotes := cs.Votes.Prevotes(cs.Round)
  1593. blockID, hasTwoThirds := prevotes.TwoThirdsMajority()
  1594. if hasTwoThirds && !blockID.IsZero() && (cs.ValidRound < cs.Round) {
  1595. if cs.ProposalBlock.HashesTo(blockID.Hash) {
  1596. cs.Logger.Debug(
  1597. "updating valid block to new proposal block",
  1598. "valid_round", cs.Round,
  1599. "valid_block_hash", cs.ProposalBlock.Hash(),
  1600. )
  1601. cs.ValidRound = cs.Round
  1602. cs.ValidBlock = cs.ProposalBlock
  1603. cs.ValidBlockParts = cs.ProposalBlockParts
  1604. }
  1605. // TODO: In case there is +2/3 majority in Prevotes set for some
  1606. // block and cs.ProposalBlock contains different block, either
  1607. // proposer is faulty or voting power of faulty processes is more
  1608. // than 1/3. We should trigger in the future accountability
  1609. // procedure at this point.
  1610. }
  1611. if cs.Step <= cstypes.RoundStepPropose && cs.isProposalComplete() {
  1612. // Move onto the next step
  1613. cs.enterPrevote(height, cs.Round)
  1614. if hasTwoThirds { // this is optimisation as this will be triggered when prevote is added
  1615. cs.enterPrecommit(height, cs.Round)
  1616. }
  1617. } else if cs.Step == cstypes.RoundStepCommit {
  1618. // If we're waiting on the proposal block...
  1619. cs.tryFinalizeCommit(height)
  1620. }
  1621. return added, nil
  1622. }
  1623. return added, nil
  1624. }
  1625. // Attempt to add the vote. if its a duplicate signature, dupeout the validator
  1626. func (cs *State) tryAddVote(vote *types.Vote, peerID types.NodeID) (bool, error) {
  1627. added, err := cs.addVote(vote, peerID)
  1628. if err != nil {
  1629. // If the vote height is off, we'll just ignore it,
  1630. // But if it's a conflicting sig, add it to the cs.evpool.
  1631. // If it's otherwise invalid, punish peer.
  1632. // nolint: gocritic
  1633. if voteErr, ok := err.(*types.ErrVoteConflictingVotes); ok {
  1634. if cs.privValidatorPubKey == nil {
  1635. return false, errPubKeyIsNotSet
  1636. }
  1637. if bytes.Equal(vote.ValidatorAddress, cs.privValidatorPubKey.Address()) {
  1638. cs.Logger.Error(
  1639. "found conflicting vote from ourselves; did you unsafe_reset a validator?",
  1640. "height", vote.Height,
  1641. "round", vote.Round,
  1642. "type", vote.Type,
  1643. )
  1644. return added, err
  1645. }
  1646. // report conflicting votes to the evidence pool
  1647. cs.evpool.ReportConflictingVotes(voteErr.VoteA, voteErr.VoteB)
  1648. cs.Logger.Debug(
  1649. "found and sent conflicting votes to the evidence pool",
  1650. "vote_a", voteErr.VoteA,
  1651. "vote_b", voteErr.VoteB,
  1652. )
  1653. return added, err
  1654. } else if errors.Is(err, types.ErrVoteNonDeterministicSignature) {
  1655. cs.Logger.Debug("vote has non-deterministic signature", "err", err)
  1656. } else {
  1657. // Either
  1658. // 1) bad peer OR
  1659. // 2) not a bad peer? this can also err sometimes with "Unexpected step" OR
  1660. // 3) tmkms use with multiple validators connecting to a single tmkms instance
  1661. // (https://github.com/tendermint/tendermint/issues/3839).
  1662. cs.Logger.Info("failed attempting to add vote", "err", err)
  1663. return added, ErrAddingVote
  1664. }
  1665. }
  1666. return added, nil
  1667. }
  1668. func (cs *State) addVote(vote *types.Vote, peerID types.NodeID) (added bool, err error) {
  1669. cs.Logger.Debug(
  1670. "adding vote",
  1671. "vote_height", vote.Height,
  1672. "vote_type", vote.Type,
  1673. "val_index", vote.ValidatorIndex,
  1674. "cs_height", cs.Height,
  1675. )
  1676. // A precommit for the previous height?
  1677. // These come in while we wait timeoutCommit
  1678. if vote.Height+1 == cs.Height && vote.Type == tmproto.PrecommitType {
  1679. if cs.Step != cstypes.RoundStepNewHeight {
  1680. // Late precommit at prior height is ignored
  1681. cs.Logger.Debug("precommit vote came in after commit timeout and has been ignored", "vote", vote)
  1682. return
  1683. }
  1684. added, err = cs.LastCommit.AddVote(vote)
  1685. if !added {
  1686. return
  1687. }
  1688. cs.Logger.Debug("added vote to last precommits", "last_commit", cs.LastCommit.StringShort())
  1689. if err := cs.eventBus.PublishEventVote(types.EventDataVote{Vote: vote}); err != nil {
  1690. return added, err
  1691. }
  1692. cs.evsw.FireEvent(types.EventVoteValue, vote)
  1693. // if we can skip timeoutCommit and have all the votes now,
  1694. if cs.config.SkipTimeoutCommit && cs.LastCommit.HasAll() {
  1695. // go straight to new round (skip timeout commit)
  1696. // cs.scheduleTimeout(time.Duration(0), cs.Height, 0, cstypes.RoundStepNewHeight)
  1697. cs.enterNewRound(cs.Height, 0)
  1698. }
  1699. return
  1700. }
  1701. // Height mismatch is ignored.
  1702. // Not necessarily a bad peer, but not favorable behavior.
  1703. if vote.Height != cs.Height {
  1704. cs.Logger.Debug("vote ignored and not added", "vote_height", vote.Height, "cs_height", cs.Height, "peer", peerID)
  1705. return
  1706. }
  1707. height := cs.Height
  1708. added, err = cs.Votes.AddVote(vote, peerID)
  1709. if !added {
  1710. // Either duplicate, or error upon cs.Votes.AddByIndex()
  1711. return
  1712. }
  1713. if err := cs.eventBus.PublishEventVote(types.EventDataVote{Vote: vote}); err != nil {
  1714. return added, err
  1715. }
  1716. cs.evsw.FireEvent(types.EventVoteValue, vote)
  1717. switch vote.Type {
  1718. case tmproto.PrevoteType:
  1719. prevotes := cs.Votes.Prevotes(vote.Round)
  1720. cs.Logger.Debug("added vote to prevote", "vote", vote, "prevotes", prevotes.StringShort())
  1721. // If +2/3 prevotes for a block or nil for *any* round:
  1722. if blockID, ok := prevotes.TwoThirdsMajority(); ok {
  1723. // There was a polka!
  1724. // If we're locked but this is a recent polka, unlock.
  1725. // If it matches our ProposalBlock, update the ValidBlock
  1726. // Unlock if `cs.LockedRound < vote.Round <= cs.Round`
  1727. // NOTE: If vote.Round > cs.Round, we'll deal with it when we get to vote.Round
  1728. if (cs.LockedBlock != nil) &&
  1729. (cs.LockedRound < vote.Round) &&
  1730. (vote.Round <= cs.Round) &&
  1731. !cs.LockedBlock.HashesTo(blockID.Hash) {
  1732. cs.Logger.Debug("unlocking because of POL", "locked_round", cs.LockedRound, "pol_round", vote.Round)
  1733. cs.LockedRound = -1
  1734. cs.LockedBlock = nil
  1735. cs.LockedBlockParts = nil
  1736. if err := cs.eventBus.PublishEventUnlock(cs.RoundStateEvent()); err != nil {
  1737. return added, err
  1738. }
  1739. }
  1740. // Update Valid* if we can.
  1741. // NOTE: our proposal block may be nil or not what received a polka..
  1742. if len(blockID.Hash) != 0 && (cs.ValidRound < vote.Round) && (vote.Round == cs.Round) {
  1743. if cs.ProposalBlock.HashesTo(blockID.Hash) {
  1744. cs.Logger.Debug("updating valid block because of POL", "valid_round", cs.ValidRound, "pol_round", vote.Round)
  1745. cs.ValidRound = vote.Round
  1746. cs.ValidBlock = cs.ProposalBlock
  1747. cs.ValidBlockParts = cs.ProposalBlockParts
  1748. } else {
  1749. cs.Logger.Debug(
  1750. "valid block we do not know about; set ProposalBlock=nil",
  1751. "proposal", cs.ProposalBlock.Hash(),
  1752. "block_id", blockID.Hash,
  1753. )
  1754. // we're getting the wrong block
  1755. cs.ProposalBlock = nil
  1756. }
  1757. if !cs.ProposalBlockParts.HasHeader(blockID.PartSetHeader) {
  1758. cs.ProposalBlockParts = types.NewPartSetFromHeader(blockID.PartSetHeader)
  1759. }
  1760. cs.evsw.FireEvent(types.EventValidBlockValue, &cs.RoundState)
  1761. if err := cs.eventBus.PublishEventValidBlock(cs.RoundStateEvent()); err != nil {
  1762. return added, err
  1763. }
  1764. }
  1765. }
  1766. // If +2/3 prevotes for *anything* for future round:
  1767. switch {
  1768. case cs.Round < vote.Round && prevotes.HasTwoThirdsAny():
  1769. // Round-skip if there is any 2/3+ of votes ahead of us
  1770. cs.enterNewRound(height, vote.Round)
  1771. case cs.Round == vote.Round && cstypes.RoundStepPrevote <= cs.Step: // current round
  1772. blockID, ok := prevotes.TwoThirdsMajority()
  1773. if ok && (cs.isProposalComplete() || len(blockID.Hash) == 0) {
  1774. cs.enterPrecommit(height, vote.Round)
  1775. } else if prevotes.HasTwoThirdsAny() {
  1776. cs.enterPrevoteWait(height, vote.Round)
  1777. }
  1778. case cs.Proposal != nil && 0 <= cs.Proposal.POLRound && cs.Proposal.POLRound == vote.Round:
  1779. // If the proposal is now complete, enter prevote of cs.Round.
  1780. if cs.isProposalComplete() {
  1781. cs.enterPrevote(height, cs.Round)
  1782. }
  1783. }
  1784. case tmproto.PrecommitType:
  1785. precommits := cs.Votes.Precommits(vote.Round)
  1786. cs.Logger.Debug("added vote to precommit",
  1787. "height", vote.Height,
  1788. "round", vote.Round,
  1789. "validator", vote.ValidatorAddress.String(),
  1790. "vote_timestamp", vote.Timestamp,
  1791. "data", precommits.LogString())
  1792. blockID, ok := precommits.TwoThirdsMajority()
  1793. if ok {
  1794. // Executed as TwoThirdsMajority could be from a higher round
  1795. cs.enterNewRound(height, vote.Round)
  1796. cs.enterPrecommit(height, vote.Round)
  1797. if len(blockID.Hash) != 0 {
  1798. cs.enterCommit(height, vote.Round)
  1799. if cs.config.SkipTimeoutCommit && precommits.HasAll() {
  1800. cs.enterNewRound(cs.Height, 0)
  1801. }
  1802. } else {
  1803. cs.enterPrecommitWait(height, vote.Round)
  1804. }
  1805. } else if cs.Round <= vote.Round && precommits.HasTwoThirdsAny() {
  1806. cs.enterNewRound(height, vote.Round)
  1807. cs.enterPrecommitWait(height, vote.Round)
  1808. }
  1809. default:
  1810. panic(fmt.Sprintf("unexpected vote type %v", vote.Type))
  1811. }
  1812. return added, err
  1813. }
  1814. // CONTRACT: cs.privValidator is not nil.
  1815. func (cs *State) signVote(
  1816. msgType tmproto.SignedMsgType,
  1817. hash []byte,
  1818. header types.PartSetHeader,
  1819. ) (*types.Vote, error) {
  1820. // Flush the WAL. Otherwise, we may not recompute the same vote to sign,
  1821. // and the privValidator will refuse to sign anything.
  1822. if err := cs.wal.FlushAndSync(); err != nil {
  1823. return nil, err
  1824. }
  1825. if cs.privValidatorPubKey == nil {
  1826. return nil, errPubKeyIsNotSet
  1827. }
  1828. addr := cs.privValidatorPubKey.Address()
  1829. valIdx, _ := cs.Validators.GetByAddress(addr)
  1830. vote := &types.Vote{
  1831. ValidatorAddress: addr,
  1832. ValidatorIndex: valIdx,
  1833. Height: cs.Height,
  1834. Round: cs.Round,
  1835. Timestamp: cs.voteTime(),
  1836. Type: msgType,
  1837. BlockID: types.BlockID{Hash: hash, PartSetHeader: header},
  1838. }
  1839. v := vote.ToProto()
  1840. // If the signedMessageType is for precommit,
  1841. // use our local precommit Timeout as the max wait time for getting a singed commit. The same goes for prevote.
  1842. var timeout time.Duration
  1843. switch msgType {
  1844. case tmproto.PrecommitType:
  1845. timeout = cs.config.TimeoutPrecommit
  1846. case tmproto.PrevoteType:
  1847. timeout = cs.config.TimeoutPrevote
  1848. default:
  1849. timeout = time.Second
  1850. }
  1851. ctx, cancel := context.WithTimeout(context.TODO(), timeout)
  1852. defer cancel()
  1853. err := cs.privValidator.SignVote(ctx, cs.state.ChainID, v)
  1854. vote.Signature = v.Signature
  1855. vote.Timestamp = v.Timestamp
  1856. return vote, err
  1857. }
  1858. // voteTime ensures monotonicity of the time a validator votes on.
  1859. // It ensures that for a prior block with a BFT-timestamp of T,
  1860. // any vote from this validator will have time at least time T + 1ms.
  1861. // This is needed, as monotonicity of time is a guarantee that BFT time provides.
  1862. func (cs *State) voteTime() time.Time {
  1863. now := tmtime.Now()
  1864. minVoteTime := now
  1865. // Minimum time increment between blocks
  1866. const timeIota = time.Millisecond
  1867. // TODO: We should remove next line in case we don't vote for v in case cs.ProposalBlock == nil,
  1868. // even if cs.LockedBlock != nil. See https://docs.tendermint.com/master/spec/.
  1869. if cs.LockedBlock != nil {
  1870. // See the BFT time spec https://docs.tendermint.com/master/spec/consensus/bft-time.html
  1871. minVoteTime = cs.LockedBlock.Time.Add(timeIota)
  1872. } else if cs.ProposalBlock != nil {
  1873. minVoteTime = cs.ProposalBlock.Time.Add(timeIota)
  1874. }
  1875. if now.After(minVoteTime) {
  1876. return now
  1877. }
  1878. return minVoteTime
  1879. }
  1880. // sign the vote and publish on internalMsgQueue
  1881. func (cs *State) signAddVote(msgType tmproto.SignedMsgType, hash []byte, header types.PartSetHeader) *types.Vote {
  1882. if cs.privValidator == nil { // the node does not have a key
  1883. return nil
  1884. }
  1885. if cs.privValidatorPubKey == nil {
  1886. // Vote won't be signed, but it's not critical.
  1887. cs.Logger.Error(fmt.Sprintf("signAddVote: %v", errPubKeyIsNotSet))
  1888. return nil
  1889. }
  1890. // If the node not in the validator set, do nothing.
  1891. if !cs.Validators.HasAddress(cs.privValidatorPubKey.Address()) {
  1892. return nil
  1893. }
  1894. // TODO: pass pubKey to signVote
  1895. vote, err := cs.signVote(msgType, hash, header)
  1896. if err == nil {
  1897. cs.sendInternalMessage(msgInfo{&VoteMessage{vote}, ""})
  1898. cs.Logger.Debug("signed and pushed vote", "height", cs.Height, "round", cs.Round, "vote", vote)
  1899. return vote
  1900. }
  1901. cs.Logger.Error("failed signing vote", "height", cs.Height, "round", cs.Round, "vote", vote, "err", err)
  1902. return nil
  1903. }
  1904. // updatePrivValidatorPubKey get's the private validator public key and
  1905. // memoizes it. This func returns an error if the private validator is not
  1906. // responding or responds with an error.
  1907. func (cs *State) updatePrivValidatorPubKey() error {
  1908. if cs.privValidator == nil {
  1909. return nil
  1910. }
  1911. var timeout time.Duration
  1912. if cs.config.TimeoutPrecommit > cs.config.TimeoutPrevote {
  1913. timeout = cs.config.TimeoutPrecommit
  1914. } else {
  1915. timeout = cs.config.TimeoutPrevote
  1916. }
  1917. // no GetPubKey retry beyond the proposal/voting in RetrySignerClient
  1918. if cs.Step >= cstypes.RoundStepPrecommit && cs.privValidatorType == types.RetrySignerClient {
  1919. timeout = 0
  1920. }
  1921. // set context timeout depending on the configuration and the State step,
  1922. // this helps in avoiding blocking of the remote signer connection.
  1923. ctx, cancel := context.WithTimeout(context.TODO(), timeout)
  1924. defer cancel()
  1925. pubKey, err := cs.privValidator.GetPubKey(ctx)
  1926. if err != nil {
  1927. return err
  1928. }
  1929. cs.privValidatorPubKey = pubKey
  1930. return nil
  1931. }
  1932. // look back to check existence of the node's consensus votes before joining consensus
  1933. func (cs *State) checkDoubleSigningRisk(height int64) error {
  1934. if cs.privValidator != nil && cs.privValidatorPubKey != nil && cs.config.DoubleSignCheckHeight > 0 && height > 0 {
  1935. valAddr := cs.privValidatorPubKey.Address()
  1936. doubleSignCheckHeight := cs.config.DoubleSignCheckHeight
  1937. if doubleSignCheckHeight > height {
  1938. doubleSignCheckHeight = height
  1939. }
  1940. for i := int64(1); i < doubleSignCheckHeight; i++ {
  1941. lastCommit := cs.LoadCommit(height - i)
  1942. if lastCommit != nil {
  1943. for sigIdx, s := range lastCommit.Signatures {
  1944. if s.BlockIDFlag == types.BlockIDFlagCommit && bytes.Equal(s.ValidatorAddress, valAddr) {
  1945. cs.Logger.Info("found signature from the same key", "sig", s, "idx", sigIdx, "height", height-i)
  1946. return ErrSignatureFoundInPastBlocks
  1947. }
  1948. }
  1949. }
  1950. }
  1951. }
  1952. return nil
  1953. }
  1954. //---------------------------------------------------------
  1955. func CompareHRS(h1 int64, r1 int32, s1 cstypes.RoundStepType, h2 int64, r2 int32, s2 cstypes.RoundStepType) int {
  1956. if h1 < h2 {
  1957. return -1
  1958. } else if h1 > h2 {
  1959. return 1
  1960. }
  1961. if r1 < r2 {
  1962. return -1
  1963. } else if r1 > r2 {
  1964. return 1
  1965. }
  1966. if s1 < s2 {
  1967. return -1
  1968. } else if s1 > s2 {
  1969. return 1
  1970. }
  1971. return 0
  1972. }
  1973. // repairWalFile decodes messages from src (until the decoder errors) and
  1974. // writes them to dst.
  1975. func repairWalFile(src, dst string) error {
  1976. in, err := os.Open(src)
  1977. if err != nil {
  1978. return err
  1979. }
  1980. defer in.Close()
  1981. out, err := os.Create(dst)
  1982. if err != nil {
  1983. return err
  1984. }
  1985. defer out.Close()
  1986. var (
  1987. dec = NewWALDecoder(in)
  1988. enc = NewWALEncoder(out)
  1989. )
  1990. // best-case repair (until first error is encountered)
  1991. for {
  1992. msg, err := dec.Decode()
  1993. if err != nil {
  1994. break
  1995. }
  1996. err = enc.Encode(msg)
  1997. if err != nil {
  1998. return fmt.Errorf("failed to encode msg: %w", err)
  1999. }
  2000. }
  2001. return nil
  2002. }