good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
be23d02c
Unverified
Commit
be23d02c
authored
Dec 8, 2020
by
Jaynti Kanani
Browse files
Options
Downloads
Patches
Plain Diff
chg: use sprint from genesis
parent
7cea1447
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
eth/backend.go
+8
-1
8 additions, 1 deletion
eth/backend.go
eth/filters/api.go
+12
-2
12 additions, 2 deletions
eth/filters/api.go
eth/filters/bor_api.go
+16
-2
16 additions, 2 deletions
eth/filters/bor_api.go
eth/filters/bor_filter.go
+10
-8
10 additions, 8 deletions
eth/filters/bor_filter.go
with
46 additions
and
13 deletions
eth/backend.go
+
8
−
1
View file @
be23d02c
...
...
@@ -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
.
NewP
ublicFilterAPI
(
s
.
APIBackend
,
false
),
Service
:
p
ublicFilterAPI
,
// BOR related change
Public
:
true
,
},
{
Namespace
:
"admin"
,
...
...
This diff is collapsed.
Click to expand it.
eth/filters/api.go
+
12
−
2
View file @
be23d02c
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
eth/filters/bor_api.go
+
16
−
2
View file @
be23d02c
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
eth/filters/bor_filter.go
+
10
−
8
View file @
be23d02c
...
...
@@ -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
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment