Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
cd30eb09
Commit
cd30eb09
authored
Jun 07, 2023
by
Hamdi Allam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
expand on node.EthClient ot retrieve header by hash
parent
142e4f53
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
8 deletions
+32
-8
bigint.go
indexer/node/bigint.go
+1
-1
client.go
indexer/node/client.go
+28
-3
fetcher.go
indexer/node/fetcher.go
+3
-4
No files found.
indexer/node/bigint.go
View file @
cd30eb09
...
...
@@ -15,7 +15,7 @@ func clampBigInt(start, end *big.Int, size uint64) *big.Int {
return
end
}
// we re
sult
the allocated temp as the new end
// we re
-use
the allocated temp as the new end
temp
.
Add
(
start
,
big
.
NewInt
(
int64
(
size
-
1
)))
return
temp
}
indexer/node/client.go
View file @
cd30eb09
...
...
@@ -2,11 +2,14 @@ package node
import
(
"context"
"errors"
"math/big"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
)
...
...
@@ -22,7 +25,9 @@ const (
type
EthClient
interface
{
FinalizedBlockHeight
()
(
*
big
.
Int
,
error
)
BlockHeadersByRange
(
*
big
.
Int
,
*
big
.
Int
)
([]
*
types
.
Header
,
error
)
BlockHeaderByHash
(
common
.
Hash
)
(
*
types
.
Header
,
error
)
RawRpcClient
()
*
rpc
.
Client
}
...
...
@@ -53,13 +58,33 @@ func (c *client) FinalizedBlockHeight() (*big.Int, error) {
ctxwt
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
defaultRequestTimeout
)
defer
cancel
()
var
block
*
types
.
Block
err
:=
c
.
rpcClient
.
CallContext
(
ctxwt
,
block
,
"eth_getBlockByNumber"
,
"finalized"
,
false
)
// Local devnet is having issues with the "finalized" block tag. Switch to "latest"
// to iterate faster locally but this needs to be updated
header
:=
new
(
types
.
Header
)
err
:=
c
.
rpcClient
.
CallContext
(
ctxwt
,
header
,
"eth_getBlockByNumber"
,
"latest"
,
false
)
if
err
!=
nil
{
return
nil
,
err
}
return
header
.
Number
,
nil
}
// BlockHeaderByHash retrieves the block header attributed to the supplied hash
func
(
c
*
client
)
BlockHeaderByHash
(
hash
common
.
Hash
)
(
*
types
.
Header
,
error
)
{
ctxwt
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
defaultRequestTimeout
)
defer
cancel
()
header
,
err
:=
ethclient
.
NewClient
(
c
.
rpcClient
)
.
HeaderByHash
(
ctxwt
,
hash
)
if
err
!=
nil
{
return
nil
,
err
}
return
block
.
Number
(),
nil
// sanity check on the data returned
if
header
.
Hash
()
!=
hash
{
return
nil
,
errors
.
New
(
"header mismatch"
)
}
return
header
,
nil
}
// BlockHeadersByRange will retrieve block headers within the specified range -- includsive. No restrictions
...
...
indexer/node/fetcher.go
View file @
cd30eb09
...
...
@@ -20,9 +20,8 @@ type Fetcher struct {
// NewFetcher instantiates a new instance of Fetcher against the supplied rpc client.
// The Fetcher will start fetching blocks starting from the supplied header unless
// nil, indicating genesis.
func
NewFetcher
(
ethClient
EthClient
,
fromHeader
*
types
.
Header
)
(
*
Fetcher
,
error
)
{
fetcher
:=
&
Fetcher
{
ethClient
:
ethClient
,
lastHeader
:
fromHeader
}
return
fetcher
,
nil
func
NewFetcher
(
ethClient
EthClient
,
fromHeader
*
types
.
Header
)
*
Fetcher
{
return
&
Fetcher
{
ethClient
:
ethClient
,
lastHeader
:
fromHeader
}
}
// NextConfirmedHeaders retrives the next set of headers that have been
...
...
@@ -50,7 +49,7 @@ func (f *Fetcher) NextFinalizedHeaders() ([]*types.Header, error) {
return
nil
,
err
}
numHeaders
:=
int64
(
len
(
headers
)
)
numHeaders
:=
len
(
headers
)
if
numHeaders
==
0
{
return
nil
,
nil
}
else
if
f
.
lastHeader
!=
nil
&&
headers
[
0
]
.
ParentHash
!=
f
.
lastHeader
.
Hash
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment