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
98dc2ae4
Commit
98dc2ae4
authored
Jul 12, 2023
by
Felipe Andrade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add .
parent
b3d6e6e0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
0 deletions
+99
-0
common.go
op-ufm/pkg/provider/common.go
+11
-0
heartbeat.go
op-ufm/pkg/provider/heartbeat.go
+54
-0
tx_pool.go
op-ufm/pkg/provider/tx_pool.go
+34
-0
No files found.
op-ufm/pkg/provider/common.go
0 → 100644
View file @
98dc2ae4
package
provider
import
(
"context"
"github.com/ethereum/go-ethereum/ethclient"
)
func
(
p
*
Provider
)
dial
(
ctx
context
.
Context
)
(
*
ethclient
.
Client
,
error
)
{
return
ethclient
.
Dial
(
p
.
config
.
URL
)
}
op-ufm/pkg/provider/heartbeat.go
0 → 100644
View file @
98dc2ae4
package
provider
import
(
"context"
"time"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/log"
"github.com/pkg/errors"
)
// Heartbeat polls for expected in-flight transactions
func
(
p
*
Provider
)
Heartbeat
(
ctx
context
.
Context
)
{
log
.
Debug
(
"heartbeat"
,
"provider"
,
p
.
name
)
if
len
(
p
.
txPool
.
Transactions
)
==
0
{
log
.
Debug
(
"no in-flight txs"
,
"provider"
,
p
.
name
)
return
}
ethClient
,
err
:=
p
.
dial
(
ctx
)
if
err
!=
nil
{
log
.
Error
(
"cant dial to provider"
,
"provider"
,
p
.
name
,
"url"
,
p
.
config
.
URL
,
"err"
,
err
)
}
log
.
Debug
(
"checking in-flight tx"
,
"count"
,
len
(
p
.
txPool
.
Transactions
),
"provider"
,
p
.
name
)
for
hash
,
st
:=
range
p
.
txPool
.
Transactions
{
log
.
Debug
(
hash
,
"st"
,
st
)
_
,
isPending
,
err
:=
ethClient
.
TransactionByHash
(
ctx
,
st
.
Hash
)
if
err
!=
nil
&&
!
errors
.
Is
(
err
,
ethereum
.
NotFound
)
{
log
.
Error
(
"cant check transaction"
,
"provider"
,
p
.
name
,
"url"
,
p
.
config
.
URL
,
"err"
,
err
)
continue
}
log
.
Debug
(
"got transaction"
,
"provider"
,
p
.
name
,
"hash"
,
hash
,
"isPending"
,
isPending
)
st
.
M
.
Lock
()
if
st
.
FirstSeen
.
IsZero
()
{
st
.
FirstSeen
=
time
.
Now
()
}
if
_
,
exist
:=
st
.
SeenBy
[
p
.
name
];
!
exist
{
st
.
SeenBy
[
p
.
name
]
=
time
.
Now
()
}
st
.
M
.
Unlock
()
p
.
txPool
.
M
.
Lock
()
// every provider has seen this transaction
if
len
(
st
.
SeenBy
)
==
p
.
txPool
.
Expected
{
log
.
Debug
(
"transaction seen by all"
,
"hash"
,
hash
)
delete
(
p
.
txPool
.
Transactions
,
hash
)
}
p
.
txPool
.
M
.
Unlock
()
}
}
op-ufm/pkg/provider/tx_pool.go
0 → 100644
View file @
98dc2ae4
package
provider
import
(
"sync"
"time"
"github.com/ethereum/go-ethereum/common"
)
// TransactionPool is used locally to share transactions between providers under the same pool
type
TransactionPool
map
[
string
]
*
NetworkTransactionPool
// NetworkTransactionPool is used locally to share transactions between providers under the same network
type
NetworkTransactionPool
struct
{
M
sync
.
Mutex
Transactions
map
[
string
]
*
TransactionState
Expected
int
}
type
TransactionState
struct
{
// Transaction hash
Hash
common
.
Hash
// Mutex
M
sync
.
Mutex
SentAt
time
.
Time
FirstSeen
time
.
Time
// Map of providers that have seen this transaction, and when
// Once all providers have seen the transaction it is removed from the pool
SeenBy
map
[
string
]
time
.
Time
}
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