Skip to content

Commit

Permalink
rlps: refactor. remove e2pg dep
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandotsmith committed Oct 12, 2023
1 parent e59a57a commit 6af704a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions e2pg/e2pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ func (g *Geth) Latest() (uint64, []byte, error) {
return bint.Uint64(n), h, nil
}

func Skip(filter [][]byte, bf bloom.Filter) bool {
func skip(filter [][]byte, bf bloom.Filter) bool {
if len(filter) == 0 {
return false
}
Expand All @@ -513,7 +513,7 @@ func (g *Geth) LoadBlocks(filter [][]byte, bfs []geth.Buffer, blks []eth.Block)
}
for i := range blks {
blks[i].Header.UnmarshalRLP(bfs[i].Header())
if Skip(filter, bloom.Filter(blks[i].Header.LogsBloom)) {
if skip(filter, bloom.Filter(blks[i].Header.LogsBloom)) {
continue
}
//rlp contains: [transactions,uncles]
Expand Down
15 changes: 13 additions & 2 deletions rlps/rlps.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/indexsupply/x/bint"
"github.com/indexsupply/x/bloom"
"github.com/indexsupply/x/e2pg"
"github.com/indexsupply/x/eth"
"github.com/indexsupply/x/freezer"
"github.com/indexsupply/x/geth"
Expand Down Expand Up @@ -181,7 +180,7 @@ func (s *Server) get(filter [][]byte, n, limit uint64) ([]byte, error) {
block := eth.Block{}
block.UnmarshalRLP(hrlp)
switch {
case e2pg.Skip(filter, bloom.Filter(block.LogsBloom)):
case skip(filter, bloom.Filter(block.LogsBloom)):
res[i] = rlp.List(rlp.Encode(hrlp, zero, zero))
default:
res[i] = rlp.List(rlp.Encode(
Expand All @@ -194,6 +193,18 @@ func (s *Server) get(filter [][]byte, n, limit uint64) ([]byte, error) {
return rlp.List(res...), nil
}

func skip(filter [][]byte, bf bloom.Filter) bool {
if len(filter) == 0 {
return false
}
for i := range filter {
if !bf.Missing(filter[i]) {
return false
}
}
return true
}

func (s *Server) Index(w http.ResponseWriter, r *http.Request) {
num, hash, err := geth.Latest(s.rc)
if err != nil {
Expand Down

0 comments on commit 6af704a

Please sign in to comment.