Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/#2669_LxLy
Browse files Browse the repository at this point in the history
  • Loading branch information
ARR552 committed Nov 8, 2023
2 parents e09661a + 930cab8 commit 7bb568e
Show file tree
Hide file tree
Showing 126 changed files with 6,066 additions and 2,594 deletions.
8 changes: 4 additions & 4 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ docs/ @agnusmor @joanestebanr
etherman/ @ARR552 @joanestebanr
ethtxmanager/ @tclemos
gasprice/ @ARR552
jsonrpc/ @tclemos @Psykepro
jsonrpc/ @tclemos
merkletree/ @ToniRamirezM
pool/ @tclemos @Psykepro
pool/ @tclemos
proto/ @ToniRamirezM
sequencer/ @ToniRamirezM @Psykepro @agnusmor
sequencesender/ @ToniRamirezM @Psykepro @agnusmor
sequencer/ @ToniRamirezM @dpunish3r @agnusmor
sequencesender/ @ToniRamirezM @dpunish3r @agnusmor
state/ @ToniRamirezM @tclemos
synchronizer/ @ARR552 @joanestebanr
test/ @tclemos
8 changes: 4 additions & 4 deletions .github/workflows/push-docker-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ jobs:
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
push: true
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/push-docker-tagged.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ jobs:
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]' # this action will only run on tags that follow semver

- 'v[0-9]+.[0-9]+.[0-9]+' # this action will only run on tags that follow semver
jobs:
releaser:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -41,7 +40,7 @@ jobs:
mkdir -p testnet/db/scripts
cp config/environments/testnet/* testnet/config/environments/testnet
cp docker-compose.yml testnet
sed -i 's/\/config\/environments\/${ZKEVM_NETWORK}/\/config\/environments\/testnet/g' mainnet/docker-compose.yml
sed -i 's/\/config\/environments\/${ZKEVM_NETWORK}/\/config\/environments\/testnet/g' testnet/docker-compose.yml
cp db/scripts/init_prover_db.sql testnet/db/scripts
mv testnet/config/environments/testnet/example.env testnet
sed -i -e "s/image: zkevm-node/image: hermeznetwork\/zkevm-node:$GIT_TAG_NAME/g" testnet/docker-compose.yml
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/sonarqube.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,27 @@ on:
push:
branches:
- develop
- feature/sonarcloud-coverage

jobs:
sonarqube:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
# Disabling shallow clone is recommended for improving relevancy of reporting.
fetch-depth: 0

- name: Compile SCs
run: make compile-scs
working-directory: test

- name: Test
env:
ZKPROVER_URI: 127.0.0.1
run: make test-full-non-e2e
working-directory: test

# Triggering SonarQube analysis as results of it are required by Quality Gate check.
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@master
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-from-prover.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
GOARCH: ${{ matrix.goarch }}

- name: Login to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
Expand Down
5 changes: 5 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ builds:
- arm64
env:
- CGO_ENABLED=0
ldflags:
- -X github.com/0xPolygonHermez/zkevm-node.Version={{.Version}}
- -X github.com/0xPolygonHermez/zkevm-node.GitRev={{.Commit}}
- -X github.com/0xPolygonHermez/zkevm-node.BuildDate={{.Date}}
- -X github.com/0xPolygonHermez/zkevm-node.GitBranch={{.Branch}}
release:
# If set to auto, will mark the release as not ready for production
# in case there is an indicator for this in the tag e.g. v1.0.0-rc1
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN cd /src/db && packr2
RUN cd /src && make build

# CONTAINER FOR RUNNING BINARY
FROM alpine:3.18.0
FROM alpine:3.18.4
COPY --from=build /src/dist/zkevm-node /app/zkevm-node
COPY --from=build /src/config/environments/testnet/node.config.toml /app/example.config.toml
RUN apk update && apk add postgresql15-client
Expand Down
14 changes: 7 additions & 7 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ func (a *Aggregator) sendFinalProof() {
continue
}
monitoredTxID := buildMonitoredTxID(proof.BatchNumber, proof.BatchNumberFinal)
err = a.EthTxManager.Add(ctx, ethTxManagerOwner, monitoredTxID, sender, to, nil, data, nil)
err = a.EthTxManager.Add(ctx, ethTxManagerOwner, monitoredTxID, sender, to, nil, data, a.cfg.GasOffset, nil)
if err != nil {
log := log.WithFields("tx", monitoredTxID)
log.Errorf("Error to add batch verification tx to eth tx manager: %v", err)
mTxLogger := ethtxmanager.CreateLogger(ethTxManagerOwner, monitoredTxID, sender, to)
mTxLogger.Errorf("Error to add batch verification tx to eth tx manager: %v", err)
a.handleFailureToAddVerifyBatchToBeMonitored(ctx, proof)
continue
}
Expand Down Expand Up @@ -1027,23 +1027,23 @@ func (hc *healthChecker) Watch(req *grpchealth.HealthCheckRequest, server grpche
}

func (a *Aggregator) handleMonitoredTxResult(result ethtxmanager.MonitoredTxResult) {
resLog := log.WithFields("owner", ethTxManagerOwner, "txId", result.ID)
mTxResultLogger := ethtxmanager.CreateMonitoredTxResultLogger(ethTxManagerOwner, result)
if result.Status == ethtxmanager.MonitoredTxStatusFailed {
resLog.Fatal("failed to send batch verification, TODO: review this fatal and define what to do in this case")
mTxResultLogger.Fatal("failed to send batch verification, TODO: review this fatal and define what to do in this case")
}

// monitoredIDFormat: "proof-from-%v-to-%v"
idSlice := strings.Split(result.ID, "-")
proofBatchNumberStr := idSlice[2]
proofBatchNumber, err := strconv.ParseUint(proofBatchNumberStr, encoding.Base10, 0)
if err != nil {
resLog.Errorf("failed to read final proof batch number from monitored tx: %v", err)
mTxResultLogger.Errorf("failed to read final proof batch number from monitored tx: %v", err)
}

proofBatchNumberFinalStr := idSlice[4]
proofBatchNumberFinal, err := strconv.ParseUint(proofBatchNumberFinalStr, encoding.Base10, 0)
if err != nil {
resLog.Errorf("failed to read final proof batch number final from monitored tx: %v", err)
mTxResultLogger.Errorf("failed to read final proof batch number final from monitored tx: %v", err)
}

log := log.WithFields("txId", result.ID, "batches", fmt.Sprintf("%d-%d", proofBatchNumber, proofBatchNumberFinal))
Expand Down
6 changes: 3 additions & 3 deletions aggregator/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestSendFinalProof(t *testing.T) {
BatchNumberFinal: batchNumFinal,
}
finalProof := &prover.FinalProof{}
cfg := Config{SenderAddress: from.Hex()}
cfg := Config{SenderAddress: from.Hex(), GasOffset: uint64(10)}

testCases := []struct {
name string
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestSendFinalProof(t *testing.T) {
assert.True(a.verifyingProof)
}).Return(&to, data, nil).Once()
monitoredTxID := buildMonitoredTxID(batchNum, batchNumFinal)
m.ethTxManager.On("Add", mock.Anything, ethTxManagerOwner, monitoredTxID, from, &to, value, data, nil).Return(errBanana).Once()
m.ethTxManager.On("Add", mock.Anything, ethTxManagerOwner, monitoredTxID, from, &to, value, data, cfg.GasOffset, nil).Return(errBanana).Once()
m.stateMock.On("UpdateGeneratedProof", mock.Anything, recursiveProof, nil).Run(func(args mock.Arguments) {
// test is done, stop the sendFinalProof method
a.exit()
Expand All @@ -160,7 +160,7 @@ func TestSendFinalProof(t *testing.T) {
assert.True(a.verifyingProof)
}).Return(&to, data, nil).Once()
monitoredTxID := buildMonitoredTxID(batchNum, batchNumFinal)
m.ethTxManager.On("Add", mock.Anything, ethTxManagerOwner, monitoredTxID, from, &to, value, data, nil).Return(nil).Once()
m.ethTxManager.On("Add", mock.Anything, ethTxManagerOwner, monitoredTxID, from, &to, value, data, cfg.GasOffset, nil).Return(nil).Once()
ethTxManResult := ethtxmanager.MonitoredTxResult{
ID: monitoredTxID,
Status: ethtxmanager.MonitoredTxStatusConfirmed,
Expand Down
12 changes: 12 additions & 0 deletions aggregator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,16 @@ type Config struct {
// which a proof in generating state is considered to be stuck and
// allowed to be cleared.
GeneratingProofCleanupThreshold string `mapstructure:"GeneratingProofCleanupThreshold"`

// GasOffset is the amount of gas to be added to the gas estimation in order
// to provide an amount that is higher than the estimated one. This is used
// to avoid the TX getting reverted in case something has changed in the network
// state after the estimation which can cause the TX to require more gas to be
// executed.
//
// ex:
// gas estimation: 1000
// gas offset: 100
// final gas: 1100
GasOffset uint64 `mapstructure:"GasOffset"`
}
2 changes: 1 addition & 1 deletion aggregator/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type proverInterface interface {
// ethTxManager contains the methods required to send txs to
// ethereum.
type ethTxManager interface {
Add(ctx context.Context, owner, id string, from common.Address, to *common.Address, value *big.Int, data []byte, dbTx pgx.Tx) error
Add(ctx context.Context, owner, id string, from common.Address, to *common.Address, value *big.Int, data []byte, gasOffset uint64, dbTx pgx.Tx) error
Result(ctx context.Context, owner, id string, dbTx pgx.Tx) (ethtxmanager.MonitoredTxResult, error)
ResultsByStatus(ctx context.Context, owner string, statuses []ethtxmanager.MonitoredTxStatus, dbTx pgx.Tx) ([]ethtxmanager.MonitoredTxResult, error)
ProcessPendingMonitoredTxs(ctx context.Context, owner string, failedResultHandler ethtxmanager.ResultHandler, dbTx pgx.Tx)
Expand Down
10 changes: 5 additions & 5 deletions aggregator/mocks/mock_ethtxmanager.go

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

15 changes: 7 additions & 8 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func start(cliCtx *cli.Context) error {
if poolInstance == nil {
poolInstance = createPool(c.Pool, c.State.Batch.Constraints, l2ChainID, st, eventLog)
}
seq := createSequencer(*c, poolInstance, ethTxManagerStorage, st, eventLog)
seq := createSequencer(*c, poolInstance, st, eventLog)
go seq.Start(cliCtx.Context)
case SEQUENCE_SENDER:
ev.Component = event.Component_Sequence_Sender
Expand Down Expand Up @@ -217,7 +217,7 @@ func start(cliCtx *cli.Context) error {
if poolInstance == nil {
poolInstance = createPool(c.Pool, c.State.Batch.Constraints, l2ChainID, st, eventLog)
}
go runSynchronizer(*c, etherman, etm, st, poolInstance, eventLog)
go runSynchronizer(*c, etherman, ethTxManagerStorage, st, poolInstance, eventLog)
case ETHTXMANAGER:
ev.Component = event.Component_EthTxManager
ev.Description = "Running eth tx manager service"
Expand Down Expand Up @@ -281,7 +281,7 @@ func newEtherman(c config.Config) (*etherman.Client, error) {
return etherman.NewClient(c.Etherman, c.NetworkConfig.L1Config)
}

func runSynchronizer(cfg config.Config, etherman *etherman.Client, ethTxManager *ethtxmanager.Client, st *state.State, pool *pool.Pool, eventLog *event.EventLog) {
func runSynchronizer(cfg config.Config, etherman *etherman.Client, ethTxManagerStorage *ethtxmanager.PostgresStorage, st *state.State, pool *pool.Pool, eventLog *event.EventLog) {
var trustedSequencerURL string
var err error
if !cfg.IsTrustedSequencer {
Expand Down Expand Up @@ -309,8 +309,9 @@ func runSynchronizer(cfg config.Config, etherman *etherman.Client, ethTxManager
etherManForL1 = append(etherManForL1, eth)
}
}
etm := ethtxmanager.New(cfg.EthTxManager, etherman, ethTxManagerStorage, st)
sy, err := synchronizer.NewSynchronizer(
cfg.IsTrustedSequencer, etherman, etherManForL1, st, pool, ethTxManager,
cfg.IsTrustedSequencer, etherman, etherManForL1, st, pool, etm,
zkEVMClient, eventLog, cfg.NetworkConfig.Genesis, cfg.Synchronizer, cfg.Log.Environment == "development",
)
if err != nil {
Expand Down Expand Up @@ -385,15 +386,13 @@ func runJSONRPCServer(c config.Config, etherman *etherman.Client, chainID uint64
}
}

func createSequencer(cfg config.Config, pool *pool.Pool, etmStorage *ethtxmanager.PostgresStorage, st *state.State, eventLog *event.EventLog) *sequencer.Sequencer {
func createSequencer(cfg config.Config, pool *pool.Pool, st *state.State, eventLog *event.EventLog) *sequencer.Sequencer {
etherman, err := newEtherman(cfg)
if err != nil {
log.Fatal(err)
}

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

seq, err := sequencer.New(cfg.Sequencer, cfg.State.Batch, pool, st, etherman, ethTxManager, eventLog)
seq, err := sequencer.New(cfg.Sequencer, cfg.State.Batch, pool, st, etherman, eventLog)
if err != nil {
log.Fatal(err)
}
Expand Down
Loading

0 comments on commit 7bb568e

Please sign in to comment.