diff --git a/rollup/cmd/mock_app.go b/rollup/cmd/mock_app.go index c186e5a339..aaa26ceba6 100644 --- a/rollup/cmd/mock_app.go +++ b/rollup/cmd/mock_app.go @@ -88,9 +88,9 @@ func (b *MockApp) MockConfig(store bool) error { } cfg.L1Config.Endpoint = base.L1gethImg.Endpoint() - cfg.L2Config.RelayerConfig.SenderConfig.Endpoint = base.L1gethImg.Endpoint() - cfg.L2Config.Endpoint = base.L2gethImg.Endpoint() cfg.L1Config.RelayerConfig.SenderConfig.Endpoint = base.L2gethImg.Endpoint() + cfg.L2Config.Endpoint = base.L2gethImg.Endpoint() + cfg.L2Config.RelayerConfig.SenderConfig.Endpoint = base.L1gethImg.Endpoint() cfg.DBConfig.DSN = base.DBImg.Endpoint() b.Config = cfg diff --git a/rollup/conf/config.json b/rollup/conf/config.json index c02abe0068..612c6cd10f 100644 --- a/rollup/conf/config.json +++ b/rollup/conf/config.json @@ -1,14 +1,14 @@ { "l1_config": { "confirmations": "0x6", - "endpoint": "DUMMY_ENDPOINT", + "endpoint": "https://rpc.ankr.com/eth", "l1_message_queue_address": "0x0000000000000000000000000000000000000000", "scroll_chain_address": "0x0000000000000000000000000000000000000000", "start_height": 0, "relayer_config": { "gas_price_oracle_address": "0x0000000000000000000000000000000000000000", "sender_config": { - "endpoint": "https://sepolia-rpc.scroll.io", + "endpoint": "https://rpc.scroll.io", "check_pending_time": 2, "check_balance_time": 100, "escalate_blocks": 100, @@ -29,14 +29,14 @@ }, "l2_config": { "confirmations": "0x1", - "endpoint": "https://sepolia-rpc.scroll.io", + "endpoint": "https://rpc.scroll.io", "l2_messenger_address": "0x0000000000000000000000000000000000000000", "l2_message_queue_address": "0x0000000000000000000000000000000000000000", "relayer_config": { "rollup_contract_address": "0x0000000000000000000000000000000000000000", "gas_price_oracle_address": "0x0000000000000000000000000000000000000000", "sender_config": { - "endpoint": "https://sepolia-rpc.scroll.io", + "endpoint": "https://rpc.ankr.com/eth", "check_pending_time": 10, "check_balance_time": 100, "escalate_blocks": 100, @@ -44,7 +44,7 @@ "escalate_multiple_num": 11, "escalate_multiple_den": 10, "max_gas_price": 10000000000, - "tx_type": "LegacyTx", + "tx_type": "DynamicFeeTx", "min_balance": 100000000000000000000, "pending_limit": 10 }, diff --git a/rollup/internal/controller/relayer/relayer_test.go b/rollup/internal/controller/relayer/relayer_test.go index 6ca76d8cf4..d2ddb12504 100644 --- a/rollup/internal/controller/relayer/relayer_test.go +++ b/rollup/internal/controller/relayer/relayer_test.go @@ -10,6 +10,7 @@ import ( "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/ethclient" + "github.com/scroll-tech/go-ethereum/log" "github.com/stretchr/testify/assert" "scroll-tech/common/database" @@ -40,6 +41,10 @@ var ( ) func setupEnv(t *testing.T) { + glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.LogfmtFormat())) + glogger.Verbosity(log.LvlInfo) + log.Root().SetHandler(glogger) + // Load config. var err error cfg, err = config.NewConfig("../../../conf/config.json") diff --git a/rollup/internal/controller/sender/estimategas.go b/rollup/internal/controller/sender/estimategas.go index 0edab916de..6f813bd60e 100644 --- a/rollup/internal/controller/sender/estimategas.go +++ b/rollup/internal/controller/sender/estimategas.go @@ -102,7 +102,7 @@ func (s *Sender) estimateGasLimit(contract *common.Address, data []byte, gasPric return gasLimitWithoutAccessList, nil, fmt.Errorf(errStr) } - // Heuristically fine-tune accessList because 'to' address is automatically included in the access list by the Ethereum protocol: https://github.com/ethereum/go-ethereum/blob/v1.13.10/core/state/statedb.go#L1322 + // Fine-tune accessList because 'to' address is automatically included in the access list by the Ethereum protocol: https://github.com/ethereum/go-ethereum/blob/v1.13.10/core/state/statedb.go#L1322 // This function returns a gas estimation because GO SDK does not support access list: https://github.com/ethereum/go-ethereum/blob/v1.13.10/ethclient/ethclient.go#L642 accessList, gasLimitWithAccessList = finetuneAccessList(accessList, gasLimitWithAccessList, msg.To) @@ -122,11 +122,11 @@ func finetuneAccessList(accessList *types.AccessList, gasLimitWithAccessList uin var newAccessList types.AccessList for _, entry := range *accessList { if entry.Address == *to && len(entry.StorageKeys) < 24 { - // This is a heuristic method, we check if number of slots is < 24. - // If so, we remove it and adjust the gas limit estimate accordingly. + // Based on: https://arxiv.org/pdf/2312.06574.pdf + // We remove the address and respective storage keys as long as the number of storage keys < 24. // This removal helps in preventing double-counting of the 'to' address in access list calculations. gasLimitWithAccessList -= 2400 - // Assuming each slot saves 100 gas units as access list storage key cost (1900 gas) plus warm sload (100 gas) is cheaper than cold sload (2100 gas). + // Each storage key saves 100 gas units. gasLimitWithAccessList += uint64(100 * len(entry.StorageKeys)) } else { // Otherwise, keep the entry in the new access list. diff --git a/rollup/internal/controller/sender/sender_test.go b/rollup/internal/controller/sender/sender_test.go index f79826ffeb..eff73af73a 100644 --- a/rollup/internal/controller/sender/sender_test.go +++ b/rollup/internal/controller/sender/sender_test.go @@ -5,6 +5,7 @@ import ( "crypto/ecdsa" "errors" "math/big" + "os" "strconv" "testing" @@ -14,6 +15,7 @@ import ( "github.com/scroll-tech/go-ethereum/core/types" "github.com/scroll-tech/go-ethereum/crypto" "github.com/scroll-tech/go-ethereum/ethclient" + "github.com/scroll-tech/go-ethereum/log" "github.com/scroll-tech/go-ethereum/rpc" "github.com/stretchr/testify/assert" @@ -44,6 +46,10 @@ func TestMain(m *testing.M) { } func setupEnv(t *testing.T) { + glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.LogfmtFormat())) + glogger.Verbosity(log.LvlInfo) + log.Root().SetHandler(glogger) + var err error cfg, err = config.NewConfig("../../../conf/config.json") assert.NoError(t, err) @@ -194,12 +200,12 @@ func testAccessListTransactionGasLimit(t *testing.T) { gasLimit, accessList, err := s.estimateGasLimit(&scrollChainAddress, data, big.NewInt(100000000000), big.NewInt(100000000000), big.NewInt(100000000000), big.NewInt(0), true) assert.NoError(t, err) - assert.Equal(t, uint64(43450), gasLimit) + assert.Equal(t, uint64(43472), gasLimit) assert.NotNil(t, accessList) gasLimit, accessList, err = s.estimateGasLimit(&scrollChainAddress, data, big.NewInt(100000000000), big.NewInt(100000000000), big.NewInt(100000000000), big.NewInt(0), false) assert.NoError(t, err) - assert.Equal(t, uint64(43927), gasLimit) + assert.Equal(t, uint64(43949), gasLimit) assert.Nil(t, accessList) s.Stop() diff --git a/rollup/internal/controller/watcher/watcher_test.go b/rollup/internal/controller/watcher/watcher_test.go index 0bae139de3..c032a8079a 100644 --- a/rollup/internal/controller/watcher/watcher_test.go +++ b/rollup/internal/controller/watcher/watcher_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/scroll-tech/go-ethereum/ethclient" + "github.com/scroll-tech/go-ethereum/log" "github.com/stretchr/testify/assert" "gorm.io/gorm" @@ -33,6 +34,10 @@ var ( ) func setupEnv(t *testing.T) (err error) { + glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.LogfmtFormat())) + glogger.Verbosity(log.LvlInfo) + log.Root().SetHandler(glogger) + // Load config. cfg, err = config.NewConfig("../../../conf/config.json") assert.NoError(t, err) diff --git a/rollup/mock_bridge/MockBridgeL1.sol b/rollup/mock_bridge/MockBridgeL1.sol index 9824e40cf8..a18ba6083f 100644 --- a/rollup/mock_bridge/MockBridgeL1.sol +++ b/rollup/mock_bridge/MockBridgeL1.sol @@ -128,6 +128,10 @@ contract MockBridgeL1 { * Functions from ScrollChain * ******************************/ + /// @notice Import layer 2 genesis block + function importGenesisBatch(bytes calldata _batchHeader, bytes32 _stateRoot) external { + } + function commitBatch( uint8 /*version*/, bytes calldata _parentBatchHeader, diff --git a/rollup/tests/bridge_test.go b/rollup/tests/bridge_test.go index 57ab7dac11..eae810be6c 100644 --- a/rollup/tests/bridge_test.go +++ b/rollup/tests/bridge_test.go @@ -5,6 +5,7 @@ import ( "crypto/rand" "math/big" "net/http" + "os" "strconv" "strings" "testing" @@ -14,6 +15,7 @@ import ( "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/core/types" "github.com/scroll-tech/go-ethereum/ethclient" + "github.com/scroll-tech/go-ethereum/log" "github.com/stretchr/testify/assert" "gorm.io/gorm" @@ -68,6 +70,10 @@ func TestMain(m *testing.M) { } func setupEnv(t *testing.T) { + glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.LogfmtFormat())) + glogger.Verbosity(log.LvlInfo) + log.Root().SetHandler(glogger) + base.RunImages(t) var err error @@ -138,15 +144,10 @@ func TestFunction(t *testing.T) { t.Run("TestProcessStartEnableMetrics", testProcessStartEnableMetrics) // l1 rollup and watch rollup events + t.Run("TestCommitAndFinalizeGenesisBatch", testCommitAndFinalizeGenesisBatch) t.Run("TestCommitBatchAndFinalizeBatch", testCommitBatchAndFinalizeBatch) - // l1 message - - // l2 message - // TODO: add a "user relay l2msg Succeed" test - // l1/l2 gas oracle t.Run("TestImportL1GasPrice", testImportL1GasPrice) t.Run("TestImportL2GasPrice", testImportL2GasPrice) - } diff --git a/rollup/tests/rollup_test.go b/rollup/tests/rollup_test.go index 5eae9d86b1..682b2dfe68 100644 --- a/rollup/tests/rollup_test.go +++ b/rollup/tests/rollup_test.go @@ -20,6 +20,34 @@ import ( "scroll-tech/rollup/internal/orm" ) +func testCommitAndFinalizeGenesisBatch(t *testing.T) { + db := setupDB(t) + defer database.CloseDB(db) + + prepareContracts(t) + + l2Cfg := rollupApp.Config.L2Config + l2Relayer, err := relayer.NewLayer2Relayer(context.Background(), l2Client, db, l2Cfg.RelayerConfig, true, nil) + assert.NoError(t, err) + assert.NotNil(t, l2Relayer) + + genesisChunkHash := common.HexToHash("0x00e076380b00a3749816fcc9a2a576b529952ef463222a54544d21b7d434dfe1") + chunkOrm := orm.NewChunk(db) + dbChunk, err := chunkOrm.GetChunksInRange(context.Background(), 0, 0) + assert.NoError(t, err) + assert.Len(t, dbChunk, 1) + assert.Equal(t, genesisChunkHash.String(), dbChunk[0].Hash) + assert.Equal(t, types.ProvingTaskVerified, types.ProvingStatus(dbChunk[0].ProvingStatus)) + + genesisBatchHash := common.HexToHash("0x2d214b024f5337d83a5681f88575ab225f345ec2e4e3ce53cf4dc4b0cb5c96b1") + batchOrm := orm.NewBatch(db) + batch, err := batchOrm.GetBatchByIndex(context.Background(), 0) + assert.NoError(t, err) + assert.Equal(t, genesisBatchHash.String(), batch.Hash) + assert.Equal(t, types.ProvingTaskVerified, types.ProvingStatus(batch.ProvingStatus)) + assert.Equal(t, types.RollupFinalized, types.RollupStatus(batch.RollupStatus)) +} + func testCommitBatchAndFinalizeBatch(t *testing.T) { db := setupDB(t) defer database.CloseDB(db)