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

[R4R]-{develop}:Optimize the rollup service #1301

Merged
merged 30 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7267401
add mt-batcher flag
Ethanncnm Jul 17, 2023
08d47b8
add mt-batcher params flag.
Ethanncnm Jul 18, 2023
17ceb59
finish mt-batcher logic change
Ethanncnm Jul 18, 2023
7f8f8d6
add judge logic
Ethanncnm Jul 19, 2023
f15226b
Merge branch 'develop' into ethan/rollup_service_optimize
Ethanncnm Jul 19, 2023
0db15e5
finish mt-batcher
Ethanncnm Jul 19, 2023
bc679c5
Merge branch 'develop' into ethan/rollup_service_optimize
Ethanncnm Jul 19, 2023
be697f3
add batch_submitter flag config
Ethanncnm Jul 20, 2023
5350abd
finish adding MinRollupTxn and MaxRollupTxn config for limiting rollu…
Ethanncnm Jul 20, 2023
6eabc03
cancel the limit of requiring 1 deposit tx for rollup submitting
Ethanncnm Jul 20, 2023
7b93641
delete size limit for rollup process
Ethanncnm Jul 20, 2023
969590e
add rollup timeout config flag.
Ethanncnm Jul 21, 2023
3fed71b
Merge branch 'develop' into ethan/rollup_service_optimize
Ethanncnm Jul 21, 2023
a31b7b3
fix some error
Ethanncnm Jul 25, 2023
e2dbc71
delete unnecessary judge logic
Ethanncnm Jul 25, 2023
5c2c89e
fix bug
Ethanncnm Jul 25, 2023
7ca1218
fix bug
Ethanncnm Jul 26, 2023
d9aad4a
Merge branch 'develop' into ethan/rollup_service_optimize
guoshijiang Jul 26, 2023
6a51463
fix PR comments problem
Ethanncnm Jul 27, 2023
c0d2968
Merge branch 'develop' into ethan/rollup_service_optimize
Ethanncnm Jul 27, 2023
51567ef
Merge remote-tracking branch 'origin/ethan/rollup_service_optimize' i…
Ethanncnm Jul 27, 2023
04ff800
fix PR comments problem for annotation
Ethanncnm Jul 27, 2023
ec18824
delete unnecessary log info msg
Ethanncnm Jul 27, 2023
9b35527
Add new timeout check logic
Ethanncnm Aug 1, 2023
916db4b
Merge branch 'develop' into ethan/rollup_service_optimize
guoshijiang Aug 1, 2023
7401719
change time check
Ethanncnm Aug 1, 2023
715ede3
Merge remote-tracking branch 'origin/ethan/rollup_service_optimize' i…
Ethanncnm Aug 1, 2023
2dc46e9
fix config error drop
Ethanncnm Aug 2, 2023
388dfff
fix import format
Ethanncnm Aug 2, 2023
446864e
delete unused import ERC20
Ethanncnm Aug 2, 2023
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
85 changes: 41 additions & 44 deletions batch-submitter/batch_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/getsentry/sentry-go"
"github.com/urfave/cli"

"github.com/mantlenetworkio/mantle/batch-submitter/drivers/proposer"
"github.com/mantlenetworkio/mantle/batch-submitter/drivers/sequencer"
Expand All @@ -17,6 +15,9 @@ import (
"github.com/mantlenetworkio/mantle/bss-core/dial"
"github.com/mantlenetworkio/mantle/bss-core/metrics"
"github.com/mantlenetworkio/mantle/bss-core/txmgr"

"github.com/getsentry/sentry-go"
"github.com/urfave/cli"
)

// Main is the entrypoint into the batch submitter service. This method returns
Expand All @@ -30,10 +31,6 @@ func Main(gitVersion string) func(ctx *cli.Context) error {
return err
}

log.Info("Config parsed",
"min_tx_size", cfg.MinL1TxSize,
"max_tx_size", cfg.MaxL1TxSize)

// The call to defer is done here so that any errors logged from
// this point on are posted to Sentry before exiting.
if cfg.SentryEnable {
Expand Down Expand Up @@ -130,23 +127,22 @@ func Main(gitVersion string) func(ctx *cli.Context) error {
var services []*bsscore.Service
if cfg.RunTxBatchSubmitter {
batchTxDriver, err := sequencer.NewDriver(sequencer.Config{
Name: "Sequencer",
L1Client: l1Client,
L2Client: l2Client,
BlockOffset: cfg.BlockOffset,
MinTxSize: cfg.MinL1TxSize,
MaxTxSize: cfg.MaxL1TxSize,
MaxPlaintextBatchSize: cfg.MaxPlaintextBatchSize,
DaUpgradeBlock: cfg.DaUpgradeBlock,
DAAddr: common.Address(common.HexToAddress(cfg.DAAddress)),
CTCAddr: ctcAddress,
ChainID: chainID,
PrivKey: sequencerPrivKey,
EnableSequencerHsm: cfg.EnableSequencerHsm,
SequencerHsmAddress: cfg.SequencerHsmAddress,
SequencerHsmAPIName: cfg.SequencerHsmAPIName,
SequencerHsmCreden: cfg.SequencerHsmCreden,
BatchType: sequencer.BatchTypeFromString(cfg.SequencerBatchType),
Name: "Sequencer",
L1Client: l1Client,
L2Client: l2Client,
BlockOffset: cfg.BlockOffset,
DaUpgradeBlock: cfg.DaUpgradeBlock,
DAAddr: common.Address(common.HexToAddress(cfg.DAAddress)),
CTCAddr: ctcAddress,
ChainID: chainID,
PrivKey: sequencerPrivKey,
EnableSequencerHsm: cfg.EnableSequencerHsm,
SequencerHsmAddress: cfg.SequencerHsmAddress,
SequencerHsmAPIName: cfg.SequencerHsmAPIName,
SequencerHsmCreden: cfg.SequencerHsmCreden,
BatchType: sequencer.BatchTypeFromString(cfg.SequencerBatchType),
MaxRollupTxn: cfg.MaxRollupTxn,
MinRollupTxn: cfg.MinRollupTxn,
})
if err != nil {
return err
Expand All @@ -164,27 +160,28 @@ func Main(gitVersion string) func(ctx *cli.Context) error {

if cfg.RunStateBatchSubmitter {
batchStateDriver, err := proposer.NewDriver(proposer.Config{
Name: "Proposer",
L1Client: l1Client,
L2Client: l2Client,
TssClient: tssClient,
BlockOffset: cfg.BlockOffset,
MinStateRootElements: cfg.MinStateRootElements,
MaxStateRootElements: cfg.MaxStateRootElements,
SCCAddr: sccAddress,
CTCAddr: ctcAddress,
FPRollupAddr: common.HexToAddress(cfg.FPRollupAddress),
ChainID: chainID,
PrivKey: proposerPrivKey,
SccRollback: cfg.EnableSccRollback,
MaxBatchSubmissionTime: cfg.MaxBatchSubmissionTime,
PollInterval: cfg.PollInterval,
FinalityConfirmations: cfg.FinalityConfirmations,
EnableProposerHsm: cfg.EnableProposerHsm,
ProposerHsmAddress: cfg.ProposerHsmAddress,
ProposerHsmCreden: cfg.ProposerHsmCreden,
ProposerHsmAPIName: cfg.ProposerHsmAPIName,
AllowL2AutoRollback: cfg.AllowL2AutoRollback,
Name: "Proposer",
L1Client: l1Client,
L2Client: l2Client,
TssClient: tssClient,
BlockOffset: cfg.BlockOffset,
MinStateRootElements: cfg.MinStateRootElements,
MaxStateRootElements: cfg.MaxStateRootElements,
SCCAddr: sccAddress,
CTCAddr: ctcAddress,
FPRollupAddr: common.HexToAddress(cfg.FPRollupAddress),
ChainID: chainID,
PrivKey: proposerPrivKey,
SccRollback: cfg.EnableSccRollback,
RollupTimeout: cfg.RollupTimeout,
PollInterval: cfg.PollInterval,
FinalityConfirmations: cfg.FinalityConfirmations,
EnableProposerHsm: cfg.EnableProposerHsm,
ProposerHsmAddress: cfg.ProposerHsmAddress,
ProposerHsmCreden: cfg.ProposerHsmCreden,
ProposerHsmAPIName: cfg.ProposerHsmAPIName,
AllowL2AutoRollback: cfg.AllowL2AutoRollback,
MinTimeoutStateRootElements: cfg.MinTimeoutStateRootElements,
})
if err != nil {
return err
Expand Down
88 changes: 42 additions & 46 deletions batch-submitter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,6 @@ type Config struct {
// FPRollupAddress is the fraud proof rollup contract address.
FPRollupAddress string

// MinL1TxSize is the minimum size in bytes of any L1 transactions generated
// by the batch submitter.
MinL1TxSize uint64

// MaxL1TxSize is the maximum size in bytes of any L1 transactions generated
// by the batch submitter.
MaxL1TxSize uint64

// MaxPlaintextL1TxSize is the maximum size in bytes of the plaintext tx
// data encoded in batches.
MaxPlaintextBatchSize uint64

// MinStateRootElements is the minimum number of state root elements that
// can be submitted in single proposer batch.
MinStateRootElements uint64
Expand All @@ -105,9 +93,8 @@ type Config struct {
// in a batch.
MaxTxBatchCount uint64

// MaxBatchSubmissionTime is the maximum amount of time that we will
// wait before submitting an under-sized batch.
MaxBatchSubmissionTime time.Duration
// RollupTimeout is the criterion which used to determine if the transaction is timeout.
RollupTimeout time.Duration

// PollInterval is the delay between querying L2 for more transaction
// and creating a new batch.
Expand Down Expand Up @@ -232,6 +219,15 @@ type Config struct {

// batch submitter rollback
AllowL2AutoRollback bool

// MaxRollupTxn is the maximum length of rollup batch transactions for every round.
MaxRollupTxn uint64

// MinRollupTxn is the minimum length of rollup batch transactions for every round.
MinRollupTxn uint64

// MinTimeoutStateRootElements is the minimum length of timeout rollup batch transactions for every round.
MinTimeoutStateRootElements uint64
Ethanncnm marked this conversation as resolved.
Show resolved Hide resolved
}

// NewConfig parses the Config from the provided flags or environment variables.
Expand All @@ -250,12 +246,9 @@ func NewConfig(ctx *cli.Context) (Config, error) {
CTCAddress: ctx.GlobalString(flags.CTCAddressFlag.Name),
SCCAddress: ctx.GlobalString(flags.SCCAddressFlag.Name),
FPRollupAddress: ctx.GlobalString(flags.FPRollupAddressFlag.Name),
MinL1TxSize: ctx.GlobalUint64(flags.MinL1TxSizeFlag.Name),
MaxL1TxSize: ctx.GlobalUint64(flags.MaxL1TxSizeFlag.Name),
MaxPlaintextBatchSize: ctx.GlobalUint64(flags.MaxPlaintextBatchSizeFlag.Name),
MinStateRootElements: ctx.GlobalUint64(flags.MinStateRootElementsFlag.Name),
MaxStateRootElements: ctx.GlobalUint64(flags.MaxStateRootElementsFlag.Name),
MaxBatchSubmissionTime: ctx.GlobalDuration(flags.MaxBatchSubmissionTimeFlag.Name),
RollupTimeout: ctx.GlobalDuration(flags.RollupTimeoutFlag.Name),
PollInterval: ctx.GlobalDuration(flags.PollIntervalFlag.Name),
NumConfirmations: ctx.GlobalUint64(flags.NumConfirmationsFlag.Name),
SafeAbortNonceTooLowCount: ctx.GlobalUint64(flags.SafeAbortNonceTooLowCountFlag.Name),
Expand All @@ -266,33 +259,36 @@ func NewConfig(ctx *cli.Context) (Config, error) {
SafeMinimumEtherBalance: ctx.GlobalUint64(flags.SafeMinimumEtherBalanceFlag.Name),
ClearPendingTxs: ctx.GlobalBool(flags.ClearPendingTxsFlag.Name),
/* Optional Flags */
LogLevel: ctx.GlobalString(flags.LogLevelFlag.Name),
LogTerminal: ctx.GlobalBool(flags.LogTerminalFlag.Name),
SentryEnable: ctx.GlobalBool(flags.SentryEnableFlag.Name),
SentryDsn: ctx.GlobalString(flags.SentryDsnFlag.Name),
SentryTraceRate: ctx.GlobalDuration(flags.SentryTraceRateFlag.Name),
BlockOffset: ctx.GlobalUint64(flags.BlockOffsetFlag.Name),
SequencerPrivateKey: ctx.GlobalString(flags.SequencerPrivateKeyFlag.Name),
ProposerPrivateKey: ctx.GlobalString(flags.ProposerPrivateKeyFlag.Name),
Mnemonic: ctx.GlobalString(flags.MnemonicFlag.Name),
SequencerHDPath: ctx.GlobalString(flags.SequencerHDPathFlag.Name),
ProposerHDPath: ctx.GlobalString(flags.ProposerHDPathFlag.Name),
SequencerBatchType: ctx.GlobalString(flags.SequencerBatchType.Name),
MetricsServerEnable: ctx.GlobalBool(flags.MetricsServerEnableFlag.Name),
MetricsHostname: ctx.GlobalString(flags.MetricsHostnameFlag.Name),
MetricsPort: ctx.GlobalUint64(flags.MetricsPortFlag.Name),
DisableHTTP2: ctx.GlobalBool(flags.HTTP2DisableFlag.Name),
EnableSccRollback: ctx.GlobalBool(flags.SccRollbackFlag.Name),
EnableSequencerHsm: ctx.GlobalBool(flags.EnableSequencerHsmFlag.Name),
SequencerHsmAddress: ctx.GlobalString(flags.SequencerHsmAddressFlag.Name),
SequencerHsmAPIName: ctx.GlobalString(flags.SequencerHsmAPIName.Name),
SequencerHsmCreden: ctx.GlobalString(flags.SequencerHsmCreden.Name),
EnableProposerHsm: ctx.GlobalBool(flags.EnableProposerHsmFlag.Name),
ProposerHsmAddress: ctx.GlobalString(flags.ProposerHsmAddressFlag.Name),
ProposerHsmAPIName: ctx.GlobalString(flags.ProposerHsmAPIName.Name),
ProposerHsmCreden: ctx.GlobalString(flags.ProposerHsmCreden.Name),
RollupClientHttp: ctx.GlobalString(flags.RollupClientHttpFlag.Name),
AllowL2AutoRollback: ctx.GlobalBool(flags.AllowL2AutoRollback.Name),
LogLevel: ctx.GlobalString(flags.LogLevelFlag.Name),
LogTerminal: ctx.GlobalBool(flags.LogTerminalFlag.Name),
SentryEnable: ctx.GlobalBool(flags.SentryEnableFlag.Name),
SentryDsn: ctx.GlobalString(flags.SentryDsnFlag.Name),
SentryTraceRate: ctx.GlobalDuration(flags.SentryTraceRateFlag.Name),
BlockOffset: ctx.GlobalUint64(flags.BlockOffsetFlag.Name),
SequencerPrivateKey: ctx.GlobalString(flags.SequencerPrivateKeyFlag.Name),
ProposerPrivateKey: ctx.GlobalString(flags.ProposerPrivateKeyFlag.Name),
Mnemonic: ctx.GlobalString(flags.MnemonicFlag.Name),
SequencerHDPath: ctx.GlobalString(flags.SequencerHDPathFlag.Name),
ProposerHDPath: ctx.GlobalString(flags.ProposerHDPathFlag.Name),
SequencerBatchType: ctx.GlobalString(flags.SequencerBatchType.Name),
MetricsServerEnable: ctx.GlobalBool(flags.MetricsServerEnableFlag.Name),
MetricsHostname: ctx.GlobalString(flags.MetricsHostnameFlag.Name),
MetricsPort: ctx.GlobalUint64(flags.MetricsPortFlag.Name),
DisableHTTP2: ctx.GlobalBool(flags.HTTP2DisableFlag.Name),
EnableSccRollback: ctx.GlobalBool(flags.SccRollbackFlag.Name),
EnableSequencerHsm: ctx.GlobalBool(flags.EnableSequencerHsmFlag.Name),
SequencerHsmAddress: ctx.GlobalString(flags.SequencerHsmAddressFlag.Name),
SequencerHsmAPIName: ctx.GlobalString(flags.SequencerHsmAPIName.Name),
SequencerHsmCreden: ctx.GlobalString(flags.SequencerHsmCreden.Name),
EnableProposerHsm: ctx.GlobalBool(flags.EnableProposerHsmFlag.Name),
ProposerHsmAddress: ctx.GlobalString(flags.ProposerHsmAddressFlag.Name),
ProposerHsmAPIName: ctx.GlobalString(flags.ProposerHsmAPIName.Name),
ProposerHsmCreden: ctx.GlobalString(flags.ProposerHsmCreden.Name),
RollupClientHttp: ctx.GlobalString(flags.RollupClientHttpFlag.Name),
AllowL2AutoRollback: ctx.GlobalBool(flags.AllowL2AutoRollback.Name),
MaxRollupTxn: ctx.GlobalUint64(flags.MaxRollupTxnFlag.Name),
MinRollupTxn: ctx.GlobalUint64(flags.MinRollupTxnFlag.Name),
MinTimeoutStateRootElements: ctx.GlobalUint64(flags.MinTimeoutStateRootElementsFlag.Name),
}

err := ValidateConfig(&cfg)
Expand Down
64 changes: 33 additions & 31 deletions batch-submitter/drivers/proposer/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ import (
"sync"
"time"

kms "cloud.google.com/go/kms/apiv1"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
"google.golang.org/api/option"

"github.com/mantlenetworkio/mantle/batch-submitter/bindings/ctc"
"github.com/mantlenetworkio/mantle/batch-submitter/bindings/scc"
Expand All @@ -35,6 +33,9 @@ import (
l2types "github.com/mantlenetworkio/mantle/l2geth/core/types"
l2ethclient "github.com/mantlenetworkio/mantle/l2geth/ethclient"
tss_types "github.com/mantlenetworkio/mantle/tss/common"

kms "cloud.google.com/go/kms/apiv1"
"google.golang.org/api/option"
)

// stateRootSize is the size in bytes of a state root.
Expand All @@ -46,27 +47,28 @@ const blockBuffer = 2
var bigOne = new(big.Int).SetUint64(1) //nolint:unused

type Config struct {
Name string
L1Client *ethclient.Client
L2Client *l2ethclient.Client
TssClient *tssClient.Client
BlockOffset uint64
MaxStateRootElements uint64
MinStateRootElements uint64
SCCAddr common.Address
CTCAddr common.Address
FPRollupAddr common.Address
ChainID *big.Int
PrivKey *ecdsa.PrivateKey
SccRollback bool
MaxBatchSubmissionTime time.Duration
PollInterval time.Duration
FinalityConfirmations uint64
EnableProposerHsm bool
ProposerHsmCreden string
ProposerHsmAddress string
ProposerHsmAPIName string
AllowL2AutoRollback bool
Name string
L1Client *ethclient.Client
L2Client *l2ethclient.Client
TssClient *tssClient.Client
BlockOffset uint64
MaxStateRootElements uint64
MinStateRootElements uint64
SCCAddr common.Address
CTCAddr common.Address
FPRollupAddr common.Address
ChainID *big.Int
PrivKey *ecdsa.PrivateKey
SccRollback bool
RollupTimeout time.Duration
PollInterval time.Duration
FinalityConfirmations uint64
EnableProposerHsm bool
ProposerHsmCreden string
ProposerHsmAddress string
ProposerHsmAPIName string
AllowL2AutoRollback bool
MinTimeoutStateRootElements uint64
}

type Driver struct {
Expand Down Expand Up @@ -242,7 +244,6 @@ func (d *Driver) GetBatchBlockRange(
return nil, nil, fmt.Errorf("invalid range, "+
"end(%v) < start(%v)", end, start)
}

return start, end, nil
}

Expand All @@ -264,19 +265,20 @@ func (d *Driver) CraftBatchTx(
d.lastStart = start
d.lastCommitTime = time.Now().Add(-d.cfg.PollInterval)
}

//If the waiting time has not been reached, then check whether the minimum stateroot number
//is met. if not, return nil
if time.Now().Add(-d.cfg.MaxBatchSubmissionTime).Before(d.lastCommitTime) {
// Abort if we don't have enough state roots to meet our minimum
// requirement.
rangeLen := end.Uint64() - start.Uint64()
if rangeLen < d.cfg.MinStateRootElements {
rollupTxn := end.Uint64() - start.Uint64()
if rollupTxn < d.cfg.MinStateRootElements && (d.lastCommitTime.Add(d.cfg.RollupTimeout).After(time.Now()) || rollupTxn < d.cfg.MinTimeoutStateRootElements) {
if rollupTxn < d.cfg.MinStateRootElements {
log.Info(name+" number of state roots below minimum",
"num_state_roots", rangeLen,
"num_state_roots", rollupTxn,
"min_state_roots", d.cfg.MinStateRootElements)
return nil, nil
}
log.Info(name+" number of timeout state roots below minimum or timeout can't satisfy the constrain",
"num_state_roots", rollupTxn,
"min_timeout_state_roots", d.cfg.MinTimeoutStateRootElements)
return nil, nil
}

var blocks []*l2types.Block
Expand Down
Loading
Loading