Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into release/v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vcastellm committed Oct 14, 2024
2 parents ef6849a + 8e2015f commit e233e6d
Show file tree
Hide file tree
Showing 30 changed files with 4,368 additions and 650 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ book/
index.html
tmp
.vscode
coverage.out
coverage.html
.idea
.idea/*

Expand Down
4 changes: 2 additions & 2 deletions aggoracle/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (

gerContractL1 "github.com/0xPolygon/cdk-contracts-tooling/contracts/manual/globalexitrootnopush0"
"github.com/0xPolygon/cdk/aggoracle"
"github.com/0xPolygon/cdk/test/helpers"
"github.com/0xPolygon/cdk/test/aggoraclehelpers"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient/simulated"
"github.com/stretchr/testify/require"
)

func TestEVM(t *testing.T) {
env := helpers.SetupAggoracleWithEVMChain(t)
env := aggoraclehelpers.SetupAggoracleWithEVMChain(t)
runTest(t, env.GERL1Contract, env.AggOracleSender, env.L1Client, env.AuthL1)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package aggregator
package agglayer

import (
"context"
Expand All @@ -13,6 +13,10 @@ import (
"github.com/ethereum/go-ethereum/common"
)

const errCodeAgglayerRateLimitExceeded int = -10007

var ErrAgglayerRateLimitExceeded = fmt.Errorf("agglayer rate limit exceeded")

// AgglayerClientInterface is the interface that defines the methods that the AggLayerClient will implement
type AgglayerClientInterface interface {
SendTx(signedTx SignedTx) (common.Hash, error)
Expand All @@ -39,6 +43,9 @@ func (c *AggLayerClient) SendTx(signedTx SignedTx) (common.Hash, error) {
}

if response.Error != nil {
if response.Error.Code == errCodeAgglayerRateLimitExceeded {
return common.Hash{}, ErrAgglayerRateLimitExceeded
}
return common.Hash{}, fmt.Errorf("%v %v", response.Error.Code, response.Error.Message)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package aggregator
package agglayer

import (
"crypto/ecdsa"
Expand Down
43 changes: 24 additions & 19 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/0xPolygon/cdk-rpc/rpc"
cdkTypes "github.com/0xPolygon/cdk-rpc/types"
"github.com/0xPolygon/cdk/aggregator/agglayer"
ethmanTypes "github.com/0xPolygon/cdk/aggregator/ethmantypes"
"github.com/0xPolygon/cdk/aggregator/prover"
cdkcommon "github.com/0xPolygon/cdk/common"
Expand Down Expand Up @@ -66,10 +67,10 @@ type Aggregator struct {
cfg Config
logger *log.Logger

state stateInterface
etherman etherman
ethTxManager *ethtxmanager.Client
streamClient *datastreamer.StreamClient
state StateInterface
etherman Etherman
ethTxManager EthTxManagerClient
streamClient StreamClient
l1Syncr synchronizer.Synchronizer
halted atomic.Bool

Expand Down Expand Up @@ -97,16 +98,16 @@ type Aggregator struct {
exit context.CancelFunc

sequencerPrivateKey *ecdsa.PrivateKey
aggLayerClient AgglayerClientInterface
aggLayerClient agglayer.AgglayerClientInterface
}

// New creates a new aggregator.
func New(
ctx context.Context,
cfg Config,
logger *log.Logger,
stateInterface stateInterface,
etherman etherman) (*Aggregator, error) {
stateInterface StateInterface,
etherman Etherman) (*Aggregator, error) {
var profitabilityChecker aggregatorTxProfitabilityChecker

switch cfg.TxProfitabilityCheckerType {
Expand Down Expand Up @@ -167,12 +168,12 @@ func New(
}

var (
aggLayerClient AgglayerClientInterface
aggLayerClient agglayer.AgglayerClientInterface
sequencerPrivateKey *ecdsa.PrivateKey
)

if !cfg.SyncModeOnlyEnabled && cfg.SettlementBackend == AggLayer {
aggLayerClient = NewAggLayerClient(cfg.AggLayerURL)
aggLayerClient = agglayer.NewAggLayerClient(cfg.AggLayerURL)

sequencerPrivateKey, err = newKeyFromKeystore(cfg.SequencerPrivateKey)
if err != nil {
Expand Down Expand Up @@ -921,10 +922,11 @@ func (a *Aggregator) settleWithAggLayer(
inputs ethmanTypes.FinalProofInputs) bool {
proofStrNo0x := strings.TrimPrefix(inputs.FinalProof.Proof, "0x")
proofBytes := common.Hex2Bytes(proofStrNo0x)
tx := Tx{

tx := agglayer.Tx{
LastVerifiedBatch: cdkTypes.ArgUint64(proof.BatchNumber - 1),
NewVerifiedBatch: cdkTypes.ArgUint64(proof.BatchNumberFinal),
ZKP: ZKP{
ZKP: agglayer.ZKP{
NewStateRoot: common.BytesToHash(inputs.NewStateRoot),
NewLocalExitRoot: common.BytesToHash(inputs.NewLocalExitRoot),
Proof: cdkTypes.ArgBytes(proofBytes),
Expand All @@ -943,9 +945,12 @@ func (a *Aggregator) settleWithAggLayer(
a.logger.Debug("final proof signedTx: ", signedTx.Tx.ZKP.Proof.Hex())
txHash, err := a.aggLayerClient.SendTx(*signedTx)
if err != nil {
a.logger.Errorf("failed to send tx to the agglayer: %v", err)
if errors.Is(err, agglayer.ErrAgglayerRateLimitExceeded) {
a.logger.Errorf("%s. Config param VerifyProofInterval should match the agglayer configured rate limit.", err)
} else {
a.logger.Errorf("failed to send tx to the agglayer: %v", err)
}
a.handleFailureToAddVerifyBatchToBeMonitored(ctx, proof)

return false
}

Expand Down Expand Up @@ -1013,7 +1018,7 @@ func (a *Aggregator) handleFailureToAddVerifyBatchToBeMonitored(ctx context.Cont

// buildFinalProof builds and return the final proof for an aggregated/batch proof.
func (a *Aggregator) buildFinalProof(
ctx context.Context, prover proverInterface, proof *state.Proof) (*prover.FinalProof, error) {
ctx context.Context, prover ProverInterface, proof *state.Proof) (*prover.FinalProof, error) {
tmpLogger := a.logger.WithFields(
"prover", prover.Name(),
"proverId", prover.ID(),
Expand Down Expand Up @@ -1059,7 +1064,7 @@ func (a *Aggregator) buildFinalProof(
// build the final proof. If no proof is provided it looks for a previously
// generated proof. If the proof is eligible, then the final proof generation
// is triggered.
func (a *Aggregator) tryBuildFinalProof(ctx context.Context, prover proverInterface, proof *state.Proof) (bool, error) {
func (a *Aggregator) tryBuildFinalProof(ctx context.Context, prover ProverInterface, proof *state.Proof) (bool, error) {
proverName := prover.Name()
proverID := prover.ID()

Expand Down Expand Up @@ -1245,7 +1250,7 @@ func (a *Aggregator) unlockProofsToAggregate(ctx context.Context, proof1 *state.
}

func (a *Aggregator) getAndLockProofsToAggregate(
ctx context.Context, prover proverInterface) (*state.Proof, *state.Proof, error) {
ctx context.Context, prover ProverInterface) (*state.Proof, *state.Proof, error) {
tmpLogger := a.logger.WithFields(
"prover", prover.Name(),
"proverId", prover.ID(),
Expand Down Expand Up @@ -1293,7 +1298,7 @@ func (a *Aggregator) getAndLockProofsToAggregate(
return proof1, proof2, nil
}

func (a *Aggregator) tryAggregateProofs(ctx context.Context, prover proverInterface) (bool, error) {
func (a *Aggregator) tryAggregateProofs(ctx context.Context, prover ProverInterface) (bool, error) {
proverName := prover.Name()
proverID := prover.ID()

Expand Down Expand Up @@ -1458,7 +1463,7 @@ func (a *Aggregator) getVerifiedBatchAccInputHash(ctx context.Context, batchNumb
}

func (a *Aggregator) getAndLockBatchToProve(
ctx context.Context, prover proverInterface,
ctx context.Context, prover ProverInterface,
) (*state.Batch, []byte, *state.Proof, error) {
proverID := prover.ID()
proverName := prover.Name()
Expand Down Expand Up @@ -1574,7 +1579,7 @@ func (a *Aggregator) getAndLockBatchToProve(
return &dbBatch.Batch, dbBatch.Witness, proof, nil
}

func (a *Aggregator) tryGenerateBatchProof(ctx context.Context, prover proverInterface) (bool, error) {
func (a *Aggregator) tryGenerateBatchProof(ctx context.Context, prover ProverInterface) (bool, error) {
tmpLogger := a.logger.WithFields(
"prover", prover.Name(),
"proverId", prover.ID(),
Expand Down
Loading

0 comments on commit e233e6d

Please sign in to comment.