Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/agglayer #67

Open
wants to merge 60 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
7914028
draft integration of beethoven endpoint for proof settlement
nivida Jan 12, 2024
05b033d
Getter added for RollupID to the etherman struct and updated the depe…
nivida Jan 12, 2024
0888768
trusted sequencer private key added to cmd/run, aggregator/aggregator…
nivida Jan 16, 2024
4abe334
overtook aggregator_test changes from Arnau's PR
nivida Jan 16, 2024
a04fa54
etherman mock for aggregator test updated with mockery
nivida Jan 16, 2024
bd64c7b
dependencies updated
nivida Jan 16, 2024
1eced59
Merge remote-tracking branch 'origin' into feature/beethoven-integration
vcastellm Jan 19, 2024
5c48881
Go get
vcastellm Jan 19, 2024
44a23ee
fix smtProof
agnusmor Jan 19, 2024
e2879d2
Go sum
vcastellm Jan 19, 2024
02d5a48
Merge tag 'v0.5.0-RC19' into feature/beethoven-integration
vcastellm Jan 19, 2024
5431256
fix: using constructor to create StackTrie
praetoriansentry Jan 22, 2024
6a468ec
Load PK from Keystore file config
vcastellm Jan 23, 2024
6e8ad9e
fix migration batch wip field. fix sequence when no wip batch (#3126)
agnusmor Jan 23, 2024
22b2651
fix Leaves smtproof (#3127)
ARR552 Jan 23, 2024
1962ca1
Add l2block log dump when storing error. Refactor ProcessBatchV2 logs…
agnusmor Jan 24, 2024
c3dddf7
fix panic etherman (#3133)
ARR552 Jan 24, 2024
8e1e5e9
Fix GetL2Hash function. Use tx L2 hash returned by the executor when …
agnusmor Jan 24, 2024
19d493e
remove l2 tx hash computation and use data stored in the state return…
tclemos Jan 25, 2024
8124e52
etrog: fix permissionless errors (#3140)
joanestebanr Jan 25, 2024
895c1e0
Fix missing batch bookmark (#3122)
ToniRamirezM Jan 25, 2024
6feb7b8
fix wipL2Block deltaTimestamp (#3142)
agnusmor Jan 25, 2024
646603e
ensure tx order in stream (#3144)
ToniRamirezM Jan 25, 2024
4ddba20
fix wipL2Block stateRoot (#3145)
agnusmor Jan 25, 2024
1825164
fix panic NewStackTrie (#3146)
ARR552 Jan 25, 2024
bc51813
fix sync initalization for etrog (#3147)
tclemos Jan 25, 2024
4dc6258
fix wipL2block imStateRoot (#3148)
agnusmor Jan 26, 2024
6ed0e0d
Merge remote-tracking branch 'origin' into feature/beethoven-integration
vcastellm Jan 26, 2024
0a92869
go mod tidy
vcastellm Jan 26, 2024
ece3819
Update refs to agglayer
vcastellm Jan 26, 2024
86fcb5b
fix tracer to work by block stateroot instead of by tx (#3150)
tclemos Jan 26, 2024
75a957f
update prover image (#3151)
ToniRamirezM Jan 26, 2024
f69f0f9
if a trusted batch is empty and WIP just create the entry in state.ba…
joanestebanr Jan 26, 2024
65a507e
fix trace for tx index greater than 0 (#3153)
tclemos Jan 26, 2024
8f79b21
add cardona.zip (#3154)
joanestebanr Jan 26, 2024
c100d40
Fix default value when creating transaction.used_sha256_hashes field …
agnusmor Jan 26, 2024
1a8dd7d
add cardona testnet (#2909) (#3155)
joanestebanr Jan 26, 2024
f3b86d4
new fields in stream (#3149)
ToniRamirezM Jan 26, 2024
b47986a
set stateManagerPurge to false in Cardona (#3158)
joanestebanr Jan 26, 2024
eea3833
synchronizer: fix case emtpy batch and unittest (#3159)
joanestebanr Jan 27, 2024
7497d07
update prover image to v4.0.1 (#3160)
agnusmor Jan 27, 2024
12022c2
update prover image to v4.0.2 (#3162)
agnusmor Jan 27, 2024
a296484
Add a note in deployment instruction to restart rpc after forkId 7 (#…
joanestebanr Jan 27, 2024
5dfe003
change position of point 10
agnusmor Jan 27, 2024
479ba46
add point 11
agnusmor Jan 27, 2024
9e2a95d
add lines
agnusmor Jan 27, 2024
b216df0
add breakline
agnusmor Jan 27, 2024
f5bc983
add lines
agnusmor Jan 27, 2024
87bb731
add line
agnusmor Jan 27, 2024
fd05d50
EncodeBatchV2 allow to set Tx in binary (#3143)
joanestebanr Jan 29, 2024
b938572
synchronizer: unittest and remove pool_reorg (#3111)
joanestebanr Jan 30, 2024
4e0d164
Pull changes from zkevm-node @ release/v0.5.0
rachit77 Jan 30, 2024
3f537af
avoid unnecessary get code call when address doesn't have code hash (…
tclemos Jan 30, 2024
188969b
fix parentHash when storing a new L2 block (#3171) (#3174)
agnusmor Jan 31, 2024
aed5088
new geth version v1.13.11 (#3179)
ARR552 Jan 31, 2024
2f51cda
Fix/rom error (#3177) (#3178)
ARR552 Feb 1, 2024
cb2424a
synchronizer: update fromTrusted fix cache update (#3169) (#3183)
joanestebanr Feb 1, 2024
0faaad7
Merge remote-tracking branch 'origin/develop' into feature/beethoven-…
vcastellm Feb 1, 2024
36930bb
Merge latest changes
vcastellm Feb 1, 2024
d6a47d3
Merge remote-tracking branch 'upstream/feature/beethoven-integration'…
vcastellm Feb 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/jsonschema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 #v3
uses: actions/checkout@v4
# https://github.com/actions/checkout#Checkout-pull-request-HEAD-commit-instead-of-merge-commit
# Checkout pull request HEAD commit instead of merge commit
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.21.x
- name: Checkout code
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
uses: actions/checkout@v4
- name: Lint
run: |
make install-linter
Expand Down
75 changes: 75 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: release

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+' # this action will only run on tags that follow semver
jobs:
releaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21

- name: Get packr
run: go install github.com/gobuffalo/packr/v2/packr2@v2.8.3

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_RELEASE }}

- name: Get tag
uses: olegtarasov/get-tag@v2.1.2
id: tagName

- name: Put cardona, testnet and mainnet artifacts into a single zip
run: |
# CARDONA
mkdir -p cardona/config/environments/cardona
mkdir -p cardona/db/scripts
cp config/environments/cardona/* cardona/config/environments/cardona
cp docker-compose.yml cardona
sed -i 's/\/config\/environments\/${ZKEVM_NETWORK}/\/config\/environments\/cardona/g' cardona/docker-compose.yml
cp db/scripts/init_prover_db.sql cardona/db/scripts
mv cardona/config/environments/cardona/example.env cardona
sed -i -e "s/image: zkevm-node/image: hermeznetwork\/zkevm-node:$GIT_TAG_NAME/g" cardona/docker-compose.yml
zip -r cardona.zip cardona
# TESTNET
mkdir -p testnet/config/environments/testnet
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' 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
zip -r testnet.zip testnet
# MAINNET
mkdir -p mainnet/config/environments/mainnet
mkdir -p mainnet/db/scripts
cp config/environments/mainnet/* mainnet/config/environments/mainnet
cp docker-compose.yml mainnet
sed -i 's/\/config\/environments\/${ZKEVM_NETWORK}/\/config\/environments\/mainnet/g' mainnet/docker-compose.yml
cp db/scripts/init_prover_db.sql mainnet/db/scripts
mv mainnet/config/environments/mainnet/example.env mainnet
sed -i -e "s/image: zkevm-node/image: hermeznetwork\/zkevm-node:$GIT_TAG_NAME/g" mainnet/docker-compose.yml
zip -r mainnet.zip mainnet

- name: Publish cardona, testnet and mainnet zip into release
uses: AButler/upload-release-assets@v2.0
with:
files: 'cardona.zip;testnet.zip;mainnet.zip'
repo-token: ${{ secrets.TOKEN_RELEASE }}
release-tag: ${{ steps.tagName.outputs.tag }}

4 changes: 2 additions & 2 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-full-non-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
env:
Expand Down
190 changes: 161 additions & 29 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"context"
"crypto/ecdsa"
"encoding/json"
"errors"
"fmt"
Expand All @@ -13,6 +14,10 @@
"time"
"unicode"

"github.com/0xPolygon/agglayer/tx"

Check failure on line 17 in aggregator/aggregator.go

View workflow job for this annotation

GitHub Actions / json-schema (1.21.x, amd64)

github.com/0xPolygon/agglayer@v0.0.0-20240126091628-9016453dc02b: invalid version: git ls-remote -q origin in /home/runner/go/pkg/mod/cache/vcs/7c387218d32c30b42d7f16ea9c6d5515d4d876b117f4d008fd68123e67afa92f: exit status 128:

"github.com/0xPolygon/agglayer/client"
agglayerTypes "github.com/0xPolygon/agglayer/rpc/types"

Check failure on line 20 in aggregator/aggregator.go

View workflow job for this annotation

GitHub Actions / json-schema (1.21.x, amd64)

github.com/0xPolygon/agglayer@v0.0.0-20240126091628-9016453dc02b: invalid version: git ls-remote -q origin in /home/runner/go/pkg/mod/cache/vcs/7c387218d32c30b42d7f16ea9c6d5515d4d876b117f4d008fd68123e67afa92f: exit status 128:
"github.com/0xPolygonHermez/zkevm-node/aggregator/metrics"
"github.com/0xPolygonHermez/zkevm-node/aggregator/prover"
"github.com/0xPolygonHermez/zkevm-node/config/types"
Expand Down Expand Up @@ -65,6 +70,9 @@
srv *grpc.Server
ctx context.Context
exit context.CancelFunc

AggLayerClient client.ClientInterface
sequencerPrivateKey *ecdsa.PrivateKey
}

// New creates a new aggregator.
Expand All @@ -73,6 +81,8 @@
stateInterface stateInterface,
ethTxManager ethTxManager,
etherman etherman,
agglayerClient client.ClientInterface,
sequencerPrivateKey *ecdsa.PrivateKey,
) (Aggregator, error) {
var profitabilityChecker aggregatorTxProfitabilityChecker
switch cfg.TxProfitabilityCheckerType {
Expand All @@ -94,6 +104,9 @@
TimeCleanupLockedProofs: cfg.CleanupLockedProofsInterval,

finalProof: make(chan finalProofMsg),

AggLayerClient: agglayerClient,
sequencerPrivateKey: sequencerPrivateKey,
}

return a, nil
Expand Down Expand Up @@ -267,34 +280,139 @@

log.Infof("Final proof inputs: NewLocalExitRoot [%#x], NewStateRoot [%#x]", inputs.NewLocalExitRoot, inputs.NewStateRoot)

// add batch verification to be monitored
sender := common.HexToAddress(a.cfg.SenderAddress)
to, data, err := a.Ethman.BuildTrustedVerifyBatchesTxData(proof.BatchNumber-1, proof.BatchNumberFinal, &inputs, sender)
if err != nil {
log.Errorf("Error estimating batch verification to add to eth tx manager: %v", err)
a.handleFailureToAddVerifyBatchToBeMonitored(ctx, proof)
continue
}
monitoredTxID := buildMonitoredTxID(proof.BatchNumber, proof.BatchNumberFinal)
err = a.EthTxManager.Add(ctx, ethTxManagerOwner, monitoredTxID, sender, to, nil, data, a.cfg.GasOffset, nil)
if err != nil {
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
switch a.cfg.SettlementBackend {
case AggLayer:
if success := a.settleWithAggLayer(ctx, proof, inputs); !success {
continue
}
default:
if success := a.settleDirect(ctx, proof, inputs); !success {
continue
}
}

// process monitored batch verifications before starting a next cycle
a.EthTxManager.ProcessPendingMonitoredTxs(ctx, ethTxManagerOwner, func(result ethtxmanager.MonitoredTxResult, dbTx pgx.Tx) {
a.handleMonitoredTxResult(result)
}, nil)

a.resetVerifyProofTime()
a.endProofVerification()
}
}
}

func (a *Aggregator) settleDirect(
ctx context.Context,
proof *state.Proof,
inputs ethmanTypes.FinalProofInputs,
) (success bool) {
// add batch verification to be monitored
sender := common.HexToAddress(a.cfg.SenderAddress)

to, data, err := a.Ethman.BuildTrustedVerifyBatchesTxData(
proof.BatchNumber-1,
proof.BatchNumberFinal,
&inputs,
sender,
)
if err != nil {
log.Errorf("Error estimating batch verification to add to eth tx manager: %v", err)
a.handleFailureToAddVerifyBatchToBeMonitored(ctx, proof)

return false
}

monitoredTxID := buildMonitoredTxID(proof.BatchNumber, proof.BatchNumberFinal)
err = a.EthTxManager.Add(
ctx,
ethTxManagerOwner,
monitoredTxID,
sender,
to,
nil,
data,
a.cfg.GasOffset,
nil,
)
if err != nil {
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)

return false
}

// process monitored batch verifications before starting a next cycle
a.EthTxManager.ProcessPendingMonitoredTxs(
ctx,
ethTxManagerOwner,
func(result ethtxmanager.MonitoredTxResult, dbTx pgx.Tx) {
a.handleMonitoredTxResult(result)
},
nil,
)

return true
}

func (a *Aggregator) settleWithAggLayer(
ctx context.Context,
proof *state.Proof,
inputs ethmanTypes.FinalProofInputs,
) (success bool) {
proofStrNo0x := strings.TrimPrefix(inputs.FinalProof.Proof, "0x")
proofBytes := common.Hex2Bytes(proofStrNo0x)
tx := tx.Tx{
LastVerifiedBatch: agglayerTypes.ArgUint64(proof.BatchNumber - 1),
NewVerifiedBatch: agglayerTypes.ArgUint64(proof.BatchNumberFinal),
ZKP: tx.ZKP{
NewStateRoot: common.BytesToHash(inputs.NewStateRoot),
NewLocalExitRoot: common.BytesToHash(inputs.NewLocalExitRoot),
Proof: agglayerTypes.ArgBytes(proofBytes),
},
RollupID: a.Ethman.GetRollupId(),
}
signedTx, err := tx.Sign(a.sequencerPrivateKey)

if err != nil {
log.Errorf("failed to sign tx: %v", err)
a.handleFailureToSendToAggLayer(ctx, proof)

return false
}

log.Debug("final proof signedTx: ", signedTx.Tx.ZKP.Proof.Hex())
txHash, err := a.AggLayerClient.SendTx(*signedTx)
if err != nil {
log.Errorf("failed to send tx to the interop: %v", err)
a.handleFailureToSendToAggLayer(ctx, proof)

return false
}

log.Infof("tx %s sent to agglayer, waiting to be mined", txHash.Hex())
log.Debugf("Timeout set to %f seconds", a.cfg.AggLayerTxTimeout.Duration.Seconds())
waitCtx, cancelFunc := context.WithDeadline(ctx, time.Now().Add(a.cfg.AggLayerTxTimeout.Duration))
defer cancelFunc()
if err := a.AggLayerClient.WaitTxToBeMined(txHash, waitCtx); err != nil {
log.Errorf("interop didn't mine the tx: %v", err)
a.handleFailureToSendToAggLayer(ctx, proof)

return false
}

// TODO: wait for synchronizer to catch up
return true
}

func (a *Aggregator) handleFailureToSendToAggLayer(ctx context.Context, proof *state.Proof) {
log := log.WithFields("proofId", proof.ProofID, "batches", fmt.Sprintf("%d-%d", proof.BatchNumber, proof.BatchNumberFinal))
proof.GeneratingSince = nil

err := a.State.UpdateGeneratedProof(ctx, proof, nil)
if err != nil {
log.Errorf("Failed updating proof state (false): %v", err)
}

a.endProofVerification()
}

func (a *Aggregator) handleFailureToAddVerifyBatchToBeMonitored(ctx context.Context, proof *state.Proof) {
log := log.WithFields("proofId", proof.ProofID, "batches", fmt.Sprintf("%d-%d", proof.BatchNumber, proof.BatchNumberFinal))
proof.GeneratingSince = nil
Expand Down Expand Up @@ -1004,6 +1122,15 @@
if err != nil {
return nil, err
}
leaves, err := a.State.GetLeafsByL1InfoRoot(ctx, *l1InfoRoot, nil)
if err != nil {
return nil, err
}

aLeaves := make([][32]byte, len(leaves))
for i, leaf := range leaves {
aLeaves[i] = l1infotree.HashLeafData(leaf.GlobalExitRoot.GlobalExitRoot, leaf.PreviousBlockHash, uint64(leaf.Timestamp.Unix()))
}

for _, l2blockRaw := range batchRawData.Blocks {
_, contained := l1InfoTreeData[l2blockRaw.IndexL1InfoTree]
Expand All @@ -1013,20 +1140,25 @@
return nil, err
}

leaves, err := a.State.GetLeafsByL1InfoRoot(ctx, l1InfoTreeExitRootStorageEntry.L1InfoTreeRoot, nil)
// Calculate smt proof
smtProof, calculatedL1InfoRoot, err := tree.ComputeMerkleProof(l2blockRaw.IndexL1InfoTree, aLeaves)
if err != nil {
return nil, err
}

aLeaves := make([][32]byte, len(leaves))
for i, leaf := range leaves {
aLeaves[i] = l1infotree.HashLeafData(leaf.GlobalExitRoot.GlobalExitRoot, leaf.PreviousBlockHash, uint64(leaf.Timestamp.Unix()))
if l1InfoRoot != nil && *l1InfoRoot != calculatedL1InfoRoot {
for i, l := range aLeaves {
log.Info("AllLeaves[%d]: %s", i, common.Bytes2Hex(l[:]))
}
for i, s := range smtProof {
log.Info("smtProof[%d]: %s", i, common.Bytes2Hex(s[:]))
}
return nil, fmt.Errorf("error: l1InfoRoot mismatch. L1InfoRoot: %s, calculatedL1InfoRoot: %s. l1InfoTreeIndex: %d", l1InfoRoot.String(), calculatedL1InfoRoot.String(), l2blockRaw.IndexL1InfoTree)
}

// Calculate smt proof
smtProof, _, err := tree.ComputeMerkleProof(l2blockRaw.IndexL1InfoTree, aLeaves)
if err != nil {
return nil, err
log.Debugf("L1InfoRoot: %s", l1InfoRoot.String())

for i, proof := range smtProof {
log.Debugf("smtProof[%d]: %s", i, common.Bytes2Hex(proof[:]))
}

protoProof := make([][]byte, len(smtProof))
Expand Down
Loading
Loading