From cb7c8e8ee36df450c2264599658b5b0969e0d6c8 Mon Sep 17 00:00:00 2001 From: lklimek <842586+lklimek@users.noreply.github.com> Date: Wed, 21 Oct 2026 12:25:47 +0200 Subject: [PATCH 01/12] refactor(db)!: own GoLevelDB and memory database adapters (#1551) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor(db)!: own GoLevelDB and memory database adapters Retain the GoLevelDB, MemDB and PrefixDB adapters from cometbft-db v1.0.4 under libs/db, with their license, provenance and contract tests. Upstream plans to retire the shared wrapper and discourages new dependencies on it. Preserve engine versions, persistence behavior, node configuration and SQL indexing while removing unused backend registrations and dependencies. Verify old-to-local-to-old persisted data compatibility and storage race tests. BREAKING CHANGE: exported DB APIs now use Tenderdash's libs/db interfaces; custom providers must update imports or adapt their Batch/Iterator return types. 🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent Co-Authored-By: Codex GPT-6 * fix(db): retain upstream attribution and modification notices Mark the eight modified upstream files and preserve cometbft-db's tm-db ancestry while retaining the original Apache license verbatim. 🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent Co-Authored-By: Claude GPT-6 * fix(db): release debug iterators and characterize empty values Release the GoLevelDB Print iterator before returning. Replace the skipped empty-value check with explicit backend Get/Has expectations and document the inherited difference tracked in issue #1554. 🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent Co-Authored-By: Claude GPT-6 --------- Co-authored-by: Codex GPT-6 Co-authored-by: Claude GPT-6 --- abci/example/kvstore/kvstore.go | 3 +- abci/example/kvstore/state.go | 2 +- abci/example/kvstore/state_test.go | 3 +- abci/example/kvstore/store.go | 3 +- cmd/tenderdash/commands/light.go | 3 +- cmd/tenderdash/commands/reindex_event.go | 3 +- cmd/tenderdash/commands/reindex_event_test.go | 3 +- config/db.go | 2 +- dash/quorum/validator_conn_executor_test.go | 3 +- go.mod | 22 +- go.sum | 46 -- internal/blocksync/applier_test.go | 3 +- internal/blocksync/reactor_test.go | 3 +- internal/consensus/byzantine_test.go | 3 +- internal/consensus/common_test.go | 3 +- internal/consensus/flood_reactor_test.go | 3 +- internal/consensus/helper_test.go | 3 +- internal/consensus/mempool_test.go | 3 +- internal/consensus/reactor_test.go | 3 +- internal/consensus/replay_file.go | 2 +- internal/consensus/replay_test.go | 3 +- internal/consensus/replayer_test.go | 3 +- internal/evidence/duplicate_lookup_test.go | 3 +- internal/evidence/evidence_admission_test.go | 3 +- internal/evidence/pool.go | 3 +- internal/evidence/pool_test.go | 3 +- internal/evidence/reactor_retry_test.go | 3 +- internal/evidence/reactor_test.go | 3 +- internal/evidence/verify_test.go | 3 +- internal/p2p/p2ptest/network.go | 3 +- internal/p2p/peermanager.go | 3 +- internal/p2p/peermanager_protected_test.go | 3 +- internal/p2p/peermanager_reconnect_test.go | 3 +- internal/p2p/peermanager_retry_test.go | 3 +- internal/p2p/peermanager_scoring_test.go | 3 +- internal/p2p/peermanager_test.go | 3 +- internal/p2p/pex/reactor_deadlock_test.go | 3 +- internal/p2p/pex/reactor_test.go | 3 +- internal/p2p/router_init_test.go | 3 +- internal/p2p/router_test.go | 3 +- internal/rpc/core/blocks_test.go | 2 +- internal/rpc/core/rpc_validation_test.go | 2 +- internal/state/execution_test.go | 3 +- internal/state/helpers_test.go | 3 +- internal/state/indexer/block/kv/kv.go | 3 +- internal/state/indexer/block/kv/kv_test.go | 3 +- .../state/indexer/indexer_service_test.go | 3 +- internal/state/indexer/sink/kv/kv.go | 2 +- internal/state/indexer/sink/kv/kv_test.go | 2 +- internal/state/indexer/tx/kv/kv.go | 3 +- internal/state/indexer/tx/kv/kv_bench_test.go | 2 +- .../state/indexer/tx/kv/kv_errors_test.go | 3 +- internal/state/indexer/tx/kv/kv_test.go | 3 +- internal/state/nofsync_test.go | 3 +- internal/state/rollback_test.go | 3 +- internal/state/state_test.go | 3 +- internal/state/store.go | 5 +- internal/state/store_test.go | 3 +- internal/state/validation_test.go | 3 +- internal/statesync/params_response_test.go | 3 +- internal/statesync/reactor_test.go | 3 +- internal/statesync/stateprovider.go | 3 +- internal/store/nofsync_test.go | 3 +- internal/store/store.go | 3 +- internal/store/store_test.go | 3 +- internal/test/dbspy/dbspy.go | 2 +- libs/db/LICENSE | 202 ++++++++ libs/db/README.md | 31 ++ libs/db/backend_test.go | 455 ++++++++++++++++++ libs/db/common_test.go | 190 ++++++++ libs/db/db.go | 50 ++ libs/db/db_test.go | 140 ++++++ libs/db/doc.go | 3 + libs/db/goleveldb.go | 202 ++++++++ libs/db/goleveldb_batch.go | 79 +++ libs/db/goleveldb_iterator.go | 136 ++++++ libs/db/goleveldb_test.go | 70 +++ libs/db/memdb.go | 216 +++++++++ libs/db/memdb_batch.go | 94 ++++ libs/db/memdb_iterator.go | 163 +++++++ libs/db/memdb_test.go | 26 + libs/db/persistence_test.go | 76 +++ libs/db/prefixdb.go | 205 ++++++++ libs/db/prefixdb_batch.go | 51 ++ libs/db/prefixdb_iterator.go | 131 +++++ libs/db/prefixdb_test.go | 123 +++++ libs/db/test_helpers_test.go | 38 ++ libs/db/types.go | 163 +++++++ libs/db/util.go | 51 ++ libs/db/util_test.go | 118 +++++ light/client_benchmark_test.go | 2 +- light/client_test.go | 3 +- light/example_test.go | 3 +- light/light_test.go | 3 +- light/store/db/db.go | 3 +- light/store/db/db_test.go | 3 +- node/node_test.go | 3 +- node/setup.go | 3 +- scripts/keymigrate/migrate.go | 3 +- scripts/scmigrate/migrate.go | 3 +- scripts/scmigrate/migrate_test.go | 3 +- test/e2e/app/app.go | 3 +- test/e2e/tests/app_test.go | 3 +- test/floodclient/client_test.go | 3 +- 104 files changed, 3161 insertions(+), 146 deletions(-) create mode 100644 libs/db/LICENSE create mode 100644 libs/db/README.md create mode 100644 libs/db/backend_test.go create mode 100644 libs/db/common_test.go create mode 100644 libs/db/db.go create mode 100644 libs/db/db_test.go create mode 100644 libs/db/doc.go create mode 100644 libs/db/goleveldb.go create mode 100644 libs/db/goleveldb_batch.go create mode 100644 libs/db/goleveldb_iterator.go create mode 100644 libs/db/goleveldb_test.go create mode 100644 libs/db/memdb.go create mode 100644 libs/db/memdb_batch.go create mode 100644 libs/db/memdb_iterator.go create mode 100644 libs/db/memdb_test.go create mode 100644 libs/db/persistence_test.go create mode 100644 libs/db/prefixdb.go create mode 100644 libs/db/prefixdb_batch.go create mode 100644 libs/db/prefixdb_iterator.go create mode 100644 libs/db/prefixdb_test.go create mode 100644 libs/db/test_helpers_test.go create mode 100644 libs/db/types.go create mode 100644 libs/db/util.go create mode 100644 libs/db/util_test.go diff --git a/abci/example/kvstore/kvstore.go b/abci/example/kvstore/kvstore.go index b7fb85bcc6..02e287e7a0 100644 --- a/abci/example/kvstore/kvstore.go +++ b/abci/example/kvstore/kvstore.go @@ -12,10 +12,11 @@ import ( sync "github.com/sasha-s/go-deadlock" - dbm "github.com/cometbft/cometbft-db" "github.com/cosmos/gogoproto/proto" "github.com/dashpay/dashd-go/btcjson" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/abci/example/code" abci "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/crypto" diff --git a/abci/example/kvstore/state.go b/abci/example/kvstore/state.go index 9852ab3c58..cfdfd14256 100644 --- a/abci/example/kvstore/state.go +++ b/abci/example/kvstore/state.go @@ -7,7 +7,7 @@ import ( "io" "net/url" - dbm "github.com/cometbft/cometbft-db" + dbm "github.com/dashpay/tenderdash/libs/db" "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/crypto" diff --git a/abci/example/kvstore/state_test.go b/abci/example/kvstore/state_test.go index 6ad3ad750a..0a9c2cc793 100644 --- a/abci/example/kvstore/state_test.go +++ b/abci/example/kvstore/state_test.go @@ -4,10 +4,11 @@ import ( "bytes" "testing" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/crypto" tmbytes "github.com/dashpay/tenderdash/libs/bytes" ) diff --git a/abci/example/kvstore/store.go b/abci/example/kvstore/store.go index 786d5267ee..d532e49a8f 100644 --- a/abci/example/kvstore/store.go +++ b/abci/example/kvstore/store.go @@ -6,8 +6,9 @@ import ( "io" "os" - dbm "github.com/cometbft/cometbft-db" "github.com/creachadair/atomicfile" + + dbm "github.com/dashpay/tenderdash/libs/db" ) // StoreFactory reads state and replaces it after a successful write. diff --git a/cmd/tenderdash/commands/light.go b/cmd/tenderdash/commands/light.go index f7c4830755..11c1f25281 100644 --- a/cmd/tenderdash/commands/light.go +++ b/cmd/tenderdash/commands/light.go @@ -11,9 +11,10 @@ import ( "syscall" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/spf13/cobra" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/config" dashcore "github.com/dashpay/tenderdash/dash/core" "github.com/dashpay/tenderdash/libs/log" diff --git a/cmd/tenderdash/commands/reindex_event.go b/cmd/tenderdash/commands/reindex_event.go index 5716876090..8da8ccd002 100644 --- a/cmd/tenderdash/commands/reindex_event.go +++ b/cmd/tenderdash/commands/reindex_event.go @@ -6,9 +6,10 @@ import ( "path/filepath" "strings" - dbm "github.com/cometbft/cometbft-db" "github.com/spf13/cobra" + dbm "github.com/dashpay/tenderdash/libs/db" + abcitypes "github.com/dashpay/tenderdash/abci/types" tmcfg "github.com/dashpay/tenderdash/config" "github.com/dashpay/tenderdash/internal/libs/progressbar" diff --git a/cmd/tenderdash/commands/reindex_event_test.go b/cmd/tenderdash/commands/reindex_event_test.go index de55ad924e..0eee53e329 100644 --- a/cmd/tenderdash/commands/reindex_event_test.go +++ b/cmd/tenderdash/commands/reindex_event_test.go @@ -5,11 +5,12 @@ import ( "errors" "testing" - dbm "github.com/cometbft/cometbft-db" "github.com/spf13/cobra" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + abcitypes "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/config" "github.com/dashpay/tenderdash/internal/state/indexer" diff --git a/config/db.go b/config/db.go index 12c85bf695..22998f8170 100644 --- a/config/db.go +++ b/config/db.go @@ -5,7 +5,7 @@ import ( "fmt" "path/filepath" - dbm "github.com/cometbft/cometbft-db" + dbm "github.com/dashpay/tenderdash/libs/db" "github.com/dashpay/tenderdash/libs/log" tmos "github.com/dashpay/tenderdash/libs/os" diff --git a/dash/quorum/validator_conn_executor_test.go b/dash/quorum/validator_conn_executor_test.go index 14d1c5700f..a6717c3532 100644 --- a/dash/quorum/validator_conn_executor_test.go +++ b/dash/quorum/validator_conn_executor_test.go @@ -6,11 +6,12 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/assert" testifymock "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + abciclient "github.com/dashpay/tenderdash/abci/client" abci "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/crypto" diff --git a/go.mod b/go.mod index faa44f5748..9198c4103a 100644 --- a/go.mod +++ b/go.mod @@ -39,7 +39,6 @@ require ( github.com/Antonboom/testifylint v1.6.4 // indirect github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect github.com/ClickHouse/clickhouse-go-linter v1.2.1 // indirect - github.com/DataDog/zstd v1.5.7 // indirect github.com/Djarvur/go-err113 v0.1.1 // indirect github.com/Masterminds/semver/v3 v3.5.0 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect @@ -86,12 +85,6 @@ require ( github.com/cli/browser v1.3.0 // indirect github.com/clipperhouse/displaywidth v0.11.0 // indirect github.com/clipperhouse/uax29/v2 v2.7.0 // indirect - github.com/cockroachdb/errors v1.12.0 // indirect - github.com/cockroachdb/fifo v0.0.0-20240816210425-c5d0cb0b6fc0 // indirect - github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506 // indirect - github.com/cockroachdb/pebble v1.1.5 // indirect - github.com/cockroachdb/redact v1.1.6 // indirect - github.com/cockroachdb/tokenbucket v0.0.0-20250429170803-42689b6311bb // indirect github.com/cometbft/cometbft v1.0.1 // indirect github.com/containerd/continuity v0.4.5 // indirect github.com/containerd/errdefs v1.0.0 // indirect @@ -105,15 +98,12 @@ require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect github.com/denis-tingaikin/go-header v1.0.0 // indirect - github.com/dgraph-io/badger/v4 v4.9.1 // indirect - github.com/dgraph-io/ristretto/v2 v2.4.0 // indirect github.com/distribution/reference v0.6.0 // indirect github.com/dlclark/regexp2/v2 v2.2.1 // indirect github.com/docker/cli v29.8.0+incompatible // indirect github.com/docker/docker-credential-helpers v0.9.9 // indirect github.com/docker/go-connections v0.8.1 // indirect github.com/docker/go-units v0.5.0 // indirect - github.com/dustin/go-humanize v1.0.1 // indirect github.com/ettle/strcase v0.2.0 // indirect github.com/fatih/color v1.19.0 // indirect github.com/fatih/structtag v1.2.0 // indirect @@ -121,7 +111,6 @@ require ( github.com/firefart/nonamedreturns v1.0.8 // indirect github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/fzipp/gocyclo v0.6.0 // indirect - github.com/getsentry/sentry-go v0.42.0 // indirect github.com/ghostiam/protogetter v1.0.1 // indirect github.com/go-critic/go-critic v0.15.0 // indirect github.com/go-logr/logr v1.4.4 // indirect @@ -140,7 +129,6 @@ require ( github.com/gobwas/glob v0.2.3 // indirect github.com/godoc-lint/godoc-lint v0.11.4 // indirect github.com/gofrs/flock v0.13.1 // indirect - github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/snappy v1.0.0 // indirect github.com/golangci/asciicheck v0.5.0 // indirect github.com/golangci/canonicalheader v0.0.0-20260928145534-e18e5c5a078f // indirect @@ -154,8 +142,6 @@ require ( github.com/golangci/rowserrcheck v0.0.0-20261005233414-e0740d52dee8 // indirect github.com/golangci/swaggoswag v0.0.0-20250504205917-77f2aca3143e // indirect github.com/golangci/unconvert v0.0.0-20250410112200-a129a6e6413e // indirect - github.com/google/btree v1.1.3 // indirect - github.com/google/flatbuffers v25.12.19+incompatible // indirect github.com/google/go-containerregistry v0.22.1 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/gordonklaus/ineffassign v0.2.0 // indirect @@ -175,15 +161,12 @@ require ( github.com/jgautheron/goconst v1.11.0 // indirect github.com/jinzhu/copier v0.4.0 // indirect github.com/jjti/go-spancheck v0.6.5 // indirect - github.com/jmhodges/levigo v1.0.0 // indirect github.com/julz/importas v0.2.0 // indirect github.com/karamaru-alpha/copyloopvar v1.2.2 // indirect github.com/kisielk/errcheck v1.30.0 // indirect github.com/kkHAIKE/contextcheck v1.1.6 // indirect github.com/klauspost/compress v1.20.1 // indirect github.com/klauspost/pgzip v1.2.6 // indirect - github.com/kr/pretty v0.3.1 // indirect - github.com/kr/text v0.2.0 // indirect github.com/kulti/thelper v0.7.1 // indirect github.com/kunwardeep/paralleltest v1.0.16 // indirect github.com/ldez/exptostd v0.4.5 // indirect @@ -193,7 +176,6 @@ require ( github.com/ldez/tagliatelle v0.8.0 // indirect github.com/ldez/usetesting v0.5.0 // indirect github.com/leonklingele/grouper v1.1.2 // indirect - github.com/linxGnu/grocksdb v1.10.2 // indirect github.com/lucasb-eyer/go-colorful v1.4.1 // indirect github.com/macabu/inamedparam v0.2.0 // indirect github.com/manuelarte/embeddedstructfieldcheck v0.4.0 // indirect @@ -224,7 +206,6 @@ require ( github.com/opencontainers/runc v1.3.6 // indirect github.com/pelletier/go-toml/v2 v2.4.3 // indirect github.com/petermattis/goid v0.0.0-20260820044319-269ab09b5261 // indirect - github.com/pkg/errors v0.9.1 // indirect github.com/prometheus/procfs v0.22.0 // indirect github.com/quasilyte/go-ruleguard v0.4.5 // indirect github.com/quasilyte/go-ruleguard/dsl v0.3.23 // indirect @@ -284,7 +265,6 @@ require ( go-simpler.org/sloglint v0.12.0 // indirect go.augendre.info/arangolint v0.4.0 // indirect go.augendre.info/fatcontext v0.10.1 // indirect - go.etcd.io/bbolt v1.4.3 // indirect go.lsp.dev/jsonrpc2 v0.10.0 // indirect go.lsp.dev/pkg v0.0.0-20210717090340-384b27a52fb2 // indirect go.lsp.dev/protocol v0.12.0 // indirect @@ -318,7 +298,6 @@ require ( github.com/btcsuite/btcd/btcec/v2 v2.5.0 github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce github.com/bufbuild/buf v1.73.0 - github.com/cometbft/cometbft-db v1.0.4 github.com/cosmos/gogoproto v1.7.2 github.com/creachadair/atomicfile v0.4.2 github.com/creachadair/tomledit v0.0.29 @@ -330,6 +309,7 @@ require ( github.com/go-pkgz/jrpc v0.4.2 github.com/golang/protobuf v1.5.4 github.com/golangci/golangci-lint/v2 v2.15.0 + github.com/google/btree v1.1.3 github.com/google/go-cmp v0.7.0 github.com/google/gopacket v1.1.19 github.com/google/orderedcode v0.0.1 diff --git a/go.sum b/go.sum index fd34c23bff..219a344508 100644 --- a/go.sum +++ b/go.sum @@ -80,8 +80,6 @@ github.com/ClickHouse/clickhouse-go-linter v1.2.1 h1:zGEKIyd5YL08ieWG/LOUmlau2Dx github.com/ClickHouse/clickhouse-go-linter v1.2.1/go.mod h1:pLorS7ffPTfuUV9M0SJgfHA/h/WQPQUk2FWG9x74cQ4= github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU= github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU= -github.com/DataDog/zstd v1.5.7 h1:ybO8RBeh29qrxIhCA9E8gKY6xfONU9T6G6aP9DTKfLE= -github.com/DataDog/zstd v1.5.7/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= github.com/Djarvur/go-err113 v0.1.1 h1:eHfopDqXRwAi+YmCUas75ZE0+hoBHJ2GQNLYRSxao4g= github.com/Djarvur/go-err113 v0.1.1/go.mod h1:IaWJdYFLg76t2ihfflPZnM1LIQszWOsFDh2hhhAVF6k= github.com/Masterminds/semver/v3 v3.5.0 h1:kQceYJfbupGfZOKZQg0kou0DgAKhzDg2NZPAwZ/2OOE= @@ -212,24 +210,8 @@ github.com/clipperhouse/displaywidth v0.11.0/go.mod h1:bkrFNkf81G8HyVqmKGxsPufD3 github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk= github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaYPt5hWxV3MUfO5dFPFiOXg9CyG5/kCfayTqsJ4= -github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= -github.com/cockroachdb/errors v1.12.0 h1:d7oCs6vuIMUQRVbi6jWWWEJZahLCfJpnJSVobd1/sUo= -github.com/cockroachdb/errors v1.12.0/go.mod h1:SvzfYNNBshAVbZ8wzNc/UPK3w1vf0dKDUP41ucAIf7g= -github.com/cockroachdb/fifo v0.0.0-20240816210425-c5d0cb0b6fc0 h1:pU88SPhIFid6/k0egdR5V6eALQYq2qbSmukrkgIh/0A= -github.com/cockroachdb/fifo v0.0.0-20240816210425-c5d0cb0b6fc0/go.mod h1:9/y3cnZ5GKakj/H4y9r9GTjCvAFta7KLgSHPJJYc52M= -github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506 h1:ASDL+UJcILMqgNeV5jiqR4j+sTuvQNHdf2chuKj1M5k= -github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506/go.mod h1:Mw7HqKr2kdtu6aYGn3tPmAftiP3QPX63LdK/zcariIo= -github.com/cockroachdb/pebble v1.1.5 h1:5AAWCBWbat0uE0blr8qzufZP5tBjkRyy/jWe1QWLnvw= -github.com/cockroachdb/pebble v1.1.5/go.mod h1:17wO9el1YEigxkP/YtV8NtCivQDgoCyBg5c4VR/eOWo= -github.com/cockroachdb/redact v1.1.6 h1:zXJBwDZ84xJNlHl1rMyCojqyIxv+7YUpQiJLQ7n4314= -github.com/cockroachdb/redact v1.1.6/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= -github.com/cockroachdb/tokenbucket v0.0.0-20250429170803-42689b6311bb h1:3bCgBvB8PbJVMX1ouCcSIxvsqKPYM7gs72o0zC76n9g= -github.com/cockroachdb/tokenbucket v0.0.0-20250429170803-42689b6311bb/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ= github.com/cometbft/cometbft v1.0.1 h1:JNVgbpL76sA4kXmBnyZ7iPjFAxi6HVp2l+rdT2RXVUs= github.com/cometbft/cometbft v1.0.1/go.mod h1:r9fEwrbU6Oxs11I2bLsfAiG37OMn0Vip0w9arYU0Nw0= -github.com/cometbft/cometbft-db v1.0.4 h1:cezb8yx/ZWcF124wqUtAFjAuDksS1y1yXedvtprUFxs= -github.com/cometbft/cometbft-db v1.0.4/go.mod h1:M+BtHAGU2XLrpUxo3Nn1nOCcnVCiLM9yx5OuT0u5SCA= github.com/containerd/continuity v0.4.5 h1:ZRoN1sXq9u7V6QoHMcVWGhOwDFqZ4B9i5H6un1Wh0x4= github.com/containerd/continuity v0.4.5/go.mod h1:/lNJvtJKUQStBzpVQ1+rasXO1LAWtUQssk28EZvJ3nE= github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI= @@ -245,7 +227,6 @@ github.com/creachadair/mds v0.29.2 h1:1IBhfyolZUCA53twI1hXembOdpIe4bJ4OGJELBbGrN github.com/creachadair/mds v0.29.2/go.mod h1:dMBTCSy3iS3dwh4Rb1zxeZz2d7K8+N24GCTsayWtQRI= github.com/creachadair/tomledit v0.0.29 h1:dB5CbdwJMpn/fmfAPTAAleXF/KJwY0Ggc1eL/zvZRgk= github.com/creachadair/tomledit v0.0.29/go.mod h1:4SoTXxzHgvzHRMIJPw+o6zK/yXii4VjLrb6/3gCQnyA= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s= github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE= github.com/curioswitch/go-reassign v0.3.0 h1:dh3kpQHuADL3cobV/sSGETA8DOv457dwl+fbBAhrQPs= @@ -275,12 +256,6 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvw github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40= github.com/denis-tingaikin/go-header v1.0.0 h1:QIwZWb3jLC6pOp9NEFldiD8raqRmCE/n0VUdZKW32x8= github.com/denis-tingaikin/go-header v1.0.0/go.mod h1:NT3qKwqsXQYp8WHVgkwxL49qB5jsRmdr9dGQCDfpmZ0= -github.com/dgraph-io/badger/v4 v4.9.1 h1:DocZXZkg5JJHJPtUErA0ibyHxOVUDVoXLSCV6t8NC8w= -github.com/dgraph-io/badger/v4 v4.9.1/go.mod h1:5/MEx97uzdPUHR4KtkNt8asfI2T4JiEiQlV7kWUo8c0= -github.com/dgraph-io/ristretto/v2 v2.4.0 h1:I/w09yLjhdcVD2QV192UJcq8dPBaAJb9pOuMyNy0XlU= -github.com/dgraph-io/ristretto/v2 v2.4.0/go.mod h1:0KsrXtXvnv0EqnzyowllbVJB8yBonswa2lTCK2gGo9E= -github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da h1:aIftn67I1fkbMa512G+w+Pxci9hJPB8oMnkcP3iZF38= -github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= github.com/dlclark/regexp2 v1.12.0 h1:0j4c5qQmnC6XOWNjP3PIXURXN2gWx76rd3KvgdPkCz8= @@ -295,8 +270,6 @@ github.com/docker/go-connections v0.8.1 h1:JibmG5hULs5qXSr/cp/w3Pw5fZuStt4MOHMUE github.com/docker/go-connections v0.8.1/go.mod h1:no1qkHdjq7kLMGUXYAduOhYPSJxxvgWBh7ogVvptn3Q= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= -github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -324,14 +297,10 @@ github.com/fxamacker/cbor/v2 v2.9.6 h1:NHZPxuUjJXQjX9itA785y/5NKSlI4HQ+S7noZsmI7 github.com/fxamacker/cbor/v2 v2.9.6/go.mod h1:4EaZp6ClVunETjQ4GHmGNzysDK91Lr+r6Yz6tJqzVCw= github.com/fzipp/gocyclo v0.6.0 h1:lsblElZG7d3ALtGMx9fmxeTKZaLLpU8mET09yN4BBLo= github.com/fzipp/gocyclo v0.6.0/go.mod h1:rXPyn8fnlpa0R2csP/31uerbiVBugk5whMdlyaLkLoA= -github.com/getsentry/sentry-go v0.42.0 h1:eeFMACuZTbUQf90RE8dE4tXeSe4CZyfvR1MBL7RLEt8= -github.com/getsentry/sentry-go v0.42.0/go.mod h1:eRXCoh3uvmjQLY6qu63BjUZnaBu5L5WhMV1RwYO8W5s= github.com/ghostiam/protogetter v1.0.1 h1:q4LLTx2KJHJpxrfO3BniUDWoFkoqWD/UlHhClBlUlLM= github.com/ghostiam/protogetter v1.0.1/go.mod h1:50Fh5yZfs6SFGrd1FlmT04NcguyEOxyjNK5zGD6/EvM= github.com/go-critic/go-critic v0.15.0 h1:MDUZIQKytIl+vPEc0Igw51m4uLTdi1ZGz2jatEqNs1g= github.com/go-critic/go-critic v0.15.0/go.mod h1:3BPrw8nHATGm3o2n37cssOmJzpySGKCdY8JWkCzxgKQ= -github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= -github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/go-kit/kit v0.13.0 h1:OoneCcHKHQ03LfBpoQCUfCluwd2Vt3ohz+kvbJneZAU= github.com/go-kit/kit v0.13.0/go.mod h1:phqEHMMUbyrCFCTgH48JueqrM3md2HcAZ8N3XE4FKDg= github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= @@ -385,7 +354,6 @@ github.com/godoc-lint/godoc-lint v0.11.4 h1:N9zUYVJ/OkznBbrBsU/zODvua64EUplMBLQW github.com/godoc-lint/godoc-lint v0.11.4/go.mod h1:7usTXoxS0QYIi5usTSCPwR0w/6xLjcz450shXjLn3t4= github.com/gofrs/flock v0.13.1 h1:jjREztyBeSKBZYAC+mgc1laB+xsgy4kYMf3FbKF2UBo= github.com/gofrs/flock v0.13.1/go.mod h1:sf4BFiHwnvgxa25DlQoDqXQnwRMEOwqxRq37P6MzzmE= -github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA= github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= @@ -438,8 +406,6 @@ github.com/golangci/unconvert v0.0.0-20250410112200-a129a6e6413e h1:gD6P7NEo7Eqt github.com/golangci/unconvert v0.0.0-20250410112200-a129a6e6413e/go.mod h1:h+wZwLjUTJnm/P2rwlbJdRPZXOzaT36/FwnPnY2inzc= github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg= github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= -github.com/google/flatbuffers v25.12.19+incompatible h1:haMV2JRRJCe1998HeW/p0X9UaMTK6SDo0ffLn2+DbLs= -github.com/google/flatbuffers v25.12.19+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -521,8 +487,6 @@ github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8= github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg= github.com/jjti/go-spancheck v0.6.5 h1:lmi7pKxa37oKYIMScialXUK6hP3iY5F1gu+mLBPgYB8= github.com/jjti/go-spancheck v0.6.5/go.mod h1:aEogkeatBrbYsyW6y5TgDfihCulDYciL1B7rG2vSsrU= -github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U= -github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ= github.com/jonboulle/clockwork v0.5.0 h1:Hyh9A8u51kptdkR+cqRpT1EebBwTn1oK9YfGYbdFz6I= github.com/jonboulle/clockwork v0.5.0/go.mod h1:3mZlmanh0g2NDKO5TWZVJAfofYk64M7XN3SzBPjZF60= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= @@ -573,8 +537,6 @@ github.com/lib/pq v1.12.3 h1:tTWxr2YLKwIvK90ZXEw8GP7UFHtcbTtty8zsI+YjrfQ= github.com/lib/pq v1.12.3/go.mod h1:/p+8NSbOcwzAEI7wiMXFlgydTwcgTr3OSKMsD2BitpA= github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg= -github.com/linxGnu/grocksdb v1.10.2 h1:y0dXsWYULY15/BZMcwAZzLd13ZuyA470vyoNzWwmqG0= -github.com/linxGnu/grocksdb v1.10.2/go.mod h1:C3CNe9UYc9hlEM2pC82AqiGS3LRW537u9LFV4wIZuHk= github.com/lklimek/gogoproto v0.0.0-20251113111343-8abb160fc047 h1:QS17Zd/yQWxUciJi4/DDgtBuM8d70ibRlQIYKAfmybM= github.com/lklimek/gogoproto v0.0.0-20251113111343-8abb160fc047/go.mod h1:8S7w53P1Y1cHwND64o0BnArT6RmdgIvsBuco6uTllsk= github.com/lucasb-eyer/go-colorful v1.4.1 h1:1EO+WB73+EH8EVbzlrG3KLAfEypQWVHIBqlTf+2hNss= @@ -683,12 +645,7 @@ github.com/pelletier/go-toml/v2 v2.4.3/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8 github.com/petermattis/goid v0.0.0-20250813065127-a731cc31b4fe/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/petermattis/goid v0.0.0-20260820044319-269ab09b5261 h1:lcWAnrqr2nNfDiArwFNHCE4787Mw2tCdVSOXCru0/0E= github.com/petermattis/goid v0.0.0-20260820044319-269ab09b5261/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= -github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= -github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -725,7 +682,6 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rodaine/protogofakeit v0.1.1 h1:ZKouljuRM3A+TArppfBqnH8tGZHOwM/pjvtXe9DaXH8= github.com/rodaine/protogofakeit v0.1.1/go.mod h1:pXn/AstBYMaSfc1/RqH3N82pBuxtWgejz1AlYpY1mI0= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.16.0 h1:O9DK+vNMDVGLr2BeZqmpLeMjiMNkuXfcqntWbZV6S5g= github.com/rogpeppe/go-internal v1.16.0/go.mod h1:DrUVZyrJU+txYW5/1kwtXQSMFio52ZOxX7yM1VHvnxs= github.com/rs/cors v1.11.1 h1:eU3gRzXLRK57F5rKMGMZURNdIG4EoAmX8k94r9wXWHA= @@ -874,8 +830,6 @@ go.augendre.info/arangolint v0.4.0 h1:xSCZjRoS93nXazBSg5d0OGCi9APPLNMmmLrC995tR5 go.augendre.info/arangolint v0.4.0/go.mod h1:l+f/b4plABuFISuKnTGD4RioXiCCgghv2xqst/xOvAA= go.augendre.info/fatcontext v0.10.1 h1:HCS/+eob32cM0mEtmZM6NiXdqvS5KiZmsR+fCubTpbc= go.augendre.info/fatcontext v0.10.1/go.mod h1:pqpGvA9GlrXy+aXkp8L2dKz12Zp4g2FhzcAtwToU+2w= -go.etcd.io/bbolt v1.4.3 h1:dEadXpI6G79deX5prL3QRNP6JB8UxVkqo4UPnHaNXJo= -go.etcd.io/bbolt v1.4.3/go.mod h1:tKQlpPaYCVFctUIgFKFnAlvbmB3tpy1vkTnDWohtc0E= go.lsp.dev/jsonrpc2 v0.10.0 h1:Pr/YcXJoEOTMc/b6OTmcR1DPJ3mSWl/SWiU1Cct6VmI= go.lsp.dev/jsonrpc2 v0.10.0/go.mod h1:fmEzIdXPi/rf6d4uFcayi8HpFP1nBF99ERP1htC72Ac= go.lsp.dev/pkg v0.0.0-20210717090340-384b27a52fb2 h1:hCzQgh6UcwbKgNSRurYWSqh8MufqRRPODRBblutn4TE= diff --git a/internal/blocksync/applier_test.go b/internal/blocksync/applier_test.go index 586d7233cc..31333ac05f 100644 --- a/internal/blocksync/applier_test.go +++ b/internal/blocksync/applier_test.go @@ -7,10 +7,11 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + abciclient "github.com/dashpay/tenderdash/abci/client" abci "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/crypto" diff --git a/internal/blocksync/reactor_test.go b/internal/blocksync/reactor_test.go index d0f565848a..5197cfd830 100644 --- a/internal/blocksync/reactor_test.go +++ b/internal/blocksync/reactor_test.go @@ -7,11 +7,12 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/fortytw2/leaktest" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + abciclient "github.com/dashpay/tenderdash/abci/client" abci "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/config" diff --git a/internal/consensus/byzantine_test.go b/internal/consensus/byzantine_test.go index 2b94eff885..a3e4d48c50 100644 --- a/internal/consensus/byzantine_test.go +++ b/internal/consensus/byzantine_test.go @@ -9,10 +9,11 @@ import ( sync "github.com/sasha-s/go-deadlock" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + abciclient "github.com/dashpay/tenderdash/abci/client" "github.com/dashpay/tenderdash/abci/example/kvstore" abci "github.com/dashpay/tenderdash/abci/types" diff --git a/internal/consensus/common_test.go b/internal/consensus/common_test.go index d9df4e175e..85514655bf 100644 --- a/internal/consensus/common_test.go +++ b/internal/consensus/common_test.go @@ -15,11 +15,12 @@ import ( sync "github.com/sasha-s/go-deadlock" - dbm "github.com/cometbft/cometbft-db" "github.com/dashpay/dashd-go/btcjson" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + abciclient "github.com/dashpay/tenderdash/abci/client" "github.com/dashpay/tenderdash/abci/example/kvstore" abci "github.com/dashpay/tenderdash/abci/types" diff --git a/internal/consensus/flood_reactor_test.go b/internal/consensus/flood_reactor_test.go index b06c744a64..2b6339b086 100644 --- a/internal/consensus/flood_reactor_test.go +++ b/internal/consensus/flood_reactor_test.go @@ -9,9 +9,10 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/crypto" "github.com/dashpay/tenderdash/dash" "github.com/dashpay/tenderdash/internal/p2p" diff --git a/internal/consensus/helper_test.go b/internal/consensus/helper_test.go index cb8cff4d13..bf59ae3ad3 100644 --- a/internal/consensus/helper_test.go +++ b/internal/consensus/helper_test.go @@ -4,9 +4,10 @@ import ( "context" "testing" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + abciclient "github.com/dashpay/tenderdash/abci/client" "github.com/dashpay/tenderdash/abci/example/kvstore" abci "github.com/dashpay/tenderdash/abci/types" diff --git a/internal/consensus/mempool_test.go b/internal/consensus/mempool_test.go index 08ec7aaa97..6b6c5c5583 100644 --- a/internal/consensus/mempool_test.go +++ b/internal/consensus/mempool_test.go @@ -9,10 +9,11 @@ import ( sync "github.com/sasha-s/go-deadlock" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/abci/example/code" abci "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/crypto" diff --git a/internal/consensus/reactor_test.go b/internal/consensus/reactor_test.go index 9787e40d1e..0a1db6cfa8 100644 --- a/internal/consensus/reactor_test.go +++ b/internal/consensus/reactor_test.go @@ -9,12 +9,13 @@ import ( sync "github.com/sasha-s/go-deadlock" - dbm "github.com/cometbft/cometbft-db" "github.com/fortytw2/leaktest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + abciclient "github.com/dashpay/tenderdash/abci/client" "github.com/dashpay/tenderdash/abci/example/kvstore" abci "github.com/dashpay/tenderdash/abci/types" diff --git a/internal/consensus/replay_file.go b/internal/consensus/replay_file.go index 9d201ed776..3996107766 100644 --- a/internal/consensus/replay_file.go +++ b/internal/consensus/replay_file.go @@ -10,7 +10,7 @@ import ( "strconv" "strings" - dbm "github.com/cometbft/cometbft-db" + dbm "github.com/dashpay/tenderdash/libs/db" "github.com/dashpay/tenderdash/config" "github.com/dashpay/tenderdash/internal/eventbus" diff --git a/internal/consensus/replay_test.go b/internal/consensus/replay_test.go index d2ce9c1332..5c23bafc49 100644 --- a/internal/consensus/replay_test.go +++ b/internal/consensus/replay_test.go @@ -13,13 +13,14 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/cosmos/gogoproto/proto" "github.com/dashpay/dashd-go/btcjson" "github.com/fortytw2/leaktest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + abciclient "github.com/dashpay/tenderdash/abci/client" "github.com/dashpay/tenderdash/abci/example/kvstore" abci "github.com/dashpay/tenderdash/abci/types" diff --git a/internal/consensus/replayer_test.go b/internal/consensus/replayer_test.go index 440c2719e4..644a546ab1 100644 --- a/internal/consensus/replayer_test.go +++ b/internal/consensus/replayer_test.go @@ -7,11 +7,12 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/dashd-go/btcjson" abciclient "github.com/dashpay/tenderdash/abci/client" diff --git a/internal/evidence/duplicate_lookup_test.go b/internal/evidence/duplicate_lookup_test.go index 5a4d6518b4..ff87495db2 100644 --- a/internal/evidence/duplicate_lookup_test.go +++ b/internal/evidence/duplicate_lookup_test.go @@ -4,10 +4,11 @@ import ( "context" "testing" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/crypto" "github.com/dashpay/tenderdash/libs/log" tmrand "github.com/dashpay/tenderdash/libs/rand" diff --git a/internal/evidence/evidence_admission_test.go b/internal/evidence/evidence_admission_test.go index b297504ccf..93a8964033 100644 --- a/internal/evidence/evidence_admission_test.go +++ b/internal/evidence/evidence_admission_test.go @@ -9,7 +9,6 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/dashpay/dashd-go/btcjson" "github.com/fortytw2/leaktest" "github.com/jonboulle/clockwork" @@ -17,6 +16,8 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/crypto" "github.com/dashpay/tenderdash/internal/eventbus" "github.com/dashpay/tenderdash/internal/evidence" diff --git a/internal/evidence/pool.go b/internal/evidence/pool.go index 5fe7348159..58ac1dade4 100644 --- a/internal/evidence/pool.go +++ b/internal/evidence/pool.go @@ -10,11 +10,12 @@ import ( sync "github.com/sasha-s/go-deadlock" - dbm "github.com/cometbft/cometbft-db" "github.com/cosmos/gogoproto/proto" gogotypes "github.com/cosmos/gogoproto/types" "github.com/google/orderedcode" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/internal/eventbus" clist "github.com/dashpay/tenderdash/internal/libs/clist" sm "github.com/dashpay/tenderdash/internal/state" diff --git a/internal/evidence/pool_test.go b/internal/evidence/pool_test.go index 99665f5f68..48eaa71c94 100644 --- a/internal/evidence/pool_test.go +++ b/internal/evidence/pool_test.go @@ -5,12 +5,13 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/dashpay/dashd-go/btcjson" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/crypto" "github.com/dashpay/tenderdash/internal/consensus/versioned/selectproposer" psmocks "github.com/dashpay/tenderdash/internal/consensus/versioned/selectproposer/mocks" diff --git a/internal/evidence/reactor_retry_test.go b/internal/evidence/reactor_retry_test.go index 309e235edf..e74443b2b6 100644 --- a/internal/evidence/reactor_retry_test.go +++ b/internal/evidence/reactor_retry_test.go @@ -6,12 +6,13 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/dashpay/dashd-go/btcjson" "github.com/fortytw2/leaktest" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/crypto" "github.com/dashpay/tenderdash/internal/eventbus" "github.com/dashpay/tenderdash/internal/evidence" diff --git a/internal/evidence/reactor_test.go b/internal/evidence/reactor_test.go index 5c4c4a4199..5675be8ce8 100644 --- a/internal/evidence/reactor_test.go +++ b/internal/evidence/reactor_test.go @@ -11,13 +11,14 @@ import ( sync "github.com/sasha-s/go-deadlock" - dbm "github.com/cometbft/cometbft-db" "github.com/dashpay/dashd-go/btcjson" "github.com/fortytw2/leaktest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/crypto" "github.com/dashpay/tenderdash/crypto/bls12381" "github.com/dashpay/tenderdash/internal/eventbus" diff --git a/internal/evidence/verify_test.go b/internal/evidence/verify_test.go index 87fb65e077..5a37c3d5ef 100644 --- a/internal/evidence/verify_test.go +++ b/internal/evidence/verify_test.go @@ -5,12 +5,13 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/dashpay/dashd-go/btcjson" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/crypto" "github.com/dashpay/tenderdash/internal/eventbus" "github.com/dashpay/tenderdash/internal/evidence" diff --git a/internal/p2p/p2ptest/network.go b/internal/p2p/p2ptest/network.go index 953ee60042..030d150007 100644 --- a/internal/p2p/p2ptest/network.go +++ b/internal/p2p/p2ptest/network.go @@ -6,9 +6,10 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/config" "github.com/dashpay/tenderdash/crypto" "github.com/dashpay/tenderdash/crypto/ed25519" diff --git a/internal/p2p/peermanager.go b/internal/p2p/peermanager.go index 6aa79b36f0..ac11a29a5a 100644 --- a/internal/p2p/peermanager.go +++ b/internal/p2p/peermanager.go @@ -10,13 +10,14 @@ import ( "sort" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/cosmos/gogoproto/jsonpb" "github.com/cosmos/gogoproto/proto" "github.com/google/orderedcode" "github.com/rs/zerolog" sync "github.com/sasha-s/go-deadlock" + dbm "github.com/dashpay/tenderdash/libs/db" + tmsync "github.com/dashpay/tenderdash/internal/libs/sync" "github.com/dashpay/tenderdash/libs/log" p2pproto "github.com/dashpay/tenderdash/proto/tendermint/p2p" diff --git a/internal/p2p/peermanager_protected_test.go b/internal/p2p/peermanager_protected_test.go index a4997563eb..98c63e0787 100644 --- a/internal/p2p/peermanager_protected_test.go +++ b/internal/p2p/peermanager_protected_test.go @@ -6,9 +6,10 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/crypto/ed25519" "github.com/dashpay/tenderdash/types" ) diff --git a/internal/p2p/peermanager_reconnect_test.go b/internal/p2p/peermanager_reconnect_test.go index 6b1a4ca775..a137b27702 100644 --- a/internal/p2p/peermanager_reconnect_test.go +++ b/internal/p2p/peermanager_reconnect_test.go @@ -7,9 +7,10 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/internal/p2p" "github.com/dashpay/tenderdash/types" ) diff --git a/internal/p2p/peermanager_retry_test.go b/internal/p2p/peermanager_retry_test.go index 168898fa68..bde6f6bb6b 100644 --- a/internal/p2p/peermanager_retry_test.go +++ b/internal/p2p/peermanager_retry_test.go @@ -7,9 +7,10 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/types" ) diff --git a/internal/p2p/peermanager_scoring_test.go b/internal/p2p/peermanager_scoring_test.go index c0469ccf9f..e2e62cbf6c 100644 --- a/internal/p2p/peermanager_scoring_test.go +++ b/internal/p2p/peermanager_scoring_test.go @@ -6,9 +6,10 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/crypto/ed25519" "github.com/dashpay/tenderdash/libs/log" "github.com/dashpay/tenderdash/types" diff --git a/internal/p2p/peermanager_test.go b/internal/p2p/peermanager_test.go index b49f4ada59..939b94b0e2 100644 --- a/internal/p2p/peermanager_test.go +++ b/internal/p2p/peermanager_test.go @@ -8,12 +8,13 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/fortytw2/leaktest" "github.com/google/orderedcode" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/internal/p2p" "github.com/dashpay/tenderdash/libs/log" p2pproto "github.com/dashpay/tenderdash/proto/tendermint/p2p" diff --git a/internal/p2p/pex/reactor_deadlock_test.go b/internal/p2p/pex/reactor_deadlock_test.go index 1ecf0d3405..27c49577d8 100644 --- a/internal/p2p/pex/reactor_deadlock_test.go +++ b/internal/p2p/pex/reactor_deadlock_test.go @@ -6,9 +6,10 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/internal/p2p" "github.com/dashpay/tenderdash/libs/log" "github.com/dashpay/tenderdash/types" diff --git a/internal/p2p/pex/reactor_test.go b/internal/p2p/pex/reactor_test.go index 6602c677bd..617dfd8011 100644 --- a/internal/p2p/pex/reactor_test.go +++ b/internal/p2p/pex/reactor_test.go @@ -7,9 +7,10 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/config" "github.com/dashpay/tenderdash/crypto/ed25519" "github.com/dashpay/tenderdash/internal/p2p" diff --git a/internal/p2p/router_init_test.go b/internal/p2p/router_init_test.go index af22cc3fed..1110fd8281 100644 --- a/internal/p2p/router_init_test.go +++ b/internal/p2p/router_init_test.go @@ -6,9 +6,10 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/libs/log" "github.com/dashpay/tenderdash/types" ) diff --git a/internal/p2p/router_test.go b/internal/p2p/router_test.go index da7db4a65a..8c49c76ace 100644 --- a/internal/p2p/router_test.go +++ b/internal/p2p/router_test.go @@ -11,7 +11,6 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" gogotypes "github.com/cosmos/gogoproto/types" "github.com/fortytw2/leaktest" sync "github.com/sasha-s/go-deadlock" @@ -19,6 +18,8 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/crypto" tmsync "github.com/dashpay/tenderdash/internal/libs/sync" "github.com/dashpay/tenderdash/internal/p2p" diff --git a/internal/rpc/core/blocks_test.go b/internal/rpc/core/blocks_test.go index 4a2cf4f50b..cd722b81a8 100644 --- a/internal/rpc/core/blocks_test.go +++ b/internal/rpc/core/blocks_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - dbm "github.com/cometbft/cometbft-db" + dbm "github.com/dashpay/tenderdash/libs/db" abci "github.com/dashpay/tenderdash/abci/types" sm "github.com/dashpay/tenderdash/internal/state" diff --git a/internal/rpc/core/rpc_validation_test.go b/internal/rpc/core/rpc_validation_test.go index 4d668fe969..18949d24df 100644 --- a/internal/rpc/core/rpc_validation_test.go +++ b/internal/rpc/core/rpc_validation_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - dbm "github.com/cometbft/cometbft-db" + dbm "github.com/dashpay/tenderdash/libs/db" mempoolmocks "github.com/dashpay/tenderdash/internal/mempool/mocks" "github.com/dashpay/tenderdash/internal/state/indexer" diff --git a/internal/state/execution_test.go b/internal/state/execution_test.go index 6d4d9f7601..739972f641 100644 --- a/internal/state/execution_test.go +++ b/internal/state/execution_test.go @@ -9,11 +9,12 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + abciclient "github.com/dashpay/tenderdash/abci/client" abciclientmocks "github.com/dashpay/tenderdash/abci/client/mocks" abci "github.com/dashpay/tenderdash/abci/types" diff --git a/internal/state/helpers_test.go b/internal/state/helpers_test.go index 12f26316d7..e883011b30 100644 --- a/internal/state/helpers_test.go +++ b/internal/state/helpers_test.go @@ -5,10 +5,11 @@ import ( "fmt" "testing" - dbm "github.com/cometbft/cometbft-db" "github.com/dashpay/dashd-go/btcjson" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + abci "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/crypto" selectproposer "github.com/dashpay/tenderdash/internal/consensus/versioned/selectproposer" diff --git a/internal/state/indexer/block/kv/kv.go b/internal/state/indexer/block/kv/kv.go index 92edab6d10..45a315318a 100644 --- a/internal/state/indexer/block/kv/kv.go +++ b/internal/state/indexer/block/kv/kv.go @@ -8,9 +8,10 @@ import ( "strconv" "strings" - dbm "github.com/cometbft/cometbft-db" "github.com/google/orderedcode" + dbm "github.com/dashpay/tenderdash/libs/db" + abci "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/internal/pubsub/query" "github.com/dashpay/tenderdash/internal/pubsub/query/syntax" diff --git a/internal/state/indexer/block/kv/kv_test.go b/internal/state/indexer/block/kv/kv_test.go index ada8c05f61..b9d01ec17d 100644 --- a/internal/state/indexer/block/kv/kv_test.go +++ b/internal/state/indexer/block/kv/kv_test.go @@ -5,9 +5,10 @@ import ( "fmt" "testing" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + abci "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/internal/pubsub/query" blockidxkv "github.com/dashpay/tenderdash/internal/state/indexer/block/kv" diff --git a/internal/state/indexer/indexer_service_test.go b/internal/state/indexer/indexer_service_test.go index 31da483020..d3cf2a14dc 100644 --- a/internal/state/indexer/indexer_service_test.go +++ b/internal/state/indexer/indexer_service_test.go @@ -9,12 +9,13 @@ import ( "time" "github.com/adlio/schema" - dbm "github.com/cometbft/cometbft-db" "github.com/ory/dockertest/v3" "github.com/ory/dockertest/v3/docker" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + abci "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/internal/eventbus" "github.com/dashpay/tenderdash/internal/state/indexer" diff --git a/internal/state/indexer/sink/kv/kv.go b/internal/state/indexer/sink/kv/kv.go index 26a28dfca7..2fb361919d 100644 --- a/internal/state/indexer/sink/kv/kv.go +++ b/internal/state/indexer/sink/kv/kv.go @@ -3,7 +3,7 @@ package kv import ( "context" - dbm "github.com/cometbft/cometbft-db" + dbm "github.com/dashpay/tenderdash/libs/db" abci "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/internal/pubsub/query" diff --git a/internal/state/indexer/sink/kv/kv_test.go b/internal/state/indexer/sink/kv/kv_test.go index ae1d598b48..cff2fe7ce4 100644 --- a/internal/state/indexer/sink/kv/kv_test.go +++ b/internal/state/indexer/sink/kv/kv_test.go @@ -5,7 +5,7 @@ import ( "fmt" "testing" - dbm "github.com/cometbft/cometbft-db" + dbm "github.com/dashpay/tenderdash/libs/db" "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/assert" diff --git a/internal/state/indexer/tx/kv/kv.go b/internal/state/indexer/tx/kv/kv.go index b865f5dbfd..96a7276ef6 100644 --- a/internal/state/indexer/tx/kv/kv.go +++ b/internal/state/indexer/tx/kv/kv.go @@ -7,10 +7,11 @@ import ( "strconv" "strings" - dbm "github.com/cometbft/cometbft-db" "github.com/cosmos/gogoproto/proto" "github.com/google/orderedcode" + dbm "github.com/dashpay/tenderdash/libs/db" + abci "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/internal/pubsub/query" "github.com/dashpay/tenderdash/internal/pubsub/query/syntax" diff --git a/internal/state/indexer/tx/kv/kv_bench_test.go b/internal/state/indexer/tx/kv/kv_bench_test.go index ed6a8dac4f..e8e6cb25c6 100644 --- a/internal/state/indexer/tx/kv/kv_bench_test.go +++ b/internal/state/indexer/tx/kv/kv_bench_test.go @@ -6,7 +6,7 @@ import ( "fmt" "testing" - dbm "github.com/cometbft/cometbft-db" + dbm "github.com/dashpay/tenderdash/libs/db" abci "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/internal/pubsub/query" diff --git a/internal/state/indexer/tx/kv/kv_errors_test.go b/internal/state/indexer/tx/kv/kv_errors_test.go index cce1eed255..b63479f08f 100644 --- a/internal/state/indexer/tx/kv/kv_errors_test.go +++ b/internal/state/indexer/tx/kv/kv_errors_test.go @@ -6,9 +6,10 @@ import ( "fmt" "testing" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + abci "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/internal/pubsub/query" "github.com/dashpay/tenderdash/types" diff --git a/internal/state/indexer/tx/kv/kv_test.go b/internal/state/indexer/tx/kv/kv_test.go index b93e1fb54e..4f442f593e 100644 --- a/internal/state/indexer/tx/kv/kv_test.go +++ b/internal/state/indexer/tx/kv/kv_test.go @@ -5,11 +5,12 @@ import ( "fmt" "testing" - dbm "github.com/cometbft/cometbft-db" "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + abci "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/internal/pubsub/query" "github.com/dashpay/tenderdash/internal/state/indexer" diff --git a/internal/state/nofsync_test.go b/internal/state/nofsync_test.go index 1569de1524..b91f08e8bb 100644 --- a/internal/state/nofsync_test.go +++ b/internal/state/nofsync_test.go @@ -3,9 +3,10 @@ package state_test import ( "testing" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + abci "github.com/dashpay/tenderdash/abci/types" sm "github.com/dashpay/tenderdash/internal/state" "github.com/dashpay/tenderdash/internal/test/dbspy" diff --git a/internal/state/rollback_test.go b/internal/state/rollback_test.go index b7d9d3ed2f..1681a6002f 100644 --- a/internal/state/rollback_test.go +++ b/internal/state/rollback_test.go @@ -3,9 +3,10 @@ package state_test import ( "testing" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/internal/state" "github.com/dashpay/tenderdash/internal/state/mocks" "github.com/dashpay/tenderdash/internal/test/factory" diff --git a/internal/state/state_test.go b/internal/state/state_test.go index 873338b2d2..e57adf375a 100644 --- a/internal/state/state_test.go +++ b/internal/state/state_test.go @@ -6,11 +6,12 @@ import ( "os" "testing" - dbm "github.com/cometbft/cometbft-db" "github.com/dashpay/dashd-go/btcjson" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/abci/example/kvstore" abci "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/config" diff --git a/internal/state/store.go b/internal/state/store.go index c857fa630e..e899ad29e3 100644 --- a/internal/state/store.go +++ b/internal/state/store.go @@ -5,10 +5,11 @@ import ( "errors" "fmt" - dbm "github.com/cometbft/cometbft-db" "github.com/cosmos/gogoproto/proto" "github.com/google/orderedcode" + dbm "github.com/dashpay/tenderdash/libs/db" + abci "github.com/dashpay/tenderdash/abci/types" selectproposer "github.com/dashpay/tenderdash/internal/consensus/versioned/selectproposer" "github.com/dashpay/tenderdash/libs/log" @@ -113,7 +114,7 @@ type Store interface { Close() error } -// dbStore wraps a db (github.com/cometbft/cometbft-db) +// dbStore wraps a db (github.com/dashpay/tenderdash/libs/db) type dbStore struct { db dbm.DB logger log.Logger diff --git a/internal/state/store_test.go b/internal/state/store_test.go index e63839b69c..017638c6b2 100644 --- a/internal/state/store_test.go +++ b/internal/state/store_test.go @@ -6,12 +6,13 @@ import ( "os" "testing" - dbm "github.com/cometbft/cometbft-db" "github.com/dashpay/dashd-go/btcjson" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + abci "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/config" "github.com/dashpay/tenderdash/crypto" diff --git a/internal/state/validation_test.go b/internal/state/validation_test.go index a82864c23a..e95e02d57e 100644 --- a/internal/state/validation_test.go +++ b/internal/state/validation_test.go @@ -8,11 +8,12 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + abciclient "github.com/dashpay/tenderdash/abci/client" abci "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/crypto" diff --git a/internal/statesync/params_response_test.go b/internal/statesync/params_response_test.go index 61b87cecf6..76a18a6d85 100644 --- a/internal/statesync/params_response_test.go +++ b/internal/statesync/params_response_test.go @@ -5,10 +5,11 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + coremocks "github.com/dashpay/tenderdash/dash/core/mocks" "github.com/dashpay/tenderdash/internal/p2p" p2pmocks "github.com/dashpay/tenderdash/internal/p2p/mocks" diff --git a/internal/statesync/reactor_test.go b/internal/statesync/reactor_test.go index 5a87f7a399..70a39c6d5b 100644 --- a/internal/statesync/reactor_test.go +++ b/internal/statesync/reactor_test.go @@ -10,12 +10,13 @@ import ( sync "github.com/sasha-s/go-deadlock" - dbm "github.com/cometbft/cometbft-db" "github.com/dashpay/dashd-go/btcjson" "github.com/fortytw2/leaktest" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + clientmocks "github.com/dashpay/tenderdash/abci/client/mocks" abci "github.com/dashpay/tenderdash/abci/types" "github.com/dashpay/tenderdash/config" diff --git a/internal/statesync/stateprovider.go b/internal/statesync/stateprovider.go index 2eb5d2c404..7de84607d1 100644 --- a/internal/statesync/stateprovider.go +++ b/internal/statesync/stateprovider.go @@ -12,9 +12,10 @@ import ( sync "github.com/sasha-s/go-deadlock" - dbm "github.com/cometbft/cometbft-db" "github.com/dashpay/dashd-go/btcjson" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/crypto" "github.com/dashpay/tenderdash/crypto/bls12381" dashcore "github.com/dashpay/tenderdash/dash/core" diff --git a/internal/store/nofsync_test.go b/internal/store/nofsync_test.go index a865a6096d..4216aead32 100644 --- a/internal/store/nofsync_test.go +++ b/internal/store/nofsync_test.go @@ -3,9 +3,10 @@ package store import ( "testing" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/config" sm "github.com/dashpay/tenderdash/internal/state" "github.com/dashpay/tenderdash/internal/state/test/factory" diff --git a/internal/store/store.go b/internal/store/store.go index bd3086a0b7..ef88c6ce8c 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -6,10 +6,11 @@ import ( "fmt" "strconv" - dbm "github.com/cometbft/cometbft-db" "github.com/cosmos/gogoproto/proto" "github.com/google/orderedcode" + dbm "github.com/dashpay/tenderdash/libs/db" + tmproto "github.com/dashpay/tenderdash/proto/tendermint/types" "github.com/dashpay/tenderdash/types" ) diff --git a/internal/store/store_test.go b/internal/store/store_test.go index 88b263976b..447ba59cfe 100644 --- a/internal/store/store_test.go +++ b/internal/store/store_test.go @@ -8,10 +8,11 @@ import ( "strings" "testing" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/config" "github.com/dashpay/tenderdash/crypto" "github.com/dashpay/tenderdash/crypto/bls12381" diff --git a/internal/test/dbspy/dbspy.go b/internal/test/dbspy/dbspy.go index 8a61f363e1..1c9ba4a90a 100644 --- a/internal/test/dbspy/dbspy.go +++ b/internal/test/dbspy/dbspy.go @@ -3,7 +3,7 @@ // fsync. package dbspy -import dbm "github.com/cometbft/cometbft-db" +import dbm "github.com/dashpay/tenderdash/libs/db" // DB counts the syncing and non-syncing writes made through it. type DB struct { diff --git a/libs/db/LICENSE b/libs/db/LICENSE new file mode 100644 index 0000000000..d645695673 --- /dev/null +++ b/libs/db/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/libs/db/README.md b/libs/db/README.md new file mode 100644 index 0000000000..e6c8cc67d5 --- /dev/null +++ b/libs/db/README.md @@ -0,0 +1,31 @@ +# Tenderdash database adapters + +This package provides Tenderdash's GoLevelDB, MemDB and PrefixDB adapters and +the DB, Batch and Iterator interfaces. GoLevelDB uses `.db` directories; +MemDB is transient storage. The engine versions are pinned in the root `go.mod`. + +The implementation and its original tests derive from +[`cometbft-db v1.0.4`](https://github.com/cometbft/cometbft-db/tree/v1.0.4), +commit `f5ed70fe0e068393bf5aa4fe84162b6ad57ce19e`, +under the Apache License 2.0 included in [LICENSE](LICENSE). +CometBFT DB is a fork of [tm-db](https://github.com/tendermint/tm-db). +The retained source files are `db.go`, `types.go`, `util.go`, `goleveldb*.go`, +`memdb*.go`, and `prefixdb*.go`. Only GoLevelDB and MemDB are registered. +The upstream test helper `test_helpers.go` is named `test_helpers_test.go` here. +Local changes narrow backend registration, close the debugging Print iterator, +and adapt tests and documentation to the retained implementations. + +GoLevelDB returns nil from Get and false from Has for a stored empty value; +MemDB returns a non-nil empty slice and true. This inherited difference is +characterized by tests and tracked in [#1554](https://github.com/dashpay/tenderdash/issues/1554). +Use non-empty values when callers must distinguish existing from absent keys. + +Callers must close databases, batches and iterators. PrefixDB borrows its prefix +slice, so callers must not mutate it. Closing a PrefixDB closes its underlying +database; owners sharing a database across prefixes must coordinate that lifetime. +PrefixDB compaction bounds are passed directly to the underlying database. + +Custom DB providers must import `github.com/dashpay/tenderdash/libs/db` for their +DB, Batch and Iterator types. The interfaces are separate Go types from those in +`cometbft-db`; an implementation returning that module's Batch or Iterator +interfaces requires an import update or an adapter. diff --git a/libs/db/backend_test.go b/libs/db/backend_test.go new file mode 100644 index 0000000000..d3153ca5e2 --- /dev/null +++ b/libs/db/backend_test.go @@ -0,0 +1,455 @@ +// Modified by Tenderdash contributors from cometbft-db v1.0.4. +// See README.md for provenance and LICENSE for license terms. + +package db + +import ( + "fmt" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// Register a test backend for PrefixDB as well, with some unrelated junk data. +func init() { + //nolint: errcheck, revive // probably should check errors? + registerDBCreator("prefixdb", func(name, dir string) (DB, error) { + mdb := NewMemDB() + mdb.Set([]byte("a"), []byte{1}) + mdb.Set([]byte("b"), []byte{2}) + mdb.Set([]byte("t"), []byte{20}) + mdb.Set([]byte("test"), []byte{0}) + mdb.Set([]byte("u"), []byte{21}) + mdb.Set([]byte("z"), []byte{26}) + return NewPrefixDB(mdb, []byte("test/")), nil + }) +} + +func cleanupDBDir(dir, name string) { + err := os.RemoveAll(filepath.Join(dir, name) + ".db") + if err != nil { + panic(err) + } +} + +func testBackendGetSetDelete(t *testing.T, backend BackendType) { + t.Helper() + // Default + dirname, err := os.MkdirTemp("", fmt.Sprintf("test_backend_%s_", backend)) + require.Nil(t, err) + name := fmt.Sprintf("testdb_%x", randStr(12)) + db, err := NewDB(name, backend, dirname) + require.NoError(t, err) + defer cleanupDBDir(dirname, name) + defer db.Close() + + // A nonexistent key should return nil. + value, err := db.Get([]byte("a")) + require.NoError(t, err) + require.Nil(t, value) + + ok, err := db.Has([]byte("a")) + require.NoError(t, err) + require.False(t, ok) + + // Set and get a value. + err = db.Set([]byte("a"), []byte{0x01}) + require.NoError(t, err) + + ok, err = db.Has([]byte("a")) + require.NoError(t, err) + require.True(t, ok) + + value, err = db.Get([]byte("a")) + require.NoError(t, err) + require.Equal(t, []byte{0x01}, value) + + err = db.SetSync([]byte("b"), []byte{0x02}) + require.NoError(t, err) + + value, err = db.Get([]byte("b")) + require.NoError(t, err) + require.Equal(t, []byte{0x02}, value) + + // Deleting a non-existent value is fine. + err = db.Delete([]byte("x")) + require.NoError(t, err) + + err = db.DeleteSync([]byte("x")) + require.NoError(t, err) + + // Delete a value. + err = db.Delete([]byte("a")) + require.NoError(t, err) + + value, err = db.Get([]byte("a")) + require.NoError(t, err) + require.Nil(t, value) + + err = db.DeleteSync([]byte("b")) + require.NoError(t, err) + + value, err = db.Get([]byte("b")) + require.NoError(t, err) + require.Nil(t, value) + + // Setting, getting, and deleting an empty key should error. + _, err = db.Get([]byte{}) + require.Equal(t, errKeyEmpty, err) + _, err = db.Get(nil) + require.Equal(t, errKeyEmpty, err) + + _, err = db.Has([]byte{}) + require.Equal(t, errKeyEmpty, err) + _, err = db.Has(nil) + require.Equal(t, errKeyEmpty, err) + + err = db.Set([]byte{}, []byte{0x01}) + require.Equal(t, errKeyEmpty, err) + err = db.Set(nil, []byte{0x01}) + require.Equal(t, errKeyEmpty, err) + err = db.SetSync([]byte{}, []byte{0x01}) + require.Equal(t, errKeyEmpty, err) + err = db.SetSync(nil, []byte{0x01}) + require.Equal(t, errKeyEmpty, err) + + err = db.Delete([]byte{}) + require.Equal(t, errKeyEmpty, err) + err = db.Delete(nil) + require.Equal(t, errKeyEmpty, err) + err = db.DeleteSync([]byte{}) + require.Equal(t, errKeyEmpty, err) + err = db.DeleteSync(nil) + require.Equal(t, errKeyEmpty, err) + + // Setting a nil value should error, but an empty value is fine. + err = db.Set([]byte("x"), nil) + require.Equal(t, errValueNil, err) + err = db.SetSync([]byte("x"), nil) + require.Equal(t, errValueNil, err) + + err = db.Set([]byte("x"), []byte{}) + require.NoError(t, err) + err = db.SetSync([]byte("x"), []byte{}) + require.NoError(t, err) + value, err = db.Get([]byte("x")) + require.NoError(t, err) + has, err := db.Has([]byte("x")) + require.NoError(t, err) + if backend == GoLevelDBBackend { + require.Nil(t, value) + require.False(t, has, "GoLevelDB cannot distinguish a stored empty value from an absent key") + } else { + require.Equal(t, []byte{}, value) + require.True(t, has) + } + + err = db.Compact(nil, nil) + require.NoError(t, err) + + err = db.Set([]byte("y"), []byte{}) + require.NoError(t, err) + + err = db.Compact(nil, nil) + require.NoError(t, err) + +} + +func TestBackendsGetSetDelete(t *testing.T) { + for dbType := range backends { + t.Run(string(dbType), func(t *testing.T) { + testBackendGetSetDelete(t, dbType) + }) + } +} + +func TestDBIterator(t *testing.T) { + for dbType := range backends { + t.Run(string(dbType), func(t *testing.T) { + testDBIterator(t, dbType) + }) + } +} + +func testDBIterator(t *testing.T, backend BackendType) { + t.Helper() + + name := fmt.Sprintf("test_%x", randStr(12)) + dir := os.TempDir() + db, err := NewDB(name, backend, dir) + require.NoError(t, err) + defer cleanupDBDir(dir, name) + defer db.Close() + + for i := 0; i < 10; i++ { + if i != 6 { // but skip 6. + err := db.Set(int642Bytes(int64(i)), []byte{}) + require.NoError(t, err) + } + } + + // Blank iterator keys should error + _, err = db.Iterator([]byte{}, nil) + require.Equal(t, errKeyEmpty, err) + _, err = db.Iterator(nil, []byte{}) + require.Equal(t, errKeyEmpty, err) + _, err = db.ReverseIterator([]byte{}, nil) + require.Equal(t, errKeyEmpty, err) + _, err = db.ReverseIterator(nil, []byte{}) + require.Equal(t, errKeyEmpty, err) + + itr, err := db.Iterator(nil, nil) + require.NoError(t, err) + verifyIterator(t, itr, []int64{0, 1, 2, 3, 4, 5, 7, 8, 9}, "forward iterator") + + ritr, err := db.ReverseIterator(nil, nil) + require.NoError(t, err) + verifyIterator(t, ritr, []int64{9, 8, 7, 5, 4, 3, 2, 1, 0}, "reverse iterator") + + itr, err = db.Iterator(nil, int642Bytes(0)) + require.NoError(t, err) + verifyIterator(t, itr, []int64(nil), "forward iterator to 0") + + ritr, err = db.ReverseIterator(int642Bytes(10), nil) + require.NoError(t, err) + verifyIterator(t, ritr, []int64(nil), "reverse iterator from 10 (ex)") + + itr, err = db.Iterator(int642Bytes(0), nil) + require.NoError(t, err) + verifyIterator(t, itr, []int64{0, 1, 2, 3, 4, 5, 7, 8, 9}, "forward iterator from 0") + + itr, err = db.Iterator(int642Bytes(1), nil) + require.NoError(t, err) + verifyIterator(t, itr, []int64{1, 2, 3, 4, 5, 7, 8, 9}, "forward iterator from 1") + + ritr, err = db.ReverseIterator(nil, int642Bytes(10)) + require.NoError(t, err) + verifyIterator(t, ritr, + []int64{9, 8, 7, 5, 4, 3, 2, 1, 0}, "reverse iterator from 10 (ex)") + + ritr, err = db.ReverseIterator(nil, int642Bytes(9)) + require.NoError(t, err) + verifyIterator(t, ritr, + []int64{8, 7, 5, 4, 3, 2, 1, 0}, "reverse iterator from 9 (ex)") + + ritr, err = db.ReverseIterator(nil, int642Bytes(8)) + require.NoError(t, err) + verifyIterator(t, ritr, + []int64{7, 5, 4, 3, 2, 1, 0}, "reverse iterator from 8 (ex)") + + itr, err = db.Iterator(int642Bytes(5), int642Bytes(6)) + require.NoError(t, err) + verifyIterator(t, itr, []int64{5}, "forward iterator from 5 to 6") + + itr, err = db.Iterator(int642Bytes(5), int642Bytes(7)) + require.NoError(t, err) + verifyIterator(t, itr, []int64{5}, "forward iterator from 5 to 7") + + itr, err = db.Iterator(int642Bytes(5), int642Bytes(8)) + require.NoError(t, err) + verifyIterator(t, itr, []int64{5, 7}, "forward iterator from 5 to 8") + + itr, err = db.Iterator(int642Bytes(6), int642Bytes(7)) + require.NoError(t, err) + verifyIterator(t, itr, []int64(nil), "forward iterator from 6 to 7") + + itr, err = db.Iterator(int642Bytes(6), int642Bytes(8)) + require.NoError(t, err) + verifyIterator(t, itr, []int64{7}, "forward iterator from 6 to 8") + + itr, err = db.Iterator(int642Bytes(7), int642Bytes(8)) + require.NoError(t, err) + verifyIterator(t, itr, []int64{7}, "forward iterator from 7 to 8") + + ritr, err = db.ReverseIterator(int642Bytes(4), int642Bytes(5)) + require.NoError(t, err) + verifyIterator(t, ritr, []int64{4}, "reverse iterator from 5 (ex) to 4") + + ritr, err = db.ReverseIterator(int642Bytes(4), int642Bytes(6)) + require.NoError(t, err) + verifyIterator(t, ritr, + []int64{5, 4}, "reverse iterator from 6 (ex) to 4") + + ritr, err = db.ReverseIterator(int642Bytes(4), int642Bytes(7)) + require.NoError(t, err) + verifyIterator(t, ritr, + []int64{5, 4}, "reverse iterator from 7 (ex) to 4") + + ritr, err = db.ReverseIterator(int642Bytes(5), int642Bytes(6)) + require.NoError(t, err) + verifyIterator(t, ritr, []int64{5}, "reverse iterator from 6 (ex) to 5") + + ritr, err = db.ReverseIterator(int642Bytes(5), int642Bytes(7)) + require.NoError(t, err) + verifyIterator(t, ritr, []int64{5}, "reverse iterator from 7 (ex) to 5") + + ritr, err = db.ReverseIterator(int642Bytes(6), int642Bytes(7)) + require.NoError(t, err) + verifyIterator(t, ritr, + []int64(nil), "reverse iterator from 7 (ex) to 6") + + ritr, err = db.ReverseIterator(int642Bytes(10), nil) + require.NoError(t, err) + verifyIterator(t, ritr, []int64(nil), "reverse iterator to 10") + + ritr, err = db.ReverseIterator(int642Bytes(6), nil) + require.NoError(t, err) + verifyIterator(t, ritr, []int64{9, 8, 7}, "reverse iterator to 6") + + ritr, err = db.ReverseIterator(int642Bytes(5), nil) + require.NoError(t, err) + verifyIterator(t, ritr, []int64{9, 8, 7, 5}, "reverse iterator to 5") + + ritr, err = db.ReverseIterator(int642Bytes(8), int642Bytes(9)) + require.NoError(t, err) + verifyIterator(t, ritr, []int64{8}, "reverse iterator from 9 (ex) to 8") + + ritr, err = db.ReverseIterator(int642Bytes(2), int642Bytes(4)) + require.NoError(t, err) + verifyIterator(t, ritr, + []int64{3, 2}, "reverse iterator from 4 (ex) to 2") + + ritr, err = db.ReverseIterator(int642Bytes(4), int642Bytes(2)) + require.NoError(t, err) + verifyIterator(t, ritr, + []int64(nil), "reverse iterator from 2 (ex) to 4") + + // Ensure that the iterators don't panic with an empty database. + dir2, err := os.MkdirTemp("", "tm-db-test") + require.NoError(t, err) + name = fmt.Sprintf("test_%x", randStr(12)) + db2, err := NewDB(name, backend, dir2) + require.NoError(t, err) + defer cleanupDBDir(dir2, name) + defer db2.Close() + + itr, err = db2.Iterator(nil, nil) + require.NoError(t, err) + verifyIterator(t, itr, nil, "forward iterator with empty db") + + ritr, err = db2.ReverseIterator(nil, nil) + require.NoError(t, err) + verifyIterator(t, ritr, nil, "reverse iterator with empty db") +} + +func verifyIterator(t *testing.T, itr Iterator, expected []int64, msg string) { + t.Helper() + defer itr.Close() + + var list []int64 + for itr.Valid() { + key := make([]byte, len(itr.Key())) + copy(key, itr.Key()) + list = append(list, bytes2Int64(key)) + itr.Next() + } + assert.Equal(t, expected, list, msg) +} + +func TestDBBatch(t *testing.T) { + for dbType := range backends { + t.Run(fmt.Sprintf("%v", dbType), func(t *testing.T) { + testDBBatch(t, dbType) + }) + } +} + +func testDBBatch(t *testing.T, backend BackendType) { + t.Helper() + + name := fmt.Sprintf("test_%x", randStr(12)) + dir := os.TempDir() + db, err := NewDB(name, backend, dir) + require.NoError(t, err) + defer cleanupDBDir(dir, name) + defer db.Close() + + // create a new batch, and some items - they should not be visible until we write + batch := db.NewBatch() + require.NoError(t, batch.Set([]byte("a"), []byte{1})) + require.NoError(t, batch.Set([]byte("b"), []byte{2})) + require.NoError(t, batch.Set([]byte("c"), []byte{3})) + assertKeyValues(t, db, map[string][]byte{}) + + err = batch.Write() + require.NoError(t, err) + assertKeyValues(t, db, map[string][]byte{"a": {1}, "b": {2}, "c": {3}}) + + // trying to modify or rewrite a written batch should error, but closing it should work + require.Error(t, batch.Set([]byte("a"), []byte{9})) + require.Error(t, batch.Delete([]byte("a"))) + require.Error(t, batch.Write()) + require.Error(t, batch.WriteSync()) + require.NoError(t, batch.Close()) + + // batches should write changes in order + batch = db.NewBatch() + require.NoError(t, batch.Delete([]byte("a"))) + require.NoError(t, batch.Set([]byte("a"), []byte{1})) + require.NoError(t, batch.Set([]byte("b"), []byte{1})) + require.NoError(t, batch.Set([]byte("b"), []byte{2})) + require.NoError(t, batch.Set([]byte("c"), []byte{3})) + require.NoError(t, batch.Delete([]byte("c"))) + require.NoError(t, batch.Write()) + require.NoError(t, batch.Close()) + assertKeyValues(t, db, map[string][]byte{"a": {1}, "b": {2}}) + + // empty and nil keys, as well as nil values, should be disallowed + batch = db.NewBatch() + err = batch.Set([]byte{}, []byte{0x01}) + require.Equal(t, errKeyEmpty, err) + err = batch.Set(nil, []byte{0x01}) + require.Equal(t, errKeyEmpty, err) + err = batch.Set([]byte("a"), nil) + require.Equal(t, errValueNil, err) + + err = batch.Delete([]byte{}) + require.Equal(t, errKeyEmpty, err) + err = batch.Delete(nil) + require.Equal(t, errKeyEmpty, err) + + err = batch.Close() + require.NoError(t, err) + + // it should be possible to write an empty batch + batch = db.NewBatch() + err = batch.Write() + require.NoError(t, err) + assertKeyValues(t, db, map[string][]byte{"a": {1}, "b": {2}}) + + // it should be possible to close an empty batch, and to re-close a closed batch + batch = db.NewBatch() + if err := batch.Close(); err != nil { + require.NoError(t, err) + } + if err := batch.Close(); err != nil { + require.NoError(t, err) + } + + // all other operations on a closed batch should error + require.Error(t, batch.Set([]byte("a"), []byte{9})) + require.Error(t, batch.Delete([]byte("a"))) + require.Error(t, batch.Write()) + require.Error(t, batch.WriteSync()) +} + +func assertKeyValues(t *testing.T, db DB, expect map[string][]byte) { + t.Helper() + iter, err := db.Iterator(nil, nil) + require.NoError(t, err) + defer iter.Close() + + actual := make(map[string][]byte) + for ; iter.Valid(); iter.Next() { + require.NoError(t, iter.Error()) + + value := make([]byte, len(iter.Value())) + copy(value, iter.Value()) + actual[string(iter.Key())] = value + } + + assert.Equal(t, expect, actual) +} diff --git a/libs/db/common_test.go b/libs/db/common_test.go new file mode 100644 index 0000000000..c8fa63dc6d --- /dev/null +++ b/libs/db/common_test.go @@ -0,0 +1,190 @@ +// Modified by Tenderdash contributors from cometbft-db v1.0.4. +// See README.md for provenance and LICENSE for license terms. + +package db + +import ( + "bytes" + "encoding/binary" + "math/rand" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// ---------------------------------------- +// Helper functions. + +func checkValue(t *testing.T, db DB, key []byte, valueWanted []byte) { + t.Helper() + valueGot, err := db.Get(key) + assert.NoError(t, err) + assert.Equal(t, valueWanted, valueGot) +} + +func checkValid(t *testing.T, itr Iterator, expected bool) { + t.Helper() + valid := itr.Valid() + require.Equal(t, expected, valid) +} + +func checkNext(t *testing.T, itr Iterator, expected bool) { + t.Helper() + itr.Next() + valid := itr.Valid() + require.Equal(t, expected, valid) +} + +func checkNextPanics(t *testing.T, itr Iterator) { + t.Helper() + assert.Panics(t, func() { itr.Next() }, "checkNextPanics expected an error but didn't") +} + +func checkDomain(t *testing.T, itr Iterator, start, end []byte) { + t.Helper() + ds, de := itr.Domain() + assert.Equal(t, start, ds, "checkDomain domain start incorrect") + assert.Equal(t, end, de, "checkDomain domain end incorrect") +} + +func checkItem(t *testing.T, itr Iterator, key []byte, value []byte) { + t.Helper() + v := itr.Value() + + k := itr.Key() + + assert.Exactly(t, key, k) + assert.Exactly(t, value, v) +} + +func checkInvalid(t *testing.T, itr Iterator) { + t.Helper() + checkValid(t, itr, false) + checkKeyPanics(t, itr) + checkValuePanics(t, itr) + checkNextPanics(t, itr) +} + +func checkKeyPanics(t *testing.T, itr Iterator) { + t.Helper() + assert.Panics(t, func() { itr.Key() }, "checkKeyPanics expected panic but didn't") +} + +func checkValuePanics(t *testing.T, itr Iterator) { + t.Helper() + + msg := "checkValuePanics expected panic but didn't" + assert.Panics(t, func() { itr.Value() }, msg) +} + +func newTempDB(t *testing.T, backend BackendType) (db DB, dbDir string) { + t.Helper() + dirname := t.TempDir() + db, err := NewDB("testdb", backend, dirname) + require.NoError(t, err) + t.Cleanup(func() { require.NoError(t, db.Close()) }) + return db, dirname +} + +func benchmarkRangeScans(b *testing.B, db DB, dbSize int64) { + b.Helper() + b.StopTimer() + + rangeSize := int64(10000) + if dbSize < rangeSize { + b.Errorf("db size %v cannot be less than range size %v", dbSize, rangeSize) + } + + for i := int64(0); i < dbSize; i++ { + int64bytes := int642Bytes(i) + err := db.Set(int64bytes, int64bytes) + if err != nil { + // require.NoError() is very expensive (according to profiler), so check manually + b.Fatal(b, err) + } + } + b.StartTimer() + + for i := 0; i < b.N; i++ { + start := rand.Int63n(dbSize - rangeSize) + end := start + rangeSize + iter, err := db.Iterator(int642Bytes(start), int642Bytes(end)) + require.NoError(b, err) + count := 0 + for ; iter.Valid(); iter.Next() { + count++ + } + err = iter.Close() + require.NoError(b, err) + require.EqualValues(b, rangeSize, count) + } +} + +func benchmarkRandomReadsWrites(b *testing.B, db DB) { + b.Helper() + b.StopTimer() + + // create dummy data + const numItems = int64(1000000) + internal := map[int64]int64{} + for i := 0; i < int(numItems); i++ { + internal[int64(i)] = int64(0) + } + + b.StartTimer() + + for i := 0; i < b.N; i++ { + // Write something + { + idx := rand.Int63n(numItems) + internal[idx]++ + val := internal[idx] + idxBytes := int642Bytes(idx) + valBytes := int642Bytes(val) + err := db.Set(idxBytes, valBytes) + if err != nil { + // require.NoError() is very expensive (according to profiler), so check manually + b.Fatal(b, err) + } + } + + // Read something + { + idx := rand.Int63n(numItems) + valExp := internal[idx] + idxBytes := int642Bytes(idx) + valBytes, err := db.Get(idxBytes) + if err != nil { + // require.NoError() is very expensive (according to profiler), so check manually + b.Fatal(b, err) + } + if valExp == 0 { + if !bytes.Equal(valBytes, nil) { + b.Errorf("Expected %v for %v, got %X", nil, idx, valBytes) + break + } + } else { + if len(valBytes) != 8 { + b.Errorf("Expected length 8 for %v, got %X", idx, valBytes) + break + } + valGot := bytes2Int64(valBytes) + if valExp != valGot { + b.Errorf("Expected %v for %v, got %v", valExp, idx, valGot) + break + } + } + } + } +} + +func int642Bytes(i int64) []byte { + buf := make([]byte, 8) + binary.BigEndian.PutUint64(buf, uint64(i)) + return buf +} + +func bytes2Int64(buf []byte) int64 { + return int64(binary.BigEndian.Uint64(buf)) +} diff --git a/libs/db/db.go b/libs/db/db.go new file mode 100644 index 0000000000..16a7e26dc6 --- /dev/null +++ b/libs/db/db.go @@ -0,0 +1,50 @@ +// Modified by Tenderdash contributors from cometbft-db v1.0.4. +// See README.md for provenance and LICENSE for license terms. + +package db + +import ( + "fmt" + "strings" +) + +type BackendType string + +// These are valid backend types. +const ( + // GoLevelDBBackend is the persistent GoLevelDB backend. + GoLevelDBBackend BackendType = "goleveldb" + // MemDBBackend is an in-memory key-value store. + MemDBBackend BackendType = "memdb" +) + +type dbCreator func(name string, dir string) (DB, error) + +var backends = map[BackendType]dbCreator{} + +func registerDBCreator(backend BackendType, creator dbCreator) { + _, ok := backends[backend] + if ok { + return + } + backends[backend] = creator +} + +// NewDB creates a new database of type backend with the given name. +func NewDB(name string, backend BackendType, dir string) (DB, error) { + dbCreator, ok := backends[backend] + if !ok { + keys := make([]string, 0, len(backends)) + for k := range backends { + keys = append(keys, string(k)) + } + return nil, fmt.Errorf("unknown db_backend %s, expected one of %v", + backend, strings.Join(keys, ",")) + } + + db, err := dbCreator(name, dir) + if err != nil { + return nil, fmt.Errorf("failed to initialize database: %w", err) + } + return db, nil +} diff --git a/libs/db/db_test.go b/libs/db/db_test.go new file mode 100644 index 0000000000..e3b5b18896 --- /dev/null +++ b/libs/db/db_test.go @@ -0,0 +1,140 @@ +// Modified by Tenderdash contributors from cometbft-db v1.0.4. +// See README.md for provenance and LICENSE for license terms. + +package db + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestDBIteratorSingleKey(t *testing.T) { + for backend := range backends { + t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) { + db, _ := newTempDB(t, backend) + + err := db.SetSync(bz("1"), bz("value_1")) + assert.NoError(t, err) + itr, err := db.Iterator(nil, nil) + assert.NoError(t, err) + defer itr.Close() + + checkValid(t, itr, true) + checkNext(t, itr, false) + checkValid(t, itr, false) + checkNextPanics(t, itr) + + // Once invalid... + checkInvalid(t, itr) + }) + } +} + +func TestDBIteratorTwoKeys(t *testing.T) { + for backend := range backends { + t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) { + db, _ := newTempDB(t, backend) + + err := db.SetSync(bz("1"), bz("value_1")) + assert.NoError(t, err) + + err = db.SetSync(bz("2"), bz("value_1")) + assert.NoError(t, err) + + { // Fail by calling Next too much + itr, err := db.Iterator(nil, nil) + assert.NoError(t, err) + defer itr.Close() + checkValid(t, itr, true) + + checkNext(t, itr, true) + checkValid(t, itr, true) + + checkNext(t, itr, false) + checkValid(t, itr, false) + + checkNextPanics(t, itr) + + // Once invalid... + checkInvalid(t, itr) + } + }) + } +} + +func TestDBIteratorMany(t *testing.T) { + for backend := range backends { + t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) { + db, _ := newTempDB(t, backend) + + keys := make([][]byte, 100) + for i := 0; i < 100; i++ { + keys[i] = []byte{byte(i)} + } + + value := []byte{5} + for _, k := range keys { + err := db.Set(k, value) + assert.NoError(t, err) + } + + itr, err := db.Iterator(nil, nil) + assert.NoError(t, err) + defer itr.Close() + + for ; itr.Valid(); itr.Next() { + key := itr.Key() + value = itr.Value() + value1, err := db.Get(key) + assert.NoError(t, err) + assert.Equal(t, value1, value) + } + }) + } +} + +func TestDBIteratorEmpty(t *testing.T) { + for backend := range backends { + t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) { + db, _ := newTempDB(t, backend) + + itr, err := db.Iterator(nil, nil) + assert.NoError(t, err) + defer itr.Close() + + checkInvalid(t, itr) + }) + } +} + +func TestDBIteratorEmptyBeginAfter(t *testing.T) { + for backend := range backends { + t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) { + db, _ := newTempDB(t, backend) + + itr, err := db.Iterator(bz("1"), nil) + assert.NoError(t, err) + defer itr.Close() + + checkInvalid(t, itr) + }) + } +} + +func TestDBIteratorNonemptyBeginAfter(t *testing.T) { + for backend := range backends { + t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) { + db, _ := newTempDB(t, backend) + + err := db.SetSync(bz("1"), bz("value_1")) + assert.NoError(t, err) + itr, err := db.Iterator(bz("2"), nil) + assert.NoError(t, err) + defer itr.Close() + + checkInvalid(t, itr) + }) + } +} diff --git a/libs/db/doc.go b/libs/db/doc.go new file mode 100644 index 0000000000..ce2d9f630d --- /dev/null +++ b/libs/db/doc.go @@ -0,0 +1,3 @@ +// Package db provides persistent GoLevelDB storage, transient MemDB storage, +// and prefixed views for Tenderdash. +package db diff --git a/libs/db/goleveldb.go b/libs/db/goleveldb.go new file mode 100644 index 0000000000..d792420837 --- /dev/null +++ b/libs/db/goleveldb.go @@ -0,0 +1,202 @@ +// Modified by Tenderdash contributors from cometbft-db v1.0.4. +// See README.md for provenance and LICENSE for license terms. + +package db + +import ( + "fmt" + "path/filepath" + + "github.com/syndtr/goleveldb/leveldb" + "github.com/syndtr/goleveldb/leveldb/errors" + "github.com/syndtr/goleveldb/leveldb/opt" + "github.com/syndtr/goleveldb/leveldb/util" +) + +func init() { + dbCreator := func(name string, dir string) (DB, error) { + return NewGoLevelDB(name, dir) + } + registerDBCreator(GoLevelDBBackend, dbCreator) +} + +type GoLevelDB struct { + db *leveldb.DB +} + +var _ DB = (*GoLevelDB)(nil) + +func NewGoLevelDB(name string, dir string) (*GoLevelDB, error) { + return NewGoLevelDBWithOpts(name, dir, nil) +} + +func NewGoLevelDBWithOpts(name string, dir string, o *opt.Options) (*GoLevelDB, error) { + dbPath := filepath.Join(dir, name+".db") + db, err := leveldb.OpenFile(dbPath, o) + if err != nil { + return nil, err + } + + database := &GoLevelDB{ + db: db, + } + return database, nil +} + +// Get implements DB. +func (db *GoLevelDB) Get(key []byte) ([]byte, error) { + if len(key) == 0 { + return nil, errKeyEmpty + } + res, err := db.db.Get(key, nil) + if err != nil { + if err == errors.ErrNotFound { + return nil, nil + } + return nil, err + } + return res, nil +} + +// Has implements DB. +func (db *GoLevelDB) Has(key []byte) (bool, error) { + bytes, err := db.Get(key) + if err != nil { + return false, err + } + return bytes != nil, nil +} + +// Set implements DB. +func (db *GoLevelDB) Set(key []byte, value []byte) error { + if len(key) == 0 { + return errKeyEmpty + } + if value == nil { + return errValueNil + } + err := db.db.Put(key, value, nil) + if err != nil { + return err + } + return nil +} + +// SetSync implements DB. +func (db *GoLevelDB) SetSync(key []byte, value []byte) error { + if len(key) == 0 { + return errKeyEmpty + } + if value == nil { + return errValueNil + } + + err := db.db.Put(key, value, &opt.WriteOptions{Sync: true}) + if err != nil { + return err + } + return nil +} + +// Delete implements DB. +func (db *GoLevelDB) Delete(key []byte) error { + if len(key) == 0 { + return errKeyEmpty + } + + err := db.db.Delete(key, nil) + if err != nil { + return err + } + return nil +} + +// DeleteSync implements DB. +func (db *GoLevelDB) DeleteSync(key []byte) error { + if len(key) == 0 { + return errKeyEmpty + } + err := db.db.Delete(key, &opt.WriteOptions{Sync: true}) + if err != nil { + return err + } + return nil +} + +func (db *GoLevelDB) DB() *leveldb.DB { + return db.db +} + +// Close implements DB. +func (db *GoLevelDB) Close() error { + return db.db.Close() +} + +// Print implements DB. +func (db *GoLevelDB) Print() error { + str, err := db.db.GetProperty("leveldb.stats") + if err != nil { + return err + } + fmt.Printf("%v\n", str) + + itr := db.db.NewIterator(nil, nil) + defer itr.Release() + for itr.Next() { + key := itr.Key() + value := itr.Value() + fmt.Printf("[%X]:\t[%X]\n", key, value) + } + return nil +} + +// Stats implements DB. +func (db *GoLevelDB) Stats() map[string]string { + keys := []string{ + "leveldb.num-files-at-level{n}", + "leveldb.stats", + "leveldb.sstables", + "leveldb.blockpool", + "leveldb.cachedblock", + "leveldb.openedtables", + "leveldb.alivesnaps", + "leveldb.aliveiters", + } + + stats := make(map[string]string) + for _, key := range keys { + str, err := db.db.GetProperty(key) + if err == nil { + stats[key] = str + } + } + return stats +} + +// NewBatch implements DB. +func (db *GoLevelDB) NewBatch() Batch { + return newGoLevelDBBatch(db) +} + +// Iterator implements DB. +func (db *GoLevelDB) Iterator(start, end []byte) (Iterator, error) { + if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) { + return nil, errKeyEmpty + } + itr := db.db.NewIterator(&util.Range{Start: start, Limit: end}, nil) + return newGoLevelDBIterator(itr, start, end, false), nil +} + +// ReverseIterator implements DB. +func (db *GoLevelDB) ReverseIterator(start, end []byte) (Iterator, error) { + if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) { + return nil, errKeyEmpty + } + itr := db.db.NewIterator(&util.Range{Start: start, Limit: end}, nil) + return newGoLevelDBIterator(itr, start, end, true), nil +} + +// Compact range. +func (db *GoLevelDB) Compact(start, end []byte) error { + return db.db.CompactRange(util.Range{Start: start, Limit: end}) +} diff --git a/libs/db/goleveldb_batch.go b/libs/db/goleveldb_batch.go new file mode 100644 index 0000000000..4db2bd0464 --- /dev/null +++ b/libs/db/goleveldb_batch.go @@ -0,0 +1,79 @@ +package db + +import ( + "github.com/syndtr/goleveldb/leveldb" + "github.com/syndtr/goleveldb/leveldb/opt" +) + +type goLevelDBBatch struct { + db *GoLevelDB + batch *leveldb.Batch +} + +var _ Batch = (*goLevelDBBatch)(nil) + +func newGoLevelDBBatch(db *GoLevelDB) *goLevelDBBatch { + return &goLevelDBBatch{ + db: db, + batch: new(leveldb.Batch), + } +} + +// Set implements Batch. +func (b *goLevelDBBatch) Set(key, value []byte) error { + if len(key) == 0 { + return errKeyEmpty + } + if value == nil { + return errValueNil + } + if b.batch == nil { + return errBatchClosed + } + b.batch.Put(key, value) + return nil +} + +// Delete implements Batch. +func (b *goLevelDBBatch) Delete(key []byte) error { + if len(key) == 0 { + return errKeyEmpty + } + if b.batch == nil { + return errBatchClosed + } + b.batch.Delete(key) + return nil +} + +// Write implements Batch. +func (b *goLevelDBBatch) Write() error { + return b.write(false) +} + +// WriteSync implements Batch. +func (b *goLevelDBBatch) WriteSync() error { + return b.write(true) +} + +func (b *goLevelDBBatch) write(sync bool) error { + if b.batch == nil { + return errBatchClosed + } + + err := b.db.db.Write(b.batch, &opt.WriteOptions{Sync: sync}) + if err != nil { + return err + } + // Make sure batch cannot be used afterwards. Callers should still call Close(), for errors. + return b.Close() +} + +// Close implements Batch. +func (b *goLevelDBBatch) Close() error { + if b.batch != nil { + b.batch.Reset() + b.batch = nil + } + return nil +} diff --git a/libs/db/goleveldb_iterator.go b/libs/db/goleveldb_iterator.go new file mode 100644 index 0000000000..de29e97bdd --- /dev/null +++ b/libs/db/goleveldb_iterator.go @@ -0,0 +1,136 @@ +package db + +import ( + "bytes" + + "github.com/syndtr/goleveldb/leveldb/iterator" +) + +type goLevelDBIterator struct { + source iterator.Iterator + start []byte + end []byte + isReverse bool + isInvalid bool +} + +var _ Iterator = (*goLevelDBIterator)(nil) + +func newGoLevelDBIterator(source iterator.Iterator, start, end []byte, isReverse bool) *goLevelDBIterator { + if isReverse { + if end == nil { + source.Last() + } else { + valid := source.Seek(end) + if valid { + eoakey := source.Key() // end or after key + if bytes.Compare(end, eoakey) <= 0 { + source.Prev() + } + } else { + source.Last() + } + } + } else { + if start == nil { + source.First() + } else { + source.Seek(start) + } + } + return &goLevelDBIterator{ + source: source, + start: start, + end: end, + isReverse: isReverse, + isInvalid: false, + } +} + +// Domain implements Iterator. +func (itr *goLevelDBIterator) Domain() (start []byte, end []byte) { + return itr.start, itr.end +} + +// Valid implements Iterator. +func (itr *goLevelDBIterator) Valid() bool { + // Once invalid, forever invalid. + if itr.isInvalid { + return false + } + + // If source errors, invalid. + if err := itr.Error(); err != nil { + itr.isInvalid = true + return false + } + + // If source is invalid, invalid. + if !itr.source.Valid() { + itr.isInvalid = true + return false + } + + // If key is end or past it, invalid. + start := itr.start + end := itr.end + key := itr.source.Key() + + if itr.isReverse { + if start != nil && bytes.Compare(key, start) < 0 { + itr.isInvalid = true + return false + } + } else { + if end != nil && bytes.Compare(end, key) <= 0 { + itr.isInvalid = true + return false + } + } + + // Valid + return true +} + +// Key implements Iterator. +// The caller should not modify the contents of the returned slice. +// Instead, the caller should make a copy and work on the copy. +func (itr *goLevelDBIterator) Key() []byte { + itr.assertIsValid() + return itr.source.Key() +} + +// Value implements Iterator. +// The caller should not modify the contents of the returned slice. +// Instead, the caller should make a copy and work on the copy. +func (itr *goLevelDBIterator) Value() []byte { + itr.assertIsValid() + return itr.source.Value() +} + +// Next implements Iterator. +func (itr *goLevelDBIterator) Next() { + itr.assertIsValid() + if itr.isReverse { + itr.source.Prev() + } else { + itr.source.Next() + } +} + +// Error implements Iterator. +func (itr *goLevelDBIterator) Error() error { + return itr.source.Error() +} + +// Close implements Iterator. +func (itr *goLevelDBIterator) Close() error { + itr.source.Release() + return nil +} + +func (itr goLevelDBIterator) assertIsValid() { + if !itr.Valid() { + panic("iterator is invalid") + } +} diff --git a/libs/db/goleveldb_test.go b/libs/db/goleveldb_test.go new file mode 100644 index 0000000000..549c0a17fd --- /dev/null +++ b/libs/db/goleveldb_test.go @@ -0,0 +1,70 @@ +// Modified by Tenderdash contributors from cometbft-db v1.0.4. +// See README.md for provenance and LICENSE for license terms. + +package db + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/syndtr/goleveldb/leveldb/opt" +) + +func TestGoLevelDBNewGoLevelDB(t *testing.T) { + name := fmt.Sprintf("test_%x", randStr(12)) + dir := t.TempDir() + + // Test we can't open the db twice for writing + wr1, err := NewGoLevelDB(name, dir) + require.Nil(t, err) + _, err = NewGoLevelDB(name, dir) + require.NotNil(t, err) + err = wr1.Close() // Close the db to release the lock + require.Nil(t, err) + + // Test we can open the db twice for reading only + ro1, err := NewGoLevelDBWithOpts(name, dir, &opt.Options{ReadOnly: true}) + require.Nil(t, err) + defer ro1.Close() + ro2, err := NewGoLevelDBWithOpts(name, dir, &opt.Options{ReadOnly: true}) + require.Nil(t, err) + defer ro2.Close() +} + +func BenchmarkGoLevelDBRandomReadsWrites(b *testing.B) { + name := fmt.Sprintf("test_%x", randStr(12)) + dir := b.TempDir() + db, err := NewGoLevelDB(name, dir) + if err != nil { + b.Fatal(err) + } + defer func() { + err = db.Close() + require.NoError(b, err) + }() + + benchmarkRandomReadsWrites(b, db) +} + +func TestGoLevelDBBackend(t *testing.T) { + name := fmt.Sprintf("test_%x", randStr(12)) + db, err := NewDB(name, GoLevelDBBackend, t.TempDir()) + require.NoError(t, err) + defer db.Close() + + _, ok := db.(*GoLevelDB) + assert.True(t, ok) +} + +func TestGoLevelDBPrintReleasesIterator(t *testing.T) { + db, err := NewGoLevelDB("print", t.TempDir()) + require.NoError(t, err) + t.Cleanup(func() { require.NoError(t, db.Close()) }) + require.NoError(t, db.Set([]byte("key"), []byte("value"))) + + before := db.Stats()["leveldb.aliveiters"] + require.NoError(t, db.Print()) + require.Equal(t, before, db.Stats()["leveldb.aliveiters"], "Print must release its iterator before returning") +} diff --git a/libs/db/memdb.go b/libs/db/memdb.go new file mode 100644 index 0000000000..1e977de72c --- /dev/null +++ b/libs/db/memdb.go @@ -0,0 +1,216 @@ +package db + +import ( + "bytes" + "fmt" + "strconv" + "sync" + + "github.com/google/btree" +) + +const ( + // The approximate number of items and children per B-tree node. Tuned with benchmarks. + bTreeDegree = 32 +) + +func init() { + registerDBCreator(MemDBBackend, func(_, _ string) (DB, error) { + return NewMemDB(), nil + }) +} + +// item is a btree.Item with byte slices as keys and values. +type item struct { + key []byte + value []byte +} + +// Less implements btree.Item. +func (i *item) Less(other btree.Item) bool { + // this considers nil == []byte{}, but that's ok since we handle nil endpoints + // in iterators specially anyway + return bytes.Compare(i.key, other.(*item).key) == -1 +} + +// newKey creates a new key item. +func newKey(key []byte) *item { + return &item{key: key} +} + +// newPair creates a new pair item. +func newPair(key, value []byte) *item { + return &item{key: key, value: value} +} + +// MemDB is an in-memory database backend using a B-tree for storage. +// +// For performance reasons, all given and returned keys and values are pointers to the in-memory +// database, so modifying them will cause the stored values to be modified as well. All DB methods +// already specify that keys and values should be considered read-only, but this is especially +// important with MemDB. +type MemDB struct { + mtx sync.RWMutex + btree *btree.BTree +} + +var _ DB = (*MemDB)(nil) + +// NewMemDB creates a new in-memory database. +func NewMemDB() *MemDB { + database := &MemDB{ + btree: btree.New(bTreeDegree), + } + return database +} + +// Get implements DB. +func (db *MemDB) Get(key []byte) ([]byte, error) { + if len(key) == 0 { + return nil, errKeyEmpty + } + db.mtx.RLock() + defer db.mtx.RUnlock() + + i := db.btree.Get(newKey(key)) + if i != nil { + return i.(*item).value, nil + } + return nil, nil +} + +// Has implements DB. +func (db *MemDB) Has(key []byte) (bool, error) { + if len(key) == 0 { + return false, errKeyEmpty + } + db.mtx.RLock() + defer db.mtx.RUnlock() + + return db.btree.Has(newKey(key)), nil +} + +// Set implements DB. +func (db *MemDB) Set(key []byte, value []byte) error { + if len(key) == 0 { + return errKeyEmpty + } + if value == nil { + return errValueNil + } + db.mtx.Lock() + defer db.mtx.Unlock() + + db.set(key, value) + return nil +} + +// set sets a value without locking the mutex. +func (db *MemDB) set(key []byte, value []byte) { + db.btree.ReplaceOrInsert(newPair(key, value)) +} + +// SetSync implements DB. +func (db *MemDB) SetSync(key []byte, value []byte) error { + return db.Set(key, value) +} + +// Delete implements DB. +func (db *MemDB) Delete(key []byte) error { + if len(key) == 0 { + return errKeyEmpty + } + db.mtx.Lock() + defer db.mtx.Unlock() + + db.delete(key) + return nil +} + +// delete deletes a key without locking the mutex. +func (db *MemDB) delete(key []byte) { + db.btree.Delete(newKey(key)) +} + +// DeleteSync implements DB. +func (db *MemDB) DeleteSync(key []byte) error { + return db.Delete(key) +} + +// Close implements DB. +func (*MemDB) Close() error { + // Close is a noop since for an in-memory database, we don't have a destination to flush + // contents to nor do we want any data loss on invoking Close(). + return nil +} + +// Print implements DB. +func (db *MemDB) Print() error { + db.mtx.RLock() + defer db.mtx.RUnlock() + + db.btree.Ascend(func(i btree.Item) bool { + item, ok := i.(*item) + if !ok { + return false // or handle the error as appropriate + } + fmt.Printf("[%X]:\t[%X]\n", item.key, item.value) + return true + }) + return nil +} + +// Stats implements DB. +func (db *MemDB) Stats() map[string]string { + db.mtx.RLock() + defer db.mtx.RUnlock() + + stats := make(map[string]string) + stats["database.type"] = "memDB" + stats["database.size"] = strconv.Itoa(db.btree.Len()) + return stats +} + +// NewBatch implements DB. +func (db *MemDB) NewBatch() Batch { + return newMemDBBatch(db) +} + +// Iterator implements DB. +// Takes out a read-lock on the database until the iterator is closed. +func (db *MemDB) Iterator(start, end []byte) (Iterator, error) { + if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) { + return nil, errKeyEmpty + } + return newMemDBIterator(db, start, end, false), nil +} + +// ReverseIterator implements DB. +// Takes out a read-lock on the database until the iterator is closed. +func (db *MemDB) ReverseIterator(start, end []byte) (Iterator, error) { + if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) { + return nil, errKeyEmpty + } + return newMemDBIterator(db, start, end, true), nil +} + +// IteratorNoMtx makes an iterator with no mutex. +func (db *MemDB) IteratorNoMtx(start, end []byte) (Iterator, error) { + if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) { + return nil, errKeyEmpty + } + return newMemDBIteratorMtxChoice(db, start, end, false, false), nil +} + +// ReverseIteratorNoMtx makes an iterator with no mutex. +func (db *MemDB) ReverseIteratorNoMtx(start, end []byte) (Iterator, error) { + if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) { + return nil, errKeyEmpty + } + return newMemDBIteratorMtxChoice(db, start, end, true, false), nil +} + +func (*MemDB) Compact(_, _ []byte) error { + // No Compaction is supported for memDB and there is no point in supporting compaction for a memory DB + return nil +} diff --git a/libs/db/memdb_batch.go b/libs/db/memdb_batch.go new file mode 100644 index 0000000000..c1e4d6f188 --- /dev/null +++ b/libs/db/memdb_batch.go @@ -0,0 +1,94 @@ +package db + +import "fmt" + +// memDBBatch operations. +type opType int + +const ( + opTypeSet opType = iota + 1 + opTypeDelete +) + +type operation struct { + opType + key []byte + value []byte +} + +// memDBBatch handles in-memory batching. +type memDBBatch struct { + db *MemDB + ops []operation +} + +var _ Batch = (*memDBBatch)(nil) + +// newMemDBBatch creates a new memDBBatch. +func newMemDBBatch(db *MemDB) *memDBBatch { + return &memDBBatch{ + db: db, + ops: []operation{}, + } +} + +// Set implements Batch. +func (b *memDBBatch) Set(key, value []byte) error { + if len(key) == 0 { + return errKeyEmpty + } + if value == nil { + return errValueNil + } + if b.ops == nil { + return errBatchClosed + } + b.ops = append(b.ops, operation{opTypeSet, key, value}) + return nil +} + +// Delete implements Batch. +func (b *memDBBatch) Delete(key []byte) error { + if len(key) == 0 { + return errKeyEmpty + } + if b.ops == nil { + return errBatchClosed + } + b.ops = append(b.ops, operation{opTypeDelete, key, nil}) + return nil +} + +// Write implements Batch. +func (b *memDBBatch) Write() error { + if b.ops == nil { + return errBatchClosed + } + b.db.mtx.Lock() + defer b.db.mtx.Unlock() + + for _, op := range b.ops { + switch op.opType { + case opTypeSet: + b.db.set(op.key, op.value) + case opTypeDelete: + b.db.delete(op.key) + default: + return fmt.Errorf("unknown operation type %v (%v)", op.opType, op) + } + } + + // Make sure batch cannot be used afterwards. Callers should still call Close(), for errors. + return b.Close() +} + +// WriteSync implements Batch. +func (b *memDBBatch) WriteSync() error { + return b.Write() +} + +// Close implements Batch. +func (b *memDBBatch) Close() error { + b.ops = nil + return nil +} diff --git a/libs/db/memdb_iterator.go b/libs/db/memdb_iterator.go new file mode 100644 index 0000000000..07fbe9af40 --- /dev/null +++ b/libs/db/memdb_iterator.go @@ -0,0 +1,163 @@ +// Modified by Tenderdash contributors from cometbft-db v1.0.4. +// See README.md for provenance and LICENSE for license terms. + +package db + +import ( + "bytes" + "context" + + "github.com/google/btree" +) + +const ( + // Size of the channel buffer between traversal goroutine and iterator. Using an unbuffered + // channel causes two context switches per item sent, while buffering allows more work per + // context switch. Tuned with benchmarks. + chBufferSize = 64 +) + +// memDBIterator is a memDB iterator. +type memDBIterator struct { + ch <-chan *item + cancel context.CancelFunc + item *item + start []byte + end []byte + useMtx bool +} + +var _ Iterator = (*memDBIterator)(nil) + +// newMemDBIterator creates a new memDBIterator. +func newMemDBIterator(db *MemDB, start []byte, end []byte, reverse bool) *memDBIterator { + return newMemDBIteratorMtxChoice(db, start, end, reverse, true) +} + +func newMemDBIteratorMtxChoice(db *MemDB, start []byte, end []byte, reverse bool, useMtx bool) *memDBIterator { + ctx, cancel := context.WithCancel(context.Background()) + ch := make(chan *item, chBufferSize) + iter := &memDBIterator{ + ch: ch, + cancel: cancel, + start: start, + end: end, + useMtx: useMtx, + } + + if useMtx { + db.mtx.RLock() + } + go func() { + if useMtx { + defer db.mtx.RUnlock() + } + // Because we use [start, end) for reverse ranges, while btree uses (start, end], we need + // the following variables to handle some reverse iteration conditions ourselves. + var ( + skipEqual []byte + abortLessThan []byte + ) + visitor := func(i btree.Item) bool { + item, ok := i.(*item) + if !ok { + return false // or handle the error as appropriate + } + if skipEqual != nil && bytes.Equal(item.key, skipEqual) { + skipEqual = nil + return true + } + if abortLessThan != nil && bytes.Compare(item.key, abortLessThan) == -1 { + return false + } + select { + case <-ctx.Done(): + return false + case ch <- item: + return true + } + } + switch { + case start == nil && end == nil && !reverse: + db.btree.Ascend(visitor) + case start == nil && end == nil && reverse: + db.btree.Descend(visitor) + case end == nil && !reverse: + // must handle this specially, since nil is considered less than anything else + db.btree.AscendGreaterOrEqual(newKey(start), visitor) + case !reverse: + db.btree.AscendRange(newKey(start), newKey(end), visitor) + case end == nil: + // abort after start, since we use [start, end) while btree uses (start, end] + abortLessThan = start + db.btree.Descend(visitor) + default: + // skip end and abort after start, since we use [start, end) while btree uses (start, end] + skipEqual = end + abortLessThan = start + db.btree.DescendLessOrEqual(newKey(end), visitor) + } + close(ch) + }() + + // prime the iterator with the first value, if any + if item, ok := <-ch; ok { + iter.item = item + } + + return iter +} + +// Close implements Iterator. +func (i *memDBIterator) Close() error { + i.cancel() + for range i.ch { // drain channel + } + i.item = nil + return nil +} + +// Domain implements Iterator. +func (i *memDBIterator) Domain() (start []byte, end []byte) { + return i.start, i.end +} + +// Valid implements Iterator. +func (i *memDBIterator) Valid() bool { + return i.item != nil +} + +// Next implements Iterator. +func (i *memDBIterator) Next() { + i.assertIsValid() + item, ok := <-i.ch + switch { + case ok: + i.item = item + default: + i.item = nil + } +} + +// Error implements Iterator. +func (*memDBIterator) Error() error { + return nil // famous last words +} + +// Key implements Iterator. +func (i *memDBIterator) Key() []byte { + i.assertIsValid() + return i.item.key +} + +// Value implements Iterator. +func (i *memDBIterator) Value() []byte { + i.assertIsValid() + return i.item.value +} + +func (i *memDBIterator) assertIsValid() { + if !i.Valid() { + panic("iterator is invalid") + } +} diff --git a/libs/db/memdb_test.go b/libs/db/memdb_test.go new file mode 100644 index 0000000000..4e67e813de --- /dev/null +++ b/libs/db/memdb_test.go @@ -0,0 +1,26 @@ +package db + +import ( + "testing" +) + +func BenchmarkMemDBRangeScans1M(b *testing.B) { + db := NewMemDB() + defer db.Close() + + benchmarkRangeScans(b, db, int64(1e6)) +} + +func BenchmarkMemDBRangeScans10M(b *testing.B) { + db := NewMemDB() + defer db.Close() + + benchmarkRangeScans(b, db, int64(10e6)) +} + +func BenchmarkMemDBRandomReadsWrites(b *testing.B) { + db := NewMemDB() + defer db.Close() + + benchmarkRandomReadsWrites(b, db) +} diff --git a/libs/db/persistence_test.go b/libs/db/persistence_test.go new file mode 100644 index 0000000000..f066edf86a --- /dev/null +++ b/libs/db/persistence_test.go @@ -0,0 +1,76 @@ +package db + +import ( + "fmt" + "testing" + "time" + + "github.com/stretchr/testify/require" +) + +func TestGoLevelDBReopen(t *testing.T) { + dir := t.TempDir() + db, err := NewGoLevelDB("state", dir) + require.NoError(t, err) + require.NoError(t, db.SetSync([]byte("deleted"), []byte("old"))) + + batch := db.NewBatch() + require.NoError(t, batch.Set([]byte("prefix/a"), []byte("value"))) + require.NoError(t, batch.Set([]byte("prefix/b"), []byte{})) + require.NoError(t, batch.Delete([]byte("deleted"))) + require.NoError(t, batch.WriteSync()) + require.NoError(t, batch.Close()) + require.NoError(t, db.Close()) + + db, err = NewGoLevelDB("state", dir) + require.NoError(t, err) + t.Cleanup(func() { require.NoError(t, db.Close()) }) + value, err := db.Get([]byte("deleted")) + require.NoError(t, err) + require.Nil(t, value) + + prefix := NewPrefixDB(db, []byte("prefix/")) + iter, err := prefix.ReverseIterator(nil, nil) + require.NoError(t, err) + defer iter.Close() + require.True(t, iter.Valid()) + require.Equal(t, []byte("b"), iter.Key()) + require.Empty(t, iter.Value()) + iter.Next() + require.True(t, iter.Valid()) + require.Equal(t, []byte("a"), iter.Key()) + require.Equal(t, []byte("value"), iter.Value()) + iter.Next() + require.False(t, iter.Valid()) + require.NoError(t, iter.Error()) +} + +func TestMemDBIteratorCloseReleasesWriter(t *testing.T) { + db := NewMemDB() + // Exceed the iterator's buffer so the producer must stop on early Close. + for i := 0; i < 256; i++ { + require.NoError(t, db.Set([]byte(fmt.Sprintf("%03d", i)), []byte("value"))) + } + for _, reverse := range []bool{false, true} { + t.Run(fmt.Sprintf("reverse=%t", reverse), func(t *testing.T) { + var iter Iterator + var err error + if reverse { + iter, err = db.ReverseIterator(nil, nil) + } else { + iter, err = db.Iterator(nil, nil) + } + require.NoError(t, err) + require.True(t, iter.Valid()) + done := make(chan error, 1) + go func() { done <- db.Set([]byte("writer"), []byte("value")) }() + require.NoError(t, iter.Close()) + select { + case err := <-done: + require.NoError(t, err) + case <-time.After(5 * time.Second): + t.Fatal("writer blocked after closing iterator") + } + }) + } +} diff --git a/libs/db/prefixdb.go b/libs/db/prefixdb.go new file mode 100644 index 0000000000..bb10113d12 --- /dev/null +++ b/libs/db/prefixdb.go @@ -0,0 +1,205 @@ +package db + +import ( + "fmt" + "sync" +) + +// PrefixDB wraps a namespace of another database as a logical database. +type PrefixDB struct { + mtx sync.Mutex + prefix []byte + db DB +} + +var _ DB = (*PrefixDB)(nil) + +// NewPrefixDB lets you namespace multiple DBs within a single DB. +func NewPrefixDB(db DB, prefix []byte) *PrefixDB { + return &PrefixDB{ + prefix: prefix, + db: db, + } +} + +// Get implements DB. +func (pdb *PrefixDB) Get(key []byte) ([]byte, error) { + if len(key) == 0 { + return nil, errKeyEmpty + } + pdb.mtx.Lock() + defer pdb.mtx.Unlock() + + pkey := pdb.prefixed(key) + value, err := pdb.db.Get(pkey) + if err != nil { + return nil, err + } + return value, nil +} + +// Has implements DB. +func (pdb *PrefixDB) Has(key []byte) (bool, error) { + if len(key) == 0 { + return false, errKeyEmpty + } + pdb.mtx.Lock() + defer pdb.mtx.Unlock() + + ok, err := pdb.db.Has(pdb.prefixed(key)) + if err != nil { + return ok, err + } + + return ok, nil +} + +// Set implements DB. +func (pdb *PrefixDB) Set(key []byte, value []byte) error { + if len(key) == 0 { + return errKeyEmpty + } + if value == nil { + return errValueNil + } + pdb.mtx.Lock() + defer pdb.mtx.Unlock() + + pkey := pdb.prefixed(key) + return pdb.db.Set(pkey, value) +} + +// SetSync implements DB. +func (pdb *PrefixDB) SetSync(key []byte, value []byte) error { + if len(key) == 0 { + return errKeyEmpty + } + if value == nil { + return errValueNil + } + pdb.mtx.Lock() + defer pdb.mtx.Unlock() + + return pdb.db.SetSync(pdb.prefixed(key), value) +} + +// Delete implements DB. +func (pdb *PrefixDB) Delete(key []byte) error { + if len(key) == 0 { + return errKeyEmpty + } + pdb.mtx.Lock() + defer pdb.mtx.Unlock() + + return pdb.db.Delete(pdb.prefixed(key)) +} + +// DeleteSync implements DB. +func (pdb *PrefixDB) DeleteSync(key []byte) error { + if len(key) == 0 { + return errKeyEmpty + } + pdb.mtx.Lock() + defer pdb.mtx.Unlock() + + return pdb.db.DeleteSync(pdb.prefixed(key)) +} + +// Iterator implements DB. +func (pdb *PrefixDB) Iterator(start, end []byte) (Iterator, error) { + if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) { + return nil, errKeyEmpty + } + pdb.mtx.Lock() + defer pdb.mtx.Unlock() + + var pstart, pend []byte + pstart = append(cp(pdb.prefix), start...) + if end == nil { + pend = cpIncr(pdb.prefix) + } else { + pend = append(cp(pdb.prefix), end...) + } + itr, err := pdb.db.Iterator(pstart, pend) + if err != nil { + return nil, err + } + + return newPrefixIterator(pdb.prefix, start, end, itr) +} + +// ReverseIterator implements DB. +func (pdb *PrefixDB) ReverseIterator(start, end []byte) (Iterator, error) { + if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) { + return nil, errKeyEmpty + } + pdb.mtx.Lock() + defer pdb.mtx.Unlock() + + var pstart, pend []byte + pstart = append(cp(pdb.prefix), start...) + if end == nil { + pend = cpIncr(pdb.prefix) + } else { + pend = append(cp(pdb.prefix), end...) + } + ritr, err := pdb.db.ReverseIterator(pstart, pend) + if err != nil { + return nil, err + } + + return newPrefixIterator(pdb.prefix, start, end, ritr) +} + +// NewBatch implements DB. +func (pdb *PrefixDB) NewBatch() Batch { + pdb.mtx.Lock() + defer pdb.mtx.Unlock() + + return newPrefixBatch(pdb.prefix, pdb.db.NewBatch()) +} + +// Close implements DB. +func (pdb *PrefixDB) Close() error { + pdb.mtx.Lock() + defer pdb.mtx.Unlock() + + return pdb.db.Close() +} + +// Print implements DB. +func (pdb *PrefixDB) Print() error { + fmt.Printf("prefix: %X\n", pdb.prefix) + + itr, err := pdb.Iterator(nil, nil) + if err != nil { + return err + } + defer itr.Close() + for ; itr.Valid(); itr.Next() { + key := itr.Key() + value := itr.Value() + fmt.Printf("[%X]:\t[%X]\n", key, value) + } + return nil +} + +// Stats implements DB. +func (pdb *PrefixDB) Stats() map[string]string { + stats := make(map[string]string) + stats["prefixdb.prefix.string"] = string(pdb.prefix) + stats["prefixdb.prefix.hex"] = fmt.Sprintf("%X", pdb.prefix) + source := pdb.db.Stats() + for key, value := range source { + stats["prefixdb.source."+key] = value + } + return stats +} + +func (pdb *PrefixDB) prefixed(key []byte) []byte { + return append(cp(pdb.prefix), key...) +} + +func (pdb *PrefixDB) Compact(start, end []byte) error { + return pdb.db.Compact(start, end) +} diff --git a/libs/db/prefixdb_batch.go b/libs/db/prefixdb_batch.go new file mode 100644 index 0000000000..1a8005cad5 --- /dev/null +++ b/libs/db/prefixdb_batch.go @@ -0,0 +1,51 @@ +package db + +type prefixDBBatch struct { + prefix []byte + source Batch +} + +var _ Batch = (*prefixDBBatch)(nil) + +func newPrefixBatch(prefix []byte, source Batch) prefixDBBatch { + return prefixDBBatch{ + prefix: prefix, + source: source, + } +} + +// Set implements Batch. +func (pb prefixDBBatch) Set(key, value []byte) error { + if len(key) == 0 { + return errKeyEmpty + } + if value == nil { + return errValueNil + } + pkey := append(cp(pb.prefix), key...) + return pb.source.Set(pkey, value) +} + +// Delete implements Batch. +func (pb prefixDBBatch) Delete(key []byte) error { + if len(key) == 0 { + return errKeyEmpty + } + pkey := append(cp(pb.prefix), key...) + return pb.source.Delete(pkey) +} + +// Write implements Batch. +func (pb prefixDBBatch) Write() error { + return pb.source.Write() +} + +// WriteSync implements Batch. +func (pb prefixDBBatch) WriteSync() error { + return pb.source.WriteSync() +} + +// Close implements Batch. +func (pb prefixDBBatch) Close() error { + return pb.source.Close() +} diff --git a/libs/db/prefixdb_iterator.go b/libs/db/prefixdb_iterator.go new file mode 100644 index 0000000000..02bcc8c45e --- /dev/null +++ b/libs/db/prefixdb_iterator.go @@ -0,0 +1,131 @@ +package db + +import ( + "bytes" + "fmt" +) + +// IteratePrefix is a convenience function for iterating over a key domain +// restricted by prefix. +func IteratePrefix(db DB, prefix []byte) (Iterator, error) { + var start, end []byte + if len(prefix) == 0 { + start = nil + end = nil + } else { + start = cp(prefix) + end = cpIncr(prefix) + } + itr, err := db.Iterator(start, end) + if err != nil { + return nil, err + } + return itr, nil +} + +// Strips prefix while iterating from Iterator. +type prefixDBIterator struct { + prefix []byte + start []byte + end []byte + source Iterator + valid bool + err error +} + +var _ Iterator = (*prefixDBIterator)(nil) + +func newPrefixIterator(prefix, start, end []byte, source Iterator) (*prefixDBIterator, error) { //nolint:unparam + pitrInvalid := &prefixDBIterator{ + prefix: prefix, + start: start, + end: end, + source: source, + valid: false, + } + + // Empty keys are not allowed, so if a key exists in the database that exactly matches the + // prefix we need to skip it. + if source.Valid() && bytes.Equal(source.Key(), prefix) { + source.Next() + } + + if !source.Valid() || !bytes.HasPrefix(source.Key(), prefix) { + return pitrInvalid, nil + } + + return &prefixDBIterator{ + prefix: prefix, + start: start, + end: end, + source: source, + valid: true, + }, nil +} + +// Domain implements Iterator. +func (itr *prefixDBIterator) Domain() (start []byte, end []byte) { + return itr.start, itr.end +} + +// Valid implements Iterator. +func (itr *prefixDBIterator) Valid() bool { + if !itr.valid || itr.err != nil || !itr.source.Valid() { + return false + } + + key := itr.source.Key() + if len(key) < len(itr.prefix) || !bytes.Equal(key[:len(itr.prefix)], itr.prefix) { + itr.err = fmt.Errorf("received invalid key from backend: %x (expected prefix %x)", + key, itr.prefix) + return false + } + + return true +} + +// Next implements Iterator. +func (itr *prefixDBIterator) Next() { + itr.assertIsValid() + itr.source.Next() + + if !itr.source.Valid() || !bytes.HasPrefix(itr.source.Key(), itr.prefix) { + itr.valid = false + } else if bytes.Equal(itr.source.Key(), itr.prefix) { + // Empty keys are not allowed, so if a key exists in the database that exactly matches the + // prefix we need to skip it. + itr.Next() + } +} + +// Next implements Iterator. +func (itr *prefixDBIterator) Key() []byte { + itr.assertIsValid() + key := itr.source.Key() + return key[len(itr.prefix):] // we have checked the key in Valid() +} + +// Value implements Iterator. +func (itr *prefixDBIterator) Value() []byte { + itr.assertIsValid() + return itr.source.Value() +} + +// Error implements Iterator. +func (itr *prefixDBIterator) Error() error { + if err := itr.source.Error(); err != nil { + return err + } + return itr.err +} + +// Close implements Iterator. +func (itr *prefixDBIterator) Close() error { + return itr.source.Close() +} + +func (itr *prefixDBIterator) assertIsValid() { + if !itr.Valid() { + panic("iterator is invalid") + } +} diff --git a/libs/db/prefixdb_test.go b/libs/db/prefixdb_test.go new file mode 100644 index 0000000000..4f7194d8bd --- /dev/null +++ b/libs/db/prefixdb_test.go @@ -0,0 +1,123 @@ +package db + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func mockDBWithStuff(t *testing.T) DB { + t.Helper() + db := NewMemDB() + // Under "key" prefix + require.NoError(t, db.Set(bz("key"), bz("value"))) + require.NoError(t, db.Set(bz("key1"), bz("value1"))) + require.NoError(t, db.Set(bz("key2"), bz("value2"))) + require.NoError(t, db.Set(bz("key3"), bz("value3"))) + require.NoError(t, db.Set(bz("something"), bz("else"))) + require.NoError(t, db.Set(bz("k"), bz("val"))) + require.NoError(t, db.Set(bz("ke"), bz("valu"))) + require.NoError(t, db.Set(bz("kee"), bz("valuu"))) + return db +} + +func TestPrefixDBSimple(t *testing.T) { + db := mockDBWithStuff(t) + pdb := NewPrefixDB(db, bz("key")) + + checkValue(t, pdb, bz("key"), nil) + checkValue(t, pdb, bz("key1"), nil) + checkValue(t, pdb, bz("1"), bz("value1")) + checkValue(t, pdb, bz("key2"), nil) + checkValue(t, pdb, bz("2"), bz("value2")) + checkValue(t, pdb, bz("key3"), nil) + checkValue(t, pdb, bz("3"), bz("value3")) + checkValue(t, pdb, bz("something"), nil) + checkValue(t, pdb, bz("k"), nil) + checkValue(t, pdb, bz("ke"), nil) + checkValue(t, pdb, bz("kee"), nil) +} + +func TestPrefixDBIterator1(t *testing.T) { + db := mockDBWithStuff(t) + pdb := NewPrefixDB(db, bz("key")) + + itr, err := pdb.Iterator(nil, nil) + require.NoError(t, err) + checkDomain(t, itr, nil, nil) + checkItem(t, itr, bz("1"), bz("value1")) + checkNext(t, itr, true) + checkItem(t, itr, bz("2"), bz("value2")) + checkNext(t, itr, true) + checkItem(t, itr, bz("3"), bz("value3")) + checkNext(t, itr, false) + checkInvalid(t, itr) + err = itr.Close() + require.NoError(t, err) +} + +func TestPrefixDBReverseIterator1(t *testing.T) { + db := mockDBWithStuff(t) + pdb := NewPrefixDB(db, bz("key")) + + itr, err := pdb.ReverseIterator(nil, nil) + require.NoError(t, err) + checkDomain(t, itr, nil, nil) + checkItem(t, itr, bz("3"), bz("value3")) + checkNext(t, itr, true) + checkItem(t, itr, bz("2"), bz("value2")) + checkNext(t, itr, true) + checkItem(t, itr, bz("1"), bz("value1")) + checkNext(t, itr, false) + checkInvalid(t, itr) + err = itr.Close() + require.NoError(t, err) +} + +func TestPrefixDBReverseIterator5(t *testing.T) { + db := mockDBWithStuff(t) + pdb := NewPrefixDB(db, bz("key")) + + itr, err := pdb.ReverseIterator(bz("1"), nil) + require.NoError(t, err) + checkDomain(t, itr, bz("1"), nil) + checkItem(t, itr, bz("3"), bz("value3")) + checkNext(t, itr, true) + checkItem(t, itr, bz("2"), bz("value2")) + checkNext(t, itr, true) + checkItem(t, itr, bz("1"), bz("value1")) + checkNext(t, itr, false) + checkInvalid(t, itr) + err = itr.Close() + require.NoError(t, err) +} + +func TestPrefixDBReverseIterator6(t *testing.T) { + db := mockDBWithStuff(t) + pdb := NewPrefixDB(db, bz("key")) + + itr, err := pdb.ReverseIterator(bz("2"), nil) + require.NoError(t, err) + checkDomain(t, itr, bz("2"), nil) + checkItem(t, itr, bz("3"), bz("value3")) + checkNext(t, itr, true) + checkItem(t, itr, bz("2"), bz("value2")) + checkNext(t, itr, false) + checkInvalid(t, itr) + err = itr.Close() + require.NoError(t, err) +} + +func TestPrefixDBReverseIterator7(t *testing.T) { + db := mockDBWithStuff(t) + pdb := NewPrefixDB(db, bz("key")) + + itr, err := pdb.ReverseIterator(nil, bz("2")) + require.NoError(t, err) + checkDomain(t, itr, nil, bz("2")) + checkItem(t, itr, bz("1"), bz("value1")) + checkNext(t, itr, false) + checkInvalid(t, itr) + err = itr.Close() + require.NoError(t, err) +} diff --git a/libs/db/test_helpers_test.go b/libs/db/test_helpers_test.go new file mode 100644 index 0000000000..7bfc579aa7 --- /dev/null +++ b/libs/db/test_helpers_test.go @@ -0,0 +1,38 @@ +// Modified by Tenderdash contributors from cometbft-db v1.0.4. +// See README.md for provenance and LICENSE for license terms. + +package db + +import "math/rand" + +const ( + strChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" // 62 characters +) + +// For testing convenience. +func bz(s string) []byte { + return []byte(s) +} + +// Str constructs a random alphanumeric string of given length. +func randStr(length int) string { //nolint:unparam + chars := []byte{} +MAIN_LOOP: + for { + val := rand.Int63() + for i := 0; i < 10; i++ { + v := int(val & 0x3f) // rightmost 6 bits + if v >= 62 { // only 62 characters in strChars + val >>= 6 + continue + } + chars = append(chars, strChars[v]) + if len(chars) == length { + break MAIN_LOOP + } + val >>= 6 + } + } + + return string(chars) +} diff --git a/libs/db/types.go b/libs/db/types.go new file mode 100644 index 0000000000..06bf5c4d8b --- /dev/null +++ b/libs/db/types.go @@ -0,0 +1,163 @@ +// Modified by Tenderdash contributors from cometbft-db v1.0.4. +// See README.md for provenance and LICENSE for license terms. + +package db + +import "errors" + +var ( + // errBatchClosed is returned when a closed or written batch is used. + errBatchClosed = errors.New("batch has been written or closed") + + // errKeyEmpty is returned when attempting to use an empty or nil key. + errKeyEmpty = errors.New("key cannot be empty") + + // errValueNil is returned when attempting to set a nil value. + errValueNil = errors.New("value cannot be nil") +) + +// DB is the main interface for all database backends. DBs are concurrency-safe. Callers must call +// Close on the database when done. +// +// Keys cannot be nil or empty, while values cannot be nil. Keys and values should be considered +// read-only, both when returned and when given, and must be copied before they are modified. +type DB interface { + // Get fetches the value of the given key, or nil if it does not exist. + // GoLevelDB also returns nil for stored empty values; MemDB returns a non-nil empty slice. + // This inherited difference is tracked at https://github.com/dashpay/tenderdash/issues/1554. + // CONTRACT: key, value readonly []byte + Get(key []byte) ([]byte, error) + + // Has checks if a key exists. + // GoLevelDB reports false for stored empty values; MemDB reports true. + // CONTRACT: key, value readonly []byte + Has(key []byte) (bool, error) + + // Set sets the value for the given key, replacing it if it already exists. + // CONTRACT: key, value readonly []byte + Set(key []byte, value []byte) error + + // SetSync sets the value for the given key, and flushes it to storage before returning. + SetSync(key []byte, value []byte) error + + // Delete deletes the key, or does nothing if the key does not exist. + // CONTRACT: key readonly []byte + Delete(key []byte) error + + // DeleteSync deletes the key, and flushes the delete to storage before returning. + DeleteSync(key []byte) error + + // Iterator returns an iterator over a domain of keys, in ascending order. The caller must call + // Close when done. End is exclusive, and start must be less than end. A nil start iterates + // from the first key, and a nil end iterates to the last key (inclusive). Empty keys are not + // valid. + // CONTRACT: No writes may happen within a domain while an iterator exists over it. + // CONTRACT: start, end readonly []byte + Iterator(start, end []byte) (Iterator, error) + + // ReverseIterator returns an iterator over a domain of keys, in descending order. The caller + // must call Close when done. End is exclusive, and start must be less than end. A nil end + // iterates from the last key (inclusive), and a nil start iterates to the first key (inclusive). + // Empty keys are not valid. + // CONTRACT: No writes may happen within a domain while an iterator exists over it. + // CONTRACT: start, end readonly []byte + ReverseIterator(start, end []byte) (Iterator, error) + + // Close closes the database connection. + Close() error + + // NewBatch creates a batch for atomic updates. The caller must call Batch.Close. + NewBatch() Batch + + // Print is used for debugging. + Print() error + + // Stats returns a map of property values for all keys and the size of the cache. + Stats() map[string]string + + // Compact explicitly + Compact(start, end []byte) error +} + +// Batch represents a group of writes. They may or may not be written atomically depending on the +// backend. Callers must call Close on the batch when done. +// +// As with DB, given keys and values should be considered read-only, and must not be modified after +// passing them to the batch. +type Batch interface { + // Set sets a key/value pair. + // CONTRACT: key, value readonly []byte + Set(key, value []byte) error + + // Delete deletes a key/value pair. + // CONTRACT: key readonly []byte + Delete(key []byte) error + + // Write writes the batch, possibly without flushing to disk. Only Close() can be called after, + // other methods will error. + Write() error + + // WriteSync writes the batch and flushes it to disk. Only Close() can be called after, other + // methods will error. + WriteSync() error + + // Close closes the batch. It is idempotent, but calls to other methods afterwards will error. + Close() error +} + +// Iterator represents an iterator over a domain of keys. Callers must call Close when done. +// No writes can happen to a domain while there exists an iterator over it, some backends may take +// out database locks to ensure this will not happen. +// +// Callers must make sure the iterator is valid before calling any methods on it, otherwise +// these methods will panic. This is in part caused by most backend databases using this convention. +// +// As with DB, keys and values should be considered read-only, and must be copied before they are +// modified. +// +// Typical usage: +// +// var itr Iterator = ... +// defer itr.Close() +// +// for ; itr.Valid(); itr.Next() { +// k, v := itr.Key(); itr.Value() +// ... +// } +// +// if err := itr.Error(); err != nil { +// ... +// } +type Iterator interface { + // Domain returns the start (inclusive) and end (exclusive) limits of the iterator. + // CONTRACT: start, end readonly []byte + Domain() (start []byte, end []byte) + + // Valid returns whether the current iterator is valid. Once invalid, the Iterator remains + // invalid forever. + Valid() bool + + // Next moves the iterator to the next key in the database, as defined by order of iteration. + // If Valid returns false, this method will panic. + Next() + + // Key returns the key at the current position. Panics if the iterator is invalid. + // Key returns the key of the current key/value pair, or nil if done. + // The caller should not modify the contents of the returned slice, and + // its contents may change on the next call to any 'seeks method'. + // Instead, the caller should make a copy and work on the copy. + Key() (key []byte) + + // Value returns the value at the current position. Panics if the iterator is invalid. + // Value returns the value of the current key/value pair, or nil if done. + // The caller should not modify the contents of the returned slice, and + // its contents may change on the next call to any 'seeks method'. + // Instead, the caller should make a copy and work on the copy. + Value() (value []byte) + + // Error returns the last error encountered by the iterator, if any. + Error() error + + // Close closes the iterator, relasing any allocated resources. + Close() error +} diff --git a/libs/db/util.go b/libs/db/util.go new file mode 100644 index 0000000000..c7e57dd441 --- /dev/null +++ b/libs/db/util.go @@ -0,0 +1,51 @@ +package db + +import ( + "bytes" + "os" +) + +func cp(bz []byte) (ret []byte) { + ret = make([]byte, len(bz)) + copy(ret, bz) + return ret +} + +// Returns a slice of the same length (big endian) +// except incremented by one. +// Returns nil on overflow (e.g. if bz bytes are all 0xFF) +// CONTRACT: len(bz) > 0. +func cpIncr(bz []byte) (ret []byte) { + if len(bz) == 0 { + panic("cpIncr expects non-zero bz length") + } + ret = cp(bz) + for i := len(bz) - 1; i >= 0; i-- { + if ret[i] < byte(0xFF) { + ret[i]++ + return ret + } + ret[i] = byte(0x00) + if i == 0 { + // Overflow + return nil + } + } + return nil +} + +// See DB interface documentation for more information. +func IsKeyInDomain(key, start, end []byte) bool { + if bytes.Compare(key, start) < 0 { + return false + } + if end != nil && bytes.Compare(end, key) <= 0 { + return false + } + return true +} + +func FileExists(filePath string) bool { + _, err := os.Stat(filePath) + return !os.IsNotExist(err) +} diff --git a/libs/db/util_test.go b/libs/db/util_test.go new file mode 100644 index 0000000000..a83cf25a07 --- /dev/null +++ b/libs/db/util_test.go @@ -0,0 +1,118 @@ +// Modified by Tenderdash contributors from cometbft-db v1.0.4. +// See README.md for provenance and LICENSE for license terms. + +package db + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" +) + +// Empty iterator for empty db. +func TestPrefixIteratorNoMatchNil(t *testing.T) { + for backend := range backends { + t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { + db, _ := newTempDB(t, backend) + itr, err := IteratePrefix(db, []byte("2")) + require.NoError(t, err) + defer itr.Close() + + checkInvalid(t, itr) + }) + } +} + +// Empty iterator for db populated after iterator created. +func TestPrefixIteratorNoMatch1(t *testing.T) { + for backend := range backends { + + t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { + db, _ := newTempDB(t, backend) + itr, err := IteratePrefix(db, []byte("2")) + require.NoError(t, err) + defer itr.Close() + err = db.SetSync(bz("1"), bz("value_1")) + require.NoError(t, err) + + checkInvalid(t, itr) + }) + } +} + +// Empty iterator for prefix starting after db entry. +func TestPrefixIteratorNoMatch2(t *testing.T) { + for backend := range backends { + t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { + db, _ := newTempDB(t, backend) + err := db.SetSync(bz("3"), bz("value_3")) + require.NoError(t, err) + itr, err := IteratePrefix(db, []byte("4")) + require.NoError(t, err) + defer itr.Close() + + checkInvalid(t, itr) + }) + } +} + +// Iterator with single val for db with single val, starting from that val. +func TestPrefixIteratorMatch1(t *testing.T) { + for backend := range backends { + t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { + db, _ := newTempDB(t, backend) + err := db.SetSync(bz("2"), bz("value_2")) + require.NoError(t, err) + itr, err := IteratePrefix(db, bz("2")) + require.NoError(t, err) + defer itr.Close() + + checkValid(t, itr, true) + checkItem(t, itr, bz("2"), bz("value_2")) + checkNext(t, itr, false) + + // Once invalid... + checkInvalid(t, itr) + }) + } +} + +// Iterator with prefix iterates over everything with same prefix. +func TestPrefixIteratorMatches1N(t *testing.T) { + for backend := range backends { + t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { + db, _ := newTempDB(t, backend) + + // prefixed + err := db.SetSync(bz("a/1"), bz("value_1")) + require.NoError(t, err) + err = db.SetSync(bz("a/3"), bz("value_3")) + require.NoError(t, err) + + // not + err = db.SetSync(bz("b/3"), bz("value_3")) + require.NoError(t, err) + err = db.SetSync(bz("a-3"), bz("value_3")) + require.NoError(t, err) + err = db.SetSync(bz("a.3"), bz("value_3")) + require.NoError(t, err) + err = db.SetSync(bz("abcdefg"), bz("value_3")) + require.NoError(t, err) + itr, err := IteratePrefix(db, bz("a/")) + require.NoError(t, err) + defer itr.Close() + + checkValid(t, itr, true) + checkItem(t, itr, bz("a/1"), bz("value_1")) + checkNext(t, itr, true) + checkItem(t, itr, bz("a/3"), bz("value_3")) + + // Bad! + checkNext(t, itr, false) + + // Once invalid... + checkInvalid(t, itr) + }) + } +} diff --git a/light/client_benchmark_test.go b/light/client_benchmark_test.go index 63681c06fb..127240f457 100644 --- a/light/client_benchmark_test.go +++ b/light/client_benchmark_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" + dbm "github.com/dashpay/tenderdash/libs/db" dashcore "github.com/dashpay/tenderdash/dash/core" "github.com/dashpay/tenderdash/libs/log" diff --git a/light/client_test.go b/light/client_test.go index d0e41229bc..a7bdf0f172 100644 --- a/light/client_test.go +++ b/light/client_test.go @@ -9,11 +9,12 @@ import ( sync "github.com/sasha-s/go-deadlock" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + dashcore "github.com/dashpay/tenderdash/dash/core" "github.com/dashpay/tenderdash/libs/log" "github.com/dashpay/tenderdash/light" diff --git a/light/example_test.go b/light/example_test.go index 55b93fedae..3fbcc3e76b 100644 --- a/light/example_test.go +++ b/light/example_test.go @@ -5,10 +5,11 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/dashpay/dashd-go/btcjson" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/abci/example/kvstore" dashcore "github.com/dashpay/tenderdash/dash/core" "github.com/dashpay/tenderdash/libs/log" diff --git a/light/light_test.go b/light/light_test.go index 2403670bfd..7643b58a82 100644 --- a/light/light_test.go +++ b/light/light_test.go @@ -5,9 +5,10 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/dashd-go/btcjson" "github.com/dashpay/tenderdash/abci/example/kvstore" diff --git a/light/store/db/db.go b/light/store/db/db.go index 63e3f89d1b..9d16c0f8cf 100644 --- a/light/store/db/db.go +++ b/light/store/db/db.go @@ -6,9 +6,10 @@ import ( sync "github.com/sasha-s/go-deadlock" - dbm "github.com/cometbft/cometbft-db" "github.com/google/orderedcode" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/light/store" tmproto "github.com/dashpay/tenderdash/proto/tendermint/types" "github.com/dashpay/tenderdash/types" diff --git a/light/store/db/db_test.go b/light/store/db/db_test.go index dbed75004b..c3b19e7769 100644 --- a/light/store/db/db_test.go +++ b/light/store/db/db_test.go @@ -7,10 +7,11 @@ import ( sync "github.com/sasha-s/go-deadlock" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/crypto" tmrand "github.com/dashpay/tenderdash/libs/rand" "github.com/dashpay/tenderdash/types" diff --git a/node/node_test.go b/node/node_test.go index 106b2e23f5..3906b1082e 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -12,12 +12,13 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/fortytw2/leaktest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + abciclient "github.com/dashpay/tenderdash/abci/client" abcimocks "github.com/dashpay/tenderdash/abci/client/mocks" "github.com/dashpay/tenderdash/abci/example/kvstore" diff --git a/node/setup.go b/node/setup.go index 3e096d4227..13be7b24c6 100644 --- a/node/setup.go +++ b/node/setup.go @@ -9,11 +9,12 @@ import ( "strings" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/dashpay/dashd-go/btcjson" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" + dbm "github.com/dashpay/tenderdash/libs/db" + abciclient "github.com/dashpay/tenderdash/abci/client" "github.com/dashpay/tenderdash/config" "github.com/dashpay/tenderdash/crypto" diff --git a/scripts/keymigrate/migrate.go b/scripts/keymigrate/migrate.go index 364ee5c9c7..a5afd87038 100644 --- a/scripts/keymigrate/migrate.go +++ b/scripts/keymigrate/migrate.go @@ -17,9 +17,10 @@ import ( "strconv" "sync" - dbm "github.com/cometbft/cometbft-db" "github.com/google/orderedcode" "golang.org/x/sync/errgroup" + + dbm "github.com/dashpay/tenderdash/libs/db" ) type ( diff --git a/scripts/scmigrate/migrate.go b/scripts/scmigrate/migrate.go index ddacff31c4..5e1ab3d480 100644 --- a/scripts/scmigrate/migrate.go +++ b/scripts/scmigrate/migrate.go @@ -13,10 +13,11 @@ import ( "fmt" "sort" - dbm "github.com/cometbft/cometbft-db" "github.com/cosmos/gogoproto/proto" "github.com/google/orderedcode" + dbm "github.com/dashpay/tenderdash/libs/db" + tmproto "github.com/dashpay/tenderdash/proto/tendermint/types" "github.com/dashpay/tenderdash/types" ) diff --git a/scripts/scmigrate/migrate_test.go b/scripts/scmigrate/migrate_test.go index fded33727b..88b2be4f1b 100644 --- a/scripts/scmigrate/migrate_test.go +++ b/scripts/scmigrate/migrate_test.go @@ -6,9 +6,10 @@ import ( "math/rand" "testing" - dbm "github.com/cometbft/cometbft-db" "github.com/cosmos/gogoproto/proto" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/types" ) diff --git a/test/e2e/app/app.go b/test/e2e/app/app.go index 0ee3573672..155d164e28 100644 --- a/test/e2e/app/app.go +++ b/test/e2e/app/app.go @@ -11,9 +11,10 @@ import ( "strings" "time" - db "github.com/cometbft/cometbft-db" sync "github.com/sasha-s/go-deadlock" + db "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/abci/example/code" "github.com/dashpay/tenderdash/abci/example/kvstore" abci "github.com/dashpay/tenderdash/abci/types" diff --git a/test/e2e/tests/app_test.go b/test/e2e/tests/app_test.go index 4a7a3e84b2..5287da03db 100644 --- a/test/e2e/tests/app_test.go +++ b/test/e2e/tests/app_test.go @@ -11,11 +11,12 @@ import ( "testing" "time" - db "github.com/cometbft/cometbft-db" sync "github.com/sasha-s/go-deadlock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + db "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/abci/example/code" "github.com/dashpay/tenderdash/abci/example/kvstore" tmbytes "github.com/dashpay/tenderdash/libs/bytes" diff --git a/test/floodclient/client_test.go b/test/floodclient/client_test.go index 633019b91d..8dbb6360e0 100644 --- a/test/floodclient/client_test.go +++ b/test/floodclient/client_test.go @@ -8,9 +8,10 @@ import ( "testing" "time" - dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/require" + dbm "github.com/dashpay/tenderdash/libs/db" + "github.com/dashpay/tenderdash/internal/p2p" "github.com/dashpay/tenderdash/internal/p2p/conn" "github.com/dashpay/tenderdash/libs/log" From c516ed61e4dfb63453d1098e32ece733e680a2de Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:22:48 +0000 Subject: [PATCH 02/12] docs: specify full consensus parameter commitments for v2.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define a draft canonical full snapshot, independent commitment selector, activation boundary, historical verification and state-sync trust rules. Add the source protobuf schema and an implementation and verification plan. Runtime support and generated bindings are intentionally deferred. 🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent Co-Authored-By: Codex GPT-6 --- proto/tendermint/types/canonical.proto | 3 +- proto/tendermint/types/params.proto | 40 +++- proto/tendermint/types/types.proto | 2 + spec/README.md | 1 + spec/consensus/consensus-params-v2.md | 265 +++++++++++++++++++++++++ spec/consensus/consensus.md | 4 + 6 files changed, 311 insertions(+), 4 deletions(-) create mode 100644 spec/consensus/consensus-params-v2.md diff --git a/proto/tendermint/types/canonical.proto b/proto/tendermint/types/canonical.proto index c88923b7a5..63f4d567b4 100644 --- a/proto/tendermint/types/canonical.proto +++ b/proto/tendermint/types/canonical.proto @@ -35,7 +35,8 @@ message CanonicalVote { SignedMsgType type = 1; // type alias for byte sfixed64 height = 2; // canonicalization requires fixed size encoding here sfixed64 round = 3; // canonicalization requires fixed size encoding here - // block_id is a checksum (sha256) of CanonicalBlockID for the block being voted on + // block_id is a checksum (sha256) of CanonicalBlockID for the block being voted on. + // Its header hash binds current and next consensus parameter commitments. bytes block_id = 4 [(gogoproto.customname) = "BlockID"]; // state_id is a checksum (sha256) of StateID message for the block being voted on bytes state_id = 5 [(gogoproto.customname) = "StateID"]; diff --git a/proto/tendermint/types/params.proto b/proto/tendermint/types/params.proto index ebfc8bf8a4..9d91d48e57 100644 --- a/proto/tendermint/types/params.proto +++ b/proto/tendermint/types/params.proto @@ -20,6 +20,16 @@ message ConsensusParams { SynchronyParams synchrony = 5; TimeoutParams timeout = 6; ABCIParams abci = 7; + + // Draft v2.0 selector, independent of the consensus protocol version. + // Omission retains the current value in a partial update; FULL cannot downgrade. + // See spec/consensus/consensus-params-v2.md; runtime support is deferred. + optional CommitmentVersion commitment_version = 8; + + enum CommitmentVersion { + COMMITMENT_VERSION_LEGACY = 0; + COMMITMENT_VERSION_FULL = 1; + } } // BlockParams contains limits on the block size. @@ -95,15 +105,39 @@ message VersionParams { } } -// HashedParams is a subset of ConsensusParams. -// -// It is hashed into the Header.ConsensusHash. +// HashedParams is the legacy subset committed by Header.ConsensusHash. +// Preserve its schema and encoding for historical block verification. message HashedParams { int64 block_max_bytes = 1; int64 block_max_gas = 2; int32 consensus_version = 3; } +// HashedParamsV2 is the draft complete effective-parameter snapshot for FULL. +// Freeze this mapping and its encoding before activation; do not hash ABCI patches. +// See spec/consensus/consensus-params-v2.md for canonical bytes and domain separation. +message HashedParamsV2 { + option (gogoproto.stable_marshaler) = true; + + uint32 commitment_version = 1; // Must be 1 (FULL). + int64 block_max_bytes = 2; + int64 block_max_gas = 3; + int64 evidence_max_age_num_blocks = 4; + int64 evidence_max_age_duration_ns = 5; + int64 evidence_max_bytes = 6; + repeated string validator_pub_key_types = 7; + optional uint64 validator_voting_power_threshold = 8; + uint64 version_app_version = 9; + int32 version_consensus_version = 10; + int64 synchrony_message_delay_ns = 11; + int64 synchrony_precision_ns = 12; + int64 timeout_propose_ns = 13; + int64 timeout_propose_delta_ns = 14; + int64 timeout_vote_ns = 15; + int64 timeout_vote_delta_ns = 16; + bool abci_recheck_tx = 17; +} + // SynchronyParams configure the bounds under which a proposed block's timestamp is considered valid. // These parameters are part of the proposer-based timestamps algorithm. For more information, // see the specification of proposer-based timestamps: diff --git a/proto/tendermint/types/types.proto b/proto/tendermint/types/types.proto index ea64fa29dc..02de7234c4 100644 --- a/proto/tendermint/types/types.proto +++ b/proto/tendermint/types/types.proto @@ -104,6 +104,8 @@ message Header { // hashes from the app output from the prev block bytes validators_hash = 8; // validators for the current block bytes next_validators_hash = 9; // validators for the next block + // Current and next parameter commitments enter Header.Hash and the signed BlockID. + // Draft full-commitment rules: spec/consensus/consensus-params-v2.md. bytes consensus_hash = 10; // consensus params for current block bytes next_consensus_hash = 11; // consensus params for next block bytes app_hash = 12; // state after txs from the previous block diff --git a/spec/README.md b/spec/README.md index c60951f28d..5b2c440439 100644 --- a/spec/README.md +++ b/spec/README.md @@ -20,6 +20,7 @@ It shall be used to describe protocol semantics, namely the BFT consensus engine - [Core Data Structures](./core/data_structures.md) - [State](./core/state.md) - [Consensus Algorithm](./consensus/consensus.md) +- [Full Consensus Parameter Commitment (draft v2.0)](./consensus/consensus-params-v2.md) - [Creating a proposal](./consensus/creating-proposal.md) - [Time](./consensus/proposer-based-timestamp/README.md) - [Light Client](./consensus/light-client/README.md) diff --git a/spec/consensus/consensus-params-v2.md b/spec/consensus/consensus-params-v2.md new file mode 100644 index 0000000000..cb57516fb2 --- /dev/null +++ b/spec/consensus/consensus-params-v2.md @@ -0,0 +1,265 @@ +# Full Consensus Parameter Commitment + +**DRAFT — v2.0 target.** This is a normative design and source schema proposal, +not implemented consensus behavior. Generated bindings, runtime support and +activation are deliberately deferred. The current Go implementation is unchanged. +MUST, MUST NOT and SHOULD describe the target implementation. + +## Acceptance scenarios + +| Scenario | Required result | +| --- | --- | +| Change any effective parameter, including evidence limits, timeout or threshold presence | The full commitment changes; a substituted snapshot fails authentication. | +| Equivalent complete state reached through different partial updates | Identical canonical bytes and hash; raw ABCI patches are never hashed. | +| Omit the commitment selector in a partial update | Retain the current selector. An explicit FULL-to-LEGACY downgrade is rejected. | +| Activate FULL at height H | H-1 signs the full next-parameter hash; H uses the full current-parameter hash. | +| Attempt activation with incomplete groups or duration fields | Reject before accepting a candidate; unauthenticated legacy values cannot fill gaps. | +| Bootstrap from FULL history with a changed threshold | Authenticate each required height's parameters and validator context; do not pin a legitimate mutable threshold to genesis. | +| Replay or restart across activation | Preserve selector presence and historical hash rules; produce the original block IDs and verify the original signatures. | +| Receive unknown selectors, unsupported parameter fields or noncanonical snapshot bytes | Fail closed; never silently downgrade or omit a new parameter. | + +## Existing commitment and threat boundary + +At this proposal's base, `types/params.go:HashConsensusParams` hashes only +`Block.MaxBytes`, `Block.MaxGas` and `Version.ConsensusVersion` through the existing +`HashedParams` message. Evidence limits, validator key types and voting threshold, +application version, synchrony bounds, timeouts and ABCI rechecking are outside +that digest. Actual evidence proofs already contribute to `EvidenceHash`; this +proposal adds their configurable limits, not a second commitment to the proofs. + +`Header.Hash` already includes `ConsensusHash` and `NextConsensusHash`. Its result +enters `BlockID.Hash`, the canonical block-ID digest, `CanonicalVote` and the +quorum-bound BLS signing digest. `Vote.SignBytes` in +[`proto/tendermint/types/types.go`](../../proto/tendermint/types/types.go) uses +[`libs/bytes/marshal.go`](../../libs/bytes/marshal.go)'s fixed-size field encoding, +not ordinary Protobuf wire encoding of the vote. Authenticating both parameter +hashes therefore needs no new signature field and no new `StateID` field. Preserve +that existing vote layout, fixed-width height/round encoding and signing domains. See +[signing](signing.md), [block headers](../core/data_structures.md#header), +[`types/block.go`](../../types/block.go), +[`types/canonical.go`](../../types/canonical.go) and +[`types/quorum_sign_data.go`](../../types/quorum_sign_data.go). + +A threshold BLS signature proves recovery under the quorum key. It does not prove +that a raised application voting-power threshold was met by enough distinct +signers. Adding signer-count attestation for that separate issue is out of scope. + +## Independent commitment selector + +`ConsensusParams.commitment_version`, optional field 8, selects the hash rule: + +| Value | Meaning | +| --- | --- | +| `COMMITMENT_VERSION_LEGACY = 0` | Preserve the hash rule applicable to that historical protocol/height. | +| `COMMITMENT_VERSION_FULL = 1` | Domain-separated hash of the complete `HashedParamsV2` snapshot below. | + +Omission in an existing genesis document means LEGACY. Omission in an ABCI partial +update means retain the current value, including FULL. An explicit selector is +validated before merging the update; unknown values and FULL-to-LEGACY transitions +MUST be rejected. ABCI patch conversions and no-op detection MUST preserve selector +presence and value: an explicit LEGACY value and an omitted update are different +inputs. Materialized state MUST serialize its resolved selector explicitly through +domain/protobuf/JSON, state-store and state-sync conversions; state equality MUST +compare that value as well as threshold presence and value. + +This selector is independent of `VersionParams.ConsensusVersion`, the block wire +protocol version, and release numbering. The v2.0 release label does not allocate +`CONSENSUS_VERSION_2` or any new block protocol constant. + +## Complete snapshot and frozen mapping + +Start with a validated, fully resolved effective `ConsensusParams` value. Apply +the normal ABCI candidate update and completion rules before constructing this +snapshot. Do not hash a response patch, pointer addresses, JSON, local timeout +overrides or opaque encoded `ConsensusParams` bytes. Nodes MUST use the same +effective parameter values for validation and commitment. + +The source of truth is +[`proto/tendermint/types/params.proto`](../../proto/tendermint/types/params.proto). +`HashedParamsV2` is a flat message; the following mapping is exhaustive for the +seven parameter groups in this base. Durations are signed 64-bit nanosecond counts. + +| Tag | Snapshot field | Protobuf type | Effective source | +| --- | --- | --- | --- | +| 1 | `commitment_version` | `uint32` | Constant 1 for FULL | +| 2 | `block_max_bytes` | `int64` | `Block.MaxBytes` | +| 3 | `block_max_gas` | `int64` | `Block.MaxGas` | +| 4 | `evidence_max_age_num_blocks` | `int64` | `Evidence.MaxAgeNumBlocks` | +| 5 | `evidence_max_age_duration_ns` | `int64` | `Evidence.MaxAgeDuration` | +| 6 | `evidence_max_bytes` | `int64` | `Evidence.MaxBytes` | +| 7 | `validator_pub_key_types` | repeated `string` | `Validator.PubKeyTypes`, preserving order | +| 8 | `validator_voting_power_threshold` | optional `uint64` | `Validator.VotingPowerThreshold`, preserving absence versus explicit zero | +| 9 | `version_app_version` | `uint64` | `Version.AppVersion` | +| 10 | `version_consensus_version` | `int32` | `Version.ConsensusVersion` | +| 11 | `synchrony_message_delay_ns` | `int64` | `Synchrony.MessageDelay` | +| 12 | `synchrony_precision_ns` | `int64` | `Synchrony.Precision` | +| 13 | `timeout_propose_ns` | `int64` | `Timeout.Propose` | +| 14 | `timeout_propose_delta_ns` | `int64` | `Timeout.ProposeDelta` | +| 15 | `timeout_vote_ns` | `int64` | `Timeout.Vote` | +| 16 | `timeout_vote_delta_ns` | `int64` | `Timeout.VoteDelta` | +| 17 | `abci_recheck_tx` | `bool` | `ABCI.RecheckTx` | + +Do not sort or deduplicate public-key types during hashing. Their order is part of +the committed value even if current validation treats the list as a membership +set. Null and zero voting thresholds remain distinct snapshots; resolving a +threshold to a quorum default MUST NOT erase this distinction. Duration conversion +MUST be exact and within int64 range; reject overflow and invalid effective values. + +The `HashedParamsV2` field meanings, tags, wire types and canonical encoding MUST +be frozen before activation. A future parameter or changed interpretation requires +an explicit reviewed commitment-version upgrade, not silent omission or mutation +of this snapshot. The existing `HashedParams` schema and historical bytes remain +unchanged. + +## Canonical bytes and domain + +For validated effective parameters `P`, define: + +```text +FullHash(P) = SHA256(ASCII("tenderdash/consensus-params/v2") || 0x00 || EncodeV2(P)) +``` + +`EncodeV2` is Protobuf wire encoding with these additional normative constraints: + +1. Encode fields in ascending tag order. Encode each singular field at most once; + repeated strings appear consecutively in their original order. +2. Use minimal unsigned varints for tags, lengths, unsigned integers and positive + signed integers. Negative `int64` values use their two's-complement 64-bit + value as a ten-byte varint; `block_max_gas = -1` is valid. Do not use zigzag + encoding. Supported consensus-version values must pass protocol validation. +3. Omit zero non-presence scalar fields, false booleans and absent optional fields. + Encode a present optional threshold even when its value is zero. A nonempty + repeated list retains each entry, including an empty string if validation ever + permits it; current parameter validation still applies. +4. Strings MUST be valid UTF-8 and are encoded as their exact UTF-8 bytes without + Unicode normalization. No maps, nested messages or `Duration` wire encodings + occur in this snapshot. +5. Reject unknown snapshot tags, duplicate singular fields, wrong wire types, + nonminimal varints, malformed lengths, invalid UTF-8 and any byte sequence + differing from the canonical re-encoding. Reject unsupported effective + parameter fields before constructing the snapshot rather than dropping them. + +Stable-marshaler options in the source schema support the implementation but are +not the cross-language definition. Generic “deterministic protobuf” serialization +alone is not a sufficient contract; see the official +[serialization is not canonical](https://protobuf.dev/programming-guides/serialization-not-canonical/) +guidance. Implementations MUST satisfy these rules and the shared conformance +vectors. The domain prefix is included only for FULL; +never apply it retroactively to a legacy hash. + +## Activation and ordinary updates + +Let H be the first height whose current parameters select FULL. The software and +application upgrade MUST be deployed before height H-1, whose candidate already +needs to construct and validate a full next-parameter commitment. + +| Block height | Current selector and `ConsensusHash` | Next selector and `NextConsensusHash` | +| --- | --- | --- | +| H-2 | LEGACY / historical hash | LEGACY / historical hash | +| H-1 | LEGACY / historical hash | FULL / `FullHash(P_H)` | +| H and later | FULL / `FullHash(P_h)` | FULL / `FullHash(P_(h+1))` | + +At H-1 the application MUST explicitly supply `commitment_version = FULL` and all +seven parameter-group messages: block, evidence, validator, version, synchrony, +timeout and ABCI. Every duration field MUST be supplied. Each supplied group is +the complete intended replacement under the normal update semantics; zero scalar +values are intentional values where valid. Within the complete validator group, +an absent threshold explicitly means no configured override, not inheritance. +Recompute the candidate validator set's live voting threshold from these complete +parameters even when membership does not change: absence MUST clear a copied +override to the quorum-default representation (`VotingPowerThreshold = 0`). +Explicit zero also selects that default at runtime, while remaining distinct in +the snapshot. A signed parameter hash MUST NOT coexist with a stale inherited +validator-set override. + +Reject activation patches that omit a group or duration, require inherited +uncommitted values, or fail normal validation. Validate completeness before any +completion routine can fill omissions. This prevents an earlier unauthenticated +state-sync parameter from seeding the first full snapshot. Validate the complete +candidate after normal ABCI processing and require the proposer and validator to +derive identical next commitments before acceptance. A chain starting in FULL +MUST likewise supply a complete validated genesis/InitChain parameter snapshot. + +After activation, ordinary partial updates are allowed: merge into the last +authenticated full state, preserve an omitted selector, validate the result and +hash the complete effective value. Unchanged updates produce unchanged hashes. +Persist the selected current and next states atomically with their normal block +application state; restart and replay MUST recover the original transition. + +## State sync, light verification and history + +Both RPC and P2P state providers MUST select the commitment rule from authenticated +protocol/height context and the candidate selector, verify it against the signed +header hash, and reject mismatches or unknown rules before installing state. +A peer's selector is not independently trusted. Authenticate the snapshot at the +height whose `ConsensusHash` is used; if using a prior header's `NextConsensusHash`, +bind it to the successor height. Do not infer authenticity from structural +validation, a claimed response height or the mere presence of FULL. + +For FULL, allow legitimate threshold updates only after complete-hash verification; +do not keep the legacy genesis pin as a substitute for that authentication. +Bootstrap may require different parameter snapshots for `LastValidators` and +`Validators`: bind each validator set to its own height's signed parameters rather +than applying one current threshold to both. Preserve Dash Core quorum membership, +key and quorum-hash verification; `ValidatorSet.Hash` alone does not commit every +member or a voting-power override. Never trust remote quorum/threshold data merely +because it accompanies an application snapshot. + +For LEGACY history, retain existing genesis-threshold and quorum-binding defenses; +FULL is not a reason to weaken verification of old blocks. Keep each historical +hash variant applicable to its original protocol and height. Old clients that +ignore the selector cannot safely follow activation: interoperability is an +upgrade requirement, not a fallback to legacy verification. + +## Integration and implementation sequence + +1. Resolve the integration blocker before freezing this snapshot. Open + [#1572](https://github.com/dashpay/tenderdash/pull/1572) assigns heartbeat behavior + `ConsensusVersion = 2` and adds two timeouts to its legacy hash; + [#1583](https://github.com/dashpay/tenderdash/pull/1583) also uses version 2 for + randomness. Reconcile those protocol assignments separately. Any heartbeat + parameters merged before activation MUST be added to the full mapping/schema + and vectors before freezing it. Preserve any merged legacy hash variant for + replay. The 17-field draft above MUST NOT activate while that coverage is stale. +2. Generate bindings and implement selector-preserving conversions, defaults, + equality and update validation in `types/params.go` and ABCI/state messages. + `Equals` currently omits voting-threshold presence/value; include both that + comparison and the selector to avoid incorrect empty/no-op shortcuts. +3. Implement the canonical snapshot encoder and version dispatch; retain the + existing legacy encoder. Wire current/next hashes through + `internal/state/current_round_state.go`, `internal/state/validation.go` and + proposal/block validation. Enforce the complete transition in genesis/InitChain + and proposal processing. Recompute derived validator thresholds, including + clearing a prior positive override when the complete new snapshot has none; + do not depend on a membership update to perform this reset. Do not allocate a + new consensus version implicitly. +4. Update persisted-state conversions, replay and startup handling. Update both + `internal/statesync/stateprovider.go` providers, `verifyConsensusParams`, + `applyVotingPowerThreshold` and P2P parameter-response conversion. Audit RPC, + light-client and SDK consumers for selector transport and height binding. +5. Publish cross-language vectors and run the tests below. Coordinate an explicit + H, deploy before H-1, exercise mixed-version rejection on a test network, and + permit activation only after all blockers and acceptance tests pass. + +## Required verification before runtime release + +| Area | Required tests | +| --- | --- | +| Coverage | Mutate every mapped scalar and each list element/order; test nil, present zero and positive threshold separately. Every effective change changes the full hash. | +| Updates | Different patches reaching the same state hash equally; omitted groups/durations retain values only after activation; invalid values, unknown selectors, unsupported fields and downgrade attempts fail closed. | +| Transition | Complete H-1 proposal accepted, incomplete transition rejected; current/next hashes at H-2/H-1/H agree across proposer, validators, stored state and RPC. Old positive live threshold to FULL with no override clears the derived threshold even with unchanged members. Complete FULL genesis works. | +| Encoding | Cross-language bytes and hashes for valid complete snapshots, zero-value omission, threshold presence, `max_gas = -1`, list order, UTF-8 and duration boundaries; reject duplicate/unknown fields and nonminimal encodings. | +| Authentication | Substitute each previously unhashed field in RPC/P2P responses; correlate response height and signed header; require per-height thresholds when validator sets cross an update. | +| Recovery | Replay and restart before/at/after H; historical signature/block-ID vectors unchanged; persisted selector and optional threshold survive round trips. | +| Quorum and policy | Retain Core-backed membership/key binding and all legacy trust defenses; authenticate FULL mutable thresholds without genesis pinning; do not claim raised-threshold signer-count attestation. | + +## Tracking + +No dedicated GitHub issue was found for the complete commitment at drafting. +This committed plan is the implementation tracker. Related work: +[#1442](https://github.com/dashpay/tenderdash/pull/1442) (legacy state-sync trust), +[#1476](https://github.com/dashpay/tenderdash/issues/1476) (peer/height correlation), +[#1546](https://github.com/dashpay/tenderdash/issues/1546) (deferred evidence) and +[#1547](https://github.com/dashpay/tenderdash/pull/1547) (evidence mode). + +🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent diff --git a/spec/consensus/consensus.md b/spec/consensus/consensus.md index 5d1526a178..7b3945573c 100644 --- a/spec/consensus/consensus.md +++ b/spec/consensus/consensus.md @@ -3,6 +3,10 @@ order: 1 --- # Byzantine Consensus Algorithm +For the proposed v2.0 parameter authentication change, see the +[Full Consensus Parameter Commitment draft](consensus-params-v2.md). +It defines a future schema and activation plan; current runtime behavior is unchanged. + ## Terms - The network is composed of optionally connected _nodes_. Nodes From dccffb86f9a40e11cf64e3e1722785bfdfd00b85 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Fri, 6 Nov 2026 12:41:47 +0000 Subject: [PATCH 03/12] docs(book): list the v2.0 consensus parameter commitment chapter Co-Authored-By: Claude Opus 5.5 --- book/SUMMARY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/book/SUMMARY.md b/book/SUMMARY.md index bc57bf6b02..615f62047a 100644 --- a/book/SUMMARY.md +++ b/book/SUMMARY.md @@ -80,6 +80,7 @@ - [Commit handling](spec/consensus/consensus-commit.md) - [Recovery and synchronisation](spec/consensus/consensus-recovery.md) - [Known issues and discrepancies](spec/consensus/consensus-known-issues.md) + - [Full consensus parameter commitment (v2.0 draft)](spec/consensus/consensus-params-v2.md) # ABCI++ From 76430450bd297933f6f225402f10b67300419a1e Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Fri, 6 Nov 2026 15:20:16 +0000 Subject: [PATCH 04/12] docs(spec)!: remove app version from consensus params and drop release labels Specify complete removal of ConsensusParams.Version.AppVersion: reserve VersionParams field 1 and HashedParamsV2 tag 9, make ResponsePrepareProposal.app_version the only source of Header.Version.App, remove State.Version.Consensus.App, source NodeInfo app version from Info and relax state-sync verifyApp to Info.app_version >= header app version. Rename the spec to consensus-params-commitment.md and remove release labels from the chapter, links and proto comments; HashedParamsV2 names the snapshot schema only. Co-Authored-By: Claude Opus 5.5 --- book/SUMMARY.md | 2 +- proto/tendermint/abci/types.proto | 7 +- proto/tendermint/types/params.proto | 18 +++-- proto/tendermint/types/types.proto | 2 +- spec/README.md | 2 +- ...s-v2.md => consensus-params-commitment.md} | 72 +++++++++++++++++-- spec/consensus/consensus.md | 4 +- 7 files changed, 86 insertions(+), 21 deletions(-) rename spec/consensus/{consensus-params-v2.md => consensus-params-commitment.md} (79%) diff --git a/book/SUMMARY.md b/book/SUMMARY.md index 615f62047a..ff50f48332 100644 --- a/book/SUMMARY.md +++ b/book/SUMMARY.md @@ -80,7 +80,7 @@ - [Commit handling](spec/consensus/consensus-commit.md) - [Recovery and synchronisation](spec/consensus/consensus-recovery.md) - [Known issues and discrepancies](spec/consensus/consensus-known-issues.md) - - [Full consensus parameter commitment (v2.0 draft)](spec/consensus/consensus-params-v2.md) + - [Full consensus parameter commitment (draft)](spec/consensus/consensus-params-commitment.md) # ABCI++ diff --git a/proto/tendermint/abci/types.proto b/proto/tendermint/abci/types.proto index 385b9fb1ea..cc5799d646 100644 --- a/proto/tendermint/abci/types.proto +++ b/proto/tendermint/abci/types.proto @@ -290,8 +290,8 @@ message RequestPrepareProposal { bytes proposer_pro_tx_hash = 10; // Proposer's latest available app protocol version. uint64 proposed_app_version = 11; - // App and block version used to generate the block. - // App version included in the block can be modified by setting ResponsePrepareProposal.app_version. + // Block version used to generate the block. App is not set by Tenderdash; + // the application sets the block's app version in ResponsePrepareProposal.app_version. tendermint.version.Consensus version = 12; // quorum_hash contains hash of validator quorum that will sign the block bytes quorum_hash = 13; @@ -703,7 +703,8 @@ message ResponsePrepareProposal { tendermint.types.CoreChainLock core_chain_lock_update = 5; // Changes to validator set that will be applied at next height. ValidatorSetUpdate validator_set_update = 6 [(gogoproto.nullable) = true]; - // Application version that was used to create the current proposal. + // Application protocol version used to create this proposal; MUST be non-zero. + // It becomes Header.Version.App. Validators' applications verify it in ProcessProposal. uint64 app_version = 7; } diff --git a/proto/tendermint/types/params.proto b/proto/tendermint/types/params.proto index 9d91d48e57..8a02206803 100644 --- a/proto/tendermint/types/params.proto +++ b/proto/tendermint/types/params.proto @@ -21,9 +21,9 @@ message ConsensusParams { TimeoutParams timeout = 6; ABCIParams abci = 7; - // Draft v2.0 selector, independent of the consensus protocol version. + // Draft commitment selector, independent of the consensus protocol version. // Omission retains the current value in a partial update; FULL cannot downgrade. - // See spec/consensus/consensus-params-v2.md; runtime support is deferred. + // See spec/consensus/consensus-params-commitment.md; runtime support is deferred. optional CommitmentVersion commitment_version = 8; enum CommitmentVersion { @@ -91,9 +91,12 @@ message ValidatorParams { optional uint64 voting_power_threshold = 2; //[(gogoproto.nullable) = true] } -// VersionParams contains the ABCI application version. +// VersionParams contains the consensus protocol version. +// The application protocol version is not a consensus parameter: the proposer's +// ResponsePrepareProposal.app_version sets Header.Version.App for each block. message VersionParams { - uint64 app_version = 1; + reserved 1; + reserved "app_version"; // Version of consensus protocol, used to upgrade consensus without hard forks ConsensusVersion consensus_version = 2; @@ -115,7 +118,7 @@ message HashedParams { // HashedParamsV2 is the draft complete effective-parameter snapshot for FULL. // Freeze this mapping and its encoding before activation; do not hash ABCI patches. -// See spec/consensus/consensus-params-v2.md for canonical bytes and domain separation. +// See spec/consensus/consensus-params-commitment.md for canonical bytes and domain separation. message HashedParamsV2 { option (gogoproto.stable_marshaler) = true; @@ -127,7 +130,6 @@ message HashedParamsV2 { int64 evidence_max_bytes = 6; repeated string validator_pub_key_types = 7; optional uint64 validator_voting_power_threshold = 8; - uint64 version_app_version = 9; int32 version_consensus_version = 10; int64 synchrony_message_delay_ns = 11; int64 synchrony_precision_ns = 12; @@ -136,6 +138,10 @@ message HashedParamsV2 { int64 timeout_vote_ns = 15; int64 timeout_vote_delta_ns = 16; bool abci_recheck_tx = 17; + + // Tag 9 is never assigned: the application version is not a consensus parameter. + reserved 9; + reserved "version_app_version"; } // SynchronyParams configure the bounds under which a proposed block's timestamp is considered valid. diff --git a/proto/tendermint/types/types.proto b/proto/tendermint/types/types.proto index 02de7234c4..bc2a868629 100644 --- a/proto/tendermint/types/types.proto +++ b/proto/tendermint/types/types.proto @@ -105,7 +105,7 @@ message Header { bytes validators_hash = 8; // validators for the current block bytes next_validators_hash = 9; // validators for the next block // Current and next parameter commitments enter Header.Hash and the signed BlockID. - // Draft full-commitment rules: spec/consensus/consensus-params-v2.md. + // Draft full-commitment rules: spec/consensus/consensus-params-commitment.md. bytes consensus_hash = 10; // consensus params for current block bytes next_consensus_hash = 11; // consensus params for next block bytes app_hash = 12; // state after txs from the previous block diff --git a/spec/README.md b/spec/README.md index c75be56718..9d4d5b14fc 100644 --- a/spec/README.md +++ b/spec/README.md @@ -20,7 +20,7 @@ It shall be used to describe protocol semantics, namely the BFT consensus engine - [Core Data Structures](./core/data_structures.md) - [State](./core/state.md) - [Consensus Protocol](./consensus/consensus.md) (source-derived; see the [consensus index](./consensus/readme.md)) -- [Full Consensus Parameter Commitment (draft v2.0)](./consensus/consensus-params-v2.md) +- [Full Consensus Parameter Commitment (draft)](./consensus/consensus-params-commitment.md) - [Proposer Selection](./consensus/proposer-selection.md) - [Time](./consensus/consensus-alternative-flows.md#proposal-timestamps-and-time-rules) (historical design: [Proposer-Based Timestamps](./consensus/proposer-based-timestamp/README.md)) - [Light Client](./consensus/light-client/README.md) diff --git a/spec/consensus/consensus-params-v2.md b/spec/consensus/consensus-params-commitment.md similarity index 79% rename from spec/consensus/consensus-params-v2.md rename to spec/consensus/consensus-params-commitment.md index cb57516fb2..03235b2ff8 100644 --- a/spec/consensus/consensus-params-v2.md +++ b/spec/consensus/consensus-params-commitment.md @@ -1,6 +1,6 @@ # Full Consensus Parameter Commitment -**DRAFT — v2.0 target.** This is a normative design and source schema proposal, +**DRAFT.** This is a normative design and source schema proposal, not implemented consensus behavior. Generated bindings, runtime support and activation are deliberately deferred. The current Go implementation is unchanged. MUST, MUST NOT and SHOULD describe the target implementation. @@ -23,8 +23,9 @@ MUST, MUST NOT and SHOULD describe the target implementation. At this proposal's base, `types/params.go:HashConsensusParams` hashes only `Block.MaxBytes`, `Block.MaxGas` and `Version.ConsensusVersion` through the existing `HashedParams` message. Evidence limits, validator key types and voting threshold, -application version, synchrony bounds, timeouts and ABCI rechecking are outside -that digest. Actual evidence proofs already contribute to `EvidenceHash`; this +synchrony bounds, timeouts and ABCI rechecking are outside that digest. The +application version leaves consensus parameters entirely; see +[application version](#application-version-is-not-a-consensus-parameter). Actual evidence proofs already contribute to `EvidenceHash`; this proposal adds their configurable limits, not a second commitment to the proofs. `Header.Hash` already includes `ConsensusHash` and `NextConsensusHash`. Its result @@ -63,8 +64,9 @@ domain/protobuf/JSON, state-store and state-sync conversions; state equality MUS compare that value as well as threshold presence and value. This selector is independent of `VersionParams.ConsensusVersion`, the block wire -protocol version, and release numbering. The v2.0 release label does not allocate -`CONSENSUS_VERSION_2` or any new block protocol constant. +protocol version, and release numbering. FULL does not allocate +`CONSENSUS_VERSION_2` or any new block protocol constant. The `V2` in +`HashedParamsV2` and the hash domain names the snapshot schema, not a release. ## Complete snapshot and frozen mapping @@ -78,6 +80,10 @@ The source of truth is [`proto/tendermint/types/params.proto`](../../proto/tendermint/types/params.proto). `HashedParamsV2` is a flat message; the following mapping is exhaustive for the seven parameter groups in this base. Durations are signed 64-bit nanosecond counts. +Tag 9 and the name `version_app_version` are reserved and never assigned: +`Version.AppVersion` is removed rather than committed (see +[application version](#application-version-is-not-a-consensus-parameter)), so +the snapshot covers every remaining effective parameter. | Tag | Snapshot field | Protobuf type | Effective source | | --- | --- | --- | --- | @@ -89,7 +95,6 @@ seven parameter groups in this base. Durations are signed 64-bit nanosecond coun | 6 | `evidence_max_bytes` | `int64` | `Evidence.MaxBytes` | | 7 | `validator_pub_key_types` | repeated `string` | `Validator.PubKeyTypes`, preserving order | | 8 | `validator_voting_power_threshold` | optional `uint64` | `Validator.VotingPowerThreshold`, preserving absence versus explicit zero | -| 9 | `version_app_version` | `uint64` | `Version.AppVersion` | | 10 | `version_consensus_version` | `int32` | `Version.ConsensusVersion` | | 11 | `synchrony_message_delay_ns` | `int64` | `Synchrony.MessageDelay` | | 12 | `synchrony_precision_ns` | `int64` | `Synchrony.Precision` | @@ -211,6 +216,58 @@ hash variant applicable to its original protocol and height. Old clients that ignore the selector cannot safely follow activation: interoperability is an upgrade requirement, not a fallback to legacy verification. +## Application version is not a consensus parameter + +`ConsensusParams.Version.AppVersion` (`VersionParams.app_version`, field 1) is +removed. Field 1 and its name are reserved in `VersionParams`. The legacy +`HashedParams` never included it, so no historical or LEGACY hash changes, and the +removal needs no activation height. Citations below describe this base. + +1. **Block header.** `ResponsePrepareProposal.app_version` MUST be non-zero and is + the only source of `Header.Version.App`. `ResponsePrepareProposal.Validate` + already rejects zero ([`abci/types/types.go:275`](../../abci/types/types.go), + called at [`internal/state/execution.go:301`](../../internal/state/execution.go)); + the proposer cannot produce a proposal without it, and the `ver > 0` guard at + `execution.go:324` becomes an unconditional assignment. The value enters + `StateID.AppVersion` ([`types/block.go:553`](../../types/block.go)) and is signed. + Tenderdash does not check `Version.App` on non-proposers + ([`internal/state/validation.go:33`](../../internal/state/validation.go)); the + application MUST verify it in ProcessProposal. +2. **Node state.** `State.Version.Consensus.App` is removed with its writers: + parameters at commit + ([`internal/state/current_round_state.go:100`](../../internal/state/current_round_state.go)), + `ResponseInfo` at height 0 + ([`internal/consensus/replay.go:273`](../../internal/consensus/replay.go)) and + previous parameters on rollback + ([`internal/state/rollback.go:78`](../../internal/state/rollback.go)). + `State.MakeBlock` does not seed the header's app version from state + ([`internal/state/state.go:291`](../../internal/state/state.go)), so + `RequestPrepareProposal.version` carries only the block version; Tenderdash + leaves `app` unset. The shared `tendermint.version.Consensus` message keeps + `app` because `Header.Version` uses it. +3. **Node info.** `NodeInfo.ProtocolVersion.App` is taken from + `ResponseInfo.app_version`, which the handshake already returns + ([`internal/consensus/replay.go:287`](../../internal/consensus/replay.go), + [`node/node.go:514`](../../node/node.go)), instead of from state + ([`node/node.go:533`](../../node/node.go), + [`node/setup.go:447`](../../node/setup.go) for seeds, which have no application + and report 0). Peer compatibility checks only the block version + ([`types/node_info.go:148`](../../types/node_info.go)). +4. **State sync.** `verifyApp` + ([`internal/statesync/syncer.go:697`](../../internal/statesync/syncer.go)) MUST + require `ResponseInfo.app_version >= Header.Version.App` of the trusted snapshot + header instead of equality; the header value is today reached through the state + provider's `State.Version` + ([`internal/statesync/stateprovider.go:176`](../../internal/statesync/stateprovider.go)). + Applications may report their latest supported protocol version in Info, as + Dash Platform does. +5. **Compatibility.** Protobuf decoding ignores field 1 sent by older applications + in `InitChain`, `PrepareProposal` or `FinalizeBlock` parameter updates. Genesis + JSON containing `consensus_params.version.app_version` still loads, because + [`types/genesis.go`](../../types/genesis.go) decodes with lenient + `json.Unmarshal`. Generated ABCI clients drop the field, which requires a + coordinated application release. + ## Integration and implementation sequence 1. Resolve the integration blocker before freezing this snapshot. Open @@ -220,7 +277,7 @@ upgrade requirement, not a fallback to legacy verification. randomness. Reconcile those protocol assignments separately. Any heartbeat parameters merged before activation MUST be added to the full mapping/schema and vectors before freezing it. Preserve any merged legacy hash variant for - replay. The 17-field draft above MUST NOT activate while that coverage is stale. + replay. The 16-field draft above MUST NOT activate while that coverage is stale. 2. Generate bindings and implement selector-preserving conversions, defaults, equality and update validation in `types/params.go` and ABCI/state messages. `Equals` currently omits voting-threshold presence/value; include both that @@ -250,6 +307,7 @@ upgrade requirement, not a fallback to legacy verification. | Transition | Complete H-1 proposal accepted, incomplete transition rejected; current/next hashes at H-2/H-1/H agree across proposer, validators, stored state and RPC. Old positive live threshold to FULL with no override clears the derived threshold even with unchanged members. Complete FULL genesis works. | | Encoding | Cross-language bytes and hashes for valid complete snapshots, zero-value omission, threshold presence, `max_gas = -1`, list order, UTF-8 and duration boundaries; reject duplicate/unknown fields and nonminimal encodings. | | Authentication | Substitute each previously unhashed field in RPC/P2P responses; correlate response height and signed header; require per-height thresholds when validator sets cross an update. | +| Application version | Proposal with zero `app_version` rejected; header app version always equals the proposer response; legacy hashes unchanged; field 1 from an old application and in genesis JSON ignored; state sync accepts Info above the header version and rejects below. | | Recovery | Replay and restart before/at/after H; historical signature/block-ID vectors unchanged; persisted selector and optional threshold survive round trips. | | Quorum and policy | Retain Core-backed membership/key binding and all legacy trust defenses; authenticate FULL mutable thresholds without genesis pinning; do not claim raised-threshold signer-count attestation. | diff --git a/spec/consensus/consensus.md b/spec/consensus/consensus.md index d7808c004d..5288e40d29 100644 --- a/spec/consensus/consensus.md +++ b/spec/consensus/consensus.md @@ -4,8 +4,8 @@ order: 2 # Tenderdash Consensus Protocol -For the proposed v2.0 parameter authentication change, see the -[Full Consensus Parameter Commitment draft](consensus-params-v2.md). +For the proposed parameter authentication change, see the +[Full Consensus Parameter Commitment draft](consensus-params-commitment.md). It defines a future schema and activation plan; current runtime behavior is unchanged. This document and its companions specify the Tenderdash consensus protocol From 1428c0f6d277c8ced960b6e2bdc4a4cf451de640 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Fri, 6 Nov 2026 15:29:44 +0000 Subject: [PATCH 05/12] docs(spec)!: select full parameter commitment by consensus version Drop the separate commitment_version selector. CONSENSUS_VERSION_2 keeps version 1 proposer selection and hashes the complete HashedParamsV2 snapshot; lower versions keep the legacy hash. Specify the missing range and no-downgrade checks and activation through consensus_param_updates. Renumber HashedParamsV2 contiguously with consensus_version at tag 1. Keep VersionParams.app_version as deprecated until the implementation reserves it, and regenerate Go bindings and the ABCI API reference. Co-Authored-By: Claude Opus 5.5 --- abci/types/types.pb.go | 3 +- proto/tendermint/abci/types.proto | 4 +- proto/tendermint/types/canonical.pb.go | 3 +- proto/tendermint/types/params.pb.go | 1095 +++++++++++++++-- proto/tendermint/types/params.proto | 46 +- proto/tendermint/types/types.pb.go | 10 +- spec/abci++/api.md | 2 +- spec/consensus/consensus-params-commitment.md | 218 ++-- 8 files changed, 1131 insertions(+), 250 deletions(-) diff --git a/abci/types/types.pb.go b/abci/types/types.pb.go index b13cc1e139..1741589a5a 100644 --- a/abci/types/types.pb.go +++ b/abci/types/types.pb.go @@ -3008,7 +3008,8 @@ type ResponsePrepareProposal struct { CoreChainLockUpdate *types1.CoreChainLock `protobuf:"bytes,5,opt,name=core_chain_lock_update,json=coreChainLockUpdate,proto3" json:"core_chain_lock_update,omitempty"` // Changes to validator set that will be applied at next height. ValidatorSetUpdate *ValidatorSetUpdate `protobuf:"bytes,6,opt,name=validator_set_update,json=validatorSetUpdate,proto3" json:"validator_set_update,omitempty"` - // Application version that was used to create the current proposal. + // Application protocol version used to create this proposal; MUST be non-zero. + // It becomes Header.Version.App. Validators' applications verify it in ProcessProposal. AppVersion uint64 `protobuf:"varint,7,opt,name=app_version,json=appVersion,proto3" json:"app_version,omitempty"` } diff --git a/proto/tendermint/abci/types.proto b/proto/tendermint/abci/types.proto index cc5799d646..0c589bc2b1 100644 --- a/proto/tendermint/abci/types.proto +++ b/proto/tendermint/abci/types.proto @@ -290,8 +290,8 @@ message RequestPrepareProposal { bytes proposer_pro_tx_hash = 10; // Proposer's latest available app protocol version. uint64 proposed_app_version = 11; - // Block version used to generate the block. App is not set by Tenderdash; - // the application sets the block's app version in ResponsePrepareProposal.app_version. + // App and block version used to generate the block. + // App version included in the block can be modified by setting ResponsePrepareProposal.app_version. tendermint.version.Consensus version = 12; // quorum_hash contains hash of validator quorum that will sign the block bytes quorum_hash = 13; diff --git a/proto/tendermint/types/canonical.pb.go b/proto/tendermint/types/canonical.pb.go index 83b3784d1c..f673209e61 100644 --- a/proto/tendermint/types/canonical.pb.go +++ b/proto/tendermint/types/canonical.pb.go @@ -218,7 +218,8 @@ type CanonicalVote struct { Type SignedMsgType `protobuf:"varint,1,opt,name=type,proto3,enum=tendermint.types.SignedMsgType" json:"type,omitempty"` Height int64 `protobuf:"fixed64,2,opt,name=height,proto3" json:"height,omitempty"` Round int64 `protobuf:"fixed64,3,opt,name=round,proto3" json:"round,omitempty"` - // block_id is a checksum (sha256) of CanonicalBlockID for the block being voted on + // block_id is a checksum (sha256) of CanonicalBlockID for the block being voted on. + // Its header hash binds current and next consensus parameter commitments. BlockID []byte `protobuf:"bytes,4,opt,name=block_id,json=blockId,proto3" json:"block_id,omitempty"` // state_id is a checksum (sha256) of StateID message for the block being voted on StateID []byte `protobuf:"bytes,5,opt,name=state_id,json=stateId,proto3" json:"state_id,omitempty"` diff --git a/proto/tendermint/types/params.pb.go b/proto/tendermint/types/params.pb.go index 30e77c5387..4b9a16e229 100644 --- a/proto/tendermint/types/params.pb.go +++ b/proto/tendermint/types/params.pb.go @@ -34,16 +34,21 @@ const ( VersionParams_CONSENSUS_VERSION_0 VersionParams_ConsensusVersion = 0 // CONSENSUS_VERSION_1 changes proposer selection algorithm to not double-propose when previous proposer is offline. VersionParams_CONSENSUS_VERSION_1 VersionParams_ConsensusVersion = 1 + // CONSENSUS_VERSION_2 keeps version 1 proposer selection and commits HashedParamsV2 (draft). + // See spec/consensus/consensus-params-commitment.md; runtime support is deferred. + VersionParams_CONSENSUS_VERSION_2 VersionParams_ConsensusVersion = 2 ) var VersionParams_ConsensusVersion_name = map[int32]string{ 0: "CONSENSUS_VERSION_0", 1: "CONSENSUS_VERSION_1", + 2: "CONSENSUS_VERSION_2", } var VersionParams_ConsensusVersion_value = map[string]int32{ "CONSENSUS_VERSION_0": 0, "CONSENSUS_VERSION_1": 1, + "CONSENSUS_VERSION_2": 2, } func (x VersionParams_ConsensusVersion) String() string { @@ -60,8 +65,7 @@ type ConsensusParams struct { Block *BlockParams `protobuf:"bytes,1,opt,name=block,proto3" json:"block,omitempty"` Evidence *EvidenceParams `protobuf:"bytes,2,opt,name=evidence,proto3" json:"evidence,omitempty"` Validator *ValidatorParams `protobuf:"bytes,3,opt,name=validator,proto3" json:"validator,omitempty"` - // DEPRECATED. This will be removed in a future release. - // Replaced by ResponsePrepareProposal.app_version + // Consensus protocol version; its app_version field is deprecated. Version *VersionParams `protobuf:"bytes,4,opt,name=version,proto3" json:"version,omitempty"` Synchrony *SynchronyParams `protobuf:"bytes,5,opt,name=synchrony,proto3" json:"synchrony,omitempty"` Timeout *TimeoutParams `protobuf:"bytes,6,opt,name=timeout,proto3" json:"timeout,omitempty"` @@ -363,8 +367,10 @@ func (*ValidatorParams) XXX_OneofWrappers() []interface{} { } } -// VersionParams contains the ABCI application version. +// VersionParams contains the consensus protocol version. type VersionParams struct { + // DEPRECATED: ResponsePrepareProposal.app_version sets Header.Version.App. + // Removal: spec/consensus/consensus-params-commitment.md#application-version-is-not-a-consensus-parameter AppVersion uint64 `protobuf:"varint,1,opt,name=app_version,json=appVersion,proto3" json:"app_version,omitempty"` // Version of consensus protocol, used to upgrade consensus without hard forks ConsensusVersion VersionParams_ConsensusVersion `protobuf:"varint,2,opt,name=consensus_version,json=consensusVersion,proto3,enum=tendermint.types.VersionParams_ConsensusVersion" json:"consensus_version,omitempty"` @@ -417,9 +423,8 @@ func (m *VersionParams) GetConsensusVersion() VersionParams_ConsensusVersion { return VersionParams_CONSENSUS_VERSION_0 } -// HashedParams is a subset of ConsensusParams. -// -// It is hashed into the Header.ConsensusHash. +// HashedParams is the legacy subset committed by Header.ConsensusHash. +// Preserve its schema and encoding for historical block verification. type HashedParams struct { BlockMaxBytes int64 `protobuf:"varint,1,opt,name=block_max_bytes,json=blockMaxBytes,proto3" json:"block_max_bytes,omitempty"` BlockMaxGas int64 `protobuf:"varint,2,opt,name=block_max_gas,json=blockMaxGas,proto3" json:"block_max_gas,omitempty"` @@ -480,6 +485,191 @@ func (m *HashedParams) GetConsensusVersion() int32 { return 0 } +// HashedParamsV2 is the draft complete effective-parameter snapshot for consensus version >= 2. +// Freeze this mapping and its encoding before activation; do not hash ABCI patches. +// See spec/consensus/consensus-params-commitment.md for canonical bytes and domain separation. +type HashedParamsV2 struct { + ConsensusVersion int32 `protobuf:"varint,1,opt,name=consensus_version,json=consensusVersion,proto3" json:"consensus_version,omitempty"` + BlockMaxBytes int64 `protobuf:"varint,2,opt,name=block_max_bytes,json=blockMaxBytes,proto3" json:"block_max_bytes,omitempty"` + BlockMaxGas int64 `protobuf:"varint,3,opt,name=block_max_gas,json=blockMaxGas,proto3" json:"block_max_gas,omitempty"` + EvidenceMaxAgeNumBlocks int64 `protobuf:"varint,4,opt,name=evidence_max_age_num_blocks,json=evidenceMaxAgeNumBlocks,proto3" json:"evidence_max_age_num_blocks,omitempty"` + EvidenceMaxAgeDurationNs int64 `protobuf:"varint,5,opt,name=evidence_max_age_duration_ns,json=evidenceMaxAgeDurationNs,proto3" json:"evidence_max_age_duration_ns,omitempty"` + EvidenceMaxBytes int64 `protobuf:"varint,6,opt,name=evidence_max_bytes,json=evidenceMaxBytes,proto3" json:"evidence_max_bytes,omitempty"` + ValidatorPubKeyTypes []string `protobuf:"bytes,7,rep,name=validator_pub_key_types,json=validatorPubKeyTypes,proto3" json:"validator_pub_key_types,omitempty"` + // Types that are valid to be assigned to XValidatorVotingPowerThreshold: + // *HashedParamsV2_ValidatorVotingPowerThreshold + XValidatorVotingPowerThreshold isHashedParamsV2_XValidatorVotingPowerThreshold `protobuf_oneof:"_validator_voting_power_threshold"` + SynchronyMessageDelayNs int64 `protobuf:"varint,9,opt,name=synchrony_message_delay_ns,json=synchronyMessageDelayNs,proto3" json:"synchrony_message_delay_ns,omitempty"` + SynchronyPrecisionNs int64 `protobuf:"varint,10,opt,name=synchrony_precision_ns,json=synchronyPrecisionNs,proto3" json:"synchrony_precision_ns,omitempty"` + TimeoutProposeNs int64 `protobuf:"varint,11,opt,name=timeout_propose_ns,json=timeoutProposeNs,proto3" json:"timeout_propose_ns,omitempty"` + TimeoutProposeDeltaNs int64 `protobuf:"varint,12,opt,name=timeout_propose_delta_ns,json=timeoutProposeDeltaNs,proto3" json:"timeout_propose_delta_ns,omitempty"` + TimeoutVoteNs int64 `protobuf:"varint,13,opt,name=timeout_vote_ns,json=timeoutVoteNs,proto3" json:"timeout_vote_ns,omitempty"` + TimeoutVoteDeltaNs int64 `protobuf:"varint,14,opt,name=timeout_vote_delta_ns,json=timeoutVoteDeltaNs,proto3" json:"timeout_vote_delta_ns,omitempty"` + AbciRecheckTx bool `protobuf:"varint,15,opt,name=abci_recheck_tx,json=abciRecheckTx,proto3" json:"abci_recheck_tx,omitempty"` +} + +func (m *HashedParamsV2) Reset() { *m = HashedParamsV2{} } +func (m *HashedParamsV2) String() string { return proto.CompactTextString(m) } +func (*HashedParamsV2) ProtoMessage() {} +func (*HashedParamsV2) Descriptor() ([]byte, []int) { + return fileDescriptor_e12598271a686f57, []int{6} +} +func (m *HashedParamsV2) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *HashedParamsV2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *HashedParamsV2) XXX_Merge(src proto.Message) { + xxx_messageInfo_HashedParamsV2.Merge(m, src) +} +func (m *HashedParamsV2) XXX_Size() int { + return m.Size() +} +func (m *HashedParamsV2) XXX_DiscardUnknown() { + xxx_messageInfo_HashedParamsV2.DiscardUnknown(m) +} + +var xxx_messageInfo_HashedParamsV2 proto.InternalMessageInfo + +type isHashedParamsV2_XValidatorVotingPowerThreshold interface { + isHashedParamsV2_XValidatorVotingPowerThreshold() + Equal(interface{}) bool + MarshalTo([]byte) (int, error) + Size() int +} + +type HashedParamsV2_ValidatorVotingPowerThreshold struct { + ValidatorVotingPowerThreshold uint64 `protobuf:"varint,8,opt,name=validator_voting_power_threshold,json=validatorVotingPowerThreshold,proto3,oneof" json:"validator_voting_power_threshold,omitempty"` +} + +func (*HashedParamsV2_ValidatorVotingPowerThreshold) isHashedParamsV2_XValidatorVotingPowerThreshold() { +} + +func (m *HashedParamsV2) GetXValidatorVotingPowerThreshold() isHashedParamsV2_XValidatorVotingPowerThreshold { + if m != nil { + return m.XValidatorVotingPowerThreshold + } + return nil +} + +func (m *HashedParamsV2) GetConsensusVersion() int32 { + if m != nil { + return m.ConsensusVersion + } + return 0 +} + +func (m *HashedParamsV2) GetBlockMaxBytes() int64 { + if m != nil { + return m.BlockMaxBytes + } + return 0 +} + +func (m *HashedParamsV2) GetBlockMaxGas() int64 { + if m != nil { + return m.BlockMaxGas + } + return 0 +} + +func (m *HashedParamsV2) GetEvidenceMaxAgeNumBlocks() int64 { + if m != nil { + return m.EvidenceMaxAgeNumBlocks + } + return 0 +} + +func (m *HashedParamsV2) GetEvidenceMaxAgeDurationNs() int64 { + if m != nil { + return m.EvidenceMaxAgeDurationNs + } + return 0 +} + +func (m *HashedParamsV2) GetEvidenceMaxBytes() int64 { + if m != nil { + return m.EvidenceMaxBytes + } + return 0 +} + +func (m *HashedParamsV2) GetValidatorPubKeyTypes() []string { + if m != nil { + return m.ValidatorPubKeyTypes + } + return nil +} + +func (m *HashedParamsV2) GetValidatorVotingPowerThreshold() uint64 { + if x, ok := m.GetXValidatorVotingPowerThreshold().(*HashedParamsV2_ValidatorVotingPowerThreshold); ok { + return x.ValidatorVotingPowerThreshold + } + return 0 +} + +func (m *HashedParamsV2) GetSynchronyMessageDelayNs() int64 { + if m != nil { + return m.SynchronyMessageDelayNs + } + return 0 +} + +func (m *HashedParamsV2) GetSynchronyPrecisionNs() int64 { + if m != nil { + return m.SynchronyPrecisionNs + } + return 0 +} + +func (m *HashedParamsV2) GetTimeoutProposeNs() int64 { + if m != nil { + return m.TimeoutProposeNs + } + return 0 +} + +func (m *HashedParamsV2) GetTimeoutProposeDeltaNs() int64 { + if m != nil { + return m.TimeoutProposeDeltaNs + } + return 0 +} + +func (m *HashedParamsV2) GetTimeoutVoteNs() int64 { + if m != nil { + return m.TimeoutVoteNs + } + return 0 +} + +func (m *HashedParamsV2) GetTimeoutVoteDeltaNs() int64 { + if m != nil { + return m.TimeoutVoteDeltaNs + } + return 0 +} + +func (m *HashedParamsV2) GetAbciRecheckTx() bool { + if m != nil { + return m.AbciRecheckTx + } + return false +} + +// XXX_OneofWrappers is for the internal use of the proto package. +func (*HashedParamsV2) XXX_OneofWrappers() []interface{} { + return []interface{}{ + (*HashedParamsV2_ValidatorVotingPowerThreshold)(nil), + } +} + // SynchronyParams configure the bounds under which a proposed block's timestamp is considered valid. // These parameters are part of the proposer-based timestamps algorithm. For more information, // see the specification of proposer-based timestamps: @@ -497,7 +687,7 @@ func (m *SynchronyParams) Reset() { *m = SynchronyParams{} } func (m *SynchronyParams) String() string { return proto.CompactTextString(m) } func (*SynchronyParams) ProtoMessage() {} func (*SynchronyParams) Descriptor() ([]byte, []int) { - return fileDescriptor_e12598271a686f57, []int{6} + return fileDescriptor_e12598271a686f57, []int{7} } func (m *SynchronyParams) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -576,7 +766,7 @@ func (m *TimeoutParams) Reset() { *m = TimeoutParams{} } func (m *TimeoutParams) String() string { return proto.CompactTextString(m) } func (*TimeoutParams) ProtoMessage() {} func (*TimeoutParams) Descriptor() ([]byte, []int) { - return fileDescriptor_e12598271a686f57, []int{7} + return fileDescriptor_e12598271a686f57, []int{8} } func (m *TimeoutParams) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -644,7 +834,7 @@ func (m *ABCIParams) Reset() { *m = ABCIParams{} } func (m *ABCIParams) String() string { return proto.CompactTextString(m) } func (*ABCIParams) ProtoMessage() {} func (*ABCIParams) Descriptor() ([]byte, []int) { - return fileDescriptor_e12598271a686f57, []int{8} + return fileDescriptor_e12598271a686f57, []int{9} } func (m *ABCIParams) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -688,6 +878,7 @@ func init() { proto.RegisterType((*ValidatorParams)(nil), "tendermint.types.ValidatorParams") proto.RegisterType((*VersionParams)(nil), "tendermint.types.VersionParams") proto.RegisterType((*HashedParams)(nil), "tendermint.types.HashedParams") + proto.RegisterType((*HashedParamsV2)(nil), "tendermint.types.HashedParamsV2") proto.RegisterType((*SynchronyParams)(nil), "tendermint.types.SynchronyParams") proto.RegisterType((*TimeoutParams)(nil), "tendermint.types.TimeoutParams") proto.RegisterType((*ABCIParams)(nil), "tendermint.types.ABCIParams") @@ -696,60 +887,76 @@ func init() { func init() { proto.RegisterFile("tendermint/types/params.proto", fileDescriptor_e12598271a686f57) } var fileDescriptor_e12598271a686f57 = []byte{ - // 844 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x95, 0xcd, 0x6e, 0xdb, 0x46, - 0x10, 0xc7, 0xb5, 0x11, 0x2d, 0x4b, 0x23, 0xcb, 0x52, 0xb7, 0x69, 0xcd, 0xa4, 0xb5, 0xec, 0xf2, - 0x50, 0x04, 0x08, 0x40, 0xb9, 0x71, 0x2f, 0x01, 0xfa, 0x81, 0xc8, 0x32, 0xf2, 0x51, 0xc4, 0x09, - 0x28, 0x37, 0x87, 0x02, 0x05, 0xb1, 0xa4, 0xb6, 0x14, 0x61, 0x91, 0x4b, 0x70, 0x49, 0x55, 0x7c, - 0x82, 0x16, 0xe8, 0xa5, 0xa7, 0xa2, 0x8f, 0xd0, 0x5e, 0x8a, 0x3e, 0x46, 0x8e, 0xb9, 0x14, 0xe8, - 0xa9, 0x2d, 0xec, 0x17, 0x29, 0x76, 0xb9, 0x2b, 0x45, 0xb2, 0x82, 0xe8, 0x24, 0xed, 0xce, 0xff, - 0xc7, 0xd9, 0x9d, 0xf9, 0x0f, 0x09, 0xfb, 0x19, 0x8d, 0x47, 0x34, 0x8d, 0xc2, 0x38, 0xeb, 0x65, - 0x45, 0x42, 0x79, 0x2f, 0x21, 0x29, 0x89, 0xb8, 0x9d, 0xa4, 0x2c, 0x63, 0xb8, 0xb3, 0x08, 0xdb, - 0x32, 0x7c, 0xfb, 0x66, 0xc0, 0x02, 0x26, 0x83, 0x3d, 0xf1, 0xaf, 0xd4, 0xdd, 0xee, 0x06, 0x8c, - 0x05, 0x13, 0xda, 0x93, 0x2b, 0x2f, 0xff, 0xae, 0x37, 0xca, 0x53, 0x92, 0x85, 0x2c, 0x2e, 0xe3, - 0xd6, 0x1f, 0x55, 0x68, 0x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18, 0x7f, 0x01, 0x20, 0x7e, 0x55, 0x5e, 0x63, 0xc3, 0x3a, 0x08, 0x44, 0x26, - 0x7d, 0x62, 0xd4, 0xb7, 0x3a, 0xb5, 0x27, 0x46, 0xbd, 0xd6, 0xd9, 0x76, 0x6a, 0x3e, 0x8b, 0xa2, - 0x30, 0x73, 0xde, 0xf3, 0x8a, 0x84, 0x70, 0xee, 0x96, 0x4b, 0x57, 0xbd, 0xde, 0xac, 0xbb, 0x00, - 0x8b, 0x17, 0x18, 0xde, 0x07, 0x48, 0xa9, 0x3f, 0xa6, 0xfe, 0x85, 0x9b, 0xcd, 0x64, 0xc5, 0xea, - 0x4e, 0x43, 0xed, 0x9c, 0xcf, 0xfa, 0xce, 0x6f, 0x97, 0x5d, 0xf4, 0xf2, 0xb2, 0x8b, 0x5e, 0x5d, - 0x76, 0xd1, 0x7f, 0x97, 0x5d, 0xf4, 0xf3, 0x55, 0xb7, 0xf2, 0xea, 0xaa, 0x5b, 0xf9, 0xfb, 0xaa, - 0x5b, 0xf9, 0xe6, 0xd3, 0x20, 0xcc, 0xc6, 0xb9, 0x67, 0xfb, 0x2c, 0xea, 0x8d, 0x08, 0x1f, 0x27, - 0xa4, 0xe8, 0x95, 0xc3, 0x23, 0x56, 0xe5, 0xf7, 0xad, 0xb7, 0xfa, 0xcd, 0xf4, 0x6a, 0x72, 0xff, - 0xf8, 0xff, 0x01, 0x00, 0xb2, 0xb1, 0x36, 0x07, 0x4e, 0x07, 0x00, 0x00, + // 1091 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x96, 0xcf, 0x6f, 0xe3, 0x44, + 0x14, 0xc7, 0xe3, 0x26, 0x4d, 0x93, 0x97, 0xa6, 0x09, 0x43, 0x77, 0xeb, 0xfd, 0xd1, 0xb4, 0x6b, + 0x24, 0x54, 0x69, 0x51, 0xd2, 0x6d, 0x17, 0xa1, 0x85, 0x65,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 0x29, 0x3d, 0x3b, 0x1f, 0x2c, 0xcd, + 0xe8, 0x09, 0xc0, 0xa4, 0xbc, 0x7a, 0x6e, 0x3e, 0xb4, 0x38, 0x54, 0x55, 0x7f, 0x99, 0x2b, 0x2c, + 0x56, 0xf3, 0x2f, 0x73, 0x85, 0x7c, 0x75, 0xc9, 0xcc, 0x5b, 0xcc, 0x71, 0xec, 0xc0, 0xbc, 0xd1, + 0x1e, 0x7b, 0x84, 0x73, 0x1c, 0x3e, 0xe2, 0xa8, 0x53, 0x8c, 0xfb, 0x00, 0x93, 0xbf, 0x07, 0x68, + 0x1d, 0x60, 0xaa, 0x4f, 0x34, 0xd9, 0x27, 0x45, 0x5f, 0xf5, 0x48, 0xd3, 0xfc, 0xf5, 0xbc, 0xa6, + 0xbd, 0x3d, 0xaf, 0x69, 0xef, 0xce, 0x6b, 0xda, 0xbf, 0xe7, 0x35, 0xed, 0xa7, 0x8b, 0x5a, 0xe6, + 0xdd, 0x45, 0x2d, 0xf3, 0xd7, 0x45, 0x2d, 0xf3, 0xcd, 0xc3, 0xae, 0x1d, 0xf4, 0x06, 0xed, 0xba, + 0xc5, 0x9c, 0x46, 0x87, 0xf0, 0x9e, 0x47, 0xc6, 0x8d, 0xf0, 0xd3, 0x24, 0x9e, 0xc2, 0x7f, 0x8f, + 0x8d, 0xd9, 0x7f, 0xa4, 0xed, 0xbc, 0x5c, 0xdf, 0xfd, 0x7f, 0x00, 0x52, 0xed, 0xaa, 0xaf, 0xac, + 0x0a, 0x00, 0x00, } func (this *ConsensusParams) Equal(that interface{}) bool { @@ -970,6 +1177,107 @@ func (this *HashedParams) Equal(that interface{}) bool { } return true } +func (this *HashedParamsV2) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*HashedParamsV2) + if !ok { + that2, ok := that.(HashedParamsV2) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.ConsensusVersion != that1.ConsensusVersion { + return false + } + if this.BlockMaxBytes != that1.BlockMaxBytes { + return false + } + if this.BlockMaxGas != that1.BlockMaxGas { + return false + } + if this.EvidenceMaxAgeNumBlocks != that1.EvidenceMaxAgeNumBlocks { + return false + } + if this.EvidenceMaxAgeDurationNs != that1.EvidenceMaxAgeDurationNs { + return false + } + if this.EvidenceMaxBytes != that1.EvidenceMaxBytes { + return false + } + if len(this.ValidatorPubKeyTypes) != len(that1.ValidatorPubKeyTypes) { + return false + } + for i := range this.ValidatorPubKeyTypes { + if this.ValidatorPubKeyTypes[i] != that1.ValidatorPubKeyTypes[i] { + return false + } + } + if that1.XValidatorVotingPowerThreshold == nil { + if this.XValidatorVotingPowerThreshold != nil { + return false + } + } else if this.XValidatorVotingPowerThreshold == nil { + return false + } else if !this.XValidatorVotingPowerThreshold.Equal(that1.XValidatorVotingPowerThreshold) { + return false + } + if this.SynchronyMessageDelayNs != that1.SynchronyMessageDelayNs { + return false + } + if this.SynchronyPrecisionNs != that1.SynchronyPrecisionNs { + return false + } + if this.TimeoutProposeNs != that1.TimeoutProposeNs { + return false + } + if this.TimeoutProposeDeltaNs != that1.TimeoutProposeDeltaNs { + return false + } + if this.TimeoutVoteNs != that1.TimeoutVoteNs { + return false + } + if this.TimeoutVoteDeltaNs != that1.TimeoutVoteDeltaNs { + return false + } + if this.AbciRecheckTx != that1.AbciRecheckTx { + return false + } + return true +} +func (this *HashedParamsV2_ValidatorVotingPowerThreshold) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*HashedParamsV2_ValidatorVotingPowerThreshold) + if !ok { + that2, ok := that.(HashedParamsV2_ValidatorVotingPowerThreshold) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.ValidatorVotingPowerThreshold != that1.ValidatorVotingPowerThreshold { + return false + } + return true +} func (this *SynchronyParams) Equal(that interface{}) bool { if that == nil { return this == nil @@ -1416,7 +1724,7 @@ func (m *HashedParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *SynchronyParams) Marshal() (dAtA []byte, err error) { +func (m *HashedParamsV2) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1426,12 +1734,12 @@ func (m *SynchronyParams) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *SynchronyParams) MarshalTo(dAtA []byte) (int, error) { +func (m *HashedParamsV2) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *SynchronyParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *HashedParamsV2) MarshalToSizedBuffer(dAtA []byte) (int, error) { if m == nil { return 0, nil } @@ -1439,71 +1747,200 @@ func (m *SynchronyParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.Precision != nil { - n9, err9 := github_com_cosmos_gogoproto_types.StdDurationMarshalTo(*m.Precision, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(*m.Precision):]) - if err9 != nil { - return 0, err9 + if m.AbciRecheckTx { + i-- + if m.AbciRecheckTx { + dAtA[i] = 1 + } else { + dAtA[i] = 0 } - i -= n9 - i = encodeVarintParams(dAtA, i, uint64(n9)) i-- - dAtA[i] = 0x12 + dAtA[i] = 0x78 } - if m.MessageDelay != nil { - n10, err10 := github_com_cosmos_gogoproto_types.StdDurationMarshalTo(*m.MessageDelay, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(*m.MessageDelay):]) - if err10 != nil { - return 0, err10 - } - i -= n10 - i = encodeVarintParams(dAtA, i, uint64(n10)) + if m.TimeoutVoteDeltaNs != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.TimeoutVoteDeltaNs)) i-- - dAtA[i] = 0xa + dAtA[i] = 0x70 } - return len(dAtA) - i, nil -} - -func (m *TimeoutParams) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err + if m.TimeoutVoteNs != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.TimeoutVoteNs)) + i-- + dAtA[i] = 0x68 } - return dAtA[:n], nil -} - -func (m *TimeoutParams) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *TimeoutParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { - if m == nil { - return 0, nil + if m.TimeoutProposeDeltaNs != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.TimeoutProposeDeltaNs)) + i-- + dAtA[i] = 0x60 } - i := len(dAtA) - _ = i - var l int - _ = l - if m.VoteDelta != nil { - n11, err11 := github_com_cosmos_gogoproto_types.StdDurationMarshalTo(*m.VoteDelta, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(*m.VoteDelta):]) - if err11 != nil { - return 0, err11 - } - i -= n11 - i = encodeVarintParams(dAtA, i, uint64(n11)) + if m.TimeoutProposeNs != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.TimeoutProposeNs)) i-- - dAtA[i] = 0x22 + dAtA[i] = 0x58 } - if m.Vote != nil { - n12, err12 := github_com_cosmos_gogoproto_types.StdDurationMarshalTo(*m.Vote, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(*m.Vote):]) - if err12 != nil { - return 0, err12 - } - i -= n12 - i = encodeVarintParams(dAtA, i, uint64(n12)) + if m.SynchronyPrecisionNs != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.SynchronyPrecisionNs)) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x50 + } + if m.SynchronyMessageDelayNs != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.SynchronyMessageDelayNs)) + i-- + dAtA[i] = 0x48 + } + if m.XValidatorVotingPowerThreshold != nil { + { + size := m.XValidatorVotingPowerThreshold.Size() + i -= size + if _, err := m.XValidatorVotingPowerThreshold.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + } + } + if len(m.ValidatorPubKeyTypes) > 0 { + for iNdEx := len(m.ValidatorPubKeyTypes) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.ValidatorPubKeyTypes[iNdEx]) + copy(dAtA[i:], m.ValidatorPubKeyTypes[iNdEx]) + i = encodeVarintParams(dAtA, i, uint64(len(m.ValidatorPubKeyTypes[iNdEx]))) + i-- + dAtA[i] = 0x3a + } + } + if m.EvidenceMaxBytes != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.EvidenceMaxBytes)) + i-- + dAtA[i] = 0x30 + } + if m.EvidenceMaxAgeDurationNs != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.EvidenceMaxAgeDurationNs)) + i-- + dAtA[i] = 0x28 + } + if m.EvidenceMaxAgeNumBlocks != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.EvidenceMaxAgeNumBlocks)) + i-- + dAtA[i] = 0x20 + } + if m.BlockMaxGas != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.BlockMaxGas)) + i-- + dAtA[i] = 0x18 + } + if m.BlockMaxBytes != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.BlockMaxBytes)) + i-- + dAtA[i] = 0x10 + } + if m.ConsensusVersion != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.ConsensusVersion)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *HashedParamsV2_ValidatorVotingPowerThreshold) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *HashedParamsV2_ValidatorVotingPowerThreshold) MarshalToSizedBuffer(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + i = encodeVarintParams(dAtA, i, uint64(m.ValidatorVotingPowerThreshold)) + i-- + dAtA[i] = 0x40 + return len(dAtA) - i, nil +} +func (m *SynchronyParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SynchronyParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SynchronyParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.Precision != nil { + n9, err9 := github_com_cosmos_gogoproto_types.StdDurationMarshalTo(*m.Precision, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(*m.Precision):]) + if err9 != nil { + return 0, err9 + } + i -= n9 + i = encodeVarintParams(dAtA, i, uint64(n9)) + i-- + dAtA[i] = 0x12 + } + if m.MessageDelay != nil { + n10, err10 := github_com_cosmos_gogoproto_types.StdDurationMarshalTo(*m.MessageDelay, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(*m.MessageDelay):]) + if err10 != nil { + return 0, err10 + } + i -= n10 + i = encodeVarintParams(dAtA, i, uint64(n10)) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *TimeoutParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TimeoutParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TimeoutParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.VoteDelta != nil { + n11, err11 := github_com_cosmos_gogoproto_types.StdDurationMarshalTo(*m.VoteDelta, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(*m.VoteDelta):]) + if err11 != nil { + return 0, err11 + } + i -= n11 + i = encodeVarintParams(dAtA, i, uint64(n11)) + i-- + dAtA[i] = 0x22 + } + if m.Vote != nil { + n12, err12 := github_com_cosmos_gogoproto_types.StdDurationMarshalTo(*m.Vote, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(*m.Vote):]) + if err12 != nil { + return 0, err12 + } + i -= n12 + i = encodeVarintParams(dAtA, i, uint64(n12)) + i-- + dAtA[i] = 0x1a } if m.ProposeDelta != nil { n13, err13 := github_com_cosmos_gogoproto_types.StdDurationMarshalTo(*m.ProposeDelta, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(*m.ProposeDelta):]) @@ -1704,6 +2141,72 @@ func (m *HashedParams) Size() (n int) { return n } +func (m *HashedParamsV2) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ConsensusVersion != 0 { + n += 1 + sovParams(uint64(m.ConsensusVersion)) + } + if m.BlockMaxBytes != 0 { + n += 1 + sovParams(uint64(m.BlockMaxBytes)) + } + if m.BlockMaxGas != 0 { + n += 1 + sovParams(uint64(m.BlockMaxGas)) + } + if m.EvidenceMaxAgeNumBlocks != 0 { + n += 1 + sovParams(uint64(m.EvidenceMaxAgeNumBlocks)) + } + if m.EvidenceMaxAgeDurationNs != 0 { + n += 1 + sovParams(uint64(m.EvidenceMaxAgeDurationNs)) + } + if m.EvidenceMaxBytes != 0 { + n += 1 + sovParams(uint64(m.EvidenceMaxBytes)) + } + if len(m.ValidatorPubKeyTypes) > 0 { + for _, s := range m.ValidatorPubKeyTypes { + l = len(s) + n += 1 + l + sovParams(uint64(l)) + } + } + if m.XValidatorVotingPowerThreshold != nil { + n += m.XValidatorVotingPowerThreshold.Size() + } + if m.SynchronyMessageDelayNs != 0 { + n += 1 + sovParams(uint64(m.SynchronyMessageDelayNs)) + } + if m.SynchronyPrecisionNs != 0 { + n += 1 + sovParams(uint64(m.SynchronyPrecisionNs)) + } + if m.TimeoutProposeNs != 0 { + n += 1 + sovParams(uint64(m.TimeoutProposeNs)) + } + if m.TimeoutProposeDeltaNs != 0 { + n += 1 + sovParams(uint64(m.TimeoutProposeDeltaNs)) + } + if m.TimeoutVoteNs != 0 { + n += 1 + sovParams(uint64(m.TimeoutVoteNs)) + } + if m.TimeoutVoteDeltaNs != 0 { + n += 1 + sovParams(uint64(m.TimeoutVoteDeltaNs)) + } + if m.AbciRecheckTx { + n += 2 + } + return n +} + +func (m *HashedParamsV2_ValidatorVotingPowerThreshold) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + n += 1 + sovParams(uint64(m.ValidatorVotingPowerThreshold)) + return n +} func (m *SynchronyParams) Size() (n int) { if m == nil { return 0 @@ -2572,6 +3075,356 @@ func (m *HashedParams) Unmarshal(dAtA []byte) error { } return nil } +func (m *HashedParamsV2) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: HashedParamsV2: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: HashedParamsV2: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ConsensusVersion", wireType) + } + m.ConsensusVersion = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ConsensusVersion |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockMaxBytes", wireType) + } + m.BlockMaxBytes = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BlockMaxBytes |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockMaxGas", wireType) + } + m.BlockMaxGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BlockMaxGas |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EvidenceMaxAgeNumBlocks", wireType) + } + m.EvidenceMaxAgeNumBlocks = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.EvidenceMaxAgeNumBlocks |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EvidenceMaxAgeDurationNs", wireType) + } + m.EvidenceMaxAgeDurationNs = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.EvidenceMaxAgeDurationNs |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EvidenceMaxBytes", wireType) + } + m.EvidenceMaxBytes = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.EvidenceMaxBytes |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorPubKeyTypes", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorPubKeyTypes = append(m.ValidatorPubKeyTypes, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorVotingPowerThreshold", wireType) + } + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.XValidatorVotingPowerThreshold = &HashedParamsV2_ValidatorVotingPowerThreshold{v} + case 9: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SynchronyMessageDelayNs", wireType) + } + m.SynchronyMessageDelayNs = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SynchronyMessageDelayNs |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 10: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SynchronyPrecisionNs", wireType) + } + m.SynchronyPrecisionNs = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SynchronyPrecisionNs |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 11: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TimeoutProposeNs", wireType) + } + m.TimeoutProposeNs = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TimeoutProposeNs |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 12: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TimeoutProposeDeltaNs", wireType) + } + m.TimeoutProposeDeltaNs = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TimeoutProposeDeltaNs |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 13: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TimeoutVoteNs", wireType) + } + m.TimeoutVoteNs = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TimeoutVoteNs |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 14: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TimeoutVoteDeltaNs", wireType) + } + m.TimeoutVoteDeltaNs = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TimeoutVoteDeltaNs |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 15: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AbciRecheckTx", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.AbciRecheckTx = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *SynchronyParams) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/proto/tendermint/types/params.proto b/proto/tendermint/types/params.proto index 8a02206803..a6a83c39fa 100644 --- a/proto/tendermint/types/params.proto +++ b/proto/tendermint/types/params.proto @@ -14,22 +14,11 @@ message ConsensusParams { BlockParams block = 1; EvidenceParams evidence = 2; ValidatorParams validator = 3; - // DEPRECATED. This will be removed in a future release. - // Replaced by ResponsePrepareProposal.app_version + // Consensus protocol version; its app_version field is deprecated. VersionParams version = 4; SynchronyParams synchrony = 5; TimeoutParams timeout = 6; ABCIParams abci = 7; - - // Draft commitment selector, independent of the consensus protocol version. - // Omission retains the current value in a partial update; FULL cannot downgrade. - // See spec/consensus/consensus-params-commitment.md; runtime support is deferred. - optional CommitmentVersion commitment_version = 8; - - enum CommitmentVersion { - COMMITMENT_VERSION_LEGACY = 0; - COMMITMENT_VERSION_FULL = 1; - } } // BlockParams contains limits on the block size. @@ -92,11 +81,10 @@ message ValidatorParams { } // VersionParams contains the consensus protocol version. -// The application protocol version is not a consensus parameter: the proposer's -// ResponsePrepareProposal.app_version sets Header.Version.App for each block. message VersionParams { - reserved 1; - reserved "app_version"; + // DEPRECATED: ResponsePrepareProposal.app_version sets Header.Version.App. + // Removal: spec/consensus/consensus-params-commitment.md#application-version-is-not-a-consensus-parameter + uint64 app_version = 1; // Version of consensus protocol, used to upgrade consensus without hard forks ConsensusVersion consensus_version = 2; @@ -105,6 +93,9 @@ message VersionParams { CONSENSUS_VERSION_0 = 0; // CONSENSUS_VERSION_1 changes proposer selection algorithm to not double-propose when previous proposer is offline. CONSENSUS_VERSION_1 = 1; + // CONSENSUS_VERSION_2 keeps version 1 proposer selection and commits HashedParamsV2 (draft). + // See spec/consensus/consensus-params-commitment.md; runtime support is deferred. + CONSENSUS_VERSION_2 = 2; } } @@ -116,13 +107,13 @@ message HashedParams { int32 consensus_version = 3; } -// HashedParamsV2 is the draft complete effective-parameter snapshot for FULL. +// HashedParamsV2 is the draft complete effective-parameter snapshot for consensus version >= 2. // Freeze this mapping and its encoding before activation; do not hash ABCI patches. // See spec/consensus/consensus-params-commitment.md for canonical bytes and domain separation. message HashedParamsV2 { option (gogoproto.stable_marshaler) = true; - uint32 commitment_version = 1; // Must be 1 (FULL). + int32 consensus_version = 1; // Always >= CONSENSUS_VERSION_2. int64 block_max_bytes = 2; int64 block_max_gas = 3; int64 evidence_max_age_num_blocks = 4; @@ -130,18 +121,13 @@ message HashedParamsV2 { int64 evidence_max_bytes = 6; repeated string validator_pub_key_types = 7; optional uint64 validator_voting_power_threshold = 8; - int32 version_consensus_version = 10; - int64 synchrony_message_delay_ns = 11; - int64 synchrony_precision_ns = 12; - int64 timeout_propose_ns = 13; - int64 timeout_propose_delta_ns = 14; - int64 timeout_vote_ns = 15; - int64 timeout_vote_delta_ns = 16; - bool abci_recheck_tx = 17; - - // Tag 9 is never assigned: the application version is not a consensus parameter. - reserved 9; - reserved "version_app_version"; + int64 synchrony_message_delay_ns = 9; + int64 synchrony_precision_ns = 10; + int64 timeout_propose_ns = 11; + int64 timeout_propose_delta_ns = 12; + int64 timeout_vote_ns = 13; + int64 timeout_vote_delta_ns = 14; + bool abci_recheck_tx = 15; } // SynchronyParams configure the bounds under which a proposed block's timestamp is considered valid. diff --git a/proto/tendermint/types/types.pb.go b/proto/tendermint/types/types.pb.go index 6c695234d0..152425fc05 100644 --- a/proto/tendermint/types/types.pb.go +++ b/proto/tendermint/types/types.pb.go @@ -366,10 +366,12 @@ type Header struct { // hashes from the app output from the prev block ValidatorsHash []byte `protobuf:"bytes,8,opt,name=validators_hash,json=validatorsHash,proto3" json:"validators_hash,omitempty"` NextValidatorsHash []byte `protobuf:"bytes,9,opt,name=next_validators_hash,json=nextValidatorsHash,proto3" json:"next_validators_hash,omitempty"` - ConsensusHash []byte `protobuf:"bytes,10,opt,name=consensus_hash,json=consensusHash,proto3" json:"consensus_hash,omitempty"` - NextConsensusHash []byte `protobuf:"bytes,11,opt,name=next_consensus_hash,json=nextConsensusHash,proto3" json:"next_consensus_hash,omitempty"` - AppHash []byte `protobuf:"bytes,12,opt,name=app_hash,json=appHash,proto3" json:"app_hash,omitempty"` - ResultsHash []byte `protobuf:"bytes,13,opt,name=results_hash,json=resultsHash,proto3" json:"results_hash,omitempty"` + // Current and next parameter commitments enter Header.Hash and the signed BlockID. + // Draft full-commitment rules: spec/consensus/consensus-params-commitment.md. + ConsensusHash []byte `protobuf:"bytes,10,opt,name=consensus_hash,json=consensusHash,proto3" json:"consensus_hash,omitempty"` + NextConsensusHash []byte `protobuf:"bytes,11,opt,name=next_consensus_hash,json=nextConsensusHash,proto3" json:"next_consensus_hash,omitempty"` + AppHash []byte `protobuf:"bytes,12,opt,name=app_hash,json=appHash,proto3" json:"app_hash,omitempty"` + ResultsHash []byte `protobuf:"bytes,13,opt,name=results_hash,json=resultsHash,proto3" json:"results_hash,omitempty"` // consensus info EvidenceHash []byte `protobuf:"bytes,14,opt,name=evidence_hash,json=evidenceHash,proto3" json:"evidence_hash,omitempty"` ProposedAppVersion uint64 `protobuf:"varint,15,opt,name=proposed_app_version,json=proposedAppVersion,proto3" json:"proposed_app_version,omitempty"` diff --git a/spec/abci++/api.md b/spec/abci++/api.md index 0acca5fde0..64c5ae71dc 100644 --- a/spec/abci++/api.md +++ b/spec/abci++/api.md @@ -1088,7 +1088,7 @@ nondeterministic | consensus_param_updates | [tendermint.types.ConsensusParams](#tendermint-types-ConsensusParams) | | Changes to consensus-critical gas, size, and other parameters that will be applied at next height. | | core_chain_lock_update | [tendermint.types.CoreChainLock](#tendermint-types-CoreChainLock) | | Core chain lock that will be used for next block. | | validator_set_update | [ValidatorSetUpdate](#tendermint-abci-ValidatorSetUpdate) | | Changes to validator set that will be applied at next height. | -| app_version | [uint64](#uint64) | | Application version that was used to create the current proposal. | +| app_version | [uint64](#uint64) | | Application protocol version used to create this proposal; MUST be non-zero. It becomes Header.Version.App. Validators' applications verify it in ProcessProposal. | diff --git a/spec/consensus/consensus-params-commitment.md b/spec/consensus/consensus-params-commitment.md index 03235b2ff8..0284383c4b 100644 --- a/spec/consensus/consensus-params-commitment.md +++ b/spec/consensus/consensus-params-commitment.md @@ -1,9 +1,12 @@ # Full Consensus Parameter Commitment **DRAFT.** This is a normative design and source schema proposal, -not implemented consensus behavior. Generated bindings, runtime support and -activation are deliberately deferred. The current Go implementation is unchanged. -MUST, MUST NOT and SHOULD describe the target implementation. +not implemented consensus behavior. The schema has generated bindings; runtime +support and activation are deliberately deferred, and current Go behavior is +unchanged. MUST, MUST NOT and SHOULD describe the target implementation. + +In this document FULL means effective `Version.ConsensusVersion >= 2`, and +LEGACY means a lower consensus version. ## Acceptance scenarios @@ -11,12 +14,12 @@ MUST, MUST NOT and SHOULD describe the target implementation. | --- | --- | | Change any effective parameter, including evidence limits, timeout or threshold presence | The full commitment changes; a substituted snapshot fails authentication. | | Equivalent complete state reached through different partial updates | Identical canonical bytes and hash; raw ABCI patches are never hashed. | -| Omit the commitment selector in a partial update | Retain the current selector. An explicit FULL-to-LEGACY downgrade is rejected. | -| Activate FULL at height H | H-1 signs the full next-parameter hash; H uses the full current-parameter hash. | +| Omit the version group in a partial update after activation | Retain the current consensus version. Any update lowering it below 2 is rejected. | +| Raise the consensus version to 2 at height H | H-1 signs the full next-parameter hash; H uses the full current-parameter hash. | | Attempt activation with incomplete groups or duration fields | Reject before accepting a candidate; unauthenticated legacy values cannot fill gaps. | | Bootstrap from FULL history with a changed threshold | Authenticate each required height's parameters and validator context; do not pin a legitimate mutable threshold to genesis. | -| Replay or restart across activation | Preserve selector presence and historical hash rules; produce the original block IDs and verify the original signatures. | -| Receive unknown selectors, unsupported parameter fields or noncanonical snapshot bytes | Fail closed; never silently downgrade or omit a new parameter. | +| Replay or restart across activation | Hash each height's parameters by their own consensus version; produce the original block IDs and verify the original signatures. | +| Receive unknown consensus versions, unsupported parameter fields or noncanonical snapshot bytes | Fail closed; never silently downgrade or omit a new parameter. | ## Existing commitment and threat boundary @@ -25,8 +28,9 @@ At this proposal's base, `types/params.go:HashConsensusParams` hashes only `HashedParams` message. Evidence limits, validator key types and voting threshold, synchrony bounds, timeouts and ABCI rechecking are outside that digest. The application version leaves consensus parameters entirely; see -[application version](#application-version-is-not-a-consensus-parameter). Actual evidence proofs already contribute to `EvidenceHash`; this -proposal adds their configurable limits, not a second commitment to the proofs. +[application version](#application-version-is-not-a-consensus-parameter). +Actual evidence proofs already contribute to `EvidenceHash`; this proposal adds +their configurable limits, not a second commitment to the proofs. `Header.Hash` already includes `ConsensusHash` and `NextConsensusHash`. Its result enters `BlockID.Hash`, the canonical block-ID digest, `CanonicalVote` and the @@ -45,28 +49,58 @@ A threshold BLS signature proves recovery under the quorum key. It does not prov that a raised application voting-power threshold was met by enough distinct signers. Adding signer-count attestation for that separate issue is out of scope. -## Independent commitment selector +## Consensus version selects the hash rule -`ConsensusParams.commitment_version`, optional field 8, selects the hash rule: +`VersionParams.consensus_version` selects the hash rule of the parameter set that +contains it: -| Value | Meaning | +| Effective `consensus_version` | Hash rule for `ConsensusHash` and `NextConsensusHash` | | --- | --- | -| `COMMITMENT_VERSION_LEGACY = 0` | Preserve the hash rule applicable to that historical protocol/height. | -| `COMMITMENT_VERSION_FULL = 1` | Domain-separated hash of the complete `HashedParamsV2` snapshot below. | - -Omission in an existing genesis document means LEGACY. Omission in an ABCI partial -update means retain the current value, including FULL. An explicit selector is -validated before merging the update; unknown values and FULL-to-LEGACY transitions -MUST be rejected. ABCI patch conversions and no-op detection MUST preserve selector -presence and value: an explicit LEGACY value and an omitted update are different -inputs. Materialized state MUST serialize its resolved selector explicitly through -domain/protobuf/JSON, state-store and state-sync conversions; state equality MUST -compare that value as well as threshold presence and value. - -This selector is independent of `VersionParams.ConsensusVersion`, the block wire -protocol version, and release numbering. FULL does not allocate -`CONSENSUS_VERSION_2` or any new block protocol constant. The `V2` in -`HashedParamsV2` and the hash domain names the snapshot schema, not a release. +| `CONSENSUS_VERSION_0`, `CONSENSUS_VERSION_1` | Legacy `HashedParams` hash, unchanged | +| `CONSENSUS_VERSION_2` | `FullHash` of the complete `HashedParamsV2` snapshot below | +| Any other value | Rejected | + +`CONSENSUS_VERSION_2` keeps the version 1 proposer selection +(`NewHeightRoundProposerSelector`) and adds the full commitment. +`NewProposerSelector` +([`internal/consensus/versioned/selectproposer/proposer_selector.go:59`](../../internal/consensus/versioned/selectproposer/proposer_selector.go)) +MUST map version 2 accordingly; today it rejects every value above 1. + +The rule is self-describing: each parameter set is hashed by its own version. At +H-1, `NextConsensusHash` is computed from the next parameters, which already carry +version 2, so it uses the full rule while `ConsensusHash` stays legacy. The domain +prefix starts with byte `0x74`, which no legacy `HashedParams` encoding (tags 1–3) +can start with, so legacy and full preimages never coincide. + +Validation MUST add two checks that do not exist today: + +1. **Known versions only.** `ValidateConsensusParams` + ([`types/params.go:291`](../../types/params.go)) does not range-check + `Version.ConsensusVersion`. It MUST reject values outside the defined enum, + including negative values, for genesis, InitChain, updates and state sync. +2. **No downgrade from FULL.** Where an ABCI update is merged and validated + ([`internal/state/current_round_state.go:172`](../../internal/state/current_round_state.go)), + reject a candidate below 2 when the current version is 2 or higher. + `ValidateConsensusParams` sees only the candidate, so this check compares the + current and candidate parameters. Transitions between 0 and 1 are unchanged. + +Activation uses the existing mechanism: the application returns +`consensus_param_updates` with `version.consensus_version = 2`, as e2e testnets do +with `consensus_version_updates` +([`test/e2e/pkg/manifest.go:63`](../../test/e2e/pkg/manifest.go)). A genesis +document without a version group resolves to version 0 +([`types/params.go:144`](../../types/params.go)) and therefore LEGACY. + +`UpdateConsensusParams` replaces the whole version group +([`types/params.go:422`](../../types/params.go)). Today a group sent only to set +`app_version` also overwrites `consensus_version`, typically with 0. With +`app_version` removed, the group carries only `consensus_version` and that pitfall +disappears. Protobuf cannot distinguish an omitted enum inside a present group +from an explicit 0, so after activation a present version group with 0 is a +downgrade and is rejected; omitting the group retains the version. + +The `V2` in `HashedParamsV2` and the hash domain names the snapshot schema, not a +release. A later consensus version may keep this schema or define a new one. ## Complete snapshot and frozen mapping @@ -80,14 +114,13 @@ The source of truth is [`proto/tendermint/types/params.proto`](../../proto/tendermint/types/params.proto). `HashedParamsV2` is a flat message; the following mapping is exhaustive for the seven parameter groups in this base. Durations are signed 64-bit nanosecond counts. -Tag 9 and the name `version_app_version` are reserved and never assigned: -`Version.AppVersion` is removed rather than committed (see -[application version](#application-version-is-not-a-consensus-parameter)), so -the snapshot covers every remaining effective parameter. +`Version.AppVersion` is deprecated and excluded rather than committed (see +[application version](#application-version-is-not-a-consensus-parameter)). +Tags are contiguous; the schema is not frozen yet. | Tag | Snapshot field | Protobuf type | Effective source | | --- | --- | --- | --- | -| 1 | `commitment_version` | `uint32` | Constant 1 for FULL | +| 1 | `consensus_version` | `int32` | `Version.ConsensusVersion`; always 2 or higher, so always encoded | | 2 | `block_max_bytes` | `int64` | `Block.MaxBytes` | | 3 | `block_max_gas` | `int64` | `Block.MaxGas` | | 4 | `evidence_max_age_num_blocks` | `int64` | `Evidence.MaxAgeNumBlocks` | @@ -95,14 +128,13 @@ the snapshot covers every remaining effective parameter. | 6 | `evidence_max_bytes` | `int64` | `Evidence.MaxBytes` | | 7 | `validator_pub_key_types` | repeated `string` | `Validator.PubKeyTypes`, preserving order | | 8 | `validator_voting_power_threshold` | optional `uint64` | `Validator.VotingPowerThreshold`, preserving absence versus explicit zero | -| 10 | `version_consensus_version` | `int32` | `Version.ConsensusVersion` | -| 11 | `synchrony_message_delay_ns` | `int64` | `Synchrony.MessageDelay` | -| 12 | `synchrony_precision_ns` | `int64` | `Synchrony.Precision` | -| 13 | `timeout_propose_ns` | `int64` | `Timeout.Propose` | -| 14 | `timeout_propose_delta_ns` | `int64` | `Timeout.ProposeDelta` | -| 15 | `timeout_vote_ns` | `int64` | `Timeout.Vote` | -| 16 | `timeout_vote_delta_ns` | `int64` | `Timeout.VoteDelta` | -| 17 | `abci_recheck_tx` | `bool` | `ABCI.RecheckTx` | +| 9 | `synchrony_message_delay_ns` | `int64` | `Synchrony.MessageDelay` | +| 10 | `synchrony_precision_ns` | `int64` | `Synchrony.Precision` | +| 11 | `timeout_propose_ns` | `int64` | `Timeout.Propose` | +| 12 | `timeout_propose_delta_ns` | `int64` | `Timeout.ProposeDelta` | +| 13 | `timeout_vote_ns` | `int64` | `Timeout.Vote` | +| 14 | `timeout_vote_delta_ns` | `int64` | `Timeout.VoteDelta` | +| 15 | `abci_recheck_tx` | `bool` | `ABCI.RecheckTx` | Do not sort or deduplicate public-key types during hashing. Their order is part of the committed value even if current validation treats the list as a membership @@ -112,7 +144,7 @@ MUST be exact and within int64 range; reject overflow and invalid effective valu The `HashedParamsV2` field meanings, tags, wire types and canonical encoding MUST be frozen before activation. A future parameter or changed interpretation requires -an explicit reviewed commitment-version upgrade, not silent omission or mutation +a new consensus version with a reviewed hash rule, not silent omission or mutation of this snapshot. The existing `HashedParams` schema and historical bytes remain unchanged. @@ -154,19 +186,20 @@ never apply it retroactively to a legacy hash. ## Activation and ordinary updates -Let H be the first height whose current parameters select FULL. The software and -application upgrade MUST be deployed before height H-1, whose candidate already -needs to construct and validate a full next-parameter commitment. +Let H be the first height whose current parameters have consensus version 2 or +higher. The software and application upgrade MUST be deployed before height H-1, +whose candidate already needs to construct and validate a full next-parameter +commitment. -| Block height | Current selector and `ConsensusHash` | Next selector and `NextConsensusHash` | +| Block height | Current version and `ConsensusHash` | Next version and `NextConsensusHash` | | --- | --- | --- | -| H-2 | LEGACY / historical hash | LEGACY / historical hash | -| H-1 | LEGACY / historical hash | FULL / `FullHash(P_H)` | -| H and later | FULL / `FullHash(P_h)` | FULL / `FullHash(P_(h+1))` | +| H-2 | Below 2 / historical hash | Below 2 / historical hash | +| H-1 | Below 2 / historical hash | 2 / `FullHash(P_H)` | +| H and later | 2 or higher / `FullHash(P_h)` | 2 or higher / `FullHash(P_(h+1))` | -At H-1 the application MUST explicitly supply `commitment_version = FULL` and all -seven parameter-group messages: block, evidence, validator, version, synchrony, -timeout and ABCI. Every duration field MUST be supplied. Each supplied group is +The parameter update returned for H-1 that raises the consensus version to 2 MUST +explicitly supply all seven parameter-group messages: block, evidence, validator, +version, synchrony, timeout and ABCI. Every duration field MUST be supplied. Each supplied group is the complete intended replacement under the normal update semantics; zero scalar values are intentional values where valid. Within the complete validator group, an absent threshold explicitly means no configured override, not inheritance. @@ -182,24 +215,25 @@ uncommitted values, or fail normal validation. Validate completeness before any completion routine can fill omissions. This prevents an earlier unauthenticated state-sync parameter from seeding the first full snapshot. Validate the complete candidate after normal ABCI processing and require the proposer and validator to -derive identical next commitments before acceptance. A chain starting in FULL -MUST likewise supply a complete validated genesis/InitChain parameter snapshot. +derive identical next commitments before acceptance. A chain starting at +consensus version 2 MUST likewise supply a complete validated genesis/InitChain parameter snapshot. After activation, ordinary partial updates are allowed: merge into the last -authenticated full state, preserve an omitted selector, validate the result and -hash the complete effective value. Unchanged updates produce unchanged hashes. +authenticated full state, retain the consensus version when the version group is +omitted, reject any decrease below 2, validate the result and hash the complete +effective value. Unchanged updates produce unchanged hashes. Persist the selected current and next states atomically with their normal block application state; restart and replay MUST recover the original transition. ## State sync, light verification and history -Both RPC and P2P state providers MUST select the commitment rule from authenticated -protocol/height context and the candidate selector, verify it against the signed -header hash, and reject mismatches or unknown rules before installing state. -A peer's selector is not independently trusted. Authenticate the snapshot at the +Both RPC and P2P state providers MUST select the hash rule from the candidate's +consensus version, verify the result against the signed header hash, and reject +mismatches or unknown versions before installing state. A peer's claimed version +is authenticated only by reproducing the signed hash under the rule it selects. Authenticate the snapshot at the height whose `ConsensusHash` is used; if using a prior header's `NextConsensusHash`, bind it to the successor height. Do not infer authenticity from structural -validation, a claimed response height or the mere presence of FULL. +validation, a claimed response height or a claimed version of 2 or higher. For FULL, allow legitimate threshold updates only after complete-hash verification; do not keep the legacy genesis pin as a substitute for that authentication. @@ -213,15 +247,17 @@ because it accompanies an application snapshot. For LEGACY history, retain existing genesis-threshold and quorum-binding defenses; FULL is not a reason to weaken verification of old blocks. Keep each historical hash variant applicable to its original protocol and height. Old clients that -ignore the selector cannot safely follow activation: interoperability is an +do not know version 2 cannot safely follow activation: interoperability is an upgrade requirement, not a fallback to legacy verification. ## Application version is not a consensus parameter `ConsensusParams.Version.AppVersion` (`VersionParams.app_version`, field 1) is -removed. Field 1 and its name are reserved in `VersionParams`. The legacy -`HashedParams` never included it, so no historical or LEGACY hash changes, and the -removal needs no activation height. Citations below describe this base. +removed. This schema only marks the field DEPRECATED so that generated bindings and +current code still build; reserving field 1 and its name lands with the +implementation. The legacy `HashedParams` never included it, so no historical or +LEGACY hash changes, and the removal needs no activation height. Citations below +describe this base. 1. **Block header.** `ResponsePrepareProposal.app_version` MUST be non-zero and is the only source of `Header.Version.App`. `ResponsePrepareProposal.Validate` @@ -243,8 +279,9 @@ removal needs no activation height. Citations below describe this base. `State.MakeBlock` does not seed the header's app version from state ([`internal/state/state.go:291`](../../internal/state/state.go)), so `RequestPrepareProposal.version` carries only the block version; Tenderdash - leaves `app` unset. The shared `tendermint.version.Consensus` message keeps - `app` because `Header.Version` uses it. + leaves `app` unset, and that field's comment changes with the implementation. + The shared `tendermint.version.Consensus` message keeps `app` because + `Header.Version` uses it. 3. **Node info.** `NodeInfo.ProtocolVersion.App` is taken from `ResponseInfo.app_version`, which the handshake already returns ([`internal/consensus/replay.go:287`](../../internal/consensus/replay.go), @@ -265,35 +302,36 @@ removal needs no activation height. Citations below describe this base. in `InitChain`, `PrepareProposal` or `FinalizeBlock` parameter updates. Genesis JSON containing `consensus_params.version.app_version` still loads, because [`types/genesis.go`](../../types/genesis.go) decodes with lenient - `json.Unmarshal`. Generated ABCI clients drop the field, which requires a - coordinated application release. + `json.Unmarshal`. Once field 1 is reserved, generated ABCI clients drop it, + which requires a coordinated application release. ## Integration and implementation sequence -1. Resolve the integration blocker before freezing this snapshot. Open - [#1572](https://github.com/dashpay/tenderdash/pull/1572) assigns heartbeat behavior - `ConsensusVersion = 2` and adds two timeouts to its legacy hash; - [#1583](https://github.com/dashpay/tenderdash/pull/1583) also uses version 2 for - randomness. Reconcile those protocol assignments separately. Any heartbeat - parameters merged before activation MUST be added to the full mapping/schema - and vectors before freezing it. Preserve any merged legacy hash variant for - replay. The 16-field draft above MUST NOT activate while that coverage is stale. -2. Generate bindings and implement selector-preserving conversions, defaults, - equality and update validation in `types/params.go` and ABCI/state messages. - `Equals` currently omits voting-threshold presence/value; include both that - comparison and the selector to avoid incorrect empty/no-op shortcuts. -3. Implement the canonical snapshot encoder and version dispatch; retain the - existing legacy encoder. Wire current/next hashes through - `internal/state/current_round_state.go`, `internal/state/validation.go` and +1. Resolve the integration blocker before freezing this snapshot. This document + allocates `CONSENSUS_VERSION_2`. Open + [#1572](https://github.com/dashpay/tenderdash/pull/1572) also assigns + `ConsensusVersion = 2` to heartbeat behavior and adds two timeouts to its legacy + hash; [#1583](https://github.com/dashpay/tenderdash/pull/1583) also uses version 2 + for randomness. Reconcile these number assignments before any of them merges. + Any heartbeat parameters merged before activation MUST be added to the full + mapping/schema and vectors before freezing it. Preserve any merged legacy hash + variant for replay. The 15-field draft above MUST NOT activate while that + coverage is stale. +2. Implement the version range check, the no-downgrade check, conversions, + defaults and equality in `types/params.go` and ABCI/state messages, and map + version 2 in `NewProposerSelector`. `Equals` currently omits voting-threshold + presence/value; include it to avoid incorrect empty/no-op shortcuts. +3. Implement the canonical snapshot encoder and dispatch `HashConsensusParams` by + consensus version; retain the existing legacy encoder. Wire current/next hashes + through `internal/state/current_round_state.go`, `internal/state/validation.go` and proposal/block validation. Enforce the complete transition in genesis/InitChain and proposal processing. Recompute derived validator thresholds, including clearing a prior positive override when the complete new snapshot has none; - do not depend on a membership update to perform this reset. Do not allocate a - new consensus version implicitly. + do not depend on a membership update to perform this reset. 4. Update persisted-state conversions, replay and startup handling. Update both `internal/statesync/stateprovider.go` providers, `verifyConsensusParams`, `applyVotingPowerThreshold` and P2P parameter-response conversion. Audit RPC, - light-client and SDK consumers for selector transport and height binding. + light-client and SDK consumers for consensus-version transport and height binding. 5. Publish cross-language vectors and run the tests below. Coordinate an explicit H, deploy before H-1, exercise mixed-version rejection on a test network, and permit activation only after all blockers and acceptance tests pass. @@ -303,12 +341,12 @@ removal needs no activation height. Citations below describe this base. | Area | Required tests | | --- | --- | | Coverage | Mutate every mapped scalar and each list element/order; test nil, present zero and positive threshold separately. Every effective change changes the full hash. | -| Updates | Different patches reaching the same state hash equally; omitted groups/durations retain values only after activation; invalid values, unknown selectors, unsupported fields and downgrade attempts fail closed. | -| Transition | Complete H-1 proposal accepted, incomplete transition rejected; current/next hashes at H-2/H-1/H agree across proposer, validators, stored state and RPC. Old positive live threshold to FULL with no override clears the derived threshold even with unchanged members. Complete FULL genesis works. | +| Updates | Different patches reaching the same state hash equally; omitted groups/durations retain values only after activation; invalid values, unknown consensus versions, unsupported fields and decreases below 2, including a present version group with 0, fail closed. | +| Transition | Complete H-1 proposal accepted, incomplete transition rejected; current/next hashes at H-2/H-1/H agree across proposer, validators, stored state and RPC. Old positive live threshold to FULL with no override clears the derived threshold even with unchanged members. Complete genesis at consensus version 2 works. | | Encoding | Cross-language bytes and hashes for valid complete snapshots, zero-value omission, threshold presence, `max_gas = -1`, list order, UTF-8 and duration boundaries; reject duplicate/unknown fields and nonminimal encodings. | | Authentication | Substitute each previously unhashed field in RPC/P2P responses; correlate response height and signed header; require per-height thresholds when validator sets cross an update. | | Application version | Proposal with zero `app_version` rejected; header app version always equals the proposer response; legacy hashes unchanged; field 1 from an old application and in genesis JSON ignored; state sync accepts Info above the header version and rejects below. | -| Recovery | Replay and restart before/at/after H; historical signature/block-ID vectors unchanged; persisted selector and optional threshold survive round trips. | +| Recovery | Replay and restart before/at/after H; historical signature/block-ID vectors unchanged; persisted consensus version and optional threshold survive round trips. | | Quorum and policy | Retain Core-backed membership/key binding and all legacy trust defenses; authenticate FULL mutable thresholds without genesis pinning; do not claim raised-threshold signer-count attestation. | ## Tracking From 686f8be440c6e163cda33126a87a4ec693cdd938 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Fri, 6 Nov 2026 15:58:20 +0000 Subject: [PATCH 06/12] feat(types)!: remove app version from consensus parameters Reserve VersionParams field 1 (app_version) and drop types.VersionParams.AppVersion with its conversions. State takes its application version from the committed block header, which the proposer's PrepareProposal response sets, and rollback takes it from the header of the block rolled back to. The kvstore example and e2e app stop sending the field. Genesis JSON with consensus_params.version.app_version still loads; the key is ignored. BREAKING CHANGE: ABCI applications can no longer set the application version through consensus parameter updates; field 1 is ignored on decode. Co-Authored-By: Claude Opus 5.5 --- abci/example/kvstore/kvstore.go | 6 +- abci/example/kvstore/kvstore_test.go | 2 +- internal/rpc/core/blocks_test.go | 4 +- internal/state/current_round_state.go | 1 - internal/state/execution.go | 2 + internal/state/helpers_test.go | 8 +- internal/state/rollback.go | 2 +- internal/state/rollback_test.go | 5 +- internal/state/state_test.go | 22 ++++ proto/tendermint/types/params.pb.go | 181 ++++++++++---------------- proto/tendermint/types/params.proto | 8 +- test/e2e/app/app.go | 1 - types/genesis_test.go | 24 ++++ types/params.go | 7 +- types/params_test.go | 7 +- 15 files changed, 135 insertions(+), 145 deletions(-) diff --git a/abci/example/kvstore/kvstore.go b/abci/example/kvstore/kvstore.go index 02e287e7a0..91c5b23ce4 100644 --- a/abci/example/kvstore/kvstore.go +++ b/abci/example/kvstore/kvstore.go @@ -302,11 +302,7 @@ func (app *Application) InitChain(_ context.Context, req *abci.RequestInitChain) } consensusParams, ok := app.consensusParamsUpdates[app.initialHeight] if !ok { - consensusParams = types1.ConsensusParams{ - Version: &types1.VersionParams{ - AppVersion: uint64(app.LastCommittedState.GetHeight()) + 1, - }, - } + consensusParams = types1.ConsensusParams{} } vsu := app.getValidatorSetUpdate(app.initialHeight, 0) if vsu == nil { diff --git a/abci/example/kvstore/kvstore_test.go b/abci/example/kvstore/kvstore_test.go index e109c851d2..13503a7433 100644 --- a/abci/example/kvstore/kvstore_test.go +++ b/abci/example/kvstore/kvstore_test.go @@ -215,7 +215,7 @@ func TestConsensusParamsUpdate(t *testing.T) { genesisHeight + 4: { ConsParamUpdates: &tmproto.ConsensusParams{ Version: &tmproto.VersionParams{ - AppVersion: 123, + ConsensusVersion: tmproto.VersionParams_CONSENSUS_VERSION_1, }, }, }, diff --git a/internal/rpc/core/blocks_test.go b/internal/rpc/core/blocks_test.go index cd722b81a8..4a970cd258 100644 --- a/internal/rpc/core/blocks_test.go +++ b/internal/rpc/core/blocks_test.go @@ -81,7 +81,7 @@ func TestBlockResults(t *testing.T) { }, ConsensusParamUpdates: &types.ConsensusParams{ Version: &types.VersionParams{ - AppVersion: 1, + ConsensusVersion: types.VersionParams_CONSENSUS_VERSION_1, }, }, }, @@ -111,7 +111,7 @@ func TestBlockResults(t *testing.T) { FinalizeBlockEvents: results.ProcessProposal.Events, ValidatorSetUpdate: results.ProcessProposal.ValidatorSetUpdate, ConsensusParamUpdates: &tmtypes.ConsensusParams{ - Version: tmtypes.VersionParams{AppVersion: 1}, + Version: tmtypes.VersionParams{ConsensusVersion: 1}, }, }}, } diff --git a/internal/state/current_round_state.go b/internal/state/current_round_state.go index a733d1e01e..bc4ad76ff2 100644 --- a/internal/state/current_round_state.go +++ b/internal/state/current_round_state.go @@ -97,7 +97,6 @@ func (candidate *CurrentRoundState) UpdateState(target *State) error { target.LastResultsHash = candidate.ResultsHash target.ConsensusParams = candidate.NextConsensusParams target.LastHeightConsensusParamsChanged = candidate.LastHeightConsensusParamsChanged - target.Version.Consensus.App = candidate.NextConsensusParams.Version.AppVersion target.Validators = candidate.NextValidators target.LastHeightValidatorsChanged = candidate.LastHeightValidatorsChanged if candidate.CoreChainLock != nil { diff --git a/internal/state/execution.go b/internal/state/execution.go index c196489fe6..1dd1fc550f 100644 --- a/internal/state/execution.go +++ b/internal/state/execution.go @@ -791,6 +791,8 @@ func (state State) Update( ) (State, error) { nextVersion := state.Version + // The proposer's PrepareProposal response sets the committed header's app version. + nextVersion.Consensus.App = header.Version.App // NOTE: LastBlockRound, LastStateIDHash, AppHash and VoteExtension has not been populated. // It will be filled on state.Save. diff --git a/internal/state/helpers_test.go b/internal/state/helpers_test.go index e883011b30..b895284089 100644 --- a/internal/state/helpers_test.go +++ b/internal/state/helpers_test.go @@ -273,9 +273,7 @@ func (app *testApp) PrepareProposal(_ context.Context, req *abci.RequestPrepareP AppHash: make([]byte, crypto.DefaultAppHashSize), ValidatorSetUpdate: app.ValidatorSetUpdate, ConsensusParamUpdates: &tmproto.ConsensusParams{ - Version: &tmproto.VersionParams{ - AppVersion: 1, - }, + Version: &tmproto.VersionParams{}, }, AppVersion: 1, TxResults: resTxs, @@ -291,9 +289,7 @@ func (app *testApp) ProcessProposal(_ context.Context, req *abci.RequestProcessP AppHash: make([]byte, crypto.DefaultAppHashSize), ValidatorSetUpdate: app.ValidatorSetUpdate, ConsensusParamUpdates: &tmproto.ConsensusParams{ - Version: &tmproto.VersionParams{ - AppVersion: 1, - }, + Version: &tmproto.VersionParams{}, }, TxResults: resTxs, Status: abci.ResponseProcessProposal_ACCEPT, diff --git a/internal/state/rollback.go b/internal/state/rollback.go index 5690778629..b92fbe8332 100644 --- a/internal/state/rollback.go +++ b/internal/state/rollback.go @@ -75,7 +75,7 @@ func Rollback(bs BlockStore, ss Store) (int64, []byte, error) { Version: Version{ Consensus: version.Consensus{ Block: version.BlockProtocol, - App: previousParams.Version.AppVersion, + App: rollbackBlock.Header.Version.App, }, Software: version.TMCoreSemVer, }, diff --git a/internal/state/rollback_test.go b/internal/state/rollback_test.go index 1681a6002f..eb05724892 100644 --- a/internal/state/rollback_test.go +++ b/internal/state/rollback_test.go @@ -27,7 +27,6 @@ func TestRollback(t *testing.T) { // perform the rollback over a version bump newParams := types.DefaultConsensusParams() - newParams.Version.AppVersion = 11 newParams.Block.MaxBytes = 1000 nextState := initialState.Copy() nextState.LastBlockHeight = nextHeight @@ -45,6 +44,8 @@ func TestRollback(t *testing.T) { block := &types.BlockMeta{ BlockID: initialState.LastBlockID, Header: types.Header{ + // The rolled-back state's app version comes from this header. + Version: version.Consensus{Block: version.BlockProtocol, App: initialState.Version.Consensus.App}, Height: initialState.LastBlockHeight, AppHash: factory.RandomHash(), LastBlockID: factory.MakeBlockID(), @@ -57,6 +58,7 @@ func TestRollback(t *testing.T) { nextBlock := &types.BlockMeta{ BlockID: initialState.LastBlockID, Header: types.Header{ + Version: version.Consensus{Block: version.BlockProtocol, App: 11}, Height: nextState.LastBlockHeight, AppHash: initialState.LastAppHash, LastBlockID: block.BlockID, @@ -123,7 +125,6 @@ func setupStateStore(t *testing.T, height int64) state.Store { valSet, _ := types.RandValidatorSet(5) params := types.DefaultConsensusParams() - params.Version.AppVersion = 10 initialState := state.State{ Version: state.Version{ diff --git a/internal/state/state_test.go b/internal/state/state_test.go index e57adf375a..2d14658ff0 100644 --- a/internal/state/state_test.go +++ b/internal/state/state_test.go @@ -26,6 +26,7 @@ import ( statefactory "github.com/dashpay/tenderdash/internal/state/test/factory" tmstate "github.com/dashpay/tenderdash/proto/tendermint/state" "github.com/dashpay/tenderdash/types" + "github.com/dashpay/tenderdash/version" ) // setupTestCase does setup common to all test cases. @@ -769,3 +770,24 @@ func assertLLMQDataWithValidatorSet(t *testing.T, ld *llmq.Data, valSet *types.V } require.Equal(t, ld.ThresholdPubKey, valSet.ThresholdPublicKey) } + +// The application version recorded in state follows the committed block header, +// which the proposer's PrepareProposal response sets; consensus parameters carry +// no application version. +func TestStateUpdateTakesAppVersionFromCommittedHeader(t *testing.T) { + tearDown, _, state := setupTestCase(t) + defer tearDown(t) + + state.Version.Consensus.App = 1 + ctx := dash.ContextWithProTxHash(context.Background(), state.Validators.GetByIndex(0).ProTxHash) + changes, err := state.NewStateChangeset(ctx, sm.RoundParams{}) + require.NoError(t, err) + + header := types.Header{ + Version: version.Consensus{Block: version.BlockProtocol, App: 7}, + Height: state.LastBlockHeight + 1, + } + newState, err := state.Update(types.BlockID{}, &header, &changes) + require.NoError(t, err) + assert.EqualValues(t, 7, newState.Version.Consensus.App) +} diff --git a/proto/tendermint/types/params.pb.go b/proto/tendermint/types/params.pb.go index 4b9a16e229..94e080c4c3 100644 --- a/proto/tendermint/types/params.pb.go +++ b/proto/tendermint/types/params.pb.go @@ -65,7 +65,7 @@ type ConsensusParams struct { Block *BlockParams `protobuf:"bytes,1,opt,name=block,proto3" json:"block,omitempty"` Evidence *EvidenceParams `protobuf:"bytes,2,opt,name=evidence,proto3" json:"evidence,omitempty"` Validator *ValidatorParams `protobuf:"bytes,3,opt,name=validator,proto3" json:"validator,omitempty"` - // Consensus protocol version; its app_version field is deprecated. + // Consensus protocol version. Version *VersionParams `protobuf:"bytes,4,opt,name=version,proto3" json:"version,omitempty"` Synchrony *SynchronyParams `protobuf:"bytes,5,opt,name=synchrony,proto3" json:"synchrony,omitempty"` Timeout *TimeoutParams `protobuf:"bytes,6,opt,name=timeout,proto3" json:"timeout,omitempty"` @@ -369,9 +369,6 @@ func (*ValidatorParams) XXX_OneofWrappers() []interface{} { // VersionParams contains the consensus protocol version. type VersionParams struct { - // DEPRECATED: ResponsePrepareProposal.app_version sets Header.Version.App. - // Removal: spec/consensus/consensus-params-commitment.md#application-version-is-not-a-consensus-parameter - AppVersion uint64 `protobuf:"varint,1,opt,name=app_version,json=appVersion,proto3" json:"app_version,omitempty"` // Version of consensus protocol, used to upgrade consensus without hard forks ConsensusVersion VersionParams_ConsensusVersion `protobuf:"varint,2,opt,name=consensus_version,json=consensusVersion,proto3,enum=tendermint.types.VersionParams_ConsensusVersion" json:"consensus_version,omitempty"` } @@ -409,13 +406,6 @@ func (m *VersionParams) XXX_DiscardUnknown() { var xxx_messageInfo_VersionParams proto.InternalMessageInfo -func (m *VersionParams) GetAppVersion() uint64 { - if m != nil { - return m.AppVersion - } - return 0 -} - func (m *VersionParams) GetConsensusVersion() VersionParams_ConsensusVersion { if m != nil { return m.ConsensusVersion @@ -887,76 +877,75 @@ func init() { func init() { proto.RegisterFile("tendermint/types/params.proto", fileDescriptor_e12598271a686f57) } var fileDescriptor_e12598271a686f57 = []byte{ - // 1091 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x96, 0xcf, 0x6f, 0xe3, 0x44, - 0x14, 0xc7, 0xe3, 0x26, 0x4d, 0x93, 0x97, 0xa6, 0x09, 0x43, 0x77, 0xeb, 0xfd, 0xd1, 0xb4, 0x6b, - 0x24, 0x54, 0x69, 0x51, 0xd2, 0x6d, 0x17, 0xa1, 0x85, 0x65, 0xd1, 0xa6, 0xad, 0xf6, 0x07, 0x34, - 0x5b, 0xb9, 0xa5, 0x07, 0xa4, 0xd5, 0x68, 0xe2, 0x0c, 0x89, 0xd5, 0xd8, 0x63, 0x79, 0x9c, 0x90, - 0xfc, 0x05, 0x20, 0x71, 0xe1, 0x84, 0xf6, 0xca, 0x0d, 0x2e, 0x88, 0xbf, 0x81, 0xd3, 0x1e, 0xf7, - 0xc8, 0x09, 0x50, 0x7b, 0xe7, 0x6f, 0x40, 0x33, 0xf6, 0x38, 0x71, 0xea, 0xaa, 0xb9, 0xc5, 0xf3, - 0xfd, 0x7e, 0xfc, 0xe6, 0xcd, 0x7b, 0x6f, 0x1c, 0x58, 0x0f, 0xa8, 0xdb, 0xa1, 0xbe, 0x63, 0xbb, - 0x41, 0x23, 0x18, 0x7b, 0x94, 0x37, 0x3c, 0xe2, 0x13, 0x87, 0xd7, 0x3d, 0x9f, 0x05, 0x0c, 0x55, - 0x27, 0x72, 0x5d, 0xca, 0xb7, 0x57, 0xbb, 0xac, 0xcb, 0xa4, 0xd8, 0x10, 0xbf,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, 0xf4, 0x06, 0xed, 0xba, - 0xc5, 0x9c, 0x46, 0x87, 0xf0, 0x9e, 0x47, 0xc6, 0x8d, 0xf0, 0xd3, 0x24, 0x9e, 0xc2, 0x7f, 0x8f, - 0x8d, 0xd9, 0x7f, 0xa4, 0xed, 0xbc, 0x5c, 0xdf, 0xfd, 0x7f, 0x00, 0x52, 0xed, 0xaa, 0xaf, 0xac, - 0x0a, 0x00, 0x00, + // 1086 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x96, 0x41, 0x6f, 0x1b, 0x45, + 0x14, 0xc7, 0x3d, 0xb6, 0xe3, 0xd8, 0xcf, 0x71, 0x6c, 0x86, 0xb4, 0xd9, 0xa6, 0x8d, 0x93, 0x2e, + 0x12, 0x8a, 0x54, 0x64, 0xa7, 0x49, 0x11, 0x2a, 0x94, 0xa2, 0x3a, 0x89, 0xda, 0x06, 0xe2, 0x46, + 0x9b, 0x90, 0x03, 0x52, 0x35, 0x5a, 0xdb, 0x83, 0xbd, 0x8a, 0x77, 0x67, 0xb5, 0xb3, 0x36, 0xf6, + 0x27, 0x00, 0x89, 0x0b, 0x27, 0xd4, 0x2b, 0x37, 0xb8, 0x20, 0x3e, 0x03, 0xa7, 0x1e, 0x7b, 0xe4, + 0x04, 0x55, 0xf2, 0x45, 0xd0, 0xcc, 0xee, 0xac, 0xbd, 0xce, 0x46, 0xf1, 0xcd, 0x3b, 0xff, 0xff, + 0x6f, 0xdf, 0xbc, 0x79, 0xef, 0xcd, 0x1a, 0xd6, 0x7d, 0xea, 0x74, 0xa8, 0x67, 0x5b, 0x8e, 0x5f, + 0xf7, 0xc7, 0x2e, 0xe5, 0x75, 0xd7, 0xf4, 0x4c, 0x9b, 0xd7, 0x5c, 0x8f, 0xf9, 0x0c, 0x57, 0x26, + 0x72, 0x4d, 0xca, 0x6b, 0x2b, 0x5d, 0xd6, 0x65, 0x52, 0xac, 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c0, 0x31, + 0x3e, 0x48, 0x26, 0x27, 0xa9, 0xca, 0x14, 0x15, 0xe4, 0xf3, 0x29, 0xac, 0x46, 0x37, 0x23, 0x89, + 0x0f, 0xca, 0xa2, 0x1c, 0x94, 0x95, 0x48, 0x3e, 0x9e, 0x9a, 0x98, 0x6f, 0x60, 0x73, 0x82, 0x5d, + 0x33, 0x3b, 0xf9, 0x70, 0x76, 0xd6, 0x23, 0xe7, 0x59, 0xf2, 0x10, 0xe1, 0x2f, 0x60, 0x2d, 0xba, + 0x22, 0x89, 0x4d, 0x39, 0x97, 0x39, 0xd3, 0xbe, 0x39, 0x16, 0x09, 0x17, 0x82, 0xf3, 0x8a, 0x1c, + 0x47, 0x81, 0x61, 0x5f, 0xe8, 0x4d, 0x8e, 0x1f, 0xc1, 0xed, 0x09, 0xec, 0x7a, 0xb4, 0x6d, 0xf1, + 0xf0, 0xa4, 0x40, 0x82, 0x2b, 0x91, 0x7a, 0xac, 0xc4, 0xe0, 0x94, 0xc2, 0x8b, 0x95, 0xb8, 0x1e, + 0x73, 0x19, 0xa7, 0x82, 0x28, 0x06, 0xa7, 0x14, 0x2a, 0xc7, 0x81, 0xd0, 0xe4, 0xf8, 0x33, 0xd0, + 0x66, 0xdd, 0x1d, 0xda, 0xf7, 0x4d, 0xc1, 0x2c, 0x49, 0xe6, 0x56, 0x9c, 0xd9, 0x17, 0x6a, 0x53, + 0xce, 0x83, 0x02, 0x87, 0xcc, 0x97, 0x31, 0x4a, 0x41, 0x5b, 0x85, 0xcb, 0x67, 0xcc, 0x17, 0x01, + 0x1e, 0xc2, 0xad, 0x98, 0x2f, 0x7a, 0xfb, 0xb2, 0x74, 0xe3, 0x29, 0xf7, 0xd4, 0xab, 0xc5, 0x2d, + 0x4f, 0x3c, 0xda, 0xee, 0xd1, 0xf6, 0x39, 0xf1, 0x47, 0x5a, 0x79, 0x13, 0x6d, 0xe5, 0x8d, 0x92, + 0x58, 0x36, 0x82, 0xd5, 0xd3, 0xd1, 0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 0xf5, 0x8e, 0xc9, 0x7b, + 0xae, 0x39, 0xae, 0x07, 0x5f, 0x2b, 0xf1, 0x14, 0xfc, 0x5f, 0xac, 0xcf, 0xfe, 0x07, 0x6d, 0xe5, + 0xe4, 0xfa, 0xee, 0xff, 0x03, 0x00, 0xb4, 0x8c, 0xf5, 0x9b, 0x9e, 0x0a, 0x00, 0x00, } func (this *ConsensusParams) Equal(that interface{}) bool { @@ -1139,9 +1128,6 @@ func (this *VersionParams) Equal(that interface{}) bool { } else if this == nil { return false } - if this.AppVersion != that1.AppVersion { - return false - } if this.ConsensusVersion != that1.ConsensusVersion { return false } @@ -1675,11 +1661,6 @@ func (m *VersionParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x10 } - if m.AppVersion != 0 { - i = encodeVarintParams(dAtA, i, uint64(m.AppVersion)) - i-- - dAtA[i] = 0x8 - } return len(dAtA) - i, nil } @@ -2114,9 +2095,6 @@ func (m *VersionParams) Size() (n int) { } var l int _ = l - if m.AppVersion != 0 { - n += 1 + sovParams(uint64(m.AppVersion)) - } if m.ConsensusVersion != 0 { n += 1 + sovParams(uint64(m.ConsensusVersion)) } @@ -2909,25 +2887,6 @@ func (m *VersionParams) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: VersionParams: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field AppVersion", wireType) - } - m.AppVersion = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowParams - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.AppVersion |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } case 2: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field ConsensusVersion", wireType) diff --git a/proto/tendermint/types/params.proto b/proto/tendermint/types/params.proto index a6a83c39fa..823038a6bf 100644 --- a/proto/tendermint/types/params.proto +++ b/proto/tendermint/types/params.proto @@ -14,7 +14,7 @@ message ConsensusParams { BlockParams block = 1; EvidenceParams evidence = 2; ValidatorParams validator = 3; - // Consensus protocol version; its app_version field is deprecated. + // Consensus protocol version. VersionParams version = 4; SynchronyParams synchrony = 5; TimeoutParams timeout = 6; @@ -82,9 +82,9 @@ message ValidatorParams { // VersionParams contains the consensus protocol version. message VersionParams { - // DEPRECATED: ResponsePrepareProposal.app_version sets Header.Version.App. - // Removal: spec/consensus/consensus-params-commitment.md#application-version-is-not-a-consensus-parameter - uint64 app_version = 1; + // ResponsePrepareProposal.app_version sets Header.Version.App instead. + reserved 1; + reserved "app_version"; // Version of consensus protocol, used to upgrade consensus without hard forks ConsensusVersion consensus_version = 2; diff --git a/test/e2e/app/app.go b/test/e2e/app/app.go index 155d164e28..12b8058305 100644 --- a/test/e2e/app/app.go +++ b/test/e2e/app/app.go @@ -71,7 +71,6 @@ func NewApplication(cfg kvstore.Config, opts ...kvstore.OptFunc) (*Application, params := types1.ConsensusParams{ Version: &types1.VersionParams{ ConsensusVersion: types1.VersionParams_ConsensusVersion(ver), - AppVersion: kvstore.ProtocolVersion, }, } app.AddConsensusParamsUpdate(params, int64(height)) diff --git a/types/genesis_test.go b/types/genesis_test.go index ff690af645..b55fc55a21 100644 --- a/types/genesis_test.go +++ b/types/genesis_test.go @@ -336,6 +336,30 @@ func TestGenesisDocFromJSON_OnlyRemovedTimeoutKeys(t *testing.T) { assert.EqualValues(t, 100, genDoc.ConsensusParams.Block.MaxBytes) } +// A genesis written while consensus parameters carried an application version +// must still load. The key is ignored on decoding and not written back. +func TestGenesisDocFromJSON_IgnoresRemovedAppVersion(t *testing.T) { + genDocBytes := []byte(`{ + "chain_id": "test-chain-removed-app-version", + "validator_quorum_type": 100, + "consensus_params": { + "version": {"app_version": "5", "consensus": "1"}, + "synchrony": {"precision": "1", "message_delay": "10"}, + "validator": {"pub_key_types":["ed25519"]}, + "block": {"max_bytes": "100"}, + "evidence": {"max_age_num_blocks": "100", "max_age_duration": "10"} + } + }`) + + genDoc, err := GenesisDocFromJSON(genDocBytes) + require.NoError(t, err) + assert.EqualValues(t, 1, genDoc.ConsensusParams.Version.ConsensusVersion) + + encoded, err := json.Marshal(genDoc.ConsensusParams) + require.NoError(t, err) + assert.NotContains(t, string(encoded), "app_version") +} + func TestGenesisSaveAs(t *testing.T) { tmpfile, err := os.CreateTemp(t.TempDir(), "genesis") require.NoError(t, err) diff --git a/types/params.go b/types/params.go index 4b411be6ad..118623b43b 100644 --- a/types/params.go +++ b/types/params.go @@ -73,8 +73,7 @@ type ValidatorParams struct { } type VersionParams struct { - AppVersion uint64 `json:"app_version,string"` - ConsensusVersion int32 `json:"consensus,string"` + ConsensusVersion int32 `json:"consensus,string"` } // SynchronyParams influence the validity of block timestamps. @@ -143,7 +142,6 @@ func DefaultValidatorParams() ValidatorParams { func DefaultVersionParams() VersionParams { return VersionParams{ - AppVersion: 0, ConsensusVersion: 0, } } @@ -420,7 +418,6 @@ func (params ConsensusParams) UpdateConsensusParams(params2 *tmproto.ConsensusPa res.Validator = ValidatorParamsFromProto(params2.Validator) } if params2.Version != nil { - res.Version.AppVersion = params2.Version.AppVersion res.Version.ConsensusVersion = int32(params2.Version.ConsensusVersion) } if params2.Synchrony != nil { @@ -464,7 +461,6 @@ func (params *ConsensusParams) ToProto() tmproto.ConsensusParams { }, Validator: params.Validator.ToProto(), Version: &tmproto.VersionParams{ - AppVersion: params.Version.AppVersion, ConsensusVersion: tmproto.VersionParams_ConsensusVersion(params.Version.ConsensusVersion), }, Synchrony: &tmproto.SynchronyParams{ @@ -515,7 +511,6 @@ func ConsensusParamsFromProto(pbParams tmproto.ConsensusParams) ConsensusParams if pbParams.Version != nil { c.Version = VersionParams{ - AppVersion: pbParams.Version.AppVersion, ConsensusVersion: int32(pbParams.Version.ConsensusVersion), } } diff --git a/types/params_test.go b/types/params_test.go index 781e9d7c60..edbd627cf2 100644 --- a/types/params_test.go +++ b/types/params_test.go @@ -238,7 +238,6 @@ func makeParams(args makeParamsArgs) ConsensusParams { if args.consensusVersion != 0 { cp.Version = VersionParams{ - AppVersion: 1, ConsensusVersion: args.consensusVersion, } } @@ -369,7 +368,6 @@ func TestConsensusParamsUpdate(t *testing.T) { initialParams: makeParams(makeParamsArgs{blockBytes: 100, blockGas: 200, evidenceAge: 300}), updates: &tmproto.ConsensusParams{ Version: &tmproto.VersionParams{ - AppVersion: 1, ConsensusVersion: 1, }, }, @@ -390,12 +388,11 @@ func TestConsensusParamsUpdate(t *testing.T) { func TestConsensusParamsUpdate_Version(t *testing.T) { params := makeParams(makeParamsArgs{blockBytes: 1, blockGas: 2, evidenceAge: 3}) - assert.EqualValues(t, 0, params.Version.AppVersion) + assert.EqualValues(t, 0, params.Version.ConsensusVersion) updated := params.UpdateConsensusParams( - &tmproto.ConsensusParams{Version: &tmproto.VersionParams{AppVersion: 1, ConsensusVersion: 1}}) + &tmproto.ConsensusParams{Version: &tmproto.VersionParams{ConsensusVersion: 1}}) - assert.EqualValues(t, 1, updated.Version.AppVersion) assert.EqualValues(t, 1, updated.Version.ConsensusVersion) } From de6f24b5d7a2a99702360f786e42e337d3de396a Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Fri, 6 Nov 2026 15:58:20 +0000 Subject: [PATCH 07/12] docs(spec): require monotonic consensus version without block protocol bump Reject any consensus-version decrease, not only below 2, and record that this changes today's behavior. State that activation must not bump version.BlockProtocol and why. Describe which parts of the app version removal this change implements and which remain. Co-Authored-By: Claude Opus 5.5 --- spec/consensus/consensus-params-commitment.md | 124 +++++++++++------- 1 file changed, 73 insertions(+), 51 deletions(-) diff --git a/spec/consensus/consensus-params-commitment.md b/spec/consensus/consensus-params-commitment.md index 0284383c4b..8e963a942d 100644 --- a/spec/consensus/consensus-params-commitment.md +++ b/spec/consensus/consensus-params-commitment.md @@ -2,8 +2,10 @@ **DRAFT.** This is a normative design and source schema proposal, not implemented consensus behavior. The schema has generated bindings; runtime -support and activation are deliberately deferred, and current Go behavior is -unchanged. MUST, MUST NOT and SHOULD describe the target implementation. +support and activation are deliberately deferred. Only the application-version +removal is partly implemented; see +[application version](#application-version-is-not-a-consensus-parameter). +MUST, MUST NOT and SHOULD describe the target implementation. In this document FULL means effective `Version.ConsensusVersion >= 2`, and LEGACY means a lower consensus version. @@ -14,7 +16,7 @@ LEGACY means a lower consensus version. | --- | --- | | Change any effective parameter, including evidence limits, timeout or threshold presence | The full commitment changes; a substituted snapshot fails authentication. | | Equivalent complete state reached through different partial updates | Identical canonical bytes and hash; raw ABCI patches are never hashed. | -| Omit the version group in a partial update after activation | Retain the current consensus version. Any update lowering it below 2 is rejected. | +| Omit the version group in a partial update | Retain the current consensus version. Any update lowering it is rejected. | | Raise the consensus version to 2 at height H | H-1 signs the full next-parameter hash; H uses the full current-parameter hash. | | Attempt activation with incomplete groups or duration fields | Reject before accepting a candidate; unauthenticated legacy values cannot fill gaps. | | Bootstrap from FULL history with a changed threshold | Authenticate each required height's parameters and validator context; do not pin a legitimate mutable threshold to genesis. | @@ -75,29 +77,42 @@ can start with, so legacy and full preimages never coincide. Validation MUST add two checks that do not exist today: 1. **Known versions only.** `ValidateConsensusParams` - ([`types/params.go:291`](../../types/params.go)) does not range-check + ([`types/params.go:289`](../../types/params.go)) does not range-check `Version.ConsensusVersion`. It MUST reject values outside the defined enum, including negative values, for genesis, InitChain, updates and state sync. -2. **No downgrade from FULL.** Where an ABCI update is merged and validated - ([`internal/state/current_round_state.go:172`](../../internal/state/current_round_state.go)), - reject a candidate below 2 when the current version is 2 or higher. +2. **Never decrease.** Where an ABCI update is merged and validated + ([`internal/state/current_round_state.go:171`](../../internal/state/current_round_state.go)), + reject any candidate whose consensus version is lower than the current one. `ValidateConsensusParams` sees only the candidate, so this check compares the - current and candidate parameters. Transitions between 0 and 1 are unchanged. + current and candidate parameters. This changes today's behavior, which + accepts any decrease, including 1 to 0. Activation uses the existing mechanism: the application returns `consensus_param_updates` with `version.consensus_version = 2`, as e2e testnets do with `consensus_version_updates` ([`test/e2e/pkg/manifest.go:63`](../../test/e2e/pkg/manifest.go)). A genesis document without a version group resolves to version 0 -([`types/params.go:144`](../../types/params.go)) and therefore LEGACY. +([`types/params.go:143`](../../types/params.go)) and therefore LEGACY. + +Activation MUST NOT bump `version.BlockProtocol`; `CONSENSUS_VERSION_2` is the +only switch. `Header.ValidateBasic` requires every header's `Version.Block` to +equal the binary constant +([`types/block.go:477`](../../types/block.go)), state takes that constant at +genesis and rollback +([`internal/state/state.go:37`](../../internal/state/state.go), +[`internal/state/rollback.go:77`](../../internal/state/rollback.go)) and +otherwise copies it from trusted headers in state sync, and peers must match it +([`types/node_info.go:148`](../../types/node_info.go)). A bump would make the new +binary reject every historical block in block sync, replay and state sync, and +would split the network while nodes upgrade instead of switching at height H. `UpdateConsensusParams` replaces the whole version group -([`types/params.go:422`](../../types/params.go)). Today a group sent only to set -`app_version` also overwrites `consensus_version`, typically with 0. With -`app_version` removed, the group carries only `consensus_version` and that pitfall -disappears. Protobuf cannot distinguish an omitted enum inside a present group -from an explicit 0, so after activation a present version group with 0 is a -downgrade and is rejected; omitting the group retains the version. +([`types/params.go:420`](../../types/params.go)). Before `app_version` was +removed, a group sent only to set it also overwrote `consensus_version`, +typically with 0. The group now carries only `consensus_version`, so that pitfall +is gone. Protobuf cannot distinguish an omitted enum inside a present group from +an explicit 0, so a present version group with a lower value, including 0, is a +decrease and is rejected; omitting the group retains the version. The `V2` in `HashedParamsV2` and the hash domain names the snapshot schema, not a release. A later consensus version may keep this schema or define a new one. @@ -220,7 +235,7 @@ consensus version 2 MUST likewise supply a complete validated genesis/InitChain After activation, ordinary partial updates are allowed: merge into the last authenticated full state, retain the consensus version when the version group is -omitted, reject any decrease below 2, validate the result and hash the complete +omitted, reject any decrease, validate the result and hash the complete effective value. Unchanged updates produce unchanged hashes. Persist the selected current and next states atomically with their normal block application state; restart and replay MUST recover the original transition. @@ -253,36 +268,49 @@ upgrade requirement, not a fallback to legacy verification. ## Application version is not a consensus parameter `ConsensusParams.Version.AppVersion` (`VersionParams.app_version`, field 1) is -removed. This schema only marks the field DEPRECATED so that generated bindings and -current code still build; reserving field 1 and its name lands with the -implementation. The legacy `HashedParams` never included it, so no historical or -LEGACY hash changes, and the removal needs no activation height. Citations below -describe this base. - -1. **Block header.** `ResponsePrepareProposal.app_version` MUST be non-zero and is - the only source of `Header.Version.App`. `ResponsePrepareProposal.Validate` +removed. The legacy `HashedParams` never included it, so no historical or LEGACY +hash changes, and the removal needs no activation height. + +This change implements the following: + +1. **Schema.** Field 1 and the name `app_version` are reserved in `VersionParams`; + `types.VersionParams.AppVersion` and its conversions are removed. +2. **Block header.** `ResponsePrepareProposal.app_version` is the only source of + `Header.Version.App` and MUST be non-zero. `ResponsePrepareProposal.Validate` already rejects zero ([`abci/types/types.go:275`](../../abci/types/types.go), - called at [`internal/state/execution.go:301`](../../internal/state/execution.go)); - the proposer cannot produce a proposal without it, and the `ver > 0` guard at - `execution.go:324` becomes an unconditional assignment. The value enters + called at [`internal/state/execution.go:301`](../../internal/state/execution.go)), + so the proposer cannot produce a proposal without it. The value enters `StateID.AppVersion` ([`types/block.go:553`](../../types/block.go)) and is signed. Tenderdash does not check `Version.App` on non-proposers ([`internal/state/validation.go:33`](../../internal/state/validation.go)); the application MUST verify it in ProcessProposal. -2. **Node state.** `State.Version.Consensus.App` is removed with its writers: - parameters at commit - ([`internal/state/current_round_state.go:100`](../../internal/state/current_round_state.go)), +3. **Committed state.** `State.Update` sets `State.Version.Consensus.App` from the + committed header's `Version.App` + ([`internal/state/execution.go:795`](../../internal/state/execution.go)), not + from parameters. InitChain keeps the value that the handshake took from `ResponseInfo` at height 0 - ([`internal/consensus/replay.go:273`](../../internal/consensus/replay.go)) and - previous parameters on rollback + ([`internal/consensus/replay.go:273`](../../internal/consensus/replay.go)). + Rollback takes it from the header of the block rolled back to ([`internal/state/rollback.go:78`](../../internal/state/rollback.go)). - `State.MakeBlock` does not seed the header's app version from state - ([`internal/state/state.go:291`](../../internal/state/state.go)), so - `RequestPrepareProposal.version` carries only the block version; Tenderdash - leaves `app` unset, and that field's comment changes with the implementation. - The shared `tendermint.version.Consensus` message keeps `app` because - `Header.Version` uses it. -3. **Node info.** `NodeInfo.ProtocolVersion.App` is taken from +4. **Example applications.** The kvstore example and the e2e application do not + send the field in parameter updates. +5. **Compatibility.** Protobuf decoding ignores field 1 sent by older applications + in `InitChain`, `PrepareProposal` or `FinalizeBlock` parameter updates. Genesis + JSON containing `consensus_params.version.app_version` still loads, because + [`types/genesis.go`](../../types/genesis.go) decodes with lenient + `json.Unmarshal`; the key is not written back. Generated ABCI clients drop the + field, which requires a coordinated application release. + +The following remain for the implementation: + +1. **Node state.** Remove `State.Version.Consensus.App`, its height-0 write from + `ResponseInfo` and its use in `State.MakeBlock` + ([`internal/state/state.go:291`](../../internal/state/state.go)). Then + `RequestPrepareProposal.version` carries only the block version and that field's + comment changes. The `ver > 0` guard at `execution.go:324` becomes an + unconditional assignment. The shared `tendermint.version.Consensus` message + keeps `app` because `Header.Version` uses it. +2. **Node info.** Take `NodeInfo.ProtocolVersion.App` from `ResponseInfo.app_version`, which the handshake already returns ([`internal/consensus/replay.go:287`](../../internal/consensus/replay.go), [`node/node.go:514`](../../node/node.go)), instead of from state @@ -290,20 +318,14 @@ describe this base. [`node/setup.go:447`](../../node/setup.go) for seeds, which have no application and report 0). Peer compatibility checks only the block version ([`types/node_info.go:148`](../../types/node_info.go)). -4. **State sync.** `verifyApp` +3. **State sync.** `verifyApp` ([`internal/statesync/syncer.go:697`](../../internal/statesync/syncer.go)) MUST require `ResponseInfo.app_version >= Header.Version.App` of the trusted snapshot - header instead of equality; the header value is today reached through the state + header instead of equality; the header value is reached through the state provider's `State.Version` - ([`internal/statesync/stateprovider.go:176`](../../internal/statesync/stateprovider.go)). + ([`internal/statesync/stateprovider.go:177`](../../internal/statesync/stateprovider.go)). Applications may report their latest supported protocol version in Info, as Dash Platform does. -5. **Compatibility.** Protobuf decoding ignores field 1 sent by older applications - in `InitChain`, `PrepareProposal` or `FinalizeBlock` parameter updates. Genesis - JSON containing `consensus_params.version.app_version` still loads, because - [`types/genesis.go`](../../types/genesis.go) decodes with lenient - `json.Unmarshal`. Once field 1 is reserved, generated ABCI clients drop it, - which requires a coordinated application release. ## Integration and implementation sequence @@ -317,7 +339,7 @@ describe this base. mapping/schema and vectors before freezing it. Preserve any merged legacy hash variant for replay. The 15-field draft above MUST NOT activate while that coverage is stale. -2. Implement the version range check, the no-downgrade check, conversions, +2. Implement the version range check, the never-decrease check, conversions, defaults and equality in `types/params.go` and ABCI/state messages, and map version 2 in `NewProposerSelector`. `Equals` currently omits voting-threshold presence/value; include it to avoid incorrect empty/no-op shortcuts. @@ -341,11 +363,11 @@ describe this base. | Area | Required tests | | --- | --- | | Coverage | Mutate every mapped scalar and each list element/order; test nil, present zero and positive threshold separately. Every effective change changes the full hash. | -| Updates | Different patches reaching the same state hash equally; omitted groups/durations retain values only after activation; invalid values, unknown consensus versions, unsupported fields and decreases below 2, including a present version group with 0, fail closed. | +| Updates | Different patches reaching the same state hash equally; omitted groups/durations retain values only after activation; invalid values, unknown consensus versions, unsupported fields and any consensus-version decrease, including a present version group with 0, fail closed. | | Transition | Complete H-1 proposal accepted, incomplete transition rejected; current/next hashes at H-2/H-1/H agree across proposer, validators, stored state and RPC. Old positive live threshold to FULL with no override clears the derived threshold even with unchanged members. Complete genesis at consensus version 2 works. | | Encoding | Cross-language bytes and hashes for valid complete snapshots, zero-value omission, threshold presence, `max_gas = -1`, list order, UTF-8 and duration boundaries; reject duplicate/unknown fields and nonminimal encodings. | | Authentication | Substitute each previously unhashed field in RPC/P2P responses; correlate response height and signed header; require per-height thresholds when validator sets cross an update. | -| Application version | Proposal with zero `app_version` rejected; header app version always equals the proposer response; legacy hashes unchanged; field 1 from an old application and in genesis JSON ignored; state sync accepts Info above the header version and rejects below. | +| Application version | Proposal with zero `app_version` rejected; committed and rolled-back state follow the header app version; legacy hashes unchanged; field 1 from an old application and in genesis JSON ignored; state sync accepts Info above the header version and rejects below. | | Recovery | Replay and restart before/at/after H; historical signature/block-ID vectors unchanged; persisted consensus version and optional threshold survive round trips. | | Quorum and policy | Retain Core-backed membership/key binding and all legacy trust defenses; authenticate FULL mutable thresholds without genesis pinning; do not claim raised-threshold signer-count attestation. | From e68e80d6ab3977986816c25fb1173d6141c392a5 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Fri, 6 Nov 2026 16:00:11 +0000 Subject: [PATCH 08/12] docs(spec): describe the impact of forged consensus parameters State-synced nodes take every consensus parameter except block size, gas, consensus version and the pinned voting threshold on trust. List per-parameter effects of forged values, why they persist and go undetected, and how the full commitment closes the gap. Co-Authored-By: Claude Opus 5.5 --- spec/consensus/consensus-params-commitment.md | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/spec/consensus/consensus-params-commitment.md b/spec/consensus/consensus-params-commitment.md index 8e963a942d..496f46f660 100644 --- a/spec/consensus/consensus-params-commitment.md +++ b/spec/consensus/consensus-params-commitment.md @@ -51,6 +51,42 @@ A threshold BLS signature proves recovery under the quorum key. It does not prov that a raised application voting-power threshold was met by enough distinct signers. Adding signer-count attestation for that separate issue is out of scope. +## Impact of forged parameters today + +A node bootstrapped by state sync takes `ConsensusParams` from its state +provider: the configured primary RPC server +([`internal/statesync/stateprovider.go:207`](../../internal/statesync/stateprovider.go)) +or, with P2P state sync, its peers (`stateprovider.go:355`). +`verifyConsensusParams` (`stateprovider.go:509`) checks only `Block.MaxBytes`, +`Block.MaxGas` and `Version.ConsensusVersion` against the signed `ConsensusHash`, +and pins `Validator.VotingPowerThreshold` to the locally trusted genesis/InitChain +value (`stateprovider.go:522`, +[`internal/statesync/reactor.go:280`](../../internal/statesync/reactor.go)). +Every other value is taken on trust. + +| Parameter | Forged lower or narrower | Forged higher or wider | +| --- | --- | --- | +| `evidence.max_age_*` (both) | Rejects valid evidence ([`internal/evidence/verify.go:53`](../../internal/evidence/verify.go)); halts on a committed block containing it. | Accepts expired evidence; its own proposals carrying it are rejected. | +| `evidence.max_bytes` | Rejects blocks with more evidence ([`internal/state/validation.go:129`](../../internal/state/validation.go)); halts on such a committed block. | Its proposals with more evidence are rejected. | +| `validator.pub_key_types` | Rejects valid validator updates (`validation.go:245`); halts at the next rotation. | Accepts key types honest nodes reject; it cannot commit alone, so this matters only if validators share the forged view. | +| `validator.voting_power_threshold` | Not forgeable at bootstrap: a mismatch with the pinned value fails state sync. | Same. | +| `synchrony.*` | Treats timely proposals as too early or late and prevotes nil ([`internal/consensus/state_data.go:361`](../../internal/consensus/state_data.go)). | Accepts untimely proposals. | +| `timeout.*` | Leaves rounds early and casts more nil votes (`state_data.go:636`, `:651`); local unsafe overrides take precedence. | Slower rounds; affects its own liveness. | +| `abci.recheck_tx` | Invalid transactions linger in the mempool and in its proposals ([`internal/state/execution.go:766`](../../internal/state/execution.go)). | Needless `CheckTx` load. | + +Halting is the common outcome and survives restarts: the forged values are +stored, and later partial updates replace only the groups they carry +([`types/params.go:408`](../../types/params.go)). Recovery requires wiping the +node and re-syncing from a trusted source. Divergence is the worse case: a node +serving clients answers from a different parameter view. A validator with forged +parameters reduces liveness in proportion to its voting power. Nothing detects +the forgery today, because the full-node `ConsensusHash` check +([`internal/state/validation.go:66`](../../internal/state/validation.go)) also +covers only three fields. A network-wide safety impact requires many nodes or validators +to sync from the same malicious source, such as a widely used public RPC +endpoint. With the full commitment, state sync rejects forged parameters at +bootstrap. + ## Consensus version selects the hash rule `VersionParams.consensus_version` selects the hash rule of the parameter set that From b88ec6ac3c786eb52fe1d8828968e91ff07ed489 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Fri, 6 Nov 2026 16:01:09 +0000 Subject: [PATCH 09/12] docs(spec): note minority polkas under a low voting-power threshold Precommit finalization needs the DKG recovery threshold, but prevote polkas use the configurable threshold, so a low threshold lets a minority unlock honest validators across rounds. Record why the state-sync pin must not be dropped before the full commitment. Co-Authored-By: Claude Opus 5.5 --- spec/consensus/consensus-params-commitment.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/spec/consensus/consensus-params-commitment.md b/spec/consensus/consensus-params-commitment.md index 496f46f660..e1ac362ba9 100644 --- a/spec/consensus/consensus-params-commitment.md +++ b/spec/consensus/consensus-params-commitment.md @@ -69,11 +69,27 @@ Every other value is taken on trust. | `evidence.max_age_*` (both) | Rejects valid evidence ([`internal/evidence/verify.go:53`](../../internal/evidence/verify.go)); halts on a committed block containing it. | Accepts expired evidence; its own proposals carrying it are rejected. | | `evidence.max_bytes` | Rejects blocks with more evidence ([`internal/state/validation.go:129`](../../internal/state/validation.go)); halts on such a committed block. | Its proposals with more evidence are rejected. | | `validator.pub_key_types` | Rejects valid validator updates (`validation.go:245`); halts at the next rotation. | Accepts key types honest nodes reject; it cannot commit alone, so this matters only if validators share the forged view. | -| `validator.voting_power_threshold` | Not forgeable at bootstrap: a mismatch with the pinned value fails state sync. | Same. | +| `validator.voting_power_threshold` | Not forgeable at bootstrap: a mismatch with the pinned value fails state sync. If it were, the node would unlock on minority polkas (below). | Not forgeable at bootstrap; if it were, it would refuse valid polkas and commits (`vote_set.go:427`) and halt. | | `synchrony.*` | Treats timely proposals as too early or late and prevotes nil ([`internal/consensus/state_data.go:361`](../../internal/consensus/state_data.go)). | Accepts untimely proposals. | | `timeout.*` | Leaves rounds early and casts more nil votes (`state_data.go:636`, `:651`); local unsafe overrides take precedence. | Slower rounds; affects its own liveness. | | `abci.recheck_tx` | Invalid transactions linger in the mempool and in its proposals ([`internal/state/execution.go:766`](../../internal/state/execution.go)). | Needless `CheckTx` load. | +A lowered voting-power threshold cannot finalize a commit on its own: precommit +finalization recovers a BLS threshold signature, which needs the DKG threshold +`QuorumTypeThresholdVotingPower` +([`types/vote_set.go:418`](../../types/vote_set.go), `:437`; +[`types/validator_set.go:608`](../../types/validator_set.go)). Prevote +2/3, the +polka behind POL, uses the configurable `QuorumVotingThresholdPower` +(`vote_set.go:411`, `validator_set.go:585`) with no signature recovery. A low +threshold therefore lets a small minority create polkas that unlock honest +validators across rounds +([`internal/consensus/state_prevoter.go:147`](../../internal/consensus/state_prevoter.go)), +so the classic cross-round fork no longer needs at least 1/3 Byzantine power. +This applies to any threshold below the strict 2/3+1 floor. The state-sync pin +blocks forging one into a validator today; dropping the pin without the full +commitment would let a forged low threshold make that validator unlock on +minority polkas. + Halting is the common outcome and survives restarts: the forged values are stored, and later partial updates replace only the groups they carry ([`types/params.go:408`](../../types/params.go)). Recovery requires wiping the From c832d43679495f18a6d272c313adb5f48df4d8b1 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Fri, 6 Nov 2026 16:01:42 +0000 Subject: [PATCH 10/12] docs(spec): frame low voting-power threshold as a configuration risk Point to the #1052 override that permits thresholds below 2/3 through genesis or consensus_param_updates, and state that state sync cannot forge the threshold because it is pinned to the trusted local value. Co-Authored-By: Claude Opus 5.5 --- spec/consensus/consensus-params-commitment.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/consensus/consensus-params-commitment.md b/spec/consensus/consensus-params-commitment.md index e1ac362ba9..e50b636aca 100644 --- a/spec/consensus/consensus-params-commitment.md +++ b/spec/consensus/consensus-params-commitment.md @@ -85,10 +85,12 @@ threshold therefore lets a small minority create polkas that unlock honest validators across rounds ([`internal/consensus/state_prevoter.go:147`](../../internal/consensus/state_prevoter.go)), so the classic cross-round fork no longer needs at least 1/3 Byzantine power. -This applies to any threshold below the strict 2/3+1 floor. The state-sync pin -blocks forging one into a validator today; dropping the pin without the full -commitment would let a forged low threshold make that validator unlock on -minority polkas. +This applies to any threshold below the strict 2/3+1 floor, which the override +from [#1052](https://github.com/dashpay/tenderdash/pull/1052) permits through +genesis or `consensus_param_updates`. It is a configuration risk, not a +bootstrap-forgery one: state sync pins the threshold to the trusted local value. +Dropping that pin without the full commitment would let a forged low threshold +make a state-synced validator unlock on minority polkas. Halting is the common outcome and survives restarts: the forged values are stored, and later partial updates replace only the groups they carry From b0c4b8a74b0518cc657c530abb0646830e5f9d2d Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Fri, 6 Nov 2026 16:29:51 +0000 Subject: [PATCH 11/12] test: cover app version at InitChain and legacy params decoding Check that the handshake keeps the application version from ResponseInfo when InitChain returns a version parameter group, and that ConsensusParams encoded with VersionParams field 1 still decode with the field dropped. Co-Authored-By: Claude Opus 5.5 --- internal/consensus/replay_test.go | 53 +++++++++++++++++++++++++++++++ types/params_test.go | 20 ++++++++++++ 2 files changed, 73 insertions(+) diff --git a/internal/consensus/replay_test.go b/internal/consensus/replay_test.go index b75d8923aa..e2f8f0da09 100644 --- a/internal/consensus/replay_test.go +++ b/internal/consensus/replay_test.go @@ -1398,6 +1398,52 @@ func TestHandshakeInitialCoreLockHeight(t *testing.T) { assert.Equal(t, InitialCoreHeight, state.LastCoreChainLockedBlockHeight) } +// The application version recorded at height 0 comes from ResponseInfo. InitChain +// carries none, so processing its response must not reset it, even when the +// application returns a version parameter group. +func TestHandshakeInitChainKeepsInfoAppVersion(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + const infoAppVersion uint64 = 7 + logger := log.NewNopLogger() + conf, err := ResetConfig(t, "handshake_test_init_chain_app_version") + require.NoError(t, err) + + privVal, err := privval.LoadFilePV(conf.PrivValidator.KeyFile(), conf.PrivValidator.StateFile()) + require.NoError(t, err) + + eventBus := eventbus.NewDefault(logger) + require.NoError(t, eventBus.Start(ctx)) + + app := &initChainApp{ + infoAppVersion: infoAppVersion, + consensusParams: &tmproto.ConsensusParams{ + Version: &tmproto.VersionParams{ConsensusVersion: tmproto.VersionParams_CONSENSUS_VERSION_1}, + }, + } + client := abciclient.NewLocalClient(logger, app) + + proTxHash, err := privVal.GetProTxHash(ctx) + require.NoError(t, err) + stateDB, state, store := stateAndStore(t, conf, 0x0) + stateStore := sm.NewStore(stateDB) + proxyApp := proxy.New(client, logger, proxy.NopMetrics()) + require.NoError(t, proxyApp.Start(ctx), "Error starting proxy app connections") + + genDoc, _ := sm.MakeGenesisDocFromFile(conf.GenesisFile()) + replayer := newBlockReplayer(stateStore, store, genDoc, eventBus, proxyApp, proTxHash) + handshaker := NewHandshaker(replayer, logger, state) + + _, err = handshaker.Handshake(ctx, proxyApp) + require.NoError(t, err, "error on abci handshake") + + state, err = stateStore.Load() + require.NoError(t, err) + assert.Equal(t, infoAppVersion, state.Version.Consensus.App) + assert.EqualValues(t, tmproto.VersionParams_CONSENSUS_VERSION_1, state.ConsensusParams.Version.ConsensusVersion) +} + // walRoundsSkipperProposeTimeout replaces the test genesis' 30ms propose // timeout on the node that generates the WAL for testWALRoundsSkipper. That // node is the only validator, so it proposes every round and its propose @@ -1546,11 +1592,18 @@ type initChainApp struct { abci.BaseApplication vals *abci.ValidatorSetUpdate initialCoreHeight uint32 + infoAppVersion uint64 + consensusParams *tmproto.ConsensusParams +} + +func (ica *initChainApp) Info(_ context.Context, _req *abci.RequestInfo) (*abci.ResponseInfo, error) { + return &abci.ResponseInfo{AppVersion: ica.infoAppVersion}, nil } func (ica *initChainApp) InitChain(_ context.Context, _req *abci.RequestInitChain) (*abci.ResponseInitChain, error) { resp := abci.ResponseInitChain{ InitialCoreHeight: ica.initialCoreHeight, + ConsensusParams: ica.consensusParams, } if ica.vals != nil { resp.ValidatorSetUpdate = *ica.vals diff --git a/types/params_test.go b/types/params_test.go index edbd627cf2..c866740182 100644 --- a/types/params_test.go +++ b/types/params_test.go @@ -7,6 +7,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" tmproto "github.com/dashpay/tenderdash/proto/tendermint/types" ) @@ -385,6 +386,25 @@ func TestConsensusParamsUpdate(t *testing.T) { } } +// Consensus parameters encoded while VersionParams carried app_version (field 1), +// in stored state or ABCI messages, must still decode; the field is dropped. +func TestConsensusParamsDecodeIgnoresRemovedAppVersion(t *testing.T) { + // ConsensusParams{version (4): VersionParams{app_version (1): 5, consensus_version (2): 1}} + legacy := []byte{0x22, 0x04, 0x08, 0x05, 0x10, 0x01} + + var pb tmproto.ConsensusParams + require.NoError(t, pb.Unmarshal(legacy)) + require.NotNil(t, pb.Version) + assert.Equal(t, tmproto.VersionParams_CONSENSUS_VERSION_1, pb.Version.ConsensusVersion) + + reencoded, err := pb.Marshal() + require.NoError(t, err) + assert.Equal(t, []byte{0x22, 0x02, 0x10, 0x01}, reencoded, "field 1 must not survive re-encoding") + + params := ConsensusParamsFromProto(pb) + assert.EqualValues(t, 1, params.Version.ConsensusVersion) +} + func TestConsensusParamsUpdate_Version(t *testing.T) { params := makeParams(makeParamsArgs{blockBytes: 1, blockGas: 2, evidenceAge: 3}) From f3a81c2d359fc125e33ac527b77cac3e72e68562 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Fri, 6 Nov 2026 16:29:51 +0000 Subject: [PATCH 12/12] docs(spec): require applications to choose their initial protocol version InitChain carries no application version and Tenderdash adds no replacement, so the application determines its initial protocol version itself. Record the Dash Platform dependency and the required order of upgrades, and stop documenting app_version as a genesis consensus parameter. Co-Authored-By: Claude Opus 5.5 --- spec/abci/methods.md | 3 +++ spec/consensus/consensus-params-commitment.md | 25 +++++++++++++++---- spec/core/data_structures.md | 5 +++- spec/core/genesis.md | 2 +- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/spec/abci/methods.md b/spec/abci/methods.md index c799833162..d456de2ca9 100644 --- a/spec/abci/methods.md +++ b/spec/abci/methods.md @@ -92,6 +92,9 @@ that happens on startup. * **Usage**: * Called once upon genesis. +* `consensus_params` carries no application version. The application determines + its initial protocol version itself, for example per network or from its own + configuration. * If `ResponseInitChain.validator_set_update.validator_updates` is empty, genesis validator membership is retained; quorum-key and quorum-hash updates can still be supplied in `validator_set_update`. diff --git a/spec/consensus/consensus-params-commitment.md b/spec/consensus/consensus-params-commitment.md index e50b636aca..3b29412565 100644 --- a/spec/consensus/consensus-params-commitment.md +++ b/spec/consensus/consensus-params-commitment.md @@ -348,12 +348,27 @@ This change implements the following: ([`internal/state/rollback.go:78`](../../internal/state/rollback.go)). 4. **Example applications.** The kvstore example and the e2e application do not send the field in parameter updates. -5. **Compatibility.** Protobuf decoding ignores field 1 sent by older applications - in `InitChain`, `PrepareProposal` or `FinalizeBlock` parameter updates. Genesis - JSON containing `consensus_params.version.app_version` still loads, because +5. **InitChain.** `RequestInitChain.consensus_params` carries no application + version, and Tenderdash provides no replacement channel. The application MUST + determine its initial protocol version itself, for example per network or from + its own configuration. +6. **Compatibility.** Protobuf decoding ignores field 1 sent by older applications + in `InitChain`, `PrepareProposal` or `FinalizeBlock` parameter updates, and in + stored parameters. Genesis JSON containing + `consensus_params.version.app_version` still loads, because [`types/genesis.go`](../../types/genesis.go) decodes with lenient - `json.Unmarshal`; the key is not written back. Generated ABCI clients drop the - field, which requires a coordinated application release. + `json.Unmarshal`, but the value is ignored and not passed to InitChain or + written back. Generated ABCI clients drop the field, which requires a + coordinated application release. + +**Breaking for Dash Platform.** Platform selects its starting `PlatformVersion` +from `RequestInitChain.consensus_params.version.app_version`, the genesis value +`1` on mainnet and testnet, and falls back to its desired version when the value +is 0 +([`rs-drive-abci` `init_chain`](https://github.com/dashpay/platform/blob/de80f86d80ffcfa0a91ae59ce43cfeb161e27bc5/packages/rs-drive-abci/src/execution/engine/initialization/init_chain/mod.rs#L27-L52)). +Platform MUST determine its initial protocol version itself before it upgrades to +a Tenderdash without this field. Otherwise a node syncing from genesis starts at +the wrong protocol version and halts on an app-hash mismatch. The following remain for the implementation: diff --git a/spec/core/data_structures.md b/spec/core/data_structures.md index 3a996016d2..c788e218a4 100644 --- a/spec/core/data_structures.md +++ b/spec/core/data_structures.md @@ -389,9 +389,12 @@ parameter is absent from a particular header-hash subset. | Name | Type | Description | Field Number | |-------------|--------|-------------------------------|--------------| -| app_version | uint64 | The ABCI application version. | 1 | | consensus_version | `ConsensusVersion` | Version of the consensus protocol, selecting the [proposer strategy](../consensus/proposer-selection.md). | 2 | +Field 1 (`app_version`) is reserved. The application version is not a consensus +parameter; see +[application version](../consensus/consensus-params-commitment.md#application-version-is-not-a-consensus-parameter). + ### SynchronyParams | Name | Type | Description | Field Number | diff --git a/spec/core/genesis.md b/spec/core/genesis.md index 250f608d8e..1136679b9b 100644 --- a/spec/core/genesis.md +++ b/spec/core/genesis.md @@ -18,7 +18,7 @@ The genesis file is the starting point of a chain. An application will populate - `validator` - `pub_key_types`: Lists the validator consensus key types allowed by the chain. Recognized values are `ed25519`, `secp256k1`, and `bls12381`; the default allows only `bls12381` (BLS12-381). - `version` - - `app_version`: The version of the application. This is set by the application and is used to identify which version of the app a user should be using in order to operate a node. + - `consensus`: The consensus protocol version (`VersionParams.consensus_version`). Consensus parameters carry no application version; a legacy `app_version` key still loads but is ignored. - `synchrony` - `message_delay`: A bound on how long a proposal message may take to reach all validators on a network and still be considered valid. - `precision`: A bound on how skewed the proposer's clock may be from any validator on the network while still producing valid proposals.