Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* smc

* rename matic to pol

* WIP

* Etherman + unit tests

* Addresses

* aggregator

* New genesis file

* new genesis

* state unit tests

* aggregator unit test

* sequencer uni tests

* pool unit test

* fix symLinks

* linter

* documentation

* Wip

* oldPolygonZkevmBridge

* fix e2e group 1

* linter

* docs

* Fix init Batch 1

* linter

* Fix e2e

* Fix forced

* Revert "Fix forced"

This reverts commit cfaa28b.

* wip

* fix forced e2e

* support genesis config with pointer to BatchData (0xPolygonHermez#2729)

* genesis fix

* forkID 6

* fix e2e forcedBatches again

* new smc

* genesis

* linter

* Fix e2e

* genesis

* new docker + genesis

* json doc

* fix e2e
  • Loading branch information
ARR552 authored Nov 23, 2023
1 parent a91d833 commit a4212eb
Show file tree
Hide file tree
Showing 85 changed files with 26,977 additions and 5,157 deletions.
6 changes: 3 additions & 3 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (a *Aggregator) sendFinalProof() {

// add batch verification to be monitored
sender := common.HexToAddress(a.cfg.SenderAddress)
to, data, err := a.Ethman.BuildTrustedVerifyBatchesTxData(proof.BatchNumber-1, proof.BatchNumberFinal, &inputs)
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)
Expand Down Expand Up @@ -766,15 +766,15 @@ func (a *Aggregator) getAndLockBatchToProve(ctx context.Context, prover proverIn

log.Info("Checking profitability to aggregate batch")

// pass matic collateral as zero here, bcs in smart contract fee for aggregator is not defined yet
// pass pol collateral as zero here, bcs in smart contract fee for aggregator is not defined yet
isProfitable, err := a.ProfitabilityChecker.IsProfitable(ctx, big.NewInt(0))
if err != nil {
log.Errorf("Failed to check aggregator profitability, err: %v", err)
return nil, nil, err
}

if !isProfitable {
log.Infof("Batch is not profitable, matic collateral %d", big.NewInt(0))
log.Infof("Batch is not profitable, pol collateral %d", big.NewInt(0))
return nil, nil, err
}

Expand Down
8 changes: 4 additions & 4 deletions aggregator/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestSendFinalProof(t *testing.T) {
NewLocalExitRoot: finalBatch.LocalExitRoot.Bytes(),
NewStateRoot: finalBatch.StateRoot.Bytes(),
}
m.etherman.On("BuildTrustedVerifyBatchesTxData", batchNum-1, batchNumFinal, &expectedInputs).Run(func(args mock.Arguments) {
m.etherman.On("BuildTrustedVerifyBatchesTxData", batchNum-1, batchNumFinal, &expectedInputs, common.HexToAddress(cfg.SenderAddress)).Run(func(args mock.Arguments) {
assert.True(a.verifyingProof)
}).Return(nil, nil, errBanana).Once()
m.stateMock.On("UpdateGeneratedProof", mock.Anything, recursiveProof, nil).Run(func(args mock.Arguments) {
Expand All @@ -108,7 +108,7 @@ func TestSendFinalProof(t *testing.T) {
NewLocalExitRoot: finalBatch.LocalExitRoot.Bytes(),
NewStateRoot: finalBatch.StateRoot.Bytes(),
}
m.etherman.On("BuildTrustedVerifyBatchesTxData", batchNum-1, batchNumFinal, &expectedInputs).Run(func(args mock.Arguments) {
m.etherman.On("BuildTrustedVerifyBatchesTxData", batchNum-1, batchNumFinal, &expectedInputs, common.HexToAddress(cfg.SenderAddress)).Run(func(args mock.Arguments) {
assert.True(a.verifyingProof)
}).Return(nil, nil, errBanana).Once()
m.stateMock.On("UpdateGeneratedProof", mock.Anything, recursiveProof, nil).Run(func(args mock.Arguments) {
Expand All @@ -131,7 +131,7 @@ func TestSendFinalProof(t *testing.T) {
NewLocalExitRoot: finalBatch.LocalExitRoot.Bytes(),
NewStateRoot: finalBatch.StateRoot.Bytes(),
}
m.etherman.On("BuildTrustedVerifyBatchesTxData", batchNum-1, batchNumFinal, &expectedInputs).Run(func(args mock.Arguments) {
m.etherman.On("BuildTrustedVerifyBatchesTxData", batchNum-1, batchNumFinal, &expectedInputs, common.HexToAddress(cfg.SenderAddress)).Run(func(args mock.Arguments) {
assert.True(a.verifyingProof)
}).Return(&to, data, nil).Once()
monitoredTxID := buildMonitoredTxID(batchNum, batchNumFinal)
Expand All @@ -156,7 +156,7 @@ func TestSendFinalProof(t *testing.T) {
NewLocalExitRoot: finalBatch.LocalExitRoot.Bytes(),
NewStateRoot: finalBatch.StateRoot.Bytes(),
}
m.etherman.On("BuildTrustedVerifyBatchesTxData", batchNum-1, batchNumFinal, &expectedInputs).Run(func(args mock.Arguments) {
m.etherman.On("BuildTrustedVerifyBatchesTxData", batchNum-1, batchNumFinal, &expectedInputs, common.HexToAddress(cfg.SenderAddress)).Run(func(args mock.Arguments) {
assert.True(a.verifyingProof)
}).Return(&to, data, nil).Once()
monitoredTxID := buildMonitoredTxID(batchNum, batchNumFinal)
Expand Down
2 changes: 1 addition & 1 deletion aggregator/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type ethTxManager interface {
// etherman contains the methods required to interact with ethereum
type etherman interface {
GetLatestVerifiedBatchNum() (uint64, error)
BuildTrustedVerifyBatchesTxData(lastVerifiedBatch, newVerifiedBatch uint64, inputs *ethmanTypes.FinalProofInputs) (to *common.Address, data []byte, err error)
BuildTrustedVerifyBatchesTxData(lastVerifiedBatch, newVerifiedBatch uint64, inputs *ethmanTypes.FinalProofInputs, beneficiary common.Address) (to *common.Address, data []byte, err error)
}

// aggregatorTxProfitabilityChecker interface for different profitability
Expand Down
22 changes: 11 additions & 11 deletions aggregator/mocks/mock_etherman.go

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

12 changes: 6 additions & 6 deletions aggregator/profitabilitychecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
type TxProfitabilityCheckerType string

const (
// ProfitabilityBase checks matic collateral with min reward
// ProfitabilityBase checks pol collateral with min reward
ProfitabilityBase = "base"
// ProfitabilityAcceptAll validate batch anyway and don't check anything
ProfitabilityAcceptAll = "acceptall"
)

// TxProfitabilityCheckerBase checks matic collateral with min reward
// TxProfitabilityCheckerBase checks pol collateral with min reward
type TxProfitabilityCheckerBase struct {
State stateInterface
IntervalAfterWhichBatchSentAnyway time.Duration
Expand All @@ -32,8 +32,8 @@ func NewTxProfitabilityCheckerBase(state stateInterface, interval time.Duration,
}
}

// IsProfitable checks matic collateral with min reward
func (pc *TxProfitabilityCheckerBase) IsProfitable(ctx context.Context, maticCollateral *big.Int) (bool, error) {
// IsProfitable checks pol collateral with min reward
func (pc *TxProfitabilityCheckerBase) IsProfitable(ctx context.Context, polCollateral *big.Int) (bool, error) {
//if pc.IntervalAfterWhichBatchSentAnyway != 0 {
// ok, err := isConsolidatedBatchAppeared(ctx, pc.State, pc.IntervalAfterWhichBatchSentAnyway)
// if err != nil {
Expand All @@ -44,7 +44,7 @@ func (pc *TxProfitabilityCheckerBase) IsProfitable(ctx context.Context, maticCol
// }
//}

return maticCollateral.Cmp(pc.MinReward) >= 0, nil
return polCollateral.Cmp(pc.MinReward) >= 0, nil
}

// TxProfitabilityCheckerAcceptAll validate batch anyway and don't check anything
Expand All @@ -62,7 +62,7 @@ func NewTxProfitabilityCheckerAcceptAll(state stateInterface, interval time.Dura
}

// IsProfitable validate batch anyway and don't check anything
func (pc *TxProfitabilityCheckerAcceptAll) IsProfitable(ctx context.Context, maticCollateral *big.Int) (bool, error) {
func (pc *TxProfitabilityCheckerAcceptAll) IsProfitable(ctx context.Context, polCollateral *big.Int) (bool, error) {
//if pc.IntervalAfterWhichBatchSentAnyway != 0 {
// ok, err := isConsolidatedBatchAppeared(ctx, pc.State, pc.IntervalAfterWhichBatchSentAnyway)
// if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/approve.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func approveTokens(ctx *cli.Context) error {
return err
}

tx, err := etherman.ApproveMatic(ctx.Context, auth.From, amount, c.NetworkConfig.L1Config.ZkEVMAddr)
tx, err := etherman.ApprovePol(ctx.Context, auth.From, amount, c.NetworkConfig.L1Config.ZkEVMAddr)
if err != nil {
return err
}
Expand Down
6 changes: 1 addition & 5 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,7 @@ func runMigrations(c db.Config, name string) {
}

func newEtherman(c config.Config) (*etherman.Client, error) {
etherman, err := etherman.NewClient(c.Etherman, c.NetworkConfig.L1Config)
if err != nil {
return nil, err
}
return etherman, nil
return etherman.NewClient(c.Etherman, c.NetworkConfig.L1Config)
}

func runSynchronizer(cfg config.Config, etherman *etherman.Client, ethTxManagerStorage *ethtxmanager.PostgresStorage, st *state.State, pool *pool.Pool, eventLog *event.EventLog) {
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func Test_Defaults(t *testing.T) {
expectedValue: common.HexToAddress("0xa997cfD539E703921fD1e3Cf25b4c241a27a4c7A"),
},
{
path: "NetworkConfig.L1Config.MaticAddr",
path: "NetworkConfig.L1Config.PolAddr",
expectedValue: common.HexToAddress("0x1319D23c2F7034F52Eb07399702B040bA278Ca49"),
},
{
Expand Down
Loading

0 comments on commit a4212eb

Please sign in to comment.