forked from 0xPolygonHermez/zkevm-node
-
Notifications
You must be signed in to change notification settings - Fork 118
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/beethoven #44
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3bebb97
WIP
arnaubennassar e774772
Update Beethoven
arnaubennassar 60e5635
Fix var coment
arnaubennassar 7cc5d3b
Update generated config docs
arnaubennassar 9d1a90c
Fix linter
arnaubennassar 0abeeff
Rename beethoven repo
vcastellm e2ef6a9
Rename beethoven repo
vcastellm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
# CONTAINER FOR BUILDING BINARY | ||
FROM golang:1.21 AS build | ||
|
||
# TODO: REMOVE SSH BEFORE MERGING, ONCE AGGLAYER IS PUBLIC | ||
|
||
# SSH KEY | ||
ARG SSH_PRIVATE_KEY | ||
RUN mkdir /root/.ssh/ | ||
RUN echo "${SSH_PRIVATE_KEY}" > /root/.ssh/id_rsa | ||
RUN chmod 700 /root/.ssh/id_rsa | ||
RUN echo "Host github.com\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config | ||
RUN git config --global --add url."[email protected]:".insteadOf "https://github.com/" | ||
ENV GOPRIVATE=github.com/0xPolygon/agglayer | ||
|
||
# INSTALL DEPENDENCIES | ||
RUN go install github.com/gobuffalo/packr/v2/[email protected] | ||
COPY go.mod go.sum /src/ | ||
|
@@ -11,6 +22,9 @@ COPY . /src | |
RUN cd /src/db && packr2 | ||
RUN cd /src && make build | ||
|
||
# REMOVE SSH PRIVATE KEY | ||
RUN rm /root/.ssh/id_rsa | ||
|
||
# CONTAINER FOR RUNNING BINARY | ||
FROM alpine:3.18.0 | ||
COPY --from=build /src/dist/zkevm-node /app/zkevm-node | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import ( | ||
"context" | ||
"crypto/ecdsa" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
|
@@ -13,6 +14,9 @@ | |
"time" | ||
"unicode" | ||
|
||
"github.com/0xPolygon/agglayer/client" | ||
agglayerTypes "github.com/0xPolygon/agglayer/rpc/types" | ||
Check failure on line 18 in aggregator/aggregator.go GitHub Actions / json-schema (1.21.x, amd64)
|
||
"github.com/0xPolygon/agglayer/tx" | ||
Check failure on line 19 in aggregator/aggregator.go GitHub Actions / json-schema (1.21.x, amd64)
|
||
"github.com/0xPolygonHermez/zkevm-node/aggregator/metrics" | ||
"github.com/0xPolygonHermez/zkevm-node/aggregator/prover" | ||
"github.com/0xPolygonHermez/zkevm-node/config/types" | ||
|
@@ -22,6 +26,7 @@ | |
"github.com/0xPolygonHermez/zkevm-node/log" | ||
"github.com/0xPolygonHermez/zkevm-node/state" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/jackc/pgx/v4" | ||
"google.golang.org/grpc" | ||
grpchealth "google.golang.org/grpc/health/grpc_health_v1" | ||
|
@@ -64,6 +69,9 @@ | |
srv *grpc.Server | ||
ctx context.Context | ||
exit context.CancelFunc | ||
|
||
sequencerPrivateKey *ecdsa.PrivateKey | ||
agglayerClient client.ClientInterface | ||
} | ||
|
||
// New creates a new aggregator. | ||
|
@@ -72,6 +80,8 @@ | |
stateInterface stateInterface, | ||
ethTxManager ethTxManager, | ||
etherman etherman, | ||
agglayerClient client.ClientInterface, | ||
sequencerPrivateKey *ecdsa.PrivateKey, | ||
) (Aggregator, error) { | ||
var profitabilityChecker aggregatorTxProfitabilityChecker | ||
switch cfg.TxProfitabilityCheckerType { | ||
|
@@ -81,6 +91,23 @@ | |
profitabilityChecker = NewTxProfitabilityCheckerAcceptAll(stateInterface, cfg.IntervalAfterWhichBatchConsolidateAnyway.Duration) | ||
} | ||
|
||
if cfg.SettlementBackend == agglayer { | ||
if sequencerPrivateKey == nil { | ||
return Aggregator{}, fmt.Errorf("the private key of the sequencer needs to be provided") | ||
} | ||
sequencerAddr, err := etherman.GetSequencerAddr() | ||
if err != nil { | ||
return Aggregator{}, err | ||
} | ||
actualAddr := crypto.PubkeyToAddress(sequencerPrivateKey.PublicKey) | ||
if sequencerAddr != actualAddr { | ||
return Aggregator{}, fmt.Errorf( | ||
"the private key of the sequencer needs to be provided. Provided private key is for addr %s but sequencer addr is %s", | ||
actualAddr.Hex(), sequencerAddr.Hex(), | ||
) | ||
} | ||
} | ||
|
||
a := Aggregator{ | ||
cfg: cfg, | ||
|
||
|
@@ -92,7 +119,9 @@ | |
TimeSendFinalProofMutex: &sync.RWMutex{}, | ||
TimeCleanupLockedProofs: cfg.CleanupLockedProofsInterval, | ||
|
||
finalProof: make(chan finalProofMsg), | ||
finalProof: make(chan finalProofMsg), | ||
agglayerClient: agglayerClient, | ||
sequencerPrivateKey: sequencerPrivateKey, | ||
} | ||
|
||
return a, nil | ||
|
@@ -266,27 +295,22 @@ | |
|
||
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) | ||
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 | ||
} | ||
log.Infof("Final proof inputs: NewLocalExitRoot [%#x], NewStateRoot [%#x]", inputs.NewLocalExitRoot, inputs.NewStateRoot) | ||
|
||
// 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) | ||
switch a.cfg.SettlementBackend { | ||
case L1: | ||
if success := a.settleProofToL1(ctx, proof, inputs); !success { | ||
continue | ||
} | ||
case agglayer: | ||
if success := a.settleProofToagglayer(ctx, proof, inputs); !success { | ||
continue | ||
} | ||
default: | ||
if success := a.settleProofToL1(ctx, proof, inputs); !success { | ||
continue | ||
} | ||
} | ||
|
||
a.resetVerifyProofTime() | ||
a.endProofVerification() | ||
|
@@ -1094,3 +1118,78 @@ | |
runes[0] = unicode.ToUpper(runes[0]) | ||
return string(runes) | ||
} | ||
|
||
func (a *Aggregator) settleProofToL1(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) | ||
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 { | ||
log := log.WithFields("tx", monitoredTxID) | ||
log.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) settleProofToagglayer(ctx context.Context, proof *state.Proof, inputs ethmanTypes.FinalProofInputs) (success bool) { | ||
l1Contract := a.Ethman.GetL1ContractAddress() | ||
proofStrNo0x := strings.TrimPrefix(inputs.FinalProof.Proof, "0x") | ||
proofBytes := common.Hex2Bytes(proofStrNo0x) | ||
tx := tx.Tx{ | ||
L1Contract: l1Contract, | ||
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), | ||
}, | ||
} | ||
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is another option to do it via git token
Dockerfile:
scripts/git-configure.sh
.gittoken (ignorred)
Also just FYI