Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
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
vicotor
mybee
Commits
c491d247
Unverified
Commit
c491d247
authored
Jun 24, 2021
by
Ralph Pichler
Committed by
GitHub
Jun 24, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: more blockchain related logging (#2211)
parent
8cb1d7c1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
12 deletions
+15
-12
chain.go
pkg/node/chain.go
+3
-3
backend.go
pkg/transaction/backend.go
+9
-6
backend_test.go
pkg/transaction/backend_test.go
+3
-3
No files found.
pkg/node/chain.go
View file @
c491d247
...
...
@@ -67,13 +67,13 @@ func InitChain(
}
// Sync the with the given Ethereum backend:
isSynced
,
err
:=
transaction
.
IsSynced
(
ctx
,
backend
,
maxDelay
)
isSynced
,
_
,
err
:=
transaction
.
IsSynced
(
ctx
,
backend
,
maxDelay
)
if
err
!=
nil
{
return
nil
,
common
.
Address
{},
0
,
nil
,
nil
,
fmt
.
Errorf
(
"is synced: %w"
,
err
)
}
if
!
isSynced
{
logger
.
Infof
(
"waiting to sync with the Ethereum backend"
)
err
:=
transaction
.
WaitSynced
(
ctx
,
backend
,
maxDelay
)
err
:=
transaction
.
WaitSynced
(
logger
,
ctx
,
backend
,
maxDelay
)
if
err
!=
nil
{
return
nil
,
common
.
Address
{},
0
,
nil
,
nil
,
fmt
.
Errorf
(
"waiting backend sync: %w"
,
err
)
}
...
...
@@ -97,7 +97,7 @@ func InitChequebookFactory(
foundFactory
,
foundLegacyFactories
,
found
:=
chequebook
.
DiscoverFactoryAddress
(
chainID
)
if
factoryAddress
==
""
{
if
!
found
{
return
nil
,
errors
.
New
(
"no known factory address for this network"
)
return
nil
,
fmt
.
Errorf
(
"no known factory address for this network (chain id: %d)"
,
chainID
)
}
currentFactory
=
foundFactory
logger
.
Infof
(
"using default factory address for chain id %d: %x"
,
chainID
,
currentFactory
)
...
...
pkg/transaction/backend.go
View file @
c491d247
...
...
@@ -17,6 +17,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethersphere/bee/pkg/logging"
)
// Backend is the minimum of blockchain backend functions we need.
...
...
@@ -35,28 +36,28 @@ type Backend interface {
// is true if the current wall clock is after the block time of last block
// with the given maxDelay as the maximum duration we can be behind the block
// time.
func
IsSynced
(
ctx
context
.
Context
,
backend
Backend
,
maxDelay
time
.
Duration
)
(
bool
,
error
)
{
func
IsSynced
(
ctx
context
.
Context
,
backend
Backend
,
maxDelay
time
.
Duration
)
(
bool
,
time
.
Time
,
error
)
{
number
,
err
:=
backend
.
BlockNumber
(
ctx
)
if
err
!=
nil
{
return
false
,
err
return
false
,
time
.
Time
{},
err
}
header
,
err
:=
backend
.
HeaderByNumber
(
ctx
,
big
.
NewInt
(
int64
(
number
)))
if
err
!=
nil
{
return
false
,
err
return
false
,
time
.
Time
{},
err
}
blockTime
:=
time
.
Unix
(
int64
(
header
.
Time
),
0
)
return
blockTime
.
After
(
time
.
Now
()
.
UTC
()
.
Add
(
-
maxDelay
)),
nil
return
blockTime
.
After
(
time
.
Now
()
.
UTC
()
.
Add
(
-
maxDelay
)),
blockTime
,
nil
}
// WaitSynced will wait until we are synced with the given blockchain backend,
// with the given maxDelay duration as the maximum time we can be behind the
// last block.
func
WaitSynced
(
ctx
context
.
Context
,
backend
Backend
,
maxDelay
time
.
Duration
)
error
{
func
WaitSynced
(
logger
logging
.
Logger
,
ctx
context
.
Context
,
backend
Backend
,
maxDelay
time
.
Duration
)
error
{
for
{
synced
,
err
:=
IsSynced
(
ctx
,
backend
,
maxDelay
)
synced
,
blockTime
,
err
:=
IsSynced
(
ctx
,
backend
,
maxDelay
)
if
err
!=
nil
{
return
err
}
...
...
@@ -65,6 +66,8 @@ func WaitSynced(ctx context.Context, backend Backend, maxDelay time.Duration) er
return
nil
}
logger
.
Infof
(
"still waiting for Ethereum to sync. Block time is %s."
,
blockTime
)
select
{
case
<-
ctx
.
Done
()
:
return
ctx
.
Err
()
...
...
pkg/transaction/backend_test.go
View file @
c491d247
...
...
@@ -19,7 +19,7 @@ func TestIsSynced(t *testing.T) {
blockNumber
:=
uint64
(
100
)
t
.
Run
(
"synced"
,
func
(
t
*
testing
.
T
)
{
synced
,
err
:=
transaction
.
IsSynced
(
synced
,
_
,
err
:=
transaction
.
IsSynced
(
ctx
,
backendmock
.
New
(
backendmock
.
WithBlockNumberFunc
(
func
(
c
context
.
Context
)
(
uint64
,
error
)
{
...
...
@@ -45,7 +45,7 @@ func TestIsSynced(t *testing.T) {
})
t
.
Run
(
"not synced"
,
func
(
t
*
testing
.
T
)
{
synced
,
err
:=
transaction
.
IsSynced
(
synced
,
_
,
err
:=
transaction
.
IsSynced
(
ctx
,
backendmock
.
New
(
backendmock
.
WithBlockNumberFunc
(
func
(
c
context
.
Context
)
(
uint64
,
error
)
{
...
...
@@ -72,7 +72,7 @@ func TestIsSynced(t *testing.T) {
t
.
Run
(
"error"
,
func
(
t
*
testing
.
T
)
{
expectedErr
:=
errors
.
New
(
"err"
)
_
,
err
:=
transaction
.
IsSynced
(
_
,
_
,
err
:=
transaction
.
IsSynced
(
ctx
,
backendmock
.
New
(
backendmock
.
WithBlockNumberFunc
(
func
(
c
context
.
Context
)
(
uint64
,
error
)
{
...
...
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