mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
chg: use sprint from genesis
This commit is contained in:
parent
7cea144782
commit
be23d02c9e
4 changed files with 46 additions and 13 deletions
|
|
@ -297,6 +297,13 @@ func (s *Ethereum) APIs() []rpc.API {
|
|||
// Append any APIs exposed explicitly by the consensus engine
|
||||
apis = append(apis, s.engine.APIs(s.BlockChain())...)
|
||||
|
||||
// BOR change starts
|
||||
// set genesis to public filter api
|
||||
publicFilterAPI := filters.NewPublicFilterAPI(s.APIBackend, false)
|
||||
// avoiding constructor changed by introducing new method to set genesis
|
||||
publicFilterAPI.SetChainConfig(s.blockchain.Config())
|
||||
// BOR change ends
|
||||
|
||||
// Append all the local APIs and return
|
||||
return append(apis, []rpc.API{
|
||||
{
|
||||
|
|
@ -322,7 +329,7 @@ func (s *Ethereum) APIs() []rpc.API {
|
|||
}, {
|
||||
Namespace: "eth",
|
||||
Version: "1.0",
|
||||
Service: filters.NewPublicFilterAPI(s.APIBackend, false),
|
||||
Service: publicFilterAPI, // BOR related change
|
||||
Public: true,
|
||||
}, {
|
||||
Namespace: "admin",
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
)
|
||||
|
||||
|
|
@ -59,6 +60,8 @@ type PublicFilterAPI struct {
|
|||
events *EventSystem
|
||||
filtersMu sync.Mutex
|
||||
filters map[rpc.ID]*filter
|
||||
|
||||
chainConfig *params.ChainConfig
|
||||
}
|
||||
|
||||
// NewPublicFilterAPI returns a new PublicFilterAPI instance.
|
||||
|
|
@ -324,13 +327,20 @@ func (api *PublicFilterAPI) NewFilter(crit FilterCriteria) (rpc.ID, error) {
|
|||
//
|
||||
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getlogs
|
||||
func (api *PublicFilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*types.Log, error) {
|
||||
if api.chainConfig == nil {
|
||||
return nil, errors.New("No chain config found. Proper PublicFilterAPI initialization required")
|
||||
}
|
||||
|
||||
// get sprint from bor config
|
||||
sprint := api.chainConfig.Bor.Sprint
|
||||
|
||||
var filter *Filter
|
||||
var borLogsFilter *BorBlockLogsFilter
|
||||
if crit.BlockHash != nil {
|
||||
// Block filter requested, construct a single-shot filter
|
||||
filter = NewBlockFilter(api.backend, *crit.BlockHash, crit.Addresses, crit.Topics)
|
||||
// Block bor filter
|
||||
borLogsFilter = NewBorBlockLogsFilter(api.backend, *crit.BlockHash, crit.Addresses, crit.Topics)
|
||||
borLogsFilter = NewBorBlockLogsFilter(api.backend, sprint, *crit.BlockHash, crit.Addresses, crit.Topics)
|
||||
} else {
|
||||
// Convert the RPC block numbers into internal representations
|
||||
begin := rpc.LatestBlockNumber.Int64()
|
||||
|
|
@ -344,7 +354,7 @@ func (api *PublicFilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([
|
|||
// Construct the range filter
|
||||
filter = NewRangeFilter(api.backend, begin, end, crit.Addresses, crit.Topics)
|
||||
// Block bor filter
|
||||
borLogsFilter = NewBorBlockLogsRangeFilter(api.backend, begin, end, crit.Addresses, crit.Topics)
|
||||
borLogsFilter = NewBorBlockLogsRangeFilter(api.backend, sprint, begin, end, crit.Addresses, crit.Topics)
|
||||
}
|
||||
|
||||
// Run the filter and return all the logs
|
||||
|
|
|
|||
|
|
@ -3,18 +3,32 @@ package filters
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
ethereum "github.com/ethereum/go-ethereum"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
)
|
||||
|
||||
// SetChainConfig sets chain config
|
||||
func (api *PublicFilterAPI) SetChainConfig(chainConfig *params.ChainConfig) {
|
||||
api.chainConfig = chainConfig
|
||||
}
|
||||
|
||||
func (api *PublicFilterAPI) GetBorBlockLogs(ctx context.Context, crit FilterCriteria) ([]*types.Log, error) {
|
||||
if api.chainConfig == nil {
|
||||
return nil, errors.New("No chain config found. Proper PublicFilterAPI initialization required")
|
||||
}
|
||||
|
||||
// get sprint from bor config
|
||||
sprint := api.chainConfig.Bor.Sprint
|
||||
|
||||
var filter *BorBlockLogsFilter
|
||||
if crit.BlockHash != nil {
|
||||
// Block filter requested, construct a single-shot filter
|
||||
filter = NewBorBlockLogsFilter(api.backend, *crit.BlockHash, crit.Addresses, crit.Topics)
|
||||
filter = NewBorBlockLogsFilter(api.backend, sprint, *crit.BlockHash, crit.Addresses, crit.Topics)
|
||||
} else {
|
||||
// Convert the RPC block numbers into internal representations
|
||||
begin := rpc.LatestBlockNumber.Int64()
|
||||
|
|
@ -26,7 +40,7 @@ func (api *PublicFilterAPI) GetBorBlockLogs(ctx context.Context, crit FilterCrit
|
|||
end = crit.ToBlock.Int64()
|
||||
}
|
||||
// Construct the range filter
|
||||
filter = NewBorBlockLogsRangeFilter(api.backend, begin, end, crit.Addresses, crit.Topics)
|
||||
filter = NewBorBlockLogsRangeFilter(api.backend, sprint, begin, end, crit.Addresses, crit.Topics)
|
||||
}
|
||||
|
||||
// Run the filter and return all the logs
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import (
|
|||
// BorBlockLogsFilter can be used to retrieve and filter logs.
|
||||
type BorBlockLogsFilter struct {
|
||||
backend Backend
|
||||
sprint uint64
|
||||
|
||||
db ethdb.Database
|
||||
addresses []common.Address
|
||||
|
|
@ -40,9 +41,9 @@ type BorBlockLogsFilter struct {
|
|||
|
||||
// NewBorBlockLogsRangeFilter creates a new filter which uses a bloom filter on blocks to
|
||||
// figure out whether a particular block is interesting or not.
|
||||
func NewBorBlockLogsRangeFilter(backend Backend, begin, end int64, addresses []common.Address, topics [][]common.Hash) *BorBlockLogsFilter {
|
||||
func NewBorBlockLogsRangeFilter(backend Backend, sprint uint64, begin, end int64, addresses []common.Address, topics [][]common.Hash) *BorBlockLogsFilter {
|
||||
// Create a generic filter and convert it into a range filter
|
||||
filter := newBorBlockLogsFilter(backend, addresses, topics)
|
||||
filter := newBorBlockLogsFilter(backend, sprint, addresses, topics)
|
||||
filter.begin = begin
|
||||
filter.end = end
|
||||
|
||||
|
|
@ -51,18 +52,19 @@ func NewBorBlockLogsRangeFilter(backend Backend, begin, end int64, addresses []c
|
|||
|
||||
// NewBorBlockLogsFilter creates a new filter which directly inspects the contents of
|
||||
// a block to figure out whether it is interesting or not.
|
||||
func NewBorBlockLogsFilter(backend Backend, block common.Hash, addresses []common.Address, topics [][]common.Hash) *BorBlockLogsFilter {
|
||||
func NewBorBlockLogsFilter(backend Backend, sprint uint64, block common.Hash, addresses []common.Address, topics [][]common.Hash) *BorBlockLogsFilter {
|
||||
// Create a generic filter and convert it into a block filter
|
||||
filter := newBorBlockLogsFilter(backend, addresses, topics)
|
||||
filter := newBorBlockLogsFilter(backend, sprint, addresses, topics)
|
||||
filter.block = block
|
||||
return filter
|
||||
}
|
||||
|
||||
// newBorBlockLogsFilter creates a generic filter that can either filter based on a block hash,
|
||||
// or based on range queries. The search criteria needs to be explicitly set.
|
||||
func newBorBlockLogsFilter(backend Backend, addresses []common.Address, topics [][]common.Hash) *BorBlockLogsFilter {
|
||||
func newBorBlockLogsFilter(backend Backend, sprint uint64, addresses []common.Address, topics [][]common.Hash) *BorBlockLogsFilter {
|
||||
return &BorBlockLogsFilter{
|
||||
backend: backend,
|
||||
sprint: sprint,
|
||||
addresses: addresses,
|
||||
topics: topics,
|
||||
db: backend.ChainDb(),
|
||||
|
|
@ -97,7 +99,7 @@ func (f *BorBlockLogsFilter) Logs(ctx context.Context) ([]*types.Log, error) {
|
|||
}
|
||||
|
||||
// adjust begin for sprint
|
||||
f.begin = currentSprintEnd(f.begin)
|
||||
f.begin = currentSprintEnd(f.sprint, f.begin)
|
||||
|
||||
end := f.end
|
||||
if f.end == -1 {
|
||||
|
|
@ -143,8 +145,8 @@ func (f *BorBlockLogsFilter) borBlockLogs(ctx context.Context, receipt *types.Re
|
|||
return logs, nil
|
||||
}
|
||||
|
||||
func currentSprintEnd(n int64) int64 {
|
||||
m := n % 64
|
||||
func currentSprintEnd(sprint uint64, n int64) int64 {
|
||||
m := n % int64(sprint)
|
||||
if m == 0 {
|
||||
return n
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue