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

fix l2coinbase #31

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion aggregator/mocks/mock_dbtx.go

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

2 changes: 1 addition & 1 deletion aggregator/mocks/mock_etherman.go

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

2 changes: 1 addition & 1 deletion aggregator/mocks/mock_ethtxmanager.go

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

2 changes: 1 addition & 1 deletion aggregator/mocks/mock_profitabilitychecker.go

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

2 changes: 1 addition & 1 deletion aggregator/mocks/mock_prover.go

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

2 changes: 1 addition & 1 deletion aggregator/mocks/mock_state.go

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

3 changes: 2 additions & 1 deletion config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ MaxBinaries = 473170
MaxSteps = 7570538
TxLifetimeCheckTimeout = "10m"
MaxTxLifetime = "3h"
L2Coinbase = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
[Sequencer.Finalizer]
GERDeadlineTimeout = "5s"
ForcedBatchDeadlineTimeout = "60s"
Expand All @@ -116,8 +117,8 @@ MaxTxLifetime = "3h"
[SequenceSender]
WaitPeriodSendSequence = "5s"
LastBatchVirtualizationTimeMaxWaitPeriod = "5s"
MaxTxSizeForL1 = 131072
MaxBatchesForL1 = 10
L2Coinbase = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
PrivateKey = {Path = "/pk/sequencer.keystore", Password = "testonly"}
UseValidium = true

Expand Down
4 changes: 2 additions & 2 deletions docs/config-file/node-config-doc.html

Large diffs are not rendered by default.

132 changes: 66 additions & 66 deletions docs/config-file/node-config-doc.md

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions docs/config-file/node-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,16 @@
"300ms"
]
},
"L2Coinbase": {
"items": {
"type": "integer"
},
"type": "array",
"maxItems": 20,
"minItems": 20,
"description": "L2Coinbase defines which addess is going to receive the fees",
"default": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
},
"Finalizer": {
"properties": {
"GERDeadlineTimeout": {
Expand Down Expand Up @@ -715,7 +725,7 @@
"MaxTxSizeForL1": {
"type": "integer",
"description": "MaxTxSizeForL1 is the maximum size a single transaction can have. This field has\nnon-trivial consequences: larger transactions than 128KB are significantly harder and\nmore expensive to propagate; larger transactions also take more resources\nto validate whether they fit into the pool or not.",
"default": 0
"default": 131072
},
"MaxBatchesForL1": {
"type": "integer",
Expand All @@ -731,16 +741,6 @@
"minItems": 20,
"description": "SenderAddress defines which private key the eth tx manager needs to use\nto sign the L1 txs"
},
"L2Coinbase": {
"items": {
"type": "integer"
},
"type": "array",
"maxItems": 20,
"minItems": 20,
"description": "L2Coinbase defines which addess is going to receive the fees",
"default": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
},
"PrivateKey": {
"properties": {
"Path": {
Expand Down
2 changes: 1 addition & 1 deletion etherman/mock_etherscan.go

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

2 changes: 1 addition & 1 deletion etherman/mock_ethgasstation.go

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

2 changes: 1 addition & 1 deletion ethtxmanager/mock_etherman_test.go

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

2 changes: 1 addition & 1 deletion ethtxmanager/mock_state_test.go

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

2 changes: 1 addition & 1 deletion gasprice/mock_etherman.go

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

2 changes: 1 addition & 1 deletion gasprice/mock_pool.go

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

2 changes: 1 addition & 1 deletion jsonrpc/mock_storage.go

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

2 changes: 1 addition & 1 deletion jsonrpc/mocks/mock_dbtx.go

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

2 changes: 1 addition & 1 deletion jsonrpc/mocks/mock_etherman.go

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

2 changes: 1 addition & 1 deletion jsonrpc/mocks/mock_pool.go

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

2 changes: 1 addition & 1 deletion jsonrpc/mocks/mock_state.go

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

4 changes: 4 additions & 0 deletions sequencer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sequencer

import (
"github.com/0xPolygonHermez/zkevm-node/config/types"
"github.com/ethereum/go-ethereum/common"
)

// Config represents the configuration of a sequencer
Expand Down Expand Up @@ -53,6 +54,9 @@ type Config struct {
// MaxTxLifetime is the time a tx can be in the sequencer/worker memory
MaxTxLifetime types.Duration `mapstructure:"MaxTxLifetime"`

// L2Coinbase defines which addess is going to receive the fees
L2Coinbase common.Address `mapstructure:"L2Coinbase"`

// Finalizer's specific config properties
Finalizer FinalizerCfg `mapstructure:"Finalizer"`

Expand Down
8 changes: 6 additions & 2 deletions sequencer/dbmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func (d *dbManager) GetBatchByNumber(ctx context.Context, batchNumber uint64, db
return d.state.GetBatchByNumber(ctx, batchNumber, dbTx)
}

func (d *dbManager) DeleteBatchByNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) error {
return d.state.DeleteBatchByNumber(ctx, batchNumber, dbTx)
}

// ClosingBatchParameters contains the necessary parameters to close a batch
type ClosingBatchParameters struct {
BatchNumber uint64
Expand Down Expand Up @@ -72,10 +76,10 @@ func (d *dbManager) OpenBatch(ctx context.Context, processingContext state.Proce
}

// CreateFirstBatch is using during genesis
func (d *dbManager) CreateFirstBatch(ctx context.Context, sequencerAddress common.Address) state.ProcessingContext {
func (d *dbManager) CreateFirstBatch(ctx context.Context, l2coinbase common.Address) state.ProcessingContext {
processingCtx := state.ProcessingContext{
BatchNumber: 1,
Coinbase: sequencerAddress,
Coinbase: l2coinbase,
Timestamp: time.Now(),
GlobalExitRoot: state.ZeroHash,
}
Expand Down
39 changes: 29 additions & 10 deletions sequencer/finalizer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sequencer

import (
"bytes"
"context"
"encoding/json"
"errors"
Expand Down Expand Up @@ -40,7 +41,7 @@ type finalizer struct {
effectiveGasPriceCfg EffectiveGasPriceCfg
closingSignalCh ClosingSignalCh
isSynced func(ctx context.Context) bool
sequencerAddress common.Address
l2coinbase common.Address
worker workerInterface
dbManager dbManagerInterface
executor stateInterface
Expand Down Expand Up @@ -112,7 +113,7 @@ func newFinalizer(
worker workerInterface,
dbManager dbManagerInterface,
executor stateInterface,
sequencerAddr common.Address,
l2coinbase common.Address,
isSynced func(ctx context.Context) bool,
closingSignalCh ClosingSignalCh,
batchConstraints batchConstraints,
Expand All @@ -123,7 +124,7 @@ func newFinalizer(
effectiveGasPriceCfg: effectiveGasPriceCfg,
closingSignalCh: closingSignalCh,
isSynced: isSynced,
sequencerAddress: sequencerAddr,
l2coinbase: l2coinbase,
worker: worker,
dbManager: dbManager,
executor: executor,
Expand Down Expand Up @@ -962,11 +963,29 @@ func (f *finalizer) syncWithState(ctx context.Context, lastBatchNum *uint64) err
return err
}
} else {
f.batch, err = f.dbManager.GetWIPBatch(ctx)
if err != nil {
return fmt.Errorf("failed to get work-in-progress batch, err: %w", err)
if bytes.Equal(lastBatch.Coinbase.Bytes(), f.l2coinbase.Bytes()) {
f.batch, err = f.dbManager.GetWIPBatch(ctx)
if err != nil {
return fmt.Errorf("failed to get work-in-progress batch, err: %w", err)
}
} else {
oldGER := lastBatch.GlobalExitRoot
if err := f.dbManager.DeleteBatchByNumber(ctx, *lastBatchNum, nil); err != nil {
BananaLF marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("failed to delete last no-closed batch, err: %w", err)
}
lastBatch, err = f.dbManager.GetLastBatch(ctx)
if err != nil {
return fmt.Errorf("failed to get last batch again, err: %w", err)
}
oldStateRoot := lastBatch.StateRoot

f.batch, err = f.openWIPBatch(ctx, *lastBatchNum, oldGER, oldStateRoot)
if err != nil {
return err
}
}
}

log.Infof("Initial Batch: %+v", f.batch)
log.Infof("Initial Batch.StateRoot: %s", f.batch.stateRoot.String())
log.Infof("Initial Batch.GER: %s", f.batch.globalExitRoot.String())
Expand All @@ -978,7 +997,7 @@ func (f *finalizer) syncWithState(ctx context.Context, lastBatchNum *uint64) err
BatchNumber: *lastBatchNum,
OldStateRoot: f.batch.stateRoot,
GlobalExitRoot: f.batch.globalExitRoot,
Coinbase: f.sequencerAddress,
Coinbase: f.l2coinbase,
Timestamp: f.batch.timestamp,
Transactions: make([]byte, 0, 1),
Caller: stateMetrics.SequencerCallerLabel,
Expand Down Expand Up @@ -1030,7 +1049,7 @@ func (f *finalizer) processForcedBatch(ctx context.Context, lastBatchNumberInSta
OldStateRoot: stateRoot,
GlobalExitRoot: forcedBatch.GlobalExitRoot,
Transactions: forcedBatch.RawTxsData,
Coinbase: f.sequencerAddress,
Coinbase: f.l2coinbase,
Timestamp: now(),
Caller: stateMetrics.SequencerCallerLabel,
}
Expand Down Expand Up @@ -1093,7 +1112,7 @@ func (f *finalizer) openWIPBatch(ctx context.Context, batchNum uint64, ger, stat

return &WipBatch{
batchNumber: batchNum,
coinbase: f.sequencerAddress,
coinbase: f.l2coinbase,
initialStateRoot: stateRoot,
stateRoot: stateRoot,
timestamp: openBatchResp.Timestamp,
Expand Down Expand Up @@ -1129,7 +1148,7 @@ func (f *finalizer) closeBatch(ctx context.Context) error {
func (f *finalizer) openBatch(ctx context.Context, num uint64, ger common.Hash, dbTx pgx.Tx) (state.ProcessingContext, error) {
processingCtx := state.ProcessingContext{
BatchNumber: num,
Coinbase: f.sequencerAddress,
Coinbase: f.l2coinbase,
Timestamp: now(),
GlobalExitRoot: ger,
}
Expand Down
Loading
Loading