Skip to content

Commit

Permalink
Merge New Sequencer into Develop branch (0xPolygonHermez#1658)
Browse files Browse the repository at this point in the history
* WIP

* wip: adding some implementation of the finalizer, defining needed interfaces by the finalizer from the dbmanager, and implementing the remaining resourses Sub.

Signed-off-by: Nikolay Nedkov <[email protected]>

* wip:2

Signed-off-by: Nikolay Nedkov <[email protected]>

* fix: fixing comment

Signed-off-by: Nikolay Nedkov <[email protected]>

* wip: okx#4

Signed-off-by: Nikolay Nedkov <[email protected]>

* fix: fixing bootstrap method in sequencer

Signed-off-by: Nikolay Nedkov <[email protected]>

* fix: fixing log in finalizer.reopenBatch

Signed-off-by: Nikolay Nedkov <[email protected]>

* DBManager WIP (0xPolygonHermez#1512)

* WIP

* WIP

* WIP

* wip: adding implementation for .isCurrBatchAboveLimitWindow', and doing small refactor.

Signed-off-by: Nikolay Nedkov <[email protected]>

* fix: fixing handling of deadlines and events

Signed-off-by: Nikolay Nedkov <[email protected]>

* WIP: fixing logic.

Signed-off-by: Nikolay Nedkov <[email protected]>

* WIP: fixing logic.

Signed-off-by: Nikolay Nedkov <[email protected]>

* Synchronizer stores the accumulated input hash (0xPolygonHermez#1535)

* Initial worker implementation (still WIP)

* merge

Signed-off-by: Nikolay Nedkov <[email protected]>

* Wip: merge

Signed-off-by: Nikolay Nedkov <[email protected]>

* merge

Signed-off-by: Nikolay Nedkov <[email protected]>

* Feature/dbmanager (0xPolygonHermez#1524)

* wip: adding implementation for .isCurrBatchAboveLimitWindow', and doing small refactor.

Signed-off-by: Nikolay Nedkov <[email protected]>

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* ForceBatch unit test

* SequenceForceBatch unit test

* Fix forcedBatch check

* linter

* Fix reset forcedBatch

* batch and forcedbatch table modified

* fix

* WIP

* Finish dbmanager

* Branches Integration

Signed-off-by: Nikolay Nedkov <[email protected]>
Co-authored-by: Nikolay Nedkov <[email protected]>
Co-authored-by: Alonso <[email protected]>

* implement last methods (0xPolygonHermez#1542)

* added getLastStateRoot (0xPolygonHermez#1543)

* fix,tests: fixing some methods and adding unit tests.

Signed-off-by: Nikolay Nedkov <[email protected]>

* Closing Signals Manager first implementation (0xPolygonHermez#1550)

* Closing Signals Manager first implementation

* Closing Signals Manager first implementation

* Closing Signals Manager first implementation

* refactor

* Added worker unit testing. Missing TODOs implementation done

* Cahnge getLastGer implementation (0xPolygonHermez#1556)

* wip fixes

Signed-off-by: Nikolay Nedkov <[email protected]>

* wip fixes

Signed-off-by: Nikolay Nedkov <[email protected]>

* wip fixes

Signed-off-by: Nikolay Nedkov <[email protected]>

* fixed addrqueue.addTx returning wrong (newReadyTx, prevReadyTx) when the added tx was a notReadyTxs

* Fix encoding bug in AddForcedBatch (0xPolygonHermez#1544)

The forced_batch table expects the raw_txs_data column to be a
string (specifically a hex encoding of the raw transaction bytes).
The corresponding GetForcedBatch function uses hex.DecodeString to
turn the value of this column back into raw bytes. However,
AddForcedBatch is missing a hex.EncodeToString, so it is actually
interpreting the raw transaction bytes as an ASCII representation
of a hex-encoded string.

* Feature/executor error (0xPolygonHermez#1566)

* Handle executor and rom erros from executor

* convert touched addresses

* add debug logs

* add debug logs

* store request in case of executor error

* store request in case of executor error

* minor fixes

* WIP

* convert readwriteaddresses to map

* add test

* add method to mark wip txs as pending

Co-authored-by: ToniRamirezM <[email protected]>

* fix: wip fix of prepareProcessRequestFromState to fetch txs when reprocess is done.

Signed-off-by: Nikolay Nedkov <[email protected]>

* test (0xPolygonHermez#1569)

* fix: fixing benchmark test and several bugs.

Signed-off-by: Nikolay Nedkov <[email protected]>

* Fix linter and tests (0xPolygonHermez#1576)

* fix linter

* fix linter

* fix linter

* fix linter

* fix linter

* fix linter

* fix linter

* fix linter

* fix linter

* fix linter

* fix linter

* fix linter

* fix linter

* fix linter

* fix linter

* fix linter

* fix linter

* fix linter

* fix linter

* fix linter

* fix linter

* fix linter

* remove testMain (0xPolygonHermez#1585)

* Fix errors found while running bridge/GER tests

* update mock files

* Add forced batch closing signal unit test (0xPolygonHermez#1593)

* add forced batch closing signal unit test

* add forced batch closing signal unit test

* add forced batch closing signal unit test

* add forced batch closing signal unit test

* test: adding sequencer benchmark test with ERC20 transfers.

Signed-off-by: Nikolay Nedkov <[email protected]>

* adding erc-20 benchmark test, adding metrics for wokerker processing time and fixing unit tests of finalizer

Signed-off-by: Nikolay Nedkov <[email protected]>

* adding missing mutex lock in woker.MoveTxToNotReady

Signed-off-by: Nikolay Nedkov <[email protected]>

* fix: fixing benchmark result print messages.

Signed-off-by: Nikolay Nedkov <[email protected]>

* [New Sequencer] Merge develop into new sequencer branch (0xPolygonHermez#1602)

* Backport v0.0.1-RC4 & RC5 to develop (0xPolygonHermez#1483)

* update poe sc to security mechanisms version (0xPolygonHermez#1467)

* update poe sc to security mechanisms version

* updated names, fix tests and remove ger timestamp and other fixes

* fix rlp tool

* fix linter

* new genesis + fix

* new smc

* Update executor errors

* Update executor errors

* Update executor errors

* Update executor errors

* new l2 contract names

* sequencewr unit test commented

* fix test

Co-authored-by: Alonso <[email protected]>
Co-authored-by: ToniRamirezM <[email protected]>

* Fix/1472 verify batches timeout (0xPolygonHermez#1473)

Closes 0xPolygonHermez#1472

### What does this PR do?

During testing we faced an issue of two consecutive verified batches on L1 without respecting the time spacing.
The problem was that we were relying on the timer to check if we can start generating a new final proof. That timer is only reset after the final proof is sent to L1. This means that there's a time window between the generation of a final proof and its verification in which a new proof eligible to be final can be generated and immediately trigger another final proof generation.

The fix introduced here is to have a `verifyingProof` flag that gets checked when the final proof generation process begins and released only when the verification phase ends (or in case of errors).

Co-authored-by: Thiago Coimbra Lemos <[email protected]>
Co-authored-by: Alonso <[email protected]>
Co-authored-by: ToniRamirezM <[email protected]>

* fix unpack the revert reason (0xPolygonHermez#1475)

Co-authored-by: tclemos <[email protected]>

* fix: update the genesis file (0xPolygonHermez#1489)

* update the genesis

* revert bytecode

* upgrade git hub actions to the latest versions (0xPolygonHermez#1471)

* build(deps): bump github.com/go-git/go-billy/v5 from 5.3.1 to 5.4.0 (0xPolygonHermez#1492)

Bumps [github.com/go-git/go-billy/v5](https://github.com/go-git/go-billy) from 5.3.1 to 5.4.0.
- [Release notes](https://github.com/go-git/go-billy/releases)
- [Commits](go-git/go-billy@v5.3.1...v5.4.0)

---
updated-dependencies:
- dependency-name: github.com/go-git/go-billy/v5
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fatals changed to return error (0xPolygonHermez#1494)

* fatals changed to return error

* comments

* [Aggregator] Add metrics package and ConnectedProvers metric (0xPolygonHermez#1502)

* feat: add metrics pkg and connected provers metric

This commit adds the `metrics` subpackage in the `aggregator` package.
It also adds the connected provers gauge metric to keep track of
the number of currently connected provers.

Signed-off-by: Paolo Grisoli <[email protected]>

* chore: expose aggregator metrics port

This commit exposes the aggregator metrics port in
`test/docker-compose.yml`.

Signed-off-by: Paolo Grisoli <[email protected]>

* feat: add WorkingProvers gauge metric (0xPolygonHermez#1504)

Closes 0xPolygonHermez#1503 

### What does this PR do?

This PR adds the `aggregator_current_working_provers` gauge metric to keep track of the number of Provers that are busy generating a proof at any point in time.

* build(deps): bump google.golang.org/grpc from 1.51.0 to 1.52.0 (0xPolygonHermez#1525)

Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.51.0 to 1.52.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](grpc/grpc-go@v1.51.0...v1.52.0)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump github.com/gorilla/websocket from 1.4.2 to 1.5.0 (0xPolygonHermez#1510)

Bumps [github.com/gorilla/websocket](https://github.com/gorilla/websocket) from 1.4.2 to 1.5.0.
- [Release notes](https://github.com/gorilla/websocket/releases)
- [Commits](gorilla/websocket@v1.4.2...v1.5.0)

---
updated-dependencies:
- dependency-name: github.com/gorilla/websocket
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump github.com/prometheus/common from 0.37.0 to 0.39.0 (0xPolygonHermez#1511)

Bumps [github.com/prometheus/common](https://github.com/prometheus/common) from 0.37.0 to 0.39.0.
- [Release notes](https://github.com/prometheus/common/releases)
- [Commits](prometheus/common@v0.37.0...v0.39.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/common
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Feature/0xPolygonHermez#1506 forced batch (0xPolygonHermez#1523)

* ForceBatch unit test

* SequenceForceBatch unit test

* Fix forcedBatch check

* linter

* Fix reset forcedBatch

* batch and forcedbatch table modified

* fix

* Handle and log ROM OOC errors in executor (0xPolygonHermez#1528)

* Handle and log ROM OOC errors in executor

* Fix IP

* linter

* improve test

* solve conflicts

* Feature/0xPolygonHermez#1515 migration (0xPolygonHermez#1531)

* rpc and broadcast without migrations

* mock

* linter

* fix unit test

* migration flag for synchronizer and checkMigrations

* run/stop aggregator command

* discard invalid txs in the pool when checking for an underpriced tx (0xPolygonHermez#1563)

* allow array config params to be set via env vars (0xPolygonHermez#1553)

* new eth tx manager (0xPolygonHermez#1484)

* Fix: typos (0xPolygonHermez#1567)

* Fix: typo

Fix: typo

* Fix: typo

Fix: typo

* Fix: typo

Fix: typo

* Fix: typo

Fix: typo

* Fix: typo

Fix: typo

* Fix: typo

Fix: typo

* Fix: typo

Fix: typo

* Merge release/v0.0.1 into develop (0xPolygonHermez#1561)

Merge release/v0.0.1 changes into develop. The original release/v0.0.1 branch has been left intact to be able to perform hotfixes in case.

* build(deps): bump github.com/spf13/viper from 1.14.0 to 1.15.0 (0xPolygonHermez#1568)

Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.14.0 to 1.15.0.
- [Release notes](https://github.com/spf13/viper/releases)
- [Commits](spf13/viper@v1.14.0...v1.15.0)

---
updated-dependencies:
- dependency-name: github.com/spf13/viper
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump github.com/urfave/cli/v2 from 2.23.7 to 2.24.1 (0xPolygonHermez#1573)

Bumps [github.com/urfave/cli/v2](https://github.com/urfave/cli) from 2.23.7 to 2.24.1.
- [Release notes](https://github.com/urfave/cli/releases)
- [Changelog](https://github.com/urfave/cli/blob/main/docs/CHANGELOG.md)
- [Commits](urfave/cli@v2.23.7...v2.24.1)

---
updated-dependencies:
- dependency-name: github.com/urfave/cli/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Gas limit 150K + tests (0xPolygonHermez#1551)

* Gas limit 150K + tests

* FreeClaimGasLimit as a config param

* linter

* fix config test

* Gas limit 150K + tests (0xPolygonHermez#1551)

* Gas limit 150K + tests

* FreeClaimGasLimit as a config param

* linter

* fix config test

* Db flag to identify trusted verified batches (0xPolygonHermez#1575)

* Db flag to identify trusted verified batches

* log

* Feature/0xPolygonHermez#1549 genesis txs (0xPolygonHermez#1574)

* genesis txs

* linter

* command removed

* fixes

* Feature/0xPolygonHermez#1486 l2gasprice (0xPolygonHermez#1548)

* gasPricer as a component with the follower

follower sets the l2gasprice depending on the l1 gas price

* make command

* Unit test + mocks

* linter

* fix

* suggestions

* suggestions

* log message

* suggesto to suggester + fix merge

* file name fixed

* jRPC - Batch methods and custom endpoint docs (0xPolygonHermez#1554)

* build(deps): bump google.golang.org/grpc from 1.52.0 to 1.52.3 (0xPolygonHermez#1588)

Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.52.0 to 1.52.3.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](grpc/grpc-go@v1.52.0...v1.52.3)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* New smc version (0xPolygonHermez#1581)

* New smc version

* linter

* fix

* linter

* genesis + network update

* l2 claim gas limit

* new aggregator wallet

* config

* add support to pre-EIP155 txs (0xPolygonHermez#1582)

* add support to pre-EIP155 txs

* =)

* naming things

* add pre-EIP-155 tx e2e test

* fix merge with develop

* add check for the vitualized batch when testing pre-EIP155 tx

* remove dependency of iden3 package from jrpc (0xPolygonHermez#1596)

* Merge

* Feature/0xPolygonHermez#1577 force (0xPolygonHermez#1599)

* forcedBatch Script

* Sequence forcedBatch

* linter

* linter

* linter

* migrations

* config

* state.exit_root

* state.exit_root

* state.exit_root

* state.exit_root

* state.exit_root

* state.exit_root

* merge state migrations

* merge state migrations

* remerge with develop

* Comment TestPreEIP155Tx

* remove not used test

---------

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Paolo Grisoli <[email protected]>
Co-authored-by: Paolo Grisoli <[email protected]>
Co-authored-by: Thiago Coimbra Lemos <[email protected]>
Co-authored-by: Alonso <[email protected]>
Co-authored-by: cool-developer <[email protected]>
Co-authored-by: tclemos <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Alonso Rodriguez <[email protected]>
Co-authored-by: omahs <[email protected]>

* adding missing mutex lock in woker.MoveTxToNotReady

Signed-off-by: Nikolay Nedkov <[email protected]>

* fix: fixing benchmark result print messages.

Signed-off-by: Nikolay Nedkov <[email protected]>

* adding missing part for processing forced batches, new http port exposing profiling endpoints when enabled, fixing lastGER hash used on opening new batch, and adding context to 'finalizer.processTransation' logs.

* fixing lint error

Signed-off-by: Nikolay Nedkov <[email protected]>

* adding missing port exposing for profilintin test/docker-compose.yml

Signed-off-by: Nikolay Nedkov <[email protected]>

* adding prints for fetching methods in benchmark/.../metrics.go

Signed-off-by: Nikolay Nedkov <[email protected]>

* Fix closing signals (0xPolygonHermez#1623)

* adding wip fixes and the closing signal emit from the sequencesender (0xPolygonHermez#1625)

Signed-off-by: Nikolay Nedkov <[email protected]>

* fix forced batch query (0xPolygonHermez#1630)

* L1Timeout (0xPolygonHermez#1635)

* L1Timeout

* L1Timeout

* L1Timeout

* fix config files

* wip

* fix config files

* fix config files

* fix test

* fix test

* wip: fixing forced batches.

Signed-off-by: Nikolay Nedkov <[email protected]>

* decode txs

* wip

Signed-off-by: Nikolay Nedkov <[email protected]>

* wip okx#2

Signed-off-by: Nikolay Nedkov <[email protected]>

* wip okx#3

Signed-off-by: Nikolay Nedkov <[email protected]>

* wip fixes and improvements

Signed-off-by: Nikolay Nedkov <[email protected]>

* wip making print of reprocess state root difference to not be Fatal.

Signed-off-by: Nikolay Nedkov <[email protected]>

* wip: removing redundant fatal in reprocessBatch and fixing unit tests.

Signed-off-by: Nikolay Nedkov <[email protected]>

* wip: removing redundant fatal

Signed-off-by: Nikolay Nedkov <[email protected]>

* wip: fixing to update StateRoot when passing no txs for processing to close empty batch.

Signed-off-by: Nikolay Nedkov <[email protected]>

* wip fixes

Signed-off-by: Nikolay Nedkov <[email protected]>

* wip updating config files.

Signed-off-by: Nikolay Nedkov <[email protected]>

* changing when checking nextSendingToL1Deadline if there are no txs in the batch not to close the batch but to update the deadline

Signed-off-by: Nikolay Nedkov <[email protected]>

* removing debug prints

Signed-off-by: Nikolay Nedkov <[email protected]>

* wip

Signed-off-by: Nikolay Nedkov <[email protected]>

* update executor image to e7ac5c4

* smc update

* GetForks + test

* integrate getForks

* l1 network docker image

* linter

* Fee recipient

* genesis

* linter

* fix unit test

* coinbase

* claim signature

* smc update l2coinbase

* remove genesis txs

* genesis

* genesis docker + new addresses and names

* addresses

* genesis fix

* fix script

* fix GenBlockNum

* fix docker-compose

* fix prover config

* update makefile

* fix config toml files

* fix db schema

* timestamp

* fix state tests

* minor fixes

* fix migrations test

* update prover

* prover image

* prover image

* fix makefile

* fix fork_id in ProcessBatch

* fix fork_id in ProcessBatch

* update prover image

* update test

* update test

* do not update MT in reprocess

* change config

* update MT in reprocess

* fix RlpFieldsToLegacyTx

* fix RlpFieldsToLegacyTx

* fix RlpFieldsToLegacyTx

* change config

* change config

* increase test timeout

* increase test timeout

* wip fixes

Signed-off-by: Nikolay Nedkov <[email protected]>

* check fix

Signed-off-by: Nikolay Nedkov <[email protected]>

* fixing 'debug.node.config.toml'

Signed-off-by: Nikolay Nedkov <[email protected]>

* removing unused config props for sequencer

Signed-off-by: Nikolay Nedkov <[email protected]>

---------

Signed-off-by: Nikolay Nedkov <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Paolo Grisoli <[email protected]>
Co-authored-by: Nikolay Nedkov <[email protected]>
Co-authored-by: Alonso Rodriguez <[email protected]>
Co-authored-by: agnusmor <[email protected]>
Co-authored-by: agnusmor <[email protected]>
Co-authored-by: Alonso <[email protected]>
Co-authored-by: Jeb Bearer <[email protected]>
Co-authored-by: Paolo Grisoli <[email protected]>
Co-authored-by: Thiago Coimbra Lemos <[email protected]>
Co-authored-by: cool-developer <[email protected]>
Co-authored-by: tclemos <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: omahs <[email protected]>
  • Loading branch information
13 people authored Feb 15, 2023
1 parent 6d529c6 commit 418c66f
Show file tree
Hide file tree
Showing 133 changed files with 9,571 additions and 6,111 deletions.
1 change: 1 addition & 0 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ func (a *Aggregator) isSynced(ctx context.Context, batchNum *uint64) bool {
log.Warnf("Failed to get last consolidated batch: %v", err)
return false
}

if lastVerifiedBatch == nil {
return false
}
Expand Down
56 changes: 27 additions & 29 deletions aggregator/pb/aggregator.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 53 additions & 30 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"context"
"fmt"
"math"
"net"
"net/http"
"net/http/pprof"
"os"
"os/signal"
"time"

"github.com/0xPolygonHermez/zkevm-node"
"github.com/0xPolygonHermez/zkevm-node/aggregator"
Expand All @@ -22,7 +23,6 @@ import (
"github.com/0xPolygonHermez/zkevm-node/metrics"
"github.com/0xPolygonHermez/zkevm-node/pool"
"github.com/0xPolygonHermez/zkevm-node/pool/pgpoolstorage"
"github.com/0xPolygonHermez/zkevm-node/pricegetter"
"github.com/0xPolygonHermez/zkevm-node/sequencer"
"github.com/0xPolygonHermez/zkevm-node/sequencer/broadcast"
"github.com/0xPolygonHermez/zkevm-node/sequencer/broadcast/pb"
Expand All @@ -36,6 +36,11 @@ import (
"google.golang.org/grpc"
)

const (
two = 2
ten = 10
)

func start(cliCtx *cli.Context) error {
zkevm.PrintVersion(os.Stdout)

Expand Down Expand Up @@ -80,21 +85,11 @@ func start(cliCtx *cli.Context) error {
log.Fatal(err)
}
// Read Fork ID FROM POE SC
// TODO: Uncomment when the POE SC is implemented
/*
currentForkID, err := etherman.GetL2ForkID()
if err != nil {
log.Fatal(err)
}
forkIDIntervals, err := etherman.GetL2ForkIDIntervals()
if err != nil {
log.Fatal(err)
}
*/

currentForkID := c.DefaultForkID
forkIDIntervals := []state.ForkIDInterval{{FromBatchNumber: 0, ToBatchNumber: math.MaxUint64, ForkId: c.DefaultForkID}}
forkIDIntervals, err := etherman.GetForks(cliCtx.Context)
if err != nil || len(forkIDIntervals) == 0 {
log.Fatal("error getting forks: ", err)
}
currentForkID := forkIDIntervals[len(forkIDIntervals)-1].ForkId

c.Aggregator.ChainID = l2ChainID
c.Aggregator.ForkId = currentForkID
Expand Down Expand Up @@ -147,9 +142,12 @@ func start(cliCtx *cli.Context) error {
}

if c.Metrics.Enabled {
go startMetricsHttpServer(c)
go startMetricsHttpServer(c.Metrics)
}

if c.Metrics.ProfilingEnabled {
go startProfilingHttpServer(c.Metrics)
}
waitSignal(cancelFuncs)

return nil
Expand Down Expand Up @@ -210,17 +208,12 @@ func runJSONRPCServer(c config.Config, pool *pool.Pool, st *state.State, apis ma
}

func createSequencer(cfg config.Config, pool *pool.Pool, etmStorage *ethtxmanager.PostgresStorage, st *state.State) *sequencer.Sequencer {
pg, err := pricegetter.NewClient(cfg.PriceGetter)
if err != nil {
log.Fatal(err)
}

etherman, err := newEtherman(cfg)
if err != nil {
log.Fatal(err)
}

for _, privateKey := range cfg.Sequencer.PrivateKeys {
for _, privateKey := range cfg.Sequencer.Finalizer.PrivateKeys {
_, err := etherman.LoadAuthFromKeyStore(privateKey.Path, privateKey.Password)
if err != nil {
log.Fatal(err)
Expand All @@ -229,7 +222,7 @@ func createSequencer(cfg config.Config, pool *pool.Pool, etmStorage *ethtxmanage

ethTxManager := ethtxmanager.New(cfg.EthTxManager, etherman, etmStorage, st)

seq, err := sequencer.New(cfg.Sequencer, pool, st, etherman, pg, ethTxManager)
seq, err := sequencer.New(cfg.Sequencer, pool, st, etherman, ethTxManager)
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -323,19 +316,49 @@ func createEthTxManager(cfg config.Config, etmStorage *ethtxmanager.PostgresStor
return etm
}

func startMetricsHttpServer(c *config.Config) {
func startProfilingHttpServer(c metrics.Config) {
mux := http.NewServeMux()
address := fmt.Sprintf("%s:%d", c.Metrics.Host, c.Metrics.Port)
address := fmt.Sprintf("%s:%d", c.ProfilingHost, c.ProfilingPort)
lis, err := net.Listen("tcp", address)
if err != nil {
log.Errorf("failed to create tcp listener for profiling: %v", err)
return
}
mux.HandleFunc(metrics.ProfilingIndexEndpoint, pprof.Index)
mux.HandleFunc(metrics.ProfileEndpoint, pprof.Profile)
mux.HandleFunc(metrics.ProfilingCmdEndpoint, pprof.Cmdline)
mux.HandleFunc(metrics.ProfilingSymbolEndpoint, pprof.Symbol)
mux.HandleFunc(metrics.ProfilingTraceEndpoint, pprof.Trace)
profilingServer := &http.Server{
Handler: mux,
ReadTimeout: two * time.Minute,
}
log.Infof("profiling server listening on port %d", c.ProfilingPort)
if err := profilingServer.Serve(lis); err != nil {
if err == http.ErrServerClosed {
log.Warnf("http server for profiling stopped")
return
}
log.Errorf("closed http connection for profiling server: %v", err)
return
}
}

func startMetricsHttpServer(c metrics.Config) {
mux := http.NewServeMux()
address := fmt.Sprintf("%s:%d", c.Host, c.Port)
lis, err := net.Listen("tcp", address)
if err != nil {
log.Errorf("failed to create tcp listener for metrics: %v", err)
return
}
mux.Handle(metrics.Endpoint, promhttp.Handler())
metricsServer := &http.Server{ //nolint Potential Slowloris Attack
Handler: mux,

metricsServer := &http.Server{
Handler: mux,
ReadTimeout: ten * time.Second,
}
log.Infof("metrics server listening on port %d", c.Metrics.Port)
log.Infof("metrics server listening on port %d", c.Port)
if err := metricsServer.Serve(lis); err != nil {
if err == http.ErrServerClosed {
log.Warnf("http server for metrics stopped")
Expand Down
Loading

0 comments on commit 418c66f

Please sign in to comment.