Commit 3eaf194c authored by mergify[bot]'s avatar mergify[bot] Committed by GitHub

Merge branch 'develop' into felipe/cache-fix-b

parents 3e83c889 4f228fe9
---
'@eth-optimism/contracts-bedrock': patch
---
contracts-bedrock was exporting hardhat when it didn't need to be
...@@ -48,16 +48,17 @@ const ( ...@@ -48,16 +48,17 @@ const (
maxThrottleDelay = time.Second * 20 maxThrottleDelay = time.Second * 20
// Do not serve more than 20 requests per second // Do not serve more than 20 requests per second
globalServerBlocksRateLimit rate.Limit = 20 globalServerBlocksRateLimit rate.Limit = 20
// Allow up to 5 concurrent requests to be served, eating into our rate-limit // Allows a burst of 2x our rate limit
globalServerBlocksBurst = 5 globalServerBlocksBurst = 40
// Do not serve more than 5 requests per second to the same peer, so we can serve other peers at the same time // Do not serve more than 4 requests per second to the same peer, so we can serve other peers at the same time
peerServerBlocksRateLimit rate.Limit = 5 peerServerBlocksRateLimit rate.Limit = 4
// Allow a peer to burst 3 requests, so it does not have to wait // Allow a peer to request 30s of blocks at once
peerServerBlocksBurst = 3 peerServerBlocksBurst = 15
// If the client hits a request error, it counts as a lot of rate-limit tokens for syncing from that peer: // If the client hits a request error, it counts as a lot of rate-limit tokens for syncing from that peer:
// we rather sync from other servers. We'll try again later, // we rather sync from other servers. We'll try again later,
// and eventually kick the peer based on degraded scoring if it's really not serving us well. // and eventually kick the peer based on degraded scoring if it's really not serving us well.
clientErrRateCost = 100 // TODO(CLI-4009): Use a backoff rather than this mechanism.
clientErrRateCost = peerServerBlocksBurst
) )
func PayloadByNumberProtocolID(l2ChainID *big.Int) protocol.ID { func PayloadByNumberProtocolID(l2ChainID *big.Int) protocol.ID {
...@@ -204,6 +205,9 @@ type SyncClient struct { ...@@ -204,6 +205,9 @@ type SyncClient struct {
receivePayload receivePayloadFn receivePayload receivePayloadFn
// Global rate limiter for all peers.
globalRL *rate.Limiter
// resource context: all peers and mainLoop tasks inherit this, and start shutting down once resCancel() is called. // resource context: all peers and mainLoop tasks inherit this, and start shutting down once resCancel() is called.
resCtx context.Context resCtx context.Context
resCancel context.CancelFunc resCancel context.CancelFunc
...@@ -231,6 +235,7 @@ func NewSyncClient(log log.Logger, cfg *rollup.Config, newStream newStreamFn, rc ...@@ -231,6 +235,7 @@ func NewSyncClient(log log.Logger, cfg *rollup.Config, newStream newStreamFn, rc
requests: make(chan rangeRequest), // blocking requests: make(chan rangeRequest), // blocking
peerRequests: make(chan peerRequest, 128), peerRequests: make(chan peerRequest, 128),
results: make(chan syncResult, 128), results: make(chan syncResult, 128),
globalRL: rate.NewLimiter(globalServerBlocksRateLimit, globalServerBlocksBurst),
resCtx: ctx, resCtx: ctx,
resCancel: cancel, resCancel: cancel,
receivePayload: rcv, receivePayload: rcv,
...@@ -463,16 +468,17 @@ func (s *SyncClient) peerLoop(ctx context.Context, id peer.ID) { ...@@ -463,16 +468,17 @@ func (s *SyncClient) peerLoop(ctx context.Context, id peer.ID) {
log := s.log.New("peer", id) log := s.log.New("peer", id)
log.Info("Starting P2P sync client event loop") log.Info("Starting P2P sync client event loop")
var rl rate.Limiter
// Implement the same rate limits as the server does per-peer, // Implement the same rate limits as the server does per-peer,
// so we don't be too aggressive to the server. // so we don't be too aggressive to the server.
rl.SetLimit(peerServerBlocksRateLimit) rl := rate.NewLimiter(peerServerBlocksRateLimit, peerServerBlocksBurst)
rl.SetBurst(peerServerBlocksBurst)
for { for {
// wait for a global allocation to be available
if err := s.globalRL.Wait(ctx); err != nil {
return
}
// wait for peer to be available for more work // wait for peer to be available for more work
if err := rl.WaitN(ctx, 1); err != nil { if err := rl.Wait(ctx); err != nil {
return return
} }
...@@ -636,7 +642,6 @@ func NewReqRespServer(cfg *rollup.Config, l2 L2Chain, metrics ReqRespServerMetri ...@@ -636,7 +642,6 @@ func NewReqRespServer(cfg *rollup.Config, l2 L2Chain, metrics ReqRespServerMetri
// so it's fine to prune rate-limit details past this. // so it's fine to prune rate-limit details past this.
peerRateLimits, _ := simplelru.NewLRU[peer.ID, *peerStat](1000, nil) peerRateLimits, _ := simplelru.NewLRU[peer.ID, *peerStat](1000, nil)
// 3 sync requests per second, with 2 burst
globalRequestsRL := rate.NewLimiter(globalServerBlocksRateLimit, globalServerBlocksBurst) globalRequestsRL := rate.NewLimiter(globalServerBlocksRateLimit, globalServerBlocksBurst)
return &ReqRespServer{ return &ReqRespServer{
......
...@@ -10,6 +10,8 @@ import ( ...@@ -10,6 +10,8 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum-optimism/optimism/op-node/eth" "github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/beacon" "github.com/ethereum/go-ethereum/consensus/beacon"
...@@ -104,7 +106,7 @@ func (ch *Cheater) RunAndClose(fn HeadFn) error { ...@@ -104,7 +106,7 @@ func (ch *Cheater) RunAndClose(fn HeadFn) error {
_ = ch.Close() _ = ch.Close()
return fmt.Errorf("failed to commit state change: %w", err) return fmt.Errorf("failed to commit state change: %w", err)
} }
header := preHeader // copy the header header := types.CopyHeader(preHeader) // copy the header
header.Root = stateRoot header.Root = stateRoot
blockHash := header.Hash() blockHash := header.Hash()
......
...@@ -56,8 +56,7 @@ ...@@ -56,8 +56,7 @@
"@eth-optimism/core-utils": "^0.12.0", "@eth-optimism/core-utils": "^0.12.0",
"@openzeppelin/contracts": "4.7.3", "@openzeppelin/contracts": "4.7.3",
"@openzeppelin/contracts-upgradeable": "4.7.3", "@openzeppelin/contracts-upgradeable": "4.7.3",
"ethers": "^5.7.0", "ethers": "^5.7.0"
"hardhat": "^2.9.6"
}, },
"devDependencies": { "devDependencies": {
"@eth-optimism/hardhat-deploy-config": "^0.2.6", "@eth-optimism/hardhat-deploy-config": "^0.2.6",
...@@ -82,6 +81,7 @@ ...@@ -82,6 +81,7 @@
"ethereum-waffle": "^3.0.0", "ethereum-waffle": "^3.0.0",
"forge-std": "https://github.com/foundry-rs/forge-std.git#46264e9788017fc74f9f58b7efa0bc6e1df6d410", "forge-std": "https://github.com/foundry-rs/forge-std.git#46264e9788017fc74f9f58b7efa0bc6e1df6d410",
"glob": "^7.1.6", "glob": "^7.1.6",
"hardhat": "^2.9.6",
"hardhat-deploy": "^0.11.4", "hardhat-deploy": "^0.11.4",
"solhint": "^3.3.7", "solhint": "^3.3.7",
"solhint-plugin-prettier": "^0.0.5", "solhint-plugin-prettier": "^0.0.5",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment