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.

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