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
c2c76ced
Unverified
Commit
c2c76ced
authored
Aug 24, 2021
by
Ralph Pichler
Committed by
GitHub
Aug 24, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: wait for confirmations in WaitBlock (#2416)
parent
2fc7fa29
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
13 deletions
+26
-13
chain.go
pkg/node/chain.go
+4
-9
backend.go
pkg/transaction/backend.go
+22
-4
No files found.
pkg/node/chain.go
View file @
c2c76ced
...
@@ -30,8 +30,9 @@ import (
...
@@ -30,8 +30,9 @@ import (
)
)
const
(
const
(
maxDelay
=
1
*
time
.
Minute
maxDelay
=
1
*
time
.
Minute
cancellationDepth
=
6
cancellationDepth
=
6
additionalConfirmations
=
2
)
)
// InitChain will initialize the Ethereum backend at the given endpoint and
// InitChain will initialize the Ethereum backend at the given endpoint and
...
@@ -293,13 +294,7 @@ func GetTxNextBlock(ctx context.Context, logger logging.Logger, backend transact
...
@@ -293,13 +294,7 @@ func GetTxNextBlock(ctx context.Context, logger logging.Logger, backend transact
return
blockHash
,
nil
return
blockHash
,
nil
}
}
// if not found in statestore, fetch from chain
block
,
err
:=
transaction
.
WaitBlockAfterTransaction
(
ctx
,
backend
,
duration
,
common
.
BytesToHash
(
trx
),
additionalConfirmations
)
tx
,
err
:=
backend
.
TransactionReceipt
(
ctx
,
common
.
BytesToHash
(
trx
))
if
err
!=
nil
{
return
nil
,
err
}
block
,
err
:=
transaction
.
WaitBlock
(
ctx
,
backend
,
duration
,
big
.
NewInt
(
0
)
.
Add
(
tx
.
BlockNumber
,
big
.
NewInt
(
1
)))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
pkg/transaction/backend.go
View file @
c2c76ced
...
@@ -76,15 +76,33 @@ func WaitSynced(ctx context.Context, logger logging.Logger, backend Backend, max
...
@@ -76,15 +76,33 @@ func WaitSynced(ctx context.Context, logger logging.Logger, backend Backend, max
}
}
}
}
func
WaitBlock
(
ctx
context
.
Context
,
backend
Backend
,
pollingInterval
time
.
Duration
,
block
*
big
.
Int
)
(
*
types
.
Header
,
error
)
{
func
WaitBlock
AfterTransaction
(
ctx
context
.
Context
,
backend
Backend
,
pollingInterval
time
.
Duration
,
txHash
common
.
Hash
,
additionalConfirmations
uint64
)
(
*
types
.
Header
,
error
)
{
for
{
for
{
header
,
err
:=
backend
.
HeaderByNumber
(
ctx
,
block
)
receipt
,
err
:=
backend
.
TransactionReceipt
(
ctx
,
txHash
)
if
err
!=
nil
{
if
err
!=
nil
{
if
!
errors
.
Is
(
err
,
ethereum
.
NotFound
)
{
if
!
errors
.
Is
(
err
,
ethereum
.
NotFound
)
{
return
nil
,
err
return
nil
,
err
}
}
}
else
{
continue
return
header
,
nil
}
bn
,
err
:=
backend
.
BlockNumber
(
ctx
)
if
err
!=
nil
{
return
nil
,
err
}
nextBlock
:=
receipt
.
BlockNumber
.
Uint64
()
+
1
if
bn
>=
nextBlock
+
additionalConfirmations
{
header
,
err
:=
backend
.
HeaderByNumber
(
ctx
,
new
(
big
.
Int
)
.
SetUint64
(
nextBlock
))
if
err
!=
nil
{
if
!
errors
.
Is
(
err
,
ethereum
.
NotFound
)
{
return
nil
,
err
}
// in the case where we cannot find the block even though we already saw a higher number we keep on trying
}
else
{
return
header
,
nil
}
}
}
select
{
select
{
...
...
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