From 0a88c29a8026ae8e8ac7edb2613829adf2be6678 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 8 Feb 2021 16:44:55 -0600 Subject: [PATCH 01/46] adjust KVStores to fit new CacheWrapper interface --- store/cachekv/store.go | 2 ++ store/dbadapter/store.go | 2 ++ store/iavl/store.go | 2 ++ store/mem/store.go | 2 ++ store/prefix/store.go | 2 ++ 5 files changed, 10 insertions(+) diff --git a/store/cachekv/store.go b/store/cachekv/store.go index 48c59d8da8d3..210c1df67e40 100644 --- a/store/cachekv/store.go +++ b/store/cachekv/store.go @@ -7,6 +7,8 @@ import ( "sync" "time" + "github.com/cosmos/cosmos-sdk/store/listenkv" + dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/internal/conv" diff --git a/store/dbadapter/store.go b/store/dbadapter/store.go index 2f0ceb5df54a..9614be52c9e3 100644 --- a/store/dbadapter/store.go +++ b/store/dbadapter/store.go @@ -3,6 +3,8 @@ package dbadapter import ( "io" + "github.com/cosmos/cosmos-sdk/store/listenkv" + dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/cachekv" diff --git a/store/iavl/store.go b/store/iavl/store.go index 440b26754de5..8ba3c369739a 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -7,6 +7,8 @@ import ( "sync" "time" + "github.com/cosmos/cosmos-sdk/store/listenkv" + ics23 "github.com/confio/ics23/go" "github.com/cosmos/iavl" abci "github.com/tendermint/tendermint/abci/types" diff --git a/store/mem/store.go b/store/mem/store.go index c8aa6dca5997..6137a8ca3700 100644 --- a/store/mem/store.go +++ b/store/mem/store.go @@ -3,6 +3,8 @@ package mem import ( "io" + "github.com/cosmos/cosmos-sdk/store/listenkv" + dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/cachekv" diff --git a/store/prefix/store.go b/store/prefix/store.go index 295278a0a853..e7f85cbc6f8b 100644 --- a/store/prefix/store.go +++ b/store/prefix/store.go @@ -5,6 +5,8 @@ import ( "errors" "io" + "github.com/cosmos/cosmos-sdk/store/listenkv" + "github.com/cosmos/cosmos-sdk/store/cachekv" "github.com/cosmos/cosmos-sdk/store/listenkv" "github.com/cosmos/cosmos-sdk/store/tracekv" From 875f23e536c586cefec8e7ee5fa40476e4760ddf Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 8 Feb 2021 16:46:08 -0600 Subject: [PATCH 02/46] adjust multistores to fit new MultiStore interface and enable wrapping returned KVStores with the new ListenKVStore --- store/cachemulti/store.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/store/cachemulti/store.go b/store/cachemulti/store.go index 05637a45ff16..6f1b215775c5 100644 --- a/store/cachemulti/store.go +++ b/store/cachemulti/store.go @@ -60,6 +60,9 @@ func NewFromKVStore( } else { cms.stores[key] = cacheWrapped } + if cms.ListeningEnabled(key) { + cacheWrapped = cacheWrapped.CacheWrapWithListeners(key, cms.listeners[key]) + } } return cms From 5e02e3daf68ee3484bc81e962d175c36d8de90bb Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 9 Feb 2021 12:59:55 -0600 Subject: [PATCH 03/46] update server mock KVStore and MultiStore --- server/mock/store.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server/mock/store.go b/server/mock/store.go index 33f573518c19..47421e9229d7 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -35,6 +35,10 @@ func (ms multiStore) CacheWrapWithListeners(_ store.StoreKey, _ []store.WriteLis panic("not implemented") } +func (ms multiStore) CacheWrapWithListeners(_ store.StoreKey, _ []store.WriteListener) store.CacheWrap { + panic("not implemented") +} + func (ms multiStore) TracingEnabled() bool { panic("not implemented") } @@ -55,6 +59,14 @@ func (ms multiStore) ListeningEnabled(key store.StoreKey) bool { panic("not implemented") } +func (ms multiStore) SetListeners(key store.StoreKey, listeners []store.WriteListener) { + panic("not implemented") +} + +func (ms multiStore) ListeningEnabled(key store.StoreKey) bool { + panic("not implemented") +} + func (ms multiStore) Commit() sdk.CommitID { panic("not implemented") } @@ -147,6 +159,10 @@ func (kv kvStore) CacheWrapWithListeners(_ store.StoreKey, _ []store.WriteListen panic("not implemented") } +func (kv kvStore) CacheWrapWithListeners(_ store.StoreKey, _ []store.WriteListener) store.CacheWrap { + panic("not implemented") +} + func (kv kvStore) GetStoreType() sdk.StoreType { panic("not implemented") } From c394e5dc6b040348edb9c5a3bf69ac312db3ffc5 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 9 Feb 2021 15:27:42 -0600 Subject: [PATCH 04/46] fix bug identified in CI --- store/cachemulti/store.go | 3 --- store/rootmulti/store.go | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/store/cachemulti/store.go b/store/cachemulti/store.go index 6f1b215775c5..05637a45ff16 100644 --- a/store/cachemulti/store.go +++ b/store/cachemulti/store.go @@ -60,9 +60,6 @@ func NewFromKVStore( } else { cms.stores[key] = cacheWrapped } - if cms.ListeningEnabled(key) { - cacheWrapped = cacheWrapped.CacheWrapWithListeners(key, cms.listeners[key]) - } } return cms diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 471a24efe2cc..de742fff10cc 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -52,6 +52,7 @@ type Store struct { stores map[types.StoreKey]types.CommitKVStore keysByName map[string]types.StoreKey lazyLoading bool + cacheListening bool pruneHeights []int64 initialVersion int64 From c92556af16065e073ef1bab315e6818a68a117de Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Wed, 10 Feb 2021 14:32:03 -0600 Subject: [PATCH 05/46] improve codecov, minor fixes/adjustments --- store/rootmulti/store.go | 1 - 1 file changed, 1 deletion(-) diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index de742fff10cc..471a24efe2cc 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -52,7 +52,6 @@ type Store struct { stores map[types.StoreKey]types.CommitKVStore keysByName map[string]types.StoreKey lazyLoading bool - cacheListening bool pruneHeights []int64 initialVersion int64 From 18bf622fd3916cecc141a1bbdd9d0b393718a0d7 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Wed, 24 Feb 2021 15:28:31 -0600 Subject: [PATCH 06/46] review fixes --- docs/architecture/adr-038-state-listening.md | 2 +- server/mock/store.go | 16 ---------------- store/cachekv/store.go | 2 -- store/dbadapter/store.go | 2 -- store/iavl/store.go | 2 -- store/mem/store.go | 2 -- store/prefix/store.go | 2 -- 7 files changed, 1 insertion(+), 27 deletions(-) diff --git a/docs/architecture/adr-038-state-listening.md b/docs/architecture/adr-038-state-listening.md index 9bc644dddb26..7c925b73cdbe 100644 --- a/docs/architecture/adr-038-state-listening.md +++ b/docs/architecture/adr-038-state-listening.md @@ -32,7 +32,7 @@ In a new file, `store/types/listening.go`, we will create a `WriteListener` inte type WriteListener interface { // if value is nil then it was deleted // storeKey indicates the source KVStore, to facilitate using the the same WriteListener across separate KVStores - // set bool indicates if it was a set; true: set, false: delete + // delete bool indicates if it was a delete; true: delete, false: set OnWrite(storeKey StoreKey, key []byte, value []byte, delete bool) error } ``` diff --git a/server/mock/store.go b/server/mock/store.go index 47421e9229d7..33f573518c19 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -35,10 +35,6 @@ func (ms multiStore) CacheWrapWithListeners(_ store.StoreKey, _ []store.WriteLis panic("not implemented") } -func (ms multiStore) CacheWrapWithListeners(_ store.StoreKey, _ []store.WriteListener) store.CacheWrap { - panic("not implemented") -} - func (ms multiStore) TracingEnabled() bool { panic("not implemented") } @@ -59,14 +55,6 @@ func (ms multiStore) ListeningEnabled(key store.StoreKey) bool { panic("not implemented") } -func (ms multiStore) SetListeners(key store.StoreKey, listeners []store.WriteListener) { - panic("not implemented") -} - -func (ms multiStore) ListeningEnabled(key store.StoreKey) bool { - panic("not implemented") -} - func (ms multiStore) Commit() sdk.CommitID { panic("not implemented") } @@ -159,10 +147,6 @@ func (kv kvStore) CacheWrapWithListeners(_ store.StoreKey, _ []store.WriteListen panic("not implemented") } -func (kv kvStore) CacheWrapWithListeners(_ store.StoreKey, _ []store.WriteListener) store.CacheWrap { - panic("not implemented") -} - func (kv kvStore) GetStoreType() sdk.StoreType { panic("not implemented") } diff --git a/store/cachekv/store.go b/store/cachekv/store.go index 210c1df67e40..48c59d8da8d3 100644 --- a/store/cachekv/store.go +++ b/store/cachekv/store.go @@ -7,8 +7,6 @@ import ( "sync" "time" - "github.com/cosmos/cosmos-sdk/store/listenkv" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/internal/conv" diff --git a/store/dbadapter/store.go b/store/dbadapter/store.go index 9614be52c9e3..2f0ceb5df54a 100644 --- a/store/dbadapter/store.go +++ b/store/dbadapter/store.go @@ -3,8 +3,6 @@ package dbadapter import ( "io" - "github.com/cosmos/cosmos-sdk/store/listenkv" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/cachekv" diff --git a/store/iavl/store.go b/store/iavl/store.go index 8ba3c369739a..440b26754de5 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -7,8 +7,6 @@ import ( "sync" "time" - "github.com/cosmos/cosmos-sdk/store/listenkv" - ics23 "github.com/confio/ics23/go" "github.com/cosmos/iavl" abci "github.com/tendermint/tendermint/abci/types" diff --git a/store/mem/store.go b/store/mem/store.go index 6137a8ca3700..c8aa6dca5997 100644 --- a/store/mem/store.go +++ b/store/mem/store.go @@ -3,8 +3,6 @@ package mem import ( "io" - "github.com/cosmos/cosmos-sdk/store/listenkv" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/cachekv" diff --git a/store/prefix/store.go b/store/prefix/store.go index e7f85cbc6f8b..295278a0a853 100644 --- a/store/prefix/store.go +++ b/store/prefix/store.go @@ -5,8 +5,6 @@ import ( "errors" "io" - "github.com/cosmos/cosmos-sdk/store/listenkv" - "github.com/cosmos/cosmos-sdk/store/cachekv" "github.com/cosmos/cosmos-sdk/store/listenkv" "github.com/cosmos/cosmos-sdk/store/tracekv" From d92f1d0e437bdbf1a72971289047183f530d7aba Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Fri, 5 Mar 2021 11:49:24 -0600 Subject: [PATCH 07/46] review updates; flip set to delete in KVStorePair, updated proto-docs from running 'make proto-gen' --- docs/core/proto-docs.md | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 0794c8c0f86e..accafc1b37f1 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -82,7 +82,6 @@ - [Output](#cosmos.bank.v1beta1.Output) - [Params](#cosmos.bank.v1beta1.Params) - [SendEnabled](#cosmos.bank.v1beta1.SendEnabled) - - [Supply](#cosmos.bank.v1beta1.Supply) - [cosmos/bank/v1beta1/genesis.proto](#cosmos/bank/v1beta1/genesis.proto) - [Balance](#cosmos.bank.v1beta1.Balance) @@ -1623,23 +1622,6 @@ sendable). - - - -### Supply -Supply represents a struct that passively keeps track of the total supply -amounts in the network. -This message is deprecated now that supply is indexed by denom. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `total` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | | - - - - - From 72d6a886d1c8ced9c1179876d56faf596ac103f8 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 8 Feb 2021 16:44:55 -0600 Subject: [PATCH 08/46] adjust KVStores to fit new CacheWrapper interface --- store/cachekv/store.go | 2 ++ store/dbadapter/store.go | 2 ++ store/iavl/store.go | 2 ++ store/mem/store.go | 2 ++ store/prefix/store.go | 2 ++ 5 files changed, 10 insertions(+) diff --git a/store/cachekv/store.go b/store/cachekv/store.go index 48c59d8da8d3..210c1df67e40 100644 --- a/store/cachekv/store.go +++ b/store/cachekv/store.go @@ -7,6 +7,8 @@ import ( "sync" "time" + "github.com/cosmos/cosmos-sdk/store/listenkv" + dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/internal/conv" diff --git a/store/dbadapter/store.go b/store/dbadapter/store.go index 2f0ceb5df54a..9614be52c9e3 100644 --- a/store/dbadapter/store.go +++ b/store/dbadapter/store.go @@ -3,6 +3,8 @@ package dbadapter import ( "io" + "github.com/cosmos/cosmos-sdk/store/listenkv" + dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/cachekv" diff --git a/store/iavl/store.go b/store/iavl/store.go index 440b26754de5..8ba3c369739a 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -7,6 +7,8 @@ import ( "sync" "time" + "github.com/cosmos/cosmos-sdk/store/listenkv" + ics23 "github.com/confio/ics23/go" "github.com/cosmos/iavl" abci "github.com/tendermint/tendermint/abci/types" diff --git a/store/mem/store.go b/store/mem/store.go index c8aa6dca5997..6137a8ca3700 100644 --- a/store/mem/store.go +++ b/store/mem/store.go @@ -3,6 +3,8 @@ package mem import ( "io" + "github.com/cosmos/cosmos-sdk/store/listenkv" + dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/cachekv" diff --git a/store/prefix/store.go b/store/prefix/store.go index 295278a0a853..e7f85cbc6f8b 100644 --- a/store/prefix/store.go +++ b/store/prefix/store.go @@ -5,6 +5,8 @@ import ( "errors" "io" + "github.com/cosmos/cosmos-sdk/store/listenkv" + "github.com/cosmos/cosmos-sdk/store/cachekv" "github.com/cosmos/cosmos-sdk/store/listenkv" "github.com/cosmos/cosmos-sdk/store/tracekv" From 602867e34e2dcf81f09cca7076231115aacebf2a Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Wed, 24 Feb 2021 15:28:31 -0600 Subject: [PATCH 09/46] review fixes --- store/cachekv/store.go | 2 -- store/dbadapter/store.go | 2 -- store/iavl/store.go | 2 -- store/mem/store.go | 2 -- store/prefix/store.go | 2 -- 5 files changed, 10 deletions(-) diff --git a/store/cachekv/store.go b/store/cachekv/store.go index 210c1df67e40..48c59d8da8d3 100644 --- a/store/cachekv/store.go +++ b/store/cachekv/store.go @@ -7,8 +7,6 @@ import ( "sync" "time" - "github.com/cosmos/cosmos-sdk/store/listenkv" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/internal/conv" diff --git a/store/dbadapter/store.go b/store/dbadapter/store.go index 9614be52c9e3..2f0ceb5df54a 100644 --- a/store/dbadapter/store.go +++ b/store/dbadapter/store.go @@ -3,8 +3,6 @@ package dbadapter import ( "io" - "github.com/cosmos/cosmos-sdk/store/listenkv" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/cachekv" diff --git a/store/iavl/store.go b/store/iavl/store.go index 8ba3c369739a..440b26754de5 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -7,8 +7,6 @@ import ( "sync" "time" - "github.com/cosmos/cosmos-sdk/store/listenkv" - ics23 "github.com/confio/ics23/go" "github.com/cosmos/iavl" abci "github.com/tendermint/tendermint/abci/types" diff --git a/store/mem/store.go b/store/mem/store.go index 6137a8ca3700..c8aa6dca5997 100644 --- a/store/mem/store.go +++ b/store/mem/store.go @@ -3,8 +3,6 @@ package mem import ( "io" - "github.com/cosmos/cosmos-sdk/store/listenkv" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/cachekv" diff --git a/store/prefix/store.go b/store/prefix/store.go index e7f85cbc6f8b..295278a0a853 100644 --- a/store/prefix/store.go +++ b/store/prefix/store.go @@ -5,8 +5,6 @@ import ( "errors" "io" - "github.com/cosmos/cosmos-sdk/store/listenkv" - "github.com/cosmos/cosmos-sdk/store/cachekv" "github.com/cosmos/cosmos-sdk/store/listenkv" "github.com/cosmos/cosmos-sdk/store/tracekv" From 93dbea98b2b8f555e888f83e52ce6f6d0a12435c Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 8 Feb 2021 16:44:55 -0600 Subject: [PATCH 10/46] adjust KVStores to fit new CacheWrapper interface --- store/cachekv/store.go | 2 ++ store/dbadapter/store.go | 2 ++ store/iavl/store.go | 2 ++ store/mem/store.go | 2 ++ store/prefix/store.go | 2 ++ 5 files changed, 10 insertions(+) diff --git a/store/cachekv/store.go b/store/cachekv/store.go index 48c59d8da8d3..210c1df67e40 100644 --- a/store/cachekv/store.go +++ b/store/cachekv/store.go @@ -7,6 +7,8 @@ import ( "sync" "time" + "github.com/cosmos/cosmos-sdk/store/listenkv" + dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/internal/conv" diff --git a/store/dbadapter/store.go b/store/dbadapter/store.go index 2f0ceb5df54a..9614be52c9e3 100644 --- a/store/dbadapter/store.go +++ b/store/dbadapter/store.go @@ -3,6 +3,8 @@ package dbadapter import ( "io" + "github.com/cosmos/cosmos-sdk/store/listenkv" + dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/cachekv" diff --git a/store/iavl/store.go b/store/iavl/store.go index 440b26754de5..8ba3c369739a 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -7,6 +7,8 @@ import ( "sync" "time" + "github.com/cosmos/cosmos-sdk/store/listenkv" + ics23 "github.com/confio/ics23/go" "github.com/cosmos/iavl" abci "github.com/tendermint/tendermint/abci/types" diff --git a/store/mem/store.go b/store/mem/store.go index c8aa6dca5997..6137a8ca3700 100644 --- a/store/mem/store.go +++ b/store/mem/store.go @@ -3,6 +3,8 @@ package mem import ( "io" + "github.com/cosmos/cosmos-sdk/store/listenkv" + dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/cachekv" diff --git a/store/prefix/store.go b/store/prefix/store.go index 295278a0a853..e7f85cbc6f8b 100644 --- a/store/prefix/store.go +++ b/store/prefix/store.go @@ -5,6 +5,8 @@ import ( "errors" "io" + "github.com/cosmos/cosmos-sdk/store/listenkv" + "github.com/cosmos/cosmos-sdk/store/cachekv" "github.com/cosmos/cosmos-sdk/store/listenkv" "github.com/cosmos/cosmos-sdk/store/tracekv" From 441af0e44a2cd462a3591e5c6ed6e97dfe1ed890 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Wed, 24 Feb 2021 15:28:31 -0600 Subject: [PATCH 11/46] review fixes --- store/cachekv/store.go | 2 -- store/dbadapter/store.go | 2 -- store/iavl/store.go | 2 -- store/mem/store.go | 2 -- store/prefix/store.go | 2 -- 5 files changed, 10 deletions(-) diff --git a/store/cachekv/store.go b/store/cachekv/store.go index 210c1df67e40..48c59d8da8d3 100644 --- a/store/cachekv/store.go +++ b/store/cachekv/store.go @@ -7,8 +7,6 @@ import ( "sync" "time" - "github.com/cosmos/cosmos-sdk/store/listenkv" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/internal/conv" diff --git a/store/dbadapter/store.go b/store/dbadapter/store.go index 9614be52c9e3..2f0ceb5df54a 100644 --- a/store/dbadapter/store.go +++ b/store/dbadapter/store.go @@ -3,8 +3,6 @@ package dbadapter import ( "io" - "github.com/cosmos/cosmos-sdk/store/listenkv" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/cachekv" diff --git a/store/iavl/store.go b/store/iavl/store.go index 8ba3c369739a..440b26754de5 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -7,8 +7,6 @@ import ( "sync" "time" - "github.com/cosmos/cosmos-sdk/store/listenkv" - ics23 "github.com/confio/ics23/go" "github.com/cosmos/iavl" abci "github.com/tendermint/tendermint/abci/types" diff --git a/store/mem/store.go b/store/mem/store.go index 6137a8ca3700..c8aa6dca5997 100644 --- a/store/mem/store.go +++ b/store/mem/store.go @@ -3,8 +3,6 @@ package mem import ( "io" - "github.com/cosmos/cosmos-sdk/store/listenkv" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/cachekv" diff --git a/store/prefix/store.go b/store/prefix/store.go index e7f85cbc6f8b..295278a0a853 100644 --- a/store/prefix/store.go +++ b/store/prefix/store.go @@ -5,8 +5,6 @@ import ( "errors" "io" - "github.com/cosmos/cosmos-sdk/store/listenkv" - "github.com/cosmos/cosmos-sdk/store/cachekv" "github.com/cosmos/cosmos-sdk/store/listenkv" "github.com/cosmos/cosmos-sdk/store/tracekv" From f7ecbcb09430518e1779d0913bf0fa155337b47a Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 8 Feb 2021 17:01:43 -0600 Subject: [PATCH 12/46] hook and streaming service interfaces --- types/streaming.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 types/streaming.go diff --git a/types/streaming.go b/types/streaming.go new file mode 100644 index 000000000000..81af98e28ad1 --- /dev/null +++ b/types/streaming.go @@ -0,0 +1,29 @@ +package types + +import ( + "sync" + + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/store/types" +) + +// Hook interface used to hook into the ABCI message processing of the BaseApp +type Hook interface { + // update the streaming service with the latest BeginBlock messages + ListenBeginBlock(ctx Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) + // update the steaming service with the latest EndBlock messages + ListenEndBlock(ctx Context, req abci.RequestEndBlock, res abci.ResponseEndBlock) + // update the steaming service with the latest DeliverTx messages + ListenDeliverTx(ctx Context, req abci.RequestDeliverTx, res abci.ResponseDeliverTx) +} + +// StreamingService interface for registering WriteListeners with the BaseApp and updating the service with the ABCI messages using the hooks +type StreamingService interface { + // streaming service loop, awaits kv pairs and writes them to some destination stream or file + Stream(wg *sync.WaitGroup, quitChan <-chan struct{}) + // returns the streaming service's listeners for the BaseApp to register + Listeners() map[StoreKey][]types.WriteListener + // interface for hooking into the ABCI messages from inside the BaseApp + Hook +} From 5f74b6860ad2aa43d397d703183af6e4ab7754a3 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 8 Feb 2021 17:25:03 -0600 Subject: [PATCH 13/46] integrate Hooks and StreamingService into BaseApp --- baseapp/abci.go | 27 +++++++++++++++++++++++++-- baseapp/baseapp.go | 4 ++++ baseapp/options.go | 11 +++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 3464a5d43688..3592b6d92d20 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -195,6 +195,12 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg } // set the signed validators for addition to context in deliverTx app.voteInfos = req.LastCommitInfo.GetVotes() + + // call the hooks with the BeginBlock messages + for _, hook := range app.hooks { + hook.ListenBeginBlock(app.deliverState.ctx, req, res) + } + return res } @@ -215,6 +221,11 @@ func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBloc res.ConsensusParamUpdates = cp } + // call the streaming service hooks with the EndBlock messages + for _, hook := range app.hooks { + hook.ListenEndBlock(app.deliverState.ctx, req, res) + } + return res } @@ -275,16 +286,28 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx gInfo, result, err := app.runTx(runTxModeDeliver, req.Tx) if err != nil { resultStr = "failed" - return sdkerrors.ResponseDeliverTx(err, gInfo.GasWanted, gInfo.GasUsed, app.trace) + res := sdkerrors.ResponseDeliverTx(err, gInfo.GasWanted, gInfo.GasUsed, app.trace) + // if we throw and error, be sure to still call the streaming service's hook + for _, hook := range app.hooks { + hook.ListenDeliverTx(app.deliverState.ctx, req, res) + } + return res } - return abci.ResponseDeliverTx{ + res := abci.ResponseDeliverTx{ GasWanted: int64(gInfo.GasWanted), // TODO: Should type accept unsigned ints? GasUsed: int64(gInfo.GasUsed), // TODO: Should type accept unsigned ints? Log: result.Log, Data: result.Data, Events: sdk.MarkEventsToIndex(result.Events, app.indexEvents), } + + // call the streaming service hooks with the DeliverTx messages + for _, hook := range app.hooks { + hook.ListenDeliverTx(app.deliverState.ctx, req, res) + } + + return res } // Commit implements the ABCI interface. It will commit all state that exists in diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index ceb553dd7d62..11601aaf0da7 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -134,6 +134,10 @@ type BaseApp struct { // nolint: maligned // indexEvents defines the set of events in the form {eventType}.{attributeKey}, // which informs Tendermint what to index. If empty, all events will be indexed. indexEvents map[string]struct{} + + // hooked services + // these hooks will have the ABCI messages routed through them + hooks []sdk.Hook } // NewBaseApp returns a reference to an initialized BaseApp. It accepts a diff --git a/baseapp/options.go b/baseapp/options.go index be9fbdc659a0..04f32f7f69fd 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -237,3 +237,14 @@ func (app *BaseApp) SetInterfaceRegistry(registry types.InterfaceRegistry) { app.grpcQueryRouter.SetInterfaceRegistry(registry) app.msgServiceRouter.SetInterfaceRegistry(registry) } + +// SetHooks is used to set a streaming service into the BaseApp hooks +func (app *BaseApp) SetHooks(s sdk.StreamingService) { + // set the listeners for each StoreKey + for key, lis := range s.Listeners() { + app.cms.SetListeners(key, lis) + } + // register the streaming service hooks within the BaseApp + // BaseApp will pass BeginBlock, DeliverTx, and EndBlock requests and responses to the streaming services to update their ABCI context using these hooks + app.hooks = append(app.hooks, s) +} From d3c44a49aa9000718be0a0ea698bd9be46d1009d Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 8 Feb 2021 17:25:47 -0600 Subject: [PATCH 14/46] begin file streaming service implementation --- streaming/file/service.go | 131 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 streaming/file/service.go diff --git a/streaming/file/service.go b/streaming/file/service.go new file mode 100644 index 000000000000..e9de7c14002b --- /dev/null +++ b/streaming/file/service.go @@ -0,0 +1,131 @@ +package file + +import ( + "io/ioutil" + "os" + "path" + "sync" + + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// StreamingService is a concrete implementation of StreamingService that writes state changes out to files +type StreamingService struct { + listeners map[sdk.StoreKey][]types.WriteListener // the listeners that will be initialized with BaseApp + srcChan <-chan []byte // the channel that all of the WriteListeners write their data out to + filePrefix string // optional prefix for each of the generated files + writeDir string // directory to write files into + dstFile *os.File // the current write output file + marshaller codec.BinaryMarshaler // marshaller used for re-marshalling the ABCI messages to write them out to the destination files + stateCache [][]byte // cache the protobuf binary encoded StoreKVPairs in the order they are received +} + +// intermediateWriter is used so that we do not need to update the underlying io.Writer inside the StoreKVPairWriteListener +// everytime we begin writing to a new file +type intermediateWriter struct { + outChan chan<- []byte +} + +// NewIntermediateWriter create an instance of an intermediateWriter that sends to the provided channel +func NewIntermediateWriter(outChan chan<- []byte) *intermediateWriter { + return &intermediateWriter{ + outChan: outChan, + } +} + +// Write satisfies io.Writer +func (iw *intermediateWriter) Write(b []byte) (int, error) { + iw.outChan <- b + return len(b), nil +} + +// NewStreamingService creates a new StreamingService for the provided writeDir, (optional) filePrefix, and storeKeys +func NewStreamingService(writeDir, filePrefix string, storeKeys []sdk.StoreKey, m codec.BinaryMarshaler) (*StreamingService, error) { + listenChan := make(chan []byte, 0) + iw := NewIntermediateWriter(listenChan) + listener := types.NewStoreKVPairWriteListener(iw, m) + listeners := make(map[sdk.StoreKey][]types.WriteListener, len(storeKeys)) + // in this case, we are using the same listener for each Store + for _, key := range storeKeys { + listeners[key] = append(listeners[key], listener) + } + // check that the writeDir exists and is writeable so that we can catch the error here at initialization if it is not + // we don't open a dstFile until we receive our first ABCI message + if err := isDirWriteable(writeDir); err != nil { + return nil, err + } + return &StreamingService{ + listeners: listeners, + srcChan: listenChan, + filePrefix: filePrefix, + writeDir: writeDir, + marshaller: m, + stateCache: make([][]byte, 0), + }, nil +} + +// Listeners returns the StreamingService's underlying WriteListeners, use for registering them with the BaseApp +func (fss *StreamingService) Listeners() map[sdk.StoreKey][]types.WriteListener { + return fss.listeners +} + +func (fss *StreamingService) ListenBeginBlock(ctx sdk.Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) { + // NOTE: this could either be done synchronously or asynchronously + // create a new file with the req info according to naming schema + // write req to file + // write all state changes cached for this stage to file + // reset cache + // write res to file + // close file +} + +func (fss *StreamingService) ListenEndBlock(ctx sdk.Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) { + // NOTE: this could either be done synchronously or asynchronously + // create a new file with the req info according to naming schema + // write req to file + // write all state changes cached for this stage to file + // reset cache + // write res to file + // close file +} + +func (fss *StreamingService) ListenDeliverTx(ctx sdk.Context, req abci.RequestDeliverTx, res abci.ResponseDeliverTx) { + // NOTE: this could either be done synchronously or asynchronously + // create a new file with the req info according to naming schema + // NOTE: if the tx failed, handle accordingly + // write req to file + // write all state changes cached for this stage to file + // reset cache + // write res to file + // close file +} + +// Stream spins up a goroutine select loop which awaits length-prefixed binary encoded KV pairs and caches them in the order they were received +func (fss *StreamingService) Stream(wg *sync.WaitGroup, quitChan <-chan struct{}) { + wg.Add(1) + go func() { + defer wg.Done() + for { + select { + case <-quitChan: + return + case by := <-fss.srcChan: + fss.stateCache = append(fss.stateCache, by) + } + } + }() +} + +// isDirWriteable checks if dir is writable by writing and removing a file +// to dir. It returns nil if dir is writable. +func isDirWriteable(dir string) error { + f := path.Join(dir, ".touch") + if err := ioutil.WriteFile(f, []byte(""), 0600); err != nil { + return err + } + return os.Remove(f) +} From 7cc4dbd99c5bb7957acf7187c8773e8277b945df Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Thu, 11 Feb 2021 13:12:02 -0600 Subject: [PATCH 15/46] update Hook interface to return errors so that they can be logged at the BaseApp logger level --- baseapp/abci.go | 16 ++++++++++++---- docs/architecture/adr-038-state-listening.md | 6 +++--- types/streaming.go | 6 +++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 3592b6d92d20..7863e26c3a1f 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -198,7 +198,9 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg // call the hooks with the BeginBlock messages for _, hook := range app.hooks { - hook.ListenBeginBlock(app.deliverState.ctx, req, res) + if err := hook.ListenBeginBlock(app.deliverState.ctx, req, res); err != nil { + app.logger.Error("BeginBlock listening hook failed", "height", req.Header.Height, "err", err) + } } return res @@ -223,7 +225,9 @@ func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBloc // call the streaming service hooks with the EndBlock messages for _, hook := range app.hooks { - hook.ListenEndBlock(app.deliverState.ctx, req, res) + if err := hook.ListenEndBlock(app.deliverState.ctx, req, res); err != nil { + app.logger.Error("EndBlock listening hook failed", "height", req.Height, "err", err) + } } return res @@ -289,7 +293,9 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx res := sdkerrors.ResponseDeliverTx(err, gInfo.GasWanted, gInfo.GasUsed, app.trace) // if we throw and error, be sure to still call the streaming service's hook for _, hook := range app.hooks { - hook.ListenDeliverTx(app.deliverState.ctx, req, res) + if err := hook.ListenDeliverTx(app.deliverState.ctx, req, res); err != nil { + app.logger.Error("DeliverTx listening hook failed", "err", err) + } } return res } @@ -304,7 +310,9 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx // call the streaming service hooks with the DeliverTx messages for _, hook := range app.hooks { - hook.ListenDeliverTx(app.deliverState.ctx, req, res) + if err := hook.ListenDeliverTx(app.deliverState.ctx, req, res); err != nil { + app.logger.Error("DeliverTx listening hook failed", "err", err) + } } return res diff --git a/docs/architecture/adr-038-state-listening.md b/docs/architecture/adr-038-state-listening.md index 7c925b73cdbe..0c205d1b2a0c 100644 --- a/docs/architecture/adr-038-state-listening.md +++ b/docs/architecture/adr-038-state-listening.md @@ -209,9 +209,9 @@ We will introduce a new `StreamingService` interface for exposing `WriteListener ```go // Hook interface used to hook into the ABCI message processing of the BaseApp type Hook interface { - ListenBeginBlock(ctx sdk.Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) // update the streaming service with the latest BeginBlock messages - ListenEndBlock(ctx sdk.Context, req abci.RequestEndBlock, res abci.ResponseEndBlock) // update the steaming service with the latest EndBlock messages - ListenDeliverTx(ctx sdk.Context, req abci.RequestDeliverTx, res abci.ResponseDeliverTx) // update the steaming service with the latest DeliverTx messages + ListenBeginBlock(ctx sdk.Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) error // update the streaming service with the latest BeginBlock messages + ListenEndBlock(ctx sdk.Context, req abci.RequestEndBlock, res abci.ResponseEndBlock) error// update the steaming service with the latest EndBlock messages + ListenDeliverTx(ctx sdk.Context, req abci.RequestDeliverTx, res abci.ResponseDeliverTx) error // update the steaming service with the latest DeliverTx messages } // StreamingService interface for registering WriteListeners with the BaseApp and updating the service with the ABCI messages using the hooks diff --git a/types/streaming.go b/types/streaming.go index 81af98e28ad1..f1dcfac6ecd3 100644 --- a/types/streaming.go +++ b/types/streaming.go @@ -11,11 +11,11 @@ import ( // Hook interface used to hook into the ABCI message processing of the BaseApp type Hook interface { // update the streaming service with the latest BeginBlock messages - ListenBeginBlock(ctx Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) + ListenBeginBlock(ctx Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) error // update the steaming service with the latest EndBlock messages - ListenEndBlock(ctx Context, req abci.RequestEndBlock, res abci.ResponseEndBlock) + ListenEndBlock(ctx Context, req abci.RequestEndBlock, res abci.ResponseEndBlock) error // update the steaming service with the latest DeliverTx messages - ListenDeliverTx(ctx Context, req abci.RequestDeliverTx, res abci.ResponseDeliverTx) + ListenDeliverTx(ctx Context, req abci.RequestDeliverTx, res abci.ResponseDeliverTx) error } // StreamingService interface for registering WriteListeners with the BaseApp and updating the service with the ABCI messages using the hooks From 7d2e9d6d89945cd0f4495cdc014c2ff658385b26 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Thu, 11 Feb 2021 13:12:29 -0600 Subject: [PATCH 16/46] finish implementation of the file streaming service --- streaming/file/service.go | 145 +++++++++++++++++++++++++++++++++----- 1 file changed, 128 insertions(+), 17 deletions(-) diff --git a/streaming/file/service.go b/streaming/file/service.go index e9de7c14002b..7d09baf5c954 100644 --- a/streaming/file/service.go +++ b/streaming/file/service.go @@ -1,9 +1,11 @@ package file import ( + "fmt" "io/ioutil" "os" "path" + "path/filepath" "sync" abci "github.com/tendermint/tendermint/abci/types" @@ -13,15 +15,35 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) +/* +The naming schema and data format for the files this service writes out to is as such: + +After every `BeginBlock` request a new file is created with the name `block-{N}-begin`, where N is the block number. All +subsequent state changes are written out to this file until the first `DeliverTx` request is received. At the head of these files, +the length-prefixed protobuf encoded `BeginBlock` request is written, and the response is written at the tail. + +After every `DeliverTx` request a new file is created with the name `block-{N}-tx-{M}` where N is the block number and M +is the tx number in the block (i.e. 0, 1, 2...). All subsequent state changes are written out to this file until the next +`DeliverTx` request is received or an `EndBlock` request is received. At the head of these files, the length-prefixed protobuf +encoded `DeliverTx` request is written, and the response is written at the tail. + +After every `EndBlock` request a new file is created with the name `block-{N}-end`, where N is the block number. All +subsequent state changes are written out to this file until the next `BeginBlock` request is received. At the head of these files, +the length-prefixed protobuf encoded `EndBlock` request is written, and the response is written at the tail. +*/ + +var _ sdk.StreamingService = &StreamingService{} + // StreamingService is a concrete implementation of StreamingService that writes state changes out to files type StreamingService struct { - listeners map[sdk.StoreKey][]types.WriteListener // the listeners that will be initialized with BaseApp - srcChan <-chan []byte // the channel that all of the WriteListeners write their data out to - filePrefix string // optional prefix for each of the generated files - writeDir string // directory to write files into - dstFile *os.File // the current write output file - marshaller codec.BinaryMarshaler // marshaller used for re-marshalling the ABCI messages to write them out to the destination files - stateCache [][]byte // cache the protobuf binary encoded StoreKVPairs in the order they are received + listeners map[sdk.StoreKey][]types.WriteListener // the listeners that will be initialized with BaseApp + srcChan <-chan []byte // the channel that all of the WriteListeners write their data out to + filePrefix string // optional prefix for each of the generated files + writeDir string // directory to write files into + marshaller codec.BinaryMarshaler // marshaller used for re-marshalling the ABCI messages to write them out to the destination files + stateCache [][]byte // cache the protobuf binary encoded StoreKVPairs in the order they are received + currentBlockNumber int64 // the current block number + currentTxIndex int64 // the index of the current tx } // intermediateWriter is used so that we do not need to update the underlying io.Writer inside the StoreKVPairWriteListener @@ -73,35 +95,124 @@ func (fss *StreamingService) Listeners() map[sdk.StoreKey][]types.WriteListener return fss.listeners } -func (fss *StreamingService) ListenBeginBlock(ctx sdk.Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) { - // NOTE: this could either be done synchronously or asynchronously - // create a new file with the req info according to naming schema +// ListenBeginBlock satisfies the Hook interface +// It writes out the received BeginBlock request and response and the resulting state changes out to a file as described +// in the above the naming schema +func (fss *StreamingService) ListenBeginBlock(ctx sdk.Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) error { + // generate the new file + dstFile, err := fss.openBeginBlockFile(req) + if err != nil { + return err + } // write req to file + lengthPrefixedReqBytes, err := fss.marshaller.MarshalBinaryLengthPrefixed(&req) + if err != nil { + return err + } + if _, err = dstFile.Write(lengthPrefixedReqBytes); err != nil { + return err + } // write all state changes cached for this stage to file + for _, stateChange := range fss.stateCache { + if _, err = dstFile.Write(stateChange); err != nil { + return err + } + } // reset cache + fss.stateCache = nil // write res to file + lengthPrefixedResBytes, err := fss.marshaller.MarshalBinaryLengthPrefixed(&res) + if _, err = dstFile.Write(lengthPrefixedResBytes); err != nil { + return err + } // close file + return dstFile.Close() +} + +func (fss *StreamingService) openBeginBlockFile(req abci.RequestBeginBlock) (*os.File, error) { + fss.currentBlockNumber = req.GetHeader().Height + fss.currentTxIndex = 0 + fileName := fmt.Sprintf("block-%d-begin", fss.currentBlockNumber) + return os.OpenFile(filepath.Join(fss.writeDir, fileName), os.O_CREATE|os.O_WRONLY, 0600) } -func (fss *StreamingService) ListenEndBlock(ctx sdk.Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) { - // NOTE: this could either be done synchronously or asynchronously - // create a new file with the req info according to naming schema +// ListenDeliverTx satisfies the Hook interface +// It writes out the received DeliverTx request and response and the resulting state changes out to a file as described +// in the above the naming schema +func (fss *StreamingService) ListenDeliverTx(ctx sdk.Context, req abci.RequestDeliverTx, res abci.ResponseDeliverTx) error { + // generate the new file + dstFile, err := fss.openDeliverTxFile() + if err != nil { + return err + } // write req to file + lengthPrefixedReqBytes, err := fss.marshaller.MarshalBinaryLengthPrefixed(&req) + if err != nil { + return err + } + if _, err = dstFile.Write(lengthPrefixedReqBytes); err != nil { + return err + } // write all state changes cached for this stage to file + for _, stateChange := range fss.stateCache { + if _, err = dstFile.Write(stateChange); err != nil { + return err + } + } // reset cache + fss.stateCache = nil // write res to file + lengthPrefixedResBytes, err := fss.marshaller.MarshalBinaryLengthPrefixed(&res) + if _, err = dstFile.Write(lengthPrefixedResBytes); err != nil { + return err + } // close file + return dstFile.Close() +} + +func (fss *StreamingService) openDeliverTxFile() (*os.File, error) { + fileName := fmt.Sprintf("block-%d-tx-%d", fss.currentBlockNumber, fss.currentTxIndex) + fss.currentTxIndex++ + return os.OpenFile(filepath.Join(fss.writeDir, fileName), os.O_CREATE|os.O_WRONLY, 0600) } -func (fss *StreamingService) ListenDeliverTx(ctx sdk.Context, req abci.RequestDeliverTx, res abci.ResponseDeliverTx) { - // NOTE: this could either be done synchronously or asynchronously - // create a new file with the req info according to naming schema - // NOTE: if the tx failed, handle accordingly +// ListenEndBlock satisfies the Hook interface +// It writes out the received EndBlock request and response and the resulting state changes out to a file as described +// in the above the naming schema +func (fss *StreamingService) ListenEndBlock(ctx sdk.Context, req abci.RequestEndBlock, res abci.ResponseEndBlock) error { + // generate the new file + dstFile, err := fss.openEndBlockFile() + if err != nil { + return err + } // write req to file + lengthPrefixedReqBytes, err := fss.marshaller.MarshalBinaryLengthPrefixed(&req) + if err != nil { + return err + } + if _, err = dstFile.Write(lengthPrefixedReqBytes); err != nil { + return err + } // write all state changes cached for this stage to file + for _, stateChange := range fss.stateCache { + if _, err = dstFile.Write(stateChange); err != nil { + return err + } + } // reset cache + fss.stateCache = nil // write res to file + lengthPrefixedResBytes, err := fss.marshaller.MarshalBinaryLengthPrefixed(&res) + if _, err = dstFile.Write(lengthPrefixedResBytes); err != nil { + return err + } // close file + return dstFile.Close() +} + +func (fss *StreamingService) openEndBlockFile() (*os.File, error) { + fileName := fmt.Sprintf("block-%d-end", fss.currentBlockNumber) + return os.OpenFile(filepath.Join(fss.writeDir, fileName), os.O_CREATE|os.O_WRONLY, 0600) } // Stream spins up a goroutine select loop which awaits length-prefixed binary encoded KV pairs and caches them in the order they were received From 8f72e009e95e06322d8a989ff41661f333665743 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Thu, 18 Feb 2021 12:55:19 -0600 Subject: [PATCH 17/46] streaming service unit tests; minor adjustments --- baseapp/options.go | 4 +- docs/architecture/adr-038-state-listening.md | 4 +- streaming/file/service.go | 11 + streaming/file/service_test.go | 396 +++++++++++++++++++ 4 files changed, 411 insertions(+), 4 deletions(-) create mode 100644 streaming/file/service_test.go diff --git a/baseapp/options.go b/baseapp/options.go index 04f32f7f69fd..53ab17930ace 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -238,8 +238,8 @@ func (app *BaseApp) SetInterfaceRegistry(registry types.InterfaceRegistry) { app.msgServiceRouter.SetInterfaceRegistry(registry) } -// SetHooks is used to set a streaming service into the BaseApp hooks -func (app *BaseApp) SetHooks(s sdk.StreamingService) { +// SetStreamingService is used to set a streaming service into the BaseApp hooks and load the listeners into the multistore +func (app *BaseApp) SetStreamingService(s sdk.StreamingService) { // set the listeners for each StoreKey for key, lis := range s.Listeners() { app.cms.SetListeners(key, lis) diff --git a/docs/architecture/adr-038-state-listening.md b/docs/architecture/adr-038-state-listening.md index 0c205d1b2a0c..b5e6a85b45fa 100644 --- a/docs/architecture/adr-038-state-listening.md +++ b/docs/architecture/adr-038-state-listening.md @@ -384,8 +384,8 @@ using the provided `AppOptions` and TOML configuration fields. We will add a new method to the `BaseApp` to enable the registration of `StreamingService`s: ```go -// RegisterStreamingService is used to register a streaming service with the BaseApp -func (app *BaseApp) RegisterHooks(s StreamingService) { +// SetStreamingService is used to register a streaming service with the BaseApp +func (app *BaseApp) SetStreamingService(s StreamingService) { // set the listeners for each StoreKey for key, lis := range s.Listeners() { app.cms.AddListeners(key, lis) diff --git a/streaming/file/service.go b/streaming/file/service.go index 7d09baf5c954..3e41601fad79 100644 --- a/streaming/file/service.go +++ b/streaming/file/service.go @@ -133,6 +133,9 @@ func (fss *StreamingService) openBeginBlockFile(req abci.RequestBeginBlock) (*os fss.currentBlockNumber = req.GetHeader().Height fss.currentTxIndex = 0 fileName := fmt.Sprintf("block-%d-begin", fss.currentBlockNumber) + if fss.filePrefix != "" { + fileName = fmt.Sprintf("%s-%s", fss.filePrefix, fileName) + } return os.OpenFile(filepath.Join(fss.writeDir, fileName), os.O_CREATE|os.O_WRONLY, 0600) } @@ -172,6 +175,9 @@ func (fss *StreamingService) ListenDeliverTx(ctx sdk.Context, req abci.RequestDe func (fss *StreamingService) openDeliverTxFile() (*os.File, error) { fileName := fmt.Sprintf("block-%d-tx-%d", fss.currentBlockNumber, fss.currentTxIndex) + if fss.filePrefix != "" { + fileName = fmt.Sprintf("%s-%s", fss.filePrefix, fileName) + } fss.currentTxIndex++ return os.OpenFile(filepath.Join(fss.writeDir, fileName), os.O_CREATE|os.O_WRONLY, 0600) } @@ -212,9 +218,14 @@ func (fss *StreamingService) ListenEndBlock(ctx sdk.Context, req abci.RequestEnd func (fss *StreamingService) openEndBlockFile() (*os.File, error) { fileName := fmt.Sprintf("block-%d-end", fss.currentBlockNumber) + if fss.filePrefix != "" { + fileName = fmt.Sprintf("%s-%s", fss.filePrefix, fileName) + } return os.OpenFile(filepath.Join(fss.writeDir, fileName), os.O_CREATE|os.O_WRONLY, 0600) } +// Do we need this and an intermediate writer? We could just write directly to the buffer on calls to Write +// But then we don't support a Stream interface, which could be needed for other types of streamers // Stream spins up a goroutine select loop which awaits length-prefixed binary encoded KV pairs and caches them in the order they were received func (fss *StreamingService) Stream(wg *sync.WaitGroup, quitChan <-chan struct{}) { wg.Add(1) diff --git a/streaming/file/service_test.go b/streaming/file/service_test.go new file mode 100644 index 000000000000..9c989ca03533 --- /dev/null +++ b/streaming/file/service_test.go @@ -0,0 +1,396 @@ +package file + +import ( + "encoding/binary" + "fmt" + "io/ioutil" + "os" + "path/filepath" + "sync" + "testing" + + "github.com/cosmos/cosmos-sdk/codec" + codecTypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" + types1 "github.com/tendermint/tendermint/proto/tendermint/types" +) + +var ( + interfaceRegistry = codecTypes.NewInterfaceRegistry() + testMarshaller = codec.NewProtoCodec(interfaceRegistry) + testStreamingService *StreamingService + testListener1, testListener2 types.WriteListener + emptyContext = sdk.Context{} + + // test abci message types + mockHash = []byte{1, 2, 3, 4, 5, 6, 7, 8, 9} + testBeginBlockReq = abci.RequestBeginBlock{ + Header: types1.Header{ + Height: 1, + }, + ByzantineValidators: []abci.Evidence{}, + Hash: mockHash, + LastCommitInfo: abci.LastCommitInfo{ + Round: 1, + Votes: []abci.VoteInfo{}, + }, + } + testBeginBlockRes = abci.ResponseBeginBlock{ + Events: []abci.Event{ + { + Type: "testEventType1", + }, + { + Type: "testEventType2", + }, + }, + } + testEndBlockReq = abci.RequestEndBlock{ + Height: 1, + } + testEndBlockRes = abci.ResponseEndBlock{ + Events: []abci.Event{}, + ConsensusParamUpdates: &abci.ConsensusParams{}, + ValidatorUpdates: []abci.ValidatorUpdate{}, + } + mockTxBytes1 = []byte{9, 8, 7, 6, 5, 4, 3, 2, 1} + testDeliverTxReq1 = abci.RequestDeliverTx{ + Tx: mockTxBytes1, + } + mockTxBytes2 = []byte{8, 7, 6, 5, 4, 3, 2} + testDeliverTxReq2 = abci.RequestDeliverTx{ + Tx: mockTxBytes2, + } + mockTxResponseData1 = []byte{1, 3, 5, 7, 9} + testDeliverTxRes1 = abci.ResponseDeliverTx{ + Events: []abci.Event{}, + Code: 1, + Codespace: "mockCodeSpace", + Data: mockTxResponseData1, + GasUsed: 2, + GasWanted: 3, + Info: "mockInfo", + Log: "mockLog", + } + mockTxResponseData2 = []byte{1, 3, 5, 7, 9} + testDeliverTxRes2 = abci.ResponseDeliverTx{ + Events: []abci.Event{}, + Code: 1, + Codespace: "mockCodeSpace", + Data: mockTxResponseData2, + GasUsed: 2, + GasWanted: 3, + Info: "mockInfo", + Log: "mockLog", + } + + // mock store keys + mockStoreKey1 = sdk.NewKVStoreKey("mockStore1") + mockStoreKey2 = sdk.NewKVStoreKey("mockStore2") + + // file stuff + testPrefix = "testPrefix" + testDir = "./.test" + + // mock state changes + mockKey1 = []byte{1, 2, 3} + mockValue1 = []byte{3, 2, 1} + mockKey2 = []byte{2, 3, 4} + mockValue2 = []byte{4, 3, 2} + mockKey3 = []byte{3, 4, 5} + mockValue3 = []byte{5, 4, 3} +) + +func TestIntermediateWriter(t *testing.T) { + outChan := make(chan []byte, 0) + iw := NewIntermediateWriter(outChan) + require.IsType(t, &intermediateWriter{}, iw) + testBytes := []byte{1, 2, 3, 4, 5} + var length int + var err error + go func() { + length, err = iw.Write(testBytes) + }() + receivedBytes := <-outChan + require.Equal(t, len(testBytes), length) + require.Equal(t, testBytes, receivedBytes) + require.Nil(t, err) +} + +func TestFileStreamingService(t *testing.T) { + err := os.Mkdir(testDir, 0700) + require.Nil(t, err) + defer os.RemoveAll(testDir) + + testKeys := []sdk.StoreKey{mockStoreKey1, mockStoreKey2} + testStreamingService, err = NewStreamingService(testDir, testPrefix, testKeys, testMarshaller) + require.Nil(t, err) + require.IsType(t, &StreamingService{}, testStreamingService) + require.Equal(t, testPrefix, testStreamingService.filePrefix) + require.Equal(t, testDir, testStreamingService.writeDir) + require.Equal(t, testMarshaller, testStreamingService.marshaller) + testListener1 = testStreamingService.listeners[mockStoreKey1][0] + testListener2 = testStreamingService.listeners[mockStoreKey2][0] + wg := new(sync.WaitGroup) + quitChan := make(chan struct{}) + testStreamingService.Stream(wg, quitChan) + testListenBeginBlock(t) + testListenDeliverTx1(t) + testListenDeliverTx2(t) + testListenEndBlock(t) + close(quitChan) + wg.Wait() +} + +func testListenBeginBlock(t *testing.T) { + expectedBeginBlockReqBytes, err := testMarshaller.MarshalBinaryBare(&testBeginBlockReq) + require.Nil(t, err) + expectedBeginBlockResBytes, err := testMarshaller.MarshalBinaryBare(&testBeginBlockRes) + require.Nil(t, err) + + // Write state changes + testListener1.OnWrite(mockStoreKey1, true, mockKey1, mockValue1) + testListener2.OnWrite(mockStoreKey2, true, mockKey2, mockValue2) + testListener1.OnWrite(mockStoreKey1, true, mockKey3, mockValue3) + + // expected KV pairs + expectedKVPair1, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + StoreKey: mockStoreKey1.Name(), + Key: mockKey1, + Value: mockValue1, + Set: true, + }) + require.Nil(t, err) + expectedKVPair2, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + StoreKey: mockStoreKey2.Name(), + Key: mockKey2, + Value: mockValue2, + Set: true, + }) + require.Nil(t, err) + expectedKVPair3, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + StoreKey: mockStoreKey1.Name(), + Key: mockKey3, + Value: mockValue3, + Set: true, + }) + require.Nil(t, err) + + // Send the ABCI messages + err = testStreamingService.ListenBeginBlock(emptyContext, testBeginBlockReq, testBeginBlockRes) + require.Nil(t, err) + + // Load the file, checking that it was created with the expected name + fileName := fmt.Sprintf("%s-block-%d-begin", testPrefix, testBeginBlockReq.GetHeader().Height) + fileBytes, err := readInFile(fileName) + require.Nil(t, err) + + // Segment the file into the separate gRPC messages and check the correctness of each + segments, err := segmentBytes(fileBytes) + require.Nil(t, err) + require.Equal(t, 5, len(segments)) + require.Equal(t, expectedBeginBlockReqBytes, segments[0]) + require.Equal(t, expectedKVPair1, segments[1]) + require.Equal(t, expectedKVPair2, segments[2]) + require.Equal(t, expectedKVPair3, segments[3]) + require.Equal(t, expectedBeginBlockResBytes, segments[4]) +} + +func testListenDeliverTx1(t *testing.T) { + expectedDeliverTxReq1Bytes, err := testMarshaller.MarshalBinaryBare(&testDeliverTxReq1) + require.Nil(t, err) + expectedDeliverTxRes1Bytes, err := testMarshaller.MarshalBinaryBare(&testDeliverTxRes1) + require.Nil(t, err) + + // Write state changes + testListener1.OnWrite(mockStoreKey1, true, mockKey1, mockValue1) + testListener2.OnWrite(mockStoreKey2, true, mockKey2, mockValue2) + testListener1.OnWrite(mockStoreKey2, true, mockKey3, mockValue3) + + // expected KV pairs + expectedKVPair1, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + StoreKey: mockStoreKey1.Name(), + Key: mockKey1, + Value: mockValue1, + Set: true, + }) + require.Nil(t, err) + expectedKVPair2, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + StoreKey: mockStoreKey2.Name(), + Key: mockKey2, + Value: mockValue2, + Set: true, + }) + require.Nil(t, err) + expectedKVPair3, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + StoreKey: mockStoreKey2.Name(), + Key: mockKey3, + Value: mockValue3, + Set: true, + }) + require.Nil(t, err) + + // Send the ABCI messages + err = testStreamingService.ListenDeliverTx(emptyContext, testDeliverTxReq1, testDeliverTxRes1) + require.Nil(t, err) + + // Load the file, checking that it was created with the expected name + fileName := fmt.Sprintf("%s-block-%d-tx-%d", testPrefix, testBeginBlockReq.GetHeader().Height, 0) + fileBytes, err := readInFile(fileName) + require.Nil(t, err) + + // Segment the file into the separate gRPC messages and check the correctness of each + segments, err := segmentBytes(fileBytes) + require.Nil(t, err) + require.Equal(t, 5, len(segments)) + require.Equal(t, expectedDeliverTxReq1Bytes, segments[0]) + require.Equal(t, expectedKVPair1, segments[1]) + require.Equal(t, expectedKVPair2, segments[2]) + require.Equal(t, expectedKVPair3, segments[3]) + require.Equal(t, expectedDeliverTxRes1Bytes, segments[4]) +} + +func testListenDeliverTx2(t *testing.T) { + expectedDeliverTxReq2Bytes, err := testMarshaller.MarshalBinaryBare(&testDeliverTxReq2) + require.Nil(t, err) + expectedDeliverTxRes2Bytes, err := testMarshaller.MarshalBinaryBare(&testDeliverTxRes2) + require.Nil(t, err) + + // Write state changes + testListener1.OnWrite(mockStoreKey2, true, mockKey1, mockValue1) + testListener2.OnWrite(mockStoreKey1, true, mockKey2, mockValue2) + testListener1.OnWrite(mockStoreKey2, true, mockKey3, mockValue3) + + // expected KV pairs + expectedKVPair1, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + StoreKey: mockStoreKey2.Name(), + Key: mockKey1, + Value: mockValue1, + Set: true, + }) + require.Nil(t, err) + expectedKVPair2, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + StoreKey: mockStoreKey1.Name(), + Key: mockKey2, + Value: mockValue2, + Set: true, + }) + require.Nil(t, err) + expectedKVPair3, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + StoreKey: mockStoreKey2.Name(), + Key: mockKey3, + Value: mockValue3, + Set: true, + }) + require.Nil(t, err) + + // Send the ABCI messages + err = testStreamingService.ListenDeliverTx(emptyContext, testDeliverTxReq2, testDeliverTxRes2) + require.Nil(t, err) + + // Load the file, checking that it was created with the expected name + fileName := fmt.Sprintf("%s-block-%d-tx-%d", testPrefix, testBeginBlockReq.GetHeader().Height, 1) + fileBytes, err := readInFile(fileName) + require.Nil(t, err) + + // Segment the file into the separate gRPC messages and check the correctness of each + segments, err := segmentBytes(fileBytes) + require.Nil(t, err) + require.Equal(t, 5, len(segments)) + require.Equal(t, expectedDeliverTxReq2Bytes, segments[0]) + require.Equal(t, expectedKVPair1, segments[1]) + require.Equal(t, expectedKVPair2, segments[2]) + require.Equal(t, expectedKVPair3, segments[3]) + require.Equal(t, expectedDeliverTxRes2Bytes, segments[4]) +} + +func testListenEndBlock(t *testing.T) { + expectedEndBlockReqBytes, err := testMarshaller.MarshalBinaryBare(&testEndBlockReq) + require.Nil(t, err) + expectedEndBlockResBytes, err := testMarshaller.MarshalBinaryBare(&testEndBlockRes) + require.Nil(t, err) + + // Write state changes + testListener1.OnWrite(mockStoreKey1, true, mockKey1, mockValue1) + testListener2.OnWrite(mockStoreKey1, true, mockKey2, mockValue2) + testListener1.OnWrite(mockStoreKey2, true, mockKey3, mockValue3) + + // expected KV pairs + expectedKVPair1, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + StoreKey: mockStoreKey1.Name(), + Key: mockKey1, + Value: mockValue1, + Set: true, + }) + require.Nil(t, err) + expectedKVPair2, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + StoreKey: mockStoreKey1.Name(), + Key: mockKey2, + Value: mockValue2, + Set: true, + }) + require.Nil(t, err) + expectedKVPair3, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + StoreKey: mockStoreKey2.Name(), + Key: mockKey3, + Value: mockValue3, + Set: true, + }) + require.Nil(t, err) + + // Send the ABCI messages + err = testStreamingService.ListenEndBlock(emptyContext, testEndBlockReq, testEndBlockRes) + require.Nil(t, err) + + // Load the file, checking that it was created with the expected name + fileName := fmt.Sprintf("%s-block-%d-end", testPrefix, testEndBlockReq.Height) + fileBytes, err := readInFile(fileName) + require.Nil(t, err) + + // Segment the file into the separate gRPC messages and check the correctness of each + segments, err := segmentBytes(fileBytes) + require.Nil(t, err) + require.Equal(t, 5, len(segments)) + require.Equal(t, expectedEndBlockReqBytes, segments[0]) + require.Equal(t, expectedKVPair1, segments[1]) + require.Equal(t, expectedKVPair2, segments[2]) + require.Equal(t, expectedKVPair3, segments[3]) + require.Equal(t, expectedEndBlockResBytes, segments[4]) +} + +func readInFile(name string) ([]byte, error) { + path := filepath.Join(testDir, name) + return ioutil.ReadFile(path) +} + +// Returns all of the protobuf messages contained in the byte array as an array of byte arrays +// The messages have their length prefix removed +func segmentBytes(bz []byte) ([][]byte, error) { + var err error + segments := make([][]byte, 0) + for len(bz) > 0 { + var segment []byte + segment, bz, err = getHeadSegment(bz) + if err != nil { + return nil, err + } + segments = append(segments, segment) + } + return segments, nil +} + +// Returns the bytes for the leading protobuf object in the byte array (removing the length prefix) and returns the remainder of the byte array +func getHeadSegment(bz []byte) ([]byte, []byte, error) { + size, prefixSize := binary.Uvarint(bz) + if prefixSize < 0 { + return nil, nil, fmt.Errorf("invalid number of bytes read from length-prefixed encoding: %d", prefixSize) + } + if size > uint64(len(bz)-prefixSize) { + return nil, nil, fmt.Errorf("not enough bytes to read; want: %v, got: %v", size, len(bz)-prefixSize) + } + return bz[prefixSize:(uint64(prefixSize) + size)], bz[uint64(prefixSize)+size:], nil +} From 613a4c5b2f3cae01a3941838294406b3d53ab7da Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 22 Feb 2021 10:41:11 -0600 Subject: [PATCH 18/46] streaming service constuctor, constructor unit test, update adr --- docs/architecture/adr-038-state-listening.md | 98 ++++++++++---------- streaming/constructor.go | 69 ++++++++++++++ streaming/constructor_test.go | 42 +++++++++ 3 files changed, 160 insertions(+), 49 deletions(-) create mode 100644 streaming/constructor.go create mode 100644 streaming/constructor_test.go diff --git a/docs/architecture/adr-038-state-listening.md b/docs/architecture/adr-038-state-listening.md index b5e6a85b45fa..00f63ebfe94b 100644 --- a/docs/architecture/adr-038-state-listening.md +++ b/docs/architecture/adr-038-state-listening.md @@ -482,60 +482,60 @@ We will also provide a mapping of the TOML `store.streamers` "file" configuratio streaming service. In the future, as other streaming services are added, their constructors will be added here as well. ```go -// StreamingServiceConstructor is used to construct a streaming service -type StreamingServiceConstructor func(opts servertypes.AppOptions, keys []sdk.StoreKey) (StreamingService, error) +// ServiceConstructor is used to construct a streaming service +type ServiceConstructor func(opts serverTypes.AppOptions, keys []sdk.StoreKey, marshaller codec.BinaryMarshaler) (sdk.StreamingService, error) -// StreamingServiceType enum for specifying the type of StreamingService -type StreamingServiceType int +// ServiceType enum for specifying the type of StreamingService +type ServiceType int const ( - Unknown StreamingServiceType = iota - File - // add more in the future + Unknown ServiceType = iota + File + // add more in the future ) -// NewStreamingServiceType returns the StreamingServiceType corresponding to the provided name -func NewStreamingServiceType(name string) StreamingServiceType { - switch strings.ToLower(name) { - case "file", "f": - return File - default: - return Unknown - } -} - -// String returns the string name of a StreamingServiceType -func (sst StreamingServiceType) String() string { - switch sst { - case File: - return "file" - default: - return "" - } -} - -// StreamingServiceConstructorLookupTable is a mapping of StreamingServiceTypes to StreamingServiceConstructors -var StreamingServiceConstructorLookupTable = map[StreamingServiceType]StreamingServiceConstructor{ - File: FileStreamingConstructor, -} - -// NewStreamingServiceConstructor returns the StreamingServiceConstructor corresponding to the provided name -func NewStreamingServiceConstructor(name string) (StreamingServiceConstructor, error) { - ssType := NewStreamingServiceType(name) - if ssType == Unknown { - return nil, fmt.Errorf("unrecognized streaming service name %s", name) - } - if constructor, ok := StreamingServiceConstructorLookupTable[ssType]; ok { - return constructor, nil - } - return nil, fmt.Errorf("streaming service constructor of type %s not found", ssType.String()) -} - -// FileStreamingConstructor is the StreamingServiceConstructor function for creating a FileStreamingService -func FileStreamingConstructor(opts servertypes.AppOptions, keys []sdk.StoreKey) (StreamingService, error) { - filePrefix := cast.ToString(opts.Get("streamers.file.prefix")) - fileDir := cast.ToString(opts.Get("streamers.file.writeDir")) - return streaming.NewFileStreamingService(fileDir, filePrefix, keys), nil +// NewStreamingServiceType returns the streaming.ServiceType corresponding to the provided name +func NewStreamingServiceType(name string) ServiceType { + switch strings.ToLower(name) { + case "file", "f": + return File + default: + return Unknown + } +} + +// String returns the string name of a streaming.ServiceType +func (sst ServiceType) String() string { + switch sst { + case File: + return "file" + default: + return "" + } +} + +// ServiceConstructorLookupTable is a mapping of streaming.ServiceTypes to streaming.ServiceConstructors +var ServiceConstructorLookupTable = map[ServiceType]ServiceConstructor{ + File: FileStreamingConstructor, +} + +// NewServiceConstructor returns the streaming.ServiceConstructor corresponding to the provided name +func NewServiceConstructor(name string) (ServiceConstructor, error) { + ssType := NewStreamingServiceType(name) + if ssType == Unknown { + return nil, fmt.Errorf("unrecognized streaming service name %s", name) + } + if constructor, ok := ServiceConstructorLookupTable[ssType]; ok { + return constructor, nil + } + return nil, fmt.Errorf("streaming service constructor of type %s not found", ssType.String()) +} + +// FileStreamingConstructor is the streaming.ServiceConstructor function for creating a FileStreamingService +func FileStreamingConstructor(opts serverTypes.AppOptions, keys []sdk.StoreKey, marshaller codec.BinaryMarshaler) (sdk.StreamingService, error) { + filePrefix := cast.ToString(opts.Get("streamers.file.prefix")) + fileDir := cast.ToString(opts.Get("streamers.file.writeDir")) + return file.NewStreamingService(fileDir, filePrefix, keys, marshaller) } ``` diff --git a/streaming/constructor.go b/streaming/constructor.go new file mode 100644 index 000000000000..28c60b50c762 --- /dev/null +++ b/streaming/constructor.go @@ -0,0 +1,69 @@ +package streaming + +import ( + "fmt" + "strings" + + "github.com/cosmos/cosmos-sdk/codec" + serverTypes "github.com/cosmos/cosmos-sdk/server/types" + "github.com/cosmos/cosmos-sdk/streaming/file" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/spf13/cast" +) + +// ServiceConstructor is used to construct a streaming service +type ServiceConstructor func(opts serverTypes.AppOptions, keys []sdk.StoreKey, marshaller codec.BinaryMarshaler) (sdk.StreamingService, error) + +// ServiceType enum for specifying the type of StreamingService +type ServiceType int + +const ( + Unknown ServiceType = iota + File + // add more in the future +) + +// NewStreamingServiceType returns the streaming.ServiceType corresponding to the provided name +func NewStreamingServiceType(name string) ServiceType { + switch strings.ToLower(name) { + case "file", "f": + return File + default: + return Unknown + } +} + +// String returns the string name of a streaming.ServiceType +func (sst ServiceType) String() string { + switch sst { + case File: + return "file" + default: + return "" + } +} + +// ServiceConstructorLookupTable is a mapping of streaming.ServiceTypes to streaming.ServiceConstructors +var ServiceConstructorLookupTable = map[ServiceType]ServiceConstructor{ + File: FileStreamingConstructor, +} + +// NewServiceConstructor returns the streaming.ServiceConstructor corresponding to the provided name +func NewServiceConstructor(name string) (ServiceConstructor, error) { + ssType := NewStreamingServiceType(name) + if ssType == Unknown { + return nil, fmt.Errorf("unrecognized streaming service name %s", name) + } + if constructor, ok := ServiceConstructorLookupTable[ssType]; ok { + return constructor, nil + } + return nil, fmt.Errorf("streaming service constructor of type %s not found", ssType.String()) +} + +// FileStreamingConstructor is the streaming.ServiceConstructor function for creating a FileStreamingService +func FileStreamingConstructor(opts serverTypes.AppOptions, keys []sdk.StoreKey, marshaller codec.BinaryMarshaler) (sdk.StreamingService, error) { + filePrefix := cast.ToString(opts.Get("streamers.file.prefix")) + fileDir := cast.ToString(opts.Get("streamers.file.writeDir")) + return file.NewStreamingService(fileDir, filePrefix, keys, marshaller) +} diff --git a/streaming/constructor_test.go b/streaming/constructor_test.go new file mode 100644 index 000000000000..a6b3f4f842cd --- /dev/null +++ b/streaming/constructor_test.go @@ -0,0 +1,42 @@ +package streaming + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/codec" + codecTypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/streaming/file" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/stretchr/testify/require" +) + +type fakeOptions struct{} + +func (f *fakeOptions) Get(string) interface{} { return nil } + +var ( + mockOptions = new(fakeOptions) + mockKeys = []sdk.StoreKey{sdk.NewKVStoreKey("mockKey1"), sdk.NewKVStoreKey("mockKey2")} + interfaceRegistry = codecTypes.NewInterfaceRegistry() + testMarshaller = codec.NewProtoCodec(interfaceRegistry) +) + +func TestStreamingServiceConstructor(t *testing.T) { + _, err := NewServiceConstructor("unexpectedName") + require.NotNil(t, err) + + constructor, err := NewServiceConstructor("file") + require.Nil(t, err) + var expectedType ServiceConstructor + require.IsType(t, expectedType, constructor) + + serv, err := constructor(mockOptions, mockKeys, testMarshaller) + require.Nil(t, err) + require.IsType(t, &file.StreamingService{}, serv) + listeners := serv.Listeners() + for _, key := range mockKeys { + _, ok := listeners[key] + require.True(t, ok) + } +} From c6ad1ed08f6acc9c4399dae2e6fc695236884003 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 22 Feb 2021 10:44:27 -0600 Subject: [PATCH 19/46] example toml configuration --- streaming/file/example_config.toml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 streaming/file/example_config.toml diff --git a/streaming/file/example_config.toml b/streaming/file/example_config.toml new file mode 100644 index 000000000000..042391a7703e --- /dev/null +++ b/streaming/file/example_config.toml @@ -0,0 +1,10 @@ +[store] + streamers = [ # if len(streamers) > 0 we are streaming + "file", + ] + +[streamers] + [streamers.file] + keys = ["list", "of", "store", "keys", "we", "want", "to", "expose", "for", "this", "streaming", "service"] + writeDir = "path to the write directory" + prefix = "optional prefix to prepend to the generated file names" \ No newline at end of file From 7198289374e0aa596ef20112131417093322844b Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 22 Feb 2021 11:57:45 -0600 Subject: [PATCH 20/46] ci/linting fixes --- baseapp/options.go | 4 ++-- streaming/file/service.go | 21 +++++++++++++++------ streaming/file/service_test.go | 34 +++++++++++++++++----------------- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/baseapp/options.go b/baseapp/options.go index 53ab17930ace..db32b1f813a7 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -240,9 +240,9 @@ func (app *BaseApp) SetInterfaceRegistry(registry types.InterfaceRegistry) { // SetStreamingService is used to set a streaming service into the BaseApp hooks and load the listeners into the multistore func (app *BaseApp) SetStreamingService(s sdk.StreamingService) { - // set the listeners for each StoreKey + // add the listeners for each StoreKey for key, lis := range s.Listeners() { - app.cms.SetListeners(key, lis) + app.cms.AddListeners(key, lis) } // register the streaming service hooks within the BaseApp // BaseApp will pass BeginBlock, DeliverTx, and EndBlock requests and responses to the streaming services to update their ABCI context using these hooks diff --git a/streaming/file/service.go b/streaming/file/service.go index 3e41601fad79..9ada1baafab9 100644 --- a/streaming/file/service.go +++ b/streaming/file/service.go @@ -46,28 +46,28 @@ type StreamingService struct { currentTxIndex int64 // the index of the current tx } -// intermediateWriter is used so that we do not need to update the underlying io.Writer inside the StoreKVPairWriteListener +// IntermediateWriter is used so that we do not need to update the underlying io.Writer inside the StoreKVPairWriteListener // everytime we begin writing to a new file -type intermediateWriter struct { +type IntermediateWriter struct { outChan chan<- []byte } // NewIntermediateWriter create an instance of an intermediateWriter that sends to the provided channel -func NewIntermediateWriter(outChan chan<- []byte) *intermediateWriter { - return &intermediateWriter{ +func NewIntermediateWriter(outChan chan<- []byte) *IntermediateWriter { + return &IntermediateWriter{ outChan: outChan, } } // Write satisfies io.Writer -func (iw *intermediateWriter) Write(b []byte) (int, error) { +func (iw *IntermediateWriter) Write(b []byte) (int, error) { iw.outChan <- b return len(b), nil } // NewStreamingService creates a new StreamingService for the provided writeDir, (optional) filePrefix, and storeKeys func NewStreamingService(writeDir, filePrefix string, storeKeys []sdk.StoreKey, m codec.BinaryMarshaler) (*StreamingService, error) { - listenChan := make(chan []byte, 0) + listenChan := make(chan []byte) iw := NewIntermediateWriter(listenChan) listener := types.NewStoreKVPairWriteListener(iw, m) listeners := make(map[sdk.StoreKey][]types.WriteListener, len(storeKeys)) @@ -122,6 +122,9 @@ func (fss *StreamingService) ListenBeginBlock(ctx sdk.Context, req abci.RequestB fss.stateCache = nil // write res to file lengthPrefixedResBytes, err := fss.marshaller.MarshalBinaryLengthPrefixed(&res) + if err != nil { + return err + } if _, err = dstFile.Write(lengthPrefixedResBytes); err != nil { return err } @@ -166,6 +169,9 @@ func (fss *StreamingService) ListenDeliverTx(ctx sdk.Context, req abci.RequestDe fss.stateCache = nil // write res to file lengthPrefixedResBytes, err := fss.marshaller.MarshalBinaryLengthPrefixed(&res) + if err != nil { + return err + } if _, err = dstFile.Write(lengthPrefixedResBytes); err != nil { return err } @@ -209,6 +215,9 @@ func (fss *StreamingService) ListenEndBlock(ctx sdk.Context, req abci.RequestEnd fss.stateCache = nil // write res to file lengthPrefixedResBytes, err := fss.marshaller.MarshalBinaryLengthPrefixed(&res) + if err != nil { + return err + } if _, err = dstFile.Write(lengthPrefixedResBytes); err != nil { return err } diff --git a/streaming/file/service_test.go b/streaming/file/service_test.go index 9c989ca03533..0f1085d883cd 100644 --- a/streaming/file/service_test.go +++ b/streaming/file/service_test.go @@ -108,7 +108,7 @@ var ( func TestIntermediateWriter(t *testing.T) { outChan := make(chan []byte, 0) iw := NewIntermediateWriter(outChan) - require.IsType(t, &intermediateWriter{}, iw) + require.IsType(t, &IntermediateWriter{}, iw) testBytes := []byte{1, 2, 3, 4, 5} var length int var err error @@ -152,7 +152,7 @@ func testListenBeginBlock(t *testing.T) { expectedBeginBlockResBytes, err := testMarshaller.MarshalBinaryBare(&testBeginBlockRes) require.Nil(t, err) - // Write state changes + // write state changes testListener1.OnWrite(mockStoreKey1, true, mockKey1, mockValue1) testListener2.OnWrite(mockStoreKey2, true, mockKey2, mockValue2) testListener1.OnWrite(mockStoreKey1, true, mockKey3, mockValue3) @@ -180,16 +180,16 @@ func testListenBeginBlock(t *testing.T) { }) require.Nil(t, err) - // Send the ABCI messages + // send the ABCI messages err = testStreamingService.ListenBeginBlock(emptyContext, testBeginBlockReq, testBeginBlockRes) require.Nil(t, err) - // Load the file, checking that it was created with the expected name + // load the file, checking that it was created with the expected name fileName := fmt.Sprintf("%s-block-%d-begin", testPrefix, testBeginBlockReq.GetHeader().Height) fileBytes, err := readInFile(fileName) require.Nil(t, err) - // Segment the file into the separate gRPC messages and check the correctness of each + // segment the file into the separate gRPC messages and check the correctness of each segments, err := segmentBytes(fileBytes) require.Nil(t, err) require.Equal(t, 5, len(segments)) @@ -206,7 +206,7 @@ func testListenDeliverTx1(t *testing.T) { expectedDeliverTxRes1Bytes, err := testMarshaller.MarshalBinaryBare(&testDeliverTxRes1) require.Nil(t, err) - // Write state changes + // write state changes testListener1.OnWrite(mockStoreKey1, true, mockKey1, mockValue1) testListener2.OnWrite(mockStoreKey2, true, mockKey2, mockValue2) testListener1.OnWrite(mockStoreKey2, true, mockKey3, mockValue3) @@ -234,16 +234,16 @@ func testListenDeliverTx1(t *testing.T) { }) require.Nil(t, err) - // Send the ABCI messages + // send the ABCI messages err = testStreamingService.ListenDeliverTx(emptyContext, testDeliverTxReq1, testDeliverTxRes1) require.Nil(t, err) - // Load the file, checking that it was created with the expected name + // load the file, checking that it was created with the expected name fileName := fmt.Sprintf("%s-block-%d-tx-%d", testPrefix, testBeginBlockReq.GetHeader().Height, 0) fileBytes, err := readInFile(fileName) require.Nil(t, err) - // Segment the file into the separate gRPC messages and check the correctness of each + // segment the file into the separate gRPC messages and check the correctness of each segments, err := segmentBytes(fileBytes) require.Nil(t, err) require.Equal(t, 5, len(segments)) @@ -260,7 +260,7 @@ func testListenDeliverTx2(t *testing.T) { expectedDeliverTxRes2Bytes, err := testMarshaller.MarshalBinaryBare(&testDeliverTxRes2) require.Nil(t, err) - // Write state changes + // write state changes testListener1.OnWrite(mockStoreKey2, true, mockKey1, mockValue1) testListener2.OnWrite(mockStoreKey1, true, mockKey2, mockValue2) testListener1.OnWrite(mockStoreKey2, true, mockKey3, mockValue3) @@ -288,16 +288,16 @@ func testListenDeliverTx2(t *testing.T) { }) require.Nil(t, err) - // Send the ABCI messages + // send the ABCI messages err = testStreamingService.ListenDeliverTx(emptyContext, testDeliverTxReq2, testDeliverTxRes2) require.Nil(t, err) - // Load the file, checking that it was created with the expected name + // load the file, checking that it was created with the expected name fileName := fmt.Sprintf("%s-block-%d-tx-%d", testPrefix, testBeginBlockReq.GetHeader().Height, 1) fileBytes, err := readInFile(fileName) require.Nil(t, err) - // Segment the file into the separate gRPC messages and check the correctness of each + // segment the file into the separate gRPC messages and check the correctness of each segments, err := segmentBytes(fileBytes) require.Nil(t, err) require.Equal(t, 5, len(segments)) @@ -314,7 +314,7 @@ func testListenEndBlock(t *testing.T) { expectedEndBlockResBytes, err := testMarshaller.MarshalBinaryBare(&testEndBlockRes) require.Nil(t, err) - // Write state changes + // write state changes testListener1.OnWrite(mockStoreKey1, true, mockKey1, mockValue1) testListener2.OnWrite(mockStoreKey1, true, mockKey2, mockValue2) testListener1.OnWrite(mockStoreKey2, true, mockKey3, mockValue3) @@ -342,16 +342,16 @@ func testListenEndBlock(t *testing.T) { }) require.Nil(t, err) - // Send the ABCI messages + // send the ABCI messages err = testStreamingService.ListenEndBlock(emptyContext, testEndBlockReq, testEndBlockRes) require.Nil(t, err) - // Load the file, checking that it was created with the expected name + // load the file, checking that it was created with the expected name fileName := fmt.Sprintf("%s-block-%d-end", testPrefix, testEndBlockReq.Height) fileBytes, err := readInFile(fileName) require.Nil(t, err) - // Segment the file into the separate gRPC messages and check the correctness of each + // segment the file into the separate gRPC messages and check the correctness of each segments, err := segmentBytes(fileBytes) require.Nil(t, err) require.Equal(t, 5, len(segments)) From 2fffbd0a8962b1f3014e004a7ac61a6e5ecd9d39 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 1 Mar 2021 09:41:15 -0600 Subject: [PATCH 21/46] simapp integration --- docs/architecture/adr-038-state-listening.md | 8 ++--- simapp/app.go | 34 ++++++++++++++++++++ streaming/constructor.go | 2 +- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/docs/architecture/adr-038-state-listening.md b/docs/architecture/adr-038-state-listening.md index 00f63ebfe94b..d9864bd0f3a1 100644 --- a/docs/architecture/adr-038-state-listening.md +++ b/docs/architecture/adr-038-state-listening.md @@ -564,8 +564,8 @@ func NewSimApp( listeners := cast.ToStringSlice(appOpts.Get("store.streamers")) for _, listenerName := range listeners { // get the store keys allowed to be exposed for this streaming service/state listeners - exposeKeyStrs := cast.ToStringSlice(appOpts.Get(fmt.Sprintf("streamers.%s.keys", listenerName)) - exposeStoreKeys = make([]storeTypes.StoreKey, 0, len(exposeKeyStrs)) + exposeKeyStrs := cast.ToStringSlice(appOpts.Get(fmt.Sprintf("streamers.%s.keys", listenerName))) + exposeStoreKeys := make([]storeTypes.StoreKey, 0, len(exposeKeyStrs)) for _, keyStr := range exposeKeyStrs { if storeKey, ok := keys[keyStr]; ok { exposeStoreKeys = append(exposeStoreKeys, storeKey) @@ -577,7 +577,7 @@ func NewSimApp( tmos.Exit(err.Error()) // or continue? } // generate the streaming service using the constructor, appOptions, and the StoreKeys we want to expose - streamingService, err := constructor(appOpts, exposeStoreKeys) + streamingService, err := constructor(appOpts, exposeStoreKeys, appCodec) if err != nil { tmos.Exit(err.Error()) } @@ -585,7 +585,7 @@ func NewSimApp( bApp.RegisterStreamingService(streamingService) // waitgroup and quit channel for optional shutdown coordination of the streaming service wg := new(sync.WaitGroup) - quitChan := new(chan struct{})) + quitChan := make(chan struct{})) // kick off the background streaming service loop streamingService.Stream(wg, quitChan) // maybe this should be done from inside BaseApp instead? } diff --git a/simapp/app.go b/simapp/app.go index 9197cd1b0765..afcfb609f753 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -2,10 +2,14 @@ package simapp import ( "encoding/json" + "fmt" "io" "net/http" "os" "path/filepath" + "sync" + + "github.com/cosmos/cosmos-sdk/streaming" "github.com/gorilla/mux" "github.com/rakyll/statik/fs" @@ -210,6 +214,36 @@ func NewSimApp( tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) + // configure state listening capabilities using AppOptions + listeners := cast.ToStringSlice(appOpts.Get("store.streamers")) + for _, listenerName := range listeners { + // get the store keys allowed to be exposed for this streaming service/state listeners + exposeKeyStrs := cast.ToStringSlice(appOpts.Get(fmt.Sprintf("streamers.%s.keys", listenerName))) + exposeStoreKeys := make([]sdk.StoreKey, 0, len(exposeKeyStrs)) + for _, keyStr := range exposeKeyStrs { + if storeKey, ok := keys[keyStr]; ok { + exposeStoreKeys = append(exposeStoreKeys, storeKey) + } + } + // get the constructor for this listener name + constructor, err := streaming.NewServiceConstructor(listenerName) + if err != nil { + tmos.Exit(err.Error()) // or continue? + } + // generate the streaming service using the constructor, appOptions, and the StoreKeys we want to expose + streamingService, err := constructor(appOpts, exposeStoreKeys, appCodec) + if err != nil { + tmos.Exit(err.Error()) + } + // register the streaming service with the BaseApp + bApp.SetStreamingService(streamingService) + // waitgroup and quit channel for optional shutdown coordination of the streaming service + wg := new(sync.WaitGroup) + quitChan := make(chan struct{}) + // kick off the background streaming service loop + streamingService.Stream(wg, quitChan) // maybe this should be done from inside BaseApp instead? + } + app := &SimApp{ BaseApp: bApp, legacyAmino: legacyAmino, diff --git a/streaming/constructor.go b/streaming/constructor.go index 28c60b50c762..3f0816b75b13 100644 --- a/streaming/constructor.go +++ b/streaming/constructor.go @@ -55,7 +55,7 @@ func NewServiceConstructor(name string) (ServiceConstructor, error) { if ssType == Unknown { return nil, fmt.Errorf("unrecognized streaming service name %s", name) } - if constructor, ok := ServiceConstructorLookupTable[ssType]; ok { + if constructor, ok := ServiceConstructorLookupTable[ssType]; ok && constructor != nil { return constructor, nil } return nil, fmt.Errorf("streaming service constructor of type %s not found", ssType.String()) From d398cbfa1b309dc6950ce475e48239977f73c971 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Wed, 3 Mar 2021 09:38:24 -0600 Subject: [PATCH 22/46] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18bfb37b1438..edb9b89678e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#9533](https://github.com/cosmos/cosmos-sdk/pull/9533) Added a new gRPC method, `DenomOwners`, in `x/bank` to query for all account holders of a specific denomination. * (bank) [\#9618](https://github.com/cosmos/cosmos-sdk/pull/9618) Update bank.Metadata: add URI and URIHash attributes. +* (store) [\#8664](https://github.com/cosmos/cosmos-sdk/pull/8664) Implementation of ADR-038 file StreamingService ### API Breaking Changes @@ -210,7 +211,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#8460](https://github.com/cosmos/cosmos-sdk/pull/8460) Ensure b.ReportAllocs() in all the benchmarks * [\#8461](https://github.com/cosmos/cosmos-sdk/pull/8461) Fix upgrade tx commands not showing up in CLI - ### Bug Fixes * (x/gov) [\#8813](https://github.com/cosmos/cosmos-sdk/pull/8813) fix `{appd} q gov deposits [proposal-id]`, `GET /gov/proposals/{proposal_id}/deposits` to include initial deposit. From e0a1f326e696c6f89f67633bd464865d93077b1d Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Wed, 3 Mar 2021 10:54:38 -0600 Subject: [PATCH 23/46] documentation for configuring and using a StreamingService --- simapp/app.go | 2 +- streaming/README.md | 64 ++++++++++++++++++++++++ streaming/{file => }/example_config.toml | 2 +- 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 streaming/README.md rename streaming/{file => }/example_config.toml (83%) diff --git a/simapp/app.go b/simapp/app.go index afcfb609f753..67bf01ad3560 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -241,7 +241,7 @@ func NewSimApp( wg := new(sync.WaitGroup) quitChan := make(chan struct{}) // kick off the background streaming service loop - streamingService.Stream(wg, quitChan) // maybe this should be done from inside BaseApp instead? + streamingService.Stream(wg, quitChan) } app := &SimApp{ diff --git a/streaming/README.md b/streaming/README.md new file mode 100644 index 000000000000..17f17a82e468 --- /dev/null +++ b/streaming/README.md @@ -0,0 +1,64 @@ +# State Streaming Service +This package contains the constructors for the `StreamingService`s used to write state changes out from individual KVStores to a +file or stream, as described in [ADR-038](../docs/architecture/adr-038-state-listening.md) and defined in [types/streaming.go](../types/streaming.go). +The child directories contain the implementations for specific output destinations. + +Currently, a `StreamingService` implementation that writes state changes out to files is supported, in the future support for additional +output destinations can be added. + +The `StreamingService` is configured from within an App using the `AppOptions` loaded from a .toml file: + +```toml +[store] + streamers = [ # if len(streamers) > 0 we are streaming + "file", # name of the streaming service, used by constructor + ] + +[streamers] + [streamers.file] + keys = ["list", "of", "store", "keys", "we", "want", "to", "expose", "for", "this", "streaming", "service"] + writeDir = "path to the write directory" + prefix = "optional prefix to prepend to the generated file names" +``` + +`store.streamers` contains a list of the names of the `StreamingService` implementations to employ which are used by `NewServiceConstructor` +to return the `ServiceConstructor` for that particular implementation: + + +```go +listeners := cast.ToStringSlice(appOpts.Get("store.streamers")) +for _, listenerName := range listeners { + constructor, err := NewServiceConstructor(listenerName) + if err != nil { + // handle error + } +} +``` + +`streamers` contains a mapping of the specific `StreamingService` implementation name to the configuration parameters for that specific service. +`streamers.x.keys` contains the list of `StoreKey` names for the KVStores to expose using this service and is required by every type of `StreamingService`, +other options will be specific to the implementation. In the case of the file streaming service, `streamers.file.writeDir` contains the path to the +directory to write the files to, and `streamers.file.prefix` contains an optional prefix to prepend to the output files to prevent potential collisions +with other App `StreamingService` output files. + +The `ServiceConstructor` accepts `AppOptions`, the store keys collected using `streamers.x.keys`, a `BinaryMarshaller` and +returns a `StreamingService` implementation. The `AppOptions` are passed in to provide access to any implementation specific configuration options, +e.g. in the case of the file streaming service the `streamers.file.writeDir` and `streamers.file.prefix`. + +```go +streamingService, err := constructor(appOpts, exposeStoreKeys, appCodec) +if err != nil { + // handler error +} +``` + +The returned `StreamingService` is then loaded into the BaseApp using the BaseApp's `SetStreamingService` method. +The `Stream` method is called on the service to begin the streaming process. Depending on the implementation this process +may be synchronous or asynchronous with the message processing of the state machine. For the file streaming service the process is synchronous. + +```go +bApp.SetStreamingService(streamingService) +wg := new(sync.WaitGroup) +quitChan := make(chan struct{}) +streamingService.Stream(wg, quitChan) +``` \ No newline at end of file diff --git a/streaming/file/example_config.toml b/streaming/example_config.toml similarity index 83% rename from streaming/file/example_config.toml rename to streaming/example_config.toml index 042391a7703e..1e89d004efc4 100644 --- a/streaming/file/example_config.toml +++ b/streaming/example_config.toml @@ -1,6 +1,6 @@ [store] streamers = [ # if len(streamers) > 0 we are streaming - "file", + "file", # name of the streaming service, used by constructor ] [streamers] From caf96a0f97a96a6627677f9c897416879d69c49a Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Fri, 5 Mar 2021 12:38:34 -0600 Subject: [PATCH 24/46] update to use new KVStorePair type --- streaming/file/service_test.go | 48 +++++++++++++++++----------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/streaming/file/service_test.go b/streaming/file/service_test.go index 0f1085d883cd..4fb240392061 100644 --- a/streaming/file/service_test.go +++ b/streaming/file/service_test.go @@ -153,30 +153,30 @@ func testListenBeginBlock(t *testing.T) { require.Nil(t, err) // write state changes - testListener1.OnWrite(mockStoreKey1, true, mockKey1, mockValue1) - testListener2.OnWrite(mockStoreKey2, true, mockKey2, mockValue2) - testListener1.OnWrite(mockStoreKey1, true, mockKey3, mockValue3) + testListener1.OnWrite(mockStoreKey1, mockKey1, mockValue1, false) + testListener2.OnWrite(mockStoreKey2, mockKey2, mockValue2, false) + testListener1.OnWrite(mockStoreKey1, mockKey3, mockValue3, false) // expected KV pairs expectedKVPair1, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ StoreKey: mockStoreKey1.Name(), Key: mockKey1, Value: mockValue1, - Set: true, + Delete: false, }) require.Nil(t, err) expectedKVPair2, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ StoreKey: mockStoreKey2.Name(), Key: mockKey2, Value: mockValue2, - Set: true, + Delete: false, }) require.Nil(t, err) expectedKVPair3, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ StoreKey: mockStoreKey1.Name(), Key: mockKey3, Value: mockValue3, - Set: true, + Delete: false, }) require.Nil(t, err) @@ -207,30 +207,30 @@ func testListenDeliverTx1(t *testing.T) { require.Nil(t, err) // write state changes - testListener1.OnWrite(mockStoreKey1, true, mockKey1, mockValue1) - testListener2.OnWrite(mockStoreKey2, true, mockKey2, mockValue2) - testListener1.OnWrite(mockStoreKey2, true, mockKey3, mockValue3) + testListener1.OnWrite(mockStoreKey1, mockKey1, mockValue1, false) + testListener2.OnWrite(mockStoreKey2, mockKey2, mockValue2, false) + testListener1.OnWrite(mockStoreKey2, mockKey3, mockValue3, false) // expected KV pairs expectedKVPair1, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ StoreKey: mockStoreKey1.Name(), Key: mockKey1, Value: mockValue1, - Set: true, + Delete: false, }) require.Nil(t, err) expectedKVPair2, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ StoreKey: mockStoreKey2.Name(), Key: mockKey2, Value: mockValue2, - Set: true, + Delete: false, }) require.Nil(t, err) expectedKVPair3, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ StoreKey: mockStoreKey2.Name(), Key: mockKey3, Value: mockValue3, - Set: true, + Delete: false, }) require.Nil(t, err) @@ -261,30 +261,30 @@ func testListenDeliverTx2(t *testing.T) { require.Nil(t, err) // write state changes - testListener1.OnWrite(mockStoreKey2, true, mockKey1, mockValue1) - testListener2.OnWrite(mockStoreKey1, true, mockKey2, mockValue2) - testListener1.OnWrite(mockStoreKey2, true, mockKey3, mockValue3) + testListener1.OnWrite(mockStoreKey2, mockKey1, mockValue1, false) + testListener2.OnWrite(mockStoreKey1, mockKey2, mockValue2, false) + testListener1.OnWrite(mockStoreKey2, mockKey3, mockValue3, false) // expected KV pairs expectedKVPair1, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ StoreKey: mockStoreKey2.Name(), Key: mockKey1, Value: mockValue1, - Set: true, + Delete: false, }) require.Nil(t, err) expectedKVPair2, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ StoreKey: mockStoreKey1.Name(), Key: mockKey2, Value: mockValue2, - Set: true, + Delete: false, }) require.Nil(t, err) expectedKVPair3, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ StoreKey: mockStoreKey2.Name(), Key: mockKey3, Value: mockValue3, - Set: true, + Delete: false, }) require.Nil(t, err) @@ -315,30 +315,30 @@ func testListenEndBlock(t *testing.T) { require.Nil(t, err) // write state changes - testListener1.OnWrite(mockStoreKey1, true, mockKey1, mockValue1) - testListener2.OnWrite(mockStoreKey1, true, mockKey2, mockValue2) - testListener1.OnWrite(mockStoreKey2, true, mockKey3, mockValue3) + testListener1.OnWrite(mockStoreKey1, mockKey1, mockValue1, false) + testListener2.OnWrite(mockStoreKey1, mockKey2, mockValue2, false) + testListener1.OnWrite(mockStoreKey2, mockKey3, mockValue3, false) // expected KV pairs expectedKVPair1, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ StoreKey: mockStoreKey1.Name(), Key: mockKey1, Value: mockValue1, - Set: true, + Delete: false, }) require.Nil(t, err) expectedKVPair2, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ StoreKey: mockStoreKey1.Name(), Key: mockKey2, Value: mockValue2, - Set: true, + Delete: false, }) require.Nil(t, err) expectedKVPair3, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ StoreKey: mockStoreKey2.Name(), Key: mockKey3, Value: mockValue3, - Set: true, + Delete: false, }) require.Nil(t, err) From 6fdb3c1d03338ae5e113302ae0ac3a0c781321e8 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 30 Mar 2021 13:13:10 -0500 Subject: [PATCH 25/46] fix double cache wrap issue; prefer wrapping with listener vs tracer --- store/cachemulti/store.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/store/cachemulti/store.go b/store/cachemulti/store.go index 05637a45ff16..7c100934c4bd 100644 --- a/store/cachemulti/store.go +++ b/store/cachemulti/store.go @@ -50,16 +50,14 @@ func NewFromKVStore( for key, store := range stores { var cacheWrapped types.CacheWrap - if cms.TracingEnabled() { + if cms.ListeningEnabled(key) { + cacheWrapped = store.CacheWrapWithListeners(key, cms.listeners[key]) + } else if cms.TracingEnabled() { cacheWrapped = store.CacheWrapWithTrace(cms.traceWriter, cms.traceContext) } else { cacheWrapped = store.CacheWrap() } - if cms.ListeningEnabled(key) { - cms.stores[key] = cacheWrapped.CacheWrapWithListeners(key, cms.listeners[key]) - } else { - cms.stores[key] = cacheWrapped - } + cms.stores[key] = cacheWrapped } return cms From 921f28990a8afb16388f2a2254e0c1b80532c2f8 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Fri, 16 Apr 2021 08:48:46 -0500 Subject: [PATCH 26/46] review refactor --- baseapp/baseapp.go | 2 +- baseapp/options.go | 2 +- {types => baseapp}/streaming.go | 13 +++++++------ simapp/app.go | 3 +-- .../updated_config.toml | 0 {streaming => store/streaming}/README.md | 0 {streaming => store/streaming}/constructor.go | 7 ++++--- {streaming => store/streaming}/constructor_test.go | 2 +- store/streaming/example_config.toml | 10 ++++++++++ {streaming => store/streaming}/file/service.go | 3 ++- {streaming => store/streaming}/file/service_test.go | 0 11 files changed, 27 insertions(+), 15 deletions(-) rename {types => baseapp}/streaming.go (65%) rename streaming/example_config.toml => simapp/updated_config.toml (100%) rename {streaming => store/streaming}/README.md (100%) rename {streaming => store/streaming}/constructor.go (88%) rename {streaming => store/streaming}/constructor_test.go (95%) create mode 100644 store/streaming/example_config.toml rename {streaming => store/streaming}/file/service.go (99%) rename {streaming => store/streaming}/file/service_test.go (100%) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 11601aaf0da7..81d603f6e677 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -137,7 +137,7 @@ type BaseApp struct { // nolint: maligned // hooked services // these hooks will have the ABCI messages routed through them - hooks []sdk.Hook + hooks []Hook } // NewBaseApp returns a reference to an initialized BaseApp. It accepts a diff --git a/baseapp/options.go b/baseapp/options.go index db32b1f813a7..540ca9dfdaa8 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -239,7 +239,7 @@ func (app *BaseApp) SetInterfaceRegistry(registry types.InterfaceRegistry) { } // SetStreamingService is used to set a streaming service into the BaseApp hooks and load the listeners into the multistore -func (app *BaseApp) SetStreamingService(s sdk.StreamingService) { +func (app *BaseApp) SetStreamingService(s StreamingService) { // add the listeners for each StoreKey for key, lis := range s.Listeners() { app.cms.AddListeners(key, lis) diff --git a/types/streaming.go b/baseapp/streaming.go similarity index 65% rename from types/streaming.go rename to baseapp/streaming.go index f1dcfac6ecd3..9265313d463f 100644 --- a/types/streaming.go +++ b/baseapp/streaming.go @@ -1,21 +1,22 @@ -package types +package baseapp import ( "sync" abci "github.com/tendermint/tendermint/abci/types" - "github.com/cosmos/cosmos-sdk/store/types" + store "github.com/cosmos/cosmos-sdk/store/types" + "github.com/cosmos/cosmos-sdk/types" ) // Hook interface used to hook into the ABCI message processing of the BaseApp type Hook interface { // update the streaming service with the latest BeginBlock messages - ListenBeginBlock(ctx Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) error + ListenBeginBlock(ctx types.Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) error // update the steaming service with the latest EndBlock messages - ListenEndBlock(ctx Context, req abci.RequestEndBlock, res abci.ResponseEndBlock) error + ListenEndBlock(ctx types.Context, req abci.RequestEndBlock, res abci.ResponseEndBlock) error // update the steaming service with the latest DeliverTx messages - ListenDeliverTx(ctx Context, req abci.RequestDeliverTx, res abci.ResponseDeliverTx) error + ListenDeliverTx(ctx types.Context, req abci.RequestDeliverTx, res abci.ResponseDeliverTx) error } // StreamingService interface for registering WriteListeners with the BaseApp and updating the service with the ABCI messages using the hooks @@ -23,7 +24,7 @@ type StreamingService interface { // streaming service loop, awaits kv pairs and writes them to some destination stream or file Stream(wg *sync.WaitGroup, quitChan <-chan struct{}) // returns the streaming service's listeners for the BaseApp to register - Listeners() map[StoreKey][]types.WriteListener + Listeners() map[types.StoreKey][]store.WriteListener // interface for hooking into the ABCI messages from inside the BaseApp Hook } diff --git a/simapp/app.go b/simapp/app.go index 67bf01ad3560..ec90fd5ac9c3 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -9,8 +9,6 @@ import ( "path/filepath" "sync" - "github.com/cosmos/cosmos-sdk/streaming" - "github.com/gorilla/mux" "github.com/rakyll/statik/fs" "github.com/spf13/cast" @@ -29,6 +27,7 @@ import ( "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" + "github.com/cosmos/cosmos-sdk/store/streaming" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" diff --git a/streaming/example_config.toml b/simapp/updated_config.toml similarity index 100% rename from streaming/example_config.toml rename to simapp/updated_config.toml diff --git a/streaming/README.md b/store/streaming/README.md similarity index 100% rename from streaming/README.md rename to store/streaming/README.md diff --git a/streaming/constructor.go b/store/streaming/constructor.go similarity index 88% rename from streaming/constructor.go rename to store/streaming/constructor.go index 3f0816b75b13..b7e9e714bc46 100644 --- a/streaming/constructor.go +++ b/store/streaming/constructor.go @@ -4,16 +4,17 @@ import ( "fmt" "strings" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" serverTypes "github.com/cosmos/cosmos-sdk/server/types" - "github.com/cosmos/cosmos-sdk/streaming/file" + "github.com/cosmos/cosmos-sdk/store/streaming/file" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cast" ) // ServiceConstructor is used to construct a streaming service -type ServiceConstructor func(opts serverTypes.AppOptions, keys []sdk.StoreKey, marshaller codec.BinaryMarshaler) (sdk.StreamingService, error) +type ServiceConstructor func(opts serverTypes.AppOptions, keys []sdk.StoreKey, marshaller codec.BinaryMarshaler) (baseapp.StreamingService, error) // ServiceType enum for specifying the type of StreamingService type ServiceType int @@ -62,7 +63,7 @@ func NewServiceConstructor(name string) (ServiceConstructor, error) { } // FileStreamingConstructor is the streaming.ServiceConstructor function for creating a FileStreamingService -func FileStreamingConstructor(opts serverTypes.AppOptions, keys []sdk.StoreKey, marshaller codec.BinaryMarshaler) (sdk.StreamingService, error) { +func FileStreamingConstructor(opts serverTypes.AppOptions, keys []sdk.StoreKey, marshaller codec.BinaryMarshaler) (baseapp.StreamingService, error) { filePrefix := cast.ToString(opts.Get("streamers.file.prefix")) fileDir := cast.ToString(opts.Get("streamers.file.writeDir")) return file.NewStreamingService(fileDir, filePrefix, keys, marshaller) diff --git a/streaming/constructor_test.go b/store/streaming/constructor_test.go similarity index 95% rename from streaming/constructor_test.go rename to store/streaming/constructor_test.go index a6b3f4f842cd..02b4f3bd857d 100644 --- a/streaming/constructor_test.go +++ b/store/streaming/constructor_test.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codecTypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/streaming/file" + "github.com/cosmos/cosmos-sdk/store/streaming/file" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" diff --git a/store/streaming/example_config.toml b/store/streaming/example_config.toml new file mode 100644 index 000000000000..1e89d004efc4 --- /dev/null +++ b/store/streaming/example_config.toml @@ -0,0 +1,10 @@ +[store] + streamers = [ # if len(streamers) > 0 we are streaming + "file", # name of the streaming service, used by constructor + ] + +[streamers] + [streamers.file] + keys = ["list", "of", "store", "keys", "we", "want", "to", "expose", "for", "this", "streaming", "service"] + writeDir = "path to the write directory" + prefix = "optional prefix to prepend to the generated file names" \ No newline at end of file diff --git a/streaming/file/service.go b/store/streaming/file/service.go similarity index 99% rename from streaming/file/service.go rename to store/streaming/file/service.go index 9ada1baafab9..fbec361d4807 100644 --- a/streaming/file/service.go +++ b/store/streaming/file/service.go @@ -10,6 +10,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -32,7 +33,7 @@ subsequent state changes are written out to this file until the next `BeginBlock the length-prefixed protobuf encoded `EndBlock` request is written, and the response is written at the tail. */ -var _ sdk.StreamingService = &StreamingService{} +var _ baseapp.StreamingService = &StreamingService{} // StreamingService is a concrete implementation of StreamingService that writes state changes out to files type StreamingService struct { diff --git a/streaming/file/service_test.go b/store/streaming/file/service_test.go similarity index 100% rename from streaming/file/service_test.go rename to store/streaming/file/service_test.go From d5bbb0a9df06576bf9a9dcb5febf6bf5157f60cf Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Fri, 16 Apr 2021 10:57:56 -0500 Subject: [PATCH 27/46] fix linting --- store/cachemulti/store.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/store/cachemulti/store.go b/store/cachemulti/store.go index 7c100934c4bd..5f3f4b4a3a4d 100644 --- a/store/cachemulti/store.go +++ b/store/cachemulti/store.go @@ -50,11 +50,12 @@ func NewFromKVStore( for key, store := range stores { var cacheWrapped types.CacheWrap - if cms.ListeningEnabled(key) { + switch { + case cms.ListeningEnabled(key): cacheWrapped = store.CacheWrapWithListeners(key, cms.listeners[key]) - } else if cms.TracingEnabled() { + case cms.TracingEnabled(): cacheWrapped = store.CacheWrapWithTrace(cms.traceWriter, cms.traceContext) - } else { + default: cacheWrapped = store.CacheWrap() } cms.stores[key] = cacheWrapped From 901e62f47a38f2849c64ef44db1f655a149b2bc9 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 20 Apr 2021 15:08:30 -0500 Subject: [PATCH 28/46] review fixes --- simapp/app.go | 31 ++------------------------- simapp/updated_config.toml | 10 --------- store/streaming/README.md | 2 +- store/streaming/constructor.go | 39 ++++++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 40 deletions(-) delete mode 100644 simapp/updated_config.toml diff --git a/simapp/app.go b/simapp/app.go index ec90fd5ac9c3..b02be5dc7035 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -2,12 +2,10 @@ package simapp import ( "encoding/json" - "fmt" "io" "net/http" "os" "path/filepath" - "sync" "github.com/gorilla/mux" "github.com/rakyll/statik/fs" @@ -214,33 +212,8 @@ func NewSimApp( memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) // configure state listening capabilities using AppOptions - listeners := cast.ToStringSlice(appOpts.Get("store.streamers")) - for _, listenerName := range listeners { - // get the store keys allowed to be exposed for this streaming service/state listeners - exposeKeyStrs := cast.ToStringSlice(appOpts.Get(fmt.Sprintf("streamers.%s.keys", listenerName))) - exposeStoreKeys := make([]sdk.StoreKey, 0, len(exposeKeyStrs)) - for _, keyStr := range exposeKeyStrs { - if storeKey, ok := keys[keyStr]; ok { - exposeStoreKeys = append(exposeStoreKeys, storeKey) - } - } - // get the constructor for this listener name - constructor, err := streaming.NewServiceConstructor(listenerName) - if err != nil { - tmos.Exit(err.Error()) // or continue? - } - // generate the streaming service using the constructor, appOptions, and the StoreKeys we want to expose - streamingService, err := constructor(appOpts, exposeStoreKeys, appCodec) - if err != nil { - tmos.Exit(err.Error()) - } - // register the streaming service with the BaseApp - bApp.SetStreamingService(streamingService) - // waitgroup and quit channel for optional shutdown coordination of the streaming service - wg := new(sync.WaitGroup) - quitChan := make(chan struct{}) - // kick off the background streaming service loop - streamingService.Stream(wg, quitChan) + if _, _, err := streaming.LoadStreamingServices(bApp, appOpts, appCodec, keys); err != nil { + tmos.Exit(err.Error()) } app := &SimApp{ diff --git a/simapp/updated_config.toml b/simapp/updated_config.toml deleted file mode 100644 index 1e89d004efc4..000000000000 --- a/simapp/updated_config.toml +++ /dev/null @@ -1,10 +0,0 @@ -[store] - streamers = [ # if len(streamers) > 0 we are streaming - "file", # name of the streaming service, used by constructor - ] - -[streamers] - [streamers.file] - keys = ["list", "of", "store", "keys", "we", "want", "to", "expose", "for", "this", "streaming", "service"] - writeDir = "path to the write directory" - prefix = "optional prefix to prepend to the generated file names" \ No newline at end of file diff --git a/store/streaming/README.md b/store/streaming/README.md index 17f17a82e468..f0ecccd48939 100644 --- a/store/streaming/README.md +++ b/store/streaming/README.md @@ -6,7 +6,7 @@ The child directories contain the implementations for specific output destinatio Currently, a `StreamingService` implementation that writes state changes out to files is supported, in the future support for additional output destinations can be added. -The `StreamingService` is configured from within an App using the `AppOptions` loaded from a .toml file: +The `StreamingService` is configured from within an App using the `AppOptions` loaded from the app.toml file: ```toml [store] diff --git a/store/streaming/constructor.go b/store/streaming/constructor.go index b7e9e714bc46..98a85c20a2ef 100644 --- a/store/streaming/constructor.go +++ b/store/streaming/constructor.go @@ -3,6 +3,7 @@ package streaming import ( "fmt" "strings" + "sync" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" @@ -68,3 +69,41 @@ func FileStreamingConstructor(opts serverTypes.AppOptions, keys []sdk.StoreKey, fileDir := cast.ToString(opts.Get("streamers.file.writeDir")) return file.NewStreamingService(fileDir, filePrefix, keys, marshaller) } + +// LoadStreamingServices is a function for loading StreamingServices onto the BaseApp using the provided AppOptions, codec, and keys +// It returns the WaitGroup and quit channel used to synchronize with the streaming services and any error that occurs during the setup +func LoadStreamingServices(bApp *baseapp.BaseApp, appOpts serverTypes.AppOptions, appCodec codec.Marshaler, keys map[string]*sdk.KVStoreKey) (*sync.WaitGroup, chan struct{}, error) { + // waitgroup and quit channel for optional shutdown coordination of the streaming service(s) + wg := new(sync.WaitGroup) + quitChan := make(chan struct{}) + // configure state listening capabilities using AppOptions + streamers := cast.ToStringSlice(appOpts.Get("store.streamers")) + for _, streamerName := range streamers { + // get the store keys allowed to be exposed for this streaming service + exposeKeyStrs := cast.ToStringSlice(appOpts.Get(fmt.Sprintf("streamers.%s.keys", streamerName))) + exposeStoreKeys := make([]sdk.StoreKey, 0, len(exposeKeyStrs)) + for _, keyStr := range exposeKeyStrs { + if storeKey, ok := keys[keyStr]; ok { + exposeStoreKeys = append(exposeStoreKeys, storeKey) + } + } + // get the constructor for this streamer name + constructor, err := NewServiceConstructor(streamerName) + if err != nil { + // close the quitChan to shutdown any services we may have already spun up before hitting the error on this one + close(quitChan) + return nil, nil, err + } + // generate the streaming service using the constructor, appOptions, and the StoreKeys we want to expose + streamingService, err := constructor(appOpts, exposeStoreKeys, appCodec) + if err != nil { + close(quitChan) + return nil, nil, err + } + // register the streaming service with the BaseApp + bApp.SetStreamingService(streamingService) + // kick off the background streaming service loop + streamingService.Stream(wg, quitChan) + } + return wg, quitChan, nil +} From 6cf023fe30b96bd503fedeb7be4f18711e9803a3 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Fri, 4 Jun 2021 12:11:21 -0500 Subject: [PATCH 29/46] adjustments after rebase --- CHANGELOG.md | 1 + store/streaming/constructor.go | 6 ++-- store/streaming/file/service.go | 22 +++++++-------- store/streaming/file/service_test.go | 42 ++++++++++++++-------------- 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edb9b89678e9..e4ed9da3563d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -211,6 +211,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#8460](https://github.com/cosmos/cosmos-sdk/pull/8460) Ensure b.ReportAllocs() in all the benchmarks * [\#8461](https://github.com/cosmos/cosmos-sdk/pull/8461) Fix upgrade tx commands not showing up in CLI + ### Bug Fixes * (x/gov) [\#8813](https://github.com/cosmos/cosmos-sdk/pull/8813) fix `{appd} q gov deposits [proposal-id]`, `GET /gov/proposals/{proposal_id}/deposits` to include initial deposit. diff --git a/store/streaming/constructor.go b/store/streaming/constructor.go index 98a85c20a2ef..d8889a746823 100644 --- a/store/streaming/constructor.go +++ b/store/streaming/constructor.go @@ -15,7 +15,7 @@ import ( ) // ServiceConstructor is used to construct a streaming service -type ServiceConstructor func(opts serverTypes.AppOptions, keys []sdk.StoreKey, marshaller codec.BinaryMarshaler) (baseapp.StreamingService, error) +type ServiceConstructor func(opts serverTypes.AppOptions, keys []sdk.StoreKey, marshaller codec.BinaryCodec) (baseapp.StreamingService, error) // ServiceType enum for specifying the type of StreamingService type ServiceType int @@ -64,7 +64,7 @@ func NewServiceConstructor(name string) (ServiceConstructor, error) { } // FileStreamingConstructor is the streaming.ServiceConstructor function for creating a FileStreamingService -func FileStreamingConstructor(opts serverTypes.AppOptions, keys []sdk.StoreKey, marshaller codec.BinaryMarshaler) (baseapp.StreamingService, error) { +func FileStreamingConstructor(opts serverTypes.AppOptions, keys []sdk.StoreKey, marshaller codec.BinaryCodec) (baseapp.StreamingService, error) { filePrefix := cast.ToString(opts.Get("streamers.file.prefix")) fileDir := cast.ToString(opts.Get("streamers.file.writeDir")) return file.NewStreamingService(fileDir, filePrefix, keys, marshaller) @@ -72,7 +72,7 @@ func FileStreamingConstructor(opts serverTypes.AppOptions, keys []sdk.StoreKey, // LoadStreamingServices is a function for loading StreamingServices onto the BaseApp using the provided AppOptions, codec, and keys // It returns the WaitGroup and quit channel used to synchronize with the streaming services and any error that occurs during the setup -func LoadStreamingServices(bApp *baseapp.BaseApp, appOpts serverTypes.AppOptions, appCodec codec.Marshaler, keys map[string]*sdk.KVStoreKey) (*sync.WaitGroup, chan struct{}, error) { +func LoadStreamingServices(bApp *baseapp.BaseApp, appOpts serverTypes.AppOptions, appCodec codec.BinaryCodec, keys map[string]*sdk.KVStoreKey) (*sync.WaitGroup, chan struct{}, error) { // waitgroup and quit channel for optional shutdown coordination of the streaming service(s) wg := new(sync.WaitGroup) quitChan := make(chan struct{}) diff --git a/store/streaming/file/service.go b/store/streaming/file/service.go index fbec361d4807..54374359a2c0 100644 --- a/store/streaming/file/service.go +++ b/store/streaming/file/service.go @@ -41,7 +41,7 @@ type StreamingService struct { srcChan <-chan []byte // the channel that all of the WriteListeners write their data out to filePrefix string // optional prefix for each of the generated files writeDir string // directory to write files into - marshaller codec.BinaryMarshaler // marshaller used for re-marshalling the ABCI messages to write them out to the destination files + codec codec.BinaryCodec // marshaller used for re-marshalling the ABCI messages to write them out to the destination files stateCache [][]byte // cache the protobuf binary encoded StoreKVPairs in the order they are received currentBlockNumber int64 // the current block number currentTxIndex int64 // the index of the current tx @@ -67,10 +67,10 @@ func (iw *IntermediateWriter) Write(b []byte) (int, error) { } // NewStreamingService creates a new StreamingService for the provided writeDir, (optional) filePrefix, and storeKeys -func NewStreamingService(writeDir, filePrefix string, storeKeys []sdk.StoreKey, m codec.BinaryMarshaler) (*StreamingService, error) { +func NewStreamingService(writeDir, filePrefix string, storeKeys []sdk.StoreKey, c codec.BinaryCodec) (*StreamingService, error) { listenChan := make(chan []byte) iw := NewIntermediateWriter(listenChan) - listener := types.NewStoreKVPairWriteListener(iw, m) + listener := types.NewStoreKVPairWriteListener(iw, c) listeners := make(map[sdk.StoreKey][]types.WriteListener, len(storeKeys)) // in this case, we are using the same listener for each Store for _, key := range storeKeys { @@ -86,7 +86,7 @@ func NewStreamingService(writeDir, filePrefix string, storeKeys []sdk.StoreKey, srcChan: listenChan, filePrefix: filePrefix, writeDir: writeDir, - marshaller: m, + codec: c, stateCache: make([][]byte, 0), }, nil } @@ -106,7 +106,7 @@ func (fss *StreamingService) ListenBeginBlock(ctx sdk.Context, req abci.RequestB return err } // write req to file - lengthPrefixedReqBytes, err := fss.marshaller.MarshalBinaryLengthPrefixed(&req) + lengthPrefixedReqBytes, err := fss.codec.MarshalLengthPrefixed(&req) if err != nil { return err } @@ -122,7 +122,7 @@ func (fss *StreamingService) ListenBeginBlock(ctx sdk.Context, req abci.RequestB // reset cache fss.stateCache = nil // write res to file - lengthPrefixedResBytes, err := fss.marshaller.MarshalBinaryLengthPrefixed(&res) + lengthPrefixedResBytes, err := fss.codec.MarshalLengthPrefixed(&res) if err != nil { return err } @@ -153,7 +153,7 @@ func (fss *StreamingService) ListenDeliverTx(ctx sdk.Context, req abci.RequestDe return err } // write req to file - lengthPrefixedReqBytes, err := fss.marshaller.MarshalBinaryLengthPrefixed(&req) + lengthPrefixedReqBytes, err := fss.codec.MarshalLengthPrefixed(&req) if err != nil { return err } @@ -169,7 +169,7 @@ func (fss *StreamingService) ListenDeliverTx(ctx sdk.Context, req abci.RequestDe // reset cache fss.stateCache = nil // write res to file - lengthPrefixedResBytes, err := fss.marshaller.MarshalBinaryLengthPrefixed(&res) + lengthPrefixedResBytes, err := fss.codec.MarshalLengthPrefixed(&res) if err != nil { return err } @@ -199,7 +199,7 @@ func (fss *StreamingService) ListenEndBlock(ctx sdk.Context, req abci.RequestEnd return err } // write req to file - lengthPrefixedReqBytes, err := fss.marshaller.MarshalBinaryLengthPrefixed(&req) + lengthPrefixedReqBytes, err := fss.codec.MarshalLengthPrefixed(&req) if err != nil { return err } @@ -215,7 +215,7 @@ func (fss *StreamingService) ListenEndBlock(ctx sdk.Context, req abci.RequestEnd // reset cache fss.stateCache = nil // write res to file - lengthPrefixedResBytes, err := fss.marshaller.MarshalBinaryLengthPrefixed(&res) + lengthPrefixedResBytes, err := fss.codec.MarshalLengthPrefixed(&res) if err != nil { return err } @@ -234,9 +234,9 @@ func (fss *StreamingService) openEndBlockFile() (*os.File, error) { return os.OpenFile(filepath.Join(fss.writeDir, fileName), os.O_CREATE|os.O_WRONLY, 0600) } +// Stream spins up a goroutine select loop which awaits length-prefixed binary encoded KV pairs and caches them in the order they were received // Do we need this and an intermediate writer? We could just write directly to the buffer on calls to Write // But then we don't support a Stream interface, which could be needed for other types of streamers -// Stream spins up a goroutine select loop which awaits length-prefixed binary encoded KV pairs and caches them in the order they were received func (fss *StreamingService) Stream(wg *sync.WaitGroup, quitChan <-chan struct{}) { wg.Add(1) go func() { diff --git a/store/streaming/file/service_test.go b/store/streaming/file/service_test.go index 4fb240392061..89bb0458dd4a 100644 --- a/store/streaming/file/service_test.go +++ b/store/streaming/file/service_test.go @@ -132,7 +132,7 @@ func TestFileStreamingService(t *testing.T) { require.IsType(t, &StreamingService{}, testStreamingService) require.Equal(t, testPrefix, testStreamingService.filePrefix) require.Equal(t, testDir, testStreamingService.writeDir) - require.Equal(t, testMarshaller, testStreamingService.marshaller) + require.Equal(t, testMarshaller, testStreamingService.codec) testListener1 = testStreamingService.listeners[mockStoreKey1][0] testListener2 = testStreamingService.listeners[mockStoreKey2][0] wg := new(sync.WaitGroup) @@ -147,9 +147,9 @@ func TestFileStreamingService(t *testing.T) { } func testListenBeginBlock(t *testing.T) { - expectedBeginBlockReqBytes, err := testMarshaller.MarshalBinaryBare(&testBeginBlockReq) + expectedBeginBlockReqBytes, err := testMarshaller.Marshal(&testBeginBlockReq) require.Nil(t, err) - expectedBeginBlockResBytes, err := testMarshaller.MarshalBinaryBare(&testBeginBlockRes) + expectedBeginBlockResBytes, err := testMarshaller.Marshal(&testBeginBlockRes) require.Nil(t, err) // write state changes @@ -158,21 +158,21 @@ func testListenBeginBlock(t *testing.T) { testListener1.OnWrite(mockStoreKey1, mockKey3, mockValue3, false) // expected KV pairs - expectedKVPair1, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + expectedKVPair1, err := testMarshaller.Marshal(&types.StoreKVPair{ StoreKey: mockStoreKey1.Name(), Key: mockKey1, Value: mockValue1, Delete: false, }) require.Nil(t, err) - expectedKVPair2, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + expectedKVPair2, err := testMarshaller.Marshal(&types.StoreKVPair{ StoreKey: mockStoreKey2.Name(), Key: mockKey2, Value: mockValue2, Delete: false, }) require.Nil(t, err) - expectedKVPair3, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + expectedKVPair3, err := testMarshaller.Marshal(&types.StoreKVPair{ StoreKey: mockStoreKey1.Name(), Key: mockKey3, Value: mockValue3, @@ -201,9 +201,9 @@ func testListenBeginBlock(t *testing.T) { } func testListenDeliverTx1(t *testing.T) { - expectedDeliverTxReq1Bytes, err := testMarshaller.MarshalBinaryBare(&testDeliverTxReq1) + expectedDeliverTxReq1Bytes, err := testMarshaller.Marshal(&testDeliverTxReq1) require.Nil(t, err) - expectedDeliverTxRes1Bytes, err := testMarshaller.MarshalBinaryBare(&testDeliverTxRes1) + expectedDeliverTxRes1Bytes, err := testMarshaller.Marshal(&testDeliverTxRes1) require.Nil(t, err) // write state changes @@ -212,21 +212,21 @@ func testListenDeliverTx1(t *testing.T) { testListener1.OnWrite(mockStoreKey2, mockKey3, mockValue3, false) // expected KV pairs - expectedKVPair1, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + expectedKVPair1, err := testMarshaller.Marshal(&types.StoreKVPair{ StoreKey: mockStoreKey1.Name(), Key: mockKey1, Value: mockValue1, Delete: false, }) require.Nil(t, err) - expectedKVPair2, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + expectedKVPair2, err := testMarshaller.Marshal(&types.StoreKVPair{ StoreKey: mockStoreKey2.Name(), Key: mockKey2, Value: mockValue2, Delete: false, }) require.Nil(t, err) - expectedKVPair3, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + expectedKVPair3, err := testMarshaller.Marshal(&types.StoreKVPair{ StoreKey: mockStoreKey2.Name(), Key: mockKey3, Value: mockValue3, @@ -255,9 +255,9 @@ func testListenDeliverTx1(t *testing.T) { } func testListenDeliverTx2(t *testing.T) { - expectedDeliverTxReq2Bytes, err := testMarshaller.MarshalBinaryBare(&testDeliverTxReq2) + expectedDeliverTxReq2Bytes, err := testMarshaller.Marshal(&testDeliverTxReq2) require.Nil(t, err) - expectedDeliverTxRes2Bytes, err := testMarshaller.MarshalBinaryBare(&testDeliverTxRes2) + expectedDeliverTxRes2Bytes, err := testMarshaller.Marshal(&testDeliverTxRes2) require.Nil(t, err) // write state changes @@ -266,21 +266,21 @@ func testListenDeliverTx2(t *testing.T) { testListener1.OnWrite(mockStoreKey2, mockKey3, mockValue3, false) // expected KV pairs - expectedKVPair1, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + expectedKVPair1, err := testMarshaller.Marshal(&types.StoreKVPair{ StoreKey: mockStoreKey2.Name(), Key: mockKey1, Value: mockValue1, Delete: false, }) require.Nil(t, err) - expectedKVPair2, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + expectedKVPair2, err := testMarshaller.Marshal(&types.StoreKVPair{ StoreKey: mockStoreKey1.Name(), Key: mockKey2, Value: mockValue2, Delete: false, }) require.Nil(t, err) - expectedKVPair3, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + expectedKVPair3, err := testMarshaller.Marshal(&types.StoreKVPair{ StoreKey: mockStoreKey2.Name(), Key: mockKey3, Value: mockValue3, @@ -309,9 +309,9 @@ func testListenDeliverTx2(t *testing.T) { } func testListenEndBlock(t *testing.T) { - expectedEndBlockReqBytes, err := testMarshaller.MarshalBinaryBare(&testEndBlockReq) + expectedEndBlockReqBytes, err := testMarshaller.Marshal(&testEndBlockReq) require.Nil(t, err) - expectedEndBlockResBytes, err := testMarshaller.MarshalBinaryBare(&testEndBlockRes) + expectedEndBlockResBytes, err := testMarshaller.Marshal(&testEndBlockRes) require.Nil(t, err) // write state changes @@ -320,21 +320,21 @@ func testListenEndBlock(t *testing.T) { testListener1.OnWrite(mockStoreKey2, mockKey3, mockValue3, false) // expected KV pairs - expectedKVPair1, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + expectedKVPair1, err := testMarshaller.Marshal(&types.StoreKVPair{ StoreKey: mockStoreKey1.Name(), Key: mockKey1, Value: mockValue1, Delete: false, }) require.Nil(t, err) - expectedKVPair2, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + expectedKVPair2, err := testMarshaller.Marshal(&types.StoreKVPair{ StoreKey: mockStoreKey1.Name(), Key: mockKey2, Value: mockValue2, Delete: false, }) require.Nil(t, err) - expectedKVPair3, err := testMarshaller.MarshalBinaryBare(&types.StoreKVPair{ + expectedKVPair3, err := testMarshaller.Marshal(&types.StoreKVPair{ StoreKey: mockStoreKey2.Name(), Key: mockKey3, Value: mockValue3, From 317f7f1609205c0547f9811f290bcc3e8cebdff7 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 8 Feb 2021 16:44:55 -0600 Subject: [PATCH 30/46] adjust KVStores to fit new CacheWrapper interface --- store/cachekv/store.go | 2 ++ store/dbadapter/store.go | 2 ++ store/iavl/store.go | 2 ++ store/mem/store.go | 2 ++ store/prefix/store.go | 2 ++ 5 files changed, 10 insertions(+) diff --git a/store/cachekv/store.go b/store/cachekv/store.go index 48c59d8da8d3..210c1df67e40 100644 --- a/store/cachekv/store.go +++ b/store/cachekv/store.go @@ -7,6 +7,8 @@ import ( "sync" "time" + "github.com/cosmos/cosmos-sdk/store/listenkv" + dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/internal/conv" diff --git a/store/dbadapter/store.go b/store/dbadapter/store.go index 2f0ceb5df54a..9614be52c9e3 100644 --- a/store/dbadapter/store.go +++ b/store/dbadapter/store.go @@ -3,6 +3,8 @@ package dbadapter import ( "io" + "github.com/cosmos/cosmos-sdk/store/listenkv" + dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/cachekv" diff --git a/store/iavl/store.go b/store/iavl/store.go index 440b26754de5..8ba3c369739a 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -7,6 +7,8 @@ import ( "sync" "time" + "github.com/cosmos/cosmos-sdk/store/listenkv" + ics23 "github.com/confio/ics23/go" "github.com/cosmos/iavl" abci "github.com/tendermint/tendermint/abci/types" diff --git a/store/mem/store.go b/store/mem/store.go index c8aa6dca5997..6137a8ca3700 100644 --- a/store/mem/store.go +++ b/store/mem/store.go @@ -3,6 +3,8 @@ package mem import ( "io" + "github.com/cosmos/cosmos-sdk/store/listenkv" + dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/cachekv" diff --git a/store/prefix/store.go b/store/prefix/store.go index 295278a0a853..e7f85cbc6f8b 100644 --- a/store/prefix/store.go +++ b/store/prefix/store.go @@ -5,6 +5,8 @@ import ( "errors" "io" + "github.com/cosmos/cosmos-sdk/store/listenkv" + "github.com/cosmos/cosmos-sdk/store/cachekv" "github.com/cosmos/cosmos-sdk/store/listenkv" "github.com/cosmos/cosmos-sdk/store/tracekv" From d6ae81f4c306e1cef8812424933eba6e0c3f6195 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Wed, 24 Feb 2021 15:28:31 -0600 Subject: [PATCH 31/46] review fixes --- store/cachekv/store.go | 2 -- store/dbadapter/store.go | 2 -- store/iavl/store.go | 2 -- store/mem/store.go | 2 -- store/prefix/store.go | 2 -- 5 files changed, 10 deletions(-) diff --git a/store/cachekv/store.go b/store/cachekv/store.go index 210c1df67e40..48c59d8da8d3 100644 --- a/store/cachekv/store.go +++ b/store/cachekv/store.go @@ -7,8 +7,6 @@ import ( "sync" "time" - "github.com/cosmos/cosmos-sdk/store/listenkv" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/internal/conv" diff --git a/store/dbadapter/store.go b/store/dbadapter/store.go index 9614be52c9e3..2f0ceb5df54a 100644 --- a/store/dbadapter/store.go +++ b/store/dbadapter/store.go @@ -3,8 +3,6 @@ package dbadapter import ( "io" - "github.com/cosmos/cosmos-sdk/store/listenkv" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/cachekv" diff --git a/store/iavl/store.go b/store/iavl/store.go index 8ba3c369739a..440b26754de5 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -7,8 +7,6 @@ import ( "sync" "time" - "github.com/cosmos/cosmos-sdk/store/listenkv" - ics23 "github.com/confio/ics23/go" "github.com/cosmos/iavl" abci "github.com/tendermint/tendermint/abci/types" diff --git a/store/mem/store.go b/store/mem/store.go index 6137a8ca3700..c8aa6dca5997 100644 --- a/store/mem/store.go +++ b/store/mem/store.go @@ -3,8 +3,6 @@ package mem import ( "io" - "github.com/cosmos/cosmos-sdk/store/listenkv" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/cachekv" diff --git a/store/prefix/store.go b/store/prefix/store.go index e7f85cbc6f8b..295278a0a853 100644 --- a/store/prefix/store.go +++ b/store/prefix/store.go @@ -5,8 +5,6 @@ import ( "errors" "io" - "github.com/cosmos/cosmos-sdk/store/listenkv" - "github.com/cosmos/cosmos-sdk/store/cachekv" "github.com/cosmos/cosmos-sdk/store/listenkv" "github.com/cosmos/cosmos-sdk/store/tracekv" From 327972aef6ec13f0996e4a3f129fb3c3501374b2 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 6 Jul 2021 11:44:25 -0500 Subject: [PATCH 32/46] minor updates --- docs/architecture/adr-038-state-listening.md | 8 ++--- store/streaming/constructor.go | 3 ++ store/streaming/file/service.go | 2 ++ store/streaming/file/service_test.go | 37 +++----------------- store/streaming/file/utils.go | 35 ++++++++++++++++++ 5 files changed, 48 insertions(+), 37 deletions(-) create mode 100644 store/streaming/file/utils.go diff --git a/docs/architecture/adr-038-state-listening.md b/docs/architecture/adr-038-state-listening.md index d9864bd0f3a1..c0a877e27042 100644 --- a/docs/architecture/adr-038-state-listening.md +++ b/docs/architecture/adr-038-state-listening.md @@ -48,10 +48,10 @@ and determine the source of each KV pair. ```protobuf message StoreKVPair { - optional string store_key = 1; // the store key for the KVStore this pair originates from - required bool set = 2; // true indicates a set operation, false indicates a delete operation - required bytes key = 3; - required bytes value = 4; + string store_key = 1; // the store key for the KVStore this pair originates from + bool set = 2; // true indicates a set operation, false indicates a delete operation + bytes key = 3; + bytes value = 4; } ``` diff --git a/store/streaming/constructor.go b/store/streaming/constructor.go index d8889a746823..c9b0a4f13c9f 100644 --- a/store/streaming/constructor.go +++ b/store/streaming/constructor.go @@ -67,6 +67,9 @@ func NewServiceConstructor(name string) (ServiceConstructor, error) { func FileStreamingConstructor(opts serverTypes.AppOptions, keys []sdk.StoreKey, marshaller codec.BinaryCodec) (baseapp.StreamingService, error) { filePrefix := cast.ToString(opts.Get("streamers.file.prefix")) fileDir := cast.ToString(opts.Get("streamers.file.writeDir")) + if fileDir == "" { + fileDir = file.DefaultWriteDir + } return file.NewStreamingService(fileDir, filePrefix, keys, marshaller) } diff --git a/store/streaming/file/service.go b/store/streaming/file/service.go index 54374359a2c0..1339d49dab58 100644 --- a/store/streaming/file/service.go +++ b/store/streaming/file/service.go @@ -33,6 +33,8 @@ subsequent state changes are written out to this file until the next `BeginBlock the length-prefixed protobuf encoded `EndBlock` request is written, and the response is written at the tail. */ +const DefaultWriteDir = "./state_output" + var _ baseapp.StreamingService = &StreamingService{} // StreamingService is a concrete implementation of StreamingService that writes state changes out to files diff --git a/store/streaming/file/service_test.go b/store/streaming/file/service_test.go index 89bb0458dd4a..284e9ee01a66 100644 --- a/store/streaming/file/service_test.go +++ b/store/streaming/file/service_test.go @@ -1,7 +1,6 @@ package file import ( - "encoding/binary" "fmt" "io/ioutil" "os" @@ -190,7 +189,7 @@ func testListenBeginBlock(t *testing.T) { require.Nil(t, err) // segment the file into the separate gRPC messages and check the correctness of each - segments, err := segmentBytes(fileBytes) + segments, err := SegmentBytes(fileBytes) require.Nil(t, err) require.Equal(t, 5, len(segments)) require.Equal(t, expectedBeginBlockReqBytes, segments[0]) @@ -244,7 +243,7 @@ func testListenDeliverTx1(t *testing.T) { require.Nil(t, err) // segment the file into the separate gRPC messages and check the correctness of each - segments, err := segmentBytes(fileBytes) + segments, err := SegmentBytes(fileBytes) require.Nil(t, err) require.Equal(t, 5, len(segments)) require.Equal(t, expectedDeliverTxReq1Bytes, segments[0]) @@ -298,7 +297,7 @@ func testListenDeliverTx2(t *testing.T) { require.Nil(t, err) // segment the file into the separate gRPC messages and check the correctness of each - segments, err := segmentBytes(fileBytes) + segments, err := SegmentBytes(fileBytes) require.Nil(t, err) require.Equal(t, 5, len(segments)) require.Equal(t, expectedDeliverTxReq2Bytes, segments[0]) @@ -352,7 +351,7 @@ func testListenEndBlock(t *testing.T) { require.Nil(t, err) // segment the file into the separate gRPC messages and check the correctness of each - segments, err := segmentBytes(fileBytes) + segments, err := SegmentBytes(fileBytes) require.Nil(t, err) require.Equal(t, 5, len(segments)) require.Equal(t, expectedEndBlockReqBytes, segments[0]) @@ -366,31 +365,3 @@ func readInFile(name string) ([]byte, error) { path := filepath.Join(testDir, name) return ioutil.ReadFile(path) } - -// Returns all of the protobuf messages contained in the byte array as an array of byte arrays -// The messages have their length prefix removed -func segmentBytes(bz []byte) ([][]byte, error) { - var err error - segments := make([][]byte, 0) - for len(bz) > 0 { - var segment []byte - segment, bz, err = getHeadSegment(bz) - if err != nil { - return nil, err - } - segments = append(segments, segment) - } - return segments, nil -} - -// Returns the bytes for the leading protobuf object in the byte array (removing the length prefix) and returns the remainder of the byte array -func getHeadSegment(bz []byte) ([]byte, []byte, error) { - size, prefixSize := binary.Uvarint(bz) - if prefixSize < 0 { - return nil, nil, fmt.Errorf("invalid number of bytes read from length-prefixed encoding: %d", prefixSize) - } - if size > uint64(len(bz)-prefixSize) { - return nil, nil, fmt.Errorf("not enough bytes to read; want: %v, got: %v", size, len(bz)-prefixSize) - } - return bz[prefixSize:(uint64(prefixSize) + size)], bz[uint64(prefixSize)+size:], nil -} diff --git a/store/streaming/file/utils.go b/store/streaming/file/utils.go new file mode 100644 index 000000000000..0089303ff57e --- /dev/null +++ b/store/streaming/file/utils.go @@ -0,0 +1,35 @@ +package file + +import ( + "encoding/binary" + "fmt" +) + +// SegmentBytes returns all of the protobuf messages contained in the byte array as an array of byte arrays +// The messages have their length prefix removed +// The first byte array will be the abci request, the last the abci response, and in between are the KVPairs +func SegmentBytes(bz []byte) ([][]byte, error) { + var err error + segments := make([][]byte, 0) + for len(bz) > 0 { + var segment []byte + segment, bz, err = getHeadSegment(bz) + if err != nil { + return nil, err + } + segments = append(segments, segment) + } + return segments, nil +} + +// Returns the bytes for the leading protobuf object in the byte array (removing the length prefix) and returns the remainder of the byte array +func getHeadSegment(bz []byte) ([]byte, []byte, error) { + size, prefixSize := binary.Uvarint(bz) + if prefixSize < 0 { + return nil, nil, fmt.Errorf("invalid number of bytes read from length-prefixed encoding: %d", prefixSize) + } + if size > uint64(len(bz)-prefixSize) { + return nil, nil, fmt.Errorf("not enough bytes to read; want: %v, got: %v", size, len(bz)-prefixSize) + } + return bz[prefixSize:(uint64(prefixSize) + size)], bz[uint64(prefixSize)+size:], nil +} From 95be3c1f5eb9f8161f9c86f822db4a838bd2ebf7 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 6 Jul 2021 11:46:26 -0500 Subject: [PATCH 33/46] file server protobuf definitions --- docs/core/proto-docs.md | 272 +++++++++++++++--- proto/cosmos/base/server/v1beta1/server.proto | 81 ++++++ 2 files changed, 314 insertions(+), 39 deletions(-) create mode 100644 proto/cosmos/base/server/v1beta1/server.proto diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index accafc1b37f1..755ba3fc2724 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -82,6 +82,7 @@ - [Output](#cosmos.bank.v1beta1.Output) - [Params](#cosmos.bank.v1beta1.Params) - [SendEnabled](#cosmos.bank.v1beta1.SendEnabled) + - [Supply](#cosmos.bank.v1beta1.Supply) - [cosmos/bank/v1beta1/genesis.proto](#cosmos/bank/v1beta1/genesis.proto) - [Balance](#cosmos.bank.v1beta1.Balance) @@ -158,6 +159,21 @@ - [ReflectionService](#cosmos.base.reflection.v2alpha1.ReflectionService) +- [cosmos/base/store/v1beta1/listening.proto](#cosmos/base/store/v1beta1/listening.proto) + - [StoreKVPair](#cosmos.base.store.v1beta1.StoreKVPair) + +- [cosmos/base/server/v1beta1/server.proto](#cosmos/base/server/v1beta1/server.proto) + - [BeginBlockPayload](#cosmos.base.server.v1beta1.BeginBlockPayload) + - [BeginBlockRequest](#cosmos.base.server.v1beta1.BeginBlockRequest) + - [DeliverTxPayload](#cosmos.base.server.v1beta1.DeliverTxPayload) + - [DeliverTxRequest](#cosmos.base.server.v1beta1.DeliverTxRequest) + - [EndBlockPayload](#cosmos.base.server.v1beta1.EndBlockPayload) + - [EndBlockRequest](#cosmos.base.server.v1beta1.EndBlockRequest) + - [StreamRequest](#cosmos.base.server.v1beta1.StreamRequest) + - [StreamResponse](#cosmos.base.server.v1beta1.StreamResponse) + + - [StateFile](#cosmos.base.server.v1beta1.StateFile) + - [cosmos/base/snapshots/v1beta1/snapshot.proto](#cosmos/base/snapshots/v1beta1/snapshot.proto) - [Metadata](#cosmos.base.snapshots.v1beta1.Metadata) - [Snapshot](#cosmos.base.snapshots.v1beta1.Snapshot) @@ -167,9 +183,6 @@ - [CommitInfo](#cosmos.base.store.v1beta1.CommitInfo) - [StoreInfo](#cosmos.base.store.v1beta1.StoreInfo) -- [cosmos/base/store/v1beta1/listening.proto](#cosmos/base/store/v1beta1/listening.proto) - - [StoreKVPair](#cosmos.base.store.v1beta1.StoreKVPair) - - [cosmos/base/store/v1beta1/snapshot.proto](#cosmos/base/store/v1beta1/snapshot.proto) - [SnapshotIAVLItem](#cosmos.base.store.v1beta1.SnapshotIAVLItem) - [SnapshotItem](#cosmos.base.store.v1beta1.SnapshotItem) @@ -1622,6 +1635,23 @@ sendable). + + + +### Supply +Supply represents a struct that passively keeps track of the total supply +amounts in the network. +This message is deprecated now that supply is indexed by denom. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `total` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | | + + + + + @@ -2607,6 +2637,206 @@ ReflectionService defines a service for application reflection. + +

Top

+ +## cosmos/base/store/v1beta1/listening.proto + + + + + +### StoreKVPair +StoreKVPair is a KVStore KVPair used for listening to state changes (Sets and Deletes) +It optionally includes the StoreKey for the originating KVStore and a Boolean flag to distinguish between Sets and +Deletes + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `store_key` | [string](#string) | | the store key for the KVStore this pair originates from | +| `delete` | [bool](#bool) | | true indicates a delete operation, false indicates a set operation | +| `key` | [bytes](#bytes) | | | +| `value` | [bytes](#bytes) | | | + + + + + + + + + + + + + + + + +

Top

+ +## cosmos/base/server/v1beta1/server.proto + + + + + +### BeginBlockPayload +BeginBlockPayload contains the BeginBlock data + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `request` | [tendermint.abci.RequestBeginBlock](#tendermint.abci.RequestBeginBlock) | | | +| `response` | [tendermint.abci.ResponseBeginBlock](#tendermint.abci.ResponseBeginBlock) | | | +| `state_changes` | [cosmos.base.store.v1beta1.StoreKVPair](#cosmos.base.store.v1beta1.StoreKVPair) | repeated | | + + + + + + + + +### BeginBlockRequest +BeginBlockRequest is the message definition for requesting BeginBlock data at a specific height + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `height` | [int64](#int64) | | | + + + + + + + + +### DeliverTxPayload +DeliverTxPayload contains the DeliverTx data + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `request` | [tendermint.abci.RequestDeliverTx](#tendermint.abci.RequestDeliverTx) | | | +| `response` | [tendermint.abci.ResponseDeliverTx](#tendermint.abci.ResponseDeliverTx) | | | +| `state_changes` | [cosmos.base.store.v1beta1.StoreKVPair](#cosmos.base.store.v1beta1.StoreKVPair) | repeated | | + + + + + + + + +### DeliverTxRequest +DeliverTxRequest is the message definition for requesting DeliverTx data at a specific height + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `height` | [int64](#int64) | | | + + + + + + + + +### EndBlockPayload +EndBlockPayload contains the EndBlock data + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `request` | [tendermint.abci.RequestEndBlock](#tendermint.abci.RequestEndBlock) | | | +| `response` | [tendermint.abci.ResponseEndBlock](#tendermint.abci.ResponseEndBlock) | | | +| `state_changes` | [cosmos.base.store.v1beta1.StoreKVPair](#cosmos.base.store.v1beta1.StoreKVPair) | repeated | | + + + + + + + + +### EndBlockRequest +EndBlockRequest is the message definition for requesting EndBlock data at a specific height + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `height` | [int64](#int64) | | | + + + + + + + + +### StreamRequest +StreamRequest is the message definition for a streaming request sent from a client to the server + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `begin_block` | [bool](#bool) | | begin_block specifies whether or not stream BeginBlock files | +| `deliver_tx` | [bool](#bool) | | deliver_tx specifies whether or not to stream DeliverTx files | +| `end_block` | [bool](#bool) | | end_block specifies whether or not to stream EndBlock files | +| `store_keys` | [string](#string) | repeated | store_keys is a (optional) list of store keys for which to restrict the streamed KVPairs to | + + + + + + + + +### StreamResponse +StreamResponse contains the response data for a stream request + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `chain_id` | [string](#string) | | The ChainID for the tendermint application we are streaming data for | +| `height` | [int64](#int64) | | The block height that this response is for | +| `begin_block_payload` | [BeginBlockPayload](#cosmos.base.server.v1beta1.BeginBlockPayload) | | begin_block_payload contains the BeginBlock data | +| `deliver_tx_payload` | [DeliverTxPayload](#cosmos.base.server.v1beta1.DeliverTxPayload) | | deliver_tx_payload contains the DeliverTx data | +| `end_block_payload` | [EndBlockPayload](#cosmos.base.server.v1beta1.EndBlockPayload) | | end_block_payload contains the EndBlock data | +| `err` | [string](#string) | | error holds any error that occurred while generating the response | + + + + + + + + + + + + + + +### StateFile +StateFile service + +| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | +| ----------- | ------------ | ------------- | ------------| ------- | -------- | +| `BeginBlockDataAt` | [BeginBlockRequest](#cosmos.base.server.v1beta1.BeginBlockRequest) | [BeginBlockPayload](#cosmos.base.server.v1beta1.BeginBlockPayload) | | | +| `DeliverTxDataAt` | [DeliverTxRequest](#cosmos.base.server.v1beta1.DeliverTxRequest) | [DeliverTxPayload](#cosmos.base.server.v1beta1.DeliverTxPayload) | | | +| `EndBlockDataAt` | [EndBlockRequest](#cosmos.base.server.v1beta1.EndBlockRequest) | [EndBlockPayload](#cosmos.base.server.v1beta1.EndBlockPayload) | | | +| `StreamData` | [StreamRequest](#cosmos.base.server.v1beta1.StreamRequest) | [StreamResponse](#cosmos.base.server.v1beta1.StreamResponse) stream | | | +| `BackFillData` | [StreamRequest](#cosmos.base.server.v1beta1.StreamRequest) | [StreamResponse](#cosmos.base.server.v1beta1.StreamResponse) stream | | | + + + + +

Top

@@ -2714,42 +2944,6 @@ between a store name and the commit ID. - - - - - - - - - - - -

Top

- -## cosmos/base/store/v1beta1/listening.proto - - - - - -### StoreKVPair -StoreKVPair is a KVStore KVPair used for listening to state changes (Sets and Deletes) -It optionally includes the StoreKey for the originating KVStore and a Boolean flag to distinguish between Sets and -Deletes - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `store_key` | [string](#string) | | the store key for the KVStore this pair originates from | -| `delete` | [bool](#bool) | | true indicates a delete operation, false indicates a set operation | -| `key` | [bytes](#bytes) | | | -| `value` | [bytes](#bytes) | | | - - - - - diff --git a/proto/cosmos/base/server/v1beta1/server.proto b/proto/cosmos/base/server/v1beta1/server.proto new file mode 100644 index 000000000000..baa36b7af192 --- /dev/null +++ b/proto/cosmos/base/server/v1beta1/server.proto @@ -0,0 +1,81 @@ +syntax = "proto3"; +package cosmos.base.server.v1beta1; + +import "gogoproto/gogo.proto"; +import "cosmos/base/store/v1beta1/listening.proto"; +import "tendermint/abci/types.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/state_file_server/grpc/v1beta"; + +// StateFile service +service StateFile { + rpc BeginBlockDataAt (BeginBlockRequest) returns (BeginBlockPayload) {} + rpc DeliverTxDataAt (DeliverTxRequest) returns (DeliverTxPayload) {} + rpc EndBlockDataAt (EndBlockRequest) returns (EndBlockPayload) {} + rpc StreamData (StreamRequest) returns (stream StreamResponse) {} + rpc BackFillData (StreamRequest) returns (stream StreamResponse) {} +} + +// StreamRequest is the message definition for a streaming request sent from a client to the server +message StreamRequest { + // begin_block specifies whether or not stream BeginBlock files + bool begin_block = 1; + // deliver_tx specifies whether or not to stream DeliverTx files + bool deliver_tx = 2; + // end_block specifies whether or not to stream EndBlock files + bool end_block = 3; + // store_keys is a (optional) list of store keys for which to restrict the streamed KVPairs to + repeated string store_keys = 4; +} + +// BeginBlockRequest is the message definition for requesting BeginBlock data at a specific height +message BeginBlockRequest { + int64 height = 1; +} + +// DeliverTxRequest is the message definition for requesting DeliverTx data at a specific height +message DeliverTxRequest { + int64 height = 1; +} + +// EndBlockRequest is the message definition for requesting EndBlock data at a specific height +message EndBlockRequest { + int64 height = 1; +} + +// StreamResponse contains the response data for a stream request +message StreamResponse { + // The ChainID for the tendermint application we are streaming data for + string chain_id = 1; + // The block height that this response is for + int64 height = 2; + // begin_block_payload contains the BeginBlock data + BeginBlockPayload begin_block_payload = 3 [(gogoproto.nullable) = true]; + // deliver_tx_payload contains the DeliverTx data + DeliverTxPayload deliver_tx_payload = 4 [(gogoproto.nullable) = true]; + // end_block_payload contains the EndBlock data + EndBlockPayload end_block_payload = 5 [(gogoproto.nullable) = true]; + // error holds any error that occurred while generating the response + string err = 6 [(gogoproto.nullable) = true]; +} + +// BeginBlockPayload contains the BeginBlock data +message BeginBlockPayload { + tendermint.abci.RequestBeginBlock request = 1; + tendermint.abci.ResponseBeginBlock response = 2; + repeated cosmos.base.store.v1beta1.StoreKVPair state_changes = 3; +} + +// DeliverTxPayload contains the DeliverTx data +message DeliverTxPayload { + tendermint.abci.RequestDeliverTx request = 1; + tendermint.abci.ResponseDeliverTx response = 2; + repeated cosmos.base.store.v1beta1.StoreKVPair state_changes = 3; +} + +// EndBlockPayload contains the EndBlock data +message EndBlockPayload { + tendermint.abci.RequestEndBlock request = 1; + tendermint.abci.ResponseEndBlock response = 2; + repeated cosmos.base.store.v1beta1.StoreKVPair state_changes = 3; +} From 6972af6c8410fed2b17b98d9fb15d2fa41128845 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 6 Jul 2021 11:46:56 -0500 Subject: [PATCH 34/46] file server protobuf generated Go types --- state_file_server/grpc/v1beta/server.pb.go | 2585 ++++++++++++++++++++ 1 file changed, 2585 insertions(+) create mode 100644 state_file_server/grpc/v1beta/server.pb.go diff --git a/state_file_server/grpc/v1beta/server.pb.go b/state_file_server/grpc/v1beta/server.pb.go new file mode 100644 index 000000000000..dda6785a2341 --- /dev/null +++ b/state_file_server/grpc/v1beta/server.pb.go @@ -0,0 +1,2585 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/base/server/v1beta1/server.proto + +package v1beta + +import ( + context "context" + fmt "fmt" + types1 "github.com/cosmos/cosmos-sdk/store/types" + _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + types "github.com/tendermint/tendermint/abci/types" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// StreamRequest is the message definition for a streaming request sent from a client to the server +type StreamRequest struct { + // begin_block specifies whether or not stream BeginBlock files + BeginBlock bool `protobuf:"varint,1,opt,name=begin_block,json=beginBlock,proto3" json:"begin_block,omitempty"` + // deliver_tx specifies whether or not to stream DeliverTx files + DeliverTx bool `protobuf:"varint,2,opt,name=deliver_tx,json=deliverTx,proto3" json:"deliver_tx,omitempty"` + // end_block specifies whether or not to stream EndBlock files + EndBlock bool `protobuf:"varint,3,opt,name=end_block,json=endBlock,proto3" json:"end_block,omitempty"` + // store_keys is a (optional) list of store keys for which to restrict the streamed KVPairs to + StoreKeys []string `protobuf:"bytes,4,rep,name=store_keys,json=storeKeys,proto3" json:"store_keys,omitempty"` +} + +func (m *StreamRequest) Reset() { *m = StreamRequest{} } +func (m *StreamRequest) String() string { return proto.CompactTextString(m) } +func (*StreamRequest) ProtoMessage() {} +func (*StreamRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_9b48d4169ef99d67, []int{0} +} +func (m *StreamRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *StreamRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_StreamRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *StreamRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_StreamRequest.Merge(m, src) +} +func (m *StreamRequest) XXX_Size() int { + return m.Size() +} +func (m *StreamRequest) XXX_DiscardUnknown() { + xxx_messageInfo_StreamRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_StreamRequest proto.InternalMessageInfo + +func (m *StreamRequest) GetBeginBlock() bool { + if m != nil { + return m.BeginBlock + } + return false +} + +func (m *StreamRequest) GetDeliverTx() bool { + if m != nil { + return m.DeliverTx + } + return false +} + +func (m *StreamRequest) GetEndBlock() bool { + if m != nil { + return m.EndBlock + } + return false +} + +func (m *StreamRequest) GetStoreKeys() []string { + if m != nil { + return m.StoreKeys + } + return nil +} + +// BeginBlockRequest is the message definition for requesting BeginBlock data at a specific height +type BeginBlockRequest struct { + Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` +} + +func (m *BeginBlockRequest) Reset() { *m = BeginBlockRequest{} } +func (m *BeginBlockRequest) String() string { return proto.CompactTextString(m) } +func (*BeginBlockRequest) ProtoMessage() {} +func (*BeginBlockRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_9b48d4169ef99d67, []int{1} +} +func (m *BeginBlockRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BeginBlockRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BeginBlockRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *BeginBlockRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_BeginBlockRequest.Merge(m, src) +} +func (m *BeginBlockRequest) XXX_Size() int { + return m.Size() +} +func (m *BeginBlockRequest) XXX_DiscardUnknown() { + xxx_messageInfo_BeginBlockRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_BeginBlockRequest proto.InternalMessageInfo + +func (m *BeginBlockRequest) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +// DeliverTxRequest is the message definition for requesting DeliverTx data at a specific height +type DeliverTxRequest struct { + Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` +} + +func (m *DeliverTxRequest) Reset() { *m = DeliverTxRequest{} } +func (m *DeliverTxRequest) String() string { return proto.CompactTextString(m) } +func (*DeliverTxRequest) ProtoMessage() {} +func (*DeliverTxRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_9b48d4169ef99d67, []int{2} +} +func (m *DeliverTxRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DeliverTxRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DeliverTxRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DeliverTxRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeliverTxRequest.Merge(m, src) +} +func (m *DeliverTxRequest) XXX_Size() int { + return m.Size() +} +func (m *DeliverTxRequest) XXX_DiscardUnknown() { + xxx_messageInfo_DeliverTxRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_DeliverTxRequest proto.InternalMessageInfo + +func (m *DeliverTxRequest) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +// EndBlockRequest is the message definition for requesting EndBlock data at a specific height +type EndBlockRequest struct { + Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` +} + +func (m *EndBlockRequest) Reset() { *m = EndBlockRequest{} } +func (m *EndBlockRequest) String() string { return proto.CompactTextString(m) } +func (*EndBlockRequest) ProtoMessage() {} +func (*EndBlockRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_9b48d4169ef99d67, []int{3} +} +func (m *EndBlockRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EndBlockRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EndBlockRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *EndBlockRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_EndBlockRequest.Merge(m, src) +} +func (m *EndBlockRequest) XXX_Size() int { + return m.Size() +} +func (m *EndBlockRequest) XXX_DiscardUnknown() { + xxx_messageInfo_EndBlockRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_EndBlockRequest proto.InternalMessageInfo + +func (m *EndBlockRequest) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +// StreamResponse contains the response data for a stream request +type StreamResponse struct { + // The ChainID for the tendermint application we are streaming data for + ChainId string `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + // The block height that this response is for + Height int64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty"` + // begin_block_payload contains the BeginBlock data + BeginBlockPayload *BeginBlockPayload `protobuf:"bytes,3,opt,name=begin_block_payload,json=beginBlockPayload,proto3" json:"begin_block_payload,omitempty"` + // deliver_tx_payload contains the DeliverTx data + DeliverTxPayload *DeliverTxPayload `protobuf:"bytes,4,opt,name=deliver_tx_payload,json=deliverTxPayload,proto3" json:"deliver_tx_payload,omitempty"` + // end_block_payload contains the EndBlock data + EndBlockPayload *EndBlockPayload `protobuf:"bytes,5,opt,name=end_block_payload,json=endBlockPayload,proto3" json:"end_block_payload,omitempty"` + // error holds any error that occurred while generating the response + Err string `protobuf:"bytes,6,opt,name=err,proto3" json:"err,omitempty"` +} + +func (m *StreamResponse) Reset() { *m = StreamResponse{} } +func (m *StreamResponse) String() string { return proto.CompactTextString(m) } +func (*StreamResponse) ProtoMessage() {} +func (*StreamResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_9b48d4169ef99d67, []int{4} +} +func (m *StreamResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *StreamResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_StreamResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *StreamResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_StreamResponse.Merge(m, src) +} +func (m *StreamResponse) XXX_Size() int { + return m.Size() +} +func (m *StreamResponse) XXX_DiscardUnknown() { + xxx_messageInfo_StreamResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_StreamResponse proto.InternalMessageInfo + +func (m *StreamResponse) GetChainId() string { + if m != nil { + return m.ChainId + } + return "" +} + +func (m *StreamResponse) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +func (m *StreamResponse) GetBeginBlockPayload() *BeginBlockPayload { + if m != nil { + return m.BeginBlockPayload + } + return nil +} + +func (m *StreamResponse) GetDeliverTxPayload() *DeliverTxPayload { + if m != nil { + return m.DeliverTxPayload + } + return nil +} + +func (m *StreamResponse) GetEndBlockPayload() *EndBlockPayload { + if m != nil { + return m.EndBlockPayload + } + return nil +} + +func (m *StreamResponse) GetErr() string { + if m != nil { + return m.Err + } + return "" +} + +// BeginBlockPayload contains the BeginBlock data +type BeginBlockPayload struct { + Request *types.RequestBeginBlock `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"` + Response *types.ResponseBeginBlock `protobuf:"bytes,2,opt,name=response,proto3" json:"response,omitempty"` + StateChanges []*types1.StoreKVPair `protobuf:"bytes,3,rep,name=state_changes,json=stateChanges,proto3" json:"state_changes,omitempty"` +} + +func (m *BeginBlockPayload) Reset() { *m = BeginBlockPayload{} } +func (m *BeginBlockPayload) String() string { return proto.CompactTextString(m) } +func (*BeginBlockPayload) ProtoMessage() {} +func (*BeginBlockPayload) Descriptor() ([]byte, []int) { + return fileDescriptor_9b48d4169ef99d67, []int{5} +} +func (m *BeginBlockPayload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BeginBlockPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BeginBlockPayload.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *BeginBlockPayload) XXX_Merge(src proto.Message) { + xxx_messageInfo_BeginBlockPayload.Merge(m, src) +} +func (m *BeginBlockPayload) XXX_Size() int { + return m.Size() +} +func (m *BeginBlockPayload) XXX_DiscardUnknown() { + xxx_messageInfo_BeginBlockPayload.DiscardUnknown(m) +} + +var xxx_messageInfo_BeginBlockPayload proto.InternalMessageInfo + +func (m *BeginBlockPayload) GetRequest() *types.RequestBeginBlock { + if m != nil { + return m.Request + } + return nil +} + +func (m *BeginBlockPayload) GetResponse() *types.ResponseBeginBlock { + if m != nil { + return m.Response + } + return nil +} + +func (m *BeginBlockPayload) GetStateChanges() []*types1.StoreKVPair { + if m != nil { + return m.StateChanges + } + return nil +} + +// DeliverTxPayload contains the DeliverTx data +type DeliverTxPayload struct { + Request *types.RequestDeliverTx `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"` + Response *types.ResponseDeliverTx `protobuf:"bytes,2,opt,name=response,proto3" json:"response,omitempty"` + StateChanges []*types1.StoreKVPair `protobuf:"bytes,3,rep,name=state_changes,json=stateChanges,proto3" json:"state_changes,omitempty"` +} + +func (m *DeliverTxPayload) Reset() { *m = DeliverTxPayload{} } +func (m *DeliverTxPayload) String() string { return proto.CompactTextString(m) } +func (*DeliverTxPayload) ProtoMessage() {} +func (*DeliverTxPayload) Descriptor() ([]byte, []int) { + return fileDescriptor_9b48d4169ef99d67, []int{6} +} +func (m *DeliverTxPayload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DeliverTxPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DeliverTxPayload.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DeliverTxPayload) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeliverTxPayload.Merge(m, src) +} +func (m *DeliverTxPayload) XXX_Size() int { + return m.Size() +} +func (m *DeliverTxPayload) XXX_DiscardUnknown() { + xxx_messageInfo_DeliverTxPayload.DiscardUnknown(m) +} + +var xxx_messageInfo_DeliverTxPayload proto.InternalMessageInfo + +func (m *DeliverTxPayload) GetRequest() *types.RequestDeliverTx { + if m != nil { + return m.Request + } + return nil +} + +func (m *DeliverTxPayload) GetResponse() *types.ResponseDeliverTx { + if m != nil { + return m.Response + } + return nil +} + +func (m *DeliverTxPayload) GetStateChanges() []*types1.StoreKVPair { + if m != nil { + return m.StateChanges + } + return nil +} + +// EndBlockPayload contains the EndBlock data +type EndBlockPayload struct { + Request *types.RequestEndBlock `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"` + Response *types.ResponseEndBlock `protobuf:"bytes,2,opt,name=response,proto3" json:"response,omitempty"` + StateChanges []*types1.StoreKVPair `protobuf:"bytes,3,rep,name=state_changes,json=stateChanges,proto3" json:"state_changes,omitempty"` +} + +func (m *EndBlockPayload) Reset() { *m = EndBlockPayload{} } +func (m *EndBlockPayload) String() string { return proto.CompactTextString(m) } +func (*EndBlockPayload) ProtoMessage() {} +func (*EndBlockPayload) Descriptor() ([]byte, []int) { + return fileDescriptor_9b48d4169ef99d67, []int{7} +} +func (m *EndBlockPayload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EndBlockPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EndBlockPayload.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *EndBlockPayload) XXX_Merge(src proto.Message) { + xxx_messageInfo_EndBlockPayload.Merge(m, src) +} +func (m *EndBlockPayload) XXX_Size() int { + return m.Size() +} +func (m *EndBlockPayload) XXX_DiscardUnknown() { + xxx_messageInfo_EndBlockPayload.DiscardUnknown(m) +} + +var xxx_messageInfo_EndBlockPayload proto.InternalMessageInfo + +func (m *EndBlockPayload) GetRequest() *types.RequestEndBlock { + if m != nil { + return m.Request + } + return nil +} + +func (m *EndBlockPayload) GetResponse() *types.ResponseEndBlock { + if m != nil { + return m.Response + } + return nil +} + +func (m *EndBlockPayload) GetStateChanges() []*types1.StoreKVPair { + if m != nil { + return m.StateChanges + } + return nil +} + +func init() { + proto.RegisterType((*StreamRequest)(nil), "cosmos.base.server.v1beta1.StreamRequest") + proto.RegisterType((*BeginBlockRequest)(nil), "cosmos.base.server.v1beta1.BeginBlockRequest") + proto.RegisterType((*DeliverTxRequest)(nil), "cosmos.base.server.v1beta1.DeliverTxRequest") + proto.RegisterType((*EndBlockRequest)(nil), "cosmos.base.server.v1beta1.EndBlockRequest") + proto.RegisterType((*StreamResponse)(nil), "cosmos.base.server.v1beta1.StreamResponse") + proto.RegisterType((*BeginBlockPayload)(nil), "cosmos.base.server.v1beta1.BeginBlockPayload") + proto.RegisterType((*DeliverTxPayload)(nil), "cosmos.base.server.v1beta1.DeliverTxPayload") + proto.RegisterType((*EndBlockPayload)(nil), "cosmos.base.server.v1beta1.EndBlockPayload") +} + +func init() { + proto.RegisterFile("cosmos/base/server/v1beta1/server.proto", fileDescriptor_9b48d4169ef99d67) +} + +var fileDescriptor_9b48d4169ef99d67 = []byte{ + // 731 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x4b, 0x6f, 0xd3, 0x4a, + 0x14, 0x8e, 0xeb, 0xdc, 0x36, 0x99, 0xf4, 0x39, 0xf7, 0xaa, 0xca, 0x4d, 0x45, 0x9a, 0x1a, 0x09, + 0xfa, 0xa0, 0x36, 0x0d, 0xbb, 0xf2, 0x12, 0xa1, 0x54, 0x42, 0xdd, 0x54, 0x6e, 0xc5, 0x02, 0x09, + 0x19, 0x3f, 0x06, 0x67, 0x14, 0xc7, 0x0e, 0x33, 0xd3, 0xaa, 0x59, 0xb2, 0x66, 0xc3, 0x6f, 0xe1, + 0x57, 0x74, 0xd9, 0x25, 0x48, 0x08, 0x50, 0xfb, 0x47, 0x90, 0xc7, 0xe3, 0xb1, 0x93, 0x92, 0x36, + 0x5d, 0x74, 0x95, 0xcc, 0x99, 0xef, 0x9b, 0x6f, 0xbe, 0x73, 0xce, 0xcc, 0x18, 0xdc, 0x77, 0x23, + 0xda, 0x8d, 0xa8, 0xe1, 0xd8, 0x14, 0x19, 0x14, 0x91, 0x63, 0x44, 0x8c, 0xe3, 0x2d, 0x07, 0x31, + 0x7b, 0x4b, 0x0c, 0xf5, 0x1e, 0x89, 0x58, 0x04, 0x6b, 0x09, 0x50, 0x8f, 0x81, 0xba, 0x98, 0x11, + 0xc0, 0xda, 0x7f, 0x7e, 0xe4, 0x47, 0x1c, 0x66, 0xc4, 0xff, 0x12, 0x46, 0x6d, 0x6d, 0x60, 0x69, + 0x16, 0x11, 0x24, 0x57, 0x0e, 0x30, 0x65, 0x28, 0xc4, 0xa1, 0x2f, 0xa0, 0x4b, 0x0c, 0x85, 0x1e, + 0x22, 0x5d, 0x1c, 0x32, 0xc3, 0x76, 0x5c, 0x6c, 0xb0, 0x7e, 0x0f, 0xd1, 0x64, 0x52, 0xfb, 0xac, + 0x80, 0x99, 0x03, 0x46, 0x90, 0xdd, 0x35, 0xd1, 0xc7, 0x23, 0x44, 0x19, 0x5c, 0x06, 0x15, 0x07, + 0xf9, 0x38, 0xb4, 0x9c, 0x20, 0x72, 0x3b, 0x55, 0xa5, 0xa1, 0xac, 0x96, 0x4c, 0xc0, 0x43, 0xad, + 0x38, 0x02, 0xef, 0x00, 0xe0, 0xa1, 0x00, 0x1f, 0x23, 0x62, 0xb1, 0x93, 0xea, 0x04, 0x9f, 0x2f, + 0x8b, 0xc8, 0xe1, 0x09, 0x5c, 0x02, 0x65, 0x14, 0x7a, 0x82, 0xad, 0xf2, 0xd9, 0x12, 0x0a, 0x3d, + 0xc9, 0xe5, 0x9b, 0xb5, 0x3a, 0xa8, 0x4f, 0xab, 0xc5, 0x86, 0xba, 0x5a, 0x36, 0xcb, 0x3c, 0xb2, + 0x87, 0xfa, 0x54, 0xdb, 0x00, 0x0b, 0x2d, 0x29, 0x94, 0x6e, 0x68, 0x11, 0x4c, 0xb6, 0x11, 0xf6, + 0xdb, 0x8c, 0xef, 0x45, 0x35, 0xc5, 0x48, 0x5b, 0x07, 0xf3, 0x3b, 0xa9, 0xea, 0x75, 0xd8, 0x35, + 0x30, 0xf7, 0x4a, 0xec, 0xe1, 0x3a, 0xe8, 0x27, 0x15, 0xcc, 0xa6, 0x19, 0xa1, 0xbd, 0x28, 0xa4, + 0x08, 0xfe, 0x0f, 0x4a, 0x6e, 0xdb, 0xc6, 0xa1, 0x85, 0x3d, 0x0e, 0x2e, 0x9b, 0x53, 0x7c, 0xfc, + 0xda, 0xcb, 0xad, 0x32, 0x91, 0x5f, 0x05, 0xba, 0xe0, 0xdf, 0x5c, 0x16, 0xad, 0x9e, 0xdd, 0x0f, + 0x22, 0xdb, 0xe3, 0xf9, 0xa8, 0x34, 0x37, 0xf5, 0xd1, 0xf5, 0xd6, 0xb3, 0x04, 0xec, 0x27, 0xa4, + 0x56, 0xf1, 0xf4, 0xe7, 0xb2, 0x62, 0x2e, 0x38, 0xc3, 0x13, 0xf0, 0x3d, 0x80, 0x59, 0x25, 0xa4, + 0x46, 0x91, 0x6b, 0x3c, 0xb8, 0x4a, 0x43, 0xe6, 0x6d, 0x50, 0x62, 0xde, 0x1b, 0x8a, 0xc3, 0x77, + 0x60, 0x41, 0x16, 0x53, 0x0a, 0xfc, 0xc3, 0x05, 0x36, 0xae, 0x12, 0x48, 0x93, 0x3d, 0xb8, 0xfe, + 0x1c, 0x1a, 0x0c, 0xc3, 0x45, 0xa0, 0x22, 0x42, 0xaa, 0x93, 0x71, 0x4e, 0x05, 0x26, 0x0e, 0x68, + 0xbf, 0x94, 0x7c, 0x23, 0xa4, 0xe8, 0x27, 0x60, 0x8a, 0x24, 0xc5, 0xe3, 0x55, 0xa8, 0x34, 0x35, + 0x3d, 0x6b, 0x6d, 0x3d, 0x6e, 0x6d, 0x5d, 0x14, 0x37, 0xd7, 0x44, 0x29, 0x05, 0x3e, 0x07, 0x25, + 0x22, 0x0a, 0xca, 0x6b, 0x55, 0x69, 0xde, 0xfd, 0x0b, 0x3d, 0x01, 0xe4, 0xf8, 0x92, 0x04, 0xf7, + 0xc0, 0x0c, 0x65, 0x36, 0x43, 0x96, 0xdb, 0xb6, 0x43, 0x1f, 0xd1, 0xaa, 0xda, 0x50, 0x57, 0x2b, + 0xcd, 0x7b, 0x83, 0x79, 0x88, 0x7b, 0x59, 0xa6, 0xe1, 0x80, 0x77, 0xf6, 0x9b, 0x7d, 0x1b, 0x13, + 0x73, 0x9a, 0x93, 0x5f, 0x26, 0x5c, 0xed, 0x87, 0x92, 0xeb, 0xde, 0xd4, 0xe0, 0xe3, 0x61, 0x83, + 0x2b, 0xa3, 0x0c, 0x66, 0x8d, 0x2f, 0xfd, 0x3d, 0xbb, 0xe4, 0x4f, 0x1b, 0xe9, 0x2f, 0xa3, 0xdf, + 0x92, 0xbd, 0xef, 0x4a, 0x76, 0xe0, 0x52, 0x77, 0xdb, 0xc3, 0xee, 0x1a, 0xa3, 0xdc, 0xc9, 0xa3, + 0x2a, 0xcd, 0x3d, 0xbd, 0x64, 0x6e, 0x65, 0xa4, 0x39, 0xc9, 0xbe, 0x1d, 0x6f, 0xcd, 0xaf, 0x45, + 0x50, 0x3e, 0x88, 0x03, 0xbb, 0x38, 0x40, 0x90, 0x80, 0xf9, 0xac, 0x5b, 0x76, 0x6c, 0x66, 0xbf, + 0x60, 0x70, 0xcc, 0xf3, 0x2d, 0xdc, 0xd6, 0x6e, 0x76, 0x1d, 0x68, 0x05, 0x18, 0x81, 0x39, 0x59, + 0x41, 0x21, 0x39, 0xde, 0x71, 0x4f, 0x15, 0x6f, 0x74, 0x39, 0x68, 0x05, 0x18, 0x80, 0xd9, 0x34, + 0xab, 0x42, 0x6f, 0xac, 0xd3, 0x9f, 0xca, 0xdd, 0xe4, 0xaa, 0xd0, 0x0a, 0xd0, 0x07, 0x20, 0xb9, + 0x80, 0x63, 0x2d, 0xb8, 0x76, 0x15, 0x79, 0xe0, 0xe9, 0xaa, 0xad, 0x8f, 0x03, 0x4d, 0x5a, 0x42, + 0x2b, 0x3c, 0x54, 0x20, 0x06, 0xd3, 0x2d, 0xdb, 0xed, 0xec, 0xe2, 0x20, 0xb8, 0x65, 0xa9, 0xd6, + 0xe1, 0xe9, 0x79, 0x5d, 0x39, 0x3b, 0xaf, 0x2b, 0xbf, 0xcf, 0xeb, 0xca, 0x97, 0x8b, 0x7a, 0xe1, + 0xec, 0xa2, 0x5e, 0xf8, 0x76, 0x51, 0x2f, 0xbc, 0xdd, 0xf6, 0x31, 0x6b, 0x1f, 0x39, 0xba, 0x1b, + 0x75, 0x0d, 0xf1, 0xa8, 0x27, 0x3f, 0x9b, 0xd4, 0xeb, 0x18, 0x49, 0xdb, 0x7e, 0xc0, 0x01, 0xb2, + 0xc4, 0x07, 0x84, 0x4f, 0x7a, 0xae, 0x78, 0xeb, 0x9d, 0x49, 0xfe, 0x88, 0x3f, 0xfa, 0x13, 0x00, + 0x00, 0xff, 0xff, 0xa1, 0x44, 0xd2, 0x9b, 0x69, 0x08, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// StateFileClient is the client API for StateFile service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type StateFileClient interface { + BeginBlockDataAt(ctx context.Context, in *BeginBlockRequest, opts ...grpc.CallOption) (*BeginBlockPayload, error) + DeliverTxDataAt(ctx context.Context, in *DeliverTxRequest, opts ...grpc.CallOption) (*DeliverTxPayload, error) + EndBlockDataAt(ctx context.Context, in *EndBlockRequest, opts ...grpc.CallOption) (*EndBlockPayload, error) + StreamData(ctx context.Context, in *StreamRequest, opts ...grpc.CallOption) (StateFile_StreamDataClient, error) + BackFillData(ctx context.Context, in *StreamRequest, opts ...grpc.CallOption) (StateFile_BackFillDataClient, error) +} + +type stateFileClient struct { + cc grpc1.ClientConn +} + +func NewStateFileClient(cc grpc1.ClientConn) StateFileClient { + return &stateFileClient{cc} +} + +func (c *stateFileClient) BeginBlockDataAt(ctx context.Context, in *BeginBlockRequest, opts ...grpc.CallOption) (*BeginBlockPayload, error) { + out := new(BeginBlockPayload) + err := c.cc.Invoke(ctx, "/cosmos.base.server.v1beta1.StateFile/BeginBlockDataAt", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *stateFileClient) DeliverTxDataAt(ctx context.Context, in *DeliverTxRequest, opts ...grpc.CallOption) (*DeliverTxPayload, error) { + out := new(DeliverTxPayload) + err := c.cc.Invoke(ctx, "/cosmos.base.server.v1beta1.StateFile/DeliverTxDataAt", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *stateFileClient) EndBlockDataAt(ctx context.Context, in *EndBlockRequest, opts ...grpc.CallOption) (*EndBlockPayload, error) { + out := new(EndBlockPayload) + err := c.cc.Invoke(ctx, "/cosmos.base.server.v1beta1.StateFile/EndBlockDataAt", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *stateFileClient) StreamData(ctx context.Context, in *StreamRequest, opts ...grpc.CallOption) (StateFile_StreamDataClient, error) { + stream, err := c.cc.NewStream(ctx, &_StateFile_serviceDesc.Streams[0], "/cosmos.base.server.v1beta1.StateFile/StreamData", opts...) + if err != nil { + return nil, err + } + x := &stateFileStreamDataClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type StateFile_StreamDataClient interface { + Recv() (*StreamResponse, error) + grpc.ClientStream +} + +type stateFileStreamDataClient struct { + grpc.ClientStream +} + +func (x *stateFileStreamDataClient) Recv() (*StreamResponse, error) { + m := new(StreamResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func (c *stateFileClient) BackFillData(ctx context.Context, in *StreamRequest, opts ...grpc.CallOption) (StateFile_BackFillDataClient, error) { + stream, err := c.cc.NewStream(ctx, &_StateFile_serviceDesc.Streams[1], "/cosmos.base.server.v1beta1.StateFile/BackFillData", opts...) + if err != nil { + return nil, err + } + x := &stateFileBackFillDataClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type StateFile_BackFillDataClient interface { + Recv() (*StreamResponse, error) + grpc.ClientStream +} + +type stateFileBackFillDataClient struct { + grpc.ClientStream +} + +func (x *stateFileBackFillDataClient) Recv() (*StreamResponse, error) { + m := new(StreamResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +// StateFileServer is the server API for StateFile service. +type StateFileServer interface { + BeginBlockDataAt(context.Context, *BeginBlockRequest) (*BeginBlockPayload, error) + DeliverTxDataAt(context.Context, *DeliverTxRequest) (*DeliverTxPayload, error) + EndBlockDataAt(context.Context, *EndBlockRequest) (*EndBlockPayload, error) + StreamData(*StreamRequest, StateFile_StreamDataServer) error + BackFillData(*StreamRequest, StateFile_BackFillDataServer) error +} + +// UnimplementedStateFileServer can be embedded to have forward compatible implementations. +type UnimplementedStateFileServer struct { +} + +func (*UnimplementedStateFileServer) BeginBlockDataAt(ctx context.Context, req *BeginBlockRequest) (*BeginBlockPayload, error) { + return nil, status.Errorf(codes.Unimplemented, "method BeginBlockDataAt not implemented") +} +func (*UnimplementedStateFileServer) DeliverTxDataAt(ctx context.Context, req *DeliverTxRequest) (*DeliverTxPayload, error) { + return nil, status.Errorf(codes.Unimplemented, "method DeliverTxDataAt not implemented") +} +func (*UnimplementedStateFileServer) EndBlockDataAt(ctx context.Context, req *EndBlockRequest) (*EndBlockPayload, error) { + return nil, status.Errorf(codes.Unimplemented, "method EndBlockDataAt not implemented") +} +func (*UnimplementedStateFileServer) StreamData(req *StreamRequest, srv StateFile_StreamDataServer) error { + return status.Errorf(codes.Unimplemented, "method StreamData not implemented") +} +func (*UnimplementedStateFileServer) BackFillData(req *StreamRequest, srv StateFile_BackFillDataServer) error { + return status.Errorf(codes.Unimplemented, "method BackFillData not implemented") +} + +func RegisterStateFileServer(s grpc1.Server, srv StateFileServer) { + s.RegisterService(&_StateFile_serviceDesc, srv) +} + +func _StateFile_BeginBlockDataAt_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BeginBlockRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StateFileServer).BeginBlockDataAt(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.base.server.v1beta1.StateFile/BeginBlockDataAt", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StateFileServer).BeginBlockDataAt(ctx, req.(*BeginBlockRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _StateFile_DeliverTxDataAt_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeliverTxRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StateFileServer).DeliverTxDataAt(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.base.server.v1beta1.StateFile/DeliverTxDataAt", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StateFileServer).DeliverTxDataAt(ctx, req.(*DeliverTxRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _StateFile_EndBlockDataAt_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EndBlockRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StateFileServer).EndBlockDataAt(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.base.server.v1beta1.StateFile/EndBlockDataAt", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StateFileServer).EndBlockDataAt(ctx, req.(*EndBlockRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _StateFile_StreamData_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(StreamRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(StateFileServer).StreamData(m, &stateFileStreamDataServer{stream}) +} + +type StateFile_StreamDataServer interface { + Send(*StreamResponse) error + grpc.ServerStream +} + +type stateFileStreamDataServer struct { + grpc.ServerStream +} + +func (x *stateFileStreamDataServer) Send(m *StreamResponse) error { + return x.ServerStream.SendMsg(m) +} + +func _StateFile_BackFillData_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(StreamRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(StateFileServer).BackFillData(m, &stateFileBackFillDataServer{stream}) +} + +type StateFile_BackFillDataServer interface { + Send(*StreamResponse) error + grpc.ServerStream +} + +type stateFileBackFillDataServer struct { + grpc.ServerStream +} + +func (x *stateFileBackFillDataServer) Send(m *StreamResponse) error { + return x.ServerStream.SendMsg(m) +} + +var _StateFile_serviceDesc = grpc.ServiceDesc{ + ServiceName: "cosmos.base.server.v1beta1.StateFile", + HandlerType: (*StateFileServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "BeginBlockDataAt", + Handler: _StateFile_BeginBlockDataAt_Handler, + }, + { + MethodName: "DeliverTxDataAt", + Handler: _StateFile_DeliverTxDataAt_Handler, + }, + { + MethodName: "EndBlockDataAt", + Handler: _StateFile_EndBlockDataAt_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "StreamData", + Handler: _StateFile_StreamData_Handler, + ServerStreams: true, + }, + { + StreamName: "BackFillData", + Handler: _StateFile_BackFillData_Handler, + ServerStreams: true, + }, + }, + Metadata: "cosmos/base/server/v1beta1/server.proto", +} + +func (m *StreamRequest) 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 *StreamRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *StreamRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.StoreKeys) > 0 { + for iNdEx := len(m.StoreKeys) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.StoreKeys[iNdEx]) + copy(dAtA[i:], m.StoreKeys[iNdEx]) + i = encodeVarintServer(dAtA, i, uint64(len(m.StoreKeys[iNdEx]))) + i-- + dAtA[i] = 0x22 + } + } + if m.EndBlock { + i-- + if m.EndBlock { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x18 + } + if m.DeliverTx { + i-- + if m.DeliverTx { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } + if m.BeginBlock { + i-- + if m.BeginBlock { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *BeginBlockRequest) 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 *BeginBlockRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BeginBlockRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Height != 0 { + i = encodeVarintServer(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *DeliverTxRequest) 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 *DeliverTxRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DeliverTxRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Height != 0 { + i = encodeVarintServer(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *EndBlockRequest) 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 *EndBlockRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EndBlockRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Height != 0 { + i = encodeVarintServer(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *StreamResponse) 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 *StreamResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *StreamResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Err) > 0 { + i -= len(m.Err) + copy(dAtA[i:], m.Err) + i = encodeVarintServer(dAtA, i, uint64(len(m.Err))) + i-- + dAtA[i] = 0x32 + } + if m.EndBlockPayload != nil { + { + size, err := m.EndBlockPayload.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + if m.DeliverTxPayload != nil { + { + size, err := m.DeliverTxPayload.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + if m.BeginBlockPayload != nil { + { + size, err := m.BeginBlockPayload.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if m.Height != 0 { + i = encodeVarintServer(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x10 + } + if len(m.ChainId) > 0 { + i -= len(m.ChainId) + copy(dAtA[i:], m.ChainId) + i = encodeVarintServer(dAtA, i, uint64(len(m.ChainId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *BeginBlockPayload) 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 *BeginBlockPayload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BeginBlockPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.StateChanges) > 0 { + for iNdEx := len(m.StateChanges) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.StateChanges[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if m.Response != nil { + { + size, err := m.Response.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.Request != nil { + { + size, err := m.Request.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *DeliverTxPayload) 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 *DeliverTxPayload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DeliverTxPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.StateChanges) > 0 { + for iNdEx := len(m.StateChanges) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.StateChanges[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if m.Response != nil { + { + size, err := m.Response.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.Request != nil { + { + size, err := m.Request.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *EndBlockPayload) 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 *EndBlockPayload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EndBlockPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.StateChanges) > 0 { + for iNdEx := len(m.StateChanges) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.StateChanges[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if m.Response != nil { + { + size, err := m.Response.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.Request != nil { + { + size, err := m.Request.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintServer(dAtA []byte, offset int, v uint64) int { + offset -= sovServer(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *StreamRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BeginBlock { + n += 2 + } + if m.DeliverTx { + n += 2 + } + if m.EndBlock { + n += 2 + } + if len(m.StoreKeys) > 0 { + for _, s := range m.StoreKeys { + l = len(s) + n += 1 + l + sovServer(uint64(l)) + } + } + return n +} + +func (m *BeginBlockRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Height != 0 { + n += 1 + sovServer(uint64(m.Height)) + } + return n +} + +func (m *DeliverTxRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Height != 0 { + n += 1 + sovServer(uint64(m.Height)) + } + return n +} + +func (m *EndBlockRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Height != 0 { + n += 1 + sovServer(uint64(m.Height)) + } + return n +} + +func (m *StreamResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovServer(uint64(l)) + } + if m.Height != 0 { + n += 1 + sovServer(uint64(m.Height)) + } + if m.BeginBlockPayload != nil { + l = m.BeginBlockPayload.Size() + n += 1 + l + sovServer(uint64(l)) + } + if m.DeliverTxPayload != nil { + l = m.DeliverTxPayload.Size() + n += 1 + l + sovServer(uint64(l)) + } + if m.EndBlockPayload != nil { + l = m.EndBlockPayload.Size() + n += 1 + l + sovServer(uint64(l)) + } + l = len(m.Err) + if l > 0 { + n += 1 + l + sovServer(uint64(l)) + } + return n +} + +func (m *BeginBlockPayload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Request != nil { + l = m.Request.Size() + n += 1 + l + sovServer(uint64(l)) + } + if m.Response != nil { + l = m.Response.Size() + n += 1 + l + sovServer(uint64(l)) + } + if len(m.StateChanges) > 0 { + for _, e := range m.StateChanges { + l = e.Size() + n += 1 + l + sovServer(uint64(l)) + } + } + return n +} + +func (m *DeliverTxPayload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Request != nil { + l = m.Request.Size() + n += 1 + l + sovServer(uint64(l)) + } + if m.Response != nil { + l = m.Response.Size() + n += 1 + l + sovServer(uint64(l)) + } + if len(m.StateChanges) > 0 { + for _, e := range m.StateChanges { + l = e.Size() + n += 1 + l + sovServer(uint64(l)) + } + } + return n +} + +func (m *EndBlockPayload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Request != nil { + l = m.Request.Size() + n += 1 + l + sovServer(uint64(l)) + } + if m.Response != nil { + l = m.Response.Size() + n += 1 + l + sovServer(uint64(l)) + } + if len(m.StateChanges) > 0 { + for _, e := range m.StateChanges { + l = e.Size() + n += 1 + l + sovServer(uint64(l)) + } + } + return n +} + +func sovServer(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozServer(x uint64) (n int) { + return sovServer(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *StreamRequest) 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 ErrIntOverflowServer + } + 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: StreamRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: StreamRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BeginBlock", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.BeginBlock = bool(v != 0) + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DeliverTx", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.DeliverTx = bool(v != 0) + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EndBlock", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.EndBlock = bool(v != 0) + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StoreKeys", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + 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 ErrInvalidLengthServer + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StoreKeys = append(m.StoreKeys, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipServer(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthServer + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *BeginBlockRequest) 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 ErrIntOverflowServer + } + 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: BeginBlockRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BeginBlockRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipServer(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthServer + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DeliverTxRequest) 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 ErrIntOverflowServer + } + 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: DeliverTxRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DeliverTxRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipServer(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthServer + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *EndBlockRequest) 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 ErrIntOverflowServer + } + 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: EndBlockRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EndBlockRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipServer(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthServer + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *StreamResponse) 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 ErrIntOverflowServer + } + 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: StreamResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: StreamResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + 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 ErrInvalidLengthServer + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BeginBlockPayload", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.BeginBlockPayload == nil { + m.BeginBlockPayload = &BeginBlockPayload{} + } + if err := m.BeginBlockPayload.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DeliverTxPayload", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.DeliverTxPayload == nil { + m.DeliverTxPayload = &DeliverTxPayload{} + } + if err := m.DeliverTxPayload.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EndBlockPayload", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.EndBlockPayload == nil { + m.EndBlockPayload = &EndBlockPayload{} + } + if err := m.EndBlockPayload.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Err", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + 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 ErrInvalidLengthServer + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Err = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipServer(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthServer + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *BeginBlockPayload) 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 ErrIntOverflowServer + } + 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: BeginBlockPayload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BeginBlockPayload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Request", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Request == nil { + m.Request = &types.RequestBeginBlock{} + } + if err := m.Request.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Response", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Response == nil { + m.Response = &types.ResponseBeginBlock{} + } + if err := m.Response.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StateChanges", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StateChanges = append(m.StateChanges, &types1.StoreKVPair{}) + if err := m.StateChanges[len(m.StateChanges)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipServer(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthServer + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DeliverTxPayload) 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 ErrIntOverflowServer + } + 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: DeliverTxPayload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DeliverTxPayload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Request", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Request == nil { + m.Request = &types.RequestDeliverTx{} + } + if err := m.Request.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Response", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Response == nil { + m.Response = &types.ResponseDeliverTx{} + } + if err := m.Response.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StateChanges", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StateChanges = append(m.StateChanges, &types1.StoreKVPair{}) + if err := m.StateChanges[len(m.StateChanges)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipServer(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthServer + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *EndBlockPayload) 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 ErrIntOverflowServer + } + 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: EndBlockPayload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EndBlockPayload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Request", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Request == nil { + m.Request = &types.RequestEndBlock{} + } + if err := m.Request.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Response", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Response == nil { + m.Response = &types.ResponseEndBlock{} + } + if err := m.Response.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StateChanges", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StateChanges = append(m.StateChanges, &types1.StoreKVPair{}) + if err := m.StateChanges[len(m.StateChanges)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipServer(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthServer + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipServer(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowServer + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowServer + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowServer + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthServer + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupServer + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthServer + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthServer = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowServer = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupServer = fmt.Errorf("proto: unexpected end of group") +) From 0d26da6781f2e1bbb63872fe94b4f38926dddcf9 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 6 Jul 2021 11:47:19 -0500 Subject: [PATCH 35/46] state file server --- go.mod | 3 + go.sum | 2 + state_file_server/api/api.go | 1 + state_file_server/client/client.go | 52 +++++ state_file_server/config/config.go | 39 ++++ state_file_server/grpc/backend.go | 296 ++++++++++++++++++++++++++ state_file_server/grpc/grpc_server.go | 35 +++ state_file_server/grpc/grpc_web.go | 26 +++ state_file_server/grpc/server.go | 78 +++++++ 9 files changed, 532 insertions(+) create mode 100644 state_file_server/api/api.go create mode 100644 state_file_server/client/client.go create mode 100644 state_file_server/config/config.go create mode 100644 state_file_server/grpc/backend.go create mode 100644 state_file_server/grpc/grpc_server.go create mode 100644 state_file_server/grpc/grpc_web.go create mode 100644 state_file_server/grpc/server.go diff --git a/go.mod b/go.mod index 451f1688ca6a..2bac49b6b833 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/cosmos/ledger-cosmos-go v0.11.1 github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect github.com/enigmampc/btcutil v1.0.3-0.20200723161021-e2fb6adb2a25 + github.com/fkocik/fsnotify v0.0.0-00010101000000-000000000000 github.com/gogo/gateway v1.1.0 github.com/gogo/protobuf v1.3.3 github.com/golang/mock v1.6.0 @@ -59,3 +60,5 @@ replace google.golang.org/grpc => google.golang.org/grpc v1.33.2 replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 replace github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 + +replace github.com/fkocik/fsnotify => github.com/vulcanize/fsnotify v1.4.7-ir diff --git a/go.sum b/go.sum index 4fb6d7ceebe1..4eba79747dbe 100644 --- a/go.sum +++ b/go.sum @@ -775,6 +775,8 @@ github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijb github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/vmihailenco/msgpack/v5 v5.1.4/go.mod h1:C5gboKD0TJPqWDTVTtrQNfRbiBwHZGo8UTqP/9/XvLI= github.com/vmihailenco/tagparser v0.1.2/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= +github.com/vulcanize/fsnotify v1.4.7-ir h1:RFJatF7+f4Bb7iswEjRupro8amMbYovd9Mz0ctnQ4no= +github.com/vulcanize/fsnotify v1.4.7-ir/go.mod h1:aMrtLbtrZJc1YxX4Jk3S08Ytm+473ginLQIJJWDaiLA= github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208/go.mod h1:IotVbo4F+mw0EzQ08zFqg7pK3FebNXpaMsRy2RT+Ees= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= diff --git a/state_file_server/api/api.go b/state_file_server/api/api.go new file mode 100644 index 000000000000..778f64ec17cd --- /dev/null +++ b/state_file_server/api/api.go @@ -0,0 +1 @@ +package api diff --git a/state_file_server/client/client.go b/state_file_server/client/client.go new file mode 100644 index 000000000000..dc3710c65705 --- /dev/null +++ b/state_file_server/client/client.go @@ -0,0 +1,52 @@ +package client + +import ( + "context" + "io" + "log" + + pb "github.com/cosmos/cosmos-sdk/state_file_server/grpc/v1beta" + + "google.golang.org/grpc" +) + +func NewClient(conn *grpc.ClientConn) (pb.StateFileClient, error) { + client := pb.NewStateFileClient(conn) +} + +func main() { + // dial server + conn, err := grpc.Dial(":50005", grpc.WithInsecure()) + if err != nil { + log.Fatalf("can not connect with server %v", err) + } + + + // create stream + client := pb.NewStateFileClient(conn) + + in := &pb.StreamRequest{Id: 1} + stream, err := client.(context.Background(), in) + if err != nil { + log.Fatalf("open stream error %v", err) + } + + done := make(chan bool) + + go func() { + for { + resp, err := stream.Recv() + if err == io.EOF { + done <- true //means stream is finished + return + } + if err != nil { + log.Fatalf("cannot receive %v", err) + } + log.Printf("Resp received: %s", resp.Result) + } + }() + + <-done //we will wait until all response is received + log.Printf("finished") +} \ No newline at end of file diff --git a/state_file_server/config/config.go b/state_file_server/config/config.go new file mode 100644 index 000000000000..432970f265b4 --- /dev/null +++ b/state_file_server/config/config.go @@ -0,0 +1,39 @@ +package config + +import ( + "github.com/cosmos/cosmos-sdk/store/streaming/file" +) + +// Default constants +const ( + // DefaultReadDir defines the default directory to read the streamed files from + DefaultReadDir = file.DefaultWriteDir + + // DefaultGRPCAddress defines the default address to bind the gRPC server to. + DefaultGRPCAddress = "0.0.0.0:9092" + + // DefaultGRPCWebAddress defines the default address to bind the gRPC-web server to. + DefaultGRPCWebAddress = "0.0.0.0:9093" +) + +type StateServerConfig struct { + GRPCAddress string + GRPCWebAddress string +} + +// DefaultStateServerConfig returns the reference to ClientConfig with default values. +func DefaultStateServerConfig() *StateServerConfig { + return &StateServerConfig{DefaultGRPCAddress, DefaultGRPCWebAddress} +} + +type StateServerBackendConfig struct { + ChainID string + ReadDir string + FilePrefix string + Persist bool // false: once data has been streamed forward it will be removed from the filesystem +} + +// DefaultStateServerBackendConfig returns the reference to ClientConfig with default values. +func DefaultStateServerBackendConfig() *StateServerBackendConfig { + return &StateServerBackendConfig{"", DefaultReadDir, "", true} +} diff --git a/state_file_server/grpc/backend.go b/state_file_server/grpc/backend.go new file mode 100644 index 000000000000..660b1ccbc8ec --- /dev/null +++ b/state_file_server/grpc/backend.go @@ -0,0 +1,296 @@ +package grpc + +import ( + "fmt" + "io/ioutil" + "os" + "path/filepath" + "sort" + "strconv" + "strings" + + "github.com/fkocik/fsnotify" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/state_file_server/config" + pb "github.com/cosmos/cosmos-sdk/state_file_server/grpc/v1beta" + "github.com/cosmos/cosmos-sdk/store/streaming/file" + "github.com/cosmos/cosmos-sdk/store/types" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/libs/log" +) + +type StateFileBackend struct { + conf config.StateServerBackendConfig + + codec *codec.ProtoCodec + logger log.Logger + trimPrefix string +} + +func NewStateFileBackend(conf config.StateServerBackendConfig, codec *codec.ProtoCodec, logger log.Logger) *StateFileBackend { + trimPrefix := "block-" + if conf.FilePrefix != "" { + trimPrefix = fmt.Sprintf("%s-%s", conf.FilePrefix, trimPrefix) + } + return &StateFileBackend{ + conf: conf, + codec: codec, + trimPrefix: trimPrefix, + logger: logger, + } +} + +func (sfb *StateFileBackend) Stream(req *pb.StreamRequest, res chan <-*pb.StreamResponse, doneChan chan <-struct{}) error { + w, err := fsnotify.NewWatcher() + if err != nil { + close(doneChan) + return err + } + go func() { + defer w.Close() + defer close(doneChan) + for { + select { + case event, ok := <-w.Events: + if !ok { + continue + } + if event.Op == fsnotify.CloseWrite { + fileName := event.Name + readFlag := false + switch { + case strings.Contains(fileName, "begin") && req.BeginBlock: + readFlag = true + res <- sfb.formBeginBlockResponse(fileName) + case strings.Contains(fileName, "end") && req.EndBlock: + readFlag = true + res <- sfb.formBeginBlockResponse(fileName) + case strings.Contains(fileName, "tx") && req.DeliverTx: + readFlag = true + res <- sfb.formBeginBlockResponse(fileName) + default: + } + if !sfb.conf.Persist && readFlag { + if err := os.Remove(filepath.Join(sfb.conf.ReadDir, fileName)); err != nil { + sfb.logger.Error("unable to remove state change file", "err", err) + } + } + } + case err, ok := <-w.Errors: + if !ok { + continue + } + sfb.logger.Error("fsnotify watcher error", "err", err) + } + } + }() + return nil +} + +func (sfb *StateFileBackend) BackFill(req *pb.StreamRequest, res chan <-*pb.StreamResponse, doneChan chan <-struct{}) error { + f, err := os.Open(sfb.conf.ReadDir) + if err != nil { + return err + } + files, err := f.Readdir(-1) + if err != nil { + return err + } + sort.Sort(filesByTimeModified(files)) + go func() { + defer close(doneChan) + for _, f := range files { + if f.IsDir() { + continue + } + fileName := f.Name() + readFlag := false + switch { + case strings.Contains(fileName, "begin") && req.BeginBlock: + readFlag = true + res <- sfb.formBeginBlockResponse(fileName) + case strings.Contains(fileName, "end") && req.EndBlock: + readFlag = true + res <- sfb.formBeginBlockResponse(fileName) + case strings.Contains(fileName, "tx") && req.DeliverTx: + readFlag = true + res <- sfb.formBeginBlockResponse(fileName) + default: + } + if !sfb.conf.Persist && readFlag { + if err := os.Remove(filepath.Join(sfb.conf.ReadDir, fileName)); err != nil { + sfb.logger.Error("unable to remove state change file", "err", err) + } + } + } + }() + return nil +} + +type filesByTimeModified []os.FileInfo + +func (fs filesByTimeModified) Len() int { + return len(fs) +} + +func (fs filesByTimeModified) Swap(i, j int) { + fs[i], fs[j] = fs[j], fs[i] +} + +func (fs filesByTimeModified) Less(i, j int) bool { + return fs[i].ModTime().Before(fs[j].ModTime()) +} + +func (sfb *StateFileBackend) formBeginBlockResponse(fileName string) *pb.StreamResponse { + res := new(pb.StreamResponse) + res.ChainId = sfb.conf.ChainID + blockHeightStr := string(strings.TrimPrefix(fileName, sfb.trimPrefix)[0]) + blockHeight, err := strconv.ParseInt(blockHeightStr, 10, 64) + if err != nil { + res.Err = err.Error() + return res + } + res.Height = blockHeight + fileBytes, err := ioutil.ReadFile(filepath.Join(sfb.conf.ReadDir, fileName)) + if err != nil { + res.Err = err.Error() + return res + } + messageBytes, err := file.SegmentBytes(fileBytes) + if err != nil { + res.Err = err.Error() + return res + } + if len(messageBytes) < 2 { + res.Err = fmt.Sprintf("expected at least two protobuf messages, got %d", len(messageBytes)) + return res + } + beginBlockReq := new(abci.RequestBeginBlock) + if err := sfb.codec.Unmarshal(messageBytes[0], beginBlockReq); err != nil { + res.Err = err.Error() + return res + } + beginBlockRes := new(abci.ResponseBeginBlock) + if err := sfb.codec.Unmarshal(messageBytes[len(messageBytes)-1], beginBlockRes); err != nil { + res.Err = err.Error() + return res + } + kvPairs := make([]*types.StoreKVPair, len(messageBytes[1:len(messageBytes)-2])) + for i := 1; i < len(messageBytes) - 1; i++ { + kvPair := new(types.StoreKVPair) + if err := sfb.codec.Unmarshal(messageBytes[i], kvPair); err != nil { + res.Err = err.Error() + return res + } + kvPairs[i-1] = kvPair + } + res.BeginBlockPayload = &pb.BeginBlockPayload{ + Request: beginBlockReq, + Response: beginBlockRes, + StateChanges: kvPairs, + } + return res +} + +func (sfb *StateFileBackend) formDeliverTxResponse(fileName string) *pb.StreamResponse { + res := new(pb.StreamResponse) + res.ChainId = sfb.conf.ChainID + blockHeightStr := string(strings.TrimPrefix(fileName, sfb.trimPrefix)[0]) + blockHeight, err := strconv.ParseInt(blockHeightStr, 10, 64) + if err != nil { + res.Err = err.Error() + return res + } + res.Height = blockHeight + fileBytes, err := ioutil.ReadFile(filepath.Join(sfb.conf.ReadDir, fileName)) + if err != nil { + res.Err = err.Error() + return res + } + messageBytes, err := file.SegmentBytes(fileBytes) + if err != nil { + res.Err = err.Error() + return res + } + if len(messageBytes) < 2 { + res.Err = fmt.Sprintf("expected at least two protobuf messages, got %d", len(messageBytes)) + return res + } + deliverTxReq := new(abci.RequestDeliverTx) + if err := sfb.codec.Unmarshal(messageBytes[0], deliverTxReq); err != nil { + res.Err = err.Error() + return res + } + deliverTxRes := new(abci.ResponseDeliverTx) + if err := sfb.codec.Unmarshal(messageBytes[len(messageBytes)-1], deliverTxRes); err != nil { + res.Err = err.Error() + return res + } + kvPairs := make([]*types.StoreKVPair, len(messageBytes[1:len(messageBytes)-2])) + for i := 1; i < len(messageBytes) - 1; i++ { + kvPair := new(types.StoreKVPair) + if err := sfb.codec.Unmarshal(messageBytes[i], kvPair); err != nil { + res.Err = err.Error() + return res + } + kvPairs[i-1] = kvPair + } + res.DeliverTxPayload = &pb.DeliverTxPayload{ + Request: deliverTxReq, + Response: deliverTxRes, + StateChanges: kvPairs, + } + return res +} + +func (sfb *StateFileBackend) formEndBlockResponse(fileName string) *pb.StreamResponse { + res := new(pb.StreamResponse) + res.ChainId = sfb.conf.ChainID + blockHeightStr := string(strings.TrimPrefix(fileName, sfb.trimPrefix)[0]) + blockHeight, err := strconv.ParseInt(blockHeightStr, 10, 64) + if err != nil { + res.Err = err.Error() + return res + } + res.Height = blockHeight + fileBytes, err := ioutil.ReadFile(filepath.Join(sfb.conf.ReadDir, fileName)) + if err != nil { + res.Err = err.Error() + return res + } + messageBytes, err := file.SegmentBytes(fileBytes) + if err != nil { + res.Err = err.Error() + return res + } + if len(messageBytes) < 2 { + res.Err = fmt.Sprintf("expected at least two protobuf messages, got %d", len(messageBytes)) + return res + } + endBlockReq := new(abci.RequestEndBlock) + if err := sfb.codec.Unmarshal(messageBytes[0], endBlockReq); err != nil { + res.Err = err.Error() + return res + } + endBlockRes := new(abci.ResponseEndBlock) + if err := sfb.codec.Unmarshal(messageBytes[len(messageBytes)-1], endBlockRes); err != nil { + res.Err = err.Error() + return res + } + kvPairs := make([]*types.StoreKVPair, len(messageBytes[1:len(messageBytes)-2])) + for i := 1; i < len(messageBytes) - 1; i++ { + kvPair := new(types.StoreKVPair) + if err := sfb.codec.Unmarshal(messageBytes[i], kvPair); err != nil { + res.Err = err.Error() + return res + } + kvPairs[i-1] = kvPair + } + res.EndBlockPayload = &pb.EndBlockPayload{ + Request: endBlockReq, + Response: endBlockRes, + StateChanges: kvPairs, + } + return res +} \ No newline at end of file diff --git a/state_file_server/grpc/grpc_server.go b/state_file_server/grpc/grpc_server.go new file mode 100644 index 000000000000..5637cf4f244c --- /dev/null +++ b/state_file_server/grpc/grpc_server.go @@ -0,0 +1,35 @@ +package grpc + +import ( + "fmt" + "net" + "time" + + "google.golang.org/grpc" + + "github.com/cosmos/cosmos-sdk/state_file_server/config" +) + +// StartGRPCServer starts a gRPC server on the given address. +func StartGRPCServer(config config.StateServerConfig) (*grpc.Server, error) { + grpcSrv := grpc.NewServer() + listener, err := net.Listen("tcp", config.GRPCAddress) + if err != nil { + return nil, err + } + + errCh := make(chan error) + go func() { + err = grpcSrv.Serve(listener) + if err != nil { + errCh <- fmt.Errorf("failed to serve: %w", err) + } + }() + + select { + case err := <-errCh: + return nil, err + case <-time.After(5 * time.Second): // assume server started successfully + return grpcSrv, nil + } +} diff --git a/state_file_server/grpc/grpc_web.go b/state_file_server/grpc/grpc_web.go new file mode 100644 index 000000000000..56bfabac0223 --- /dev/null +++ b/state_file_server/grpc/grpc_web.go @@ -0,0 +1,26 @@ +package grpc + +import ( + "net/http" + + "github.com/improbable-eng/grpc-web/go/grpcweb" + "google.golang.org/grpc" + + "github.com/cosmos/cosmos-sdk/state_file_server/config" +) + +// StartGRPCWeb starts a gRPC-Web server on the given address. +func StartGRPCWeb(grpcSrv *grpc.Server, config config.StateServerConfig) (*http.Server, error) { + wrappedServer := grpcweb.WrapServer(grpcSrv) + handler := func(resp http.ResponseWriter, req *http.Request) { + wrappedServer.ServeHTTP(resp, req) + } + grpcWebSrv := &http.Server{ + Addr: config.GRPCWebAddress, + Handler: http.HandlerFunc(handler), + } + if err := grpcWebSrv.ListenAndServe(); err != nil { + return nil, err + } + return grpcWebSrv, nil +} diff --git a/state_file_server/grpc/server.go b/state_file_server/grpc/server.go new file mode 100644 index 000000000000..006d78fad081 --- /dev/null +++ b/state_file_server/grpc/server.go @@ -0,0 +1,78 @@ +package grpc + +import ( + "context" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/state_file_server/config" + pb "github.com/cosmos/cosmos-sdk/state_file_server/grpc/v1beta" + "github.com/tendermint/tendermint/libs/log" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +type Handler = pb.StateFileServer + +// handler is the interface which exposes the StateFile Server methods +type handler struct { + pb.UnimplementedStateFileServer + backend *StateFileBackend + logger log.Logger +} + +// New returns the object for the RPC handler +func New(conf config.StateServerBackendConfig, codec *codec.ProtoCodec, logger log.Logger) (Handler, error) { + return &handler{ + backend: NewStateFileBackend(conf, codec, logger), + logger: logger, + }, nil +} + +// StreamData streams the requested state file data +// this streams new data as it is written to disk +func (h *handler) StreamData(req *pb.StreamRequest, srv pb.StateFile_StreamDataServer) error { + resChan := make(chan *pb.StreamResponse) + stopped := make(chan struct{}) + if err := h.backend.Stream(req, resChan, stopped); err != nil { + return err + } + for { + select { + case res := <-resChan: + if err := srv.Send(res); err != nil { + h.logger.Error("StreamData send error", "err", err) + } + case <-stopped: + return nil + } + } +} + +// BackFillData stream the requested state file data +// this stream data that is already written to disk +func (h *handler) BackFillData(req *pb.StreamRequest, srv pb.StateFile_BackFillDataServer) error { + resChan := make(chan *pb.StreamResponse) + stopped := make(chan struct{}) + if err := h.backend.BackFill(req, resChan, stopped); err != nil { + return err + } + for { + select { + case res := <-resChan: + if err := srv.Send(res); err != nil { + h.logger.Error("BackFillData send error", "err", err) + } + case <-stopped: + return nil + } + } +} + +func (h *handler) BeginBlockDataAt(ctx context.Context, req *pb.BeginBlockRequest) (*pb.BeginBlockPayload, error) { + return nil, status.Errorf(codes.Unimplemented, "method BeginBlockDataAt not implemented") +} +func (h *handler) DeliverTxDataAt(ctx context.Context, req *pb.DeliverTxRequest) (*pb.DeliverTxPayload, error) { + return nil, status.Errorf(codes.Unimplemented, "method DeliverTxDataAt not implemented") +} +func (h *handler) EndBlockDataAt(ctx context.Context, req *pb.EndBlockRequest) (*pb.EndBlockPayload, error) { + return nil, status.Errorf(codes.Unimplemented, "method EndBlockDataAt not implemented") +} \ No newline at end of file From 29f09ab4a81bf12a34fc0168b1931fca57e408e6 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 6 Jul 2021 12:57:55 -0500 Subject: [PATCH 36/46] move pkg --- proto/cosmos/base/server/v1beta1/server.proto | 2 +- .../streaming/file/server}/api/api.go | 0 .../streaming/file/server}/client/client.go | 0 .../streaming/file/server}/config/config.go | 0 .../streaming/file/server}/grpc/backend.go | 0 .../file/server}/grpc/grpc_server.go | 0 .../streaming/file/server}/grpc/grpc_web.go | 0 .../streaming/file/server}/grpc/server.go | 0 .../file/server/grpc/v1beta/server.pb.go | 2585 +++++++++++++++++ .../file/server}/v1beta/server.pb.go | 90 +- 10 files changed, 2631 insertions(+), 46 deletions(-) rename {state_file_server => store/streaming/file/server}/api/api.go (100%) rename {state_file_server => store/streaming/file/server}/client/client.go (100%) rename {state_file_server => store/streaming/file/server}/config/config.go (100%) rename {state_file_server => store/streaming/file/server}/grpc/backend.go (100%) rename {state_file_server => store/streaming/file/server}/grpc/grpc_server.go (100%) rename {state_file_server => store/streaming/file/server}/grpc/grpc_web.go (100%) rename {state_file_server => store/streaming/file/server}/grpc/server.go (100%) create mode 100644 store/streaming/file/server/grpc/v1beta/server.pb.go rename {state_file_server/grpc => store/streaming/file/server}/v1beta/server.pb.go (93%) diff --git a/proto/cosmos/base/server/v1beta1/server.proto b/proto/cosmos/base/server/v1beta1/server.proto index baa36b7af192..007c1cf41fc8 100644 --- a/proto/cosmos/base/server/v1beta1/server.proto +++ b/proto/cosmos/base/server/v1beta1/server.proto @@ -5,7 +5,7 @@ import "gogoproto/gogo.proto"; import "cosmos/base/store/v1beta1/listening.proto"; import "tendermint/abci/types.proto"; -option go_package = "github.com/cosmos/cosmos-sdk/state_file_server/grpc/v1beta"; +option go_package = "github.com/cosmos/cosmos-sdk/store/streaming/file/server/v1beta"; // StateFile service service StateFile { diff --git a/state_file_server/api/api.go b/store/streaming/file/server/api/api.go similarity index 100% rename from state_file_server/api/api.go rename to store/streaming/file/server/api/api.go diff --git a/state_file_server/client/client.go b/store/streaming/file/server/client/client.go similarity index 100% rename from state_file_server/client/client.go rename to store/streaming/file/server/client/client.go diff --git a/state_file_server/config/config.go b/store/streaming/file/server/config/config.go similarity index 100% rename from state_file_server/config/config.go rename to store/streaming/file/server/config/config.go diff --git a/state_file_server/grpc/backend.go b/store/streaming/file/server/grpc/backend.go similarity index 100% rename from state_file_server/grpc/backend.go rename to store/streaming/file/server/grpc/backend.go diff --git a/state_file_server/grpc/grpc_server.go b/store/streaming/file/server/grpc/grpc_server.go similarity index 100% rename from state_file_server/grpc/grpc_server.go rename to store/streaming/file/server/grpc/grpc_server.go diff --git a/state_file_server/grpc/grpc_web.go b/store/streaming/file/server/grpc/grpc_web.go similarity index 100% rename from state_file_server/grpc/grpc_web.go rename to store/streaming/file/server/grpc/grpc_web.go diff --git a/state_file_server/grpc/server.go b/store/streaming/file/server/grpc/server.go similarity index 100% rename from state_file_server/grpc/server.go rename to store/streaming/file/server/grpc/server.go diff --git a/store/streaming/file/server/grpc/v1beta/server.pb.go b/store/streaming/file/server/grpc/v1beta/server.pb.go new file mode 100644 index 000000000000..4c30e79110fb --- /dev/null +++ b/store/streaming/file/server/grpc/v1beta/server.pb.go @@ -0,0 +1,2585 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/base/server/v1beta1/server.proto + +package v1beta + +import ( + context "context" + fmt "fmt" + types1 "github.com/cosmos/cosmos-sdk/store/types" + _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + types "github.com/tendermint/tendermint/abci/types" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// StreamRequest is the message definition for a streaming request sent from a client to the server +type StreamRequest struct { + // begin_block specifies whether or not stream BeginBlock files + BeginBlock bool `protobuf:"varint,1,opt,name=begin_block,json=beginBlock,proto3" json:"begin_block,omitempty"` + // deliver_tx specifies whether or not to stream DeliverTx files + DeliverTx bool `protobuf:"varint,2,opt,name=deliver_tx,json=deliverTx,proto3" json:"deliver_tx,omitempty"` + // end_block specifies whether or not to stream EndBlock files + EndBlock bool `protobuf:"varint,3,opt,name=end_block,json=endBlock,proto3" json:"end_block,omitempty"` + // store_keys is a (optional) list of store keys for which to restrict the streamed KVPairs to + StoreKeys []string `protobuf:"bytes,4,rep,name=store_keys,json=storeKeys,proto3" json:"store_keys,omitempty"` +} + +func (m *StreamRequest) Reset() { *m = StreamRequest{} } +func (m *StreamRequest) String() string { return proto.CompactTextString(m) } +func (*StreamRequest) ProtoMessage() {} +func (*StreamRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_9b48d4169ef99d67, []int{0} +} +func (m *StreamRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *StreamRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_StreamRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *StreamRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_StreamRequest.Merge(m, src) +} +func (m *StreamRequest) XXX_Size() int { + return m.Size() +} +func (m *StreamRequest) XXX_DiscardUnknown() { + xxx_messageInfo_StreamRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_StreamRequest proto.InternalMessageInfo + +func (m *StreamRequest) GetBeginBlock() bool { + if m != nil { + return m.BeginBlock + } + return false +} + +func (m *StreamRequest) GetDeliverTx() bool { + if m != nil { + return m.DeliverTx + } + return false +} + +func (m *StreamRequest) GetEndBlock() bool { + if m != nil { + return m.EndBlock + } + return false +} + +func (m *StreamRequest) GetStoreKeys() []string { + if m != nil { + return m.StoreKeys + } + return nil +} + +// BeginBlockRequest is the message definition for requesting BeginBlock data at a specific height +type BeginBlockRequest struct { + Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` +} + +func (m *BeginBlockRequest) Reset() { *m = BeginBlockRequest{} } +func (m *BeginBlockRequest) String() string { return proto.CompactTextString(m) } +func (*BeginBlockRequest) ProtoMessage() {} +func (*BeginBlockRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_9b48d4169ef99d67, []int{1} +} +func (m *BeginBlockRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BeginBlockRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BeginBlockRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *BeginBlockRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_BeginBlockRequest.Merge(m, src) +} +func (m *BeginBlockRequest) XXX_Size() int { + return m.Size() +} +func (m *BeginBlockRequest) XXX_DiscardUnknown() { + xxx_messageInfo_BeginBlockRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_BeginBlockRequest proto.InternalMessageInfo + +func (m *BeginBlockRequest) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +// DeliverTxRequest is the message definition for requesting DeliverTx data at a specific height +type DeliverTxRequest struct { + Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` +} + +func (m *DeliverTxRequest) Reset() { *m = DeliverTxRequest{} } +func (m *DeliverTxRequest) String() string { return proto.CompactTextString(m) } +func (*DeliverTxRequest) ProtoMessage() {} +func (*DeliverTxRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_9b48d4169ef99d67, []int{2} +} +func (m *DeliverTxRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DeliverTxRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DeliverTxRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DeliverTxRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeliverTxRequest.Merge(m, src) +} +func (m *DeliverTxRequest) XXX_Size() int { + return m.Size() +} +func (m *DeliverTxRequest) XXX_DiscardUnknown() { + xxx_messageInfo_DeliverTxRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_DeliverTxRequest proto.InternalMessageInfo + +func (m *DeliverTxRequest) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +// EndBlockRequest is the message definition for requesting EndBlock data at a specific height +type EndBlockRequest struct { + Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` +} + +func (m *EndBlockRequest) Reset() { *m = EndBlockRequest{} } +func (m *EndBlockRequest) String() string { return proto.CompactTextString(m) } +func (*EndBlockRequest) ProtoMessage() {} +func (*EndBlockRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_9b48d4169ef99d67, []int{3} +} +func (m *EndBlockRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EndBlockRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EndBlockRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *EndBlockRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_EndBlockRequest.Merge(m, src) +} +func (m *EndBlockRequest) XXX_Size() int { + return m.Size() +} +func (m *EndBlockRequest) XXX_DiscardUnknown() { + xxx_messageInfo_EndBlockRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_EndBlockRequest proto.InternalMessageInfo + +func (m *EndBlockRequest) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +// StreamResponse contains the response data for a stream request +type StreamResponse struct { + // The ChainID for the tendermint application we are streaming data for + ChainId string `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + // The block height that this response is for + Height int64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty"` + // begin_block_payload contains the BeginBlock data + BeginBlockPayload *BeginBlockPayload `protobuf:"bytes,3,opt,name=begin_block_payload,json=beginBlockPayload,proto3" json:"begin_block_payload,omitempty"` + // deliver_tx_payload contains the DeliverTx data + DeliverTxPayload *DeliverTxPayload `protobuf:"bytes,4,opt,name=deliver_tx_payload,json=deliverTxPayload,proto3" json:"deliver_tx_payload,omitempty"` + // end_block_payload contains the EndBlock data + EndBlockPayload *EndBlockPayload `protobuf:"bytes,5,opt,name=end_block_payload,json=endBlockPayload,proto3" json:"end_block_payload,omitempty"` + // error holds any error that occurred while generating the response + Err string `protobuf:"bytes,6,opt,name=err,proto3" json:"err,omitempty"` +} + +func (m *StreamResponse) Reset() { *m = StreamResponse{} } +func (m *StreamResponse) String() string { return proto.CompactTextString(m) } +func (*StreamResponse) ProtoMessage() {} +func (*StreamResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_9b48d4169ef99d67, []int{4} +} +func (m *StreamResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *StreamResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_StreamResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *StreamResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_StreamResponse.Merge(m, src) +} +func (m *StreamResponse) XXX_Size() int { + return m.Size() +} +func (m *StreamResponse) XXX_DiscardUnknown() { + xxx_messageInfo_StreamResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_StreamResponse proto.InternalMessageInfo + +func (m *StreamResponse) GetChainId() string { + if m != nil { + return m.ChainId + } + return "" +} + +func (m *StreamResponse) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +func (m *StreamResponse) GetBeginBlockPayload() *BeginBlockPayload { + if m != nil { + return m.BeginBlockPayload + } + return nil +} + +func (m *StreamResponse) GetDeliverTxPayload() *DeliverTxPayload { + if m != nil { + return m.DeliverTxPayload + } + return nil +} + +func (m *StreamResponse) GetEndBlockPayload() *EndBlockPayload { + if m != nil { + return m.EndBlockPayload + } + return nil +} + +func (m *StreamResponse) GetErr() string { + if m != nil { + return m.Err + } + return "" +} + +// BeginBlockPayload contains the BeginBlock data +type BeginBlockPayload struct { + Request *types.RequestBeginBlock `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"` + Response *types.ResponseBeginBlock `protobuf:"bytes,2,opt,name=response,proto3" json:"response,omitempty"` + StateChanges []*types1.StoreKVPair `protobuf:"bytes,3,rep,name=state_changes,json=stateChanges,proto3" json:"state_changes,omitempty"` +} + +func (m *BeginBlockPayload) Reset() { *m = BeginBlockPayload{} } +func (m *BeginBlockPayload) String() string { return proto.CompactTextString(m) } +func (*BeginBlockPayload) ProtoMessage() {} +func (*BeginBlockPayload) Descriptor() ([]byte, []int) { + return fileDescriptor_9b48d4169ef99d67, []int{5} +} +func (m *BeginBlockPayload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BeginBlockPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BeginBlockPayload.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *BeginBlockPayload) XXX_Merge(src proto.Message) { + xxx_messageInfo_BeginBlockPayload.Merge(m, src) +} +func (m *BeginBlockPayload) XXX_Size() int { + return m.Size() +} +func (m *BeginBlockPayload) XXX_DiscardUnknown() { + xxx_messageInfo_BeginBlockPayload.DiscardUnknown(m) +} + +var xxx_messageInfo_BeginBlockPayload proto.InternalMessageInfo + +func (m *BeginBlockPayload) GetRequest() *types.RequestBeginBlock { + if m != nil { + return m.Request + } + return nil +} + +func (m *BeginBlockPayload) GetResponse() *types.ResponseBeginBlock { + if m != nil { + return m.Response + } + return nil +} + +func (m *BeginBlockPayload) GetStateChanges() []*types1.StoreKVPair { + if m != nil { + return m.StateChanges + } + return nil +} + +// DeliverTxPayload contains the DeliverTx data +type DeliverTxPayload struct { + Request *types.RequestDeliverTx `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"` + Response *types.ResponseDeliverTx `protobuf:"bytes,2,opt,name=response,proto3" json:"response,omitempty"` + StateChanges []*types1.StoreKVPair `protobuf:"bytes,3,rep,name=state_changes,json=stateChanges,proto3" json:"state_changes,omitempty"` +} + +func (m *DeliverTxPayload) Reset() { *m = DeliverTxPayload{} } +func (m *DeliverTxPayload) String() string { return proto.CompactTextString(m) } +func (*DeliverTxPayload) ProtoMessage() {} +func (*DeliverTxPayload) Descriptor() ([]byte, []int) { + return fileDescriptor_9b48d4169ef99d67, []int{6} +} +func (m *DeliverTxPayload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DeliverTxPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DeliverTxPayload.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DeliverTxPayload) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeliverTxPayload.Merge(m, src) +} +func (m *DeliverTxPayload) XXX_Size() int { + return m.Size() +} +func (m *DeliverTxPayload) XXX_DiscardUnknown() { + xxx_messageInfo_DeliverTxPayload.DiscardUnknown(m) +} + +var xxx_messageInfo_DeliverTxPayload proto.InternalMessageInfo + +func (m *DeliverTxPayload) GetRequest() *types.RequestDeliverTx { + if m != nil { + return m.Request + } + return nil +} + +func (m *DeliverTxPayload) GetResponse() *types.ResponseDeliverTx { + if m != nil { + return m.Response + } + return nil +} + +func (m *DeliverTxPayload) GetStateChanges() []*types1.StoreKVPair { + if m != nil { + return m.StateChanges + } + return nil +} + +// EndBlockPayload contains the EndBlock data +type EndBlockPayload struct { + Request *types.RequestEndBlock `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"` + Response *types.ResponseEndBlock `protobuf:"bytes,2,opt,name=response,proto3" json:"response,omitempty"` + StateChanges []*types1.StoreKVPair `protobuf:"bytes,3,rep,name=state_changes,json=stateChanges,proto3" json:"state_changes,omitempty"` +} + +func (m *EndBlockPayload) Reset() { *m = EndBlockPayload{} } +func (m *EndBlockPayload) String() string { return proto.CompactTextString(m) } +func (*EndBlockPayload) ProtoMessage() {} +func (*EndBlockPayload) Descriptor() ([]byte, []int) { + return fileDescriptor_9b48d4169ef99d67, []int{7} +} +func (m *EndBlockPayload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EndBlockPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EndBlockPayload.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *EndBlockPayload) XXX_Merge(src proto.Message) { + xxx_messageInfo_EndBlockPayload.Merge(m, src) +} +func (m *EndBlockPayload) XXX_Size() int { + return m.Size() +} +func (m *EndBlockPayload) XXX_DiscardUnknown() { + xxx_messageInfo_EndBlockPayload.DiscardUnknown(m) +} + +var xxx_messageInfo_EndBlockPayload proto.InternalMessageInfo + +func (m *EndBlockPayload) GetRequest() *types.RequestEndBlock { + if m != nil { + return m.Request + } + return nil +} + +func (m *EndBlockPayload) GetResponse() *types.ResponseEndBlock { + if m != nil { + return m.Response + } + return nil +} + +func (m *EndBlockPayload) GetStateChanges() []*types1.StoreKVPair { + if m != nil { + return m.StateChanges + } + return nil +} + +func init() { + proto.RegisterType((*StreamRequest)(nil), "cosmos.base.server.v1beta1.StreamRequest") + proto.RegisterType((*BeginBlockRequest)(nil), "cosmos.base.server.v1beta1.BeginBlockRequest") + proto.RegisterType((*DeliverTxRequest)(nil), "cosmos.base.server.v1beta1.DeliverTxRequest") + proto.RegisterType((*EndBlockRequest)(nil), "cosmos.base.server.v1beta1.EndBlockRequest") + proto.RegisterType((*StreamResponse)(nil), "cosmos.base.server.v1beta1.StreamResponse") + proto.RegisterType((*BeginBlockPayload)(nil), "cosmos.base.server.v1beta1.BeginBlockPayload") + proto.RegisterType((*DeliverTxPayload)(nil), "cosmos.base.server.v1beta1.DeliverTxPayload") + proto.RegisterType((*EndBlockPayload)(nil), "cosmos.base.server.v1beta1.EndBlockPayload") +} + +func init() { + proto.RegisterFile("cosmos/base/server/v1beta1/server.proto", fileDescriptor_9b48d4169ef99d67) +} + +var fileDescriptor_9b48d4169ef99d67 = []byte{ + // 733 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x4b, 0x6f, 0xd3, 0x4c, + 0x14, 0xb5, 0xeb, 0x7c, 0x6d, 0x32, 0xe9, 0x73, 0x3e, 0x54, 0x85, 0x54, 0xa4, 0xa9, 0x91, 0xa0, + 0x0f, 0x6a, 0xd3, 0xb0, 0xe3, 0x29, 0x42, 0xa9, 0x84, 0xba, 0xa9, 0x5c, 0xc4, 0x02, 0x09, 0x82, + 0x1f, 0x83, 0x33, 0x8a, 0x63, 0x87, 0x99, 0x69, 0xd5, 0x2c, 0x59, 0xb3, 0xe1, 0xb7, 0xf0, 0x2b, + 0xba, 0xec, 0x12, 0x24, 0x04, 0xa8, 0xfd, 0x23, 0xc8, 0xe3, 0xf1, 0xd8, 0x49, 0x49, 0x9b, 0x2e, + 0xba, 0x6a, 0x7d, 0xe7, 0x9c, 0x7b, 0xe6, 0xdc, 0x7b, 0x67, 0x26, 0xe0, 0xae, 0x1b, 0xd1, 0x6e, + 0x44, 0x4d, 0xc7, 0xa6, 0xc8, 0xa4, 0x88, 0x1c, 0x22, 0x62, 0x1e, 0x6e, 0x39, 0x88, 0xd9, 0x5b, + 0xe2, 0xd3, 0xe8, 0x91, 0x88, 0x45, 0xb0, 0x9a, 0x00, 0x8d, 0x18, 0x68, 0x88, 0x15, 0x01, 0xac, + 0xde, 0xf0, 0x23, 0x3f, 0xe2, 0x30, 0x33, 0xfe, 0x2f, 0x61, 0x54, 0xd7, 0x06, 0x52, 0xb3, 0x88, + 0x20, 0x99, 0x39, 0xc0, 0x94, 0xa1, 0x10, 0x87, 0xbe, 0x80, 0x2e, 0x31, 0x14, 0x7a, 0x88, 0x74, + 0x71, 0xc8, 0x4c, 0xdb, 0x71, 0xb1, 0xc9, 0xfa, 0x3d, 0x44, 0x93, 0x45, 0xfd, 0x8b, 0x0a, 0x66, + 0xf6, 0x19, 0x41, 0x76, 0xd7, 0x42, 0x9f, 0x0e, 0x10, 0x65, 0x70, 0x19, 0x94, 0x1d, 0xe4, 0xe3, + 0xb0, 0xe5, 0x04, 0x91, 0xdb, 0xa9, 0xa8, 0x75, 0x75, 0xb5, 0x68, 0x01, 0x1e, 0x6a, 0xc6, 0x11, + 0x78, 0x0b, 0x00, 0x0f, 0x05, 0xf8, 0x10, 0x91, 0x16, 0x3b, 0xaa, 0x4c, 0xf0, 0xf5, 0x92, 0x88, + 0xbc, 0x3e, 0x82, 0x4b, 0xa0, 0x84, 0x42, 0x4f, 0xb0, 0x35, 0xbe, 0x5a, 0x44, 0xa1, 0x27, 0xb9, + 0x7c, 0xb3, 0xad, 0x0e, 0xea, 0xd3, 0x4a, 0xa1, 0xae, 0xad, 0x96, 0xac, 0x12, 0x8f, 0xec, 0xa2, + 0x3e, 0xd5, 0x37, 0xc0, 0x42, 0x53, 0x0a, 0xa5, 0x1b, 0x5a, 0x04, 0x93, 0x6d, 0x84, 0xfd, 0x36, + 0xe3, 0x7b, 0xd1, 0x2c, 0xf1, 0xa5, 0xaf, 0x83, 0xf9, 0xed, 0x54, 0xf5, 0x32, 0xec, 0x1a, 0x98, + 0x7b, 0x29, 0xf6, 0x70, 0x19, 0xf4, 0xb3, 0x06, 0x66, 0xd3, 0x8a, 0xd0, 0x5e, 0x14, 0x52, 0x04, + 0x6f, 0x82, 0xa2, 0xdb, 0xb6, 0x71, 0xd8, 0xc2, 0x1e, 0x07, 0x97, 0xac, 0x29, 0xfe, 0xfd, 0xca, + 0xcb, 0x65, 0x99, 0xc8, 0x67, 0x81, 0x2e, 0xf8, 0x3f, 0x57, 0xc5, 0x56, 0xcf, 0xee, 0x07, 0x91, + 0xed, 0xf1, 0x7a, 0x94, 0x1b, 0x9b, 0xc6, 0xe8, 0x7e, 0x1b, 0x59, 0x01, 0xf6, 0x12, 0x52, 0xb3, + 0x70, 0xfc, 0x6b, 0x59, 0xb5, 0x16, 0x9c, 0xe1, 0x05, 0xf8, 0x01, 0xc0, 0xac, 0x13, 0x52, 0xa3, + 0xc0, 0x35, 0xee, 0x5d, 0xa4, 0x21, 0xeb, 0x36, 0x28, 0x31, 0xef, 0x0d, 0xc5, 0xe1, 0x3b, 0xb0, + 0x20, 0x9b, 0x29, 0x05, 0xfe, 0xe3, 0x02, 0x1b, 0x17, 0x09, 0xa4, 0xc5, 0x1e, 0xcc, 0x3f, 0x87, + 0x06, 0xc3, 0x70, 0x11, 0x68, 0x88, 0x90, 0xca, 0x64, 0x5c, 0x53, 0x81, 0x89, 0x03, 0xfa, 0x6f, + 0x35, 0x3f, 0x08, 0x29, 0xfa, 0x31, 0x98, 0x22, 0x49, 0xf3, 0x78, 0x17, 0xca, 0x0d, 0xdd, 0xc8, + 0x46, 0xdb, 0x88, 0x47, 0xdb, 0x10, 0xcd, 0xcd, 0x0d, 0x51, 0x4a, 0x81, 0xcf, 0x40, 0x91, 0x88, + 0x86, 0xf2, 0x5e, 0x95, 0x1b, 0xb7, 0xff, 0x41, 0x4f, 0x00, 0x39, 0xbe, 0x24, 0xc1, 0x5d, 0x30, + 0x43, 0x99, 0xcd, 0x50, 0xcb, 0x6d, 0xdb, 0xa1, 0x8f, 0x68, 0x45, 0xab, 0x6b, 0xab, 0xe5, 0xc6, + 0x9d, 0xc1, 0x3a, 0xc4, 0xb3, 0x2c, 0xcb, 0xb0, 0xcf, 0x27, 0xfb, 0xcd, 0x9e, 0x8d, 0x89, 0x35, + 0xcd, 0xc9, 0x2f, 0x12, 0xae, 0xfe, 0x53, 0xcd, 0x4d, 0x6f, 0x6a, 0xf0, 0xd1, 0xb0, 0xc1, 0x95, + 0x51, 0x06, 0xb3, 0xc1, 0x97, 0xfe, 0x9e, 0x9e, 0xf3, 0xa7, 0x8f, 0xf4, 0x97, 0xd1, 0xaf, 0xc9, + 0xde, 0x0f, 0x35, 0x3b, 0x70, 0xa9, 0xbb, 0x87, 0xc3, 0xee, 0xea, 0xa3, 0xdc, 0xc9, 0xa3, 0x2a, + 0xcd, 0x3d, 0x39, 0x67, 0x6e, 0x65, 0xa4, 0x39, 0xc9, 0xbe, 0x1e, 0x6f, 0x8d, 0x6f, 0x05, 0x50, + 0xda, 0x8f, 0x03, 0x3b, 0x38, 0x40, 0x90, 0x80, 0xf9, 0x6c, 0x5a, 0xb6, 0x6d, 0x66, 0x3f, 0x67, + 0x70, 0xcc, 0xf3, 0x2d, 0xdc, 0x56, 0xaf, 0x76, 0x1d, 0xe8, 0x0a, 0x8c, 0xc0, 0x9c, 0xec, 0xa0, + 0x90, 0x1c, 0xef, 0xb8, 0xa7, 0x8a, 0x57, 0xba, 0x1c, 0x74, 0x05, 0x06, 0x60, 0x36, 0xad, 0xaa, + 0xd0, 0x1b, 0xeb, 0xf4, 0xa7, 0x72, 0x57, 0xb9, 0x2a, 0x74, 0x05, 0xfa, 0x00, 0x24, 0x17, 0x70, + 0xac, 0x05, 0xd7, 0x2e, 0x22, 0x0f, 0x3c, 0x5d, 0xd5, 0xf5, 0x71, 0xa0, 0xc9, 0x48, 0xe8, 0xca, + 0x7d, 0x15, 0x62, 0x30, 0xdd, 0xb4, 0xdd, 0xce, 0x0e, 0x0e, 0x82, 0x6b, 0x96, 0x6a, 0xbe, 0x3f, + 0x3e, 0xad, 0xa9, 0x27, 0xa7, 0x35, 0xf5, 0xcf, 0x69, 0x4d, 0xfd, 0x7a, 0x56, 0x53, 0x4e, 0xce, + 0x6a, 0xca, 0xf7, 0xb3, 0x9a, 0xf2, 0x76, 0xdb, 0xc7, 0xac, 0x7d, 0xe0, 0x18, 0x6e, 0xd4, 0x35, + 0xc5, 0xa3, 0x9e, 0xfc, 0xd9, 0xa4, 0x5e, 0x47, 0x3c, 0xed, 0x94, 0x27, 0xc4, 0xa1, 0x6f, 0x7e, + 0xc4, 0x81, 0xfc, 0x29, 0xe1, 0x93, 0x9e, 0x2b, 0x5e, 0x7d, 0x67, 0x92, 0x3f, 0xe7, 0x0f, 0xfe, + 0x06, 0x00, 0x00, 0xff, 0xff, 0xed, 0x94, 0x60, 0xfc, 0x73, 0x08, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// StateFileClient is the client API for StateFile service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type StateFileClient interface { + BeginBlockDataAt(ctx context.Context, in *BeginBlockRequest, opts ...grpc.CallOption) (*BeginBlockPayload, error) + DeliverTxDataAt(ctx context.Context, in *DeliverTxRequest, opts ...grpc.CallOption) (*DeliverTxPayload, error) + EndBlockDataAt(ctx context.Context, in *EndBlockRequest, opts ...grpc.CallOption) (*EndBlockPayload, error) + StreamData(ctx context.Context, in *StreamRequest, opts ...grpc.CallOption) (StateFile_StreamDataClient, error) + BackFillData(ctx context.Context, in *StreamRequest, opts ...grpc.CallOption) (StateFile_BackFillDataClient, error) +} + +type stateFileClient struct { + cc grpc1.ClientConn +} + +func NewStateFileClient(cc grpc1.ClientConn) StateFileClient { + return &stateFileClient{cc} +} + +func (c *stateFileClient) BeginBlockDataAt(ctx context.Context, in *BeginBlockRequest, opts ...grpc.CallOption) (*BeginBlockPayload, error) { + out := new(BeginBlockPayload) + err := c.cc.Invoke(ctx, "/cosmos.base.server.v1beta1.StateFile/BeginBlockDataAt", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *stateFileClient) DeliverTxDataAt(ctx context.Context, in *DeliverTxRequest, opts ...grpc.CallOption) (*DeliverTxPayload, error) { + out := new(DeliverTxPayload) + err := c.cc.Invoke(ctx, "/cosmos.base.server.v1beta1.StateFile/DeliverTxDataAt", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *stateFileClient) EndBlockDataAt(ctx context.Context, in *EndBlockRequest, opts ...grpc.CallOption) (*EndBlockPayload, error) { + out := new(EndBlockPayload) + err := c.cc.Invoke(ctx, "/cosmos.base.server.v1beta1.StateFile/EndBlockDataAt", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *stateFileClient) StreamData(ctx context.Context, in *StreamRequest, opts ...grpc.CallOption) (StateFile_StreamDataClient, error) { + stream, err := c.cc.NewStream(ctx, &_StateFile_serviceDesc.Streams[0], "/cosmos.base.server.v1beta1.StateFile/StreamData", opts...) + if err != nil { + return nil, err + } + x := &stateFileStreamDataClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type StateFile_StreamDataClient interface { + Recv() (*StreamResponse, error) + grpc.ClientStream +} + +type stateFileStreamDataClient struct { + grpc.ClientStream +} + +func (x *stateFileStreamDataClient) Recv() (*StreamResponse, error) { + m := new(StreamResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func (c *stateFileClient) BackFillData(ctx context.Context, in *StreamRequest, opts ...grpc.CallOption) (StateFile_BackFillDataClient, error) { + stream, err := c.cc.NewStream(ctx, &_StateFile_serviceDesc.Streams[1], "/cosmos.base.server.v1beta1.StateFile/BackFillData", opts...) + if err != nil { + return nil, err + } + x := &stateFileBackFillDataClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type StateFile_BackFillDataClient interface { + Recv() (*StreamResponse, error) + grpc.ClientStream +} + +type stateFileBackFillDataClient struct { + grpc.ClientStream +} + +func (x *stateFileBackFillDataClient) Recv() (*StreamResponse, error) { + m := new(StreamResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +// StateFileServer is the server API for StateFile service. +type StateFileServer interface { + BeginBlockDataAt(context.Context, *BeginBlockRequest) (*BeginBlockPayload, error) + DeliverTxDataAt(context.Context, *DeliverTxRequest) (*DeliverTxPayload, error) + EndBlockDataAt(context.Context, *EndBlockRequest) (*EndBlockPayload, error) + StreamData(*StreamRequest, StateFile_StreamDataServer) error + BackFillData(*StreamRequest, StateFile_BackFillDataServer) error +} + +// UnimplementedStateFileServer can be embedded to have forward compatible implementations. +type UnimplementedStateFileServer struct { +} + +func (*UnimplementedStateFileServer) BeginBlockDataAt(ctx context.Context, req *BeginBlockRequest) (*BeginBlockPayload, error) { + return nil, status.Errorf(codes.Unimplemented, "method BeginBlockDataAt not implemented") +} +func (*UnimplementedStateFileServer) DeliverTxDataAt(ctx context.Context, req *DeliverTxRequest) (*DeliverTxPayload, error) { + return nil, status.Errorf(codes.Unimplemented, "method DeliverTxDataAt not implemented") +} +func (*UnimplementedStateFileServer) EndBlockDataAt(ctx context.Context, req *EndBlockRequest) (*EndBlockPayload, error) { + return nil, status.Errorf(codes.Unimplemented, "method EndBlockDataAt not implemented") +} +func (*UnimplementedStateFileServer) StreamData(req *StreamRequest, srv StateFile_StreamDataServer) error { + return status.Errorf(codes.Unimplemented, "method StreamData not implemented") +} +func (*UnimplementedStateFileServer) BackFillData(req *StreamRequest, srv StateFile_BackFillDataServer) error { + return status.Errorf(codes.Unimplemented, "method BackFillData not implemented") +} + +func RegisterStateFileServer(s grpc1.Server, srv StateFileServer) { + s.RegisterService(&_StateFile_serviceDesc, srv) +} + +func _StateFile_BeginBlockDataAt_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BeginBlockRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StateFileServer).BeginBlockDataAt(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.base.server.v1beta1.StateFile/BeginBlockDataAt", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StateFileServer).BeginBlockDataAt(ctx, req.(*BeginBlockRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _StateFile_DeliverTxDataAt_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeliverTxRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StateFileServer).DeliverTxDataAt(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.base.server.v1beta1.StateFile/DeliverTxDataAt", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StateFileServer).DeliverTxDataAt(ctx, req.(*DeliverTxRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _StateFile_EndBlockDataAt_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EndBlockRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StateFileServer).EndBlockDataAt(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.base.server.v1beta1.StateFile/EndBlockDataAt", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StateFileServer).EndBlockDataAt(ctx, req.(*EndBlockRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _StateFile_StreamData_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(StreamRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(StateFileServer).StreamData(m, &stateFileStreamDataServer{stream}) +} + +type StateFile_StreamDataServer interface { + Send(*StreamResponse) error + grpc.ServerStream +} + +type stateFileStreamDataServer struct { + grpc.ServerStream +} + +func (x *stateFileStreamDataServer) Send(m *StreamResponse) error { + return x.ServerStream.SendMsg(m) +} + +func _StateFile_BackFillData_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(StreamRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(StateFileServer).BackFillData(m, &stateFileBackFillDataServer{stream}) +} + +type StateFile_BackFillDataServer interface { + Send(*StreamResponse) error + grpc.ServerStream +} + +type stateFileBackFillDataServer struct { + grpc.ServerStream +} + +func (x *stateFileBackFillDataServer) Send(m *StreamResponse) error { + return x.ServerStream.SendMsg(m) +} + +var _StateFile_serviceDesc = grpc.ServiceDesc{ + ServiceName: "cosmos.base.server.v1beta1.StateFile", + HandlerType: (*StateFileServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "BeginBlockDataAt", + Handler: _StateFile_BeginBlockDataAt_Handler, + }, + { + MethodName: "DeliverTxDataAt", + Handler: _StateFile_DeliverTxDataAt_Handler, + }, + { + MethodName: "EndBlockDataAt", + Handler: _StateFile_EndBlockDataAt_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "StreamData", + Handler: _StateFile_StreamData_Handler, + ServerStreams: true, + }, + { + StreamName: "BackFillData", + Handler: _StateFile_BackFillData_Handler, + ServerStreams: true, + }, + }, + Metadata: "cosmos/base/server/v1beta1/server.proto", +} + +func (m *StreamRequest) 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 *StreamRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *StreamRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.StoreKeys) > 0 { + for iNdEx := len(m.StoreKeys) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.StoreKeys[iNdEx]) + copy(dAtA[i:], m.StoreKeys[iNdEx]) + i = encodeVarintServer(dAtA, i, uint64(len(m.StoreKeys[iNdEx]))) + i-- + dAtA[i] = 0x22 + } + } + if m.EndBlock { + i-- + if m.EndBlock { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x18 + } + if m.DeliverTx { + i-- + if m.DeliverTx { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } + if m.BeginBlock { + i-- + if m.BeginBlock { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *BeginBlockRequest) 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 *BeginBlockRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BeginBlockRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Height != 0 { + i = encodeVarintServer(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *DeliverTxRequest) 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 *DeliverTxRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DeliverTxRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Height != 0 { + i = encodeVarintServer(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *EndBlockRequest) 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 *EndBlockRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EndBlockRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Height != 0 { + i = encodeVarintServer(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *StreamResponse) 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 *StreamResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *StreamResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Err) > 0 { + i -= len(m.Err) + copy(dAtA[i:], m.Err) + i = encodeVarintServer(dAtA, i, uint64(len(m.Err))) + i-- + dAtA[i] = 0x32 + } + if m.EndBlockPayload != nil { + { + size, err := m.EndBlockPayload.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + if m.DeliverTxPayload != nil { + { + size, err := m.DeliverTxPayload.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + if m.BeginBlockPayload != nil { + { + size, err := m.BeginBlockPayload.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if m.Height != 0 { + i = encodeVarintServer(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x10 + } + if len(m.ChainId) > 0 { + i -= len(m.ChainId) + copy(dAtA[i:], m.ChainId) + i = encodeVarintServer(dAtA, i, uint64(len(m.ChainId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *BeginBlockPayload) 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 *BeginBlockPayload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BeginBlockPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.StateChanges) > 0 { + for iNdEx := len(m.StateChanges) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.StateChanges[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if m.Response != nil { + { + size, err := m.Response.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.Request != nil { + { + size, err := m.Request.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *DeliverTxPayload) 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 *DeliverTxPayload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DeliverTxPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.StateChanges) > 0 { + for iNdEx := len(m.StateChanges) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.StateChanges[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if m.Response != nil { + { + size, err := m.Response.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.Request != nil { + { + size, err := m.Request.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *EndBlockPayload) 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 *EndBlockPayload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EndBlockPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.StateChanges) > 0 { + for iNdEx := len(m.StateChanges) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.StateChanges[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if m.Response != nil { + { + size, err := m.Response.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.Request != nil { + { + size, err := m.Request.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintServer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintServer(dAtA []byte, offset int, v uint64) int { + offset -= sovServer(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *StreamRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BeginBlock { + n += 2 + } + if m.DeliverTx { + n += 2 + } + if m.EndBlock { + n += 2 + } + if len(m.StoreKeys) > 0 { + for _, s := range m.StoreKeys { + l = len(s) + n += 1 + l + sovServer(uint64(l)) + } + } + return n +} + +func (m *BeginBlockRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Height != 0 { + n += 1 + sovServer(uint64(m.Height)) + } + return n +} + +func (m *DeliverTxRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Height != 0 { + n += 1 + sovServer(uint64(m.Height)) + } + return n +} + +func (m *EndBlockRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Height != 0 { + n += 1 + sovServer(uint64(m.Height)) + } + return n +} + +func (m *StreamResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovServer(uint64(l)) + } + if m.Height != 0 { + n += 1 + sovServer(uint64(m.Height)) + } + if m.BeginBlockPayload != nil { + l = m.BeginBlockPayload.Size() + n += 1 + l + sovServer(uint64(l)) + } + if m.DeliverTxPayload != nil { + l = m.DeliverTxPayload.Size() + n += 1 + l + sovServer(uint64(l)) + } + if m.EndBlockPayload != nil { + l = m.EndBlockPayload.Size() + n += 1 + l + sovServer(uint64(l)) + } + l = len(m.Err) + if l > 0 { + n += 1 + l + sovServer(uint64(l)) + } + return n +} + +func (m *BeginBlockPayload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Request != nil { + l = m.Request.Size() + n += 1 + l + sovServer(uint64(l)) + } + if m.Response != nil { + l = m.Response.Size() + n += 1 + l + sovServer(uint64(l)) + } + if len(m.StateChanges) > 0 { + for _, e := range m.StateChanges { + l = e.Size() + n += 1 + l + sovServer(uint64(l)) + } + } + return n +} + +func (m *DeliverTxPayload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Request != nil { + l = m.Request.Size() + n += 1 + l + sovServer(uint64(l)) + } + if m.Response != nil { + l = m.Response.Size() + n += 1 + l + sovServer(uint64(l)) + } + if len(m.StateChanges) > 0 { + for _, e := range m.StateChanges { + l = e.Size() + n += 1 + l + sovServer(uint64(l)) + } + } + return n +} + +func (m *EndBlockPayload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Request != nil { + l = m.Request.Size() + n += 1 + l + sovServer(uint64(l)) + } + if m.Response != nil { + l = m.Response.Size() + n += 1 + l + sovServer(uint64(l)) + } + if len(m.StateChanges) > 0 { + for _, e := range m.StateChanges { + l = e.Size() + n += 1 + l + sovServer(uint64(l)) + } + } + return n +} + +func sovServer(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozServer(x uint64) (n int) { + return sovServer(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *StreamRequest) 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 ErrIntOverflowServer + } + 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: StreamRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: StreamRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BeginBlock", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.BeginBlock = bool(v != 0) + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DeliverTx", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.DeliverTx = bool(v != 0) + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EndBlock", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.EndBlock = bool(v != 0) + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StoreKeys", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + 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 ErrInvalidLengthServer + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StoreKeys = append(m.StoreKeys, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipServer(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthServer + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *BeginBlockRequest) 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 ErrIntOverflowServer + } + 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: BeginBlockRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BeginBlockRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipServer(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthServer + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DeliverTxRequest) 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 ErrIntOverflowServer + } + 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: DeliverTxRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DeliverTxRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipServer(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthServer + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *EndBlockRequest) 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 ErrIntOverflowServer + } + 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: EndBlockRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EndBlockRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipServer(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthServer + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *StreamResponse) 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 ErrIntOverflowServer + } + 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: StreamResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: StreamResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + 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 ErrInvalidLengthServer + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BeginBlockPayload", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.BeginBlockPayload == nil { + m.BeginBlockPayload = &BeginBlockPayload{} + } + if err := m.BeginBlockPayload.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DeliverTxPayload", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.DeliverTxPayload == nil { + m.DeliverTxPayload = &DeliverTxPayload{} + } + if err := m.DeliverTxPayload.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EndBlockPayload", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.EndBlockPayload == nil { + m.EndBlockPayload = &EndBlockPayload{} + } + if err := m.EndBlockPayload.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Err", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + 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 ErrInvalidLengthServer + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Err = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipServer(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthServer + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *BeginBlockPayload) 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 ErrIntOverflowServer + } + 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: BeginBlockPayload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BeginBlockPayload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Request", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Request == nil { + m.Request = &types.RequestBeginBlock{} + } + if err := m.Request.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Response", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Response == nil { + m.Response = &types.ResponseBeginBlock{} + } + if err := m.Response.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StateChanges", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StateChanges = append(m.StateChanges, &types1.StoreKVPair{}) + if err := m.StateChanges[len(m.StateChanges)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipServer(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthServer + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DeliverTxPayload) 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 ErrIntOverflowServer + } + 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: DeliverTxPayload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DeliverTxPayload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Request", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Request == nil { + m.Request = &types.RequestDeliverTx{} + } + if err := m.Request.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Response", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Response == nil { + m.Response = &types.ResponseDeliverTx{} + } + if err := m.Response.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StateChanges", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StateChanges = append(m.StateChanges, &types1.StoreKVPair{}) + if err := m.StateChanges[len(m.StateChanges)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipServer(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthServer + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *EndBlockPayload) 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 ErrIntOverflowServer + } + 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: EndBlockPayload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EndBlockPayload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Request", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Request == nil { + m.Request = &types.RequestEndBlock{} + } + if err := m.Request.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Response", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Response == nil { + m.Response = &types.ResponseEndBlock{} + } + if err := m.Response.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StateChanges", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthServer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StateChanges = append(m.StateChanges, &types1.StoreKVPair{}) + if err := m.StateChanges[len(m.StateChanges)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipServer(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthServer + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipServer(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowServer + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowServer + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowServer + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthServer + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupServer + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthServer + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthServer = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowServer = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupServer = fmt.Errorf("proto: unexpected end of group") +) diff --git a/state_file_server/grpc/v1beta/server.pb.go b/store/streaming/file/server/v1beta/server.pb.go similarity index 93% rename from state_file_server/grpc/v1beta/server.pb.go rename to store/streaming/file/server/v1beta/server.pb.go index dda6785a2341..8fc0531ea7cd 100644 --- a/state_file_server/grpc/v1beta/server.pb.go +++ b/store/streaming/file/server/v1beta/server.pb.go @@ -528,53 +528,53 @@ func init() { } var fileDescriptor_9b48d4169ef99d67 = []byte{ - // 731 bytes of a gzipped FileDescriptorProto + // 730 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x4b, 0x6f, 0xd3, 0x4a, - 0x14, 0x8e, 0xeb, 0xdc, 0x36, 0x99, 0xf4, 0x39, 0xf7, 0xaa, 0xca, 0x4d, 0x45, 0x9a, 0x1a, 0x09, - 0xfa, 0xa0, 0x36, 0x0d, 0xbb, 0xf2, 0x12, 0xa1, 0x54, 0x42, 0xdd, 0x54, 0x6e, 0xc5, 0x02, 0x09, - 0x19, 0x3f, 0x06, 0x67, 0x14, 0xc7, 0x0e, 0x33, 0xd3, 0xaa, 0x59, 0xb2, 0x66, 0xc3, 0x6f, 0xe1, + 0x14, 0x8e, 0x9b, 0xdc, 0x36, 0x39, 0xe9, 0x73, 0xee, 0x55, 0x95, 0x9b, 0x8a, 0x34, 0x35, 0x12, + 0xf4, 0x41, 0x6d, 0x1a, 0x76, 0xbc, 0x2a, 0x42, 0xa9, 0x84, 0xba, 0xa9, 0x5c, 0x84, 0x04, 0x12, + 0x0a, 0x7e, 0x0c, 0xce, 0x28, 0x8e, 0x1d, 0x3c, 0xd3, 0xaa, 0x59, 0xb2, 0x66, 0xc3, 0x6f, 0xe1, 0x57, 0x74, 0xd9, 0x25, 0x48, 0x08, 0x50, 0xfb, 0x47, 0x90, 0xc7, 0xe3, 0xb1, 0x93, 0x92, 0x36, - 0x5d, 0x74, 0x95, 0xcc, 0x99, 0xef, 0x9b, 0x6f, 0xbe, 0x73, 0xce, 0xcc, 0x18, 0xdc, 0x77, 0x23, - 0xda, 0x8d, 0xa8, 0xe1, 0xd8, 0x14, 0x19, 0x14, 0x91, 0x63, 0x44, 0x8c, 0xe3, 0x2d, 0x07, 0x31, - 0x7b, 0x4b, 0x0c, 0xf5, 0x1e, 0x89, 0x58, 0x04, 0x6b, 0x09, 0x50, 0x8f, 0x81, 0xba, 0x98, 0x11, - 0xc0, 0xda, 0x7f, 0x7e, 0xe4, 0x47, 0x1c, 0x66, 0xc4, 0xff, 0x12, 0x46, 0x6d, 0x6d, 0x60, 0x69, - 0x16, 0x11, 0x24, 0x57, 0x0e, 0x30, 0x65, 0x28, 0xc4, 0xa1, 0x2f, 0xa0, 0x4b, 0x0c, 0x85, 0x1e, - 0x22, 0x5d, 0x1c, 0x32, 0xc3, 0x76, 0x5c, 0x6c, 0xb0, 0x7e, 0x0f, 0xd1, 0x64, 0x52, 0xfb, 0xac, - 0x80, 0x99, 0x03, 0x46, 0x90, 0xdd, 0x35, 0xd1, 0xc7, 0x23, 0x44, 0x19, 0x5c, 0x06, 0x15, 0x07, - 0xf9, 0x38, 0xb4, 0x9c, 0x20, 0x72, 0x3b, 0x55, 0xa5, 0xa1, 0xac, 0x96, 0x4c, 0xc0, 0x43, 0xad, - 0x38, 0x02, 0xef, 0x00, 0xe0, 0xa1, 0x00, 0x1f, 0x23, 0x62, 0xb1, 0x93, 0xea, 0x04, 0x9f, 0x2f, - 0x8b, 0xc8, 0xe1, 0x09, 0x5c, 0x02, 0x65, 0x14, 0x7a, 0x82, 0xad, 0xf2, 0xd9, 0x12, 0x0a, 0x3d, - 0xc9, 0xe5, 0x9b, 0xb5, 0x3a, 0xa8, 0x4f, 0xab, 0xc5, 0x86, 0xba, 0x5a, 0x36, 0xcb, 0x3c, 0xb2, - 0x87, 0xfa, 0x54, 0xdb, 0x00, 0x0b, 0x2d, 0x29, 0x94, 0x6e, 0x68, 0x11, 0x4c, 0xb6, 0x11, 0xf6, - 0xdb, 0x8c, 0xef, 0x45, 0x35, 0xc5, 0x48, 0x5b, 0x07, 0xf3, 0x3b, 0xa9, 0xea, 0x75, 0xd8, 0x35, - 0x30, 0xf7, 0x4a, 0xec, 0xe1, 0x3a, 0xe8, 0x27, 0x15, 0xcc, 0xa6, 0x19, 0xa1, 0xbd, 0x28, 0xa4, - 0x08, 0xfe, 0x0f, 0x4a, 0x6e, 0xdb, 0xc6, 0xa1, 0x85, 0x3d, 0x0e, 0x2e, 0x9b, 0x53, 0x7c, 0xfc, - 0xda, 0xcb, 0xad, 0x32, 0x91, 0x5f, 0x05, 0xba, 0xe0, 0xdf, 0x5c, 0x16, 0xad, 0x9e, 0xdd, 0x0f, - 0x22, 0xdb, 0xe3, 0xf9, 0xa8, 0x34, 0x37, 0xf5, 0xd1, 0xf5, 0xd6, 0xb3, 0x04, 0xec, 0x27, 0xa4, - 0x56, 0xf1, 0xf4, 0xe7, 0xb2, 0x62, 0x2e, 0x38, 0xc3, 0x13, 0xf0, 0x3d, 0x80, 0x59, 0x25, 0xa4, - 0x46, 0x91, 0x6b, 0x3c, 0xb8, 0x4a, 0x43, 0xe6, 0x6d, 0x50, 0x62, 0xde, 0x1b, 0x8a, 0xc3, 0x77, - 0x60, 0x41, 0x16, 0x53, 0x0a, 0xfc, 0xc3, 0x05, 0x36, 0xae, 0x12, 0x48, 0x93, 0x3d, 0xb8, 0xfe, - 0x1c, 0x1a, 0x0c, 0xc3, 0x45, 0xa0, 0x22, 0x42, 0xaa, 0x93, 0x71, 0x4e, 0x05, 0x26, 0x0e, 0x68, - 0xbf, 0x94, 0x7c, 0x23, 0xa4, 0xe8, 0x27, 0x60, 0x8a, 0x24, 0xc5, 0xe3, 0x55, 0xa8, 0x34, 0x35, - 0x3d, 0x6b, 0x6d, 0x3d, 0x6e, 0x6d, 0x5d, 0x14, 0x37, 0xd7, 0x44, 0x29, 0x05, 0x3e, 0x07, 0x25, - 0x22, 0x0a, 0xca, 0x6b, 0x55, 0x69, 0xde, 0xfd, 0x0b, 0x3d, 0x01, 0xe4, 0xf8, 0x92, 0x04, 0xf7, - 0xc0, 0x0c, 0x65, 0x36, 0x43, 0x96, 0xdb, 0xb6, 0x43, 0x1f, 0xd1, 0xaa, 0xda, 0x50, 0x57, 0x2b, - 0xcd, 0x7b, 0x83, 0x79, 0x88, 0x7b, 0x59, 0xa6, 0xe1, 0x80, 0x77, 0xf6, 0x9b, 0x7d, 0x1b, 0x13, - 0x73, 0x9a, 0x93, 0x5f, 0x26, 0x5c, 0xed, 0x87, 0x92, 0xeb, 0xde, 0xd4, 0xe0, 0xe3, 0x61, 0x83, - 0x2b, 0xa3, 0x0c, 0x66, 0x8d, 0x2f, 0xfd, 0x3d, 0xbb, 0xe4, 0x4f, 0x1b, 0xe9, 0x2f, 0xa3, 0xdf, - 0x92, 0xbd, 0xef, 0x4a, 0x76, 0xe0, 0x52, 0x77, 0xdb, 0xc3, 0xee, 0x1a, 0xa3, 0xdc, 0xc9, 0xa3, - 0x2a, 0xcd, 0x3d, 0xbd, 0x64, 0x6e, 0x65, 0xa4, 0x39, 0xc9, 0xbe, 0x1d, 0x6f, 0xcd, 0xaf, 0x45, - 0x50, 0x3e, 0x88, 0x03, 0xbb, 0x38, 0x40, 0x90, 0x80, 0xf9, 0xac, 0x5b, 0x76, 0x6c, 0x66, 0xbf, - 0x60, 0x70, 0xcc, 0xf3, 0x2d, 0xdc, 0xd6, 0x6e, 0x76, 0x1d, 0x68, 0x05, 0x18, 0x81, 0x39, 0x59, - 0x41, 0x21, 0x39, 0xde, 0x71, 0x4f, 0x15, 0x6f, 0x74, 0x39, 0x68, 0x05, 0x18, 0x80, 0xd9, 0x34, - 0xab, 0x42, 0x6f, 0xac, 0xd3, 0x9f, 0xca, 0xdd, 0xe4, 0xaa, 0xd0, 0x0a, 0xd0, 0x07, 0x20, 0xb9, - 0x80, 0x63, 0x2d, 0xb8, 0x76, 0x15, 0x79, 0xe0, 0xe9, 0xaa, 0xad, 0x8f, 0x03, 0x4d, 0x5a, 0x42, - 0x2b, 0x3c, 0x54, 0x20, 0x06, 0xd3, 0x2d, 0xdb, 0xed, 0xec, 0xe2, 0x20, 0xb8, 0x65, 0xa9, 0xd6, - 0xe1, 0xe9, 0x79, 0x5d, 0x39, 0x3b, 0xaf, 0x2b, 0xbf, 0xcf, 0xeb, 0xca, 0x97, 0x8b, 0x7a, 0xe1, - 0xec, 0xa2, 0x5e, 0xf8, 0x76, 0x51, 0x2f, 0xbc, 0xdd, 0xf6, 0x31, 0x6b, 0x1f, 0x39, 0xba, 0x1b, - 0x75, 0x0d, 0xf1, 0xa8, 0x27, 0x3f, 0x9b, 0xd4, 0xeb, 0x18, 0x49, 0xdb, 0x7e, 0xc0, 0x01, 0xb2, - 0xc4, 0x07, 0x84, 0x4f, 0x7a, 0xae, 0x78, 0xeb, 0x9d, 0x49, 0xfe, 0x88, 0x3f, 0xfa, 0x13, 0x00, - 0x00, 0xff, 0xff, 0xa1, 0x44, 0xd2, 0x9b, 0x69, 0x08, 0x00, 0x00, + 0x5d, 0x74, 0xd5, 0xfa, 0xcc, 0xf7, 0x9d, 0x6f, 0xbe, 0x73, 0xce, 0xcc, 0x04, 0xee, 0xda, 0x01, + 0xed, 0x06, 0x54, 0xb7, 0x4c, 0x8a, 0x75, 0x8a, 0xc3, 0x23, 0x1c, 0xea, 0x47, 0x5b, 0x16, 0x66, + 0xe6, 0x96, 0xf8, 0xd4, 0x7a, 0x61, 0xc0, 0x02, 0x54, 0x8d, 0x81, 0x5a, 0x04, 0xd4, 0xc4, 0x8a, + 0x00, 0x56, 0xff, 0x73, 0x03, 0x37, 0xe0, 0x30, 0x3d, 0xfa, 0x2f, 0x66, 0x54, 0xd7, 0x06, 0x52, + 0xb3, 0x20, 0xc4, 0x32, 0xb3, 0x47, 0x28, 0xc3, 0x3e, 0xf1, 0x5d, 0x01, 0x5d, 0x62, 0xd8, 0x77, + 0x70, 0xd8, 0x25, 0x3e, 0xd3, 0x4d, 0xcb, 0x26, 0x3a, 0xeb, 0xf7, 0x30, 0x8d, 0x17, 0xd5, 0xcf, + 0x0a, 0xcc, 0x1c, 0xb0, 0x10, 0x9b, 0x5d, 0x03, 0x7f, 0x3c, 0xc4, 0x94, 0xa1, 0x65, 0x28, 0x5b, + 0xd8, 0x25, 0x7e, 0xcb, 0xf2, 0x02, 0xbb, 0x53, 0x51, 0xea, 0xca, 0x6a, 0xd1, 0x00, 0x1e, 0x6a, + 0x46, 0x11, 0x74, 0x0b, 0xc0, 0xc1, 0x1e, 0x39, 0xc2, 0x61, 0x8b, 0x1d, 0x57, 0x26, 0xf8, 0x7a, + 0x49, 0x44, 0x5e, 0x1d, 0xa3, 0x25, 0x28, 0x61, 0xdf, 0x11, 0xec, 0x3c, 0x5f, 0x2d, 0x62, 0xdf, + 0x91, 0x5c, 0xbe, 0xd9, 0x56, 0x07, 0xf7, 0x69, 0xa5, 0x50, 0xcf, 0xaf, 0x96, 0x8c, 0x12, 0x8f, + 0xec, 0xe1, 0x3e, 0x55, 0x37, 0x60, 0xa1, 0x29, 0x85, 0x92, 0x0d, 0x2d, 0xc2, 0x64, 0x1b, 0x13, + 0xb7, 0xcd, 0xf8, 0x5e, 0xf2, 0x86, 0xf8, 0x52, 0xd7, 0x61, 0x7e, 0x27, 0x51, 0xbd, 0x0a, 0xbb, + 0x06, 0x73, 0x2f, 0xc4, 0x1e, 0xae, 0x82, 0x7e, 0xca, 0xc3, 0x6c, 0x52, 0x11, 0xda, 0x0b, 0x7c, + 0x8a, 0xd1, 0xff, 0x50, 0xb4, 0xdb, 0x26, 0xf1, 0x5b, 0xc4, 0xe1, 0xe0, 0x92, 0x31, 0xc5, 0xbf, + 0x5f, 0x3a, 0x99, 0x2c, 0x13, 0xd9, 0x2c, 0xc8, 0x86, 0x7f, 0x33, 0x55, 0x6c, 0xf5, 0xcc, 0xbe, + 0x17, 0x98, 0x0e, 0xaf, 0x47, 0xb9, 0xb1, 0xa9, 0x8d, 0xee, 0xb7, 0x96, 0x16, 0x60, 0x3f, 0x26, + 0x35, 0x0b, 0x27, 0x3f, 0x97, 0x15, 0x63, 0xc1, 0x1a, 0x5e, 0x40, 0xef, 0x01, 0xa5, 0x9d, 0x90, + 0x1a, 0x05, 0xae, 0x71, 0xef, 0x32, 0x0d, 0x59, 0xb7, 0x41, 0x89, 0x79, 0x67, 0x28, 0x8e, 0xde, + 0xc1, 0x82, 0x6c, 0xa6, 0x14, 0xf8, 0x87, 0x0b, 0x6c, 0x5c, 0x26, 0x90, 0x14, 0x7b, 0x30, 0xff, + 0x1c, 0x1e, 0x0c, 0xa3, 0x45, 0xc8, 0xe3, 0x30, 0xac, 0x4c, 0x46, 0x35, 0x15, 0x98, 0x28, 0xa0, + 0xfe, 0x52, 0xb2, 0x83, 0x90, 0xa0, 0x1f, 0xc3, 0x54, 0x18, 0x37, 0x8f, 0x77, 0xa1, 0xdc, 0x50, + 0xb5, 0x74, 0xb4, 0xb5, 0x68, 0xb4, 0x35, 0xd1, 0xdc, 0xcc, 0x10, 0x25, 0x14, 0xb4, 0x0d, 0xc5, + 0x50, 0x34, 0x94, 0xf7, 0xaa, 0xdc, 0xb8, 0xfd, 0x17, 0x7a, 0x0c, 0xc8, 0xf0, 0x25, 0x09, 0xed, + 0xc1, 0x0c, 0x65, 0x26, 0xc3, 0x2d, 0xbb, 0x6d, 0xfa, 0x2e, 0xa6, 0x95, 0x7c, 0x3d, 0xbf, 0x5a, + 0x6e, 0xdc, 0x19, 0xac, 0x43, 0x34, 0xcb, 0xb2, 0x0c, 0x07, 0x7c, 0xb2, 0x5f, 0xef, 0x9b, 0x24, + 0x34, 0xa6, 0x39, 0xf9, 0x79, 0xcc, 0x55, 0x7f, 0x28, 0x99, 0xe9, 0x4d, 0x0c, 0x3e, 0x1a, 0x36, + 0xb8, 0x32, 0xca, 0x60, 0x3a, 0xf8, 0xd2, 0xdf, 0xd3, 0x0b, 0xfe, 0xd4, 0x91, 0xfe, 0x52, 0xfa, + 0x0d, 0xd9, 0xfb, 0xae, 0xa4, 0x07, 0x2e, 0x71, 0xf7, 0x70, 0xd8, 0x5d, 0x7d, 0x94, 0x3b, 0x79, + 0x54, 0xa5, 0xb9, 0x27, 0x17, 0xcc, 0xad, 0x8c, 0x34, 0x27, 0xd9, 0x37, 0xe3, 0xad, 0xf1, 0xb5, + 0x00, 0xa5, 0x83, 0x28, 0xb0, 0x4b, 0x3c, 0x8c, 0x42, 0x98, 0x4f, 0xa7, 0x65, 0xc7, 0x64, 0xe6, + 0x33, 0x86, 0xc6, 0x3c, 0xdf, 0xc2, 0x6d, 0xf5, 0x7a, 0xd7, 0x81, 0x9a, 0x43, 0x01, 0xcc, 0xc9, + 0x0e, 0x0a, 0xc9, 0xf1, 0x8e, 0x7b, 0xa2, 0x78, 0xad, 0xcb, 0x41, 0xcd, 0x21, 0x0f, 0x66, 0x93, + 0xaa, 0x0a, 0xbd, 0xb1, 0x4e, 0x7f, 0x22, 0x77, 0x9d, 0xab, 0x42, 0xcd, 0x21, 0x17, 0x20, 0xbe, + 0x80, 0x23, 0x2d, 0xb4, 0x76, 0x19, 0x79, 0xe0, 0xe9, 0xaa, 0xae, 0x8f, 0x03, 0x8d, 0x47, 0x42, + 0xcd, 0xdd, 0x57, 0x10, 0x81, 0xe9, 0xa6, 0x69, 0x77, 0x76, 0x89, 0xe7, 0xdd, 0xb0, 0x54, 0xf3, + 0xcd, 0xc9, 0x59, 0x4d, 0x39, 0x3d, 0xab, 0x29, 0xbf, 0xcf, 0x6a, 0xca, 0x97, 0xf3, 0x5a, 0xee, + 0xf4, 0xbc, 0x96, 0xfb, 0x76, 0x5e, 0xcb, 0xbd, 0xdd, 0x76, 0x09, 0x6b, 0x1f, 0x5a, 0x9a, 0x1d, + 0x74, 0x75, 0xf1, 0xa8, 0xc7, 0x7f, 0x36, 0xa9, 0xd3, 0x11, 0x4f, 0x3b, 0xe5, 0x09, 0x89, 0xef, + 0xea, 0x1f, 0x88, 0x37, 0xf4, 0x53, 0xc2, 0x9a, 0xe4, 0x2f, 0xf9, 0x83, 0x3f, 0x01, 0x00, 0x00, + 0xff, 0xff, 0xdb, 0x03, 0x16, 0xaf, 0x6e, 0x08, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. From eb8570ac6e4d70a3d6a67d057358ad6ab9da0971 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 6 Jul 2021 15:27:25 -0500 Subject: [PATCH 37/46] finish server, server types, handler, config --- docs/core/proto-docs.md | 1 + proto/cosmos/base/server/v1beta1/server.proto | 1 + store/streaming/file/server/api/api.go | 1 - store/streaming/file/server/config/config.go | 30 +- store/streaming/file/server/grpc/backend.go | 175 +- .../streaming/file/server/grpc/grpc_server.go | 35 - store/streaming/file/server/grpc/grpc_web.go | 6 +- store/streaming/file/server/grpc/handler.go | 82 + store/streaming/file/server/grpc/server.go | 114 +- .../file/server/grpc/v1beta/server.pb.go | 2585 ----------------- .../streaming/file/server/v1beta/server.pb.go | 130 +- 11 files changed, 343 insertions(+), 2817 deletions(-) delete mode 100644 store/streaming/file/server/api/api.go delete mode 100644 store/streaming/file/server/grpc/grpc_server.go create mode 100644 store/streaming/file/server/grpc/handler.go delete mode 100644 store/streaming/file/server/grpc/v1beta/server.pb.go diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 755ba3fc2724..ff93dc544e38 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -2706,6 +2706,7 @@ BeginBlockRequest is the message definition for requesting BeginBlock data at a | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `height` | [int64](#int64) | | | +| `index` | [int64](#int64) | | | diff --git a/proto/cosmos/base/server/v1beta1/server.proto b/proto/cosmos/base/server/v1beta1/server.proto index 007c1cf41fc8..04ba83ea9ae8 100644 --- a/proto/cosmos/base/server/v1beta1/server.proto +++ b/proto/cosmos/base/server/v1beta1/server.proto @@ -36,6 +36,7 @@ message BeginBlockRequest { // DeliverTxRequest is the message definition for requesting DeliverTx data at a specific height message DeliverTxRequest { int64 height = 1; + int64 index = 2; } // EndBlockRequest is the message definition for requesting EndBlock data at a specific height diff --git a/store/streaming/file/server/api/api.go b/store/streaming/file/server/api/api.go deleted file mode 100644 index 778f64ec17cd..000000000000 --- a/store/streaming/file/server/api/api.go +++ /dev/null @@ -1 +0,0 @@ -package api diff --git a/store/streaming/file/server/config/config.go b/store/streaming/file/server/config/config.go index 432970f265b4..7ebb4f998d01 100644 --- a/store/streaming/file/server/config/config.go +++ b/store/streaming/file/server/config/config.go @@ -7,7 +7,7 @@ import ( // Default constants const ( // DefaultReadDir defines the default directory to read the streamed files from - DefaultReadDir = file.DefaultWriteDir + DefaultReadDir = file.DefaultWriteDir // DefaultGRPCAddress defines the default address to bind the gRPC server to. DefaultGRPCAddress = "0.0.0.0:9092" @@ -17,23 +17,25 @@ const ( ) type StateServerConfig struct { - GRPCAddress string - GRPCWebAddress string + GRPCAddress string `mapstructure:"grpc-address"` + GRPCWebAddress string `mapstructure:"grpc-web-address"` + ChainID string `mapstructure:"chain-id"` + ReadDir string `mapstructure:"read-dir"` + FilePrefix string `mapstructure:"file-prefix"` + RemoveAfter bool `mapstructure:"remove-after"` // true: once data has been streamed forward it will be removed from the filesystem } // DefaultStateServerConfig returns the reference to ClientConfig with default values. func DefaultStateServerConfig() *StateServerConfig { - return &StateServerConfig{DefaultGRPCAddress, DefaultGRPCWebAddress} + return &StateServerConfig{ + DefaultGRPCAddress, + DefaultGRPCWebAddress, + "", + DefaultReadDir, + "", + true} } -type StateServerBackendConfig struct { - ChainID string - ReadDir string - FilePrefix string - Persist bool // false: once data has been streamed forward it will be removed from the filesystem -} - -// DefaultStateServerBackendConfig returns the reference to ClientConfig with default values. -func DefaultStateServerBackendConfig() *StateServerBackendConfig { - return &StateServerBackendConfig{"", DefaultReadDir, "", true} +func WriteConfigFile(cfgFilePath string, cfg *StateServerConfig) { + panic("implement me") } diff --git a/store/streaming/file/server/grpc/backend.go b/store/streaming/file/server/grpc/backend.go index 660b1ccbc8ec..6fb71229e5b7 100644 --- a/store/streaming/file/server/grpc/backend.go +++ b/store/streaming/file/server/grpc/backend.go @@ -1,6 +1,7 @@ package grpc import ( + "context" "fmt" "io/ioutil" "os" @@ -12,36 +13,38 @@ import ( "github.com/fkocik/fsnotify" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/state_file_server/config" - pb "github.com/cosmos/cosmos-sdk/state_file_server/grpc/v1beta" "github.com/cosmos/cosmos-sdk/store/streaming/file" + "github.com/cosmos/cosmos-sdk/store/streaming/file/server/config" + pb "github.com/cosmos/cosmos-sdk/store/streaming/file/server/v1beta" "github.com/cosmos/cosmos-sdk/store/types" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" ) type StateFileBackend struct { - conf config.StateServerBackendConfig + conf config.StateServerConfig - codec *codec.ProtoCodec - logger log.Logger + codec *codec.ProtoCodec + logger log.Logger trimPrefix string } -func NewStateFileBackend(conf config.StateServerBackendConfig, codec *codec.ProtoCodec, logger log.Logger) *StateFileBackend { +func NewStateFileBackend(conf config.StateServerConfig, codec *codec.ProtoCodec, logger log.Logger) *StateFileBackend { trimPrefix := "block-" if conf.FilePrefix != "" { trimPrefix = fmt.Sprintf("%s-%s", conf.FilePrefix, trimPrefix) } return &StateFileBackend{ - conf: conf, - codec: codec, + conf: conf, + codec: codec, trimPrefix: trimPrefix, - logger: logger, + logger: logger, } } -func (sfb *StateFileBackend) Stream(req *pb.StreamRequest, res chan <-*pb.StreamResponse, doneChan chan <-struct{}) error { +// StreamData streams the requested state file data +// this streams new data as it is written to disk +func (sfb *StateFileBackend) StreamData(req *pb.StreamRequest, res chan<- *pb.StreamResponse, doneChan chan<- struct{}) error { w, err := fsnotify.NewWatcher() if err != nil { close(doneChan) @@ -71,7 +74,7 @@ func (sfb *StateFileBackend) Stream(req *pb.StreamRequest, res chan <-*pb.Stream res <- sfb.formBeginBlockResponse(fileName) default: } - if !sfb.conf.Persist && readFlag { + if sfb.conf.RemoveAfter && readFlag { if err := os.Remove(filepath.Join(sfb.conf.ReadDir, fileName)); err != nil { sfb.logger.Error("unable to remove state change file", "err", err) } @@ -88,7 +91,9 @@ func (sfb *StateFileBackend) Stream(req *pb.StreamRequest, res chan <-*pb.Stream return nil } -func (sfb *StateFileBackend) BackFill(req *pb.StreamRequest, res chan <-*pb.StreamResponse, doneChan chan <-struct{}) error { +// BackFillData stream the requested state file data +// this stream data that is already written to disk +func (sfb *StateFileBackend) BackFillData(req *pb.StreamRequest, res chan<- *pb.StreamResponse, doneChan chan<- struct{}) error { f, err := os.Open(sfb.conf.ReadDir) if err != nil { return err @@ -118,7 +123,7 @@ func (sfb *StateFileBackend) BackFill(req *pb.StreamRequest, res chan <-*pb.Stre res <- sfb.formBeginBlockResponse(fileName) default: } - if !sfb.conf.Persist && readFlag { + if sfb.conf.RemoveAfter && readFlag { if err := os.Remove(filepath.Join(sfb.conf.ReadDir, fileName)); err != nil { sfb.logger.Error("unable to remove state change file", "err", err) } @@ -128,6 +133,33 @@ func (sfb *StateFileBackend) BackFill(req *pb.StreamRequest, res chan <-*pb.Stre return nil } +// BeginBlockDataAt returns a BeginBlockPayload for the provided BeginBlockRequest +func (sfb *StateFileBackend) BeginBlockDataAt(ctx context.Context, req *pb.BeginBlockRequest) (*pb.BeginBlockPayload, error) { + fileName := fmt.Sprintf("block-%d-begin", req.Height) + if sfb.conf.FilePrefix != "" { + fileName = fmt.Sprintf("%s-%s", sfb.conf.FilePrefix, fileName) + } + return sfb.formBeginBlockPayload(fileName) +} + +// DeliverTxDataAt returns a DeliverTxPayload for the provided BeginBlockRequest +func (sfb *StateFileBackend) DeliverTxDataAt(ctx context.Context, req *pb.DeliverTxRequest) (*pb.DeliverTxPayload, error) { + fileName := fmt.Sprintf("block-%d-tx-%d", req.Height, req.Index) + if sfb.conf.FilePrefix != "" { + fileName = fmt.Sprintf("%s-%s", sfb.conf.FilePrefix, fileName) + } + return sfb.formDeliverTxPayload(fileName) +} + +// EndBlockDataAt returns a EndBlockPayload for the provided EndBlockRequest +func (sfb *StateFileBackend) EndBlockDataAt(ctx context.Context, req *pb.EndBlockRequest) (*pb.EndBlockPayload, error) { + fileName := fmt.Sprintf("block-%d-end", req.Height) + if sfb.conf.FilePrefix != "" { + fileName = fmt.Sprintf("%s-%s", sfb.conf.FilePrefix, fileName) + } + return sfb.formEndBlockPayload(fileName) +} + type filesByTimeModified []os.FileInfo func (fs filesByTimeModified) Len() int { @@ -152,45 +184,48 @@ func (sfb *StateFileBackend) formBeginBlockResponse(fileName string) *pb.StreamR return res } res.Height = blockHeight - fileBytes, err := ioutil.ReadFile(filepath.Join(sfb.conf.ReadDir, fileName)) + bbp, err := sfb.formBeginBlockPayload(fileName) if err != nil { res.Err = err.Error() return res } + res.BeginBlockPayload = bbp + return res +} + +func (sfb *StateFileBackend) formBeginBlockPayload(fileName string) (*pb.BeginBlockPayload, error) { + fileBytes, err := readFile(sfb.conf.ReadDir, fileName) + if err != nil { + return nil, err + } messageBytes, err := file.SegmentBytes(fileBytes) if err != nil { - res.Err = err.Error() - return res + return nil, err } if len(messageBytes) < 2 { - res.Err = fmt.Sprintf("expected at least two protobuf messages, got %d", len(messageBytes)) - return res + return nil, fmt.Errorf("expected at least two protobuf messages, got %d", len(messageBytes)) } beginBlockReq := new(abci.RequestBeginBlock) if err := sfb.codec.Unmarshal(messageBytes[0], beginBlockReq); err != nil { - res.Err = err.Error() - return res + return nil, err } beginBlockRes := new(abci.ResponseBeginBlock) if err := sfb.codec.Unmarshal(messageBytes[len(messageBytes)-1], beginBlockRes); err != nil { - res.Err = err.Error() - return res + return nil, err } kvPairs := make([]*types.StoreKVPair, len(messageBytes[1:len(messageBytes)-2])) - for i := 1; i < len(messageBytes) - 1; i++ { + for i := 1; i < len(messageBytes)-1; i++ { kvPair := new(types.StoreKVPair) if err := sfb.codec.Unmarshal(messageBytes[i], kvPair); err != nil { - res.Err = err.Error() - return res + return nil, err } kvPairs[i-1] = kvPair } - res.BeginBlockPayload = &pb.BeginBlockPayload{ - Request: beginBlockReq, - Response: beginBlockRes, + return &pb.BeginBlockPayload{ + Request: beginBlockReq, + Response: beginBlockRes, StateChanges: kvPairs, - } - return res + }, nil } func (sfb *StateFileBackend) formDeliverTxResponse(fileName string) *pb.StreamResponse { @@ -203,45 +238,48 @@ func (sfb *StateFileBackend) formDeliverTxResponse(fileName string) *pb.StreamRe return res } res.Height = blockHeight - fileBytes, err := ioutil.ReadFile(filepath.Join(sfb.conf.ReadDir, fileName)) + dtp, err := sfb.formDeliverTxPayload(fileName) if err != nil { res.Err = err.Error() return res } + res.DeliverTxPayload = dtp + return res +} + +func (sfb *StateFileBackend) formDeliverTxPayload(fileName string) (*pb.DeliverTxPayload, error) { + fileBytes, err := readFile(sfb.conf.ReadDir, fileName) + if err != nil { + return nil, err + } messageBytes, err := file.SegmentBytes(fileBytes) if err != nil { - res.Err = err.Error() - return res + return nil, err } if len(messageBytes) < 2 { - res.Err = fmt.Sprintf("expected at least two protobuf messages, got %d", len(messageBytes)) - return res + return nil, fmt.Errorf("expected at least two protobuf messages, got %d", len(messageBytes)) } deliverTxReq := new(abci.RequestDeliverTx) if err := sfb.codec.Unmarshal(messageBytes[0], deliverTxReq); err != nil { - res.Err = err.Error() - return res + return nil, err } deliverTxRes := new(abci.ResponseDeliverTx) if err := sfb.codec.Unmarshal(messageBytes[len(messageBytes)-1], deliverTxRes); err != nil { - res.Err = err.Error() - return res + return nil, err } kvPairs := make([]*types.StoreKVPair, len(messageBytes[1:len(messageBytes)-2])) - for i := 1; i < len(messageBytes) - 1; i++ { + for i := 1; i < len(messageBytes)-1; i++ { kvPair := new(types.StoreKVPair) if err := sfb.codec.Unmarshal(messageBytes[i], kvPair); err != nil { - res.Err = err.Error() - return res + return nil, err } kvPairs[i-1] = kvPair } - res.DeliverTxPayload = &pb.DeliverTxPayload{ - Request: deliverTxReq, - Response: deliverTxRes, + return &pb.DeliverTxPayload{ + Request: deliverTxReq, + Response: deliverTxRes, StateChanges: kvPairs, - } - return res + }, nil } func (sfb *StateFileBackend) formEndBlockResponse(fileName string) *pb.StreamResponse { @@ -254,43 +292,50 @@ func (sfb *StateFileBackend) formEndBlockResponse(fileName string) *pb.StreamRes return res } res.Height = blockHeight - fileBytes, err := ioutil.ReadFile(filepath.Join(sfb.conf.ReadDir, fileName)) + ebp, err := sfb.formEndBlockPayload(fileName) if err != nil { res.Err = err.Error() return res } + res.EndBlockPayload = ebp + return res +} + +func (sfb *StateFileBackend) formEndBlockPayload(fileName string) (*pb.EndBlockPayload, error) { + fileBytes, err := readFile(sfb.conf.ReadDir, fileName) + if err != nil { + return nil, err + } messageBytes, err := file.SegmentBytes(fileBytes) if err != nil { - res.Err = err.Error() - return res + return nil, err } if len(messageBytes) < 2 { - res.Err = fmt.Sprintf("expected at least two protobuf messages, got %d", len(messageBytes)) - return res + return nil, fmt.Errorf("expected at least two protobuf messages, got %d", len(messageBytes)) } endBlockReq := new(abci.RequestEndBlock) if err := sfb.codec.Unmarshal(messageBytes[0], endBlockReq); err != nil { - res.Err = err.Error() - return res + return nil, err } endBlockRes := new(abci.ResponseEndBlock) if err := sfb.codec.Unmarshal(messageBytes[len(messageBytes)-1], endBlockRes); err != nil { - res.Err = err.Error() - return res + return nil, err } kvPairs := make([]*types.StoreKVPair, len(messageBytes[1:len(messageBytes)-2])) - for i := 1; i < len(messageBytes) - 1; i++ { + for i := 1; i < len(messageBytes)-1; i++ { kvPair := new(types.StoreKVPair) if err := sfb.codec.Unmarshal(messageBytes[i], kvPair); err != nil { - res.Err = err.Error() - return res + return nil, err } kvPairs[i-1] = kvPair } - res.EndBlockPayload = &pb.EndBlockPayload{ - Request: endBlockReq, - Response: endBlockRes, + return &pb.EndBlockPayload{ + Request: endBlockReq, + Response: endBlockRes, StateChanges: kvPairs, - } - return res -} \ No newline at end of file + }, nil +} + +func readFile(dir, fileName string) ([]byte, error) { + return ioutil.ReadFile(filepath.Join(dir, fileName)) +} diff --git a/store/streaming/file/server/grpc/grpc_server.go b/store/streaming/file/server/grpc/grpc_server.go deleted file mode 100644 index 5637cf4f244c..000000000000 --- a/store/streaming/file/server/grpc/grpc_server.go +++ /dev/null @@ -1,35 +0,0 @@ -package grpc - -import ( - "fmt" - "net" - "time" - - "google.golang.org/grpc" - - "github.com/cosmos/cosmos-sdk/state_file_server/config" -) - -// StartGRPCServer starts a gRPC server on the given address. -func StartGRPCServer(config config.StateServerConfig) (*grpc.Server, error) { - grpcSrv := grpc.NewServer() - listener, err := net.Listen("tcp", config.GRPCAddress) - if err != nil { - return nil, err - } - - errCh := make(chan error) - go func() { - err = grpcSrv.Serve(listener) - if err != nil { - errCh <- fmt.Errorf("failed to serve: %w", err) - } - }() - - select { - case err := <-errCh: - return nil, err - case <-time.After(5 * time.Second): // assume server started successfully - return grpcSrv, nil - } -} diff --git a/store/streaming/file/server/grpc/grpc_web.go b/store/streaming/file/server/grpc/grpc_web.go index 56bfabac0223..84fde55b610f 100644 --- a/store/streaming/file/server/grpc/grpc_web.go +++ b/store/streaming/file/server/grpc/grpc_web.go @@ -5,18 +5,16 @@ import ( "github.com/improbable-eng/grpc-web/go/grpcweb" "google.golang.org/grpc" - - "github.com/cosmos/cosmos-sdk/state_file_server/config" ) // StartGRPCWeb starts a gRPC-Web server on the given address. -func StartGRPCWeb(grpcSrv *grpc.Server, config config.StateServerConfig) (*http.Server, error) { +func StartGRPCWeb(grpcSrv *grpc.Server, address string) (*http.Server, error) { wrappedServer := grpcweb.WrapServer(grpcSrv) handler := func(resp http.ResponseWriter, req *http.Request) { wrappedServer.ServeHTTP(resp, req) } grpcWebSrv := &http.Server{ - Addr: config.GRPCWebAddress, + Addr: address, Handler: http.HandlerFunc(handler), } if err := grpcWebSrv.ListenAndServe(); err != nil { diff --git a/store/streaming/file/server/grpc/handler.go b/store/streaming/file/server/grpc/handler.go new file mode 100644 index 000000000000..f44e47faa321 --- /dev/null +++ b/store/streaming/file/server/grpc/handler.go @@ -0,0 +1,82 @@ +package grpc + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/store/streaming/file/server/config" + pb "github.com/cosmos/cosmos-sdk/store/streaming/file/server/v1beta" + "github.com/tendermint/tendermint/libs/log" +) + +type Handler = pb.StateFileServer + +// handler is the interface which exposes the StateFile Server methods +type handler struct { + pb.UnimplementedStateFileServer + backend *StateFileBackend + logger log.Logger +} + +// New returns the object for the RPC handler +func New(conf config.StateServerConfig, codec *codec.ProtoCodec, logger log.Logger) (Handler, error) { + return &handler{ + backend: NewStateFileBackend(conf, codec, logger), + logger: logger, + }, nil +} + +// StreamData streams the requested state file data +// this streams new data as it is written to disk +func (h *handler) StreamData(req *pb.StreamRequest, srv pb.StateFile_StreamDataServer) error { + resChan := make(chan *pb.StreamResponse) + stopped := make(chan struct{}) + if err := h.backend.StreamData(req, resChan, stopped); err != nil { + return err + } + for { + select { + case res := <-resChan: + if err := srv.Send(res); err != nil { + h.logger.Error("StreamData send error", "err", err) + } + case <-stopped: + return nil + } + } +} + +// BackFillData stream the requested state file data +// this stream data that is already written to disk +func (h *handler) BackFillData(req *pb.StreamRequest, srv pb.StateFile_BackFillDataServer) error { + resChan := make(chan *pb.StreamResponse) + stopped := make(chan struct{}) + if err := h.backend.BackFillData(req, resChan, stopped); err != nil { + return err + } + for { + select { + case res := <-resChan: + if err := srv.Send(res); err != nil { + h.logger.Error("BackFillData send error", "err", err) + } + case <-stopped: + return nil + } + } +} + +// BeginBlockDataAt returns a BeginBlockPayload for the provided BeginBlockRequest +func (h *handler) BeginBlockDataAt(ctx context.Context, req *pb.BeginBlockRequest) (*pb.BeginBlockPayload, error) { + return h.backend.BeginBlockDataAt(ctx, req) +} + +// DeliverTxDataAt returns a DeliverTxPayload for the provided BeginBlockRequest +func (h *handler) DeliverTxDataAt(ctx context.Context, req *pb.DeliverTxRequest) (*pb.DeliverTxPayload, error) { + return h.backend.DeliverTxDataAt(ctx, req) +} + +// EndBlockDataAt returns a EndBlockPayload for the provided EndBlockRequest +func (h *handler) EndBlockDataAt(ctx context.Context, req *pb.EndBlockRequest) (*pb.EndBlockPayload, error) { + return h.backend.EndBlockDataAt(ctx, req) +} diff --git a/store/streaming/file/server/grpc/server.go b/store/streaming/file/server/grpc/server.go index 006d78fad081..d19cb919695a 100644 --- a/store/streaming/file/server/grpc/server.go +++ b/store/streaming/file/server/grpc/server.go @@ -1,78 +1,60 @@ package grpc import ( - "context" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/state_file_server/config" - pb "github.com/cosmos/cosmos-sdk/state_file_server/grpc/v1beta" - "github.com/tendermint/tendermint/libs/log" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -type Handler = pb.StateFileServer + "fmt" + "net" + "time" -// handler is the interface which exposes the StateFile Server methods -type handler struct { - pb.UnimplementedStateFileServer - backend *StateFileBackend - logger log.Logger -} + "google.golang.org/grpc" -// New returns the object for the RPC handler -func New(conf config.StateServerBackendConfig, codec *codec.ProtoCodec, logger log.Logger) (Handler, error) { - return &handler{ - backend: NewStateFileBackend(conf, codec, logger), - logger: logger, - }, nil -} + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/server/grpc/gogoreflection" + reflection "github.com/cosmos/cosmos-sdk/server/grpc/reflection/v2alpha1" + pb "github.com/cosmos/cosmos-sdk/store/streaming/file/server/v1beta" + sdk "github.com/cosmos/cosmos-sdk/types" +) -// StreamData streams the requested state file data -// this streams new data as it is written to disk -func (h *handler) StreamData(req *pb.StreamRequest, srv pb.StateFile_StreamDataServer) error { - resChan := make(chan *pb.StreamResponse) - stopped := make(chan struct{}) - if err := h.backend.Stream(req, resChan, stopped); err != nil { - return err - } - for { - select { - case res := <-resChan: - if err := srv.Send(res); err != nil { - h.logger.Error("StreamData send error", "err", err) +// StartGRPCServer starts a gRPC server on the given address. +func StartGRPCServer(clientCtx client.Context, handler pb.StateFileServer, address string) (*grpc.Server, error) { + grpcSrv := grpc.NewServer() + pb.RegisterStateFileServer(grpcSrv, handler) + // reflection allows consumers to build dynamic clients that can write + // to any cosmos-sdk application without relying on application packages at compile time + err := reflection.Register(grpcSrv, reflection.Config{ + SigningModes: func() map[string]int32 { + modes := make(map[string]int32, len(clientCtx.TxConfig.SignModeHandler().Modes())) + for _, m := range clientCtx.TxConfig.SignModeHandler().Modes() { + modes[m.String()] = (int32)(m) } - case <-stopped: - return nil - } + return modes + }(), + ChainID: clientCtx.ChainID, + SdkConfig: sdk.GetConfig(), + InterfaceRegistry: clientCtx.InterfaceRegistry, + }) + if err != nil { + return nil, err } -} - -// BackFillData stream the requested state file data -// this stream data that is already written to disk -func (h *handler) BackFillData(req *pb.StreamRequest, srv pb.StateFile_BackFillDataServer) error { - resChan := make(chan *pb.StreamResponse) - stopped := make(chan struct{}) - if err := h.backend.BackFill(req, resChan, stopped); err != nil { - return err + // Reflection allows external clients to see what services and methods + // the gRPC server exposes. + gogoreflection.Register(grpcSrv) + listener, err := net.Listen("tcp", address) + if err != nil { + return nil, err } - for { - select { - case res := <-resChan: - if err := srv.Send(res); err != nil { - h.logger.Error("BackFillData send error", "err", err) - } - case <-stopped: - return nil + + errCh := make(chan error) + go func() { + err = grpcSrv.Serve(listener) + if err != nil { + errCh <- fmt.Errorf("failed to serve: %w", err) } - } -} + }() -func (h *handler) BeginBlockDataAt(ctx context.Context, req *pb.BeginBlockRequest) (*pb.BeginBlockPayload, error) { - return nil, status.Errorf(codes.Unimplemented, "method BeginBlockDataAt not implemented") -} -func (h *handler) DeliverTxDataAt(ctx context.Context, req *pb.DeliverTxRequest) (*pb.DeliverTxPayload, error) { - return nil, status.Errorf(codes.Unimplemented, "method DeliverTxDataAt not implemented") + select { + case err := <-errCh: + return nil, err + case <-time.After(5 * time.Second): // assume server started successfully + return grpcSrv, nil + } } -func (h *handler) EndBlockDataAt(ctx context.Context, req *pb.EndBlockRequest) (*pb.EndBlockPayload, error) { - return nil, status.Errorf(codes.Unimplemented, "method EndBlockDataAt not implemented") -} \ No newline at end of file diff --git a/store/streaming/file/server/grpc/v1beta/server.pb.go b/store/streaming/file/server/grpc/v1beta/server.pb.go deleted file mode 100644 index 4c30e79110fb..000000000000 --- a/store/streaming/file/server/grpc/v1beta/server.pb.go +++ /dev/null @@ -1,2585 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: cosmos/base/server/v1beta1/server.proto - -package v1beta - -import ( - context "context" - fmt "fmt" - types1 "github.com/cosmos/cosmos-sdk/store/types" - _ "github.com/gogo/protobuf/gogoproto" - grpc1 "github.com/gogo/protobuf/grpc" - proto "github.com/gogo/protobuf/proto" - types "github.com/tendermint/tendermint/abci/types" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// StreamRequest is the message definition for a streaming request sent from a client to the server -type StreamRequest struct { - // begin_block specifies whether or not stream BeginBlock files - BeginBlock bool `protobuf:"varint,1,opt,name=begin_block,json=beginBlock,proto3" json:"begin_block,omitempty"` - // deliver_tx specifies whether or not to stream DeliverTx files - DeliverTx bool `protobuf:"varint,2,opt,name=deliver_tx,json=deliverTx,proto3" json:"deliver_tx,omitempty"` - // end_block specifies whether or not to stream EndBlock files - EndBlock bool `protobuf:"varint,3,opt,name=end_block,json=endBlock,proto3" json:"end_block,omitempty"` - // store_keys is a (optional) list of store keys for which to restrict the streamed KVPairs to - StoreKeys []string `protobuf:"bytes,4,rep,name=store_keys,json=storeKeys,proto3" json:"store_keys,omitempty"` -} - -func (m *StreamRequest) Reset() { *m = StreamRequest{} } -func (m *StreamRequest) String() string { return proto.CompactTextString(m) } -func (*StreamRequest) ProtoMessage() {} -func (*StreamRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_9b48d4169ef99d67, []int{0} -} -func (m *StreamRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *StreamRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_StreamRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *StreamRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_StreamRequest.Merge(m, src) -} -func (m *StreamRequest) XXX_Size() int { - return m.Size() -} -func (m *StreamRequest) XXX_DiscardUnknown() { - xxx_messageInfo_StreamRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_StreamRequest proto.InternalMessageInfo - -func (m *StreamRequest) GetBeginBlock() bool { - if m != nil { - return m.BeginBlock - } - return false -} - -func (m *StreamRequest) GetDeliverTx() bool { - if m != nil { - return m.DeliverTx - } - return false -} - -func (m *StreamRequest) GetEndBlock() bool { - if m != nil { - return m.EndBlock - } - return false -} - -func (m *StreamRequest) GetStoreKeys() []string { - if m != nil { - return m.StoreKeys - } - return nil -} - -// BeginBlockRequest is the message definition for requesting BeginBlock data at a specific height -type BeginBlockRequest struct { - Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` -} - -func (m *BeginBlockRequest) Reset() { *m = BeginBlockRequest{} } -func (m *BeginBlockRequest) String() string { return proto.CompactTextString(m) } -func (*BeginBlockRequest) ProtoMessage() {} -func (*BeginBlockRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_9b48d4169ef99d67, []int{1} -} -func (m *BeginBlockRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *BeginBlockRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_BeginBlockRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *BeginBlockRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_BeginBlockRequest.Merge(m, src) -} -func (m *BeginBlockRequest) XXX_Size() int { - return m.Size() -} -func (m *BeginBlockRequest) XXX_DiscardUnknown() { - xxx_messageInfo_BeginBlockRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_BeginBlockRequest proto.InternalMessageInfo - -func (m *BeginBlockRequest) GetHeight() int64 { - if m != nil { - return m.Height - } - return 0 -} - -// DeliverTxRequest is the message definition for requesting DeliverTx data at a specific height -type DeliverTxRequest struct { - Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` -} - -func (m *DeliverTxRequest) Reset() { *m = DeliverTxRequest{} } -func (m *DeliverTxRequest) String() string { return proto.CompactTextString(m) } -func (*DeliverTxRequest) ProtoMessage() {} -func (*DeliverTxRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_9b48d4169ef99d67, []int{2} -} -func (m *DeliverTxRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *DeliverTxRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_DeliverTxRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *DeliverTxRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_DeliverTxRequest.Merge(m, src) -} -func (m *DeliverTxRequest) XXX_Size() int { - return m.Size() -} -func (m *DeliverTxRequest) XXX_DiscardUnknown() { - xxx_messageInfo_DeliverTxRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_DeliverTxRequest proto.InternalMessageInfo - -func (m *DeliverTxRequest) GetHeight() int64 { - if m != nil { - return m.Height - } - return 0 -} - -// EndBlockRequest is the message definition for requesting EndBlock data at a specific height -type EndBlockRequest struct { - Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` -} - -func (m *EndBlockRequest) Reset() { *m = EndBlockRequest{} } -func (m *EndBlockRequest) String() string { return proto.CompactTextString(m) } -func (*EndBlockRequest) ProtoMessage() {} -func (*EndBlockRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_9b48d4169ef99d67, []int{3} -} -func (m *EndBlockRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *EndBlockRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_EndBlockRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *EndBlockRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_EndBlockRequest.Merge(m, src) -} -func (m *EndBlockRequest) XXX_Size() int { - return m.Size() -} -func (m *EndBlockRequest) XXX_DiscardUnknown() { - xxx_messageInfo_EndBlockRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_EndBlockRequest proto.InternalMessageInfo - -func (m *EndBlockRequest) GetHeight() int64 { - if m != nil { - return m.Height - } - return 0 -} - -// StreamResponse contains the response data for a stream request -type StreamResponse struct { - // The ChainID for the tendermint application we are streaming data for - ChainId string `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` - // The block height that this response is for - Height int64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty"` - // begin_block_payload contains the BeginBlock data - BeginBlockPayload *BeginBlockPayload `protobuf:"bytes,3,opt,name=begin_block_payload,json=beginBlockPayload,proto3" json:"begin_block_payload,omitempty"` - // deliver_tx_payload contains the DeliverTx data - DeliverTxPayload *DeliverTxPayload `protobuf:"bytes,4,opt,name=deliver_tx_payload,json=deliverTxPayload,proto3" json:"deliver_tx_payload,omitempty"` - // end_block_payload contains the EndBlock data - EndBlockPayload *EndBlockPayload `protobuf:"bytes,5,opt,name=end_block_payload,json=endBlockPayload,proto3" json:"end_block_payload,omitempty"` - // error holds any error that occurred while generating the response - Err string `protobuf:"bytes,6,opt,name=err,proto3" json:"err,omitempty"` -} - -func (m *StreamResponse) Reset() { *m = StreamResponse{} } -func (m *StreamResponse) String() string { return proto.CompactTextString(m) } -func (*StreamResponse) ProtoMessage() {} -func (*StreamResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_9b48d4169ef99d67, []int{4} -} -func (m *StreamResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *StreamResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_StreamResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *StreamResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_StreamResponse.Merge(m, src) -} -func (m *StreamResponse) XXX_Size() int { - return m.Size() -} -func (m *StreamResponse) XXX_DiscardUnknown() { - xxx_messageInfo_StreamResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_StreamResponse proto.InternalMessageInfo - -func (m *StreamResponse) GetChainId() string { - if m != nil { - return m.ChainId - } - return "" -} - -func (m *StreamResponse) GetHeight() int64 { - if m != nil { - return m.Height - } - return 0 -} - -func (m *StreamResponse) GetBeginBlockPayload() *BeginBlockPayload { - if m != nil { - return m.BeginBlockPayload - } - return nil -} - -func (m *StreamResponse) GetDeliverTxPayload() *DeliverTxPayload { - if m != nil { - return m.DeliverTxPayload - } - return nil -} - -func (m *StreamResponse) GetEndBlockPayload() *EndBlockPayload { - if m != nil { - return m.EndBlockPayload - } - return nil -} - -func (m *StreamResponse) GetErr() string { - if m != nil { - return m.Err - } - return "" -} - -// BeginBlockPayload contains the BeginBlock data -type BeginBlockPayload struct { - Request *types.RequestBeginBlock `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"` - Response *types.ResponseBeginBlock `protobuf:"bytes,2,opt,name=response,proto3" json:"response,omitempty"` - StateChanges []*types1.StoreKVPair `protobuf:"bytes,3,rep,name=state_changes,json=stateChanges,proto3" json:"state_changes,omitempty"` -} - -func (m *BeginBlockPayload) Reset() { *m = BeginBlockPayload{} } -func (m *BeginBlockPayload) String() string { return proto.CompactTextString(m) } -func (*BeginBlockPayload) ProtoMessage() {} -func (*BeginBlockPayload) Descriptor() ([]byte, []int) { - return fileDescriptor_9b48d4169ef99d67, []int{5} -} -func (m *BeginBlockPayload) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *BeginBlockPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_BeginBlockPayload.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *BeginBlockPayload) XXX_Merge(src proto.Message) { - xxx_messageInfo_BeginBlockPayload.Merge(m, src) -} -func (m *BeginBlockPayload) XXX_Size() int { - return m.Size() -} -func (m *BeginBlockPayload) XXX_DiscardUnknown() { - xxx_messageInfo_BeginBlockPayload.DiscardUnknown(m) -} - -var xxx_messageInfo_BeginBlockPayload proto.InternalMessageInfo - -func (m *BeginBlockPayload) GetRequest() *types.RequestBeginBlock { - if m != nil { - return m.Request - } - return nil -} - -func (m *BeginBlockPayload) GetResponse() *types.ResponseBeginBlock { - if m != nil { - return m.Response - } - return nil -} - -func (m *BeginBlockPayload) GetStateChanges() []*types1.StoreKVPair { - if m != nil { - return m.StateChanges - } - return nil -} - -// DeliverTxPayload contains the DeliverTx data -type DeliverTxPayload struct { - Request *types.RequestDeliverTx `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"` - Response *types.ResponseDeliverTx `protobuf:"bytes,2,opt,name=response,proto3" json:"response,omitempty"` - StateChanges []*types1.StoreKVPair `protobuf:"bytes,3,rep,name=state_changes,json=stateChanges,proto3" json:"state_changes,omitempty"` -} - -func (m *DeliverTxPayload) Reset() { *m = DeliverTxPayload{} } -func (m *DeliverTxPayload) String() string { return proto.CompactTextString(m) } -func (*DeliverTxPayload) ProtoMessage() {} -func (*DeliverTxPayload) Descriptor() ([]byte, []int) { - return fileDescriptor_9b48d4169ef99d67, []int{6} -} -func (m *DeliverTxPayload) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *DeliverTxPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_DeliverTxPayload.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *DeliverTxPayload) XXX_Merge(src proto.Message) { - xxx_messageInfo_DeliverTxPayload.Merge(m, src) -} -func (m *DeliverTxPayload) XXX_Size() int { - return m.Size() -} -func (m *DeliverTxPayload) XXX_DiscardUnknown() { - xxx_messageInfo_DeliverTxPayload.DiscardUnknown(m) -} - -var xxx_messageInfo_DeliverTxPayload proto.InternalMessageInfo - -func (m *DeliverTxPayload) GetRequest() *types.RequestDeliverTx { - if m != nil { - return m.Request - } - return nil -} - -func (m *DeliverTxPayload) GetResponse() *types.ResponseDeliverTx { - if m != nil { - return m.Response - } - return nil -} - -func (m *DeliverTxPayload) GetStateChanges() []*types1.StoreKVPair { - if m != nil { - return m.StateChanges - } - return nil -} - -// EndBlockPayload contains the EndBlock data -type EndBlockPayload struct { - Request *types.RequestEndBlock `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"` - Response *types.ResponseEndBlock `protobuf:"bytes,2,opt,name=response,proto3" json:"response,omitempty"` - StateChanges []*types1.StoreKVPair `protobuf:"bytes,3,rep,name=state_changes,json=stateChanges,proto3" json:"state_changes,omitempty"` -} - -func (m *EndBlockPayload) Reset() { *m = EndBlockPayload{} } -func (m *EndBlockPayload) String() string { return proto.CompactTextString(m) } -func (*EndBlockPayload) ProtoMessage() {} -func (*EndBlockPayload) Descriptor() ([]byte, []int) { - return fileDescriptor_9b48d4169ef99d67, []int{7} -} -func (m *EndBlockPayload) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *EndBlockPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_EndBlockPayload.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *EndBlockPayload) XXX_Merge(src proto.Message) { - xxx_messageInfo_EndBlockPayload.Merge(m, src) -} -func (m *EndBlockPayload) XXX_Size() int { - return m.Size() -} -func (m *EndBlockPayload) XXX_DiscardUnknown() { - xxx_messageInfo_EndBlockPayload.DiscardUnknown(m) -} - -var xxx_messageInfo_EndBlockPayload proto.InternalMessageInfo - -func (m *EndBlockPayload) GetRequest() *types.RequestEndBlock { - if m != nil { - return m.Request - } - return nil -} - -func (m *EndBlockPayload) GetResponse() *types.ResponseEndBlock { - if m != nil { - return m.Response - } - return nil -} - -func (m *EndBlockPayload) GetStateChanges() []*types1.StoreKVPair { - if m != nil { - return m.StateChanges - } - return nil -} - -func init() { - proto.RegisterType((*StreamRequest)(nil), "cosmos.base.server.v1beta1.StreamRequest") - proto.RegisterType((*BeginBlockRequest)(nil), "cosmos.base.server.v1beta1.BeginBlockRequest") - proto.RegisterType((*DeliverTxRequest)(nil), "cosmos.base.server.v1beta1.DeliverTxRequest") - proto.RegisterType((*EndBlockRequest)(nil), "cosmos.base.server.v1beta1.EndBlockRequest") - proto.RegisterType((*StreamResponse)(nil), "cosmos.base.server.v1beta1.StreamResponse") - proto.RegisterType((*BeginBlockPayload)(nil), "cosmos.base.server.v1beta1.BeginBlockPayload") - proto.RegisterType((*DeliverTxPayload)(nil), "cosmos.base.server.v1beta1.DeliverTxPayload") - proto.RegisterType((*EndBlockPayload)(nil), "cosmos.base.server.v1beta1.EndBlockPayload") -} - -func init() { - proto.RegisterFile("cosmos/base/server/v1beta1/server.proto", fileDescriptor_9b48d4169ef99d67) -} - -var fileDescriptor_9b48d4169ef99d67 = []byte{ - // 733 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x4b, 0x6f, 0xd3, 0x4c, - 0x14, 0xb5, 0xeb, 0x7c, 0x6d, 0x32, 0xe9, 0x73, 0x3e, 0x54, 0x85, 0x54, 0xa4, 0xa9, 0x91, 0xa0, - 0x0f, 0x6a, 0xd3, 0xb0, 0xe3, 0x29, 0x42, 0xa9, 0x84, 0xba, 0xa9, 0x5c, 0xc4, 0x02, 0x09, 0x82, - 0x1f, 0x83, 0x33, 0x8a, 0x63, 0x87, 0x99, 0x69, 0xd5, 0x2c, 0x59, 0xb3, 0xe1, 0xb7, 0xf0, 0x2b, - 0xba, 0xec, 0x12, 0x24, 0x04, 0xa8, 0xfd, 0x23, 0xc8, 0xe3, 0xf1, 0xd8, 0x49, 0x49, 0x9b, 0x2e, - 0xba, 0x6a, 0x7d, 0xe7, 0x9c, 0x7b, 0xe6, 0xdc, 0x7b, 0x67, 0x26, 0xe0, 0xae, 0x1b, 0xd1, 0x6e, - 0x44, 0x4d, 0xc7, 0xa6, 0xc8, 0xa4, 0x88, 0x1c, 0x22, 0x62, 0x1e, 0x6e, 0x39, 0x88, 0xd9, 0x5b, - 0xe2, 0xd3, 0xe8, 0x91, 0x88, 0x45, 0xb0, 0x9a, 0x00, 0x8d, 0x18, 0x68, 0x88, 0x15, 0x01, 0xac, - 0xde, 0xf0, 0x23, 0x3f, 0xe2, 0x30, 0x33, 0xfe, 0x2f, 0x61, 0x54, 0xd7, 0x06, 0x52, 0xb3, 0x88, - 0x20, 0x99, 0x39, 0xc0, 0x94, 0xa1, 0x10, 0x87, 0xbe, 0x80, 0x2e, 0x31, 0x14, 0x7a, 0x88, 0x74, - 0x71, 0xc8, 0x4c, 0xdb, 0x71, 0xb1, 0xc9, 0xfa, 0x3d, 0x44, 0x93, 0x45, 0xfd, 0x8b, 0x0a, 0x66, - 0xf6, 0x19, 0x41, 0x76, 0xd7, 0x42, 0x9f, 0x0e, 0x10, 0x65, 0x70, 0x19, 0x94, 0x1d, 0xe4, 0xe3, - 0xb0, 0xe5, 0x04, 0x91, 0xdb, 0xa9, 0xa8, 0x75, 0x75, 0xb5, 0x68, 0x01, 0x1e, 0x6a, 0xc6, 0x11, - 0x78, 0x0b, 0x00, 0x0f, 0x05, 0xf8, 0x10, 0x91, 0x16, 0x3b, 0xaa, 0x4c, 0xf0, 0xf5, 0x92, 0x88, - 0xbc, 0x3e, 0x82, 0x4b, 0xa0, 0x84, 0x42, 0x4f, 0xb0, 0x35, 0xbe, 0x5a, 0x44, 0xa1, 0x27, 0xb9, - 0x7c, 0xb3, 0xad, 0x0e, 0xea, 0xd3, 0x4a, 0xa1, 0xae, 0xad, 0x96, 0xac, 0x12, 0x8f, 0xec, 0xa2, - 0x3e, 0xd5, 0x37, 0xc0, 0x42, 0x53, 0x0a, 0xa5, 0x1b, 0x5a, 0x04, 0x93, 0x6d, 0x84, 0xfd, 0x36, - 0xe3, 0x7b, 0xd1, 0x2c, 0xf1, 0xa5, 0xaf, 0x83, 0xf9, 0xed, 0x54, 0xf5, 0x32, 0xec, 0x1a, 0x98, - 0x7b, 0x29, 0xf6, 0x70, 0x19, 0xf4, 0xb3, 0x06, 0x66, 0xd3, 0x8a, 0xd0, 0x5e, 0x14, 0x52, 0x04, - 0x6f, 0x82, 0xa2, 0xdb, 0xb6, 0x71, 0xd8, 0xc2, 0x1e, 0x07, 0x97, 0xac, 0x29, 0xfe, 0xfd, 0xca, - 0xcb, 0x65, 0x99, 0xc8, 0x67, 0x81, 0x2e, 0xf8, 0x3f, 0x57, 0xc5, 0x56, 0xcf, 0xee, 0x07, 0x91, - 0xed, 0xf1, 0x7a, 0x94, 0x1b, 0x9b, 0xc6, 0xe8, 0x7e, 0x1b, 0x59, 0x01, 0xf6, 0x12, 0x52, 0xb3, - 0x70, 0xfc, 0x6b, 0x59, 0xb5, 0x16, 0x9c, 0xe1, 0x05, 0xf8, 0x01, 0xc0, 0xac, 0x13, 0x52, 0xa3, - 0xc0, 0x35, 0xee, 0x5d, 0xa4, 0x21, 0xeb, 0x36, 0x28, 0x31, 0xef, 0x0d, 0xc5, 0xe1, 0x3b, 0xb0, - 0x20, 0x9b, 0x29, 0x05, 0xfe, 0xe3, 0x02, 0x1b, 0x17, 0x09, 0xa4, 0xc5, 0x1e, 0xcc, 0x3f, 0x87, - 0x06, 0xc3, 0x70, 0x11, 0x68, 0x88, 0x90, 0xca, 0x64, 0x5c, 0x53, 0x81, 0x89, 0x03, 0xfa, 0x6f, - 0x35, 0x3f, 0x08, 0x29, 0xfa, 0x31, 0x98, 0x22, 0x49, 0xf3, 0x78, 0x17, 0xca, 0x0d, 0xdd, 0xc8, - 0x46, 0xdb, 0x88, 0x47, 0xdb, 0x10, 0xcd, 0xcd, 0x0d, 0x51, 0x4a, 0x81, 0xcf, 0x40, 0x91, 0x88, - 0x86, 0xf2, 0x5e, 0x95, 0x1b, 0xb7, 0xff, 0x41, 0x4f, 0x00, 0x39, 0xbe, 0x24, 0xc1, 0x5d, 0x30, - 0x43, 0x99, 0xcd, 0x50, 0xcb, 0x6d, 0xdb, 0xa1, 0x8f, 0x68, 0x45, 0xab, 0x6b, 0xab, 0xe5, 0xc6, - 0x9d, 0xc1, 0x3a, 0xc4, 0xb3, 0x2c, 0xcb, 0xb0, 0xcf, 0x27, 0xfb, 0xcd, 0x9e, 0x8d, 0x89, 0x35, - 0xcd, 0xc9, 0x2f, 0x12, 0xae, 0xfe, 0x53, 0xcd, 0x4d, 0x6f, 0x6a, 0xf0, 0xd1, 0xb0, 0xc1, 0x95, - 0x51, 0x06, 0xb3, 0xc1, 0x97, 0xfe, 0x9e, 0x9e, 0xf3, 0xa7, 0x8f, 0xf4, 0x97, 0xd1, 0xaf, 0xc9, - 0xde, 0x0f, 0x35, 0x3b, 0x70, 0xa9, 0xbb, 0x87, 0xc3, 0xee, 0xea, 0xa3, 0xdc, 0xc9, 0xa3, 0x2a, - 0xcd, 0x3d, 0x39, 0x67, 0x6e, 0x65, 0xa4, 0x39, 0xc9, 0xbe, 0x1e, 0x6f, 0x8d, 0x6f, 0x05, 0x50, - 0xda, 0x8f, 0x03, 0x3b, 0x38, 0x40, 0x90, 0x80, 0xf9, 0x6c, 0x5a, 0xb6, 0x6d, 0x66, 0x3f, 0x67, - 0x70, 0xcc, 0xf3, 0x2d, 0xdc, 0x56, 0xaf, 0x76, 0x1d, 0xe8, 0x0a, 0x8c, 0xc0, 0x9c, 0xec, 0xa0, - 0x90, 0x1c, 0xef, 0xb8, 0xa7, 0x8a, 0x57, 0xba, 0x1c, 0x74, 0x05, 0x06, 0x60, 0x36, 0xad, 0xaa, - 0xd0, 0x1b, 0xeb, 0xf4, 0xa7, 0x72, 0x57, 0xb9, 0x2a, 0x74, 0x05, 0xfa, 0x00, 0x24, 0x17, 0x70, - 0xac, 0x05, 0xd7, 0x2e, 0x22, 0x0f, 0x3c, 0x5d, 0xd5, 0xf5, 0x71, 0xa0, 0xc9, 0x48, 0xe8, 0xca, - 0x7d, 0x15, 0x62, 0x30, 0xdd, 0xb4, 0xdd, 0xce, 0x0e, 0x0e, 0x82, 0x6b, 0x96, 0x6a, 0xbe, 0x3f, - 0x3e, 0xad, 0xa9, 0x27, 0xa7, 0x35, 0xf5, 0xcf, 0x69, 0x4d, 0xfd, 0x7a, 0x56, 0x53, 0x4e, 0xce, - 0x6a, 0xca, 0xf7, 0xb3, 0x9a, 0xf2, 0x76, 0xdb, 0xc7, 0xac, 0x7d, 0xe0, 0x18, 0x6e, 0xd4, 0x35, - 0xc5, 0xa3, 0x9e, 0xfc, 0xd9, 0xa4, 0x5e, 0x47, 0x3c, 0xed, 0x94, 0x27, 0xc4, 0xa1, 0x6f, 0x7e, - 0xc4, 0x81, 0xfc, 0x29, 0xe1, 0x93, 0x9e, 0x2b, 0x5e, 0x7d, 0x67, 0x92, 0x3f, 0xe7, 0x0f, 0xfe, - 0x06, 0x00, 0x00, 0xff, 0xff, 0xed, 0x94, 0x60, 0xfc, 0x73, 0x08, 0x00, 0x00, -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// StateFileClient is the client API for StateFile service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type StateFileClient interface { - BeginBlockDataAt(ctx context.Context, in *BeginBlockRequest, opts ...grpc.CallOption) (*BeginBlockPayload, error) - DeliverTxDataAt(ctx context.Context, in *DeliverTxRequest, opts ...grpc.CallOption) (*DeliverTxPayload, error) - EndBlockDataAt(ctx context.Context, in *EndBlockRequest, opts ...grpc.CallOption) (*EndBlockPayload, error) - StreamData(ctx context.Context, in *StreamRequest, opts ...grpc.CallOption) (StateFile_StreamDataClient, error) - BackFillData(ctx context.Context, in *StreamRequest, opts ...grpc.CallOption) (StateFile_BackFillDataClient, error) -} - -type stateFileClient struct { - cc grpc1.ClientConn -} - -func NewStateFileClient(cc grpc1.ClientConn) StateFileClient { - return &stateFileClient{cc} -} - -func (c *stateFileClient) BeginBlockDataAt(ctx context.Context, in *BeginBlockRequest, opts ...grpc.CallOption) (*BeginBlockPayload, error) { - out := new(BeginBlockPayload) - err := c.cc.Invoke(ctx, "/cosmos.base.server.v1beta1.StateFile/BeginBlockDataAt", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *stateFileClient) DeliverTxDataAt(ctx context.Context, in *DeliverTxRequest, opts ...grpc.CallOption) (*DeliverTxPayload, error) { - out := new(DeliverTxPayload) - err := c.cc.Invoke(ctx, "/cosmos.base.server.v1beta1.StateFile/DeliverTxDataAt", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *stateFileClient) EndBlockDataAt(ctx context.Context, in *EndBlockRequest, opts ...grpc.CallOption) (*EndBlockPayload, error) { - out := new(EndBlockPayload) - err := c.cc.Invoke(ctx, "/cosmos.base.server.v1beta1.StateFile/EndBlockDataAt", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *stateFileClient) StreamData(ctx context.Context, in *StreamRequest, opts ...grpc.CallOption) (StateFile_StreamDataClient, error) { - stream, err := c.cc.NewStream(ctx, &_StateFile_serviceDesc.Streams[0], "/cosmos.base.server.v1beta1.StateFile/StreamData", opts...) - if err != nil { - return nil, err - } - x := &stateFileStreamDataClient{stream} - if err := x.ClientStream.SendMsg(in); err != nil { - return nil, err - } - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - return x, nil -} - -type StateFile_StreamDataClient interface { - Recv() (*StreamResponse, error) - grpc.ClientStream -} - -type stateFileStreamDataClient struct { - grpc.ClientStream -} - -func (x *stateFileStreamDataClient) Recv() (*StreamResponse, error) { - m := new(StreamResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *stateFileClient) BackFillData(ctx context.Context, in *StreamRequest, opts ...grpc.CallOption) (StateFile_BackFillDataClient, error) { - stream, err := c.cc.NewStream(ctx, &_StateFile_serviceDesc.Streams[1], "/cosmos.base.server.v1beta1.StateFile/BackFillData", opts...) - if err != nil { - return nil, err - } - x := &stateFileBackFillDataClient{stream} - if err := x.ClientStream.SendMsg(in); err != nil { - return nil, err - } - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - return x, nil -} - -type StateFile_BackFillDataClient interface { - Recv() (*StreamResponse, error) - grpc.ClientStream -} - -type stateFileBackFillDataClient struct { - grpc.ClientStream -} - -func (x *stateFileBackFillDataClient) Recv() (*StreamResponse, error) { - m := new(StreamResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -// StateFileServer is the server API for StateFile service. -type StateFileServer interface { - BeginBlockDataAt(context.Context, *BeginBlockRequest) (*BeginBlockPayload, error) - DeliverTxDataAt(context.Context, *DeliverTxRequest) (*DeliverTxPayload, error) - EndBlockDataAt(context.Context, *EndBlockRequest) (*EndBlockPayload, error) - StreamData(*StreamRequest, StateFile_StreamDataServer) error - BackFillData(*StreamRequest, StateFile_BackFillDataServer) error -} - -// UnimplementedStateFileServer can be embedded to have forward compatible implementations. -type UnimplementedStateFileServer struct { -} - -func (*UnimplementedStateFileServer) BeginBlockDataAt(ctx context.Context, req *BeginBlockRequest) (*BeginBlockPayload, error) { - return nil, status.Errorf(codes.Unimplemented, "method BeginBlockDataAt not implemented") -} -func (*UnimplementedStateFileServer) DeliverTxDataAt(ctx context.Context, req *DeliverTxRequest) (*DeliverTxPayload, error) { - return nil, status.Errorf(codes.Unimplemented, "method DeliverTxDataAt not implemented") -} -func (*UnimplementedStateFileServer) EndBlockDataAt(ctx context.Context, req *EndBlockRequest) (*EndBlockPayload, error) { - return nil, status.Errorf(codes.Unimplemented, "method EndBlockDataAt not implemented") -} -func (*UnimplementedStateFileServer) StreamData(req *StreamRequest, srv StateFile_StreamDataServer) error { - return status.Errorf(codes.Unimplemented, "method StreamData not implemented") -} -func (*UnimplementedStateFileServer) BackFillData(req *StreamRequest, srv StateFile_BackFillDataServer) error { - return status.Errorf(codes.Unimplemented, "method BackFillData not implemented") -} - -func RegisterStateFileServer(s grpc1.Server, srv StateFileServer) { - s.RegisterService(&_StateFile_serviceDesc, srv) -} - -func _StateFile_BeginBlockDataAt_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(BeginBlockRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(StateFileServer).BeginBlockDataAt(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/cosmos.base.server.v1beta1.StateFile/BeginBlockDataAt", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(StateFileServer).BeginBlockDataAt(ctx, req.(*BeginBlockRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _StateFile_DeliverTxDataAt_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(DeliverTxRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(StateFileServer).DeliverTxDataAt(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/cosmos.base.server.v1beta1.StateFile/DeliverTxDataAt", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(StateFileServer).DeliverTxDataAt(ctx, req.(*DeliverTxRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _StateFile_EndBlockDataAt_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(EndBlockRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(StateFileServer).EndBlockDataAt(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/cosmos.base.server.v1beta1.StateFile/EndBlockDataAt", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(StateFileServer).EndBlockDataAt(ctx, req.(*EndBlockRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _StateFile_StreamData_Handler(srv interface{}, stream grpc.ServerStream) error { - m := new(StreamRequest) - if err := stream.RecvMsg(m); err != nil { - return err - } - return srv.(StateFileServer).StreamData(m, &stateFileStreamDataServer{stream}) -} - -type StateFile_StreamDataServer interface { - Send(*StreamResponse) error - grpc.ServerStream -} - -type stateFileStreamDataServer struct { - grpc.ServerStream -} - -func (x *stateFileStreamDataServer) Send(m *StreamResponse) error { - return x.ServerStream.SendMsg(m) -} - -func _StateFile_BackFillData_Handler(srv interface{}, stream grpc.ServerStream) error { - m := new(StreamRequest) - if err := stream.RecvMsg(m); err != nil { - return err - } - return srv.(StateFileServer).BackFillData(m, &stateFileBackFillDataServer{stream}) -} - -type StateFile_BackFillDataServer interface { - Send(*StreamResponse) error - grpc.ServerStream -} - -type stateFileBackFillDataServer struct { - grpc.ServerStream -} - -func (x *stateFileBackFillDataServer) Send(m *StreamResponse) error { - return x.ServerStream.SendMsg(m) -} - -var _StateFile_serviceDesc = grpc.ServiceDesc{ - ServiceName: "cosmos.base.server.v1beta1.StateFile", - HandlerType: (*StateFileServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "BeginBlockDataAt", - Handler: _StateFile_BeginBlockDataAt_Handler, - }, - { - MethodName: "DeliverTxDataAt", - Handler: _StateFile_DeliverTxDataAt_Handler, - }, - { - MethodName: "EndBlockDataAt", - Handler: _StateFile_EndBlockDataAt_Handler, - }, - }, - Streams: []grpc.StreamDesc{ - { - StreamName: "StreamData", - Handler: _StateFile_StreamData_Handler, - ServerStreams: true, - }, - { - StreamName: "BackFillData", - Handler: _StateFile_BackFillData_Handler, - ServerStreams: true, - }, - }, - Metadata: "cosmos/base/server/v1beta1/server.proto", -} - -func (m *StreamRequest) 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 *StreamRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *StreamRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.StoreKeys) > 0 { - for iNdEx := len(m.StoreKeys) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.StoreKeys[iNdEx]) - copy(dAtA[i:], m.StoreKeys[iNdEx]) - i = encodeVarintServer(dAtA, i, uint64(len(m.StoreKeys[iNdEx]))) - i-- - dAtA[i] = 0x22 - } - } - if m.EndBlock { - i-- - if m.EndBlock { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x18 - } - if m.DeliverTx { - i-- - if m.DeliverTx { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x10 - } - if m.BeginBlock { - i-- - if m.BeginBlock { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *BeginBlockRequest) 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 *BeginBlockRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *BeginBlockRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Height != 0 { - i = encodeVarintServer(dAtA, i, uint64(m.Height)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *DeliverTxRequest) 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 *DeliverTxRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *DeliverTxRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Height != 0 { - i = encodeVarintServer(dAtA, i, uint64(m.Height)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *EndBlockRequest) 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 *EndBlockRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *EndBlockRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Height != 0 { - i = encodeVarintServer(dAtA, i, uint64(m.Height)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *StreamResponse) 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 *StreamResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *StreamResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Err) > 0 { - i -= len(m.Err) - copy(dAtA[i:], m.Err) - i = encodeVarintServer(dAtA, i, uint64(len(m.Err))) - i-- - dAtA[i] = 0x32 - } - if m.EndBlockPayload != nil { - { - size, err := m.EndBlockPayload.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintServer(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x2a - } - if m.DeliverTxPayload != nil { - { - size, err := m.DeliverTxPayload.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintServer(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - } - if m.BeginBlockPayload != nil { - { - size, err := m.BeginBlockPayload.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintServer(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - if m.Height != 0 { - i = encodeVarintServer(dAtA, i, uint64(m.Height)) - i-- - dAtA[i] = 0x10 - } - if len(m.ChainId) > 0 { - i -= len(m.ChainId) - copy(dAtA[i:], m.ChainId) - i = encodeVarintServer(dAtA, i, uint64(len(m.ChainId))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *BeginBlockPayload) 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 *BeginBlockPayload) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *BeginBlockPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.StateChanges) > 0 { - for iNdEx := len(m.StateChanges) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.StateChanges[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintServer(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - } - if m.Response != nil { - { - size, err := m.Response.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintServer(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if m.Request != nil { - { - size, err := m.Request.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintServer(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *DeliverTxPayload) 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 *DeliverTxPayload) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *DeliverTxPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.StateChanges) > 0 { - for iNdEx := len(m.StateChanges) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.StateChanges[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintServer(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - } - if m.Response != nil { - { - size, err := m.Response.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintServer(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if m.Request != nil { - { - size, err := m.Request.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintServer(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *EndBlockPayload) 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 *EndBlockPayload) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *EndBlockPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.StateChanges) > 0 { - for iNdEx := len(m.StateChanges) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.StateChanges[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintServer(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - } - if m.Response != nil { - { - size, err := m.Response.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintServer(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if m.Request != nil { - { - size, err := m.Request.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintServer(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintServer(dAtA []byte, offset int, v uint64) int { - offset -= sovServer(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *StreamRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.BeginBlock { - n += 2 - } - if m.DeliverTx { - n += 2 - } - if m.EndBlock { - n += 2 - } - if len(m.StoreKeys) > 0 { - for _, s := range m.StoreKeys { - l = len(s) - n += 1 + l + sovServer(uint64(l)) - } - } - return n -} - -func (m *BeginBlockRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Height != 0 { - n += 1 + sovServer(uint64(m.Height)) - } - return n -} - -func (m *DeliverTxRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Height != 0 { - n += 1 + sovServer(uint64(m.Height)) - } - return n -} - -func (m *EndBlockRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Height != 0 { - n += 1 + sovServer(uint64(m.Height)) - } - return n -} - -func (m *StreamResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.ChainId) - if l > 0 { - n += 1 + l + sovServer(uint64(l)) - } - if m.Height != 0 { - n += 1 + sovServer(uint64(m.Height)) - } - if m.BeginBlockPayload != nil { - l = m.BeginBlockPayload.Size() - n += 1 + l + sovServer(uint64(l)) - } - if m.DeliverTxPayload != nil { - l = m.DeliverTxPayload.Size() - n += 1 + l + sovServer(uint64(l)) - } - if m.EndBlockPayload != nil { - l = m.EndBlockPayload.Size() - n += 1 + l + sovServer(uint64(l)) - } - l = len(m.Err) - if l > 0 { - n += 1 + l + sovServer(uint64(l)) - } - return n -} - -func (m *BeginBlockPayload) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Request != nil { - l = m.Request.Size() - n += 1 + l + sovServer(uint64(l)) - } - if m.Response != nil { - l = m.Response.Size() - n += 1 + l + sovServer(uint64(l)) - } - if len(m.StateChanges) > 0 { - for _, e := range m.StateChanges { - l = e.Size() - n += 1 + l + sovServer(uint64(l)) - } - } - return n -} - -func (m *DeliverTxPayload) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Request != nil { - l = m.Request.Size() - n += 1 + l + sovServer(uint64(l)) - } - if m.Response != nil { - l = m.Response.Size() - n += 1 + l + sovServer(uint64(l)) - } - if len(m.StateChanges) > 0 { - for _, e := range m.StateChanges { - l = e.Size() - n += 1 + l + sovServer(uint64(l)) - } - } - return n -} - -func (m *EndBlockPayload) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Request != nil { - l = m.Request.Size() - n += 1 + l + sovServer(uint64(l)) - } - if m.Response != nil { - l = m.Response.Size() - n += 1 + l + sovServer(uint64(l)) - } - if len(m.StateChanges) > 0 { - for _, e := range m.StateChanges { - l = e.Size() - n += 1 + l + sovServer(uint64(l)) - } - } - return n -} - -func sovServer(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozServer(x uint64) (n int) { - return sovServer(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *StreamRequest) 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 ErrIntOverflowServer - } - 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: StreamRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: StreamRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field BeginBlock", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.BeginBlock = bool(v != 0) - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field DeliverTx", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.DeliverTx = bool(v != 0) - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field EndBlock", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.EndBlock = bool(v != 0) - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StoreKeys", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - 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 ErrInvalidLengthServer - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthServer - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.StoreKeys = append(m.StoreKeys, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipServer(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthServer - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *BeginBlockRequest) 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 ErrIntOverflowServer - } - 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: BeginBlockRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: BeginBlockRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) - } - m.Height = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Height |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipServer(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthServer - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *DeliverTxRequest) 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 ErrIntOverflowServer - } - 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: DeliverTxRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: DeliverTxRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) - } - m.Height = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Height |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipServer(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthServer - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *EndBlockRequest) 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 ErrIntOverflowServer - } - 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: EndBlockRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: EndBlockRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) - } - m.Height = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Height |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipServer(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthServer - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *StreamResponse) 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 ErrIntOverflowServer - } - 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: StreamResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: StreamResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - 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 ErrInvalidLengthServer - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthServer - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ChainId = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) - } - m.Height = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Height |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BeginBlockPayload", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthServer - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthServer - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.BeginBlockPayload == nil { - m.BeginBlockPayload = &BeginBlockPayload{} - } - if err := m.BeginBlockPayload.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field DeliverTxPayload", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthServer - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthServer - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.DeliverTxPayload == nil { - m.DeliverTxPayload = &DeliverTxPayload{} - } - if err := m.DeliverTxPayload.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EndBlockPayload", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthServer - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthServer - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.EndBlockPayload == nil { - m.EndBlockPayload = &EndBlockPayload{} - } - if err := m.EndBlockPayload.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Err", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - 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 ErrInvalidLengthServer - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthServer - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Err = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipServer(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthServer - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *BeginBlockPayload) 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 ErrIntOverflowServer - } - 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: BeginBlockPayload: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: BeginBlockPayload: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Request", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthServer - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthServer - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Request == nil { - m.Request = &types.RequestBeginBlock{} - } - if err := m.Request.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Response", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthServer - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthServer - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Response == nil { - m.Response = &types.ResponseBeginBlock{} - } - if err := m.Response.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StateChanges", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthServer - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthServer - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.StateChanges = append(m.StateChanges, &types1.StoreKVPair{}) - if err := m.StateChanges[len(m.StateChanges)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipServer(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthServer - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *DeliverTxPayload) 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 ErrIntOverflowServer - } - 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: DeliverTxPayload: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: DeliverTxPayload: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Request", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthServer - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthServer - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Request == nil { - m.Request = &types.RequestDeliverTx{} - } - if err := m.Request.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Response", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthServer - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthServer - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Response == nil { - m.Response = &types.ResponseDeliverTx{} - } - if err := m.Response.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StateChanges", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthServer - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthServer - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.StateChanges = append(m.StateChanges, &types1.StoreKVPair{}) - if err := m.StateChanges[len(m.StateChanges)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipServer(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthServer - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *EndBlockPayload) 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 ErrIntOverflowServer - } - 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: EndBlockPayload: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: EndBlockPayload: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Request", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthServer - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthServer - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Request == nil { - m.Request = &types.RequestEndBlock{} - } - if err := m.Request.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Response", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthServer - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthServer - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Response == nil { - m.Response = &types.ResponseEndBlock{} - } - if err := m.Response.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StateChanges", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowServer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthServer - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthServer - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.StateChanges = append(m.StateChanges, &types1.StoreKVPair{}) - if err := m.StateChanges[len(m.StateChanges)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipServer(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthServer - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipServer(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowServer - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowServer - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowServer - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthServer - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupServer - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthServer - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthServer = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowServer = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupServer = fmt.Errorf("proto: unexpected end of group") -) diff --git a/store/streaming/file/server/v1beta/server.pb.go b/store/streaming/file/server/v1beta/server.pb.go index 8fc0531ea7cd..e506b04baff8 100644 --- a/store/streaming/file/server/v1beta/server.pb.go +++ b/store/streaming/file/server/v1beta/server.pb.go @@ -151,6 +151,7 @@ func (m *BeginBlockRequest) GetHeight() int64 { // DeliverTxRequest is the message definition for requesting DeliverTx data at a specific height type DeliverTxRequest struct { Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` + Index int64 `protobuf:"varint,2,opt,name=index,proto3" json:"index,omitempty"` } func (m *DeliverTxRequest) Reset() { *m = DeliverTxRequest{} } @@ -193,6 +194,13 @@ func (m *DeliverTxRequest) GetHeight() int64 { return 0 } +func (m *DeliverTxRequest) GetIndex() int64 { + if m != nil { + return m.Index + } + return 0 +} + // EndBlockRequest is the message definition for requesting EndBlock data at a specific height type EndBlockRequest struct { Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` @@ -528,53 +536,54 @@ func init() { } var fileDescriptor_9b48d4169ef99d67 = []byte{ - // 730 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x4b, 0x6f, 0xd3, 0x4a, - 0x14, 0x8e, 0x9b, 0xdc, 0x36, 0x39, 0xe9, 0x73, 0xee, 0x55, 0x95, 0x9b, 0x8a, 0x34, 0x35, 0x12, - 0xf4, 0x41, 0x6d, 0x1a, 0x76, 0xbc, 0x2a, 0x42, 0xa9, 0x84, 0xba, 0xa9, 0x5c, 0x84, 0x04, 0x12, - 0x0a, 0x7e, 0x0c, 0xce, 0x28, 0x8e, 0x1d, 0x3c, 0xd3, 0xaa, 0x59, 0xb2, 0x66, 0xc3, 0x6f, 0xe1, - 0x57, 0x74, 0xd9, 0x25, 0x48, 0x08, 0x50, 0xfb, 0x47, 0x90, 0xc7, 0xe3, 0xb1, 0x93, 0x92, 0x36, - 0x5d, 0x74, 0xd5, 0xfa, 0xcc, 0xf7, 0x9d, 0x6f, 0xbe, 0x73, 0xce, 0xcc, 0x04, 0xee, 0xda, 0x01, - 0xed, 0x06, 0x54, 0xb7, 0x4c, 0x8a, 0x75, 0x8a, 0xc3, 0x23, 0x1c, 0xea, 0x47, 0x5b, 0x16, 0x66, - 0xe6, 0x96, 0xf8, 0xd4, 0x7a, 0x61, 0xc0, 0x02, 0x54, 0x8d, 0x81, 0x5a, 0x04, 0xd4, 0xc4, 0x8a, - 0x00, 0x56, 0xff, 0x73, 0x03, 0x37, 0xe0, 0x30, 0x3d, 0xfa, 0x2f, 0x66, 0x54, 0xd7, 0x06, 0x52, - 0xb3, 0x20, 0xc4, 0x32, 0xb3, 0x47, 0x28, 0xc3, 0x3e, 0xf1, 0x5d, 0x01, 0x5d, 0x62, 0xd8, 0x77, - 0x70, 0xd8, 0x25, 0x3e, 0xd3, 0x4d, 0xcb, 0x26, 0x3a, 0xeb, 0xf7, 0x30, 0x8d, 0x17, 0xd5, 0xcf, - 0x0a, 0xcc, 0x1c, 0xb0, 0x10, 0x9b, 0x5d, 0x03, 0x7f, 0x3c, 0xc4, 0x94, 0xa1, 0x65, 0x28, 0x5b, - 0xd8, 0x25, 0x7e, 0xcb, 0xf2, 0x02, 0xbb, 0x53, 0x51, 0xea, 0xca, 0x6a, 0xd1, 0x00, 0x1e, 0x6a, - 0x46, 0x11, 0x74, 0x0b, 0xc0, 0xc1, 0x1e, 0x39, 0xc2, 0x61, 0x8b, 0x1d, 0x57, 0x26, 0xf8, 0x7a, - 0x49, 0x44, 0x5e, 0x1d, 0xa3, 0x25, 0x28, 0x61, 0xdf, 0x11, 0xec, 0x3c, 0x5f, 0x2d, 0x62, 0xdf, - 0x91, 0x5c, 0xbe, 0xd9, 0x56, 0x07, 0xf7, 0x69, 0xa5, 0x50, 0xcf, 0xaf, 0x96, 0x8c, 0x12, 0x8f, - 0xec, 0xe1, 0x3e, 0x55, 0x37, 0x60, 0xa1, 0x29, 0x85, 0x92, 0x0d, 0x2d, 0xc2, 0x64, 0x1b, 0x13, - 0xb7, 0xcd, 0xf8, 0x5e, 0xf2, 0x86, 0xf8, 0x52, 0xd7, 0x61, 0x7e, 0x27, 0x51, 0xbd, 0x0a, 0xbb, - 0x06, 0x73, 0x2f, 0xc4, 0x1e, 0xae, 0x82, 0x7e, 0xca, 0xc3, 0x6c, 0x52, 0x11, 0xda, 0x0b, 0x7c, - 0x8a, 0xd1, 0xff, 0x50, 0xb4, 0xdb, 0x26, 0xf1, 0x5b, 0xc4, 0xe1, 0xe0, 0x92, 0x31, 0xc5, 0xbf, - 0x5f, 0x3a, 0x99, 0x2c, 0x13, 0xd9, 0x2c, 0xc8, 0x86, 0x7f, 0x33, 0x55, 0x6c, 0xf5, 0xcc, 0xbe, - 0x17, 0x98, 0x0e, 0xaf, 0x47, 0xb9, 0xb1, 0xa9, 0x8d, 0xee, 0xb7, 0x96, 0x16, 0x60, 0x3f, 0x26, - 0x35, 0x0b, 0x27, 0x3f, 0x97, 0x15, 0x63, 0xc1, 0x1a, 0x5e, 0x40, 0xef, 0x01, 0xa5, 0x9d, 0x90, - 0x1a, 0x05, 0xae, 0x71, 0xef, 0x32, 0x0d, 0x59, 0xb7, 0x41, 0x89, 0x79, 0x67, 0x28, 0x8e, 0xde, - 0xc1, 0x82, 0x6c, 0xa6, 0x14, 0xf8, 0x87, 0x0b, 0x6c, 0x5c, 0x26, 0x90, 0x14, 0x7b, 0x30, 0xff, - 0x1c, 0x1e, 0x0c, 0xa3, 0x45, 0xc8, 0xe3, 0x30, 0xac, 0x4c, 0x46, 0x35, 0x15, 0x98, 0x28, 0xa0, - 0xfe, 0x52, 0xb2, 0x83, 0x90, 0xa0, 0x1f, 0xc3, 0x54, 0x18, 0x37, 0x8f, 0x77, 0xa1, 0xdc, 0x50, - 0xb5, 0x74, 0xb4, 0xb5, 0x68, 0xb4, 0x35, 0xd1, 0xdc, 0xcc, 0x10, 0x25, 0x14, 0xb4, 0x0d, 0xc5, - 0x50, 0x34, 0x94, 0xf7, 0xaa, 0xdc, 0xb8, 0xfd, 0x17, 0x7a, 0x0c, 0xc8, 0xf0, 0x25, 0x09, 0xed, - 0xc1, 0x0c, 0x65, 0x26, 0xc3, 0x2d, 0xbb, 0x6d, 0xfa, 0x2e, 0xa6, 0x95, 0x7c, 0x3d, 0xbf, 0x5a, - 0x6e, 0xdc, 0x19, 0xac, 0x43, 0x34, 0xcb, 0xb2, 0x0c, 0x07, 0x7c, 0xb2, 0x5f, 0xef, 0x9b, 0x24, - 0x34, 0xa6, 0x39, 0xf9, 0x79, 0xcc, 0x55, 0x7f, 0x28, 0x99, 0xe9, 0x4d, 0x0c, 0x3e, 0x1a, 0x36, - 0xb8, 0x32, 0xca, 0x60, 0x3a, 0xf8, 0xd2, 0xdf, 0xd3, 0x0b, 0xfe, 0xd4, 0x91, 0xfe, 0x52, 0xfa, - 0x0d, 0xd9, 0xfb, 0xae, 0xa4, 0x07, 0x2e, 0x71, 0xf7, 0x70, 0xd8, 0x5d, 0x7d, 0x94, 0x3b, 0x79, - 0x54, 0xa5, 0xb9, 0x27, 0x17, 0xcc, 0xad, 0x8c, 0x34, 0x27, 0xd9, 0x37, 0xe3, 0xad, 0xf1, 0xb5, - 0x00, 0xa5, 0x83, 0x28, 0xb0, 0x4b, 0x3c, 0x8c, 0x42, 0x98, 0x4f, 0xa7, 0x65, 0xc7, 0x64, 0xe6, - 0x33, 0x86, 0xc6, 0x3c, 0xdf, 0xc2, 0x6d, 0xf5, 0x7a, 0xd7, 0x81, 0x9a, 0x43, 0x01, 0xcc, 0xc9, - 0x0e, 0x0a, 0xc9, 0xf1, 0x8e, 0x7b, 0xa2, 0x78, 0xad, 0xcb, 0x41, 0xcd, 0x21, 0x0f, 0x66, 0x93, - 0xaa, 0x0a, 0xbd, 0xb1, 0x4e, 0x7f, 0x22, 0x77, 0x9d, 0xab, 0x42, 0xcd, 0x21, 0x17, 0x20, 0xbe, - 0x80, 0x23, 0x2d, 0xb4, 0x76, 0x19, 0x79, 0xe0, 0xe9, 0xaa, 0xae, 0x8f, 0x03, 0x8d, 0x47, 0x42, - 0xcd, 0xdd, 0x57, 0x10, 0x81, 0xe9, 0xa6, 0x69, 0x77, 0x76, 0x89, 0xe7, 0xdd, 0xb0, 0x54, 0xf3, - 0xcd, 0xc9, 0x59, 0x4d, 0x39, 0x3d, 0xab, 0x29, 0xbf, 0xcf, 0x6a, 0xca, 0x97, 0xf3, 0x5a, 0xee, - 0xf4, 0xbc, 0x96, 0xfb, 0x76, 0x5e, 0xcb, 0xbd, 0xdd, 0x76, 0x09, 0x6b, 0x1f, 0x5a, 0x9a, 0x1d, - 0x74, 0x75, 0xf1, 0xa8, 0xc7, 0x7f, 0x36, 0xa9, 0xd3, 0x11, 0x4f, 0x3b, 0xe5, 0x09, 0x89, 0xef, - 0xea, 0x1f, 0x88, 0x37, 0xf4, 0x53, 0xc2, 0x9a, 0xe4, 0x2f, 0xf9, 0x83, 0x3f, 0x01, 0x00, 0x00, - 0xff, 0xff, 0xdb, 0x03, 0x16, 0xaf, 0x6e, 0x08, 0x00, 0x00, + // 738 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x5b, 0x4f, 0x13, 0x41, + 0x14, 0xee, 0xb2, 0x05, 0xda, 0x53, 0xae, 0x23, 0x21, 0xb5, 0xc4, 0x52, 0xd6, 0x44, 0x41, 0x64, + 0x57, 0xea, 0x9b, 0x37, 0xb4, 0x22, 0x89, 0xe1, 0x85, 0x2c, 0xc6, 0x44, 0x13, 0x53, 0xf7, 0x32, + 0x6e, 0x27, 0xdd, 0xee, 0xd6, 0x9d, 0x81, 0xd0, 0x47, 0x9f, 0x7d, 0xf1, 0xb7, 0xf8, 0x2b, 0x78, + 0xe4, 0x51, 0x13, 0xa3, 0x06, 0xfe, 0x88, 0xd9, 0xd9, 0xd9, 0xe9, 0x05, 0x0b, 0xe5, 0x81, 0xa7, + 0x76, 0xce, 0x9c, 0x6f, 0xbe, 0xf3, 0x9d, 0xcb, 0xcc, 0xc2, 0x5d, 0x27, 0xa4, 0xad, 0x90, 0x1a, + 0xb6, 0x45, 0xb1, 0x41, 0x71, 0x74, 0x88, 0x23, 0xe3, 0x70, 0xd3, 0xc6, 0xcc, 0xda, 0x14, 0x4b, + 0xbd, 0x1d, 0x85, 0x2c, 0x44, 0xa5, 0xc4, 0x51, 0x8f, 0x1d, 0x75, 0xb1, 0x23, 0x1c, 0x4b, 0x0b, + 0x5e, 0xe8, 0x85, 0xdc, 0xcd, 0x88, 0xff, 0x25, 0x88, 0xd2, 0x5a, 0xdf, 0xd1, 0x2c, 0x8c, 0xb0, + 0x3c, 0xd9, 0x27, 0x94, 0xe1, 0x80, 0x04, 0x9e, 0x70, 0x5d, 0x62, 0x38, 0x70, 0x71, 0xd4, 0x22, + 0x01, 0x33, 0x2c, 0xdb, 0x21, 0x06, 0xeb, 0xb4, 0x31, 0x4d, 0x36, 0xb5, 0xaf, 0x0a, 0x4c, 0xef, + 0xb3, 0x08, 0x5b, 0x2d, 0x13, 0x7f, 0x3e, 0xc0, 0x94, 0xa1, 0x65, 0x28, 0xd8, 0xd8, 0x23, 0x41, + 0xdd, 0xf6, 0x43, 0xa7, 0x59, 0x54, 0x2a, 0xca, 0x6a, 0xce, 0x04, 0x6e, 0xaa, 0xc5, 0x16, 0x74, + 0x0b, 0xc0, 0xc5, 0x3e, 0x39, 0xc4, 0x51, 0x9d, 0x1d, 0x15, 0xc7, 0xf8, 0x7e, 0x5e, 0x58, 0xde, + 0x1c, 0xa1, 0x25, 0xc8, 0xe3, 0xc0, 0x15, 0x68, 0x95, 0xef, 0xe6, 0x70, 0xe0, 0x4a, 0x2c, 0x0f, + 0xb6, 0xde, 0xc4, 0x1d, 0x5a, 0xcc, 0x56, 0xd4, 0xd5, 0xbc, 0x99, 0xe7, 0x96, 0x5d, 0xdc, 0xa1, + 0xda, 0x3a, 0xcc, 0xd7, 0x24, 0x51, 0x1a, 0xd0, 0x22, 0x4c, 0x34, 0x30, 0xf1, 0x1a, 0x8c, 0xc7, + 0xa2, 0x9a, 0x62, 0xa5, 0x3d, 0x87, 0xb9, 0xed, 0x94, 0xf5, 0x12, 0x5f, 0xb4, 0x00, 0xe3, 0x24, + 0x70, 0x71, 0x12, 0xae, 0x6a, 0x26, 0x0b, 0x6d, 0x0d, 0x66, 0x5f, 0x89, 0xc8, 0x2e, 0x23, 0xfb, + 0xa2, 0xc2, 0x4c, 0x9a, 0x27, 0xda, 0x0e, 0x03, 0x8a, 0xd1, 0x4d, 0xc8, 0x39, 0x0d, 0x8b, 0x04, + 0x75, 0xe2, 0x72, 0xe7, 0xbc, 0x39, 0xc9, 0xd7, 0xaf, 0xdd, 0x9e, 0x53, 0xc6, 0xfa, 0xc2, 0x70, + 0xe0, 0x46, 0x4f, 0x6e, 0xeb, 0x6d, 0xab, 0xe3, 0x87, 0x96, 0xcb, 0xb3, 0x54, 0xa8, 0x6e, 0xe8, + 0xc3, 0xbb, 0x40, 0xef, 0xa6, 0x65, 0x2f, 0x01, 0xd5, 0xb2, 0xc7, 0xbf, 0x97, 0x15, 0x73, 0xde, + 0x1e, 0xdc, 0x40, 0x1f, 0x01, 0x75, 0xeb, 0x23, 0x39, 0xb2, 0x9c, 0xe3, 0xfe, 0x45, 0x1c, 0x32, + 0x9b, 0xfd, 0x14, 0x73, 0xee, 0x80, 0x1d, 0x7d, 0x80, 0x79, 0x59, 0x62, 0x49, 0x30, 0xce, 0x09, + 0xd6, 0x2f, 0x22, 0x48, 0x93, 0xdd, 0x7f, 0xfe, 0x2c, 0xee, 0x37, 0xa3, 0x45, 0x50, 0x71, 0x14, + 0x15, 0x27, 0xe2, 0x9c, 0x0a, 0x9f, 0xd8, 0xa0, 0xfd, 0x51, 0x7a, 0xdb, 0x23, 0xf5, 0x7e, 0x02, + 0x93, 0x51, 0x52, 0x3c, 0x5e, 0x85, 0x42, 0x55, 0xd3, 0xbb, 0x0d, 0xaf, 0xc7, 0x0d, 0xaf, 0x8b, + 0xe2, 0xf6, 0xb4, 0x56, 0x0a, 0x41, 0x5b, 0x90, 0x8b, 0x44, 0x41, 0x79, 0xad, 0x0a, 0xd5, 0xdb, + 0xff, 0x81, 0x27, 0x0e, 0x3d, 0x78, 0x09, 0x42, 0xbb, 0x30, 0x4d, 0x99, 0xc5, 0x70, 0xdd, 0x69, + 0x58, 0x81, 0x87, 0x69, 0x51, 0xad, 0xa8, 0xab, 0x85, 0xea, 0x9d, 0xfe, 0x3c, 0xc4, 0x1d, 0x2e, + 0xd3, 0xb0, 0xcf, 0xfb, 0xfd, 0xed, 0x9e, 0x45, 0x22, 0x73, 0x8a, 0x83, 0x5f, 0x26, 0x58, 0xed, + 0x97, 0xd2, 0xd3, 0xd3, 0xa9, 0xc0, 0xc7, 0x83, 0x02, 0x57, 0x86, 0x09, 0xec, 0x8e, 0x83, 0xd4, + 0xf7, 0xec, 0x9c, 0x3e, 0x6d, 0xa8, 0xbe, 0x2e, 0xfc, 0x9a, 0xe4, 0xfd, 0x54, 0xba, 0x03, 0x97, + 0xaa, 0x7b, 0x34, 0xa8, 0xae, 0x32, 0x4c, 0x9d, 0x1c, 0x55, 0x29, 0xee, 0xe9, 0x39, 0x71, 0x2b, + 0x43, 0xc5, 0x49, 0xf4, 0xf5, 0x68, 0xab, 0x7e, 0xcf, 0x42, 0x7e, 0x3f, 0x36, 0xec, 0x10, 0x1f, + 0xa3, 0x08, 0xe6, 0xba, 0xdd, 0xb2, 0x6d, 0x31, 0xeb, 0x05, 0x43, 0x23, 0xce, 0xb7, 0x50, 0x5b, + 0xba, 0xda, 0x75, 0xa0, 0x65, 0x50, 0x08, 0xb3, 0xb2, 0x82, 0x82, 0x72, 0xb4, 0x71, 0x4f, 0x19, + 0xaf, 0x74, 0x39, 0x68, 0x19, 0xe4, 0xc3, 0x4c, 0x9a, 0x55, 0xc1, 0x37, 0xd2, 0xf4, 0xa7, 0x74, + 0x57, 0xb9, 0x2a, 0xb4, 0x0c, 0xf2, 0x00, 0x92, 0x0b, 0x38, 0xe6, 0x42, 0x6b, 0x17, 0x81, 0xfb, + 0x1e, 0xb4, 0xd2, 0xbd, 0x51, 0x5c, 0x93, 0x96, 0xd0, 0x32, 0x0f, 0x14, 0x44, 0x60, 0xaa, 0x66, + 0x39, 0xcd, 0x1d, 0xe2, 0xfb, 0xd7, 0x4c, 0x55, 0x7b, 0x77, 0x7c, 0x5a, 0x56, 0x4e, 0x4e, 0xcb, + 0xca, 0xdf, 0xd3, 0xb2, 0xf2, 0xed, 0xac, 0x9c, 0x39, 0x39, 0x2b, 0x67, 0x7e, 0x9c, 0x95, 0x33, + 0xef, 0xb7, 0x3c, 0xc2, 0x1a, 0x07, 0xb6, 0xee, 0x84, 0x2d, 0x43, 0x3c, 0xf5, 0xc9, 0xcf, 0x06, + 0x75, 0x9b, 0xe2, 0xc1, 0xa7, 0xfc, 0x40, 0x12, 0x78, 0xc6, 0x27, 0xe2, 0x0f, 0x7c, 0x60, 0xd8, + 0x13, 0xfc, 0x7d, 0x7f, 0xf8, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x3d, 0xaf, 0x68, 0x35, 0x84, 0x08, + 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -966,6 +975,11 @@ func (m *DeliverTxRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.Index != 0 { + i = encodeVarintServer(dAtA, i, uint64(m.Index)) + i-- + dAtA[i] = 0x10 + } if m.Height != 0 { i = encodeVarintServer(dAtA, i, uint64(m.Height)) i-- @@ -1319,6 +1333,9 @@ func (m *DeliverTxRequest) Size() (n int) { if m.Height != 0 { n += 1 + sovServer(uint64(m.Height)) } + if m.Index != 0 { + n += 1 + sovServer(uint64(m.Index)) + } return n } @@ -1700,6 +1717,25 @@ func (m *DeliverTxRequest) Unmarshal(dAtA []byte) error { break } } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) + } + m.Index = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Index |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipServer(dAtA[iNdEx:]) From ee2ac55aad580a31d54cc0d203f0035c567ddc68 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 6 Jul 2021 15:27:48 -0500 Subject: [PATCH 38/46] begin cmd and context --- store/streaming/file/server/context.go | 242 +++++++++++++++++ store/streaming/file/server/start.go | 347 +++++++++++++++++++++++++ 2 files changed, 589 insertions(+) create mode 100644 store/streaming/file/server/context.go create mode 100644 store/streaming/file/server/start.go diff --git a/store/streaming/file/server/context.go b/store/streaming/file/server/context.go new file mode 100644 index 000000000000..0637cb885cb8 --- /dev/null +++ b/store/streaming/file/server/context.go @@ -0,0 +1,242 @@ +package server + +import ( + "errors" + "fmt" + tmcfg "github.com/tendermint/tendermint/config" + "io" + "os" + "os/signal" + "path" + "path/filepath" + "strconv" + "strings" + "syscall" + + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + "github.com/spf13/viper" + tmlog "github.com/tendermint/tendermint/libs/log" + + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/server" + "github.com/cosmos/cosmos-sdk/store/streaming/file/server/config" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// DONTCOVER + +// ServerContextKey defines the context key used to retrieve a server.Context from +// a command's Context. +const ServerContextKey = sdk.ContextKey("server.context") + +// server context +type Context struct { + Viper *viper.Viper + Config *config.StateServerConfig + Logger tmlog.Logger +} + +// ErrorCode contains the exit code for server exit. +type ErrorCode struct { + Code int +} + +func (e ErrorCode) Error() string { + return strconv.Itoa(e.Code) +} + +func NewDefaultContext() *Context { + return NewContext( + viper.New(), + config.DefaultStateServerConfig(), + server.ZeroLogWrapper{Logger: log.Logger}, + ) +} + +func NewContext(v *viper.Viper, cfg *config.StateServerConfig, logger tmlog.Logger) *Context { + return &Context{v, cfg,logger} +} + +func bindFlags(basename string, cmd *cobra.Command, v *viper.Viper) (err error) { + defer func() { + recover() + }() + + cmd.Flags().VisitAll(func(f *pflag.Flag) { + // Environment variables can't have dashes in them, so bind them to their equivalent + // keys with underscores, e.g. --favorite-color to STING_FAVORITE_COLOR + err = v.BindEnv(f.Name, fmt.Sprintf("%s_%s", basename, strings.ToUpper(strings.ReplaceAll(f.Name, "-", "_")))) + if err != nil { + panic(err) + } + + err = v.BindPFlag(f.Name, f) + if err != nil { + panic(err) + } + + // Apply the viper config value to the flag when the flag is not set and viper has a value + if !f.Changed && v.IsSet(f.Name) { + val := v.Get(f.Name) + err = cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val)) + if err != nil { + panic(err) + } + } + }) + + return +} + +// InterceptConfigsPreRunHandler performs a pre-run function for the root daemon +// application command. It will create a Viper literal and a default server +// Context. The server Tendermint configuration will either be read and parsed +// or created and saved to disk, where the server Context is updated to reflect +// the Tendermint configuration. The Viper literal is used to read and parse +// the application configuration. Command handlers can fetch the server Context +// to get the Tendermint configuration or to get access to Viper. +func InterceptConfigsPreRunHandler(cmd *cobra.Command) error { + serverCtx := NewDefaultContext() + + // Get the executable name and configure the viper instance so that environmental + // variables are checked based off that name. The underscore character is used + // as a separator + executableName, err := os.Executable() + if err != nil { + return err + } + + basename := path.Base(executableName) + + // Configure the viper instance + serverCtx.Viper.BindPFlags(cmd.Flags()) + serverCtx.Viper.BindPFlags(cmd.PersistentFlags()) + serverCtx.Viper.SetEnvPrefix(basename) + serverCtx.Viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) + serverCtx.Viper.AutomaticEnv() + + // intercept configuration files, using both Viper instances separately + config, err := interceptConfigs(serverCtx.Viper) + if err != nil { + return err + } + + // return value is a tendermint configuration object + serverCtx.Config = config + if err = bindFlags(basename, cmd, serverCtx.Viper); err != nil { + return err + } + + var logWriter io.Writer + if strings.ToLower(serverCtx.Viper.GetString(flags.FlagLogFormat)) == tmcfg.LogFormatPlain { + logWriter = zerolog.ConsoleWriter{Out: os.Stderr} + } else { + logWriter = os.Stderr + } + + logLvlStr := serverCtx.Viper.GetString(flags.FlagLogLevel) + logLvl, err := zerolog.ParseLevel(logLvlStr) + if err != nil { + return fmt.Errorf("failed to parse log level (%s): %w", logLvlStr, err) + } + + serverCtx.Logger = server.ZeroLogWrapper{Logger: zerolog.New(logWriter).Level(logLvl).With().Timestamp().Logger()} + + return SetCmdServerContext(cmd, serverCtx) +} + +// GetServerContextFromCmd returns a Context from a command or an empty Context +// if it has not been set. +func GetServerContextFromCmd(cmd *cobra.Command) *Context { + if v := cmd.Context().Value(ServerContextKey); v != nil { + serverCtxPtr := v.(*Context) + return serverCtxPtr + } + + return NewDefaultContext() +} + +// SetCmdServerContext sets a command's Context value to the provided argument. +func SetCmdServerContext(cmd *cobra.Command, serverCtx *Context) error { + v := cmd.Context().Value(ServerContextKey) + if v == nil { + return errors.New("server context not set") + } + + serverCtxPtr := v.(*Context) + *serverCtxPtr = *serverCtx + + return nil +} + +// interceptConfigs parses and updates a state change file server configuration file or +// creates a new one and saves it. The state change file server configuration file is parsed given a root Viper object +func interceptConfigs(rootViper *viper.Viper) (*config.StateServerConfig, error) { + rootDir := rootViper.GetString(flags.FlagHome) + configPath := filepath.Join(rootDir, "config") + cfgFile := filepath.Join(configPath, "file_server.toml") + + serverCfg := config.DefaultStateServerConfig() + + switch _, err := os.Stat(cfgFile); { + case os.IsNotExist(err): + tmcfg.EnsureRoot(rootDir) + config.WriteConfigFile(cfgFile, serverCfg) + + case err != nil: + return nil, err + + default: + rootViper.SetConfigType("toml") + rootViper.SetConfigName("file_server") + rootViper.AddConfigPath(configPath) + + if err := rootViper.ReadInConfig(); err != nil { + return nil, fmt.Errorf("failed to read in %s: %w", cfgFile, err) + } + } + + // Read into the configuration whatever data the viper instance has for it. + // This may come from the configuration file above but also any of the other + // sources viper uses. + if err := rootViper.Unmarshal(serverCfg); err != nil { + return nil, err + } + + return serverCfg, nil +} + +// TrapSignal traps SIGINT and SIGTERM and terminates the server correctly. +func TrapSignal(cleanupFunc func()) { + sigs := make(chan os.Signal, 1) + signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) + + go func() { + sig := <-sigs + + if cleanupFunc != nil { + cleanupFunc() + } + exitCode := 128 + + switch sig { + case syscall.SIGINT: + exitCode += int(syscall.SIGINT) + case syscall.SIGTERM: + exitCode += int(syscall.SIGTERM) + } + + os.Exit(exitCode) + }() +} + +// WaitForQuitSignals waits for SIGINT and SIGTERM and returns. +func WaitForQuitSignals() ErrorCode { + sigs := make(chan os.Signal, 1) + signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) + sig := <-sigs + return ErrorCode{Code: int(sig.(syscall.Signal)) + 128} +} diff --git a/store/streaming/file/server/start.go b/store/streaming/file/server/start.go new file mode 100644 index 000000000000..34696456b729 --- /dev/null +++ b/store/streaming/file/server/start.go @@ -0,0 +1,347 @@ +package server + +// DONTCOVER + +import ( + "fmt" + "net/http" + "os" + "runtime/pprof" + "time" + + "github.com/cosmos/cosmos-sdk/codec" + + "github.com/spf13/cobra" + "google.golang.org/grpc" + + "github.com/tendermint/tendermint/abci/server" + tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" + tmos "github.com/tendermint/tendermint/libs/os" + "github.com/tendermint/tendermint/node" + "github.com/tendermint/tendermint/p2p" + pvm "github.com/tendermint/tendermint/privval" + "github.com/tendermint/tendermint/proxy" + "github.com/tendermint/tendermint/rpc/client/local" + + "github.com/cosmos/cosmos-sdk/server/rosetta" + crgserver "github.com/cosmos/cosmos-sdk/server/rosetta/lib/server" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/server/api" + "github.com/cosmos/cosmos-sdk/server/config" + servergrpc "github.com/cosmos/cosmos-sdk/server/grpc" + "github.com/cosmos/cosmos-sdk/server/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" +) + +const ( + flagRemoveAfter = "file-server.remove-after" + flagFilePrefix = "file-server.file-prefix" + flagReadDir = "file-server.read-dir" + flagChainID = "file-server.chain-id" + flagGRPCAddress = "file-server.grpc.address" + flagGRPCWebEnable = "file-server.grpc-web.enable" + flagGRPCWebAddress = "file-server.grpc-web.address" +) + +// StartCmd runs the service passed in, either stand-alone or in-process with +// Tendermint. +func StartCmd(appCreator types.AppCreator, defaultNodeHome string) *cobra.Command { + cmd := &cobra.Command{ + Use: "start", + Short: "Run the state change file server", + Long: ``, + PreRunE: func(cmd *cobra.Command, _ []string) error { + serverCtx := GetServerContextFromCmd(cmd) + + // Bind flags to the Context's Viper so the app construction can set + // options accordingly. + serverCtx.Viper.BindPFlags(cmd.Flags()) + + _, err := GetPruningOptionsFromFlags(serverCtx.Viper) + return err + }, + RunE: func(cmd *cobra.Command, _ []string) error { + serverCtx := GetServerContextFromCmd(cmd) + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + withTM, _ := cmd.Flags().GetBool(flagWithTendermint) + if !withTM { + serverCtx.Logger.Info("starting ABCI without Tendermint") + return startStandAlone(serverCtx, appCreator) + } + + serverCtx.Logger.Info("starting ABCI with Tendermint") + + // amino is needed here for backwards compatibility of REST routes + err = startInProcess(serverCtx, clientCtx, appCreator) + errCode, ok := err.(ErrorCode) + if !ok { + return err + } + + serverCtx.Logger.Debug(fmt.Sprintf("received quit signal: %d", errCode.Code)) + return nil + }, + } + + cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory") + cmd.Flags().Bool(flagWithTendermint, true, "Run abci app embedded in-process with tendermint") + cmd.Flags().String(flagAddress, "tcp://0.0.0.0:26658", "Listen address") + cmd.Flags().String(flagTransport, "socket", "Transport protocol: socket, grpc") + cmd.Flags().String(flagTraceStore, "", "Enable KVStore tracing to an output file") + cmd.Flags().String(FlagMinGasPrices, "", "Minimum gas prices to accept for transactions; Any fee in a tx must meet this minimum (e.g. 0.01photino;0.0001stake)") + cmd.Flags().IntSlice(FlagUnsafeSkipUpgrades, []int{}, "Skip a set of upgrade heights to continue the old binary") + cmd.Flags().Uint64(FlagHaltHeight, 0, "Block height at which to gracefully halt the chain and shutdown the node") + cmd.Flags().Uint64(FlagHaltTime, 0, "Minimum block time (in Unix seconds) at which to gracefully halt the chain and shutdown the node") + cmd.Flags().Bool(FlagInterBlockCache, true, "Enable inter-block caching") + cmd.Flags().String(flagCPUProfile, "", "Enable CPU profiling and write to the provided file") + cmd.Flags().Bool(FlagTrace, false, "Provide full stack traces for errors in ABCI Log") + cmd.Flags().String(FlagPruning, storetypes.PruningOptionDefault, "Pruning strategy (default|nothing|everything|custom)") + cmd.Flags().Uint64(FlagPruningKeepRecent, 0, "Number of recent heights to keep on disk (ignored if pruning is not 'custom')") + cmd.Flags().Uint64(FlagPruningKeepEvery, 0, "Offset heights to keep on disk after 'keep-every' (ignored if pruning is not 'custom')") + cmd.Flags().Uint64(FlagPruningInterval, 0, "Height interval at which pruned heights are removed from disk (ignored if pruning is not 'custom')") + cmd.Flags().Uint(FlagInvCheckPeriod, 0, "Assert registered invariants every N blocks") + cmd.Flags().Uint64(FlagMinRetainBlocks, 0, "Minimum block height offset during ABCI commit to prune Tendermint blocks") + + cmd.Flags().Bool(flagGRPCEnable, true, "Define if the gRPC server should be enabled") + cmd.Flags().String(flagGRPCAddress, config.DefaultGRPCAddress, "the gRPC server address to listen on") + + cmd.Flags().Bool(flagGRPCWebEnable, true, "Define if the gRPC-Web server should be enabled. (Note: gRPC must also be enabled.)") + cmd.Flags().String(flagGRPCWebAddress, config.DefaultGRPCWebAddress, "The gRPC-Web server address to listen on") + + cmd.Flags().Uint64(FlagStateSyncSnapshotInterval, 0, "State sync snapshot interval") + cmd.Flags().Uint32(FlagStateSyncSnapshotKeepRecent, 2, "State sync snapshot to keep") + + // add support for all Tendermint-specific command line options + tcmd.AddNodeFlags(cmd) + return cmd +} + +func startStandAlone(ctx *Context, appCreator types.AppCreator) error { + addr := ctx.Viper.GetString(flagAddress) + transport := ctx.Viper.GetString(flagTransport) + home := ctx.Viper.GetString(flags.FlagHome) + + db, err := openDB(home) + if err != nil { + return err + } + + traceWriterFile := ctx.Viper.GetString(flagTraceStore) + traceWriter, err := openTraceWriter(traceWriterFile) + if err != nil { + return err + } + + app := appCreator(ctx.Logger, db, traceWriter, ctx.Viper) + + svr, err := server.NewServer(addr, transport, app) + if err != nil { + return fmt.Errorf("error creating listener: %v", err) + } + + svr.SetLogger(ctx.Logger.With("module", "abci-server")) + + err = svr.Start() + if err != nil { + tmos.Exit(err.Error()) + } + + defer func() { + if err = svr.Stop(); err != nil { + tmos.Exit(err.Error()) + } + }() + + // Wait for SIGINT or SIGTERM signal + return WaitForQuitSignals() +} + +// legacyAminoCdc is used for the legacy REST API +func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.AppCreator) error { + cfg := ctx.Config + home := cfg.RootDir + var cpuProfileCleanup func() + + if cpuProfile := ctx.Viper.GetString(flagCPUProfile); cpuProfile != "" { + f, err := os.Create(cpuProfile) + if err != nil { + return err + } + + ctx.Logger.Info("starting CPU profiler", "profile", cpuProfile) + if err := pprof.StartCPUProfile(f); err != nil { + return err + } + + cpuProfileCleanup = func() { + ctx.Logger.Info("stopping CPU profiler", "profile", cpuProfile) + pprof.StopCPUProfile() + f.Close() + } + } + + traceWriterFile := ctx.Viper.GetString(flagTraceStore) + db, err := openDB(home) + if err != nil { + return err + } + + traceWriter, err := openTraceWriter(traceWriterFile) + if err != nil { + return err + } + + app := appCreator(ctx.Logger, db, traceWriter, ctx.Viper) + + nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile()) + if err != nil { + return err + } + + genDocProvider := node.DefaultGenesisDocProviderFunc(cfg) + tmNode, err := node.NewNode( + cfg, + pvm.LoadOrGenFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile()), + nodeKey, + proxy.NewLocalClientCreator(app), + genDocProvider, + node.DefaultDBProvider, + node.DefaultMetricsProvider(cfg.Instrumentation), + ctx.Logger, + ) + if err != nil { + return err + } + + ctx.Logger.Debug("initialization: tmNode created") + if err := tmNode.Start(); err != nil { + return err + } + ctx.Logger.Debug("initialization: tmNode started") + + config := config.GetConfig(ctx.Viper) + + // Add the tx service to the gRPC router. We only need to register this + // service if API or gRPC is enabled, and avoid doing so in the general + // case, because it spawns a new local tendermint RPC client. + if config.API.Enable || config.GRPC.Enable { + clientCtx = clientCtx.WithClient(local.New(tmNode)) + + app.RegisterTxService(clientCtx) + app.RegisterTendermintService(clientCtx) + } + + var apiSrv *api.Server + if config.API.Enable { + genDoc, err := genDocProvider() + if err != nil { + return err + } + + clientCtx := clientCtx. + WithHomeDir(home). + WithChainID(genDoc.ChainID) + + apiSrv = api.New(clientCtx, ctx.Logger.With("module", "api-server")) + app.RegisterAPIRoutes(apiSrv, config.API) + errCh := make(chan error) + + go func() { + if err := apiSrv.Start(config); err != nil { + errCh <- err + } + }() + + select { + case err := <-errCh: + return err + case <-time.After(5 * time.Second): // assume server started successfully + } + } + + var ( + grpcSrv *grpc.Server + grpcWebSrv *http.Server + ) + if config.GRPC.Enable { + grpcSrv, err = servergrpc.StartGRPCServer(clientCtx, app, config.GRPC.Address) + if err != nil { + return err + } + if config.GRPCWeb.Enable { + grpcWebSrv, err = servergrpc.StartGRPCWeb(grpcSrv, config) + if err != nil { + ctx.Logger.Error("failed to start grpc-web http server: ", err) + return err + } + } + } + + var rosettaSrv crgserver.Server + if config.Rosetta.Enable { + offlineMode := config.Rosetta.Offline + if !config.GRPC.Enable { // If GRPC is not enabled rosetta cannot work in online mode, so it works in offline mode. + offlineMode = true + } + + conf := &rosetta.Config{ + Blockchain: config.Rosetta.Blockchain, + Network: config.Rosetta.Network, + TendermintRPC: ctx.Config.RPC.ListenAddress, + GRPCEndpoint: config.GRPC.Address, + Addr: config.Rosetta.Address, + Retries: config.Rosetta.Retries, + Offline: offlineMode, + } + conf.WithCodec(clientCtx.InterfaceRegistry, clientCtx.JSONCodec.(*codec.ProtoCodec)) + + rosettaSrv, err = rosetta.ServerFromConfig(conf) + if err != nil { + return err + } + errCh := make(chan error) + go func() { + if err := rosettaSrv.Start(); err != nil { + errCh <- err + } + }() + + select { + case err := <-errCh: + return err + case <-time.After(5 * time.Second): // assume server started successfully + } + } + + defer func() { + if tmNode.IsRunning() { + _ = tmNode.Stop() + } + + if cpuProfileCleanup != nil { + cpuProfileCleanup() + } + + if apiSrv != nil { + _ = apiSrv.Close() + } + + if grpcSrv != nil { + grpcSrv.Stop() + if grpcWebSrv != nil { + grpcWebSrv.Close() + } + } + + ctx.Logger.Info("exiting...") + }() + + // Wait for SIGINT or SIGTERM signal + return WaitForQuitSignals() +} \ No newline at end of file From f62ec6f7897119459f60917ae0ba0df9ff9d3222 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Wed, 7 Jul 2021 12:18:47 -0500 Subject: [PATCH 39/46] cmd and main.go --- store/streaming/file/server/cmd/root.go | 136 +++++++++ store/streaming/file/server/cmd/serve.go | 112 ++++++++ store/streaming/file/server/context.go | 242 ---------------- store/streaming/file/server/main.go | 12 + store/streaming/file/server/start.go | 347 ----------------------- 5 files changed, 260 insertions(+), 589 deletions(-) create mode 100644 store/streaming/file/server/cmd/root.go create mode 100644 store/streaming/file/server/cmd/serve.go delete mode 100644 store/streaming/file/server/context.go create mode 100644 store/streaming/file/server/main.go delete mode 100644 store/streaming/file/server/start.go diff --git a/store/streaming/file/server/cmd/root.go b/store/streaming/file/server/cmd/root.go new file mode 100644 index 000000000000..3f3d57d03f0a --- /dev/null +++ b/store/streaming/file/server/cmd/root.go @@ -0,0 +1,136 @@ +package cmd + +import ( + "fmt" + "os" + "path/filepath" + "strings" + + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" + "github.com/spf13/cobra" + "github.com/spf13/viper" + + "github.com/cosmos/cosmos-sdk/codec" + codecTypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/store/streaming/file/server/config" +) + +const ( + cliFlagConfigFile = "config-file" + cliFlagLogFile = "log-file" + cliFlagLogLevel = "log-level" + + tomlFlagLogFile = "file-server.log-file" + tomlFlagLogLevel = "file-server.log-level" +) + +var ( + configPath string + serverCfg *config.StateServerConfig + interfaceRegistry = codecTypes.NewInterfaceRegistry() + marshaller = codec.NewProtoCodec(interfaceRegistry) +) + +var rootCmd = &cobra.Command{ + Use: "file-server", + PersistentPreRun: initFuncs, +} + +func Execute() { + log.Print("----- Starting Cosmos state change file server -----") + if err := rootCmd.Execute(); err != nil { + log.Fatal().Err(err) + } +} + +func init() { + cobra.OnInitialize(initConfig) + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) + viper.AutomaticEnv() + + rootCmd.PersistentFlags().StringVar(&configPath, cliFlagConfigFile, "", "path to file server config file") + + // cli flags for all config variables + rootCmd.PersistentFlags().String(cliFlagLogFile, "", "File for writing log messages to") + rootCmd.PersistentFlags().String(cliFlagLogLevel, "", "Log level: log messages above this level will be logged") + + // and their toml bindings + viper.BindPFlag(tomlFlagLogFile, rootCmd.PersistentFlags().Lookup(cliFlagLogFile)) + viper.BindPFlag(tomlFlagLogLevel, rootCmd.PersistentFlags().Lookup(cliFlagLogLevel)) +} + +func initFuncs(cmd *cobra.Command, args []string) { + logfilePath := viper.GetString(tomlFlagLogFile) + if logfilePath != "" { + file, err := os.OpenFile(logfilePath, + os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) + if err == nil { + log.Info().Str("logfile", logfilePath) + log.Output(file) + } else { + log.Output(os.Stdout) + log.Print("Failed to log to file, using default stdout") + } + } else { + log.Output(os.Stdout) + } + logLevel() +} + +func initConfig() { + serverCfg = config.DefaultStateServerConfig() + if configPath != "" { + switch _, err := os.Stat(configPath); { + case os.IsNotExist(err): + log.Warn().Msgf("No config file found at %s, using default configuration", configPath) + config.WriteConfigFile(configPath, serverCfg) + + case err != nil: + log.Fatal().AnErr("Config file is specified but could not be loaded", err) + + default: + _, fileName := filepath.Split(configPath) + viper.SetConfigType("toml") + viper.SetConfigName(fileName) + viper.SetConfigFile(configPath) + + if err := viper.ReadInConfig(); err != nil { + log.Fatal().AnErr(fmt.Sprintf("failed to read in config file '%s'", fileName), err) + } + } + } else { + log.Warn().Msg("No config file passed with --config flag, using default configuration") + config.WriteConfigFile(configPath, serverCfg) + } + if err := viper.Unmarshal(serverCfg); err != nil { + log.Fatal().Err(err) + } +} + +func logLevel() { + lvl := parseLevel(viper.GetString(tomlFlagLogLevel)) + zerolog.SetGlobalLevel(lvl) + log.Printf("Log level set to ", lvl.String()) +} + +func parseLevel(lvlString string) zerolog.Level { + switch strings.ToLower(lvlString) { + case "panic", "p", "5": + return zerolog.PanicLevel + case "fatal", "f", "4": + return zerolog.FatalLevel + case "error", "err", "e", "3": + return zerolog.ErrorLevel + case "warn", "w", "2": + return zerolog.WarnLevel + case "info", "i", "1": + return zerolog.InfoLevel + case "debug", "d", "0": + return zerolog.DebugLevel + case "trace", "t", "-1": + return zerolog.TraceLevel + default: + return zerolog.Disabled + } +} diff --git a/store/streaming/file/server/cmd/serve.go b/store/streaming/file/server/cmd/serve.go new file mode 100644 index 000000000000..cac3205a5ee4 --- /dev/null +++ b/store/streaming/file/server/cmd/serve.go @@ -0,0 +1,112 @@ +package cmd + +import ( + "net/http" + "os" + "os/signal" + "syscall" + + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" + "github.com/spf13/cobra" + "github.com/spf13/viper" + + "github.com/cosmos/cosmos-sdk/server" + "github.com/cosmos/cosmos-sdk/store/streaming/file" + "github.com/cosmos/cosmos-sdk/store/streaming/file/server/config" + servergrpc "github.com/cosmos/cosmos-sdk/store/streaming/file/server/grpc" +) + +const ( + tomlFlagRemoveAfter = "file-server.remove-after" + tomlFlagFilePrefix = "file-server.file-prefix" + tomlFlagReadDir = "file-server.read-dir" + tomlFlagChainID = "file-server.chain-id" + tomlFlagGRPCAddress = "file-server.grpc-address" + tomlFlagGRPCWebEnable = "file-server.grpc-web-enable" + tomlFlagGRPCWebAddress = "file-server.grpc-web-address" + + cliFlagRemoveAfter = "remove-after" + cliFlagFilePrefix = "file-prefix" + cliFlagReadDir = "read-dir" + cliFlagChainID = "chain-id" + cliFlagGRPCAddress = "grpc-address" + cliFlagGRPCWebEnable = "grpc-web-enable" + cliFlagGRPCWebAddress = "grpc-web-address" +) + +var ( + subLogger zerolog.Logger +) + +// grpcCmd represents the serve command +var grpcCmd = &cobra.Command{ + Use: "grpc", + Short: "serve state change data over gRPC", + Long: `This command configures a gRPC server to serve data +from state change files. + +`, + Run: func(cmd *cobra.Command, args []string) { + subLogger = log.With().Str("subcommand", cmd.CalledAs()).Logger() + serve() + }, +} + +func serve() { + subLogger.Print("starting file server") + handler, err := servergrpc.NewHandler(serverCfg, marshaller, server.ZeroLogWrapper{Logger: subLogger}) + if err != nil { + subLogger.Fatal().AnErr("Failed to create a new file server gRPC handler", err) + } + grpcSrv, err := servergrpc.StartGRPCServer(handler, serverCfg.GRPCAddress) + if err != nil { + subLogger.Fatal().AnErr("Failed to start gRPC server", err) + } + var grpcWebSrv *http.Server + if serverCfg.GRPCWebEnabled { + grpcWebSrv, err = servergrpc.StartGRPCWeb(grpcSrv, serverCfg.GRPCWebAddress) + if err != nil { + subLogger.Fatal().AnErr("Failed to start gRPC web server", err) + } + } + + defer func() { + handler.Stop() + grpcSrv.Stop() + if grpcWebSrv != nil { + grpcWebSrv.Close() + } + subLogger.Info().Msg("exiting...") + }() + + // wait for quit signals + sigs := make(chan os.Signal, 1) + signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) + sig := <-sigs + subLogger.Info().Msgf("received %d signal, quiting file-server", int(sig.(syscall.Signal))+128) +} + +func init() { + rootCmd.AddCommand(grpcCmd) + + // cli flags for all config variables + grpcCmd.PersistentFlags().Bool(cliFlagRemoveAfter, false, "Remove files after reading from them") + grpcCmd.PersistentFlags().String(cliFlagFilePrefix, "", "Prefix for the files we are reading from") + grpcCmd.PersistentFlags().String(cliFlagReadDir, file.DefaultWriteDir, "Directory we are reading from") + grpcCmd.PersistentFlags().String(cliFlagChainID, "", "ChainID for the data we are reading and serving") + + grpcCmd.PersistentFlags().String(cliFlagGRPCAddress, config.DefaultGRPCAddress, "the gRPC server address to listen on") + grpcCmd.PersistentFlags().Bool(cliFlagGRPCWebEnable, true, "Define if the gRPC-Web server should be enabled.") + grpcCmd.PersistentFlags().String(cliFlagGRPCWebAddress, config.DefaultGRPCWebAddress, "The gRPC-Web server address to listen on") + + // and their toml bindings + viper.BindPFlag(tomlFlagRemoveAfter, grpcCmd.PersistentFlags().Lookup(cliFlagRemoveAfter)) + viper.BindPFlag(tomlFlagFilePrefix, grpcCmd.PersistentFlags().Lookup(cliFlagFilePrefix)) + viper.BindPFlag(tomlFlagReadDir, grpcCmd.PersistentFlags().Lookup(cliFlagReadDir)) + viper.BindPFlag(tomlFlagChainID, grpcCmd.PersistentFlags().Lookup(cliFlagChainID)) + + viper.BindPFlag(tomlFlagGRPCAddress, grpcCmd.PersistentFlags().Lookup(cliFlagGRPCAddress)) + viper.BindPFlag(tomlFlagGRPCWebEnable, grpcCmd.PersistentFlags().Lookup(cliFlagGRPCWebEnable)) + viper.BindPFlag(tomlFlagGRPCWebAddress, grpcCmd.PersistentFlags().Lookup(cliFlagGRPCWebAddress)) +} diff --git a/store/streaming/file/server/context.go b/store/streaming/file/server/context.go deleted file mode 100644 index 0637cb885cb8..000000000000 --- a/store/streaming/file/server/context.go +++ /dev/null @@ -1,242 +0,0 @@ -package server - -import ( - "errors" - "fmt" - tmcfg "github.com/tendermint/tendermint/config" - "io" - "os" - "os/signal" - "path" - "path/filepath" - "strconv" - "strings" - "syscall" - - "github.com/rs/zerolog" - "github.com/rs/zerolog/log" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/spf13/viper" - tmlog "github.com/tendermint/tendermint/libs/log" - - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/server" - "github.com/cosmos/cosmos-sdk/store/streaming/file/server/config" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// DONTCOVER - -// ServerContextKey defines the context key used to retrieve a server.Context from -// a command's Context. -const ServerContextKey = sdk.ContextKey("server.context") - -// server context -type Context struct { - Viper *viper.Viper - Config *config.StateServerConfig - Logger tmlog.Logger -} - -// ErrorCode contains the exit code for server exit. -type ErrorCode struct { - Code int -} - -func (e ErrorCode) Error() string { - return strconv.Itoa(e.Code) -} - -func NewDefaultContext() *Context { - return NewContext( - viper.New(), - config.DefaultStateServerConfig(), - server.ZeroLogWrapper{Logger: log.Logger}, - ) -} - -func NewContext(v *viper.Viper, cfg *config.StateServerConfig, logger tmlog.Logger) *Context { - return &Context{v, cfg,logger} -} - -func bindFlags(basename string, cmd *cobra.Command, v *viper.Viper) (err error) { - defer func() { - recover() - }() - - cmd.Flags().VisitAll(func(f *pflag.Flag) { - // Environment variables can't have dashes in them, so bind them to their equivalent - // keys with underscores, e.g. --favorite-color to STING_FAVORITE_COLOR - err = v.BindEnv(f.Name, fmt.Sprintf("%s_%s", basename, strings.ToUpper(strings.ReplaceAll(f.Name, "-", "_")))) - if err != nil { - panic(err) - } - - err = v.BindPFlag(f.Name, f) - if err != nil { - panic(err) - } - - // Apply the viper config value to the flag when the flag is not set and viper has a value - if !f.Changed && v.IsSet(f.Name) { - val := v.Get(f.Name) - err = cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val)) - if err != nil { - panic(err) - } - } - }) - - return -} - -// InterceptConfigsPreRunHandler performs a pre-run function for the root daemon -// application command. It will create a Viper literal and a default server -// Context. The server Tendermint configuration will either be read and parsed -// or created and saved to disk, where the server Context is updated to reflect -// the Tendermint configuration. The Viper literal is used to read and parse -// the application configuration. Command handlers can fetch the server Context -// to get the Tendermint configuration or to get access to Viper. -func InterceptConfigsPreRunHandler(cmd *cobra.Command) error { - serverCtx := NewDefaultContext() - - // Get the executable name and configure the viper instance so that environmental - // variables are checked based off that name. The underscore character is used - // as a separator - executableName, err := os.Executable() - if err != nil { - return err - } - - basename := path.Base(executableName) - - // Configure the viper instance - serverCtx.Viper.BindPFlags(cmd.Flags()) - serverCtx.Viper.BindPFlags(cmd.PersistentFlags()) - serverCtx.Viper.SetEnvPrefix(basename) - serverCtx.Viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) - serverCtx.Viper.AutomaticEnv() - - // intercept configuration files, using both Viper instances separately - config, err := interceptConfigs(serverCtx.Viper) - if err != nil { - return err - } - - // return value is a tendermint configuration object - serverCtx.Config = config - if err = bindFlags(basename, cmd, serverCtx.Viper); err != nil { - return err - } - - var logWriter io.Writer - if strings.ToLower(serverCtx.Viper.GetString(flags.FlagLogFormat)) == tmcfg.LogFormatPlain { - logWriter = zerolog.ConsoleWriter{Out: os.Stderr} - } else { - logWriter = os.Stderr - } - - logLvlStr := serverCtx.Viper.GetString(flags.FlagLogLevel) - logLvl, err := zerolog.ParseLevel(logLvlStr) - if err != nil { - return fmt.Errorf("failed to parse log level (%s): %w", logLvlStr, err) - } - - serverCtx.Logger = server.ZeroLogWrapper{Logger: zerolog.New(logWriter).Level(logLvl).With().Timestamp().Logger()} - - return SetCmdServerContext(cmd, serverCtx) -} - -// GetServerContextFromCmd returns a Context from a command or an empty Context -// if it has not been set. -func GetServerContextFromCmd(cmd *cobra.Command) *Context { - if v := cmd.Context().Value(ServerContextKey); v != nil { - serverCtxPtr := v.(*Context) - return serverCtxPtr - } - - return NewDefaultContext() -} - -// SetCmdServerContext sets a command's Context value to the provided argument. -func SetCmdServerContext(cmd *cobra.Command, serverCtx *Context) error { - v := cmd.Context().Value(ServerContextKey) - if v == nil { - return errors.New("server context not set") - } - - serverCtxPtr := v.(*Context) - *serverCtxPtr = *serverCtx - - return nil -} - -// interceptConfigs parses and updates a state change file server configuration file or -// creates a new one and saves it. The state change file server configuration file is parsed given a root Viper object -func interceptConfigs(rootViper *viper.Viper) (*config.StateServerConfig, error) { - rootDir := rootViper.GetString(flags.FlagHome) - configPath := filepath.Join(rootDir, "config") - cfgFile := filepath.Join(configPath, "file_server.toml") - - serverCfg := config.DefaultStateServerConfig() - - switch _, err := os.Stat(cfgFile); { - case os.IsNotExist(err): - tmcfg.EnsureRoot(rootDir) - config.WriteConfigFile(cfgFile, serverCfg) - - case err != nil: - return nil, err - - default: - rootViper.SetConfigType("toml") - rootViper.SetConfigName("file_server") - rootViper.AddConfigPath(configPath) - - if err := rootViper.ReadInConfig(); err != nil { - return nil, fmt.Errorf("failed to read in %s: %w", cfgFile, err) - } - } - - // Read into the configuration whatever data the viper instance has for it. - // This may come from the configuration file above but also any of the other - // sources viper uses. - if err := rootViper.Unmarshal(serverCfg); err != nil { - return nil, err - } - - return serverCfg, nil -} - -// TrapSignal traps SIGINT and SIGTERM and terminates the server correctly. -func TrapSignal(cleanupFunc func()) { - sigs := make(chan os.Signal, 1) - signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) - - go func() { - sig := <-sigs - - if cleanupFunc != nil { - cleanupFunc() - } - exitCode := 128 - - switch sig { - case syscall.SIGINT: - exitCode += int(syscall.SIGINT) - case syscall.SIGTERM: - exitCode += int(syscall.SIGTERM) - } - - os.Exit(exitCode) - }() -} - -// WaitForQuitSignals waits for SIGINT and SIGTERM and returns. -func WaitForQuitSignals() ErrorCode { - sigs := make(chan os.Signal, 1) - signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) - sig := <-sigs - return ErrorCode{Code: int(sig.(syscall.Signal)) + 128} -} diff --git a/store/streaming/file/server/main.go b/store/streaming/file/server/main.go new file mode 100644 index 000000000000..ce2382cb7280 --- /dev/null +++ b/store/streaming/file/server/main.go @@ -0,0 +1,12 @@ +package main + +import ( + "github.com/rs/zerolog" + + "github.com/cosmos/cosmos-sdk/store/streaming/file/server/cmd" +) + +func main() { + zerolog.TimeFieldFormat = zerolog.TimeFormatUnix + cmd.Execute() +} diff --git a/store/streaming/file/server/start.go b/store/streaming/file/server/start.go deleted file mode 100644 index 34696456b729..000000000000 --- a/store/streaming/file/server/start.go +++ /dev/null @@ -1,347 +0,0 @@ -package server - -// DONTCOVER - -import ( - "fmt" - "net/http" - "os" - "runtime/pprof" - "time" - - "github.com/cosmos/cosmos-sdk/codec" - - "github.com/spf13/cobra" - "google.golang.org/grpc" - - "github.com/tendermint/tendermint/abci/server" - tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" - tmos "github.com/tendermint/tendermint/libs/os" - "github.com/tendermint/tendermint/node" - "github.com/tendermint/tendermint/p2p" - pvm "github.com/tendermint/tendermint/privval" - "github.com/tendermint/tendermint/proxy" - "github.com/tendermint/tendermint/rpc/client/local" - - "github.com/cosmos/cosmos-sdk/server/rosetta" - crgserver "github.com/cosmos/cosmos-sdk/server/rosetta/lib/server" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/server/api" - "github.com/cosmos/cosmos-sdk/server/config" - servergrpc "github.com/cosmos/cosmos-sdk/server/grpc" - "github.com/cosmos/cosmos-sdk/server/types" - storetypes "github.com/cosmos/cosmos-sdk/store/types" -) - -const ( - flagRemoveAfter = "file-server.remove-after" - flagFilePrefix = "file-server.file-prefix" - flagReadDir = "file-server.read-dir" - flagChainID = "file-server.chain-id" - flagGRPCAddress = "file-server.grpc.address" - flagGRPCWebEnable = "file-server.grpc-web.enable" - flagGRPCWebAddress = "file-server.grpc-web.address" -) - -// StartCmd runs the service passed in, either stand-alone or in-process with -// Tendermint. -func StartCmd(appCreator types.AppCreator, defaultNodeHome string) *cobra.Command { - cmd := &cobra.Command{ - Use: "start", - Short: "Run the state change file server", - Long: ``, - PreRunE: func(cmd *cobra.Command, _ []string) error { - serverCtx := GetServerContextFromCmd(cmd) - - // Bind flags to the Context's Viper so the app construction can set - // options accordingly. - serverCtx.Viper.BindPFlags(cmd.Flags()) - - _, err := GetPruningOptionsFromFlags(serverCtx.Viper) - return err - }, - RunE: func(cmd *cobra.Command, _ []string) error { - serverCtx := GetServerContextFromCmd(cmd) - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - withTM, _ := cmd.Flags().GetBool(flagWithTendermint) - if !withTM { - serverCtx.Logger.Info("starting ABCI without Tendermint") - return startStandAlone(serverCtx, appCreator) - } - - serverCtx.Logger.Info("starting ABCI with Tendermint") - - // amino is needed here for backwards compatibility of REST routes - err = startInProcess(serverCtx, clientCtx, appCreator) - errCode, ok := err.(ErrorCode) - if !ok { - return err - } - - serverCtx.Logger.Debug(fmt.Sprintf("received quit signal: %d", errCode.Code)) - return nil - }, - } - - cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory") - cmd.Flags().Bool(flagWithTendermint, true, "Run abci app embedded in-process with tendermint") - cmd.Flags().String(flagAddress, "tcp://0.0.0.0:26658", "Listen address") - cmd.Flags().String(flagTransport, "socket", "Transport protocol: socket, grpc") - cmd.Flags().String(flagTraceStore, "", "Enable KVStore tracing to an output file") - cmd.Flags().String(FlagMinGasPrices, "", "Minimum gas prices to accept for transactions; Any fee in a tx must meet this minimum (e.g. 0.01photino;0.0001stake)") - cmd.Flags().IntSlice(FlagUnsafeSkipUpgrades, []int{}, "Skip a set of upgrade heights to continue the old binary") - cmd.Flags().Uint64(FlagHaltHeight, 0, "Block height at which to gracefully halt the chain and shutdown the node") - cmd.Flags().Uint64(FlagHaltTime, 0, "Minimum block time (in Unix seconds) at which to gracefully halt the chain and shutdown the node") - cmd.Flags().Bool(FlagInterBlockCache, true, "Enable inter-block caching") - cmd.Flags().String(flagCPUProfile, "", "Enable CPU profiling and write to the provided file") - cmd.Flags().Bool(FlagTrace, false, "Provide full stack traces for errors in ABCI Log") - cmd.Flags().String(FlagPruning, storetypes.PruningOptionDefault, "Pruning strategy (default|nothing|everything|custom)") - cmd.Flags().Uint64(FlagPruningKeepRecent, 0, "Number of recent heights to keep on disk (ignored if pruning is not 'custom')") - cmd.Flags().Uint64(FlagPruningKeepEvery, 0, "Offset heights to keep on disk after 'keep-every' (ignored if pruning is not 'custom')") - cmd.Flags().Uint64(FlagPruningInterval, 0, "Height interval at which pruned heights are removed from disk (ignored if pruning is not 'custom')") - cmd.Flags().Uint(FlagInvCheckPeriod, 0, "Assert registered invariants every N blocks") - cmd.Flags().Uint64(FlagMinRetainBlocks, 0, "Minimum block height offset during ABCI commit to prune Tendermint blocks") - - cmd.Flags().Bool(flagGRPCEnable, true, "Define if the gRPC server should be enabled") - cmd.Flags().String(flagGRPCAddress, config.DefaultGRPCAddress, "the gRPC server address to listen on") - - cmd.Flags().Bool(flagGRPCWebEnable, true, "Define if the gRPC-Web server should be enabled. (Note: gRPC must also be enabled.)") - cmd.Flags().String(flagGRPCWebAddress, config.DefaultGRPCWebAddress, "The gRPC-Web server address to listen on") - - cmd.Flags().Uint64(FlagStateSyncSnapshotInterval, 0, "State sync snapshot interval") - cmd.Flags().Uint32(FlagStateSyncSnapshotKeepRecent, 2, "State sync snapshot to keep") - - // add support for all Tendermint-specific command line options - tcmd.AddNodeFlags(cmd) - return cmd -} - -func startStandAlone(ctx *Context, appCreator types.AppCreator) error { - addr := ctx.Viper.GetString(flagAddress) - transport := ctx.Viper.GetString(flagTransport) - home := ctx.Viper.GetString(flags.FlagHome) - - db, err := openDB(home) - if err != nil { - return err - } - - traceWriterFile := ctx.Viper.GetString(flagTraceStore) - traceWriter, err := openTraceWriter(traceWriterFile) - if err != nil { - return err - } - - app := appCreator(ctx.Logger, db, traceWriter, ctx.Viper) - - svr, err := server.NewServer(addr, transport, app) - if err != nil { - return fmt.Errorf("error creating listener: %v", err) - } - - svr.SetLogger(ctx.Logger.With("module", "abci-server")) - - err = svr.Start() - if err != nil { - tmos.Exit(err.Error()) - } - - defer func() { - if err = svr.Stop(); err != nil { - tmos.Exit(err.Error()) - } - }() - - // Wait for SIGINT or SIGTERM signal - return WaitForQuitSignals() -} - -// legacyAminoCdc is used for the legacy REST API -func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.AppCreator) error { - cfg := ctx.Config - home := cfg.RootDir - var cpuProfileCleanup func() - - if cpuProfile := ctx.Viper.GetString(flagCPUProfile); cpuProfile != "" { - f, err := os.Create(cpuProfile) - if err != nil { - return err - } - - ctx.Logger.Info("starting CPU profiler", "profile", cpuProfile) - if err := pprof.StartCPUProfile(f); err != nil { - return err - } - - cpuProfileCleanup = func() { - ctx.Logger.Info("stopping CPU profiler", "profile", cpuProfile) - pprof.StopCPUProfile() - f.Close() - } - } - - traceWriterFile := ctx.Viper.GetString(flagTraceStore) - db, err := openDB(home) - if err != nil { - return err - } - - traceWriter, err := openTraceWriter(traceWriterFile) - if err != nil { - return err - } - - app := appCreator(ctx.Logger, db, traceWriter, ctx.Viper) - - nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile()) - if err != nil { - return err - } - - genDocProvider := node.DefaultGenesisDocProviderFunc(cfg) - tmNode, err := node.NewNode( - cfg, - pvm.LoadOrGenFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile()), - nodeKey, - proxy.NewLocalClientCreator(app), - genDocProvider, - node.DefaultDBProvider, - node.DefaultMetricsProvider(cfg.Instrumentation), - ctx.Logger, - ) - if err != nil { - return err - } - - ctx.Logger.Debug("initialization: tmNode created") - if err := tmNode.Start(); err != nil { - return err - } - ctx.Logger.Debug("initialization: tmNode started") - - config := config.GetConfig(ctx.Viper) - - // Add the tx service to the gRPC router. We only need to register this - // service if API or gRPC is enabled, and avoid doing so in the general - // case, because it spawns a new local tendermint RPC client. - if config.API.Enable || config.GRPC.Enable { - clientCtx = clientCtx.WithClient(local.New(tmNode)) - - app.RegisterTxService(clientCtx) - app.RegisterTendermintService(clientCtx) - } - - var apiSrv *api.Server - if config.API.Enable { - genDoc, err := genDocProvider() - if err != nil { - return err - } - - clientCtx := clientCtx. - WithHomeDir(home). - WithChainID(genDoc.ChainID) - - apiSrv = api.New(clientCtx, ctx.Logger.With("module", "api-server")) - app.RegisterAPIRoutes(apiSrv, config.API) - errCh := make(chan error) - - go func() { - if err := apiSrv.Start(config); err != nil { - errCh <- err - } - }() - - select { - case err := <-errCh: - return err - case <-time.After(5 * time.Second): // assume server started successfully - } - } - - var ( - grpcSrv *grpc.Server - grpcWebSrv *http.Server - ) - if config.GRPC.Enable { - grpcSrv, err = servergrpc.StartGRPCServer(clientCtx, app, config.GRPC.Address) - if err != nil { - return err - } - if config.GRPCWeb.Enable { - grpcWebSrv, err = servergrpc.StartGRPCWeb(grpcSrv, config) - if err != nil { - ctx.Logger.Error("failed to start grpc-web http server: ", err) - return err - } - } - } - - var rosettaSrv crgserver.Server - if config.Rosetta.Enable { - offlineMode := config.Rosetta.Offline - if !config.GRPC.Enable { // If GRPC is not enabled rosetta cannot work in online mode, so it works in offline mode. - offlineMode = true - } - - conf := &rosetta.Config{ - Blockchain: config.Rosetta.Blockchain, - Network: config.Rosetta.Network, - TendermintRPC: ctx.Config.RPC.ListenAddress, - GRPCEndpoint: config.GRPC.Address, - Addr: config.Rosetta.Address, - Retries: config.Rosetta.Retries, - Offline: offlineMode, - } - conf.WithCodec(clientCtx.InterfaceRegistry, clientCtx.JSONCodec.(*codec.ProtoCodec)) - - rosettaSrv, err = rosetta.ServerFromConfig(conf) - if err != nil { - return err - } - errCh := make(chan error) - go func() { - if err := rosettaSrv.Start(); err != nil { - errCh <- err - } - }() - - select { - case err := <-errCh: - return err - case <-time.After(5 * time.Second): // assume server started successfully - } - } - - defer func() { - if tmNode.IsRunning() { - _ = tmNode.Stop() - } - - if cpuProfileCleanup != nil { - cpuProfileCleanup() - } - - if apiSrv != nil { - _ = apiSrv.Close() - } - - if grpcSrv != nil { - grpcSrv.Stop() - if grpcWebSrv != nil { - grpcWebSrv.Close() - } - } - - ctx.Logger.Info("exiting...") - }() - - // Wait for SIGINT or SIGTERM signal - return WaitForQuitSignals() -} \ No newline at end of file From 415aad8e4eb2c784a4aff74fda114fd113b4e0d7 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Wed, 7 Jul 2021 12:20:47 -0500 Subject: [PATCH 40/46] finish config; config template --- store/streaming/file/server/config/config.go | 74 +++++++++++++++++++- 1 file changed, 71 insertions(+), 3 deletions(-) diff --git a/store/streaming/file/server/config/config.go b/store/streaming/file/server/config/config.go index 7ebb4f998d01..1ba666b20c36 100644 --- a/store/streaming/file/server/config/config.go +++ b/store/streaming/file/server/config/config.go @@ -1,7 +1,11 @@ package config import ( + "bytes" + "text/template" + "github.com/cosmos/cosmos-sdk/store/streaming/file" + tmos "github.com/tendermint/tendermint/libs/os" ) // Default constants @@ -18,24 +22,88 @@ const ( type StateServerConfig struct { GRPCAddress string `mapstructure:"grpc-address"` + GRPCWebEnabled bool `mapstructure:"grpc-web-enabled"` GRPCWebAddress string `mapstructure:"grpc-web-address"` ChainID string `mapstructure:"chain-id"` ReadDir string `mapstructure:"read-dir"` FilePrefix string `mapstructure:"file-prefix"` RemoveAfter bool `mapstructure:"remove-after"` // true: once data has been streamed forward it will be removed from the filesystem + LogFile string `mapstructure:"log-file"` + LogLevel string `mapstructure:"log-level"` } // DefaultStateServerConfig returns the reference to ClientConfig with default values. func DefaultStateServerConfig() *StateServerConfig { return &StateServerConfig{ DefaultGRPCAddress, + true, DefaultGRPCWebAddress, "", DefaultReadDir, "", - true} + true, + "", + "info", + } } -func WriteConfigFile(cfgFilePath string, cfg *StateServerConfig) { - panic("implement me") +var configTemplate *template.Template + +func init() { + var err error + + tmpl := template.New("fileServerConfigFileTemplate") + + if configTemplate, err = tmpl.Parse(defaultFileServerConfigTemplate); err != nil { + panic(err) + } } + +// WriteConfigFile renders config using the template and writes it to +// configFilePath. +func WriteConfigFile(configFilePath string, config *StateServerConfig) { + var buffer bytes.Buffer + + if err := configTemplate.Execute(&buffer, config); err != nil { + panic(err) + } + + tmos.MustWriteFile(configFilePath, buffer.Bytes(), 0644) +} + +const defaultFileServerConfigTemplate = `# This is a TOML config file. +# For more information, see https://github.com/toml-lang/toml + +############################################################################### +### File Server Configuration ### +############################################################################### + +[file-server] + +# Address defines the gRPC server address to bind to. +grpc-address = "{{ .GRPCAddress }}" + +# GRPCWebEnable defines if the gRPC-web should be enabled. +grpc-web-enable = {{ .GRPCWebEnabled }} + +# Address defines the gRPC-web server address to bind to. +grpc-web-address = "{{ .GRPCWebAddress }}" + +# ChainID defines the ChainID for the data we are serving +chain-id = "{{ .ChainID }}" + +# ReadDir defines the directory to read the data we are serving +read-dir = "{{ .ReadDir }}" + +# FilePrefix defines an (optional) prefix that has been prepended to the files from which we read data to serve +file-prefix = "{{ .ReadDir }}" + +# RemoveAfter defines whether or not to remove files after reading and serving their data +remove-after = "{{ .RemoveAfter }}" + +# LogFile defines the path to the file to write log messages to +log-file = "{{ .LogFile }}" + +# LogLevel defines the log level- which kind of logs to write to output +log-level = "{{ .LogLevel }}" +` From 94465f801fa3c4ea674d0aa3cd8cd9065f5454f0 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Wed, 7 Jul 2021 12:20:56 -0500 Subject: [PATCH 41/46] simple client --- store/streaming/file/server/client/client.go | 52 ++++---------------- 1 file changed, 9 insertions(+), 43 deletions(-) diff --git a/store/streaming/file/server/client/client.go b/store/streaming/file/server/client/client.go index dc3710c65705..9d734babbe53 100644 --- a/store/streaming/file/server/client/client.go +++ b/store/streaming/file/server/client/client.go @@ -1,52 +1,18 @@ package client import ( - "context" - "io" - "log" - - pb "github.com/cosmos/cosmos-sdk/state_file_server/grpc/v1beta" + "fmt" "google.golang.org/grpc" -) - -func NewClient(conn *grpc.ClientConn) (pb.StateFileClient, error) { - client := pb.NewStateFileClient(conn) -} - -func main() { - // dial server - conn, err := grpc.Dial(":50005", grpc.WithInsecure()) - if err != nil { - log.Fatalf("can not connect with server %v", err) - } + pb "github.com/cosmos/cosmos-sdk/store/streaming/file/server/v1beta" +) - // create stream - client := pb.NewStateFileClient(conn) - - in := &pb.StreamRequest{Id: 1} - stream, err := client.(context.Background(), in) +// NewClient creates a new gRPC client for the provided endpoint and default configuration +func NewClient(endpoint string) (pb.StateFileClient, error) { + conn, err := grpc.Dial(endpoint, grpc.WithInsecure()) if err != nil { - log.Fatalf("open stream error %v", err) + return nil, fmt.Errorf("can not connect with server %v", err) } - - done := make(chan bool) - - go func() { - for { - resp, err := stream.Recv() - if err == io.EOF { - done <- true //means stream is finished - return - } - if err != nil { - log.Fatalf("cannot receive %v", err) - } - log.Printf("Resp received: %s", resp.Result) - } - }() - - <-done //we will wait until all response is received - log.Printf("finished") -} \ No newline at end of file + return pb.NewStateFileClient(conn), nil +} From 10915ae33103815130867c4e26bcc916aee2ea03 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Wed, 7 Jul 2021 12:22:11 -0500 Subject: [PATCH 42/46] work on grpc backend, handler, and server- enable filtering of served KVPairs by store key --- store/streaming/file/server/grpc/backend.go | 94 +++++++++++++-------- store/streaming/file/server/grpc/handler.go | 35 +++++--- store/streaming/file/server/grpc/server.go | 24 +----- 3 files changed, 83 insertions(+), 70 deletions(-) diff --git a/store/streaming/file/server/grpc/backend.go b/store/streaming/file/server/grpc/backend.go index 6fb71229e5b7..6f0259d83c31 100644 --- a/store/streaming/file/server/grpc/backend.go +++ b/store/streaming/file/server/grpc/backend.go @@ -22,14 +22,14 @@ import ( ) type StateFileBackend struct { - conf config.StateServerConfig - + conf *config.StateServerConfig codec *codec.ProtoCodec logger log.Logger trimPrefix string + quitChan <-chan struct{} } -func NewStateFileBackend(conf config.StateServerConfig, codec *codec.ProtoCodec, logger log.Logger) *StateFileBackend { +func NewStateFileBackend(conf *config.StateServerConfig, codec *codec.ProtoCodec, logger log.Logger, quitChan <-chan struct{}) *StateFileBackend { trimPrefix := "block-" if conf.FilePrefix != "" { trimPrefix = fmt.Sprintf("%s-%s", conf.FilePrefix, trimPrefix) @@ -39,20 +39,19 @@ func NewStateFileBackend(conf config.StateServerConfig, codec *codec.ProtoCodec, codec: codec, trimPrefix: trimPrefix, logger: logger, + quitChan: quitChan, } } // StreamData streams the requested state file data // this streams new data as it is written to disk -func (sfb *StateFileBackend) StreamData(req *pb.StreamRequest, res chan<- *pb.StreamResponse, doneChan chan<- struct{}) error { +func (sfb *StateFileBackend) StreamData(req *pb.StreamRequest, res chan<- *pb.StreamResponse) error { w, err := fsnotify.NewWatcher() if err != nil { - close(doneChan) return err } go func() { defer w.Close() - defer close(doneChan) for { select { case event, ok := <-w.Events: @@ -65,13 +64,13 @@ func (sfb *StateFileBackend) StreamData(req *pb.StreamRequest, res chan<- *pb.St switch { case strings.Contains(fileName, "begin") && req.BeginBlock: readFlag = true - res <- sfb.formBeginBlockResponse(fileName) - case strings.Contains(fileName, "end") && req.EndBlock: - readFlag = true - res <- sfb.formBeginBlockResponse(fileName) + res <- sfb.formBeginBlockResponse(fileName, req.StoreKeys) case strings.Contains(fileName, "tx") && req.DeliverTx: readFlag = true - res <- sfb.formBeginBlockResponse(fileName) + res <- sfb.formDeliverTxResponse(fileName, req.StoreKeys) + case strings.Contains(fileName, "end") && req.EndBlock: + readFlag = true + res <- sfb.formEndBlockResponse(fileName, req.StoreKeys) default: } if sfb.conf.RemoveAfter && readFlag { @@ -85,6 +84,9 @@ func (sfb *StateFileBackend) StreamData(req *pb.StreamRequest, res chan<- *pb.St continue } sfb.logger.Error("fsnotify watcher error", "err", err) + case <-sfb.quitChan: + sfb.logger.Info("quiting StateFileBackend StreamData process") + return } } }() @@ -93,7 +95,7 @@ func (sfb *StateFileBackend) StreamData(req *pb.StreamRequest, res chan<- *pb.St // BackFillData stream the requested state file data // this stream data that is already written to disk -func (sfb *StateFileBackend) BackFillData(req *pb.StreamRequest, res chan<- *pb.StreamResponse, doneChan chan<- struct{}) error { +func (sfb *StateFileBackend) BackFillData(req *pb.StreamRequest, res chan<- *pb.StreamResponse) error { f, err := os.Open(sfb.conf.ReadDir) if err != nil { return err @@ -104,8 +106,14 @@ func (sfb *StateFileBackend) BackFillData(req *pb.StreamRequest, res chan<- *pb. } sort.Sort(filesByTimeModified(files)) go func() { - defer close(doneChan) for _, f := range files { + select { + // short circuit if the parent processes are shutting down + case <-sfb.quitChan: + sfb.logger.Info("quiting StateFileBackend BackFillData process") + return + default: + } if f.IsDir() { continue } @@ -114,13 +122,13 @@ func (sfb *StateFileBackend) BackFillData(req *pb.StreamRequest, res chan<- *pb. switch { case strings.Contains(fileName, "begin") && req.BeginBlock: readFlag = true - res <- sfb.formBeginBlockResponse(fileName) + res <- sfb.formBeginBlockResponse(fileName, req.StoreKeys) case strings.Contains(fileName, "end") && req.EndBlock: readFlag = true - res <- sfb.formBeginBlockResponse(fileName) + res <- sfb.formEndBlockResponse(fileName, req.StoreKeys) case strings.Contains(fileName, "tx") && req.DeliverTx: readFlag = true - res <- sfb.formBeginBlockResponse(fileName) + res <- sfb.formDeliverTxResponse(fileName, req.StoreKeys) default: } if sfb.conf.RemoveAfter && readFlag { @@ -139,7 +147,7 @@ func (sfb *StateFileBackend) BeginBlockDataAt(ctx context.Context, req *pb.Begin if sfb.conf.FilePrefix != "" { fileName = fmt.Sprintf("%s-%s", sfb.conf.FilePrefix, fileName) } - return sfb.formBeginBlockPayload(fileName) + return sfb.formBeginBlockPayload(fileName, req.StoreKeys) } // DeliverTxDataAt returns a DeliverTxPayload for the provided BeginBlockRequest @@ -148,7 +156,7 @@ func (sfb *StateFileBackend) DeliverTxDataAt(ctx context.Context, req *pb.Delive if sfb.conf.FilePrefix != "" { fileName = fmt.Sprintf("%s-%s", sfb.conf.FilePrefix, fileName) } - return sfb.formDeliverTxPayload(fileName) + return sfb.formDeliverTxPayload(fileName, req.StoreKeys) } // EndBlockDataAt returns a EndBlockPayload for the provided EndBlockRequest @@ -157,7 +165,7 @@ func (sfb *StateFileBackend) EndBlockDataAt(ctx context.Context, req *pb.EndBloc if sfb.conf.FilePrefix != "" { fileName = fmt.Sprintf("%s-%s", sfb.conf.FilePrefix, fileName) } - return sfb.formEndBlockPayload(fileName) + return sfb.formEndBlockPayload(fileName, req.StoreKeys) } type filesByTimeModified []os.FileInfo @@ -174,7 +182,7 @@ func (fs filesByTimeModified) Less(i, j int) bool { return fs[i].ModTime().Before(fs[j].ModTime()) } -func (sfb *StateFileBackend) formBeginBlockResponse(fileName string) *pb.StreamResponse { +func (sfb *StateFileBackend) formBeginBlockResponse(fileName string, storeKeys []string) *pb.StreamResponse { res := new(pb.StreamResponse) res.ChainId = sfb.conf.ChainID blockHeightStr := string(strings.TrimPrefix(fileName, sfb.trimPrefix)[0]) @@ -184,7 +192,7 @@ func (sfb *StateFileBackend) formBeginBlockResponse(fileName string) *pb.StreamR return res } res.Height = blockHeight - bbp, err := sfb.formBeginBlockPayload(fileName) + bbp, err := sfb.formBeginBlockPayload(fileName, storeKeys) if err != nil { res.Err = err.Error() return res @@ -193,7 +201,7 @@ func (sfb *StateFileBackend) formBeginBlockResponse(fileName string) *pb.StreamR return res } -func (sfb *StateFileBackend) formBeginBlockPayload(fileName string) (*pb.BeginBlockPayload, error) { +func (sfb *StateFileBackend) formBeginBlockPayload(fileName string, storeKeys []string) (*pb.BeginBlockPayload, error) { fileBytes, err := readFile(sfb.conf.ReadDir, fileName) if err != nil { return nil, err @@ -213,13 +221,15 @@ func (sfb *StateFileBackend) formBeginBlockPayload(fileName string) (*pb.BeginBl if err := sfb.codec.Unmarshal(messageBytes[len(messageBytes)-1], beginBlockRes); err != nil { return nil, err } - kvPairs := make([]*types.StoreKVPair, len(messageBytes[1:len(messageBytes)-2])) + kvPairs := make([]*types.StoreKVPair, 0, len(messageBytes[1:len(messageBytes)-2])) for i := 1; i < len(messageBytes)-1; i++ { kvPair := new(types.StoreKVPair) if err := sfb.codec.Unmarshal(messageBytes[i], kvPair); err != nil { return nil, err } - kvPairs[i-1] = kvPair + if listIsEmptyOrContains(storeKeys, kvPair.StoreKey) { + kvPairs = append(kvPairs, kvPair) + } } return &pb.BeginBlockPayload{ Request: beginBlockReq, @@ -228,7 +238,7 @@ func (sfb *StateFileBackend) formBeginBlockPayload(fileName string) (*pb.BeginBl }, nil } -func (sfb *StateFileBackend) formDeliverTxResponse(fileName string) *pb.StreamResponse { +func (sfb *StateFileBackend) formDeliverTxResponse(fileName string, storeKeys []string) *pb.StreamResponse { res := new(pb.StreamResponse) res.ChainId = sfb.conf.ChainID blockHeightStr := string(strings.TrimPrefix(fileName, sfb.trimPrefix)[0]) @@ -238,7 +248,7 @@ func (sfb *StateFileBackend) formDeliverTxResponse(fileName string) *pb.StreamRe return res } res.Height = blockHeight - dtp, err := sfb.formDeliverTxPayload(fileName) + dtp, err := sfb.formDeliverTxPayload(fileName, storeKeys) if err != nil { res.Err = err.Error() return res @@ -247,7 +257,7 @@ func (sfb *StateFileBackend) formDeliverTxResponse(fileName string) *pb.StreamRe return res } -func (sfb *StateFileBackend) formDeliverTxPayload(fileName string) (*pb.DeliverTxPayload, error) { +func (sfb *StateFileBackend) formDeliverTxPayload(fileName string, storeKeys []string) (*pb.DeliverTxPayload, error) { fileBytes, err := readFile(sfb.conf.ReadDir, fileName) if err != nil { return nil, err @@ -267,13 +277,15 @@ func (sfb *StateFileBackend) formDeliverTxPayload(fileName string) (*pb.DeliverT if err := sfb.codec.Unmarshal(messageBytes[len(messageBytes)-1], deliverTxRes); err != nil { return nil, err } - kvPairs := make([]*types.StoreKVPair, len(messageBytes[1:len(messageBytes)-2])) + kvPairs := make([]*types.StoreKVPair, 0, len(messageBytes[1:len(messageBytes)-2])) for i := 1; i < len(messageBytes)-1; i++ { kvPair := new(types.StoreKVPair) if err := sfb.codec.Unmarshal(messageBytes[i], kvPair); err != nil { return nil, err } - kvPairs[i-1] = kvPair + if listIsEmptyOrContains(storeKeys, kvPair.StoreKey) { + kvPairs = append(kvPairs, kvPair) + } } return &pb.DeliverTxPayload{ Request: deliverTxReq, @@ -282,7 +294,7 @@ func (sfb *StateFileBackend) formDeliverTxPayload(fileName string) (*pb.DeliverT }, nil } -func (sfb *StateFileBackend) formEndBlockResponse(fileName string) *pb.StreamResponse { +func (sfb *StateFileBackend) formEndBlockResponse(fileName string, storeKeys []string) *pb.StreamResponse { res := new(pb.StreamResponse) res.ChainId = sfb.conf.ChainID blockHeightStr := string(strings.TrimPrefix(fileName, sfb.trimPrefix)[0]) @@ -292,7 +304,7 @@ func (sfb *StateFileBackend) formEndBlockResponse(fileName string) *pb.StreamRes return res } res.Height = blockHeight - ebp, err := sfb.formEndBlockPayload(fileName) + ebp, err := sfb.formEndBlockPayload(fileName, storeKeys) if err != nil { res.Err = err.Error() return res @@ -301,7 +313,7 @@ func (sfb *StateFileBackend) formEndBlockResponse(fileName string) *pb.StreamRes return res } -func (sfb *StateFileBackend) formEndBlockPayload(fileName string) (*pb.EndBlockPayload, error) { +func (sfb *StateFileBackend) formEndBlockPayload(fileName string, storeKeys []string) (*pb.EndBlockPayload, error) { fileBytes, err := readFile(sfb.conf.ReadDir, fileName) if err != nil { return nil, err @@ -321,13 +333,15 @@ func (sfb *StateFileBackend) formEndBlockPayload(fileName string) (*pb.EndBlockP if err := sfb.codec.Unmarshal(messageBytes[len(messageBytes)-1], endBlockRes); err != nil { return nil, err } - kvPairs := make([]*types.StoreKVPair, len(messageBytes[1:len(messageBytes)-2])) + kvPairs := make([]*types.StoreKVPair, 0, len(messageBytes[1:len(messageBytes)-2])) for i := 1; i < len(messageBytes)-1; i++ { kvPair := new(types.StoreKVPair) if err := sfb.codec.Unmarshal(messageBytes[i], kvPair); err != nil { return nil, err } - kvPairs[i-1] = kvPair + if listIsEmptyOrContains(storeKeys, kvPair.StoreKey) { + kvPairs = append(kvPairs, kvPair) + } } return &pb.EndBlockPayload{ Request: endBlockReq, @@ -339,3 +353,15 @@ func (sfb *StateFileBackend) formEndBlockPayload(fileName string) (*pb.EndBlockP func readFile(dir, fileName string) ([]byte, error) { return ioutil.ReadFile(filepath.Join(dir, fileName)) } + +func listIsEmptyOrContains(list []string, str string) bool { + if len(list) == 0 { + return true + } + for _, element := range list { + if element == str { + return true + } + } + return false +} diff --git a/store/streaming/file/server/grpc/handler.go b/store/streaming/file/server/grpc/handler.go index f44e47faa321..0823bcc05a78 100644 --- a/store/streaming/file/server/grpc/handler.go +++ b/store/streaming/file/server/grpc/handler.go @@ -9,20 +9,26 @@ import ( "github.com/tendermint/tendermint/libs/log" ) -type Handler = pb.StateFileServer +type Handler interface { + pb.StateFileServer + Stop() +} // handler is the interface which exposes the StateFile Server methods type handler struct { pb.UnimplementedStateFileServer - backend *StateFileBackend - logger log.Logger + backend *StateFileBackend + logger log.Logger + quitChan chan struct{} } -// New returns the object for the RPC handler -func New(conf config.StateServerConfig, codec *codec.ProtoCodec, logger log.Logger) (Handler, error) { +// NewHandler returns the object for the gRPC handler +func NewHandler(conf *config.StateServerConfig, codec *codec.ProtoCodec, logger log.Logger) (Handler, error) { + quitChan := make(chan struct{}) return &handler{ - backend: NewStateFileBackend(conf, codec, logger), - logger: logger, + backend: NewStateFileBackend(conf, codec, logger, quitChan), + logger: logger, + quitChan: quitChan, }, nil } @@ -30,8 +36,7 @@ func New(conf config.StateServerConfig, codec *codec.ProtoCodec, logger log.Logg // this streams new data as it is written to disk func (h *handler) StreamData(req *pb.StreamRequest, srv pb.StateFile_StreamDataServer) error { resChan := make(chan *pb.StreamResponse) - stopped := make(chan struct{}) - if err := h.backend.StreamData(req, resChan, stopped); err != nil { + if err := h.backend.StreamData(req, resChan); err != nil { return err } for { @@ -40,7 +45,7 @@ func (h *handler) StreamData(req *pb.StreamRequest, srv pb.StateFile_StreamDataS if err := srv.Send(res); err != nil { h.logger.Error("StreamData send error", "err", err) } - case <-stopped: + case <-h.quitChan: return nil } } @@ -50,8 +55,7 @@ func (h *handler) StreamData(req *pb.StreamRequest, srv pb.StateFile_StreamDataS // this stream data that is already written to disk func (h *handler) BackFillData(req *pb.StreamRequest, srv pb.StateFile_BackFillDataServer) error { resChan := make(chan *pb.StreamResponse) - stopped := make(chan struct{}) - if err := h.backend.BackFillData(req, resChan, stopped); err != nil { + if err := h.backend.BackFillData(req, resChan); err != nil { return err } for { @@ -60,7 +64,7 @@ func (h *handler) BackFillData(req *pb.StreamRequest, srv pb.StateFile_BackFillD if err := srv.Send(res); err != nil { h.logger.Error("BackFillData send error", "err", err) } - case <-stopped: + case <-h.quitChan: return nil } } @@ -80,3 +84,8 @@ func (h *handler) DeliverTxDataAt(ctx context.Context, req *pb.DeliverTxRequest) func (h *handler) EndBlockDataAt(ctx context.Context, req *pb.EndBlockRequest) (*pb.EndBlockPayload, error) { return h.backend.EndBlockDataAt(ctx, req) } + +// Stop stops the handler processes and its backend processes +func (h *handler) Stop() { + close(h.quitChan) +} diff --git a/store/streaming/file/server/grpc/server.go b/store/streaming/file/server/grpc/server.go index d19cb919695a..45475b6d7ba0 100644 --- a/store/streaming/file/server/grpc/server.go +++ b/store/streaming/file/server/grpc/server.go @@ -7,36 +7,14 @@ import ( "google.golang.org/grpc" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/server/grpc/gogoreflection" - reflection "github.com/cosmos/cosmos-sdk/server/grpc/reflection/v2alpha1" pb "github.com/cosmos/cosmos-sdk/store/streaming/file/server/v1beta" - sdk "github.com/cosmos/cosmos-sdk/types" ) // StartGRPCServer starts a gRPC server on the given address. -func StartGRPCServer(clientCtx client.Context, handler pb.StateFileServer, address string) (*grpc.Server, error) { +func StartGRPCServer(handler Handler, address string) (*grpc.Server, error) { grpcSrv := grpc.NewServer() pb.RegisterStateFileServer(grpcSrv, handler) - // reflection allows consumers to build dynamic clients that can write - // to any cosmos-sdk application without relying on application packages at compile time - err := reflection.Register(grpcSrv, reflection.Config{ - SigningModes: func() map[string]int32 { - modes := make(map[string]int32, len(clientCtx.TxConfig.SignModeHandler().Modes())) - for _, m := range clientCtx.TxConfig.SignModeHandler().Modes() { - modes[m.String()] = (int32)(m) - } - return modes - }(), - ChainID: clientCtx.ChainID, - SdkConfig: sdk.GetConfig(), - InterfaceRegistry: clientCtx.InterfaceRegistry, - }) - if err != nil { - return nil, err - } - // Reflection allows external clients to see what services and methods - // the gRPC server exposes. gogoreflection.Register(grpcSrv) listener, err := net.Listen("tcp", address) if err != nil { From 55d45de354626580fd46791787be135ffe792f25 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Wed, 7 Jul 2021 12:22:32 -0500 Subject: [PATCH 43/46] update proto types --- docs/core/proto-docs.md | 11 +- proto/cosmos/base/server/v1beta1/server.proto | 10 + .../streaming/file/server/v1beta/server.pb.go | 270 ++++++++++++++---- 3 files changed, 238 insertions(+), 53 deletions(-) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index ff93dc544e38..a0881ea05be2 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -2705,8 +2705,9 @@ BeginBlockRequest is the message definition for requesting BeginBlock data at a | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `height` | [int64](#int64) | | | -| `index` | [int64](#int64) | | | +| `height` | [int64](#int64) | | height at which to return data | +| `index` | [int64](#int64) | | index of the tx for which to return data | +| `store_keys` | [string](#string) | repeated | store_keys is a (optional) list of store keys for which to restrict the streamed KVPairs to | @@ -2738,7 +2739,8 @@ DeliverTxRequest is the message definition for requesting DeliverTx data at a sp | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `height` | [int64](#int64) | | | +| `height` | [int64](#int64) | | height at which to return data | +| `store_keys` | [string](#string) | repeated | store_keys is a (optional) list of store keys for which to restrict the streamed KVPairs to | @@ -2770,7 +2772,8 @@ EndBlockRequest is the message definition for requesting EndBlock data at a spec | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `height` | [int64](#int64) | | | +| `height` | [int64](#int64) | | height at which to return data | +| `store_keys` | [string](#string) | repeated | store_keys is a (optional) list of store keys for which to restrict the streamed KVPairs to | diff --git a/proto/cosmos/base/server/v1beta1/server.proto b/proto/cosmos/base/server/v1beta1/server.proto index 04ba83ea9ae8..47fe24703705 100644 --- a/proto/cosmos/base/server/v1beta1/server.proto +++ b/proto/cosmos/base/server/v1beta1/server.proto @@ -30,18 +30,28 @@ message StreamRequest { // BeginBlockRequest is the message definition for requesting BeginBlock data at a specific height message BeginBlockRequest { + // height at which to return data int64 height = 1; + // store_keys is a (optional) list of store keys for which to restrict the streamed KVPairs to + repeated string store_keys = 2; } // DeliverTxRequest is the message definition for requesting DeliverTx data at a specific height message DeliverTxRequest { + // height at which to return data int64 height = 1; + // index of the tx for which to return data int64 index = 2; + // store_keys is a (optional) list of store keys for which to restrict the streamed KVPairs to + repeated string store_keys = 3; } // EndBlockRequest is the message definition for requesting EndBlock data at a specific height message EndBlockRequest { + // height at which to return data int64 height = 1; + // store_keys is a (optional) list of store keys for which to restrict the streamed KVPairs to + repeated string store_keys = 2; } // StreamResponse contains the response data for a stream request diff --git a/store/streaming/file/server/v1beta/server.pb.go b/store/streaming/file/server/v1beta/server.pb.go index e506b04baff8..f5da8a0bc9ad 100644 --- a/store/streaming/file/server/v1beta/server.pb.go +++ b/store/streaming/file/server/v1beta/server.pb.go @@ -105,7 +105,10 @@ func (m *StreamRequest) GetStoreKeys() []string { // BeginBlockRequest is the message definition for requesting BeginBlock data at a specific height type BeginBlockRequest struct { + // height at which to return data Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` + // store_keys is a (optional) list of store keys for which to restrict the streamed KVPairs to + StoreKeys []string `protobuf:"bytes,2,rep,name=store_keys,json=storeKeys,proto3" json:"store_keys,omitempty"` } func (m *BeginBlockRequest) Reset() { *m = BeginBlockRequest{} } @@ -148,10 +151,21 @@ func (m *BeginBlockRequest) GetHeight() int64 { return 0 } +func (m *BeginBlockRequest) GetStoreKeys() []string { + if m != nil { + return m.StoreKeys + } + return nil +} + // DeliverTxRequest is the message definition for requesting DeliverTx data at a specific height type DeliverTxRequest struct { + // height at which to return data Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` - Index int64 `protobuf:"varint,2,opt,name=index,proto3" json:"index,omitempty"` + // index of the tx for which to return data + Index int64 `protobuf:"varint,2,opt,name=index,proto3" json:"index,omitempty"` + // store_keys is a (optional) list of store keys for which to restrict the streamed KVPairs to + StoreKeys []string `protobuf:"bytes,3,rep,name=store_keys,json=storeKeys,proto3" json:"store_keys,omitempty"` } func (m *DeliverTxRequest) Reset() { *m = DeliverTxRequest{} } @@ -201,9 +215,19 @@ func (m *DeliverTxRequest) GetIndex() int64 { return 0 } +func (m *DeliverTxRequest) GetStoreKeys() []string { + if m != nil { + return m.StoreKeys + } + return nil +} + // EndBlockRequest is the message definition for requesting EndBlock data at a specific height type EndBlockRequest struct { + // height at which to return data Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` + // store_keys is a (optional) list of store keys for which to restrict the streamed KVPairs to + StoreKeys []string `protobuf:"bytes,2,rep,name=store_keys,json=storeKeys,proto3" json:"store_keys,omitempty"` } func (m *EndBlockRequest) Reset() { *m = EndBlockRequest{} } @@ -246,6 +270,13 @@ func (m *EndBlockRequest) GetHeight() int64 { return 0 } +func (m *EndBlockRequest) GetStoreKeys() []string { + if m != nil { + return m.StoreKeys + } + return nil +} + // StreamResponse contains the response data for a stream request type StreamResponse struct { // The ChainID for the tendermint application we are streaming data for @@ -536,54 +567,54 @@ func init() { } var fileDescriptor_9b48d4169ef99d67 = []byte{ - // 738 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x5b, 0x4f, 0x13, 0x41, - 0x14, 0xee, 0xb2, 0x05, 0xda, 0x53, 0xae, 0x23, 0x21, 0xb5, 0xc4, 0x52, 0xd6, 0x44, 0x41, 0x64, - 0x57, 0xea, 0x9b, 0x37, 0xb4, 0x22, 0x89, 0xe1, 0x85, 0x2c, 0xc6, 0x44, 0x13, 0x53, 0xf7, 0x32, - 0x6e, 0x27, 0xdd, 0xee, 0xd6, 0x9d, 0x81, 0xd0, 0x47, 0x9f, 0x7d, 0xf1, 0xb7, 0xf8, 0x2b, 0x78, - 0xe4, 0x51, 0x13, 0xa3, 0x06, 0xfe, 0x88, 0xd9, 0xd9, 0xd9, 0xe9, 0x05, 0x0b, 0xe5, 0x81, 0xa7, - 0x76, 0xce, 0x9c, 0x6f, 0xbe, 0xf3, 0x9d, 0xcb, 0xcc, 0xc2, 0x5d, 0x27, 0xa4, 0xad, 0x90, 0x1a, - 0xb6, 0x45, 0xb1, 0x41, 0x71, 0x74, 0x88, 0x23, 0xe3, 0x70, 0xd3, 0xc6, 0xcc, 0xda, 0x14, 0x4b, - 0xbd, 0x1d, 0x85, 0x2c, 0x44, 0xa5, 0xc4, 0x51, 0x8f, 0x1d, 0x75, 0xb1, 0x23, 0x1c, 0x4b, 0x0b, - 0x5e, 0xe8, 0x85, 0xdc, 0xcd, 0x88, 0xff, 0x25, 0x88, 0xd2, 0x5a, 0xdf, 0xd1, 0x2c, 0x8c, 0xb0, - 0x3c, 0xd9, 0x27, 0x94, 0xe1, 0x80, 0x04, 0x9e, 0x70, 0x5d, 0x62, 0x38, 0x70, 0x71, 0xd4, 0x22, - 0x01, 0x33, 0x2c, 0xdb, 0x21, 0x06, 0xeb, 0xb4, 0x31, 0x4d, 0x36, 0xb5, 0xaf, 0x0a, 0x4c, 0xef, - 0xb3, 0x08, 0x5b, 0x2d, 0x13, 0x7f, 0x3e, 0xc0, 0x94, 0xa1, 0x65, 0x28, 0xd8, 0xd8, 0x23, 0x41, - 0xdd, 0xf6, 0x43, 0xa7, 0x59, 0x54, 0x2a, 0xca, 0x6a, 0xce, 0x04, 0x6e, 0xaa, 0xc5, 0x16, 0x74, - 0x0b, 0xc0, 0xc5, 0x3e, 0x39, 0xc4, 0x51, 0x9d, 0x1d, 0x15, 0xc7, 0xf8, 0x7e, 0x5e, 0x58, 0xde, - 0x1c, 0xa1, 0x25, 0xc8, 0xe3, 0xc0, 0x15, 0x68, 0x95, 0xef, 0xe6, 0x70, 0xe0, 0x4a, 0x2c, 0x0f, - 0xb6, 0xde, 0xc4, 0x1d, 0x5a, 0xcc, 0x56, 0xd4, 0xd5, 0xbc, 0x99, 0xe7, 0x96, 0x5d, 0xdc, 0xa1, - 0xda, 0x3a, 0xcc, 0xd7, 0x24, 0x51, 0x1a, 0xd0, 0x22, 0x4c, 0x34, 0x30, 0xf1, 0x1a, 0x8c, 0xc7, - 0xa2, 0x9a, 0x62, 0xa5, 0x3d, 0x87, 0xb9, 0xed, 0x94, 0xf5, 0x12, 0x5f, 0xb4, 0x00, 0xe3, 0x24, - 0x70, 0x71, 0x12, 0xae, 0x6a, 0x26, 0x0b, 0x6d, 0x0d, 0x66, 0x5f, 0x89, 0xc8, 0x2e, 0x23, 0xfb, - 0xa2, 0xc2, 0x4c, 0x9a, 0x27, 0xda, 0x0e, 0x03, 0x8a, 0xd1, 0x4d, 0xc8, 0x39, 0x0d, 0x8b, 0x04, - 0x75, 0xe2, 0x72, 0xe7, 0xbc, 0x39, 0xc9, 0xd7, 0xaf, 0xdd, 0x9e, 0x53, 0xc6, 0xfa, 0xc2, 0x70, - 0xe0, 0x46, 0x4f, 0x6e, 0xeb, 0x6d, 0xab, 0xe3, 0x87, 0x96, 0xcb, 0xb3, 0x54, 0xa8, 0x6e, 0xe8, - 0xc3, 0xbb, 0x40, 0xef, 0xa6, 0x65, 0x2f, 0x01, 0xd5, 0xb2, 0xc7, 0xbf, 0x97, 0x15, 0x73, 0xde, - 0x1e, 0xdc, 0x40, 0x1f, 0x01, 0x75, 0xeb, 0x23, 0x39, 0xb2, 0x9c, 0xe3, 0xfe, 0x45, 0x1c, 0x32, - 0x9b, 0xfd, 0x14, 0x73, 0xee, 0x80, 0x1d, 0x7d, 0x80, 0x79, 0x59, 0x62, 0x49, 0x30, 0xce, 0x09, - 0xd6, 0x2f, 0x22, 0x48, 0x93, 0xdd, 0x7f, 0xfe, 0x2c, 0xee, 0x37, 0xa3, 0x45, 0x50, 0x71, 0x14, - 0x15, 0x27, 0xe2, 0x9c, 0x0a, 0x9f, 0xd8, 0xa0, 0xfd, 0x51, 0x7a, 0xdb, 0x23, 0xf5, 0x7e, 0x02, - 0x93, 0x51, 0x52, 0x3c, 0x5e, 0x85, 0x42, 0x55, 0xd3, 0xbb, 0x0d, 0xaf, 0xc7, 0x0d, 0xaf, 0x8b, - 0xe2, 0xf6, 0xb4, 0x56, 0x0a, 0x41, 0x5b, 0x90, 0x8b, 0x44, 0x41, 0x79, 0xad, 0x0a, 0xd5, 0xdb, - 0xff, 0x81, 0x27, 0x0e, 0x3d, 0x78, 0x09, 0x42, 0xbb, 0x30, 0x4d, 0x99, 0xc5, 0x70, 0xdd, 0x69, - 0x58, 0x81, 0x87, 0x69, 0x51, 0xad, 0xa8, 0xab, 0x85, 0xea, 0x9d, 0xfe, 0x3c, 0xc4, 0x1d, 0x2e, - 0xd3, 0xb0, 0xcf, 0xfb, 0xfd, 0xed, 0x9e, 0x45, 0x22, 0x73, 0x8a, 0x83, 0x5f, 0x26, 0x58, 0xed, - 0x97, 0xd2, 0xd3, 0xd3, 0xa9, 0xc0, 0xc7, 0x83, 0x02, 0x57, 0x86, 0x09, 0xec, 0x8e, 0x83, 0xd4, - 0xf7, 0xec, 0x9c, 0x3e, 0x6d, 0xa8, 0xbe, 0x2e, 0xfc, 0x9a, 0xe4, 0xfd, 0x54, 0xba, 0x03, 0x97, - 0xaa, 0x7b, 0x34, 0xa8, 0xae, 0x32, 0x4c, 0x9d, 0x1c, 0x55, 0x29, 0xee, 0xe9, 0x39, 0x71, 0x2b, - 0x43, 0xc5, 0x49, 0xf4, 0xf5, 0x68, 0xab, 0x7e, 0xcf, 0x42, 0x7e, 0x3f, 0x36, 0xec, 0x10, 0x1f, - 0xa3, 0x08, 0xe6, 0xba, 0xdd, 0xb2, 0x6d, 0x31, 0xeb, 0x05, 0x43, 0x23, 0xce, 0xb7, 0x50, 0x5b, - 0xba, 0xda, 0x75, 0xa0, 0x65, 0x50, 0x08, 0xb3, 0xb2, 0x82, 0x82, 0x72, 0xb4, 0x71, 0x4f, 0x19, - 0xaf, 0x74, 0x39, 0x68, 0x19, 0xe4, 0xc3, 0x4c, 0x9a, 0x55, 0xc1, 0x37, 0xd2, 0xf4, 0xa7, 0x74, - 0x57, 0xb9, 0x2a, 0xb4, 0x0c, 0xf2, 0x00, 0x92, 0x0b, 0x38, 0xe6, 0x42, 0x6b, 0x17, 0x81, 0xfb, - 0x1e, 0xb4, 0xd2, 0xbd, 0x51, 0x5c, 0x93, 0x96, 0xd0, 0x32, 0x0f, 0x14, 0x44, 0x60, 0xaa, 0x66, - 0x39, 0xcd, 0x1d, 0xe2, 0xfb, 0xd7, 0x4c, 0x55, 0x7b, 0x77, 0x7c, 0x5a, 0x56, 0x4e, 0x4e, 0xcb, - 0xca, 0xdf, 0xd3, 0xb2, 0xf2, 0xed, 0xac, 0x9c, 0x39, 0x39, 0x2b, 0x67, 0x7e, 0x9c, 0x95, 0x33, - 0xef, 0xb7, 0x3c, 0xc2, 0x1a, 0x07, 0xb6, 0xee, 0x84, 0x2d, 0x43, 0x3c, 0xf5, 0xc9, 0xcf, 0x06, - 0x75, 0x9b, 0xe2, 0xc1, 0xa7, 0xfc, 0x40, 0x12, 0x78, 0xc6, 0x27, 0xe2, 0x0f, 0x7c, 0x60, 0xd8, - 0x13, 0xfc, 0x7d, 0x7f, 0xf8, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x3d, 0xaf, 0x68, 0x35, 0x84, 0x08, - 0x00, 0x00, + // 748 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x5d, 0x4f, 0x13, 0x4d, + 0x14, 0xee, 0xd2, 0x02, 0xed, 0x29, 0x9f, 0xf3, 0x12, 0xd2, 0xb7, 0xe4, 0x2d, 0xb0, 0x6f, 0xa2, + 0xa0, 0xb2, 0x2b, 0xf5, 0xce, 0x2f, 0x62, 0x45, 0xa2, 0x72, 0x43, 0x16, 0x63, 0xa2, 0x89, 0xa9, + 0xfb, 0x31, 0x6e, 0x27, 0xdd, 0xee, 0xd6, 0x9d, 0x81, 0xd0, 0x4b, 0xaf, 0xbd, 0xf1, 0xb7, 0xf8, + 0x2b, 0xb8, 0xe4, 0x52, 0x13, 0xa3, 0x06, 0xfe, 0x88, 0xd9, 0xd9, 0xd9, 0x69, 0x77, 0xb1, 0x58, + 0x62, 0xb8, 0x82, 0x3d, 0x73, 0x9e, 0xf3, 0xcc, 0x33, 0xcf, 0x39, 0xd3, 0x81, 0xeb, 0x76, 0x40, + 0x3b, 0x01, 0xd5, 0x2d, 0x93, 0x62, 0x9d, 0xe2, 0xf0, 0x10, 0x87, 0xfa, 0xe1, 0xa6, 0x85, 0x99, + 0xb9, 0x29, 0x3e, 0xb5, 0x6e, 0x18, 0xb0, 0x00, 0x55, 0xe3, 0x44, 0x2d, 0x4a, 0xd4, 0xc4, 0x8a, + 0x48, 0xac, 0x2e, 0xb8, 0x81, 0x1b, 0xf0, 0x34, 0x3d, 0xfa, 0x2f, 0x46, 0x54, 0xd7, 0x53, 0xa5, + 0x59, 0x10, 0x62, 0x59, 0xd9, 0x23, 0x94, 0x61, 0x9f, 0xf8, 0xae, 0x48, 0x5d, 0x62, 0xd8, 0x77, + 0x70, 0xd8, 0x21, 0x3e, 0xd3, 0x4d, 0xcb, 0x26, 0x3a, 0xeb, 0x75, 0x31, 0x8d, 0x17, 0xd5, 0x8f, + 0x0a, 0x4c, 0xef, 0xb3, 0x10, 0x9b, 0x1d, 0x03, 0xbf, 0x3f, 0xc0, 0x94, 0xa1, 0x65, 0x28, 0x5b, + 0xd8, 0x25, 0x7e, 0xd3, 0xf2, 0x02, 0xbb, 0x5d, 0x51, 0x56, 0x94, 0xb5, 0xa2, 0x01, 0x3c, 0xd4, + 0x88, 0x22, 0xe8, 0x3f, 0x00, 0x07, 0x7b, 0xe4, 0x10, 0x87, 0x4d, 0x76, 0x54, 0x19, 0xe3, 0xeb, + 0x25, 0x11, 0x79, 0x71, 0x84, 0x96, 0xa0, 0x84, 0x7d, 0x47, 0xa0, 0xf3, 0x7c, 0xb5, 0x88, 0x7d, + 0x47, 0x62, 0xf9, 0x66, 0x9b, 0x6d, 0xdc, 0xa3, 0x95, 0xc2, 0x4a, 0x7e, 0xad, 0x64, 0x94, 0x78, + 0x64, 0x17, 0xf7, 0xa8, 0xfa, 0x1c, 0xe6, 0x1b, 0x92, 0x28, 0xd9, 0xd0, 0x22, 0x4c, 0xb4, 0x30, + 0x71, 0x5b, 0x8c, 0xef, 0x25, 0x6f, 0x88, 0xaf, 0x4c, 0xad, 0xb1, 0x6c, 0xad, 0x26, 0xcc, 0x6d, + 0x27, 0x9b, 0xfa, 0x53, 0xa9, 0x05, 0x18, 0x27, 0xbe, 0x83, 0x63, 0x35, 0x79, 0x23, 0xfe, 0xc8, + 0x10, 0xe4, 0xb3, 0x04, 0x4f, 0x61, 0xf6, 0x89, 0xd0, 0xf5, 0x97, 0x5b, 0xfd, 0x90, 0x87, 0x99, + 0xc4, 0x04, 0xda, 0x0d, 0x7c, 0x8a, 0xd1, 0xbf, 0x50, 0xb4, 0x5b, 0x26, 0xf1, 0x9b, 0xc4, 0xe1, + 0xb5, 0x4a, 0xc6, 0x24, 0xff, 0x7e, 0xe6, 0x0c, 0x90, 0x8c, 0xa5, 0x48, 0x6c, 0xf8, 0x67, 0xc0, + 0xb8, 0x66, 0xd7, 0xec, 0x79, 0x81, 0xe9, 0x70, 0x0b, 0xca, 0xf5, 0x0d, 0x6d, 0x78, 0x8b, 0x69, + 0xfd, 0x33, 0xdf, 0x8b, 0x41, 0x8d, 0xc2, 0xf1, 0xf7, 0x65, 0xc5, 0x98, 0xb7, 0xb2, 0x0b, 0xe8, + 0x2d, 0xa0, 0xbe, 0xf9, 0x92, 0xa3, 0xc0, 0x39, 0x6e, 0x5d, 0xc4, 0x21, 0xbd, 0x48, 0x53, 0xcc, + 0x39, 0x99, 0x38, 0x7a, 0x03, 0xf3, 0xb2, 0x7f, 0x24, 0xc1, 0x38, 0x27, 0xb8, 0x79, 0x11, 0x41, + 0xe2, 0x45, 0xba, 0xfe, 0x2c, 0x4e, 0x87, 0xd1, 0x22, 0xe4, 0x71, 0x18, 0x56, 0x26, 0xa2, 0x33, + 0x15, 0x39, 0x51, 0x40, 0xfd, 0xa1, 0x0c, 0xf6, 0x5e, 0x92, 0x7d, 0x1f, 0x26, 0xc3, 0xd8, 0x5b, + 0xee, 0x42, 0xb9, 0xae, 0x6a, 0xfd, 0x69, 0xd2, 0xa2, 0x69, 0xd2, 0x84, 0xf7, 0x03, 0x7d, 0x9b, + 0x40, 0xd0, 0x16, 0x14, 0x43, 0x61, 0x28, 0xf7, 0xaa, 0x5c, 0xff, 0xff, 0x37, 0xf0, 0x38, 0x61, + 0x00, 0x2f, 0x41, 0x68, 0x17, 0xa6, 0x29, 0x33, 0x19, 0x6e, 0xda, 0x2d, 0xd3, 0x77, 0x71, 0xdc, + 0x84, 0xe5, 0xfa, 0xb5, 0xf4, 0x39, 0x44, 0x7d, 0x24, 0x8f, 0x61, 0x9f, 0x77, 0xd5, 0xcb, 0x3d, + 0x93, 0x84, 0xc6, 0x14, 0x07, 0x3f, 0x8e, 0xb1, 0xea, 0x37, 0x65, 0x60, 0x22, 0x12, 0x81, 0xf7, + 0xb2, 0x02, 0x57, 0x87, 0x09, 0xec, 0x0f, 0x93, 0xd4, 0xf7, 0xf0, 0x9c, 0x3e, 0x75, 0xa8, 0xbe, + 0x3e, 0xfc, 0x8a, 0xe4, 0x7d, 0x55, 0xfa, 0xf3, 0x98, 0xa8, 0xbb, 0x9b, 0x55, 0xb7, 0x32, 0x4c, + 0x9d, 0x9c, 0x64, 0x29, 0xee, 0xc1, 0x39, 0x71, 0xab, 0x43, 0xc5, 0x49, 0xf4, 0xd5, 0x68, 0xab, + 0x7f, 0x2e, 0x40, 0x69, 0x3f, 0x0a, 0xec, 0x10, 0x0f, 0xa3, 0x10, 0xe6, 0xfa, 0xdd, 0xb2, 0x6d, + 0x32, 0xf3, 0x11, 0x43, 0x23, 0xce, 0xb7, 0x50, 0x5b, 0xbd, 0xdc, 0x75, 0xa0, 0xe6, 0x50, 0x00, + 0xb3, 0xd2, 0x41, 0x41, 0x39, 0xda, 0xb8, 0x27, 0x8c, 0x97, 0xba, 0x1c, 0xd4, 0x1c, 0xf2, 0x60, + 0x26, 0x39, 0x55, 0xc1, 0x37, 0xd2, 0xf4, 0x27, 0x74, 0x97, 0xb9, 0x2a, 0xd4, 0x1c, 0x72, 0x01, + 0xe2, 0x0b, 0x38, 0xe2, 0x42, 0xeb, 0x17, 0x81, 0x53, 0xbf, 0x96, 0xd5, 0x1b, 0xa3, 0xa4, 0xc6, + 0x2d, 0xa1, 0xe6, 0x6e, 0x2b, 0x88, 0xc0, 0x54, 0xc3, 0xb4, 0xdb, 0x3b, 0xc4, 0xf3, 0xae, 0x98, + 0xaa, 0xf1, 0xea, 0xf8, 0xb4, 0xa6, 0x9c, 0x9c, 0xd6, 0x94, 0x9f, 0xa7, 0x35, 0xe5, 0xd3, 0x59, + 0x2d, 0x77, 0x72, 0x56, 0xcb, 0x7d, 0x39, 0xab, 0xe5, 0x5e, 0x6f, 0xb9, 0x84, 0xb5, 0x0e, 0x2c, + 0xcd, 0x0e, 0x3a, 0xba, 0x78, 0x47, 0xc4, 0x7f, 0x36, 0xa8, 0xd3, 0x16, 0xaf, 0x09, 0xca, 0x0b, + 0x12, 0xdf, 0xd5, 0xdf, 0x11, 0x2f, 0xf3, 0x7a, 0xb1, 0x26, 0xf8, 0xe3, 0xe1, 0xce, 0xaf, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x66, 0x7b, 0x0d, 0x72, 0xe1, 0x08, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -947,6 +978,15 @@ func (m *BeginBlockRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.StoreKeys) > 0 { + for iNdEx := len(m.StoreKeys) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.StoreKeys[iNdEx]) + copy(dAtA[i:], m.StoreKeys[iNdEx]) + i = encodeVarintServer(dAtA, i, uint64(len(m.StoreKeys[iNdEx]))) + i-- + dAtA[i] = 0x12 + } + } if m.Height != 0 { i = encodeVarintServer(dAtA, i, uint64(m.Height)) i-- @@ -975,6 +1015,15 @@ func (m *DeliverTxRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.StoreKeys) > 0 { + for iNdEx := len(m.StoreKeys) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.StoreKeys[iNdEx]) + copy(dAtA[i:], m.StoreKeys[iNdEx]) + i = encodeVarintServer(dAtA, i, uint64(len(m.StoreKeys[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } if m.Index != 0 { i = encodeVarintServer(dAtA, i, uint64(m.Index)) i-- @@ -1008,6 +1057,15 @@ func (m *EndBlockRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.StoreKeys) > 0 { + for iNdEx := len(m.StoreKeys) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.StoreKeys[iNdEx]) + copy(dAtA[i:], m.StoreKeys[iNdEx]) + i = encodeVarintServer(dAtA, i, uint64(len(m.StoreKeys[iNdEx]))) + i-- + dAtA[i] = 0x12 + } + } if m.Height != 0 { i = encodeVarintServer(dAtA, i, uint64(m.Height)) i-- @@ -1321,6 +1379,12 @@ func (m *BeginBlockRequest) Size() (n int) { if m.Height != 0 { n += 1 + sovServer(uint64(m.Height)) } + if len(m.StoreKeys) > 0 { + for _, s := range m.StoreKeys { + l = len(s) + n += 1 + l + sovServer(uint64(l)) + } + } return n } @@ -1336,6 +1400,12 @@ func (m *DeliverTxRequest) Size() (n int) { if m.Index != 0 { n += 1 + sovServer(uint64(m.Index)) } + if len(m.StoreKeys) > 0 { + for _, s := range m.StoreKeys { + l = len(s) + n += 1 + l + sovServer(uint64(l)) + } + } return n } @@ -1348,6 +1418,12 @@ func (m *EndBlockRequest) Size() (n int) { if m.Height != 0 { n += 1 + sovServer(uint64(m.Height)) } + if len(m.StoreKeys) > 0 { + for _, s := range m.StoreKeys { + l = len(s) + n += 1 + l + sovServer(uint64(l)) + } + } return n } @@ -1648,6 +1724,38 @@ func (m *BeginBlockRequest) Unmarshal(dAtA []byte) error { break } } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StoreKeys", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + 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 ErrInvalidLengthServer + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StoreKeys = append(m.StoreKeys, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipServer(dAtA[iNdEx:]) @@ -1736,6 +1844,38 @@ func (m *DeliverTxRequest) Unmarshal(dAtA []byte) error { break } } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StoreKeys", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + 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 ErrInvalidLengthServer + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StoreKeys = append(m.StoreKeys, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipServer(dAtA[iNdEx:]) @@ -1805,6 +1945,38 @@ func (m *EndBlockRequest) Unmarshal(dAtA []byte) error { break } } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StoreKeys", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowServer + } + 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 ErrInvalidLengthServer + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthServer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StoreKeys = append(m.StoreKeys, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipServer(dAtA[iNdEx:]) From e23d7d6ca4daccc114b4ded7e9834ff829b81b05 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Wed, 7 Jul 2021 12:47:55 -0500 Subject: [PATCH 44/46] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4ed9da3563d..5df735a3ada8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#9533](https://github.com/cosmos/cosmos-sdk/pull/9533) Added a new gRPC method, `DenomOwners`, in `x/bank` to query for all account holders of a specific denomination. * (bank) [\#9618](https://github.com/cosmos/cosmos-sdk/pull/9618) Update bank.Metadata: add URI and URIHash attributes. * (store) [\#8664](https://github.com/cosmos/cosmos-sdk/pull/8664) Implementation of ADR-038 file StreamingService +* (store) [\#9647](https://github.com/cosmos/cosmos-sdk/pull/9647) Implementation of ADR-038 file auxiliary gRPC server ### API Breaking Changes From e6da8c701f1609860b3bd1dd01874db92bb933d3 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Wed, 7 Jul 2021 12:57:46 -0500 Subject: [PATCH 45/46] linting fix --- store/streaming/file/server/cmd/root.go | 2 +- store/streaming/file/server/grpc/backend.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/store/streaming/file/server/cmd/root.go b/store/streaming/file/server/cmd/root.go index 3f3d57d03f0a..ca76434d63d0 100644 --- a/store/streaming/file/server/cmd/root.go +++ b/store/streaming/file/server/cmd/root.go @@ -111,7 +111,7 @@ func initConfig() { func logLevel() { lvl := parseLevel(viper.GetString(tomlFlagLogLevel)) zerolog.SetGlobalLevel(lvl) - log.Printf("Log level set to ", lvl.String()) + log.Printf("Log level set to %s", lvl.String()) } func parseLevel(lvlString string) zerolog.Level { diff --git a/store/streaming/file/server/grpc/backend.go b/store/streaming/file/server/grpc/backend.go index 6f0259d83c31..b300756dc94e 100644 --- a/store/streaming/file/server/grpc/backend.go +++ b/store/streaming/file/server/grpc/backend.go @@ -123,12 +123,12 @@ func (sfb *StateFileBackend) BackFillData(req *pb.StreamRequest, res chan<- *pb. case strings.Contains(fileName, "begin") && req.BeginBlock: readFlag = true res <- sfb.formBeginBlockResponse(fileName, req.StoreKeys) - case strings.Contains(fileName, "end") && req.EndBlock: - readFlag = true - res <- sfb.formEndBlockResponse(fileName, req.StoreKeys) case strings.Contains(fileName, "tx") && req.DeliverTx: readFlag = true res <- sfb.formDeliverTxResponse(fileName, req.StoreKeys) + case strings.Contains(fileName, "end") && req.EndBlock: + readFlag = true + res <- sfb.formEndBlockResponse(fileName, req.StoreKeys) default: } if sfb.conf.RemoveAfter && readFlag { From 2549cf0bf5b37ed40f5e99bedf39b84947cf3df9 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Wed, 7 Jul 2021 22:38:01 -0500 Subject: [PATCH 46/46] improve shutdown comms; improve readability; filter stream by file prefix + fixes --- store/streaming/file/server/cmd/root.go | 5 +- store/streaming/file/server/cmd/serve.go | 16 +-- store/streaming/file/server/config/config.go | 29 +++-- store/streaming/file/server/grpc/backend.go | 130 ++++++++++++------- store/streaming/file/server/grpc/handler.go | 32 +++-- 5 files changed, 130 insertions(+), 82 deletions(-) diff --git a/store/streaming/file/server/cmd/root.go b/store/streaming/file/server/cmd/root.go index ca76434d63d0..15478f5386e1 100644 --- a/store/streaming/file/server/cmd/root.go +++ b/store/streaming/file/server/cmd/root.go @@ -27,7 +27,7 @@ const ( var ( configPath string - serverCfg *config.StateServerConfig + serverCfg *config.StateFileServerConfig interfaceRegistry = codecTypes.NewInterfaceRegistry() marshaller = codec.NewProtoCodec(interfaceRegistry) ) @@ -37,6 +37,7 @@ var rootCmd = &cobra.Command{ PersistentPreRun: initFuncs, } +// Execute is the top level command entry point func Execute() { log.Print("----- Starting Cosmos state change file server -----") if err := rootCmd.Execute(); err != nil { @@ -79,7 +80,7 @@ func initFuncs(cmd *cobra.Command, args []string) { } func initConfig() { - serverCfg = config.DefaultStateServerConfig() + serverCfg = config.DefaultStateFileServerConfig() if configPath != "" { switch _, err := os.Stat(configPath); { case os.IsNotExist(err): diff --git a/store/streaming/file/server/cmd/serve.go b/store/streaming/file/server/cmd/serve.go index cac3205a5ee4..10b49d264a77 100644 --- a/store/streaming/file/server/cmd/serve.go +++ b/store/streaming/file/server/cmd/serve.go @@ -18,14 +18,6 @@ import ( ) const ( - tomlFlagRemoveAfter = "file-server.remove-after" - tomlFlagFilePrefix = "file-server.file-prefix" - tomlFlagReadDir = "file-server.read-dir" - tomlFlagChainID = "file-server.chain-id" - tomlFlagGRPCAddress = "file-server.grpc-address" - tomlFlagGRPCWebEnable = "file-server.grpc-web-enable" - tomlFlagGRPCWebAddress = "file-server.grpc-web-address" - cliFlagRemoveAfter = "remove-after" cliFlagFilePrefix = "file-prefix" cliFlagReadDir = "read-dir" @@ -33,6 +25,14 @@ const ( cliFlagGRPCAddress = "grpc-address" cliFlagGRPCWebEnable = "grpc-web-enable" cliFlagGRPCWebAddress = "grpc-web-address" + + tomlFlagRemoveAfter = "file-server.remove-after" + tomlFlagFilePrefix = "file-server.file-prefix" + tomlFlagReadDir = "file-server.read-dir" + tomlFlagChainID = "file-server.chain-id" + tomlFlagGRPCAddress = "file-server.grpc-address" + tomlFlagGRPCWebEnable = "file-server.grpc-web-enable" + tomlFlagGRPCWebAddress = "file-server.grpc-web-address" ) var ( diff --git a/store/streaming/file/server/config/config.go b/store/streaming/file/server/config/config.go index 1ba666b20c36..c285faa12251 100644 --- a/store/streaming/file/server/config/config.go +++ b/store/streaming/file/server/config/config.go @@ -20,7 +20,8 @@ const ( DefaultGRPCWebAddress = "0.0.0.0:9093" ) -type StateServerConfig struct { +// StateFileServerConfig contains configuration parameters for the state file server +type StateFileServerConfig struct { GRPCAddress string `mapstructure:"grpc-address"` GRPCWebEnabled bool `mapstructure:"grpc-web-enabled"` GRPCWebAddress string `mapstructure:"grpc-web-address"` @@ -32,18 +33,18 @@ type StateServerConfig struct { LogLevel string `mapstructure:"log-level"` } -// DefaultStateServerConfig returns the reference to ClientConfig with default values. -func DefaultStateServerConfig() *StateServerConfig { - return &StateServerConfig{ - DefaultGRPCAddress, - true, - DefaultGRPCWebAddress, - "", - DefaultReadDir, - "", - true, - "", - "info", +// DefaultStateFileServerConfig returns the reference to ClientConfig with default values. +func DefaultStateFileServerConfig() *StateFileServerConfig { + return &StateFileServerConfig{ + GRPCAddress: DefaultGRPCAddress, + GRPCWebEnabled: true, + GRPCWebAddress: DefaultGRPCWebAddress, + ChainID: "", + ReadDir: DefaultReadDir, + FilePrefix: "", + RemoveAfter: true, + LogFile: "", + LogLevel: "info", } } @@ -61,7 +62,7 @@ func init() { // WriteConfigFile renders config using the template and writes it to // configFilePath. -func WriteConfigFile(configFilePath string, config *StateServerConfig) { +func WriteConfigFile(configFilePath string, config *StateFileServerConfig) { var buffer bytes.Buffer if err := configTemplate.Execute(&buffer, config); err != nil { diff --git a/store/streaming/file/server/grpc/backend.go b/store/streaming/file/server/grpc/backend.go index b300756dc94e..5d540fe6a282 100644 --- a/store/streaming/file/server/grpc/backend.go +++ b/store/streaming/file/server/grpc/backend.go @@ -21,15 +21,17 @@ import ( "github.com/tendermint/tendermint/libs/log" ) +// StateFileBackend performs the state file reading and filtering to service Handler requests type StateFileBackend struct { - conf *config.StateServerConfig + conf *config.StateFileServerConfig codec *codec.ProtoCodec logger log.Logger trimPrefix string quitChan <-chan struct{} } -func NewStateFileBackend(conf *config.StateServerConfig, codec *codec.ProtoCodec, logger log.Logger, quitChan <-chan struct{}) *StateFileBackend { +// NewStateFileBackend returns a new StateFileBackend +func NewStateFileBackend(conf *config.StateFileServerConfig, codec *codec.ProtoCodec, logger log.Logger, quitChan <-chan struct{}) *StateFileBackend { trimPrefix := "block-" if conf.FilePrefix != "" { trimPrefix = fmt.Sprintf("%s-%s", conf.FilePrefix, trimPrefix) @@ -45,38 +47,42 @@ func NewStateFileBackend(conf *config.StateServerConfig, codec *codec.ProtoCodec // StreamData streams the requested state file data // this streams new data as it is written to disk -func (sfb *StateFileBackend) StreamData(req *pb.StreamRequest, res chan<- *pb.StreamResponse) error { +func (sfb *StateFileBackend) StreamData(req *pb.StreamRequest, res chan<- *pb.StreamResponse) (error, <-chan struct{}) { w, err := fsnotify.NewWatcher() if err != nil { - return err + return err, nil } + + done := make(chan struct{}) go func() { defer w.Close() + defer close(done) for { select { case event, ok := <-w.Events: - if !ok { + if !ok || event.Op != fsnotify.CloseWrite { continue } - if event.Op == fsnotify.CloseWrite { - fileName := event.Name - readFlag := false - switch { - case strings.Contains(fileName, "begin") && req.BeginBlock: - readFlag = true - res <- sfb.formBeginBlockResponse(fileName, req.StoreKeys) - case strings.Contains(fileName, "tx") && req.DeliverTx: - readFlag = true - res <- sfb.formDeliverTxResponse(fileName, req.StoreKeys) - case strings.Contains(fileName, "end") && req.EndBlock: - readFlag = true - res <- sfb.formEndBlockResponse(fileName, req.StoreKeys) - default: - } - if sfb.conf.RemoveAfter && readFlag { - if err := os.Remove(filepath.Join(sfb.conf.ReadDir, fileName)); err != nil { - sfb.logger.Error("unable to remove state change file", "err", err) - } + + fileName := event.Name + if sfb.conf.FilePrefix != "" && !strings.HasPrefix(fileName, sfb.conf.FilePrefix) { + continue + } + + switch { + case strings.Contains(fileName, "begin") && req.BeginBlock: + res <- sfb.formBeginBlockResponse(fileName, req.StoreKeys) + case strings.Contains(fileName, "tx") && req.DeliverTx: + res <- sfb.formDeliverTxResponse(fileName, req.StoreKeys) + case strings.Contains(fileName, "end") && req.EndBlock: + res <- sfb.formEndBlockResponse(fileName, req.StoreKeys) + default: + continue + } + + if sfb.conf.RemoveAfter { + if err := os.Remove(filepath.Join(sfb.conf.ReadDir, fileName)); err != nil { + sfb.logger.Error("unable to remove state change file", "err", err) } } case err, ok := <-w.Errors: @@ -90,55 +96,61 @@ func (sfb *StateFileBackend) StreamData(req *pb.StreamRequest, res chan<- *pb.St } } }() - return nil + return nil, done } // BackFillData stream the requested state file data // this stream data that is already written to disk -func (sfb *StateFileBackend) BackFillData(req *pb.StreamRequest, res chan<- *pb.StreamResponse) error { +func (sfb *StateFileBackend) BackFillData(req *pb.StreamRequest, res chan<- *pb.StreamResponse) (error, <-chan struct{}) { f, err := os.Open(sfb.conf.ReadDir) if err != nil { - return err + return err, nil } files, err := f.Readdir(-1) if err != nil { - return err + return err, nil } sort.Sort(filesByTimeModified(files)) + + done := make(chan struct{}) go func() { + defer close(done) for _, f := range files { - select { - // short circuit if the parent processes are shutting down + select { // short circuit if the parent processes are shutting down case <-sfb.quitChan: sfb.logger.Info("quiting StateFileBackend BackFillData process") return default: } + if f.IsDir() { continue } + fileName := f.Name() - readFlag := false + if sfb.conf.FilePrefix != "" && !strings.HasPrefix(fileName, sfb.conf.FilePrefix) { + continue + } + switch { case strings.Contains(fileName, "begin") && req.BeginBlock: - readFlag = true res <- sfb.formBeginBlockResponse(fileName, req.StoreKeys) case strings.Contains(fileName, "tx") && req.DeliverTx: - readFlag = true res <- sfb.formDeliverTxResponse(fileName, req.StoreKeys) case strings.Contains(fileName, "end") && req.EndBlock: - readFlag = true res <- sfb.formEndBlockResponse(fileName, req.StoreKeys) default: + continue } - if sfb.conf.RemoveAfter && readFlag { + + if sfb.conf.RemoveAfter { if err := os.Remove(filepath.Join(sfb.conf.ReadDir, fileName)); err != nil { sfb.logger.Error("unable to remove state change file", "err", err) } } } }() - return nil + return nil, done } // BeginBlockDataAt returns a BeginBlockPayload for the provided BeginBlockRequest @@ -168,20 +180,6 @@ func (sfb *StateFileBackend) EndBlockDataAt(ctx context.Context, req *pb.EndBloc return sfb.formEndBlockPayload(fileName, req.StoreKeys) } -type filesByTimeModified []os.FileInfo - -func (fs filesByTimeModified) Len() int { - return len(fs) -} - -func (fs filesByTimeModified) Swap(i, j int) { - fs[i], fs[j] = fs[j], fs[i] -} - -func (fs filesByTimeModified) Less(i, j int) bool { - return fs[i].ModTime().Before(fs[j].ModTime()) -} - func (sfb *StateFileBackend) formBeginBlockResponse(fileName string, storeKeys []string) *pb.StreamResponse { res := new(pb.StreamResponse) res.ChainId = sfb.conf.ChainID @@ -192,6 +190,7 @@ func (sfb *StateFileBackend) formBeginBlockResponse(fileName string, storeKeys [ return res } res.Height = blockHeight + bbp, err := sfb.formBeginBlockPayload(fileName, storeKeys) if err != nil { res.Err = err.Error() @@ -213,14 +212,17 @@ func (sfb *StateFileBackend) formBeginBlockPayload(fileName string, storeKeys [] if len(messageBytes) < 2 { return nil, fmt.Errorf("expected at least two protobuf messages, got %d", len(messageBytes)) } + beginBlockReq := new(abci.RequestBeginBlock) if err := sfb.codec.Unmarshal(messageBytes[0], beginBlockReq); err != nil { return nil, err } + beginBlockRes := new(abci.ResponseBeginBlock) if err := sfb.codec.Unmarshal(messageBytes[len(messageBytes)-1], beginBlockRes); err != nil { return nil, err } + kvPairs := make([]*types.StoreKVPair, 0, len(messageBytes[1:len(messageBytes)-2])) for i := 1; i < len(messageBytes)-1; i++ { kvPair := new(types.StoreKVPair) @@ -231,6 +233,7 @@ func (sfb *StateFileBackend) formBeginBlockPayload(fileName string, storeKeys [] kvPairs = append(kvPairs, kvPair) } } + return &pb.BeginBlockPayload{ Request: beginBlockReq, Response: beginBlockRes, @@ -248,6 +251,7 @@ func (sfb *StateFileBackend) formDeliverTxResponse(fileName string, storeKeys [] return res } res.Height = blockHeight + dtp, err := sfb.formDeliverTxPayload(fileName, storeKeys) if err != nil { res.Err = err.Error() @@ -269,14 +273,17 @@ func (sfb *StateFileBackend) formDeliverTxPayload(fileName string, storeKeys []s if len(messageBytes) < 2 { return nil, fmt.Errorf("expected at least two protobuf messages, got %d", len(messageBytes)) } + deliverTxReq := new(abci.RequestDeliverTx) if err := sfb.codec.Unmarshal(messageBytes[0], deliverTxReq); err != nil { return nil, err } + deliverTxRes := new(abci.ResponseDeliverTx) if err := sfb.codec.Unmarshal(messageBytes[len(messageBytes)-1], deliverTxRes); err != nil { return nil, err } + kvPairs := make([]*types.StoreKVPair, 0, len(messageBytes[1:len(messageBytes)-2])) for i := 1; i < len(messageBytes)-1; i++ { kvPair := new(types.StoreKVPair) @@ -287,6 +294,7 @@ func (sfb *StateFileBackend) formDeliverTxPayload(fileName string, storeKeys []s kvPairs = append(kvPairs, kvPair) } } + return &pb.DeliverTxPayload{ Request: deliverTxReq, Response: deliverTxRes, @@ -304,6 +312,7 @@ func (sfb *StateFileBackend) formEndBlockResponse(fileName string, storeKeys []s return res } res.Height = blockHeight + ebp, err := sfb.formEndBlockPayload(fileName, storeKeys) if err != nil { res.Err = err.Error() @@ -325,14 +334,17 @@ func (sfb *StateFileBackend) formEndBlockPayload(fileName string, storeKeys []st if len(messageBytes) < 2 { return nil, fmt.Errorf("expected at least two protobuf messages, got %d", len(messageBytes)) } + endBlockReq := new(abci.RequestEndBlock) if err := sfb.codec.Unmarshal(messageBytes[0], endBlockReq); err != nil { return nil, err } + endBlockRes := new(abci.ResponseEndBlock) if err := sfb.codec.Unmarshal(messageBytes[len(messageBytes)-1], endBlockRes); err != nil { return nil, err } + kvPairs := make([]*types.StoreKVPair, 0, len(messageBytes[1:len(messageBytes)-2])) for i := 1; i < len(messageBytes)-1; i++ { kvPair := new(types.StoreKVPair) @@ -343,6 +355,7 @@ func (sfb *StateFileBackend) formEndBlockPayload(fileName string, storeKeys []st kvPairs = append(kvPairs, kvPair) } } + return &pb.EndBlockPayload{ Request: endBlockReq, Response: endBlockRes, @@ -365,3 +378,20 @@ func listIsEmptyOrContains(list []string, str string) bool { } return false } + +type filesByTimeModified []os.FileInfo + +// Len satisfies sort.Interface +func (fs filesByTimeModified) Len() int { + return len(fs) +} + +// Swap satisfies sort.Interface +func (fs filesByTimeModified) Swap(i, j int) { + fs[i], fs[j] = fs[j], fs[i] +} + +// Less satisfies sort.Interface +func (fs filesByTimeModified) Less(i, j int) bool { + return fs[i].ModTime().Before(fs[j].ModTime()) +} diff --git a/store/streaming/file/server/grpc/handler.go b/store/streaming/file/server/grpc/handler.go index 0823bcc05a78..9153c48873ab 100644 --- a/store/streaming/file/server/grpc/handler.go +++ b/store/streaming/file/server/grpc/handler.go @@ -9,12 +9,13 @@ import ( "github.com/tendermint/tendermint/libs/log" ) +// Handler wraps the StateFileServer interface with an additional Stop() method type Handler interface { pb.StateFileServer Stop() } -// handler is the interface which exposes the StateFile Server methods +// handler is the struct which implements the Handler methods type handler struct { pb.UnimplementedStateFileServer backend *StateFileBackend @@ -23,7 +24,7 @@ type handler struct { } // NewHandler returns the object for the gRPC handler -func NewHandler(conf *config.StateServerConfig, codec *codec.ProtoCodec, logger log.Logger) (Handler, error) { +func NewHandler(conf *config.StateFileServerConfig, codec *codec.ProtoCodec, logger log.Logger) (Handler, error) { quitChan := make(chan struct{}) return &handler{ backend: NewStateFileBackend(conf, codec, logger, quitChan), @@ -32,11 +33,13 @@ func NewHandler(conf *config.StateServerConfig, codec *codec.ProtoCodec, logger }, nil } +// StreamData implements StateFileServer // StreamData streams the requested state file data // this streams new data as it is written to disk func (h *handler) StreamData(req *pb.StreamRequest, srv pb.StateFile_StreamDataServer) error { resChan := make(chan *pb.StreamResponse) - if err := h.backend.StreamData(req, resChan); err != nil { + err, done := h.backend.StreamData(req, resChan) + if err != nil { return err } for { @@ -45,17 +48,23 @@ func (h *handler) StreamData(req *pb.StreamRequest, srv pb.StateFile_StreamDataS if err := srv.Send(res); err != nil { h.logger.Error("StreamData send error", "err", err) } - case <-h.quitChan: + // if Close() is called the backend process will quit and close this channel + // so we don't need a select case for h.quitChan here + // this way we wait for the backend to finish sending before shutting down the handler + case <-done: + h.logger.Info("quiting handler StreamData process") return nil } } } -// BackFillData stream the requested state file data -// this stream data that is already written to disk +// BackFillData implements StateFileServer +// BackFillData streams the requested state file data +// this streams data that is already written to disk func (h *handler) BackFillData(req *pb.StreamRequest, srv pb.StateFile_BackFillDataServer) error { resChan := make(chan *pb.StreamResponse) - if err := h.backend.BackFillData(req, resChan); err != nil { + err, done := h.backend.BackFillData(req, resChan) + if err != nil { return err } for { @@ -64,22 +73,29 @@ func (h *handler) BackFillData(req *pb.StreamRequest, srv pb.StateFile_BackFillD if err := srv.Send(res); err != nil { h.logger.Error("BackFillData send error", "err", err) } - case <-h.quitChan: + // if Close() is called the backend process will quit and close this channel + // so we don't need a select case for h.quitChan here + // this way we wait for the backend to finish sending before shutting down the handler + case <-done: + h.logger.Info("quiting handler BackFillData process") return nil } } } +// BeginBlockDataAt implements StateFileServer // BeginBlockDataAt returns a BeginBlockPayload for the provided BeginBlockRequest func (h *handler) BeginBlockDataAt(ctx context.Context, req *pb.BeginBlockRequest) (*pb.BeginBlockPayload, error) { return h.backend.BeginBlockDataAt(ctx, req) } +// DeliverTxDataAt implements StateFileServer // DeliverTxDataAt returns a DeliverTxPayload for the provided BeginBlockRequest func (h *handler) DeliverTxDataAt(ctx context.Context, req *pb.DeliverTxRequest) (*pb.DeliverTxPayload, error) { return h.backend.DeliverTxDataAt(ctx, req) } +// EndBlockDataAt implements StateFileServer // EndBlockDataAt returns a EndBlockPayload for the provided EndBlockRequest func (h *handler) EndBlockDataAt(ctx context.Context, req *pb.EndBlockRequest) (*pb.EndBlockPayload, error) { return h.backend.EndBlockDataAt(ctx, req)