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
f7d0e1ac
Unverified
Commit
f7d0e1ac
authored
Mar 23, 2023
by
mergify[bot]
Committed by
GitHub
Mar 23, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5231 from ethereum-optimism/available-rpc-methods-fix
op-node: reset back to optimal receipt fetching methods
parents
8e531951
84fda210
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
1 deletion
+41
-1
eth_client.go
op-node/sources/eth_client.go
+25
-1
l1_client.go
op-node/sources/l1_client.go
+2
-0
l2_client.go
op-node/sources/l2_client.go
+2
-0
receipts_test.go
op-node/sources/receipts_test.go
+12
-0
No files found.
op-node/sources/eth_client.go
View file @
f7d0e1ac
...
...
@@ -13,6 +13,7 @@ import (
"context"
"fmt"
"math/big"
"time"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -56,6 +57,11 @@ type EthClientConfig struct {
// RPCProviderKind is a hint at what type of RPC provider we are dealing with
RPCProviderKind
RPCProviderKind
// Method reset duration defines how long we stick to available RPC methods,
// till we re-attempt the user-preferred methods.
// If this is 0 then the client does not fall back to less optimal but available methods.
MethodResetDuration
time
.
Duration
}
func
(
c
*
EthClientConfig
)
Check
()
error
{
...
...
@@ -118,9 +124,25 @@ type EthClient struct {
// This may be modified concurrently, but we don't lock since it's a single
// uint64 that's not critical (fine to miss or mix up a modification)
availableReceiptMethods
ReceiptsFetchingMethod
// lastMethodsReset tracks when availableReceiptMethods was last reset.
// When receipt-fetching fails it falls back to available methods,
// but periodically it will try to reset to the preferred optimal methods.
lastMethodsReset
time
.
Time
// methodResetDuration defines how long we take till we reset lastMethodsReset
methodResetDuration
time
.
Duration
}
func
(
s
*
EthClient
)
PickReceiptsMethod
(
txCount
uint64
)
ReceiptsFetchingMethod
{
if
now
:=
time
.
Now
();
now
.
Sub
(
s
.
lastMethodsReset
)
>
s
.
methodResetDuration
{
m
:=
AvailableReceiptsFetchingMethods
(
s
.
provKind
)
if
s
.
availableReceiptMethods
!=
m
{
s
.
log
.
Warn
(
"resetting back RPC preferences, please review RPC provider kind setting"
,
"kind"
,
s
.
provKind
.
String
())
}
s
.
availableReceiptMethods
=
m
s
.
lastMethodsReset
=
now
}
return
PickBestReceiptsFetchingMethod
(
s
.
provKind
,
s
.
availableReceiptMethods
,
txCount
)
}
...
...
@@ -128,7 +150,7 @@ func (s *EthClient) OnReceiptsMethodErr(m ReceiptsFetchingMethod, err error) {
if
unusableMethod
(
err
)
{
// clear the bit of the method that errored
s
.
availableReceiptMethods
&^=
m
s
.
log
.
Warn
(
"failed to use selected RPC method for receipt fetching, falling back to alternatives"
,
s
.
log
.
Warn
(
"failed to use selected RPC method for receipt fetching,
temporarily
falling back to alternatives"
,
"provider_kind"
,
s
.
provKind
,
"failed_method"
,
m
,
"fallback"
,
s
.
availableReceiptMethods
,
"err"
,
err
)
}
else
{
s
.
log
.
Debug
(
"failed to use selected RPC method for receipt fetching, but method does appear to be available, so we continue to use it"
,
...
...
@@ -155,6 +177,8 @@ func NewEthClient(client client.RPC, log log.Logger, metrics caching.Metrics, co
headersCache
:
caching
.
NewLRUCache
(
metrics
,
"headers"
,
config
.
HeadersCacheSize
),
payloadsCache
:
caching
.
NewLRUCache
(
metrics
,
"payloads"
,
config
.
PayloadsCacheSize
),
availableReceiptMethods
:
AvailableReceiptsFetchingMethods
(
config
.
RPCProviderKind
),
lastMethodsReset
:
time
.
Now
(),
methodResetDuration
:
config
.
MethodResetDuration
,
},
nil
}
...
...
op-node/sources/l1_client.go
View file @
f7d0e1ac
...
...
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strings"
"time"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -40,6 +41,7 @@ func L1ClientDefaultConfig(config *rollup.Config, trustRPC bool, kind RPCProvide
TrustRPC
:
trustRPC
,
MustBePostMerge
:
false
,
RPCProviderKind
:
kind
,
MethodResetDuration
:
time
.
Minute
,
},
// Not bounded by span, to cover find-sync-start range fully for speedy recovery after errors.
L1BlockRefsCacheSize
:
fullSpan
,
...
...
op-node/sources/l2_client.go
View file @
f7d0e1ac
...
...
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strings"
"time"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -50,6 +51,7 @@ func L2ClientDefaultConfig(config *rollup.Config, trustRPC bool) *L2ClientConfig
TrustRPC
:
trustRPC
,
MustBePostMerge
:
true
,
RPCProviderKind
:
RPCKindBasic
,
MethodResetDuration
:
time
.
Minute
,
},
// Not bounded by span, to cover find-sync-start range fully for speedy recovery after errors.
L2BlockRefsCacheSize
:
fullSpan
,
...
...
op-node/sources/receipts_test.go
View file @
f7d0e1ac
...
...
@@ -6,6 +6,7 @@ import (
"fmt"
"math/rand"
"testing"
"time"
"github.com/ethereum-optimism/optimism/op-node/client"
"github.com/ethereum-optimism/optimism/op-node/eth"
...
...
@@ -85,6 +86,7 @@ func (e *methodNotFoundError) Error() string {
type
ReceiptsTestCase
struct
{
name
string
providerKind
RPCProviderKind
staticMethod
bool
setup
func
(
t
*
testing
.
T
)
(
*
rpcBlock
,
[]
ReceiptsRequest
)
}
...
...
@@ -142,6 +144,10 @@ func (tc *ReceiptsTestCase) Run(t *testing.T) {
TrustRPC
:
false
,
MustBePostMerge
:
false
,
RPCProviderKind
:
tc
.
providerKind
,
MethodResetDuration
:
time
.
Minute
,
}
if
tc
.
staticMethod
{
// if static, instantly reset, for fast clock-independent testing
testCfg
.
MethodResetDuration
=
0
}
logger
:=
testlog
.
Logger
(
t
,
log
.
LvlError
)
ethCl
,
err
:=
NewEthClient
(
client
.
NewBaseRPCClient
(
cl
),
logger
,
nil
,
testCfg
)
...
...
@@ -226,6 +232,12 @@ func TestEthClient_FetchReceipts(t *testing.T) {
providerKind
:
RPCKindAlchemy
,
setup
:
fallbackCase
(
30
,
AlchemyGetTransactionReceipts
),
},
{
name
:
"alchemy sticky"
,
providerKind
:
RPCKindAlchemy
,
staticMethod
:
true
,
setup
:
fallbackCase
(
30
,
AlchemyGetTransactionReceipts
,
AlchemyGetTransactionReceipts
),
},
{
name
:
"alchemy fallback 1"
,
providerKind
:
RPCKindAlchemy
,
...
...
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