Skip to content

Commit

Permalink
Removed Bloom from Header and filter now uses bloom from db
Browse files Browse the repository at this point in the history
  • Loading branch information
jdowning100 committed Jun 20, 2023
1 parent cd507f4 commit 8193e30
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 45 deletions.
6 changes: 0 additions & 6 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
return fmt.Errorf("invalid gas used (remote: %d local: %d)", block.GasUsed(), usedGas)
}
time2 := common.PrettyDuration(time.Since(start))
// Validate the received block's bloom with the one derived from the generated receipts.
// For valid blocks this should always validate to true.
rbloom := types.CreateBloom(receipts)
if rbloom != header.Bloom() {
return fmt.Errorf("invalid bloom (remote: %x local: %x)", header.Bloom(), rbloom)
}
time3 := common.PrettyDuration(time.Since(start))
// Tre receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, Rn]]))
receiptSha := types.DeriveSha(receipts, trie.NewStackTrie(nil))
Expand Down
1 change: 0 additions & 1 deletion core/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,6 @@ func (sl *Slice) combinePendingHeader(header *types.Header, slPendingHeader *typ
combinedPendingHeader.SetReceiptHash(header.ReceiptHash())
combinedPendingHeader.SetRoot(header.Root())
combinedPendingHeader.SetCoinbase(header.Coinbase())
combinedPendingHeader.SetBloom(header.Bloom())
combinedPendingHeader.SetBaseFee(header.BaseFee())
combinedPendingHeader.SetGasLimit(header.GasLimit())
combinedPendingHeader.SetGasUsed(header.GasUsed())
Expand Down
18 changes: 0 additions & 18 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ type Header struct {
etxRollupHash common.Hash `json:"extRollupRoot" gencodec:"required"`
manifestHash []common.Hash `json:"manifestHash" gencodec:"required"`
receiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
bloom Bloom `json:"logsBloom" gencodec:"required"`
difficulty *big.Int `json:"difficulty" gencodec:"required"`
parentEntropy []*big.Int `json:"parentEntropy" gencodec:"required"`
parentDeltaS []*big.Int `json:"parentDeltaS" gencodec:"required"`
Expand Down Expand Up @@ -139,7 +138,6 @@ type extheader struct {
EtxRollupHash common.Hash
ManifestHash []common.Hash
ReceiptHash common.Hash
Bloom Bloom
Difficulty *big.Int
ParentEntropy []*big.Int
ParentDeltaS []*big.Int
Expand Down Expand Up @@ -193,7 +191,6 @@ func (h *Header) DecodeRLP(s *rlp.Stream) error {
h.etxRollupHash = eh.EtxRollupHash
h.manifestHash = eh.ManifestHash
h.receiptHash = eh.ReceiptHash
h.bloom = eh.Bloom
h.difficulty = eh.Difficulty
h.parentEntropy = eh.ParentEntropy
h.parentDeltaS = eh.ParentDeltaS
Expand Down Expand Up @@ -221,7 +218,6 @@ func (h *Header) EncodeRLP(w io.Writer) error {
EtxRollupHash: h.etxRollupHash,
ManifestHash: h.manifestHash,
ReceiptHash: h.receiptHash,
Bloom: h.bloom,
Difficulty: h.difficulty,
ParentEntropy: h.parentEntropy,
ParentDeltaS: h.parentDeltaS,
Expand All @@ -244,7 +240,6 @@ func (h *Header) RPCMarshalHeader() map[string]interface{} {
"difficulty": (*hexutil.Big)(h.Difficulty()),
"nonce": h.Nonce(),
"sha3Uncles": h.UncleHash(),
"logsBloom": h.Bloom(),
"stateRoot": h.Root(),
"miner": h.Coinbase(),
"extraData": hexutil.Bytes(h.Extra()),
Expand Down Expand Up @@ -332,9 +327,6 @@ func (h *Header) ManifestHash(args ...int) common.Hash {
func (h *Header) ReceiptHash() common.Hash {
return h.receiptHash
}
func (h *Header) Bloom() Bloom {
return h.bloom
}
func (h *Header) Difficulty() *big.Int {
return h.difficulty
}
Expand Down Expand Up @@ -441,11 +433,6 @@ func (h *Header) SetReceiptHash(val common.Hash) {
h.sealHash = atomic.Value{} // clear sealHash cache
h.receiptHash = val
}
func (h *Header) SetBloom(val Bloom) {
h.hash = atomic.Value{} // clear hash cache
h.sealHash = atomic.Value{} // clear sealHash cache
h.bloom = val
}
func (h *Header) SetDifficulty(val *big.Int) {
h.hash = atomic.Value{} // clear hash cache
h.sealHash = atomic.Value{} // clear sealHash cache
Expand Down Expand Up @@ -515,7 +502,6 @@ type sealData struct {
EtxRollupHash common.Hash
ManifestHash []common.Hash
ReceiptHash common.Hash
Bloom Bloom
Number []*big.Int
GasLimit uint64
GasUsed uint64
Expand Down Expand Up @@ -545,7 +531,6 @@ func (h *Header) SealHash() (hash common.Hash) {
EtxRollupHash: h.EtxRollupHash(),
ManifestHash: make([]common.Hash, common.HierarchyDepth),
ReceiptHash: h.ReceiptHash(),
Bloom: h.Bloom(),
Number: make([]*big.Int, common.HierarchyDepth),
GasLimit: h.GasLimit(),
GasUsed: h.GasUsed(),
Expand Down Expand Up @@ -854,7 +839,6 @@ func NewBlock(header *Header, txs []*Transaction, uncles []*Header, etxs []*Tran
b.header.SetReceiptHash(EmptyRootHash)
} else {
b.header.SetReceiptHash(DeriveSha(Receipts(receipts), hasher))
b.header.SetBloom(CreateBloom(receipts))
}

if len(uncles) == 0 {
Expand Down Expand Up @@ -922,7 +906,6 @@ func CopyHeader(h *Header) *Header {
cpy.SetEtxHash(h.EtxHash())
cpy.SetEtxRollupHash(h.EtxRollupHash())
cpy.SetReceiptHash(h.ReceiptHash())
cpy.SetBloom(h.Bloom())
if len(h.extra) > 0 {
cpy.extra = make([]byte, len(h.extra))
copy(cpy.extra, h.extra)
Expand Down Expand Up @@ -970,7 +953,6 @@ func (b *Block) EtxHash() common.Hash { return b.header.EtxHash(
func (b *Block) EtxRollupHash() common.Hash { return b.header.EtxRollupHash() }
func (b *Block) ManifestHash(args ...int) common.Hash { return b.header.ManifestHash(args...) }
func (b *Block) ReceiptHash() common.Hash { return b.header.ReceiptHash() }
func (b *Block) Bloom() Bloom { return b.header.Bloom() }
func (b *Block) Difficulty(args ...int) *big.Int { return b.header.Difficulty() }
func (b *Block) ParentEntropy(args ...int) *big.Int { return b.header.ParentEntropy(args...) }
func (b *Block) ParentDeltaS(args ...int) *big.Int { return b.header.ParentDeltaS(args...) }
Expand Down
7 changes: 0 additions & 7 deletions core/types/gen_header_json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ func (b *QuaiAPIBackend) GetReceipts(ctx context.Context, hash common.Hash) (typ
return b.eth.core.GetReceiptsByHash(hash), nil
}

// GetBloom returns the bloom for the given block hash
func (b *QuaiAPIBackend) GetBloom(hash common.Hash) (*types.Bloom, error) {
nodeCtx := common.NodeLocation.Context()
if nodeCtx != common.ZONE_CTX {
return nil, errors.New("getBloom can only be called in zone chain")
}
return b.eth.core.Slice().HeaderChain().GetBloom(hash)
}

func (b *QuaiAPIBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error) {
nodeCtx := common.NodeLocation.Context()
if nodeCtx != common.ZONE_CTX {
Expand Down
2 changes: 1 addition & 1 deletion eth/filters/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func benchmarkBloomBits(b *testing.B, sectionSize uint64) {
if header == nil {
b.Fatalf("Error creating bloomBits data")
}
bc.AddBloom(uint(i-sectionIdx*sectionSize), header.Bloom())
bc.AddBloom(uint(i-sectionIdx*sectionSize), types.Bloom{})
}
sectionHead := rawdb.ReadCanonicalHash(db, (sectionIdx+1)*sectionSize-1)
for i := 0; i < types.BloomBitLength; i++ {
Expand Down
9 changes: 7 additions & 2 deletions eth/filters/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Backend interface {
HeaderByHash(ctx context.Context, blockHash common.Hash) (*types.Header, error)
GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error)
GetLogs(ctx context.Context, blockHash common.Hash) ([][]*types.Log, error)

GetBloom(blockHash common.Hash) (*types.Bloom, error)
SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription
SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription
Expand Down Expand Up @@ -232,7 +232,12 @@ func (f *Filter) unindexedLogs(ctx context.Context, end uint64) ([]*types.Log, e

// blockLogs returns the logs matching the filter criteria within a single block.
func (f *Filter) blockLogs(ctx context.Context, header *types.Header) (logs []*types.Log, err error) {
if bloomFilter(header.Bloom(), f.addresses, f.topics) {
// Get block bloom from the database
bloom, err := f.backend.GetBloom(header.Hash())
if err != nil {
return logs, err
}
if bloomFilter(*bloom, f.addresses, f.topics) {
found, err := f.checkMatches(ctx, header)
if err != nil {
return logs, err
Expand Down
6 changes: 5 additions & 1 deletion eth/filters/filter_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,11 @@ func (es *EventSystem) lightFilterNewHead(newHeader *types.Header, callBack func

// filter logs of a single header in light client mode
func (es *EventSystem) lightFilterLogs(header *types.Header, addresses []common.Address, topics [][]common.Hash, remove bool) []*types.Log {
if bloomFilter(header.Bloom(), addresses, topics) {
bloom, err := es.backend.GetBloom(header.Hash())
if err != nil {
return nil
}
if bloomFilter(*bloom, addresses, topics) {
// Get the logs of the block
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
Expand Down
1 change: 0 additions & 1 deletion internal/quaiapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,6 @@ func RPCMarshalETHHeader(head *types.Header) map[string]interface{} {
"parentHash": head.ParentHash,
"nonce": head.Nonce,
"sha3Uncles": head.UncleHash,
"logsBloom": head.Bloom,
"stateRoot": head.Root,
"miner": head.Coinbase,
"difficulty": (*hexutil.Big)(head.Difficulty()),
Expand Down
10 changes: 5 additions & 5 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (

// Genesis hashes to enforce below configs on.
var (
ColosseumGenesisHash = common.HexToHash("0x6b3c28921a94aa0b17240fe8144e7936c870069143195438f2360521cb73f5a1")
GardenGenesisHash = common.HexToHash("0x511bf6bbaa9400c6ade6e0e4968d85e9ed65af5777513336317b95b89e9c2dbb")
OrchardGenesisHash = common.HexToHash("0xb998fb9bf1e027f09efef05fdb6276a31156068592e6a989348ffb4c0d4387f7")
LocalGenesisHash = common.HexToHash("0x4c35b1216decc6aa2431fa2d2a1c68f15d70f83a309041ed1bfef5ad6592a3d4")
GalenaGenesisHash = common.HexToHash("0xce6c6393558ee45d8a38e1f04eb5ad33823ab9ea1122cdba747ce41d87ccdb92")
ColosseumGenesisHash = common.HexToHash("0xf4ccaa291097df67e2d98a1369955d14085f9241a5018d2bef532dc84c0039c6")
GardenGenesisHash = common.HexToHash("0x6210219b7847439325215a2d17182b801d9cc8efc2b0004d9511d37ef623405b")
OrchardGenesisHash = common.HexToHash("0xc0fc30c7860b8f4ec7a8fe1a54dfcbca17167eca5bdcbdc077b6d50addf79763")
LocalGenesisHash = common.HexToHash("0xb1eb552366e4083a11585418c4b193f024985d45b23103f0653416de083a6512")
GalenaGenesisHash = common.HexToHash("0xac2b5abb66351e833123c3364283020cadb33df906252b0f86a081ae11e0fab9")
)

var (
Expand Down
3 changes: 0 additions & 3 deletions tests/block_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,6 @@ func (t *BlockTest) insertBlocks(blockchain *core.BlockChain) ([]btBlock, error)
}

func validateHeader(h *btHeader, h2 *types.Header) error {
if h.Bloom() != h2.Bloom() {
return fmt.Errorf("bloom: want: %x have: %x", h.Bloom(), h2.Bloom())
}
if h.Coinbase() != h2.Coinbase() {
return fmt.Errorf("coinbase: want: %x have: %x", h.Coinbase(), h2.Coinbase())
}
Expand Down

0 comments on commit 8193e30

Please sign in to comment.