diff --git a/.gitignore b/.gitignore index 0ef017b38..04e5f81d6 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,4 @@ ops/data/** dist/ packages/contracts/test/data/ packages/contracts/abi/ +gas-oracle/gas-oracle-data/ diff --git a/CHANGELOG.md b/CHANGELOG.md index c16b61347..25b8dd691 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,58 @@ # Changelog +## [v0.4.3](https://github.com/mantlenetworkio/mantle/commits/v0.4.3) - 2023-08-16 + +### Features +- DA + - Added DA license([#1263](https://github.com/mantlenetworkio/mantle/pull/1263)) +- RollUp Service + - Optimized the rollup service([#1301](https://github.com/mantlenetworkio/mantle/pull/1301)) + - Log optimization for mt-batcher and da-retriever([#1329](https://github.com/mantlenetworkio/mantle/pull/1329)) + - Modified for Rollup services optimization code([#1334](https://github.com/mantlenetworkio/mantle/pull/1334)) +- SDK + - Updated @mantleio/sdk to version 0.2.2([#1349](https://github.com/mantlenetworkio/mantle/pull/1349)) + +### Bug Fixes +- Fixed spelling errors in some documents([#1300](https://github.com/mantlenetworkio/mantle/pull/1300)) +- Added Mantle audit report files([#1333](https://github.com/mantlenetworkio/mantle/pull/1333)) +- Deleted error judge logic,which causing incorrect judgment logic and resulting in timeout configuration failure([#1337](https://github.com/mantlenetworkio/mantle/pull/1337)) +- Handled testnet MNT token address compatibility([#1338](https://github.com/mantlenetworkio/mantle/pull/1338)) +- Fixed gas oracle go mod and dockerfile([#1341](https://github.com/mantlenetworkio/mantle/pull/1341),[#1342](https://github.com/mantlenetworkio/mantle/pull/1342)) +- Fixed gas oracle update frequency and block log query range([#1344](https://github.com/mantlenetworkio/mantle/pull/1344),[#1347](https://github.com/mantlenetworkio/mantle/pull/1347)) +- Updated gas oracle metric, fixed bigint cmp formula and fee_Scalar false alarm([#1345](https://github.com/mantlenetworkio/mantle/pull/1345),[#1346](https://github.com/mantlenetworkio/mantle/pull/1346)) + + +## [v0.4.3-alpha.0](https://github.com/mantlenetworkio/mantle/commits/v0.4.3-alpha.0) - 2023-08-03 + +### Features +- DTL + - Optimized performance by separating L1 and L2 process execution time for synchronous data ([#1298](https://github.com/mantlenetworkio/mantle/pull/1298)) +- SDK + - Enhanced compatibility by aligning the standard-bridge with the selected chainID ([#1268](https://github.com/mantlenetworkio/mantle/pull/1268)) +- GasOracle + - Improved metric accuracy by modifying token_ratio ([#1310](https://github.com/mantlenetworkio/mantle/pull/1310)) + +### Bug Fixes +- Resolved a 'nonce too high' error caused by the DA verifier([#1313](https://github.com/mantlenetworkio/mantle/pull/1313)) +- Fixed a panic issue during traceCall operation, eliminating unexpected program crashes ([#1305](https://github.com/mantlenetworkio/mantle/pull/1305)) +- Handled unhandled errors in DA upgrade tool and NewStateTransition of l2geth, enhancing error handling and preventing potential issues ([#1288](https://github.com/mantlenetworkio/mantle/pull/1288), [#1295](https://github.com/mantlenetworkio/mantle/pull/1295)) +- Strengthened seed generation process security by introducing passphrase protection ([#1297](https://github.com/mantlenetworkio/mantle/pull/1297)) +- Addressed nonce overflow and other security-related concerns, bolstering system security ([#1293](https://github.com/mantlenetworkio/mantle/pull/1293), [#1292](https://github.com/mantlenetworkio/mantle/pull/1292)) +- Improved JWT secret key configuration and handling for enhanced security ([#1226](https://github.com/mantlenetworkio/mantle/pull/1226)) +- Renamed 'rollup' to 'Accepted on layer1', enhancing clarity and reflecting its role in the network's hierarchy ([#1314](https://github.com/mantlenetworkio/mantle/pull/1314)) +- Resolved the issue of the 'Log/txstatus' element not found, addressing a gap in log information ([#1264](https://github.com/mantlenetworkio/mantle/pull/1264)) +- Cleaned up unused DA contracts, optimizing the codebase by removing redundant contracts ([#1283](https://github.com/mantlenetworkio/mantle/pull/1283)) +- Rectified Mantle token compilation errors on the Foundry platform, ensuring successful compilation ([#1282](https://github.com/mantlenetworkio/mantle/pull/1282)) +- Fixed go mod and mt-challenger configuration issues, modified 'WMANTLE9' to 'WMANTLE' for compatibility and clarity ([#1302](https://github.com/mantlenetworkio/mantle/pull/1302), [#1281](https://github.com/mantlenetworkio/mantle/pull/1281)) +- Addressed 'sigma MNT-35' issue, conducted a TSS security audit fix, ensuring accurate handling of 'sigma MNT-35' and enhancing TSS security ([#1257](https://github.com/mantlenetworkio/mantle/pull/1257)) +- Fixed ConsenSys audit issue: cs-6.18, ensuring compliance with audit requirements ([#1243](https://github.com/mantlenetworkio/mantle/pull/1243)) +- Addressed various ConsenSys audit issues (cs-6.30, cs-6.42, cs-6.40, cs-6.37, cs-6.14, cs-6.34, cs-6.22, cs-6.33), ensuring codebase compliance ([#1219](https://github.com/mantlenetworkio/mantle/pull/1219), [#1212](https://github.com/mantlenetworkio/mantle/pull/1212), [#1210](https://github.com/mantlenetworkio/mantle/pull/1210), [#1207](https://github.com/mantlenetworkio/mantle/pull/1207), [#1204](https://github.com/mantlenetworkio/mantle/pull/1204), [#1194](https://github.com/mantlenetworkio/mantle/pull/1194), [#1191](https://github.com/mantlenetworkio/mantle/pull/1191), [#1188](https://github.com/mantlenetworkio/mantle/pull/1188)) +- Resolved lock threshold validation issue, enhancing security and preventing potential vulnerabilities ([#1227](https://github.com/mantlenetworkio/mantle/pull/1227)) +- Fixed jwt secret key configuration issue, improving the handling of secret keys ([#1226](https://github.com/mantlenetworkio/mantle/pull/1226)) +- Resolved ConsenSys minor audit issues (cs-6.35, cs-6.43, cs-6.44, cs-6.45), ensuring adherence to audit recommendations ([#1217](https://github.com/mantlenetworkio/mantle/pull/1217), [#1183](https://github.com/mantlenetworkio/mantle/pull/1183)) +- Removed unused struct related to 'mnt-37', added a default message handler for function ProcessOneMessage:cs-6.26 ([#1202](https://github.com/mantlenetworkio/mantle/pull/1202), [#1198](https://github.com/mantlenetworkio/mantle/pull/1198)) + + ## [v0.4.2](https://github.com/mantlenetworkio/mantle/commits/v0.4.2) - 2023-07-10 ### Features diff --git a/batch-submitter/batch_submitter.go b/batch-submitter/batch_submitter.go index 94a18a8fb..8241e5a97 100644 --- a/batch-submitter/batch_submitter.go +++ b/batch-submitter/batch_submitter.go @@ -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" @@ -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 @@ -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 { @@ -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 @@ -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 diff --git a/batch-submitter/config.go b/batch-submitter/config.go index 836067189..64e5cb41e 100644 --- a/batch-submitter/config.go +++ b/batch-submitter/config.go @@ -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 @@ -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. @@ -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 } // NewConfig parses the Config from the provided flags or environment variables. @@ -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), @@ -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) diff --git a/batch-submitter/drivers/proposer/driver.go b/batch-submitter/drivers/proposer/driver.go index 4a58b4cd3..42180b3c6 100644 --- a/batch-submitter/drivers/proposer/driver.go +++ b/batch-submitter/drivers/proposer/driver.go @@ -13,7 +13,6 @@ 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" @@ -21,7 +20,6 @@ import ( "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" @@ -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. @@ -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 { @@ -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 } @@ -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 diff --git a/batch-submitter/drivers/sequencer/driver.go b/batch-submitter/drivers/sequencer/driver.go index 9d71f5a36..a1697bce5 100644 --- a/batch-submitter/drivers/sequencer/driver.go +++ b/batch-submitter/drivers/sequencer/driver.go @@ -4,11 +4,9 @@ import ( "context" "crypto/ecdsa" "encoding/hex" - "fmt" "math/big" "strings" - kms "cloud.google.com/go/kms/apiv1" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -17,7 +15,6 @@ import ( "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/da" @@ -26,6 +23,9 @@ import ( "github.com/mantlenetworkio/mantle/bss-core/metrics" "github.com/mantlenetworkio/mantle/bss-core/txmgr" l2ethclient "github.com/mantlenetworkio/mantle/l2geth/ethclient" + + kms "cloud.google.com/go/kms/apiv1" + "google.golang.org/api/option" ) const ( @@ -35,23 +35,22 @@ const ( var bigOne = new(big.Int).SetUint64(1) type Config struct { - Name string - L1Client *ethclient.Client - L2Client *l2ethclient.Client - BlockOffset uint64 - MinTxSize uint64 - MaxTxSize uint64 - MaxPlaintextBatchSize uint64 - CTCAddr common.Address - DaUpgradeBlock uint64 - DAAddr common.Address - ChainID *big.Int - PrivKey *ecdsa.PrivateKey - EnableSequencerHsm bool - SequencerHsmAddress string - SequencerHsmAPIName string - SequencerHsmCreden string - BatchType BatchType + Name string + L1Client *ethclient.Client + L2Client *l2ethclient.Client + BlockOffset uint64 + CTCAddr common.Address + DaUpgradeBlock uint64 + DAAddr common.Address + ChainID *big.Int + PrivKey *ecdsa.PrivateKey + EnableSequencerHsm bool + SequencerHsmAddress string + SequencerHsmAPIName string + SequencerHsmCreden string + BatchType BatchType + MaxRollupTxn uint64 + MinRollupTxn uint64 } type Driver struct { @@ -206,9 +205,12 @@ func (d *Driver) GetBatchBlockRange( return nil, nil, err } } - if start.Cmp(end) > 0 { - return nil, nil, fmt.Errorf("invalid range, "+ - "end(%v) < start(%v)", end, start) + l2Txn := big.NewInt(0).Sub(end, start) + if l2Txn.Cmp(big.NewInt(int64(d.cfg.MinRollupTxn))) < 0 { + return start, start, nil + } + if l2Txn.Cmp(big.NewInt(int64(d.cfg.MaxRollupTxn))) > 0 { + end = big.NewInt(0).Add(start, big.NewInt(int64(d.cfg.MaxRollupTxn))) } return start, end, nil } @@ -229,11 +231,8 @@ func (d *Driver) CraftBatchTx( log.Info(name+" crafting batch tx", "start", start, "end", end, "nonce", nonce, "type", d.cfg.BatchType.String()) - var ( - batchElements []BatchElement - totalTxSize uint64 - hasLargeNextTx bool - ) + var batchElements []BatchElement + for i := new(big.Int).Set(start); i.Cmp(end) < 0; i.Add(i, bigOne) { block, err := d.cfg.L2Client.BlockByNumber(ctx, i) if err != nil { @@ -243,30 +242,10 @@ func (d *Driver) CraftBatchTx( // For each sequencer transaction, update our running total with the // size of the transaction. batchElement := BatchElementFromBlock(block) - if batchElement.IsSequencerTx() { - // Abort once the total size estimate is greater than the maximum - // configured size. This is a conservative estimate, as the total - // calldata size will be greater when batch contexts are included. - // Below this set will be further whittled until the raw call data - // size also adheres to this constraint. - txLen := batchElement.Tx.Size() - if totalTxSize+uint64(TxLenSize+txLen) > d.cfg.MaxPlaintextBatchSize { - // Adding this transaction causes the batch to be too large, but - // we also record if the batch size without the transaction - // fails to meet our minimum size constraint. This is used below - // to determine whether or not to ignore the minimum size check, - // since in this case it can't be avoided. - hasLargeNextTx = totalTxSize < d.cfg.MinTxSize - break - } - totalTxSize += uint64(TxLenSize + txLen) - } - batchElements = append(batchElements, batchElement) } shouldStartAt := start.Uint64() - var pruneCount int for { batchParams, err := GenSequencerBatchParams( shouldStartAt, d.cfg.BlockOffset, batchElements, @@ -285,51 +264,9 @@ func (d *Driver) CraftBatchTx( calldata := append(appendSequencerBatchID, batchArguments...) log.Info(name+" testing batch size", - "calldata_size", len(calldata), - "min_tx_size", d.cfg.MinTxSize, - "max_tx_size", d.cfg.MaxTxSize) - - // Continue pruning until plaintext calldata size is less than - // configured max. - calldataSize := uint64(len(calldata)) - if calldataSize > d.cfg.MaxTxSize { - oldLen := len(batchElements) - newBatchElementsLen := (oldLen * 9) / 10 - batchElements = batchElements[:newBatchElementsLen] - log.Info(name+" pruned batch", - "old_num_txs", oldLen, - "new_num_txs", newBatchElementsLen) - pruneCount++ - continue - } - - // There are two specific cases in which we choose to ignore the minimum - // L1 tx size. These cases are permitted since they arise from - // situations where the difference between the configured MinTxSize and - // MaxTxSize is less than the maximum L2 tx size permitted by the - // mempool. - // - // This configuration is useful when trying to ensure the profitability - // is sufficient, and we permit batches to be submitted with less than - // our desired configuration only if it is not possible to construct a - // batch within the given parameters. - // - // The two cases are: - // 1. When the next elenent is larger than the difference between the - // min and the max, causing the batch to be too small without the - // element, and too large with it. - // 2. When pruning a batch that exceeds the mac size below, and then - // becomes too small as a result. This is avoided by only applying - // the min size check when the pruneCount is zero. - ignoreMinTxSize := pruneCount > 0 || hasLargeNextTx - if !ignoreMinTxSize && calldataSize < d.cfg.MinTxSize { - log.Info(name+" batch tx size below minimum", - "num_txs", len(batchElements)) - return nil, nil - } + "calldata_size", len(calldata)) d.metrics.NumElementsPerBatch().Observe(float64(len(batchElements))) - d.metrics.BatchPruneCount.Set(float64(pruneCount)) log.Info(name+" batch constructed", "num_txs", len(batchElements), diff --git a/batch-submitter/drivers/sequencer/encoding.go b/batch-submitter/drivers/sequencer/encoding.go index a2544f5c3..af994e9b8 100644 --- a/batch-submitter/drivers/sequencer/encoding.go +++ b/batch-submitter/drivers/sequencer/encoding.go @@ -188,7 +188,7 @@ type AppendSequencerBatchParams struct { Txs []*CachedTx } -// Write encodes the AppendSequencerBatchParams using the following format: +// WriteNoTxn encodes the AppendSequencerBatchParams using the following format: // - should_start_at_element: 5 bytes // - total_elements_to_append: 3 bytes // - num_contexts: 3 bytes @@ -210,68 +210,6 @@ type AppendSequencerBatchParams struct { // // Note that writing to a bytes.Buffer cannot // error, so errors are ignored here -func (p *AppendSequencerBatchParams) Write( - w *bytes.Buffer, - batchType BatchType, -) error { - - _ = writeUint64(w, p.ShouldStartAtElement, 5) - _ = writeUint64(w, p.TotalElementsToAppend, 3) - - // There must be contexts if there are transactions - if len(p.Contexts) == 0 && len(p.Txs) != 0 { - return ErrMalformedBatch - } - - // There must be transactions if there are contexts - if len(p.Txs) == 0 && len(p.Contexts) != 0 { - return ErrMalformedBatch - } - - // copy the contexts as to not malleate the struct - // when it is a typed batch - contexts := make([]BatchContext, 0, len(p.Contexts)+1) - // Add the marker context, if any, for non-legacy encodings. - markerContext := batchType.MarkerContext() - if markerContext != nil { - contexts = append(contexts, *markerContext) - } - contexts = append(contexts, p.Contexts...) - - // Write number of contexts followed by each fixed-size BatchContext. - _ = writeUint64(w, uint64(len(contexts)), 3) - for _, context := range contexts { - context.Write(w) - } - - switch batchType { - case BatchTypeLegacy: - // Write each length-prefixed tx. - for _, tx := range p.Txs { - _ = writeUint64(w, uint64(tx.Size()), TxLenSize) - _, _ = w.Write(tx.RawTx()) // can't fail for bytes.Buffer - } - case BatchTypeZlib: - zw := zlib.NewWriter(w) - for _, tx := range p.Txs { - if err := writeUint64(zw, uint64(tx.Size()), TxLenSize); err != nil { - return err - } - if _, err := zw.Write(tx.RawTx()); err != nil { - return err - } - } - if err := zw.Close(); err != nil { - return err - } - - default: - return fmt.Errorf("Unknown batch type: %s", batchType) - } - - return nil -} - func (p *AppendSequencerBatchParams) WriteNoTxn( w *bytes.Buffer, batchType BatchType, @@ -279,16 +217,6 @@ func (p *AppendSequencerBatchParams) WriteNoTxn( _ = writeUint64(w, p.ShouldStartAtElement, 5) _ = writeUint64(w, p.TotalElementsToAppend, 3) - // There must be contexts if there are transactions - if len(p.Contexts) == 0 && len(p.Txs) != 0 { - return ErrMalformedBatch - } - - // There must be transactions if there are contexts - if len(p.Txs) == 0 && len(p.Contexts) != 0 { - return ErrMalformedBatch - } - // copy the contexts as to not malleate the struct // when it is a typed batch contexts := make([]BatchContext, 0, len(p.Contexts)+1) @@ -315,14 +243,8 @@ func (p *AppendSequencerBatchParams) Serialize( upgradeBlock *big.Int, ) ([]byte, error) { var buf bytes.Buffer - if l2BlockNumber.Cmp(upgradeBlock) > 0 { - if err := p.WriteNoTxn(&buf, batchType); err != nil { - return nil, err - } - } else { - if err := p.Write(&buf, batchType); err != nil { - return nil, err - } + if err := p.WriteNoTxn(&buf, batchType); err != nil { + return nil, err } return buf.Bytes(), nil } diff --git a/batch-submitter/flags/flags.go b/batch-submitter/flags/flags.go index 48ddd5ada..27a94d120 100644 --- a/batch-submitter/flags/flags.go +++ b/batch-submitter/flags/flags.go @@ -82,27 +82,6 @@ var ( Required: true, EnvVar: "FP_ROLLUP_ADDRESS", } - MinL1TxSizeFlag = cli.Uint64Flag{ - Name: "min-l1-tx-size", - Usage: "Minimum size in bytes of any L1 transaction that gets " + - "generated by the batch submitter", - Required: true, - EnvVar: prefixEnvVar("MIN_L1_TX_SIZE"), - } - MaxL1TxSizeFlag = cli.Uint64Flag{ - Name: "max-l1-tx-size", - Usage: "Maximum size in bytes of any L1 transaction that gets " + - "generated by the batch submitter", - Required: true, - EnvVar: prefixEnvVar("MAX_L1_TX_SIZE"), - } - MaxPlaintextBatchSizeFlag = cli.Uint64Flag{ - Name: "max-plaintext-batch-size", - Usage: "Maximum size in bytes of of the plaintext tx data " + - "encoded in batches", - Required: true, - EnvVar: prefixEnvVar("MAX_PLAINTEXT_BATCH_SIZE"), - } MinStateRootElementsFlag = cli.Uint64Flag{ Name: "min-state-root-elements", Usage: "Minimum number of elements required to submit a state " + @@ -117,12 +96,11 @@ var ( Required: true, EnvVar: prefixEnvVar("MAX_STATE_ROOT_ELEMENTS"), } - MaxBatchSubmissionTimeFlag = cli.DurationFlag{ - Name: "max-batch-submission-time", - Usage: "Maximum amount of time that we will wait before " + - "submitting an under-sized batch", + RollupTimeoutFlag = cli.DurationFlag{ + Name: "rollup-timeout", + Usage: "Delay between rollup timeout transactions ", Required: true, - EnvVar: prefixEnvVar("MAX_BATCH_SUBMISSION_TIME"), + EnvVar: prefixEnvVar("ROLLUP_TIMEOUT"), } PollIntervalFlag = cli.DurationFlag{ Name: "poll-interval", @@ -343,6 +321,28 @@ var ( Required: false, EnvVar: "ROLLUP_ALLOW_L2_AUTO_ROLLBACK", } + + MinRollupTxnFlag = cli.Uint64Flag{ + Name: "min-rollup-txn", + Usage: "Minimum number of transaction from l2geth which is used to submit to rollup", + Required: true, + EnvVar: prefixEnvVar("MIN_ROLLUP_TXN"), + } + + MaxRollupTxnFlag = cli.Uint64Flag{ + Name: "max-rollup-txn", + Usage: "Maximum number of transaction from l2geth which is used to submit to rollup", + Required: true, + EnvVar: prefixEnvVar("MAX_ROLLUP_TXN"), + } + + MinTimeoutStateRootElementsFlag = cli.Uint64Flag{ + Name: "min-timeout-state-root-elements", + Usage: "Minimum number of elements required to submit a state " + + "root batch", + Required: true, + EnvVar: prefixEnvVar("MIN_TIMEOUT_STATE_ROOT_ELEMENTS"), + } ) var requiredFlags = []cli.Flag{ @@ -357,12 +357,9 @@ var requiredFlags = []cli.Flag{ CTCAddressFlag, SCCAddressFlag, FPRollupAddressFlag, - MinL1TxSizeFlag, - MaxL1TxSizeFlag, - MaxPlaintextBatchSizeFlag, MinStateRootElementsFlag, MaxStateRootElementsFlag, - MaxBatchSubmissionTimeFlag, + RollupTimeoutFlag, PollIntervalFlag, NumConfirmationsFlag, SafeAbortNonceTooLowCountFlag, @@ -372,6 +369,9 @@ var requiredFlags = []cli.Flag{ RunStateBatchSubmitterFlag, SafeMinimumEtherBalanceFlag, ClearPendingTxsFlag, + MaxRollupTxnFlag, + MinRollupTxnFlag, + MinTimeoutStateRootElementsFlag, } var optionalFlags = []cli.Flag{ diff --git a/datalayr b/datalayr index 4832e36a4..fd219c089 160000 --- a/datalayr +++ b/datalayr @@ -1 +1 @@ -Subproject commit 4832e36a46199dad5d88bf5eacdfc323f4395ed0 +Subproject commit fd219c0894b90c600328805c744aa81dba6fca68 diff --git a/gas-oracle/Dockerfile b/gas-oracle/Dockerfile index 7476def86..08f498689 100644 --- a/gas-oracle/Dockerfile +++ b/gas-oracle/Dockerfile @@ -4,6 +4,10 @@ RUN apk add --no-cache make gcc musl-dev linux-headers git jq bash COPY ./gas-oracle /gas-oracle COPY ./bss-core /bss-core +COPY ./l2geth /l2geth +COPY ./metrics /metrics +COPY ./fraud-proof /fraud-proof + COPY ./gas-oracle/docker.go.work /go/go.work RUN cd /gas-oracle && make gas-oracle diff --git a/gas-oracle/flags/flags.go b/gas-oracle/flags/flags.go index a6bc1ef47..1da7bda01 100644 --- a/gas-oracle/flags/flags.go +++ b/gas-oracle/flags/flags.go @@ -111,6 +111,12 @@ var ( Usage: "Setup StateRollupGasUsed", EnvVar: "GAS_PRICE_ORACLE_STATE_ROLLUP_GAS_USED", } + StateHashGasUsed = cli.IntFlag{ + Name: "set-state-hash-gas-used", + Value: 1412, + Usage: "Setup StateHashGasUsed", + EnvVar: "GAS_PRICE_ORACLE_STATE_HASH_GAS_USED", + } DataRollupGasUsed = cli.IntFlag{ Name: "set-data-rollup-gas-used", Value: 137893, @@ -323,6 +329,7 @@ var Flags = []cli.Flag{ BatchSizeCap, SizeGap, StateRollupGasUsed, + StateHashGasUsed, DataRollupGasUsed, EnableHsmFlag, HsmAddressFlag, diff --git a/gas-oracle/go.mod b/gas-oracle/go.mod index f0d7ea30f..586596402 100644 --- a/gas-oracle/go.mod +++ b/gas-oracle/go.mod @@ -3,12 +3,14 @@ module github.com/mantlenetworkio/mantle/gas-oracle go 1.18 replace github.com/mantlenetworkio/mantle/bss-core => ../bss-core +replace github.com/mantlenetworkio/mantle/l2geth => ../l2geth require ( cloud.google.com/go/kms v1.11.0 github.com/ethereum/go-ethereum v1.10.26 github.com/go-resty/resty/v2 v2.7.0 github.com/mantlenetworkio/mantle/bss-core v0.0.0 + github.com/mantlenetworkio/mantle/l2geth v0.0.0 github.com/stretchr/testify v1.8.4 github.com/urfave/cli v1.22.14 google.golang.org/api v0.126.0 @@ -19,7 +21,9 @@ require ( cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/iam v1.0.1 // indirect github.com/VictoriaMetrics/fastcache v1.9.0 // indirect + github.com/aristanetworks/goarista v0.0.0-20170210015632-ea17b1a17847 // indirect github.com/beorn7/perks v1.0.1 // indirect + github.com/btcsuite/btcd v0.22.1 // indirect github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect @@ -32,6 +36,7 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect github.com/decred/dcrd/hdkeychain/v3 v3.0.0 // indirect github.com/deepmap/oapi-codegen v1.8.2 // indirect + github.com/elastic/gosigar v0.14.2 // indirect github.com/getsentry/sentry-go v0.12.0 // indirect github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-stack/stack v1.8.1 // indirect @@ -66,6 +71,8 @@ require ( github.com/rjeczalik/notify v0.9.2 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/shirou/gopsutil v3.21.11+incompatible // indirect + github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570 // indirect + github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 // indirect github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect github.com/tklauser/go-sysconf v0.3.10 // indirect github.com/tklauser/numcpus v0.4.0 // indirect diff --git a/gas-oracle/go.sum b/gas-oracle/go.sum index 66bb9c0b3..8a17ca8d8 100644 --- a/gas-oracle/go.sum +++ b/gas-oracle/go.sum @@ -50,6 +50,8 @@ github.com/allegro/bigcache v1.2.1 h1:hg1sY1raCwic3Vnsvje6TT7/pnZba83LeFck5NrFKS github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/apache/arrow/go/arrow v0.0.0-20191024131854-af6fa24be0db/go.mod h1:VTxUBvSJ3s3eHAg65PNgrsn5BtqCRPdmyXh6rAfdxN0= +github.com/aristanetworks/goarista v0.0.0-20170210015632-ea17b1a17847 h1:rtI0fD4oG/8eVokGVPYJEW1F88p1ZNgXiEIs9thEE4A= +github.com/aristanetworks/goarista v0.0.0-20170210015632-ea17b1a17847/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= @@ -58,6 +60,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= +github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c= +github.com/btcsuite/btcd v0.22.1/go.mod h1:wqgTSL29+50LRkmOVknEdmt8ZojIzhuWvgu/iptuN7Y= github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k= github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= @@ -129,6 +133,8 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn github.com/eclipse/paho.mqtt.golang v1.2.0/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts= github.com/edsrzf/mmap-go v1.1.0 h1:6EUwBLQ/Mcr1EYLE4Tn1VdW1A4ckqCQWZBw8Hr0kjpQ= github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM= +github.com/elastic/gosigar v0.14.2 h1:Dg80n8cr90OZ7x+bAax/QjoW/XqTI11RmA79ZwIm9/4= +github.com/elastic/gosigar v0.14.2/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -456,6 +462,10 @@ github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb6 github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= +github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570 h1:gIlAHnH1vJb5vwEjIp5kBj/eu99p/bl0Ay2goiPe5xE= +github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8OR4w3TdeIHIh1g6EMY5p0gVNOovcWC+1vpc7naMuAw= +github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 h1:njlZPzLwU639dk2kqnCPPv+wNjq7Xb6EfUxe/oX0/NM= +github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= @@ -605,6 +615,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= +golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/gas-oracle/metrics/metrics.go b/gas-oracle/metrics/metrics.go index d64225db5..a1662268b 100644 --- a/gas-oracle/metrics/metrics.go +++ b/gas-oracle/metrics/metrics.go @@ -24,6 +24,8 @@ var ( DaFeeGauge metrics.Gauge // OverHeadGauge over_head, amortized cost of batch submission per transaction OverHeadGauge metrics.Gauge + // OverHeadGauge over_head, amortized cost of batch submission per transaction + OverHeadUpdateGauge metrics.Gauge // L1GasPriceGauge l1_base_fee + l1_priority_fee L1GasPriceGauge metrics.Gauge @@ -49,6 +51,7 @@ func InitAndRegisterStats(r metrics.Registry) { GasOracleStats.FeeScalarGauge = metrics.NewRegisteredGauge("fee_scalar", r) GasOracleStats.DaFeeGauge = metrics.NewRegisteredGauge("da_fee", r) GasOracleStats.OverHeadGauge = metrics.NewRegisteredGauge("over_head", r) + GasOracleStats.OverHeadUpdateGauge = metrics.NewRegisteredGauge("over_head_update", r) GasOracleStats.L1GasPriceGauge = metrics.NewRegisteredGauge("l1_gas_price", r) // stats for gas oracle version diff --git a/gas-oracle/oracle/base_fee.go b/gas-oracle/oracle/base_fee.go index db51a9d57..2b34be408 100644 --- a/gas-oracle/oracle/base_fee.go +++ b/gas-oracle/oracle/base_fee.go @@ -71,6 +71,17 @@ func wrapUpdateBaseFee(l1Backend bind.ContractTransactor, l2Backend DeployContra if err != nil { return nil, err } + + // initialize some metrics + // initialize fee scalar from contract + feeScalar, err := contract.Scalar(&bind.CallOpts{ + Context: context.Background(), + }) + if err != nil { + return nil, err + } + ometrics.GasOracleStats.FeeScalarGauge.Update(feeScalar.Int64()) + return func() error { baseFee, err := contract.L1BaseFee(&bind.CallOpts{ Context: context.Background(), @@ -84,7 +95,7 @@ func wrapUpdateBaseFee(l1Backend bind.ContractTransactor, l2Backend DeployContra if err != nil { return err } - // Update faa scalar metrics + // Update fee scalar metrics ometrics.GasOracleStats.FeeScalarGauge.Update(feeScalar.Int64()) // NOTE this will return base multiple with coin ratio diff --git a/gas-oracle/oracle/config.go b/gas-oracle/oracle/config.go index 009476470..0c1bbcd65 100644 --- a/gas-oracle/oracle/config.go +++ b/gas-oracle/oracle/config.go @@ -56,6 +56,7 @@ type Config struct { batchSizeCap int sizeGap int stateRollupGasUsed *big.Int + stateHashGasUsed *big.Int dataRollupGasUsed *big.Int // Metrics config MetricsEnabled bool @@ -108,6 +109,7 @@ func NewConfig(ctx *cli.Context) *Config { cfg.batchSizeBottom = ctx.GlobalInt(flags.BatchSizeBottom.Name) cfg.sizeGap = ctx.GlobalInt(flags.SizeGap.Name) cfg.stateRollupGasUsed = big.NewInt(ctx.GlobalInt64(flags.StateRollupGasUsed.Name)) + cfg.stateHashGasUsed = big.NewInt(ctx.GlobalInt64(flags.StateHashGasUsed.Name)) cfg.dataRollupGasUsed = big.NewInt(ctx.GlobalInt64(flags.DataRollupGasUsed.Name)) if cfg.EnableHsm { diff --git a/gas-oracle/oracle/gas_price_oracle.go b/gas-oracle/oracle/gas_price_oracle.go index 7ef20b5e2..c8c055bfd 100644 --- a/gas-oracle/oracle/gas_price_oracle.go +++ b/gas-oracle/oracle/gas_price_oracle.go @@ -2,6 +2,7 @@ package oracle import ( "context" + "encoding/binary" "errors" "fmt" "math/big" @@ -17,8 +18,12 @@ import ( "github.com/mantlenetworkio/mantle/gas-oracle/gasprices" ometrics "github.com/mantlenetworkio/mantle/gas-oracle/metrics" "github.com/mantlenetworkio/mantle/gas-oracle/tokenprice" + "github.com/mantlenetworkio/mantle/l2geth/core/rawdb" + "github.com/mantlenetworkio/mantle/l2geth/ethdb" ) +const GAS_ORACLE_SYNC_HEIGHT = "GAS_ORACLE_SYNC_HEIGHT" + var ( // errInvalidSigningKey represents the error when the signing key used // is not the Owner of the contract and therefore cannot update the gasprice @@ -194,12 +199,16 @@ func (g *GasPriceOracle) DaFeeLoop() { } func (g *GasPriceOracle) OverHeadLoop() { - stateBatchAppendChan := make(chan *bindings.StateCommitmentChainStateBatchAppended, 10) - stateAppendSub, err := g.sccBackend.WatchStateBatchAppended(&bind.WatchOpts{Context: g.ctx}, stateBatchAppendChan, nil) - if err != nil { - panic(err) - } - defer stateAppendSub.Unsubscribe() + // set ticker + ticker := time.NewTicker(5 * time.Second) + + // read gas-oracle synced height + db, height := readGasOracleSyncHeight() + log.Info("ReadGasOracleSyncHeight", "height", height) + // set channel + stateBatchAppendChan := make(chan *bindings.StateCommitmentChainStateBatchAppended, 1) + + // set context ctcTotalBatches, err := g.ctcBackend.GetTotalBatches(&bind.CallOpts{}) if err != nil { panic(err) @@ -209,8 +218,44 @@ func (g *GasPriceOracle) OverHeadLoop() { panic(err) } + var end uint64 for { select { + case <-ticker.C: + log.Info("OverHeadLoop is living, HeartBeat It!") + latestHeader, err := g.l1Backend.HeaderByNumber(g.ctx, nil) + if err != nil { + log.Warn("get latest header in error", "error", err) + continue + } + // repeat query latest block is not allowed + if height != nil && height.Uint64() != 0 && height.Uint64() >= latestHeader.Number.Uint64() { + continue + } + if height == nil || height.Uint64() == 0 { + height = latestHeader.Number + } + end = latestHeader.Number.Uint64() + + iter, err := g.sccBackend.FilterStateBatchAppended(&bind.FilterOpts{ + Start: height.Uint64(), + End: &end, + Context: g.ctx, + }, nil) + for iter.Next() { + select { + case stateBatchAppendChan <- iter.Event: + log.Info("write event into channel", "channel length is", len(stateBatchAppendChan)) + default: + // discard additional event to process the last one + <-stateBatchAppendChan + stateBatchAppendChan <- iter.Event + log.Warn("write additional event into channel, will ignore prev events") + } + } + _ = writeGasOracleSyncHeight(db, latestHeader.Number) + height = latestHeader.Number.Add(latestHeader.Number, big.NewInt(1)) + log.Info("Update synced height", "height", height) case ev := <-stateBatchAppendChan: currentCtcBatches, err := g.ctcBackend.GetTotalBatches(&bind.CallOpts{}) if err != nil { @@ -219,10 +264,11 @@ func (g *GasPriceOracle) OverHeadLoop() { log.Info("current scc batch size", "size", ev.BatchSize) log.Info("CTC circle num in SCC circle", "count", new(big.Int).Sub(currentCtcBatches, ctcTotalBatches)) if err := updateOverhead(new(big.Int).Sub(currentCtcBatches, ctcTotalBatches), ev.BatchSize); err != nil { - log.Error("cannot update da fee", "messgae", err) + log.Error("cannot update overhead", "message", err) } ctcTotalBatches = currentCtcBatches case <-g.ctx.Done(): + db.Close() g.Stop() } } @@ -266,7 +312,7 @@ func NewGasPriceOracle(cfg *Config) (*GasPriceOracle, error) { return nil, err } - l1Client, err := NewL1Client(cfg.ethereumWssUrl, tokenPricer) + l1Client, err := NewL1Client(cfg.ethereumHttpUrl, tokenPricer) if err != nil { return nil, err } @@ -435,3 +481,44 @@ func ensureConnection(client *ethclient.Client) error { } return nil } + +func readGasOracleSyncHeight() (ethdb.Database, *big.Int) { + // read synced height + db, err := rawdb.NewLevelDBDatabase("gas-oracle-data", 0, 0, "") + if err != nil { + log.Error("NewLevelDBDatabase in error", "err", err) + panic(err) + } + // will close connection at once + //defer db.Close() + + has, err := db.Has([]byte(GAS_ORACLE_SYNC_HEIGHT)) + if err != nil { + log.Error("check db has GAS_ORACLE_SYNC_HEIGHT in error", "err", err) + panic(err) + } + if !has { + return db, nil + } + + height, err := db.Get([]byte(GAS_ORACLE_SYNC_HEIGHT)) + if err != nil { + log.Error("check db Get GAS_ORACLE_SYNC_HEIGHT in error", "err", err) + panic(err) + } + return db, big.NewInt(0).SetUint64(binary.BigEndian.Uint64(height)) +} + +func writeGasOracleSyncHeight(db ethdb.Database, height *big.Int) error { + // will close connection at once + //defer db.Close() + + var indexBz = make([]byte, 8) + binary.BigEndian.PutUint64(indexBz, height.Uint64()) + err := db.Put([]byte(GAS_ORACLE_SYNC_HEIGHT), indexBz) + if err != nil { + log.Error("put GAS_ORACLE_SYNC_HEIGHT in error", "err", err) + return err + } + return nil +} diff --git a/gas-oracle/oracle/overhead.go b/gas-oracle/oracle/overhead.go index 1ba2753ed..a47ef3aca 100644 --- a/gas-oracle/oracle/overhead.go +++ b/gas-oracle/oracle/overhead.go @@ -88,7 +88,12 @@ func wrapUpdateOverhead(l2Backend DeployContractBackend, cfg *Config) (func(*big if err != nil { return err } - + ometrics.GasOracleStats.OverHeadUpdateGauge.Inc(1) + // skip update if overhead is not changed + if overhead.Cmp(newOverheadLevel) == 0 { + log.Info("skip update overhead", "overhead", overhead) + return nil + } // Use the configured gas price if it is set, // otherwise use gas estimation if cfg.gasPrice != nil { @@ -135,7 +140,7 @@ func calculateJumpTable(diff *big.Int, cfg *Config) { // calculate jump table for levelSize := cfg.batchSizeBottom; levelSize <= cfg.batchSizeCap; { orderedSizes = append(orderedSizes, levelSize) - jumpTable[levelSize] = new(big.Int).Add(new(big.Int).Div(OverheadGasUsedOnL1, new(big.Int).SetUint64(uint64(levelSize))), new(big.Int).SetUint64(1330)) + jumpTable[levelSize] = new(big.Int).Add(new(big.Int).Div(OverheadGasUsedOnL1, new(big.Int).SetUint64(uint64(levelSize))), cfg.stateHashGasUsed) levelSize += cfg.sizeGap } } diff --git a/l2geth/Makefile b/l2geth/Makefile index 67095f4d0..0fbdb3368 100644 --- a/l2geth/Makefile +++ b/l2geth/Makefile @@ -12,13 +12,20 @@ GOBIN = ./build/bin GO ?= latest GORUN = env GO111MODULE=on go run +# workaround for datalayr, remove in the future geth: + @echo "exclude github.com/Layr-Labs/datalayr/common v0.0.0" >> go.mod + @echo "exclude github.com/Layr-Labs/datalayr/lib/merkzg v0.0.0" >> go.mod $(GORUN) build/ci.go install ./cmd/geth @echo "Done building." @echo "Run \"$(GOBIN)/geth\" to launch geth." + @sed -i.a '/^exclude.*datalayr/d' go.mod && rm -f go.mod.a all: + @echo "exclude github.com/Layr-Labs/datalayr/common v0.0.0" >> go.mod + @echo "exclude github.com/Layr-Labs/datalayr/lib/merkzg v0.0.0" >> go.mod $(GORUN) build/ci.go install + @sed -i.a '/^exclude.*datalayr/d' go.mod && rm -f go.mod.a android: $(GORUN) build/ci.go aar --local diff --git a/mt-batcher/config.go b/mt-batcher/config.go index 72c37dea9..ceec8000b 100644 --- a/mt-batcher/config.go +++ b/mt-batcher/config.go @@ -67,6 +67,8 @@ type Config struct { HsmAddress string HsmFeeAPIName string HsmFeeAddress string + MinTimeoutRollupTxn uint64 + RollupTimeout time.Duration } func NewConfig(ctx *cli.Context) (Config, error) { @@ -128,6 +130,8 @@ func NewConfig(ctx *cli.Context) (Config, error) { HsmCreden: ctx.GlobalString(flags.HsmCredenFlag.Name), HsmFeeAPIName: ctx.GlobalString(flags.HsmFeeAPINameFlag.Name), HsmFeeAddress: ctx.GlobalString(flags.HsmFeeAddressFlag.Name), + MinTimeoutRollupTxn: ctx.GlobalUint64(flags.MinTimeoutRollupTxnFlag.Name), + RollupTimeout: ctx.GlobalDuration(flags.RollupTimeoutFlag.Name), } return cfg, nil } diff --git a/mt-batcher/flags/flags.go b/mt-batcher/flags/flags.go index ba62a4e51..f367bbe91 100644 --- a/mt-batcher/flags/flags.go +++ b/mt-batcher/flags/flags.go @@ -340,6 +340,20 @@ var ( Usage: "the creden of hsm key for mt-batcher", EnvVar: prefixEnvVar(envVarPrefix, "HSM_CREDEN"), } + + MinTimeoutRollupTxnFlag = cli.Uint64Flag{ + Name: "min-timeout-rollup-txn", + Usage: "minimum of timeout Rollup transaction amount for mantle da", + Required: true, + EnvVar: prefixEnvVar(envVarPrefix, "MIN_TIMEOUT_ROLLUP_TXN"), + } + + RollupTimeoutFlag = cli.DurationFlag{ + Name: "rollup-timeout", + Usage: "Duration we will wait before rollup batch transaction to Mantle Da", + Required: true, + EnvVar: prefixEnvVar(envVarPrefix, "ROLLUP_TIMEOUT"), + } ) var requiredFlags = []cli.Flag{ @@ -363,6 +377,8 @@ var requiredFlags = []cli.Flag{ EigenContractAddressFlag, EigenFeeContractAddressFlag, BlockOffsetFlag, + MinTimeoutRollupTxnFlag, + RollupTimeoutFlag, RollUpMinTxnFlag, RollUpMaxSizeFlag, FeeSizeSecFlag, diff --git a/mt-batcher/l1l2client/l1client.go b/mt-batcher/l1l2client/l1client.go index 9fd3c62a5..4d3f334c9 100644 --- a/mt-batcher/l1l2client/l1client.go +++ b/mt-batcher/l1l2client/l1client.go @@ -18,7 +18,7 @@ func L1EthClientWithTimeout(ctx context.Context, url string, disableHTTP2 bool) if strings.HasPrefix(url, "http") { httpClient := new(http.Client) if disableHTTP2 { - log.Info("Disabled HTTP/2 support in L1 eth client") + log.Debug("Disabled HTTP/2 support in L1 eth client") httpClient.Transport = &http.Transport{ TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper), } diff --git a/mt-batcher/l1l2client/l2client.go b/mt-batcher/l1l2client/l2client.go index 3bcc3cc0a..e2ed3850d 100644 --- a/mt-batcher/l1l2client/l2client.go +++ b/mt-batcher/l1l2client/l2client.go @@ -23,7 +23,7 @@ func DialL2EthClientWithTimeout(ctx context.Context, url string, disableHTTP2 bo if strings.HasPrefix(url, "http") { httpClient := new(http.Client) if disableHTTP2 { - log.Info("Disabled HTTP/2 support in L2 eth client") + log.Debug("Disabled HTTP/2 support in L2 eth client") httpClient.Transport = &http.Transport{ TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper), } diff --git a/mt-batcher/mt_batcher.go b/mt-batcher/mt_batcher.go index f70928549..306227bdc 100644 --- a/mt-batcher/mt_batcher.go +++ b/mt-batcher/mt_batcher.go @@ -2,22 +2,24 @@ package mt_batcher import ( "context" + "errors" "strings" - "github.com/Layr-Labs/datalayr/common/logging" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi/bind" ethc "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" - "github.com/mantlenetworkio/mantle/l2geth/common" - "github.com/urfave/cli" + "github.com/mantlenetworkio/mantle/l2geth/common" "github.com/mantlenetworkio/mantle/mt-batcher/bindings" "github.com/mantlenetworkio/mantle/mt-batcher/l1l2client" "github.com/mantlenetworkio/mantle/mt-batcher/metrics" common2 "github.com/mantlenetworkio/mantle/mt-batcher/services/common" "github.com/mantlenetworkio/mantle/mt-batcher/services/restorer" "github.com/mantlenetworkio/mantle/mt-batcher/services/sequencer" + + "github.com/Layr-Labs/datalayr/common/logging" + "github.com/urfave/cli" ) func Main(gitVersion string) func(ctx *cli.Context) error { @@ -27,8 +29,6 @@ func Main(gitVersion string) func(ctx *cli.Context) error { return err } - log.Info("Init Mantle Batcher success", "CurrentVersion", gitVersion) - mantleBatch, err := NewMantleBatch(cfg) if err != nil { return err @@ -38,7 +38,7 @@ func Main(gitVersion string) func(ctx *cli.Context) error { } defer mantleBatch.Stop() - log.Info("mantle batcher started") + log.Debug("mantle batcher started") <-(chan struct{})(nil) @@ -82,13 +82,11 @@ func NewMantleBatch(cfg Config) (*MantleBatch, error) { if err != nil { return nil, err } - log.Info("l1Client init success", "chainID", chainID) l2Client, err := l1l2client.DialL2EthClientWithTimeout(ctx, cfg.L2MtlRpc, cfg.DisableHTTP2) if err != nil { return nil, err } - log.Info("l2Client init success") eigenContract, err := bindings.NewBVMEigenDataLayrChain( ethc.Address(common.HexToAddress(cfg.EigenContractAddress)), l1Client, @@ -113,7 +111,7 @@ func NewMantleBatch(cfg Config) (*MantleBatch, error) { ethc.Address(common.HexToAddress(cfg.EigenContractAddress)), parsed, l1Client, l1Client, l1Client, ) - log.Info("contract init success", "EigenContractAddress", cfg.EigenContractAddress) + log.Debug("contract init success", "EigenContractAddress", cfg.EigenContractAddress) eigenFeeContract, err := bindings.NewBVMEigenDataLayrFee( ethc.Address(common.HexToAddress(cfg.EigenFeeContractAddress)), @@ -176,8 +174,14 @@ func NewMantleBatch(cfg Config) (*MantleBatch, error) { HsmCreden: cfg.HsmCreden, HsmFeeAPIName: cfg.HsmFeeAPIName, HsmFeeAddress: cfg.HsmFeeAddress, + MinTimeoutRollupTxn: cfg.MinTimeoutRollupTxn, + RollupTimeout: cfg.RollupTimeout, + } + if cfg.MinTimeoutRollupTxn >= cfg.RollUpMinTxn { + log.Error("new driver fail", "err", "config value error : MinTimeoutRollupTxn should less than RollUpMinTxn MinTimeoutRollupTxn(%v)>RollUpMinTxn(%v)", cfg.MinTimeoutRollupTxn, cfg.RollUpMinTxn) + return nil, errors.New("config value error : MinTimeoutRollupTxn should less than RollUpMinTxn") } - log.Info("hsm", + log.Debug("hsm", "enablehsm", driverConfig.EnableHsm, "hsmaddress", driverConfig.HsmAddress, "hsmapiname", driverConfig.HsmAPIName, "HsmFeeAPIName", driverConfig.HsmFeeAPIName, "HsmFeeAddress", driverConfig.HsmFeeAddress) driver, err := sequencer.NewDriver(ctx, driverConfig) diff --git a/mt-batcher/services/restorer/handle.go b/mt-batcher/services/restorer/handle.go index 09dd69693..7ba13d456 100644 --- a/mt-batcher/services/restorer/handle.go +++ b/mt-batcher/services/restorer/handle.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "encoding/json" - "math/big" "net/http" "strings" @@ -65,7 +64,6 @@ func (s *DaService) GetLatestTransactionBatchIndex(c gecho.Context) error { if err != nil { return c.JSON(http.StatusBadRequest, errors.New("fail to get batch index")) } - log.Info("rollup batch index", "batchIndex", batchIndex.Uint64()) return c.JSON(http.StatusOK, batchIndex.Uint64()) } @@ -84,7 +82,6 @@ func (s *DaService) GetRollupStoreByRollupBatchIndex(c gecho.Context) error { ConfirmAt: rollupStore.ConfirmAt, Status: rollupStore.Status, } - log.Info("datastore response", "rsRep", rsRep) return c.JSON(http.StatusOK, rsRep) } @@ -94,7 +91,6 @@ func (s *DaService) GetBatchTransactionByDataStoreId(c gecho.Context) error { log.Error("invalid request params", "err", err) return c.JSON(http.StatusBadRequest, errors.New("invalid request params")) } - log.Info("GetBatchTransactionByDataStoreId Request para", "StoreNumber", txReq.StoreNumber) conn, err := grpc.Dial(s.Cfg.RetrieverSocket, grpc.WithInsecure()) if err != nil { log.Error("disperser Cannot connect to", "err", err) @@ -125,7 +121,6 @@ func (s *DaService) GetDtlBatchTransactionByDataStoreId(c gecho.Context) error { log.Error("invalid request params", "err", err) return c.JSON(http.StatusBadRequest, errors.New("invalid request params")) } - log.Info("GetBatchTransactionByDataStoreId Request para", "StoreNumber", txReq.StoreNumber) conn, err := grpc.Dial(s.Cfg.RetrieverSocket, grpc.WithInsecure()) if err != nil { log.Error("disperser Cannot connect to", "err", err) @@ -169,7 +164,6 @@ func (s *DaService) GetDtlBatchTransactionByDataStoreId(c gecho.Context) error { if err := l2Tx.DecodeRLP(rlpStream); err != nil { return c.JSON(http.StatusBadRequest, errors.New("Decode RLP fail")) } - log.Info("transaction", "hash", l2Tx.Hash().Hex()) newBlockNumber := new(big.Int).SetBytes(newBatchTxn[i].BlockNumber) var queueOrigin types.QueueOrigin @@ -288,7 +282,6 @@ func (s *DaService) GetTransactionListByStoreNumber(c gecho.Context) error { log.Error("Decode RLP fail") return c.JSON(http.StatusBadRequest, errors.New("Decode RLP fail")) } - log.Info("transaction", "hash", l2Tx.Hash().Hex()) newBlockNumber := new(big.Int).SetBytes(newBatchTxn[i].BlockNumber) txSl := &TransactionListResponse{ BlockNumber: newBlockNumber.String(), diff --git a/mt-batcher/services/sequencer/db/store.go b/mt-batcher/services/sequencer/db/store.go index 3b2b4573b..7912890cf 100644 --- a/mt-batcher/services/sequencer/db/store.go +++ b/mt-batcher/services/sequencer/db/store.go @@ -11,7 +11,7 @@ type Store struct { func NewStore(path string) (*Store, error) { db, err := NewLevelDBStore(path) if err != nil { - log.Info("Could not create leveldb database.") + log.Error("Could not create leveldb database.") return nil, err } return &Store{ diff --git a/mt-batcher/services/sequencer/driver.go b/mt-batcher/services/sequencer/driver.go index b1a05f85a..52b2997fd 100644 --- a/mt-batcher/services/sequencer/driver.go +++ b/mt-batcher/services/sequencer/driver.go @@ -40,6 +40,10 @@ import ( "github.com/mantlenetworkio/mantle/mt-batcher/txmgr" ) +var ( + pollingInterval = 1000 * time.Millisecond +) + type SignerFn func(context.Context, common.Address, *types.Transaction) (*types.Transaction, error) type DriverConfig struct { @@ -76,6 +80,8 @@ type DriverConfig struct { FeeSizeSec string FeePerBytePerTime uint64 FeeModelEnable bool + MinTimeoutRollupTxn uint64 + RollupTimeout time.Duration Metrics metrics.MtBatchMetrics EnableHsm bool @@ -185,10 +191,10 @@ func (d *Driver) UpdateGasPrice(ctx context.Context, tx *types.Transaction, feeM opts.NoSend = true } if feeModelEnable { - log.Info("MtBatcher update eigen da use fee", "FeeModelEnable", d.Cfg.FeeModelEnable) + log.Debug("MtBatcher update eigen da use fee", "FeeModelEnable", d.Cfg.FeeModelEnable) finalTx, err = d.Cfg.RawEigenFeeContract.RawTransact(opts, tx.Data()) } else { - log.Info("MtBatcher rollup data", "FeeModelEnable", d.Cfg.FeeModelEnable) + log.Debug("MtBatcher rollup data", "FeeModelEnable", d.Cfg.FeeModelEnable) finalTx, err = d.Cfg.RawEigenContract.RawTransact(opts, tx.Data()) } switch { @@ -199,10 +205,10 @@ func (d *Driver) UpdateGasPrice(ctx context.Context, tx *types.Transaction, feeM log.Warn("MtBatcher eth_maxPriorityFeePerGas is unsupported by current backend, using fallback gasTipCap") opts.GasTipCap = common4.FallbackGasTipCap if feeModelEnable { - log.Info("update eigen da use fee", "FeeModelEnable", d.Cfg.FeeModelEnable) + log.Debug("update eigen da use fee", "FeeModelEnable", d.Cfg.FeeModelEnable) return d.Cfg.RawEigenFeeContract.RawTransact(opts, tx.Data()) } else { - log.Info("rollup date", "FeeModelEnable", d.Cfg.FeeModelEnable) + log.Debug("rollup date", "FeeModelEnable", d.Cfg.FeeModelEnable) return d.Cfg.RawEigenContract.RawTransact(opts, tx.Data()) } default: @@ -213,7 +219,7 @@ func (d *Driver) UpdateGasPrice(ctx context.Context, tx *types.Transaction, feeM func (d *Driver) GetBatchBlockRange(ctx context.Context) (*big.Int, *big.Int, error) { blockOffset := new(big.Int).SetUint64(d.Cfg.BlockOffset) var end *big.Int - log.Info("MtBatcher GetBatchBlockRange", "blockOffset", blockOffset) + log.Debug("MtBatcher GetBatchBlockRange", "blockOffset", blockOffset) start, err := d.Cfg.EigenDaContract.GetL2ConfirmedBlockNumber(&bind.CallOpts{ Context: context.Background(), }) @@ -248,7 +254,7 @@ func (d *Driver) TxAggregator(ctx context.Context, start, end *big.Int) (transac panic(fmt.Sprintf("MtBatcher attempting to create batch element from block %d, "+ "found %d txs instead of 1", block.Number(), len(txs))) } - log.Info("MtBatcher origin transactions", "TxHash", txs[0].Hash().String(), "l2BlockNumber", block.Number(), "QueueOrigin", txs[0].QueueOrigin(), "Index", *txs[0].GetMeta().Index, "QueueIndex", txs[0].GetMeta().QueueIndex, "i", i) + log.Debug("MtBatcher origin transactions", "TxHash", txs[0].Hash().String(), "l2BlockNumber", block.Number(), "QueueOrigin", txs[0].QueueOrigin(), "Index", *txs[0].GetMeta().Index, "QueueIndex", txs[0].GetMeta().QueueIndex, "i", i) var txBuf bytes.Buffer if err := txs[0].EncodeRLP(&txBuf); err != nil { panic(fmt.Sprintf("MtBatcher Unable to encode tx: %v", err)) @@ -265,7 +271,6 @@ func (d *Driver) TxAggregator(ctx context.Context, start, end *big.Int) (transac } else { l1MessageSender = txs[0].GetMeta().L1MessageSender } - log.Info("MtBatcher l1 tx origin", "address", l1MessageSender) txMeta := &common3.TransactionMeta{ L1BlockNumber: txs[0].GetMeta().L1BlockNumber, L1Timestamp: txs[0].GetMeta().L1Timestamp, @@ -327,12 +332,10 @@ func (d *Driver) StoreData(ctx context.Context, uploadHeader []byte, duration ui log.Error("MtBatcher unable to get current balance", "err", err) return nil, err } - log.Info("MtBatcher WalletAddr Balance", "balance", balance) d.Cfg.Metrics.MtBatchBalanceETH().Set(common4.WeiToEth64(balance)) nonce64, err := d.Cfg.L1Client.NonceAt( d.Ctx, d.WalletAddr, nil, ) - log.Info("mtbatcher-account", "walletaddr", d.WalletAddr, "nonce64", nonce64) if err != nil { return nil, err } @@ -376,7 +379,6 @@ func (d *Driver) ConfirmData(ctx context.Context, callData []byte, searchData rc log.Error("MtBatcher unable to get current balance", "err", err) return nil, err } - log.Info("MtBatcher wallet address balance", "balance", balance) d.Cfg.Metrics.MtBatchBalanceETH().Set(common4.WeiToEth64(balance)) nonce64, err := d.Cfg.L1Client.NonceAt( d.Ctx, d.WalletAddr, nil, @@ -441,11 +443,9 @@ func (d *Driver) DisperseStoreData(data []byte, startl2BlockNumber *big.Int, end } else if tx == nil { return params, nil, errors.New("tx is nil") } - log.Info("MtBatcher store data success", "txHash", tx.Hash().String()) updateGasPrice := func(ctx context.Context) (*types.Transaction, error) { return d.UpdateGasPrice(ctx, tx, false) } - log.Info("MtBatcher updateGasPrice", "gasPrice", updateGasPrice) receipt, err := d.txMgr.Send( d.Ctx, updateGasPrice, d.SendTransaction, ) @@ -475,7 +475,7 @@ func (d *Driver) ConfirmStoredData(txHash []byte, params common2.StoreParams, st log.Error("MtBatcher could not get initDataStore", "ok", ok) return nil, errors.New("MtBatcher could not get initDataStore") } - log.Info("PollingInitDataStore", "MsgHash", event.MsgHash, "StoreNumber", event.StoreNumber) + log.Debug("PollingInitDataStore", "MsgHash", event.MsgHash, "StoreNumber", event.StoreNumber) meta, err := d.callDisperse( params.HeaderHash, event.MsgHash[:], @@ -515,7 +515,6 @@ func (d *Driver) ConfirmStoredData(txHash []byte, params common2.StoreParams, st } updateGasPrice := func(ctx context.Context) (*types.Transaction, error) { - log.Info("MtBatcher ConfirmData update gas price") return d.UpdateGasPrice(ctx, tx, false) } receipt, err := d.txMgr.Send( @@ -544,12 +543,10 @@ func (d *Driver) callEncode(data []byte) (common2.StoreParams, error) { } opt := grpc.MaxCallSendMsgSize(1024 * 1024 * 300) reply, err := c.EncodeStore(ctx, request, opt) - log.Info("MtBatcher get store", "reply", reply) if err != nil { log.Error("MtBatcher get store err", err) return common2.StoreParams{}, err } - log.Info("MtBatcher get store end") g := reply.GetStore() feeBigInt := new(big.Int).SetBytes(g.Fee) params := common2.StoreParams{ @@ -628,7 +625,6 @@ func (d *Driver) UpdateFee(ctx context.Context, l2Block, daFee *big.Int) (*types log.Error("MtBatcher unable to get fee wallet address current balance", "err", err) return nil, err } - log.Info("MtBatcher fee wallet address balance", "balance", balance) d.Cfg.Metrics.MtFeeBalanceETH().Set(common4.WeiToEth64(balance)) nonce64, err := d.Cfg.L1Client.NonceAt( d.Ctx, d.FeeWalletAddr, nil, @@ -747,7 +743,6 @@ func (d *Driver) Start() error { d.Cfg.Metrics.RollupTimeDuration().Set(float64(d.Cfg.MainWorkerPollInterval)) if d.Cfg.CheckerEnable { batchIndex, ok := d.LevelDBStore.GetReRollupBatchIndex() - log.Info("get latest batch index", "batchIndex", batchIndex, "ok", ok) if batchIndex == 0 || !ok { d.LevelDBStore.SetReRollupBatchIndex(1) } @@ -768,6 +763,37 @@ func (d *Driver) Stop() { d.wg.Wait() } +func (d *Driver) GetBatchBlockRangeWithTimeout(ctx context.Context) (*big.Int, *big.Int, error) { + log.Debug("RollupTimeInterval start") + rollupTimout := d.Cfg.RollupTimeout + exit := time.NewTimer(rollupTimout) + ticker := time.NewTicker(pollingInterval) + for { + start, end, err := d.GetBatchBlockRange(d.Ctx) + if err != nil { + return nil, nil, err + } + select { + case <-ticker.C: + if big.NewInt(0).Sub(end, start).Cmp(big.NewInt(int64(d.Cfg.RollUpMinTxn))) >= 0 { + return start, end, nil + } + if start.Cmp(end) == 0 { + log.Info("MtBatcher Sequencer no updates", "start", start, "end", end) + continue + } + case <-exit.C: + if big.NewInt(0).Sub(end, start).Cmp(big.NewInt(int64(d.Cfg.MinTimeoutRollupTxn))) >= 0 { + return start, end, nil + } + return nil, nil, errors.Errorf("error: Timeout txn less than MinTimeoutRollupTxn") + case err := <-d.Ctx.Done(): + log.Error("MtBatcher get block range timeout error", "err", err) + return nil, nil, errors.New("MtBatcher get block range timeout error") + } + } +} + func (d *Driver) RollupMainWorker() { defer d.wg.Done() ticker := time.NewTicker(d.Cfg.MainWorkerPollInterval) @@ -775,22 +801,12 @@ func (d *Driver) RollupMainWorker() { for { select { case <-ticker.C: - log.Info("MtBatcher eigen da sequencer fetching current block range") - start, end, err := d.GetBatchBlockRange(d.Ctx) + start, end, err := d.GetBatchBlockRangeWithTimeout(d.Ctx) if err != nil { - log.Error("MtBatcher Sequencer unable to get block range", "err", err) + log.Warn("MtBatcher Sequencer unable to get block range", "err", err) continue } log.Info("MtBatcher get batch block range", "start", start, "end", end) - if start.Cmp(end) == 0 { - log.Info("MtBatcher Sequencer no updates", "start", start, "end", end) - continue - } - rollupMinTransactions := new(big.Int).Sub(end, start) - if big.NewInt(int64(d.Cfg.RollUpMinTxn)).Cmp(rollupMinTransactions) > 0 { - log.Info("MtBatcher rollup total transaction less than min transations in config", "RollUpMinTxn", d.Cfg.RollUpMinTxn, "rollupMinTransactions", rollupMinTransactions) - continue - } aggregateTxData, startL2BlockNumber, endL2BlockNumber := d.TxAggregator( d.Ctx, start, end, ) @@ -805,7 +821,6 @@ func (d *Driver) RollupMainWorker() { log.Error("MtBatcher disperse store data fail", "err", err) continue } - log.Info("MtBatcher disperse store data success", "txHash", receipt.TxHash.String()) d.Cfg.Metrics.L2StoredBlockNumber().Set(float64(start.Uint64())) time.Sleep(10 * time.Second) // sleep for data into graph node csdReceipt, err := d.ConfirmStoredData(receipt.TxHash.Bytes(), params, startL2BlockNumber, endL2BlockNumber, 0, big.NewInt(0), false) @@ -813,7 +828,7 @@ func (d *Driver) RollupMainWorker() { log.Error("MtBatcher confirm store data fail", "err", err) continue } - log.Info("MtBatcher confirm store data success", "txHash", csdReceipt.TxHash.String()) + log.Debug("MtBatcher confirm store data success", "txHash", csdReceipt.TxHash.String()) d.Cfg.Metrics.L2ConfirmedBlockNumber().Set(float64(start.Uint64())) if d.Cfg.FeeModelEnable { daFee, _ := d.CalcUserFeeByRules(big.NewInt(int64(len(aggregateTxData)))) @@ -825,6 +840,7 @@ func (d *Driver) RollupMainWorker() { } batchIndex, _ := d.Cfg.EigenDaContract.RollupBatchIndex(&bind.CallOpts{}) d.Cfg.Metrics.RollUpBatchIndex().Set(float64(batchIndex.Uint64())) + case err := <-d.Ctx.Done(): log.Error("MtBatcher eigenDa sequencer service shutting down", "err", err) return @@ -846,7 +862,7 @@ func (d *Driver) RollUpFeeWorker() { continue } daFee := <-d.FeeCh - log.Info("MtBatcher RollUpFeeWorker chainFee and daFee", "chainFee", chainFee, "daFee", *daFee) + log.Debug("MtBatcher RollUpFeeWorker chainFee and daFee", "chainFee", chainFee, "daFee", *daFee) if chainFee.Cmp(daFee.RollUpFee) != 0 { txfRpt, err := d.UpdateUserDaFee(daFee.EndL2BlockNumber, daFee.RollUpFee) if err != nil { @@ -854,7 +870,7 @@ func (d *Driver) RollUpFeeWorker() { continue } d.Cfg.Metrics.EigenUserFee().Set(float64(daFee.RollUpFee.Uint64())) - log.Info("MtBatcher RollUpFeeWorker update user fee success", "Hash", txfRpt.TxHash.String()) + log.Debug("MtBatcher RollUpFeeWorker update user fee success", "Hash", txfRpt.TxHash.String()) } } case err := <-d.Ctx.Done(): @@ -888,7 +904,7 @@ func (d *Driver) CheckConfirmedWorker() { continue } - log.Info("Checker db batch index and contract batch idnex", "DbBatchIndex", batchIndex, "ContractBatchIndex", latestReRollupBatchIndex.Uint64()) + log.Debug("Checker db batch index and contract batch idnex", "DbBatchIndex", batchIndex, "ContractBatchIndex", latestReRollupBatchIndex.Uint64()) for i := batchIndex; i < latestReRollupBatchIndex.Uint64(); i++ { log.Info("Checker batch confirm data index", "batchIndex", i) reConfirmedBatchIndex, err := d.Cfg.EigenDaContract.ReRollupBatchIndex(&bind.CallOpts{}, big.NewInt(int64(i))) @@ -908,7 +924,7 @@ func (d *Driver) CheckConfirmedWorker() { log.Info("Checker get l2 rollup block fail", "err", err) continue } - log.Info("Checker DataStoreIdToL2RollUpBlock", "rollupBlock.StartL2BlockNumber", rollupBlock.StartL2BlockNumber, "rollupBlock.EndBL2BlockNumber", rollupBlock.EndBL2BlockNumber) + log.Debug("Checker DataStoreIdToL2RollUpBlock", "rollupBlock.StartL2BlockNumber", rollupBlock.StartL2BlockNumber, "rollupBlock.EndBL2BlockNumber", rollupBlock.EndBL2BlockNumber) aggregateTxData, startL2BlockNumber, endL2BlockNumber := d.TxAggregator( d.Ctx, rollupBlock.StartL2BlockNumber, rollupBlock.EndBL2BlockNumber, @@ -925,7 +941,6 @@ func (d *Driver) CheckConfirmedWorker() { continue } time.Sleep(10 * time.Second) // sleep for data into graph node - log.Info("MtBatcher disperse re-rollup store data success", "txHash", receipt.TxHash.String()) csdReceipt, err := d.ConfirmStoredData(receipt.TxHash.Bytes(), params, startL2BlockNumber, endL2BlockNumber, rollupStore.DataStoreId, reConfirmedBatchIndex, true) if err != nil { log.Error("Checker confirm store data fail", "err", err) diff --git a/mt-batcher/txmgr/txmgr.go b/mt-batcher/txmgr/txmgr.go index 0796cda98..6a169c3f2 100644 --- a/mt-batcher/txmgr/txmgr.go +++ b/mt-batcher/txmgr/txmgr.go @@ -74,7 +74,7 @@ func (m *SimpleTxManager) Send(ctx context.Context, updateGasPrice UpdateGasPric nonce := tx.Nonce() gasTipCap := tx.GasTipCap() gasFeeCap := tx.GasFeeCap() - log.Info("MtBatcher publishing transaction", "txHash", txHash, "nonce", nonce, "gasTipCap", gasTipCap, "gasFeeCap", gasFeeCap) + log.Debug("MtBatcher publishing transaction", "txHash", txHash, "nonce", nonce, "gasTipCap", gasTipCap, "gasFeeCap", gasFeeCap) err = sendTx(ctxc, tx) sendState.ProcessSendError(err) @@ -89,7 +89,7 @@ func (m *SimpleTxManager) Send(ctx context.Context, updateGasPrice UpdateGasPric return } - log.Info("MtBatcher transaction published successfully", "hash", txHash, "nonce", nonce, "gasTipCap", gasTipCap, "gasFeeCap", gasFeeCap) + log.Debug("MtBatcher transaction published successfully", "hash", txHash, "nonce", nonce, "gasTipCap", gasTipCap, "gasFeeCap", gasFeeCap) receipt, err := waitMined( ctxc, m.backend, tx, m.cfg.ReceiptQueryInterval, @@ -178,7 +178,7 @@ func waitMined( "numConfirmations", numConfirmations) if txHeight+numConfirmations <= tipHeight+1 { - log.Info("MtBatcher Transaction confirmed", "txHash", txHash) + log.Debug("MtBatcher Transaction confirmed", "txHash", txHash) return receipt, nil } diff --git a/packages/contracts/contracts/L2/predeploys/BVM_MANTLE.sol b/packages/contracts/contracts/L2/predeploys/BVM_MANTLE.sol index 09c1c69f5..c0f025b91 100644 --- a/packages/contracts/contracts/L2/predeploys/BVM_MANTLE.sol +++ b/packages/contracts/contracts/L2/predeploys/BVM_MANTLE.sol @@ -6,7 +6,6 @@ import { Lib_PredeployAddresses } from "../../libraries/constants/Lib_PredeployA /* Contract Imports */ import { L2StandardERC20 } from "../../standards/L2StandardERC20.sol"; -import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; diff --git a/packages/fault-detector/package.json b/packages/fault-detector/package.json index d5055fbae..2cde9dd1c 100644 --- a/packages/fault-detector/package.json +++ b/packages/fault-detector/package.json @@ -50,7 +50,7 @@ "@mantleio/common-ts": "0.1.0", "@mantleio/contracts": "0.2.1", "@mantleio/core-utils": "0.1.0", - "@mantleio/sdk": "0.2.1", + "@mantleio/sdk": "0.2.2", "@ethersproject/abstract-provider": "^5.6.1" } } diff --git a/packages/message-relayer/package.json b/packages/message-relayer/package.json index 14db68556..83e957d26 100644 --- a/packages/message-relayer/package.json +++ b/packages/message-relayer/package.json @@ -33,7 +33,7 @@ "dependencies": { "@mantleio/common-ts": "0.1.0", "@mantleio/core-utils": "0.1.0", - "@mantleio/sdk": "0.2.1", + "@mantleio/sdk": "0.2.2", "ethers": "^5.6.8" }, "devDependencies": { diff --git a/packages/sdk/package.json b/packages/sdk/package.json index fc6b2c1b8..9504d6f3d 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@mantleio/sdk", - "version": "0.2.1", + "version": "0.2.2", "description": "[Mantle] Tools for working with Mantle", "main": "dist/index", "types": "dist/index", diff --git a/packages/sdk/src/adapters/standard-bridge.ts b/packages/sdk/src/adapters/standard-bridge.ts index efd02fccd..94cd05e48 100644 --- a/packages/sdk/src/adapters/standard-bridge.ts +++ b/packages/sdk/src/adapters/standard-bridge.ts @@ -178,8 +178,11 @@ export class StandardBridgeAdapter implements IBridgeAdapter { if (hexStringEquals(remoteL1Token, toAddress(L1_MNT_ADDRESS[this.messenger.l2ChainId]))){ return true } + if (hexStringEquals(remoteL1Token, toAddress('0x1a4b46696b2bb4794eb3d4c26f1c55f9170fa4c5'))){ + return true + } - if (!hexStringEquals(remoteL1Token, toAddress(l1Token))) { + if (!hexStringEquals(remoteL1Token, toAddress(l1Token))) { return false }