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.

444 lines
11 KiB

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
8 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
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
abci: Refactor tagging events using list of lists (#3643) ## PR This PR introduces a fundamental breaking change to the structure of ABCI response and tx tags and the way they're processed. Namely, the SDK can support more complex and aggregated events for distribution and slashing. In addition, block responses can include duplicate keys in events. Implement new Event type. An event has a type and a list of KV pairs (ie. list-of-lists). Typical events may look like: "rewards": [{"amount": "5000uatom", "validator": "...", "recipient": "..."}] "sender": [{"address": "...", "balance": "100uatom"}] The events are indexed by {even.type}.{even.attribute[i].key}/.... In this case a client would subscribe or query for rewards.recipient='...' ABCI response types and related types now include Events []Event instead of Tags []cmn.KVPair. PubSub logic now publishes/matches against map[string][]string instead of map[string]string to support duplicate keys in response events (from #1385). A match is successful if the value is found in the slice of strings. closes: #1859 closes: #2905 ## Commits: * Implement Event ABCI type and updates responses to use events * Update messages_test.go * Update kvstore.go * Update event_bus.go * Update subscription.go * Update pubsub.go * Update kvstore.go * Update query logic to handle slice of strings in events * Update Empty#Matches and unit tests * Update pubsub logic * Update EventBus#Publish * Update kv tx indexer * Update godocs * Update ResultEvent to use slice of strings; update RPC * Update more tests * Update abci.md * Check for key in validateAndStringifyEvents * Fix KV indexer to skip empty keys * Fix linting errors * Update CHANGELOG_PENDING.md * Update docs/spec/abci/abci.md Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update abci/types/types.proto Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update docs/spec/abci/abci.md Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update libs/pubsub/query/query.go Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update match function to match if ANY value matches * Implement TestSubscribeDuplicateKeys * Update TestMatches to include multi-key test cases * Update events.go * Update Query interface godoc * Update match godoc * Add godoc for matchValue * DRY-up tx indexing * Return error from PublishWithEvents in EventBus#Publish * Update PublishEventNewBlockHeader to return an error * Fix build * Update events doc in ABCI * Update ABCI events godoc * Implement TestEventBusPublishEventTxDuplicateKeys * Update TestSubscribeDuplicateKeys to be table-driven * Remove mod file * Remove markdown from events godoc * Implement TestTxSearchDeprecatedIndexing test
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
abci: Refactor tagging events using list of lists (#3643) ## PR This PR introduces a fundamental breaking change to the structure of ABCI response and tx tags and the way they're processed. Namely, the SDK can support more complex and aggregated events for distribution and slashing. In addition, block responses can include duplicate keys in events. Implement new Event type. An event has a type and a list of KV pairs (ie. list-of-lists). Typical events may look like: "rewards": [{"amount": "5000uatom", "validator": "...", "recipient": "..."}] "sender": [{"address": "...", "balance": "100uatom"}] The events are indexed by {even.type}.{even.attribute[i].key}/.... In this case a client would subscribe or query for rewards.recipient='...' ABCI response types and related types now include Events []Event instead of Tags []cmn.KVPair. PubSub logic now publishes/matches against map[string][]string instead of map[string]string to support duplicate keys in response events (from #1385). A match is successful if the value is found in the slice of strings. closes: #1859 closes: #2905 ## Commits: * Implement Event ABCI type and updates responses to use events * Update messages_test.go * Update kvstore.go * Update event_bus.go * Update subscription.go * Update pubsub.go * Update kvstore.go * Update query logic to handle slice of strings in events * Update Empty#Matches and unit tests * Update pubsub logic * Update EventBus#Publish * Update kv tx indexer * Update godocs * Update ResultEvent to use slice of strings; update RPC * Update more tests * Update abci.md * Check for key in validateAndStringifyEvents * Fix KV indexer to skip empty keys * Fix linting errors * Update CHANGELOG_PENDING.md * Update docs/spec/abci/abci.md Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update abci/types/types.proto Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update docs/spec/abci/abci.md Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update libs/pubsub/query/query.go Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update match function to match if ANY value matches * Implement TestSubscribeDuplicateKeys * Update TestMatches to include multi-key test cases * Update events.go * Update Query interface godoc * Update match godoc * Add godoc for matchValue * DRY-up tx indexing * Return error from PublishWithEvents in EventBus#Publish * Update PublishEventNewBlockHeader to return an error * Fix build * Update events doc in ABCI * Update ABCI events godoc * Implement TestEventBusPublishEventTxDuplicateKeys * Update TestSubscribeDuplicateKeys to be table-driven * Remove mod file * Remove markdown from events godoc * Implement TestTxSearchDeprecatedIndexing test
6 years ago
abci: Refactor tagging events using list of lists (#3643) ## PR This PR introduces a fundamental breaking change to the structure of ABCI response and tx tags and the way they're processed. Namely, the SDK can support more complex and aggregated events for distribution and slashing. In addition, block responses can include duplicate keys in events. Implement new Event type. An event has a type and a list of KV pairs (ie. list-of-lists). Typical events may look like: "rewards": [{"amount": "5000uatom", "validator": "...", "recipient": "..."}] "sender": [{"address": "...", "balance": "100uatom"}] The events are indexed by {even.type}.{even.attribute[i].key}/.... In this case a client would subscribe or query for rewards.recipient='...' ABCI response types and related types now include Events []Event instead of Tags []cmn.KVPair. PubSub logic now publishes/matches against map[string][]string instead of map[string]string to support duplicate keys in response events (from #1385). A match is successful if the value is found in the slice of strings. closes: #1859 closes: #2905 ## Commits: * Implement Event ABCI type and updates responses to use events * Update messages_test.go * Update kvstore.go * Update event_bus.go * Update subscription.go * Update pubsub.go * Update kvstore.go * Update query logic to handle slice of strings in events * Update Empty#Matches and unit tests * Update pubsub logic * Update EventBus#Publish * Update kv tx indexer * Update godocs * Update ResultEvent to use slice of strings; update RPC * Update more tests * Update abci.md * Check for key in validateAndStringifyEvents * Fix KV indexer to skip empty keys * Fix linting errors * Update CHANGELOG_PENDING.md * Update docs/spec/abci/abci.md Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update abci/types/types.proto Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update docs/spec/abci/abci.md Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update libs/pubsub/query/query.go Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update match function to match if ANY value matches * Implement TestSubscribeDuplicateKeys * Update TestMatches to include multi-key test cases * Update events.go * Update Query interface godoc * Update match godoc * Add godoc for matchValue * DRY-up tx indexing * Return error from PublishWithEvents in EventBus#Publish * Update PublishEventNewBlockHeader to return an error * Fix build * Update events doc in ABCI * Update ABCI events godoc * Implement TestEventBusPublishEventTxDuplicateKeys * Update TestSubscribeDuplicateKeys to be table-driven * Remove mod file * Remove markdown from events godoc * Implement TestTxSearchDeprecatedIndexing test
6 years ago
abci: Refactor tagging events using list of lists (#3643) ## PR This PR introduces a fundamental breaking change to the structure of ABCI response and tx tags and the way they're processed. Namely, the SDK can support more complex and aggregated events for distribution and slashing. In addition, block responses can include duplicate keys in events. Implement new Event type. An event has a type and a list of KV pairs (ie. list-of-lists). Typical events may look like: "rewards": [{"amount": "5000uatom", "validator": "...", "recipient": "..."}] "sender": [{"address": "...", "balance": "100uatom"}] The events are indexed by {even.type}.{even.attribute[i].key}/.... In this case a client would subscribe or query for rewards.recipient='...' ABCI response types and related types now include Events []Event instead of Tags []cmn.KVPair. PubSub logic now publishes/matches against map[string][]string instead of map[string]string to support duplicate keys in response events (from #1385). A match is successful if the value is found in the slice of strings. closes: #1859 closes: #2905 ## Commits: * Implement Event ABCI type and updates responses to use events * Update messages_test.go * Update kvstore.go * Update event_bus.go * Update subscription.go * Update pubsub.go * Update kvstore.go * Update query logic to handle slice of strings in events * Update Empty#Matches and unit tests * Update pubsub logic * Update EventBus#Publish * Update kv tx indexer * Update godocs * Update ResultEvent to use slice of strings; update RPC * Update more tests * Update abci.md * Check for key in validateAndStringifyEvents * Fix KV indexer to skip empty keys * Fix linting errors * Update CHANGELOG_PENDING.md * Update docs/spec/abci/abci.md Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update abci/types/types.proto Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update docs/spec/abci/abci.md Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update libs/pubsub/query/query.go Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update match function to match if ANY value matches * Implement TestSubscribeDuplicateKeys * Update TestMatches to include multi-key test cases * Update events.go * Update Query interface godoc * Update match godoc * Add godoc for matchValue * DRY-up tx indexing * Return error from PublishWithEvents in EventBus#Publish * Update PublishEventNewBlockHeader to return an error * Fix build * Update events doc in ABCI * Update ABCI events godoc * Implement TestEventBusPublishEventTxDuplicateKeys * Update TestSubscribeDuplicateKeys to be table-driven * Remove mod file * Remove markdown from events godoc * Implement TestTxSearchDeprecatedIndexing test
6 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
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
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
  1. package kvstore
  2. import (
  3. "bytes"
  4. "encoding/base64"
  5. "encoding/binary"
  6. "encoding/json"
  7. "fmt"
  8. "strconv"
  9. "strings"
  10. "sync"
  11. dbm "github.com/tendermint/tm-db"
  12. "github.com/tendermint/tendermint/abci/example/code"
  13. "github.com/tendermint/tendermint/abci/types"
  14. "github.com/tendermint/tendermint/crypto/encoding"
  15. "github.com/tendermint/tendermint/libs/log"
  16. cryptoproto "github.com/tendermint/tendermint/proto/tendermint/crypto"
  17. "github.com/tendermint/tendermint/version"
  18. )
  19. var (
  20. stateKey = []byte("stateKey")
  21. kvPairPrefixKey = []byte("kvPairKey:")
  22. ProtocolVersion uint64 = 0x1
  23. )
  24. type State struct {
  25. db dbm.DB
  26. Size int64 `json:"size"`
  27. Height int64 `json:"height"`
  28. AppHash []byte `json:"app_hash"`
  29. }
  30. func loadState(db dbm.DB) State {
  31. var state State
  32. state.db = db
  33. stateBytes, err := db.Get(stateKey)
  34. if err != nil {
  35. panic(err)
  36. }
  37. if len(stateBytes) == 0 {
  38. return state
  39. }
  40. err = json.Unmarshal(stateBytes, &state)
  41. if err != nil {
  42. panic(err)
  43. }
  44. return state
  45. }
  46. func saveState(state State) {
  47. stateBytes, err := json.Marshal(state)
  48. if err != nil {
  49. panic(err)
  50. }
  51. err = state.db.Set(stateKey, stateBytes)
  52. if err != nil {
  53. panic(err)
  54. }
  55. }
  56. func prefixKey(key []byte) []byte {
  57. return append(kvPairPrefixKey, key...)
  58. }
  59. //---------------------------------------------------
  60. var _ types.Application = (*Application)(nil)
  61. type Application struct {
  62. types.BaseApplication
  63. mu sync.Mutex
  64. state State
  65. RetainBlocks int64 // blocks to retain after commit (via ResponseCommit.RetainHeight)
  66. logger log.Logger
  67. // validator set
  68. ValUpdates []types.ValidatorUpdate
  69. valAddrToPubKeyMap map[string]cryptoproto.PublicKey
  70. }
  71. func NewApplication() *Application {
  72. return &Application{
  73. logger: log.NewNopLogger(),
  74. state: loadState(dbm.NewMemDB()),
  75. valAddrToPubKeyMap: make(map[string]cryptoproto.PublicKey),
  76. }
  77. }
  78. func (app *Application) InitChain(req types.RequestInitChain) types.ResponseInitChain {
  79. app.mu.Lock()
  80. defer app.mu.Unlock()
  81. for _, v := range req.Validators {
  82. r := app.updateValidator(v)
  83. if r.IsErr() {
  84. app.logger.Error("error updating validators", "r", r)
  85. panic("problem updating validators")
  86. }
  87. }
  88. return types.ResponseInitChain{}
  89. }
  90. func (app *Application) Info(req types.RequestInfo) types.ResponseInfo {
  91. app.mu.Lock()
  92. defer app.mu.Unlock()
  93. return types.ResponseInfo{
  94. Data: fmt.Sprintf("{\"size\":%v}", app.state.Size),
  95. Version: version.ABCIVersion,
  96. AppVersion: ProtocolVersion,
  97. LastBlockHeight: app.state.Height,
  98. LastBlockAppHash: app.state.AppHash,
  99. }
  100. }
  101. // tx is either "val:pubkey!power" or "key=value" or just arbitrary bytes
  102. func (app *Application) handleTx(tx []byte) *types.ExecTxResult {
  103. // if it starts with "val:", update the validator set
  104. // format is "val:pubkey!power"
  105. if isValidatorTx(tx) {
  106. // update validators in the merkle tree
  107. // and in app.ValUpdates
  108. return app.execValidatorTx(tx)
  109. }
  110. if isPrepareTx(tx) {
  111. return app.execPrepareTx(tx)
  112. }
  113. var key, value string
  114. parts := bytes.Split(tx, []byte("="))
  115. if len(parts) == 2 {
  116. key, value = string(parts[0]), string(parts[1])
  117. } else {
  118. key, value = string(tx), string(tx)
  119. }
  120. err := app.state.db.Set(prefixKey([]byte(key)), []byte(value))
  121. if err != nil {
  122. panic(err)
  123. }
  124. app.state.Size++
  125. events := []types.Event{
  126. {
  127. Type: "app",
  128. Attributes: []types.EventAttribute{
  129. {Key: "creator", Value: "Cosmoshi Netowoko", Index: true},
  130. {Key: "key", Value: key, Index: true},
  131. {Key: "index_key", Value: "index is working", Index: true},
  132. {Key: "noindex_key", Value: "index is working", Index: false},
  133. },
  134. },
  135. }
  136. return &types.ExecTxResult{Code: code.CodeTypeOK, TxEvents: events}
  137. }
  138. func (app *Application) Close() error {
  139. app.mu.Lock()
  140. defer app.mu.Unlock()
  141. return app.state.db.Close()
  142. }
  143. func (app *Application) FinalizeBlock(req types.RequestFinalizeBlock) types.ResponseFinalizeBlock {
  144. app.mu.Lock()
  145. defer app.mu.Unlock()
  146. // reset valset changes
  147. app.ValUpdates = make([]types.ValidatorUpdate, 0)
  148. // Punish validators who committed equivocation.
  149. for _, ev := range req.ByzantineValidators {
  150. if ev.Type == types.EvidenceType_DUPLICATE_VOTE {
  151. addr := string(ev.Validator.Address)
  152. if pubKey, ok := app.valAddrToPubKeyMap[addr]; ok {
  153. app.updateValidator(types.ValidatorUpdate{
  154. PubKey: pubKey,
  155. Power: ev.Validator.Power - 1,
  156. })
  157. app.logger.Info("Decreased val power by 1 because of the equivocation",
  158. "val", addr)
  159. } else {
  160. panic(fmt.Errorf("wanted to punish val %q but can't find it", addr))
  161. }
  162. }
  163. }
  164. respTxs := make([]*types.ExecTxResult, len(req.Txs))
  165. for i, tx := range req.Txs {
  166. respTxs[i] = app.handleTx(tx)
  167. }
  168. return types.ResponseFinalizeBlock{TxResults: respTxs, ValidatorUpdates: app.ValUpdates}
  169. }
  170. func (*Application) CheckTx(req types.RequestCheckTx) types.ResponseCheckTx {
  171. return types.ResponseCheckTx{Code: code.CodeTypeOK, GasWanted: 1}
  172. }
  173. func (app *Application) Commit() types.ResponseCommit {
  174. app.mu.Lock()
  175. defer app.mu.Unlock()
  176. // Using a memdb - just return the big endian size of the db
  177. appHash := make([]byte, 8)
  178. binary.PutVarint(appHash, app.state.Size)
  179. app.state.AppHash = appHash
  180. app.state.Height++
  181. saveState(app.state)
  182. resp := types.ResponseCommit{Data: appHash}
  183. if app.RetainBlocks > 0 && app.state.Height >= app.RetainBlocks {
  184. resp.RetainHeight = app.state.Height - app.RetainBlocks + 1
  185. }
  186. return resp
  187. }
  188. // Returns an associated value or nil if missing.
  189. func (app *Application) Query(reqQuery types.RequestQuery) types.ResponseQuery {
  190. app.mu.Lock()
  191. defer app.mu.Unlock()
  192. if reqQuery.Path == "/val" {
  193. key := []byte("val:" + string(reqQuery.Data))
  194. value, err := app.state.db.Get(key)
  195. if err != nil {
  196. panic(err)
  197. }
  198. return types.ResponseQuery{
  199. Key: reqQuery.Data,
  200. Value: value,
  201. }
  202. }
  203. if reqQuery.Prove {
  204. value, err := app.state.db.Get(prefixKey(reqQuery.Data))
  205. if err != nil {
  206. panic(err)
  207. }
  208. resQuery := types.ResponseQuery{
  209. Index: -1,
  210. Key: reqQuery.Data,
  211. Value: value,
  212. Height: app.state.Height,
  213. }
  214. if value == nil {
  215. resQuery.Log = "does not exist"
  216. } else {
  217. resQuery.Log = "exists"
  218. }
  219. return resQuery
  220. }
  221. value, err := app.state.db.Get(prefixKey(reqQuery.Data))
  222. if err != nil {
  223. panic(err)
  224. }
  225. resQuery := types.ResponseQuery{
  226. Key: reqQuery.Data,
  227. Value: value,
  228. Height: app.state.Height,
  229. }
  230. if value == nil {
  231. resQuery.Log = "does not exist"
  232. } else {
  233. resQuery.Log = "exists"
  234. }
  235. return resQuery
  236. }
  237. func (app *Application) PrepareProposal(req types.RequestPrepareProposal) types.ResponsePrepareProposal {
  238. app.mu.Lock()
  239. defer app.mu.Unlock()
  240. return types.ResponsePrepareProposal{BlockData: app.substPrepareTx(req.BlockData)}
  241. }
  242. func (*Application) ProcessProposal(req types.RequestProcessProposal) types.ResponseProcessProposal {
  243. for _, tx := range req.Txs {
  244. if len(tx) == 0 {
  245. return types.ResponseProcessProposal{Accept: false}
  246. }
  247. }
  248. return types.ResponseProcessProposal{Accept: true}
  249. }
  250. //---------------------------------------------
  251. // update validators
  252. func (app *Application) Validators() (validators []types.ValidatorUpdate) {
  253. app.mu.Lock()
  254. defer app.mu.Unlock()
  255. itr, err := app.state.db.Iterator(nil, nil)
  256. if err != nil {
  257. panic(err)
  258. }
  259. for ; itr.Valid(); itr.Next() {
  260. if isValidatorTx(itr.Key()) {
  261. validator := new(types.ValidatorUpdate)
  262. err := types.ReadMessage(bytes.NewBuffer(itr.Value()), validator)
  263. if err != nil {
  264. panic(err)
  265. }
  266. validators = append(validators, *validator)
  267. }
  268. }
  269. if err = itr.Error(); err != nil {
  270. panic(err)
  271. }
  272. return
  273. }
  274. func MakeValSetChangeTx(pubkey cryptoproto.PublicKey, power int64) []byte {
  275. pk, err := encoding.PubKeyFromProto(pubkey)
  276. if err != nil {
  277. panic(err)
  278. }
  279. pubStr := base64.StdEncoding.EncodeToString(pk.Bytes())
  280. return []byte(fmt.Sprintf("val:%s!%d", pubStr, power))
  281. }
  282. func isValidatorTx(tx []byte) bool {
  283. return strings.HasPrefix(string(tx), ValidatorSetChangePrefix)
  284. }
  285. // format is "val:pubkey!power"
  286. // pubkey is a base64-encoded 32-byte ed25519 key
  287. func (app *Application) execValidatorTx(tx []byte) *types.ExecTxResult {
  288. tx = tx[len(ValidatorSetChangePrefix):]
  289. // get the pubkey and power
  290. pubKeyAndPower := strings.Split(string(tx), "!")
  291. if len(pubKeyAndPower) != 2 {
  292. return &types.ExecTxResult{
  293. Code: code.CodeTypeEncodingError,
  294. Log: fmt.Sprintf("Expected 'pubkey!power'. Got %v", pubKeyAndPower)}
  295. }
  296. pubkeyS, powerS := pubKeyAndPower[0], pubKeyAndPower[1]
  297. // decode the pubkey
  298. pubkey, err := base64.StdEncoding.DecodeString(pubkeyS)
  299. if err != nil {
  300. return &types.ExecTxResult{
  301. Code: code.CodeTypeEncodingError,
  302. Log: fmt.Sprintf("Pubkey (%s) is invalid base64", pubkeyS)}
  303. }
  304. // decode the power
  305. power, err := strconv.ParseInt(powerS, 10, 64)
  306. if err != nil {
  307. return &types.ExecTxResult{
  308. Code: code.CodeTypeEncodingError,
  309. Log: fmt.Sprintf("Power (%s) is not an int", powerS)}
  310. }
  311. // update
  312. return app.updateValidator(types.UpdateValidator(pubkey, power, ""))
  313. }
  314. // add, update, or remove a validator
  315. func (app *Application) updateValidator(v types.ValidatorUpdate) *types.ExecTxResult {
  316. pubkey, err := encoding.PubKeyFromProto(v.PubKey)
  317. if err != nil {
  318. panic(fmt.Errorf("can't decode public key: %w", err))
  319. }
  320. key := []byte("val:" + string(pubkey.Bytes()))
  321. if v.Power == 0 {
  322. // remove validator
  323. hasKey, err := app.state.db.Has(key)
  324. if err != nil {
  325. panic(err)
  326. }
  327. if !hasKey {
  328. pubStr := base64.StdEncoding.EncodeToString(pubkey.Bytes())
  329. return &types.ExecTxResult{
  330. Code: code.CodeTypeUnauthorized,
  331. Log: fmt.Sprintf("Cannot remove non-existent validator %s", pubStr)}
  332. }
  333. if err = app.state.db.Delete(key); err != nil {
  334. panic(err)
  335. }
  336. delete(app.valAddrToPubKeyMap, string(pubkey.Address()))
  337. } else {
  338. // add or update validator
  339. value := bytes.NewBuffer(make([]byte, 0))
  340. if err := types.WriteMessage(&v, value); err != nil {
  341. return &types.ExecTxResult{
  342. Code: code.CodeTypeEncodingError,
  343. Log: fmt.Sprintf("error encoding validator: %v", err)}
  344. }
  345. if err = app.state.db.Set(key, value.Bytes()); err != nil {
  346. panic(err)
  347. }
  348. app.valAddrToPubKeyMap[string(pubkey.Address())] = v.PubKey
  349. }
  350. // we only update the changes array if we successfully updated the tree
  351. app.ValUpdates = append(app.ValUpdates, v)
  352. return &types.ExecTxResult{Code: code.CodeTypeOK}
  353. }
  354. // -----------------------------
  355. // prepare proposal machinery
  356. const PreparePrefix = "prepare"
  357. func isPrepareTx(tx []byte) bool {
  358. return strings.HasPrefix(string(tx), PreparePrefix)
  359. }
  360. // execPrepareTx is noop. tx data is considered as placeholder
  361. // and is substitute at the PrepareProposal.
  362. func (app *Application) execPrepareTx(tx []byte) *types.ExecTxResult {
  363. // noop
  364. return &types.ExecTxResult{}
  365. }
  366. // substPrepareTx subst all the preparetx in the blockdata
  367. // to null string(could be any arbitrary string).
  368. func (app *Application) substPrepareTx(blockData [][]byte) [][]byte {
  369. // TODO: this mechanism will change with the current spec of PrepareProposal
  370. // We now have a special type for marking a tx as changed
  371. for i, tx := range blockData {
  372. if isPrepareTx(tx) {
  373. blockData[i] = make([]byte, len(tx))
  374. }
  375. }
  376. return blockData
  377. }