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.

2406 lines
74 KiB

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