From 67df8dea77ced2abb13bb20f13d1d82f4b6aec2e Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 8 Oct 2019 15:31:07 -0500 Subject: [PATCH] header_cids.final => header_cids.uncle --- cmd/streamSubscribe.go | 4 ++-- db/migrations/00031_create_header_cids_table.sql | 2 +- documentation/super-node.md | 6 +++--- pkg/config/subscription.go | 4 ++-- pkg/ipfs/resolver_test.go | 3 +-- pkg/super_node/filterer.go | 2 +- pkg/super_node/repository.go | 12 ++++++------ pkg/super_node/repository_test.go | 2 +- pkg/super_node/retriever.go | 6 +++--- 9 files changed, 20 insertions(+), 21 deletions(-) diff --git a/cmd/streamSubscribe.go b/cmd/streamSubscribe.go index 710d66ce..998e8d27 100644 --- a/cmd/streamSubscribe.go +++ b/cmd/streamSubscribe.go @@ -175,8 +175,8 @@ func configureSubscription() { // Below default to false, which means we get all headers by default HeaderFilter: config.HeaderFilter{ - Off: viper.GetBool("subscription.headerFilter.off"), - FinalOnly: viper.GetBool("subscription.headerFilter.finalOnly"), + Off: viper.GetBool("subscription.headerFilter.off"), + Uncles: viper.GetBool("subscription.headerFilter.uncles"), }, // Below defaults to false and two slices of length 0 diff --git a/db/migrations/00031_create_header_cids_table.sql b/db/migrations/00031_create_header_cids_table.sql index 331867c1..8d63f299 100644 --- a/db/migrations/00031_create_header_cids_table.sql +++ b/db/migrations/00031_create_header_cids_table.sql @@ -4,7 +4,7 @@ CREATE TABLE public.header_cids ( block_number BIGINT NOT NULL, block_hash VARCHAR(66) NOT NULL, cid TEXT NOT NULL, - final BOOLEAN NOT NULL, + uncle BOOLEAN NOT NULL, UNIQUE (block_number, block_hash) ); diff --git a/documentation/super-node.md b/documentation/super-node.md index 927a83db..cf53d9f3 100644 --- a/documentation/super-node.md +++ b/documentation/super-node.md @@ -273,7 +273,7 @@ The config for `streamSubscribe` has the `subscribe` set of parameters, for exam endingBlock = 0 [subscription.headerFilter] off = false - finalOnly = true + uncles = false [subscription.trxFilter] off = false src = [ @@ -320,8 +320,8 @@ send that to the subscriber, if this is set to `false` then the super-node only `subscription.endingBlock` is the ending block number for the range we want to receive data in; setting to 0 means there is no end/we will continue indefinitely. -`subscription.headerFilter` has two sub-options: `off` and `finalOnly`. Setting `off` to true tells the super-node to -not send any headers to the subscriber; setting `finalOnly` to true tells the super-node to send only canonical headers. +`subscription.headerFilter` has two sub-options: `off` and `uncles`. Setting `off` to true tells the super-node to +not send any headers to the subscriber; setting `uncles` to true tells the super-node to send uncles in addition to normal headers. `subscription.trxFilter` has three sub-options: `off`, `src`, and `dst`. Setting `off` to true tells the super-node to not send any transactions to the subscriber; `src` and `dst` are string arrays which can be filled with ETH addresses we want to filter transactions for, diff --git a/pkg/config/subscription.go b/pkg/config/subscription.go index e6a160fb..29d87456 100644 --- a/pkg/config/subscription.go +++ b/pkg/config/subscription.go @@ -32,8 +32,8 @@ type Subscription struct { } type HeaderFilter struct { - Off bool - FinalOnly bool + Off bool + Uncles bool } type TrxFilter struct { diff --git a/pkg/ipfs/resolver_test.go b/pkg/ipfs/resolver_test.go index 1c07f388..d8adb6a2 100644 --- a/pkg/ipfs/resolver_test.go +++ b/pkg/ipfs/resolver_test.go @@ -35,8 +35,7 @@ var _ = Describe("Resolver", func() { resolver = ipfs.NewIPLDResolver() }) It("Resolves IPLD data to their correct geth data types and packages them to send to requesting transformers", func() { - superNodePayload, err := resolver.ResolveIPLDs(mocks.MockIPLDWrapper) - Expect(err).ToNot(HaveOccurred()) + superNodePayload := resolver.ResolveIPLDs(mocks.MockIPLDWrapper) Expect(superNodePayload.BlockNumber.Int64()).To(Equal(mocks.MockSeeNodePayload.BlockNumber.Int64())) Expect(superNodePayload.HeadersRlp).To(Equal(mocks.MockSeeNodePayload.HeadersRlp)) Expect(superNodePayload.UnclesRlp).To(Equal(mocks.MockSeeNodePayload.UnclesRlp)) diff --git a/pkg/super_node/filterer.go b/pkg/super_node/filterer.go index 7d9c105d..58bf1be8 100644 --- a/pkg/super_node/filterer.go +++ b/pkg/super_node/filterer.go @@ -71,7 +71,7 @@ func (s *Filterer) FilterResponse(streamFilters config.Subscription, payload ipf func (s *Filterer) filterHeaders(streamFilters config.Subscription, response *streamer.SuperNodePayload, payload ipfs.IPLDPayload) error { if !streamFilters.HeaderFilter.Off && checkRange(streamFilters.StartingBlock.Int64(), streamFilters.EndingBlock.Int64(), payload.BlockNumber.Int64()) { response.HeadersRlp = append(response.HeadersRlp, payload.HeaderRLP) - if !streamFilters.HeaderFilter.FinalOnly { + if streamFilters.HeaderFilter.Uncles { for _, uncle := range payload.BlockBody.Uncles { uncleRlp, err := rlp.EncodeToBytes(uncle) if err != nil { diff --git a/pkg/super_node/repository.go b/pkg/super_node/repository.go index 48366362..5a824b37 100644 --- a/pkg/super_node/repository.go +++ b/pkg/super_node/repository.go @@ -87,17 +87,17 @@ func (repo *Repository) Index(cidPayload *ipfs.CIDPayload) error { func (repo *Repository) indexHeaderCID(tx *sqlx.Tx, cid, blockNumber, hash string) (int64, error) { var headerID int64 - err := tx.QueryRowx(`INSERT INTO public.header_cids (block_number, block_hash, cid, final) VALUES ($1, $2, $3, $4) - ON CONFLICT (block_number, block_hash) DO UPDATE SET (cid, final) = ($3, $4) + err := tx.QueryRowx(`INSERT INTO public.header_cids (block_number, block_hash, cid, uncle) VALUES ($1, $2, $3, $4) + ON CONFLICT (block_number, block_hash) DO UPDATE SET (cid, uncle) = ($3, $4) RETURNING id`, - blockNumber, hash, cid, true).Scan(&headerID) + blockNumber, hash, cid, false).Scan(&headerID) return headerID, err } func (repo *Repository) indexUncleCID(tx *sqlx.Tx, cid, blockNumber, hash string) error { - _, err := tx.Exec(`INSERT INTO public.header_cids (block_number, block_hash, cid, final) VALUES ($1, $2, $3, $4) - ON CONFLICT (block_number, block_hash) DO UPDATE SET (cid, final) = ($3, $4)`, - blockNumber, hash, cid, false) + _, err := tx.Exec(`INSERT INTO public.header_cids (block_number, block_hash, cid, uncle) VALUES ($1, $2, $3, $4) + ON CONFLICT (block_number, block_hash) DO UPDATE SET (cid, uncle) = ($3, $4)`, + blockNumber, hash, cid, true) return err } diff --git a/pkg/super_node/repository_test.go b/pkg/super_node/repository_test.go index 816797d6..61a8d34c 100644 --- a/pkg/super_node/repository_test.go +++ b/pkg/super_node/repository_test.go @@ -47,7 +47,7 @@ var _ = Describe("Repository", func() { err = repo.Index(mocks.MockCIDPayload) Expect(err).ToNot(HaveOccurred()) pgStr := `SELECT cid FROM header_cids - WHERE block_number = $1 AND final IS TRUE` + WHERE block_number = $1 AND uncle IS FALSE` // check header was properly indexed headers := make([]string, 0) err = db.Select(&headers, pgStr, 1) diff --git a/pkg/super_node/retriever.go b/pkg/super_node/retriever.go index d17dd835..4d3be107 100644 --- a/pkg/super_node/retriever.go +++ b/pkg/super_node/retriever.go @@ -86,7 +86,7 @@ func (ecr *EthCIDRetriever) RetrieveCIDs(streamFilters config.Subscription, bloc log.Error("header cid retrieval error") return nil, headersErr } - if !streamFilters.HeaderFilter.FinalOnly { + if streamFilters.HeaderFilter.Uncles { var unclesErr error cw.Uncles, unclesErr = ecr.retrieveUncleCIDs(tx, streamFilters, blockNumber) if unclesErr != nil { @@ -164,7 +164,7 @@ func (ecr *EthCIDRetriever) retrieveHeaderCIDs(tx *sqlx.Tx, streamFilters config log.Debug("retrieving header cids for block ", blockNumber) headers := make([]string, 0) pgStr := `SELECT cid FROM header_cids - WHERE block_number = $1 AND final IS TRUE` + WHERE block_number = $1 AND uncle IS FALSE` err := tx.Select(&headers, pgStr, blockNumber) return headers, err } @@ -173,7 +173,7 @@ func (ecr *EthCIDRetriever) retrieveUncleCIDs(tx *sqlx.Tx, streamFilters config. log.Debug("retrieving header cids for block ", blockNumber) headers := make([]string, 0) pgStr := `SELECT cid FROM header_cids - WHERE block_number = $1 AND final IS FALSE` + WHERE block_number = $1 AND uncle IS TRUE` err := tx.Select(&headers, pgStr, blockNumber) return headers, err }