diff --git a/common/forks/forks.go b/common/forks/forks.go index 1080e3add4..be4e0deba7 100644 --- a/common/forks/forks.go +++ b/common/forks/forks.go @@ -64,17 +64,6 @@ func CollectSortedForkHeights(config *params.ChainConfig) ([]uint64, map[uint64] return forkHeights, forkHeightsMap, forkNameHeightMap } -// BlocksUntilFork returns the number of blocks until the next fork -// returns 0 if there is no fork scheduled for the future -func BlocksUntilFork(blockHeight uint64, forkHeights []uint64) uint64 { - for _, forkHeight := range forkHeights { - if forkHeight > blockHeight { - return forkHeight - blockHeight - } - } - return 0 -} - // BlockRange returns the block range of the hard fork // Need ensure the forkHeights is incremental func BlockRange(currentForkHeight uint64, forkHeights []uint64) (from, to uint64) { diff --git a/common/forks/forks_test.go b/common/forks/forks_test.go index 73a75a7a0c..44292db389 100644 --- a/common/forks/forks_test.go +++ b/common/forks/forks_test.go @@ -33,46 +33,6 @@ func TestCollectSortedForkBlocks(t *testing.T) { }, n) } -func TestBlocksUntilFork(t *testing.T) { - tests := map[string]struct { - block uint64 - forks []uint64 - expected uint64 - }{ - "NoFork": { - block: 44, - forks: []uint64{}, - expected: 0, - }, - "BeforeFork": { - block: 0, - forks: []uint64{1, 5}, - expected: 1, - }, - "OnFork": { - block: 1, - forks: []uint64{1, 5}, - expected: 4, - }, - "OnLastFork": { - block: 5, - forks: []uint64{1, 5}, - expected: 0, - }, - "AfterFork": { - block: 5, - forks: []uint64{1, 5}, - expected: 0, - }, - } - - for name, test := range tests { - t.Run(name, func(t *testing.T) { - require.Equal(t, test.expected, BlocksUntilFork(test.block, test.forks)) - }) - } -} - func TestBlockRange(t *testing.T) { tests := []struct { name string diff --git a/go.work.sum b/go.work.sum index 0adbebdf50..d884b2f426 100644 --- a/go.work.sum +++ b/go.work.sum @@ -307,6 +307,7 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= github.com/envoyproxy/go-control-plane v0.11.1/go.mod h1:uhMcXKCQMEJHiAb0w+YGefQLaTEw+YhGluxZkrTmD0g= +github.com/ethereum/c-kzg-4844 v1.0.2/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/ethereum/go-ethereum v1.10.26 h1:i/7d9RBBwiXCEuyduBQzJw/mKmnvzsN14jqBmytw72s= github.com/ethereum/go-ethereum v1.10.26/go.mod h1:EYFyF19u3ezGLD4RqOkLq+ZCXzYbLoNDdZlMt7kyKFg= github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= @@ -378,6 +379,7 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7 github.com/gotestyourself/gotestyourself v1.4.0/go.mod h1:zZKM6oeNM8k+FRljX1mnzVYeS8wiGgQyvST1/GafPbY= github.com/graph-gophers/graphql-go v0.0.0-20201113091052-beb923fada29 h1:sezaKhEfPFg8W0Enm61B9Gs911H8iesGY5R8NDPtd1M= github.com/graph-gophers/graphql-go v0.0.0-20201113091052-beb923fada29/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc= +github.com/graph-gophers/graphql-go v1.3.0 h1:Eb9x/q6MFpCLz7jBCiP/WTxjSDrYLR1QY41SORZyNJ0= github.com/graph-gophers/graphql-go v1.3.0/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= @@ -506,10 +508,7 @@ github.com/schollz/closestmatch v2.1.0+incompatible h1:Uel2GXEpJqOWBrlyI+oY9LTiy github.com/schollz/closestmatch v2.1.0+incompatible/go.mod h1:RtP1ddjLong6gTkbtmuhtR2uUrrJOpYzYRvbcPAid+g= github.com/sclevine/agouti v3.0.0+incompatible h1:8IBJS6PWz3uTlMP3YBIR5f+KAldcGuOeFkFbUWfBgK4= github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw= -github.com/scroll-tech/da-codec v0.0.0-20240515170552-2e5286688fce h1:SN43TBs7VaJt9q737eWWqGz0OCg4v+PtUn3RbJcG1o0= -github.com/scroll-tech/da-codec v0.0.0-20240515170552-2e5286688fce/go.mod h1:1wWYii0OPwd5kw+xrz0PFgS420xNadrNF1x/ELJT+TM= -github.com/scroll-tech/da-codec v0.0.0-20240626090813-e197995302f3 h1:aDnxfgflaWcRnRb7qCQdeJs980s9UDhAvE9QVqjxxJ0= -github.com/scroll-tech/da-codec v0.0.0-20240626090813-e197995302f3/go.mod h1:D6XEESeNVJkQJlv3eK+FyR+ufPkgVQbJzERylQi53Bs= +github.com/scroll-tech/da-codec v0.0.0-20240605080813-32bfc9fccde7/go.mod h1:1wWYii0OPwd5kw+xrz0PFgS420xNadrNF1x/ELJT+TM= github.com/scroll-tech/go-ethereum v1.10.14-0.20221202061207-804e7edc23ba/go.mod h1:jurIpDQ0hqtp9//xxeWzr8X9KMP/+TYn+vz3K1wZrv0= github.com/scroll-tech/go-ethereum v1.10.14-0.20221213034543-78c1f57fcfea/go.mod h1:jurIpDQ0hqtp9//xxeWzr8X9KMP/+TYn+vz3K1wZrv0= github.com/scroll-tech/go-ethereum v1.10.14-0.20221221073256-5ca70bf3a257/go.mod h1:jurIpDQ0hqtp9//xxeWzr8X9KMP/+TYn+vz3K1wZrv0= @@ -521,11 +520,7 @@ github.com/scroll-tech/go-ethereum v1.10.14-0.20230802095950-4b2bbf6225e7/go.mod github.com/scroll-tech/go-ethereum v1.10.14-0.20230829000527-f883dcdc21fc/go.mod h1:DiN3p2inoXOxGffxSswDKqWjQ7bU+Mp0c9v0XQXKmaA= github.com/scroll-tech/go-ethereum v1.10.14-0.20240607130425-e2becce6a1a4 h1:gheWXra3HdZsz6q+w4LrXy8ybHOO6/t6Kb/V64bR5wE= github.com/scroll-tech/go-ethereum v1.10.14-0.20240607130425-e2becce6a1a4/go.mod h1:byf/mZ8jLYUCnUePTicjJWn+RvKdxDn7buS6glTnMwQ= -github.com/scroll-tech/go-ethereum v1.10.14-0.20240626125436-418bc6f728b6 h1:Q8YyvrcPIcXQwE4ucm4bqmPh6TP6IB1GUTXripf2WyQ= -github.com/scroll-tech/go-ethereum v1.10.14-0.20240626125436-418bc6f728b6/go.mod h1:byf/mZ8jLYUCnUePTicjJWn+RvKdxDn7buS6glTnMwQ= github.com/scroll-tech/zktrie v0.6.0/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk= -github.com/scroll-tech/zktrie v0.8.4 h1:UagmnZ4Z3ITCk+aUq9NQZJNAwnWl4gSxsLb2Nl7IgRE= -github.com/scroll-tech/zktrie v0.8.4/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk= github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo= github.com/segmentio/kafka-go v0.2.0 h1:HtCSf6B4gN/87yc5qTl7WsxPKQIIGXLPPM1bMCPOsoY= github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo= @@ -554,6 +549,7 @@ github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980/go.mod h github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= +github.com/supranational/blst v0.3.11-0.20230124161941-ca03e11a3ff2/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= github.com/tchap/go-patricia/v2 v2.3.1/go.mod h1:VZRHKAb53DLaG+nA9EaYYiaEx6YztwDlLElMsnSHD4k= github.com/tdewolff/minify/v2 v2.12.4 h1:kejsHQMM17n6/gwdw53qsi6lg0TGddZADVyQOz1KMdE= @@ -630,7 +626,10 @@ golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.0.0-20220314234659-1baeb1ce4c0b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -658,6 +657,8 @@ golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -672,6 +673,8 @@ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -699,14 +702,21 @@ golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= +golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= +golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -731,6 +741,8 @@ golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200108203644-89082a384178/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= diff --git a/rollup/abi/bridge_abi.go b/rollup/abi/bridge_abi.go index d273be7188..8e58db048d 100644 --- a/rollup/abi/bridge_abi.go +++ b/rollup/abi/bridge_abi.go @@ -66,7 +66,7 @@ func init() { // ScrollChainMetaData contains all meta data concerning the ScrollChain contract. var ScrollChainMetaData = &bind.MetaData{ - ABI: "[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"batchIndex\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"batchHash\",\"type\":\"bytes32\"}],\"name\":\"CommitBatch\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"batchIndex\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"batchHash\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"stateRoot\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"withdrawRoot\",\"type\":\"bytes32\"}],\"name\":\"FinalizeBatch\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"batchIndex\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"batchHash\",\"type\":\"bytes32\"}],\"name\":\"RevertBatch\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"oldMaxNumTxInChunk\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"newMaxNumTxInChunk\",\"type\":\"uint256\"}],\"name\":\"UpdateMaxNumTxInChunk\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"status\",\"type\":\"bool\"}],\"name\":\"UpdateProver\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"status\",\"type\":\"bool\"}],\"name\":\"UpdateSequencer\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"version\",\"type\":\"uint8\"},{\"internalType\":\"bytes\",\"name\":\"parentBatchHeader\",\"type\":\"bytes\"},{\"internalType\":\"bytes[]\",\"name\":\"chunks\",\"type\":\"bytes[]\"},{\"internalType\":\"bytes\",\"name\":\"skippedL1MessageBitmap\",\"type\":\"bytes\"}],\"name\":\"commitBatch\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"batchIndex\",\"type\":\"uint256\"}],\"name\":\"committedBatches\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"batchHeader\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"prevStateRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"postStateRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"withdrawRoot\",\"type\":\"bytes32\"}],\"name\":\"finalizeBatch\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"batchHeader\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"prevStateRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"postStateRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"withdrawRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes\",\"name\":\"blobDataProof\",\"type\":\"bytes\"}],\"name\":\"finalizeBatch4844\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"batchHeader\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"prevStateRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"postStateRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"withdrawRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes\",\"name\":\"aggrProof\",\"type\":\"bytes\"}],\"name\":\"finalizeBatchWithProof\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"batchHeader\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"prevStateRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"postStateRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"withdrawRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes\",\"name\":\"blobDataProof\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"aggrProof\",\"type\":\"bytes\"}],\"name\":\"finalizeBatchWithProof4844\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"batchIndex\",\"type\":\"uint256\"}],\"name\":\"finalizedStateRoots\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"_batchHeader\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"_stateRoot\",\"type\":\"bytes32\"}],\"name\":\"importGenesisBatch\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"batchIndex\",\"type\":\"uint256\"}],\"name\":\"isBatchFinalized\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"lastFinalizedBatchIndex\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"batchHeader\",\"type\":\"bytes\"},{\"internalType\":\"uint256\",\"name\":\"count\",\"type\":\"uint256\"}],\"name\":\"revertBatch\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"batchIndex\",\"type\":\"uint256\"}],\"name\":\"withdrawRoots\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]", + ABI: "[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"batchIndex\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"batchHash\",\"type\":\"bytes32\"}],\"name\":\"CommitBatch\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"batchIndex\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"batchHash\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"stateRoot\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"withdrawRoot\",\"type\":\"bytes32\"}],\"name\":\"FinalizeBatch\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"batchIndex\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"batchHash\",\"type\":\"bytes32\"}],\"name\":\"RevertBatch\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"oldMaxNumTxInChunk\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"newMaxNumTxInChunk\",\"type\":\"uint256\"}],\"name\":\"UpdateMaxNumTxInChunk\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"status\",\"type\":\"bool\"}],\"name\":\"UpdateProver\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"status\",\"type\":\"bool\"}],\"name\":\"UpdateSequencer\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"version\",\"type\":\"uint8\"},{\"internalType\":\"bytes\",\"name\":\"parentBatchHeader\",\"type\":\"bytes\"},{\"internalType\":\"bytes[]\",\"name\":\"chunks\",\"type\":\"bytes[]\"},{\"internalType\":\"bytes\",\"name\":\"skippedL1MessageBitmap\",\"type\":\"bytes\"}],\"name\":\"commitBatch\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"version\",\"type\":\"uint8\"},{\"internalType\":\"bytes\",\"name\":\"parentBatchHeader\",\"type\":\"bytes\"},{\"internalType\":\"bytes[]\",\"name\":\"chunks\",\"type\":\"bytes[]\"},{\"internalType\":\"bytes\",\"name\":\"skippedL1MessageBitmap\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"blobDataProof\",\"type\":\"bytes\"}],\"name\":\"commitBatchWithBlobProof\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"batchIndex\",\"type\":\"uint256\"}],\"name\":\"committedBatches\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"batchHeader\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"prevStateRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"postStateRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"withdrawRoot\",\"type\":\"bytes32\"}],\"name\":\"finalizeBatch\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"batchHeader\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"prevStateRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"postStateRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"withdrawRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes\",\"name\":\"blobDataProof\",\"type\":\"bytes\"}],\"name\":\"finalizeBatch4844\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"batchHeader\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"prevStateRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"postStateRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"withdrawRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes\",\"name\":\"aggrProof\",\"type\":\"bytes\"}],\"name\":\"finalizeBatchWithProof\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"batchHeader\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"prevStateRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"postStateRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"withdrawRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes\",\"name\":\"blobDataProof\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"aggrProof\",\"type\":\"bytes\"}],\"name\":\"finalizeBatchWithProof4844\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"batchHeader\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"postStateRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"withdrawRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes\",\"name\":\"aggrProof\",\"type\":\"bytes\"}],\"name\":\"finalizeBundleWithProof\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"batchIndex\",\"type\":\"uint256\"}],\"name\":\"finalizedStateRoots\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"_batchHeader\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"_stateRoot\",\"type\":\"bytes32\"}],\"name\":\"importGenesisBatch\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"batchIndex\",\"type\":\"uint256\"}],\"name\":\"isBatchFinalized\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"lastFinalizedBatchIndex\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"batchHeader\",\"type\":\"bytes\"},{\"internalType\":\"uint256\",\"name\":\"count\",\"type\":\"uint256\"}],\"name\":\"revertBatch\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"batchIndex\",\"type\":\"uint256\"}],\"name\":\"withdrawRoots\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]", } // L1ScrollMessengerMetaData contains all meta data concerning the L1ScrollMessenger contract. diff --git a/rollup/go.mod b/rollup/go.mod index 1ba1f98287..51c776097e 100644 --- a/rollup/go.mod +++ b/rollup/go.mod @@ -10,8 +10,8 @@ require ( github.com/go-resty/resty/v2 v2.7.0 github.com/holiman/uint256 v1.2.4 github.com/prometheus/client_golang v1.16.0 - github.com/scroll-tech/da-codec v0.0.0-20240605080813-32bfc9fccde7 - github.com/scroll-tech/go-ethereum v1.10.14-0.20240426041101-a860446ebaea + github.com/scroll-tech/da-codec v0.0.0-20240626090813-e197995302f3 + github.com/scroll-tech/go-ethereum v1.10.14-0.20240626125436-418bc6f728b6 github.com/smartystreets/goconvey v1.8.0 github.com/stretchr/testify v1.9.0 github.com/urfave/cli/v2 v2.25.7 @@ -21,7 +21,7 @@ require ( require ( github.com/VictoriaMetrics/fastcache v1.12.1 // indirect github.com/beorn7/perks v1.0.1 // indirect - github.com/bits-and-blooms/bitset v1.12.0 // indirect + github.com/bits-and-blooms/bitset v1.13.0 // indirect github.com/btcsuite/btcd v0.20.1-beta // indirect github.com/bytedance/sonic v1.10.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect @@ -55,7 +55,7 @@ require ( github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect github.com/holiman/bloomfilter/v2 v2.0.3 // indirect github.com/huin/goupnp v1.3.0 // indirect - github.com/iden3/go-iden3-crypto v0.0.15 // indirect + github.com/iden3/go-iden3-crypto v0.0.16 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect @@ -86,25 +86,25 @@ require ( github.com/rjeczalik/notify v0.9.1 // indirect github.com/rs/cors v1.7.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/scroll-tech/zktrie v0.8.2 // indirect + github.com/scroll-tech/zktrie v0.8.4 // indirect github.com/shirou/gopsutil v3.21.11+incompatible // indirect github.com/smartystreets/assertions v1.13.1 // indirect github.com/status-im/keycard-go v0.2.0 // indirect - github.com/supranational/blst v0.3.11-0.20230124161941-ca03e11a3ff2 // indirect + github.com/supranational/blst v0.3.12 // indirect github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect - github.com/tklauser/go-sysconf v0.3.12 // indirect - github.com/tklauser/numcpus v0.6.1 // indirect + github.com/tklauser/go-sysconf v0.3.14 // indirect + github.com/tklauser/numcpus v0.8.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/tyler-smith/go-bip39 v1.1.0 // indirect github.com/ugorji/go/codec v1.2.11 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect - github.com/yusufpapurcu/wmi v1.2.3 // indirect + github.com/yusufpapurcu/wmi v1.2.4 // indirect golang.org/x/arch v0.5.0 // indirect - golang.org/x/crypto v0.17.0 // indirect - golang.org/x/net v0.18.0 // indirect - golang.org/x/sync v0.6.0 // indirect - golang.org/x/sys v0.17.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/crypto v0.24.0 // indirect + golang.org/x/net v0.21.0 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/sys v0.21.0 // indirect + golang.org/x/text v0.16.0 // indirect golang.org/x/time v0.3.0 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect diff --git a/rollup/go.sum b/rollup/go.sum index 21cfaafaf3..32d3c05488 100644 --- a/rollup/go.sum +++ b/rollup/go.sum @@ -11,8 +11,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 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/bits-and-blooms/bitset v1.12.0 h1:U/q1fAF7xXRhFCrhROzIfffYnu+dlS38vCZtmFVPHmA= -github.com/bits-and-blooms/bitset v1.12.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= +github.com/bits-and-blooms/bitset v1.13.0 h1:bAQ9OPNFYbGHV6Nez0tmNI0RiEu7/hxlYJRUA0wFAVE= +github.com/bits-and-blooms/bitset v1.13.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/btcsuite/btcd v0.20.1-beta h1:Ik4hyJqN8Jfyv3S4AGBOmyouMsYE3EdYODkMbQjwPGw= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= @@ -135,8 +135,8 @@ github.com/holiman/uint256 v1.2.4/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXei github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc= github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= -github.com/iden3/go-iden3-crypto v0.0.15 h1:4MJYlrot1l31Fzlo2sF56u7EVFeHHJkxGXXZCtESgK4= -github.com/iden3/go-iden3-crypto v0.0.15/go.mod h1:dLpM4vEPJ3nDHzhWFXDjzkn1qHoBeOT/3UEhXsEsP3E= +github.com/iden3/go-iden3-crypto v0.0.16 h1:zN867xiz6HgErXVIV/6WyteGcOukE9gybYTorBMEdsk= +github.com/iden3/go-iden3-crypto v0.0.16/go.mod h1:dLpM4vEPJ3nDHzhWFXDjzkn1qHoBeOT/3UEhXsEsP3E= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= @@ -236,12 +236,12 @@ github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/scroll-tech/da-codec v0.0.0-20240605080813-32bfc9fccde7 h1:CDrPMqifvAVyYqu0x1J5qickVV0b51tApPnOwDYLESI= -github.com/scroll-tech/da-codec v0.0.0-20240605080813-32bfc9fccde7/go.mod h1:1wWYii0OPwd5kw+xrz0PFgS420xNadrNF1x/ELJT+TM= -github.com/scroll-tech/go-ethereum v1.10.14-0.20240426041101-a860446ebaea h1:CH1WXWrpEpLaP3N+bFs2a1xdE0+lRm1AuJQb5YvE6Ls= -github.com/scroll-tech/go-ethereum v1.10.14-0.20240426041101-a860446ebaea/go.mod h1:i4VBgWoaW/y0D8MmQb7hSOulyw1dKhuiSFAbznwivCA= -github.com/scroll-tech/zktrie v0.8.2 h1:UMuIfA+jdgWMLmTgTL64Emo+zzMOdcnH0+eYdDcshxQ= -github.com/scroll-tech/zktrie v0.8.2/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk= +github.com/scroll-tech/da-codec v0.0.0-20240626090813-e197995302f3 h1:aDnxfgflaWcRnRb7qCQdeJs980s9UDhAvE9QVqjxxJ0= +github.com/scroll-tech/da-codec v0.0.0-20240626090813-e197995302f3/go.mod h1:D6XEESeNVJkQJlv3eK+FyR+ufPkgVQbJzERylQi53Bs= +github.com/scroll-tech/go-ethereum v1.10.14-0.20240626125436-418bc6f728b6 h1:Q8YyvrcPIcXQwE4ucm4bqmPh6TP6IB1GUTXripf2WyQ= +github.com/scroll-tech/go-ethereum v1.10.14-0.20240626125436-418bc6f728b6/go.mod h1:byf/mZ8jLYUCnUePTicjJWn+RvKdxDn7buS6glTnMwQ= +github.com/scroll-tech/zktrie v0.8.4 h1:UagmnZ4Z3ITCk+aUq9NQZJNAwnWl4gSxsLb2Nl7IgRE= +github.com/scroll-tech/zktrie v0.8.4/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= @@ -267,14 +267,14 @@ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/supranational/blst v0.3.11-0.20230124161941-ca03e11a3ff2 h1:wh1wzwAhZBNiZO37uWS/nDaKiIwHz4mDo4pnA+fqTO0= -github.com/supranational/blst v0.3.11-0.20230124161941-ca03e11a3ff2/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= +github.com/supranational/blst v0.3.12 h1:Vfas2U2CFHhniv2QkUm2OVa1+pGTdqtpqm9NnhUUbZ8= +github.com/supranational/blst v0.3.12/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= -github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= -github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= -github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= -github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= +github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZb78yU= +github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY= +github.com/tklauser/numcpus v0.8.0 h1:Mx4Wwe/FjZLeQsK/6kt2EOepwwSl7SmJrK5bV/dXYgY= +github.com/tklauser/numcpus v0.8.0/go.mod h1:ZJZlAY+dmR4eut8epnzf0u/VwodKmryxR8txiloSqBE= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= @@ -286,8 +286,8 @@ github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6S github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= -github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= +github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.5.0 h1:jpGode6huXQxcskEIpOCvrU+tzo81b6+oFLUYXWtH/Y= golang.org/x/arch v0.5.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= @@ -295,8 +295,8 @@ golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= -golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= +golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -306,16 +306,16 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= -golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -336,17 +336,15 @@ golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/rollup/internal/controller/relayer/l2_relayer.go b/rollup/internal/controller/relayer/l2_relayer.go index d49f136d67..984bdd9674 100644 --- a/rollup/internal/controller/relayer/l2_relayer.go +++ b/rollup/internal/controller/relayer/l2_relayer.go @@ -13,6 +13,7 @@ import ( "github.com/scroll-tech/da-codec/encoding/codecv0" "github.com/scroll-tech/da-codec/encoding/codecv1" "github.com/scroll-tech/da-codec/encoding/codecv2" + "github.com/scroll-tech/da-codec/encoding/codecv3" "github.com/scroll-tech/go-ethereum/accounts/abi" "github.com/scroll-tech/go-ethereum/common" gethTypes "github.com/scroll-tech/go-ethereum/core/types" @@ -383,12 +384,18 @@ func (r *Layer2Relayer) ProcessPendingBatches() { log.Error("failed to construct commitBatch payload codecv1", "index", dbBatch.Index, "err", err) return } - } else { // codecv2 + } else if !r.chainCfg.IsDarwin(dbChunks[0].StartBlockTime) { // codecv2 calldata, blob, err = r.constructCommitBatchPayloadCodecV2(dbBatch, dbParentBatch, dbChunks, chunks) if err != nil { log.Error("failed to construct commitBatch payload codecv2", "index", dbBatch.Index, "err", err) return } + } else { // codecv3 + calldata, blob, err = r.constructCommitBatchPayloadCodecV3(dbBatch, dbParentBatch, dbChunks, chunks) + if err != nil { + log.Error("failed to construct commitBatch payload codecv3", "index", dbBatch.Index, "err", err) + return + } } // fallbackGasLimit is non-zero only in sending non-blob transactions. @@ -833,6 +840,45 @@ func (r *Layer2Relayer) constructCommitBatchPayloadCodecV2(dbBatch *orm.Batch, d return calldata, daBatch.Blob(), nil } +func (r *Layer2Relayer) constructCommitBatchPayloadCodecV3(dbBatch *orm.Batch, dbParentBatch *orm.Batch, dbChunks []*orm.Chunk, chunks []*encoding.Chunk) ([]byte, *kzg4844.Blob, error) { + batch := &encoding.Batch{ + Index: dbBatch.Index, + TotalL1MessagePoppedBefore: dbChunks[0].TotalL1MessagesPoppedBefore, + ParentBatchHash: common.HexToHash(dbParentBatch.Hash), + Chunks: chunks, + } + + daBatch, createErr := codecv3.NewDABatch(batch) + if createErr != nil { + return nil, nil, fmt.Errorf("failed to create DA batch: %w", createErr) + } + + encodedChunks := make([][]byte, len(dbChunks)) + for i, c := range dbChunks { + daChunk, createErr := codecv3.NewDAChunk(chunks[i], c.TotalL1MessagesPoppedBefore) + if createErr != nil { + return nil, nil, fmt.Errorf("failed to create DA chunk: %w", createErr) + } + encodedChunks[i] = daChunk.Encode() + } + + blobDataProof, err := daBatch.BlobDataProofForPointEvaluation() + if err != nil { + return nil, nil, fmt.Errorf("failed to get blob data proof for point evaluation: %w", err) + } + + skippedL1MessageBitmap, _, err := encoding.ConstructSkippedBitmap(batch.Index, batch.Chunks, batch.TotalL1MessagePoppedBefore) + if err != nil { + return nil, nil, fmt.Errorf("failed to construct skipped L1 message bitmap: %w", err) + } + + calldata, packErr := r.l1RollupABI.Pack("commitBatchWithBlobProof", daBatch.Version, dbParentBatch.BatchHeader, encodedChunks, skippedL1MessageBitmap, blobDataProof) + if packErr != nil { + return nil, nil, fmt.Errorf("failed to pack commitBatchWithBlobProof: %w", packErr) + } + return calldata, daBatch.Blob(), nil +} + func (r *Layer2Relayer) constructFinalizeBatchPayloadCodecV0(dbBatch *orm.Batch, dbParentBatch *orm.Batch, aggProof *message.BatchProof) ([]byte, error) { if aggProof != nil { // finalizeBatch with proof. calldata, packErr := r.l1RollupABI.Pack( diff --git a/rollup/internal/controller/relayer/l2_relayer_test.go b/rollup/internal/controller/relayer/l2_relayer_test.go index 344e259ae9..9d098f6914 100644 --- a/rollup/internal/controller/relayer/l2_relayer_test.go +++ b/rollup/internal/controller/relayer/l2_relayer_test.go @@ -51,15 +51,21 @@ func testCreateNewRelayer(t *testing.T) { } func testL2RelayerProcessPendingBatches(t *testing.T) { - codecVersions := []encoding.CodecVersion{encoding.CodecV0, encoding.CodecV1, encoding.CodecV2} + codecVersions := []encoding.CodecVersion{encoding.CodecV0, encoding.CodecV1, encoding.CodecV2, encoding.CodecV3} for _, codecVersion := range codecVersions { db := setupL2RelayerDB(t) defer database.CloseDB(db) l2Cfg := cfg.L2Config - chainConfig := ¶ms.ChainConfig{} + var chainConfig *params.ChainConfig if codecVersion == encoding.CodecV0 { - chainConfig.BernoulliBlock = big.NewInt(0) + chainConfig = ¶ms.ChainConfig{} + } else if codecVersion == encoding.CodecV1 { + chainConfig = ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0)} + } else if codecVersion == encoding.CodecV2 { + chainConfig = ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0)} + } else { + chainConfig = ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64)} } relayer, err := NewLayer2Relayer(context.Background(), l2Cli, db, l2Cfg.RelayerConfig, chainConfig, true, ServiceTypeL2RollupRelayer, nil) diff --git a/rollup/internal/controller/watcher/batch_proposer.go b/rollup/internal/controller/watcher/batch_proposer.go index 10b5a645ab..76b8e03bf0 100644 --- a/rollup/internal/controller/watcher/batch_proposer.go +++ b/rollup/internal/controller/watcher/batch_proposer.go @@ -3,7 +3,6 @@ package watcher import ( "context" "fmt" - "math/big" "time" "github.com/prometheus/client_golang/prometheus" @@ -35,7 +34,6 @@ type BatchProposer struct { batchTimeoutSec uint64 gasCostIncreaseMultiplier float64 maxUncompressedBatchBytesSize uint64 - forkMap map[uint64]bool chainCfg *params.ChainConfig @@ -56,14 +54,12 @@ type BatchProposer struct { // NewBatchProposer creates a new BatchProposer instance. func NewBatchProposer(ctx context.Context, cfg *config.BatchProposerConfig, chainCfg *params.ChainConfig, db *gorm.DB, reg prometheus.Registerer) *BatchProposer { - forkHeights, forkMap, _ := forks.CollectSortedForkHeights(chainCfg) log.Debug("new batch proposer", "maxL1CommitGasPerBatch", cfg.MaxL1CommitGasPerBatch, "maxL1CommitCalldataSizePerBatch", cfg.MaxL1CommitCalldataSizePerBatch, "batchTimeoutSec", cfg.BatchTimeoutSec, "gasCostIncreaseMultiplier", cfg.GasCostIncreaseMultiplier, - "maxUncompressedBatchBytesSize", cfg.MaxUncompressedBatchBytesSize, - "forkHeights", forkHeights) + "maxUncompressedBatchBytesSize", cfg.MaxUncompressedBatchBytesSize) p := &BatchProposer{ ctx: ctx, @@ -76,7 +72,6 @@ func NewBatchProposer(ctx context.Context, cfg *config.BatchProposerConfig, chai batchTimeoutSec: cfg.BatchTimeoutSec, gasCostIncreaseMultiplier: cfg.GasCostIncreaseMultiplier, maxUncompressedBatchBytesSize: cfg.MaxUncompressedBatchBytesSize, - forkMap: forkMap, chainCfg: chainCfg, batchProposerCircleTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{ @@ -177,20 +172,7 @@ func (p *BatchProposer) proposeBatch() error { return err } - startBlockNum := new(big.Int).SetUint64(firstUnbatchedChunk.StartBlockNumber) - - var codecVersion encoding.CodecVersion - var maxChunksThisBatch uint64 - if !p.chainCfg.IsBernoulli(startBlockNum) { - codecVersion = encoding.CodecV0 - maxChunksThisBatch = 15 - } else if !p.chainCfg.IsCurie(startBlockNum) { - codecVersion = encoding.CodecV1 - maxChunksThisBatch = 15 - } else { - codecVersion = encoding.CodecV2 - maxChunksThisBatch = 45 - } + maxChunksThisBatch := forks.GetMaxChunksPerBatch(p.chainCfg, firstUnbatchedChunk.StartBlockNumber, firstUnbatchedChunk.StartBlockTime) // select at most maxChunkNumPerBatch chunks dbChunks, err := p.chunkOrm.GetChunksGEIndex(p.ctx, firstUnbatchedChunkIndex, int(maxChunksThisBatch)) @@ -202,13 +184,14 @@ func (p *BatchProposer) proposeBatch() error { return nil } - for i, chunk := range dbChunks { - // if a chunk is starting at a fork boundary, only consider earlier chunks - if i != 0 && p.forkMap[chunk.StartBlockNumber] { + // Ensure all chunks in the same batch use the same hardfork name + // If a different hardfork name is found, truncate the chunks slice at that point + hardforkName := forks.GetHardforkName(p.chainCfg, dbChunks[0].StartBlockNumber, dbChunks[0].StartBlockTime) + for i := 1; i < len(dbChunks); i++ { + currentHardfork := forks.GetHardforkName(p.chainCfg, dbChunks[i].StartBlockNumber, dbChunks[i].StartBlockTime) + if currentHardfork != hardforkName { dbChunks = dbChunks[:i] - if uint64(len(dbChunks)) < maxChunksThisBatch { - maxChunksThisBatch = uint64(len(dbChunks)) - } + maxChunksThisBatch = uint64(len(dbChunks)) // update maxChunksThisBatch to trigger batching, because these chunks are the last chunks before the hardfork break } } @@ -223,6 +206,8 @@ func (p *BatchProposer) proposeBatch() error { return err } + codecVersion := forks.GetCodecVersion(p.chainCfg, firstUnbatchedChunk.StartBlockNumber, firstUnbatchedChunk.StartBlockTime) + var batch encoding.Batch batch.Index = dbParentBatch.Index + 1 batch.ParentBatchHash = common.HexToHash(dbParentBatch.Hash) diff --git a/rollup/internal/controller/watcher/batch_proposer_test.go b/rollup/internal/controller/watcher/batch_proposer_test.go index 845109b98e..77aa85e8c6 100644 --- a/rollup/internal/controller/watcher/batch_proposer_test.go +++ b/rollup/internal/controller/watcher/batch_proposer_test.go @@ -75,15 +75,6 @@ func testBatchProposerCodecv0Limits(t *testing.T) { expectedBatchesLen: 1, expectedChunksInFirstBatch: 1, }, - { - name: "ForkBlockReached", - maxL1CommitGas: 50000000000, - maxL1CommitCalldataSize: 1000000, - batchTimeoutSec: 1000000000000, - expectedBatchesLen: 1, - expectedChunksInFirstBatch: 1, - forkBlock: big.NewInt(3), - }, } for _, tt := range tests { @@ -126,9 +117,7 @@ func testBatchProposerCodecv0Limits(t *testing.T) { MaxRowConsumptionPerChunk: 1000000, ChunkTimeoutSec: 300, GasCostIncreaseMultiplier: 1.2, - }, ¶ms.ChainConfig{ - HomesteadBlock: tt.forkBlock, - }, db, nil) + }, ¶ms.ChainConfig{}, db, nil) cp.TryProposeChunk() // chunk1 contains block1 cp.TryProposeChunk() // chunk2 contains block2 @@ -227,15 +216,6 @@ func testBatchProposerCodecv1Limits(t *testing.T) { expectedBatchesLen: 1, expectedChunksInFirstBatch: 1, }, - { - name: "ForkBlockReached", - maxL1CommitGas: 50000000000, - maxL1CommitCalldataSize: 1000000, - batchTimeoutSec: 1000000000000, - expectedBatchesLen: 1, - expectedChunksInFirstBatch: 1, - forkBlock: big.NewInt(3), - }, } for _, tt := range tests { @@ -280,7 +260,6 @@ func testBatchProposerCodecv1Limits(t *testing.T) { GasCostIncreaseMultiplier: 1.2, }, ¶ms.ChainConfig{ BernoulliBlock: big.NewInt(0), - HomesteadBlock: tt.forkBlock, }, db, nil) cp.TryProposeChunk() // chunk1 contains block1 cp.TryProposeChunk() // chunk2 contains block2 @@ -366,7 +345,7 @@ func testBatchProposerCodecv2Limits(t *testing.T) { }, { name: "MaxL1CommitGasPerBatchIsFirstChunk", - maxL1CommitGas: 190330, + maxL1CommitGas: 189179, maxL1CommitCalldataSize: 1000000, batchTimeoutSec: 1000000000000, expectedBatchesLen: 1, @@ -380,14 +359,152 @@ func testBatchProposerCodecv2Limits(t *testing.T) { expectedBatchesLen: 1, expectedChunksInFirstBatch: 1, }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + db := setupDB(t) + defer database.CloseDB(db) + + // Add genesis batch. + block := &encoding.Block{ + Header: &gethTypes.Header{ + Number: big.NewInt(0), + }, + RowConsumption: &gethTypes.RowConsumption{}, + } + chunk := &encoding.Chunk{ + Blocks: []*encoding.Block{block}, + } + chunkOrm := orm.NewChunk(db) + _, err := chunkOrm.InsertChunk(context.Background(), chunk, encoding.CodecV0, utils.ChunkMetrics{}) + assert.NoError(t, err) + batch := &encoding.Batch{ + Index: 0, + TotalL1MessagePoppedBefore: 0, + ParentBatchHash: common.Hash{}, + Chunks: []*encoding.Chunk{chunk}, + } + batchOrm := orm.NewBatch(db) + _, err = batchOrm.InsertBatch(context.Background(), batch, encoding.CodecV0, utils.BatchMetrics{}) + assert.NoError(t, err) + + l2BlockOrm := orm.NewL2Block(db) + err = l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block1, block2}) + assert.NoError(t, err) + + cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ + MaxBlockNumPerChunk: 1, + MaxTxNumPerChunk: 10000, + MaxL1CommitGasPerChunk: 50000000000, + MaxL1CommitCalldataSizePerChunk: 1000000, + MaxRowConsumptionPerChunk: 1000000, + ChunkTimeoutSec: 300, + GasCostIncreaseMultiplier: 1.2, + MaxUncompressedBatchBytesSize: math.MaxUint64, + }, ¶ms.ChainConfig{ + BernoulliBlock: big.NewInt(0), + CurieBlock: big.NewInt(0), + }, db, nil) + cp.TryProposeChunk() // chunk1 contains block1 + cp.TryProposeChunk() // chunk2 contains block2 + + chunks, err := chunkOrm.GetChunksInRange(context.Background(), 1, 2) + assert.NoError(t, err) + assert.Equal(t, uint64(1124), chunks[0].TotalL1CommitGas) + assert.Equal(t, uint64(60), chunks[0].TotalL1CommitCalldataSize) + assert.Equal(t, uint64(1124), chunks[1].TotalL1CommitGas) + assert.Equal(t, uint64(60), chunks[1].TotalL1CommitCalldataSize) + + bp := NewBatchProposer(context.Background(), &config.BatchProposerConfig{ + MaxL1CommitGasPerBatch: tt.maxL1CommitGas, + MaxL1CommitCalldataSizePerBatch: tt.maxL1CommitCalldataSize, + BatchTimeoutSec: tt.batchTimeoutSec, + GasCostIncreaseMultiplier: 1.2, + MaxUncompressedBatchBytesSize: math.MaxUint64, + }, ¶ms.ChainConfig{ + BernoulliBlock: big.NewInt(0), + CurieBlock: big.NewInt(0), + HomesteadBlock: tt.forkBlock, + }, db, nil) + bp.TryProposeBatch() + + batches, err := batchOrm.GetBatches(context.Background(), map[string]interface{}{}, []string{}, 0) + assert.NoError(t, err) + assert.Len(t, batches, tt.expectedBatchesLen+1) + batches = batches[1:] + if tt.expectedBatchesLen > 0 { + assert.Equal(t, uint64(1), batches[0].StartChunkIndex) + assert.Equal(t, tt.expectedChunksInFirstBatch, batches[0].EndChunkIndex) + assert.Equal(t, types.RollupPending, types.RollupStatus(batches[0].RollupStatus)) + assert.Equal(t, types.ProvingTaskUnassigned, types.ProvingStatus(batches[0].ProvingStatus)) + + dbChunks, err := chunkOrm.GetChunksInRange(context.Background(), 1, tt.expectedChunksInFirstBatch) + assert.NoError(t, err) + assert.Len(t, dbChunks, int(tt.expectedChunksInFirstBatch)) + for _, chunk := range dbChunks { + assert.Equal(t, batches[0].Hash, chunk.BatchHash) + assert.Equal(t, types.ProvingTaskUnassigned, types.ProvingStatus(chunk.ProvingStatus)) + } + } + }) + } +} + +func testBatchProposerCodecv3Limits(t *testing.T) { + tests := []struct { + name string + maxL1CommitGas uint64 + maxL1CommitCalldataSize uint64 + batchTimeoutSec uint64 + forkBlock *big.Int + expectedBatchesLen int + expectedChunksInFirstBatch uint64 // only be checked when expectedBatchesLen > 0 + }{ + { + name: "NoLimitReached", + maxL1CommitGas: 50000000000, + maxL1CommitCalldataSize: 1000000, + batchTimeoutSec: 1000000000000, + expectedBatchesLen: 0, + }, { - name: "ForkBlockReached", + name: "Timeout", maxL1CommitGas: 50000000000, maxL1CommitCalldataSize: 1000000, + batchTimeoutSec: 0, + expectedBatchesLen: 1, + expectedChunksInFirstBatch: 2, + }, + { + name: "MaxL1CommitGasPerBatchIs0", + maxL1CommitGas: 0, + maxL1CommitCalldataSize: 1000000, + batchTimeoutSec: 1000000000000, + expectedBatchesLen: 0, + }, + { + name: "MaxL1CommitCalldataSizePerBatchIs0", + maxL1CommitGas: 50000000000, + maxL1CommitCalldataSize: 0, + batchTimeoutSec: 1000000000000, + expectedBatchesLen: 0, + }, + { + name: "MaxL1CommitGasPerBatchIsFirstChunk", + maxL1CommitGas: 249179, + maxL1CommitCalldataSize: 1000000, + batchTimeoutSec: 1000000000000, + expectedBatchesLen: 1, + expectedChunksInFirstBatch: 1, + }, + { + name: "MaxL1CommitCalldataSizePerBatchIsFirstChunk", + maxL1CommitGas: 50000000000, + maxL1CommitCalldataSize: 60, batchTimeoutSec: 1000000000000, expectedBatchesLen: 1, expectedChunksInFirstBatch: 1, - forkBlock: big.NewInt(3), }, } @@ -435,6 +552,7 @@ func testBatchProposerCodecv2Limits(t *testing.T) { }, ¶ms.ChainConfig{ BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), + DarwinTime: new(uint64), HomesteadBlock: tt.forkBlock, }, db, nil) cp.TryProposeChunk() // chunk1 contains block1 @@ -442,9 +560,9 @@ func testBatchProposerCodecv2Limits(t *testing.T) { chunks, err := chunkOrm.GetChunksInRange(context.Background(), 1, 2) assert.NoError(t, err) - assert.Equal(t, uint64(1124), chunks[0].TotalL1CommitGas) + assert.Equal(t, uint64(51124), chunks[0].TotalL1CommitGas) assert.Equal(t, uint64(60), chunks[0].TotalL1CommitCalldataSize) - assert.Equal(t, uint64(1124), chunks[1].TotalL1CommitGas) + assert.Equal(t, uint64(51124), chunks[1].TotalL1CommitGas) assert.Equal(t, uint64(60), chunks[1].TotalL1CommitCalldataSize) bp := NewBatchProposer(context.Background(), &config.BatchProposerConfig{ @@ -456,7 +574,7 @@ func testBatchProposerCodecv2Limits(t *testing.T) { }, ¶ms.ChainConfig{ BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), - HomesteadBlock: tt.forkBlock, + DarwinTime: new(uint64), }, db, nil) bp.TryProposeBatch() @@ -721,9 +839,90 @@ func testBatchCommitGasAndCalldataSizeCodecv2Estimation(t *testing.T) { assert.Equal(t, uint64(120), batches[0].TotalL1CommitCalldataSize) } +func testBatchCommitGasAndCalldataSizeCodecv3Estimation(t *testing.T) { + db := setupDB(t) + defer database.CloseDB(db) + + // Add genesis batch. + block := &encoding.Block{ + Header: &gethTypes.Header{ + Number: big.NewInt(0), + }, + RowConsumption: &gethTypes.RowConsumption{}, + } + chunk := &encoding.Chunk{ + Blocks: []*encoding.Block{block}, + } + chunkOrm := orm.NewChunk(db) + _, err := chunkOrm.InsertChunk(context.Background(), chunk, encoding.CodecV0, utils.ChunkMetrics{}) + assert.NoError(t, err) + batch := &encoding.Batch{ + Index: 0, + TotalL1MessagePoppedBefore: 0, + ParentBatchHash: common.Hash{}, + Chunks: []*encoding.Chunk{chunk}, + } + batchOrm := orm.NewBatch(db) + _, err = batchOrm.InsertBatch(context.Background(), batch, encoding.CodecV0, utils.BatchMetrics{}) + assert.NoError(t, err) + + l2BlockOrm := orm.NewL2Block(db) + err = l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block1, block2}) + assert.NoError(t, err) + + cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ + MaxBlockNumPerChunk: 1, + MaxTxNumPerChunk: 10000, + MaxL1CommitGasPerChunk: 50000000000, + MaxL1CommitCalldataSizePerChunk: 1000000, + MaxRowConsumptionPerChunk: 1000000, + ChunkTimeoutSec: 300, + GasCostIncreaseMultiplier: 1.2, + MaxUncompressedBatchBytesSize: math.MaxUint64, + }, ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64)}, db, nil) + cp.TryProposeChunk() // chunk1 contains block1 + cp.TryProposeChunk() // chunk2 contains block2 + + chunks, err := chunkOrm.GetChunksInRange(context.Background(), 1, 2) + assert.NoError(t, err) + assert.Equal(t, uint64(51124), chunks[0].TotalL1CommitGas) + assert.Equal(t, uint64(60), chunks[0].TotalL1CommitCalldataSize) + assert.Equal(t, uint64(51124), chunks[1].TotalL1CommitGas) + assert.Equal(t, uint64(60), chunks[1].TotalL1CommitCalldataSize) + + bp := NewBatchProposer(context.Background(), &config.BatchProposerConfig{ + MaxL1CommitGasPerBatch: 50000000000, + MaxL1CommitCalldataSizePerBatch: 1000000, + BatchTimeoutSec: 0, + GasCostIncreaseMultiplier: 1.2, + MaxUncompressedBatchBytesSize: math.MaxUint64, + }, ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64)}, db, nil) + bp.TryProposeBatch() + + batches, err := batchOrm.GetBatches(context.Background(), map[string]interface{}{}, []string{}, 0) + assert.NoError(t, err) + assert.Len(t, batches, 2) + batches = batches[1:] + assert.Equal(t, uint64(1), batches[0].StartChunkIndex) + assert.Equal(t, uint64(2), batches[0].EndChunkIndex) + assert.Equal(t, types.RollupPending, types.RollupStatus(batches[0].RollupStatus)) + assert.Equal(t, types.ProvingTaskUnassigned, types.ProvingStatus(batches[0].ProvingStatus)) + + dbChunks, err := chunkOrm.GetChunksInRange(context.Background(), 1, 2) + assert.NoError(t, err) + assert.Len(t, dbChunks, 2) + for _, chunk := range dbChunks { + assert.Equal(t, batches[0].Hash, chunk.BatchHash) + assert.Equal(t, types.ProvingTaskUnassigned, types.ProvingStatus(chunk.ProvingStatus)) + } + + assert.Equal(t, uint64(209350), batches[0].TotalL1CommitGas) + assert.Equal(t, uint64(120), batches[0].TotalL1CommitCalldataSize) +} + func testBatchProposerBlobSizeLimit(t *testing.T) { - compressionTests := []bool{false, true} // false for uncompressed, true for compressed - for _, compressed := range compressionTests { + codecVersions := []encoding.CodecVersion{encoding.CodecV0, encoding.CodecV1, encoding.CodecV2, encoding.CodecV3} + for _, codecVersion := range codecVersions { db := setupDB(t) // Add genesis batch. @@ -750,10 +949,14 @@ func testBatchProposerBlobSizeLimit(t *testing.T) { assert.NoError(t, err) var chainConfig *params.ChainConfig - if compressed { + if codecVersion == encoding.CodecV0 { // will never hit blob size limit + chainConfig = ¶ms.ChainConfig{} + } else if codecVersion == encoding.CodecV1 { + chainConfig = ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0)} + } else if codecVersion == encoding.CodecV2 { chainConfig = ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0)} } else { - chainConfig = ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0)} + chainConfig = ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64)} } cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ @@ -769,7 +972,7 @@ func testBatchProposerBlobSizeLimit(t *testing.T) { blockHeight := int64(0) block = readBlockFromJSON(t, "../../../testdata/blockTrace_03.json") - for total := int64(0); total < 20; total++ { + for total := int64(0); total < 90; total++ { for i := int64(0); i < 30; i++ { blockHeight++ l2BlockOrm := orm.NewL2Block(db) @@ -788,7 +991,7 @@ func testBatchProposerBlobSizeLimit(t *testing.T) { MaxUncompressedBatchBytesSize: math.MaxUint64, }, chainConfig, db, nil) - for i := 0; i < 30; i++ { + for i := 0; i < 2; i++ { bp.TryProposeBatch() } @@ -798,12 +1001,18 @@ func testBatchProposerBlobSizeLimit(t *testing.T) { var expectedNumBatches int var numChunksMultiplier uint64 - if compressed { - expectedNumBatches = 1 - numChunksMultiplier = 20 - } else { - expectedNumBatches = 20 + if codecVersion == encoding.CodecV0 { + expectedNumBatches = 2 + numChunksMultiplier = 15 + } else if codecVersion == encoding.CodecV1 { + expectedNumBatches = 2 numChunksMultiplier = 1 + } else if codecVersion == encoding.CodecV2 { + expectedNumBatches = 2 + numChunksMultiplier = 45 + } else { + expectedNumBatches = 2 + numChunksMultiplier = 45 } assert.Len(t, batches, expectedNumBatches) @@ -815,8 +1024,8 @@ func testBatchProposerBlobSizeLimit(t *testing.T) { } func testBatchProposerMaxChunkNumPerBatchLimit(t *testing.T) { - compressionTests := []bool{false, true} // false for uncompressed, true for compressed - for _, compressed := range compressionTests { + codecVersions := []encoding.CodecVersion{encoding.CodecV0, encoding.CodecV1, encoding.CodecV2, encoding.CodecV3} + for _, codecVersion := range codecVersions { db := setupDB(t) // Add genesis batch. @@ -842,11 +1051,20 @@ func testBatchProposerMaxChunkNumPerBatchLimit(t *testing.T) { _, err = batchOrm.InsertBatch(context.Background(), batch, encoding.CodecV0, utils.BatchMetrics{}) assert.NoError(t, err) + var expectedChunkNum uint64 var chainConfig *params.ChainConfig - if compressed { + if codecVersion == encoding.CodecV0 { + chainConfig = ¶ms.ChainConfig{} + expectedChunkNum = 15 + } else if codecVersion == encoding.CodecV1 { + chainConfig = ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0)} + expectedChunkNum = 15 + } else if codecVersion == encoding.CodecV2 { chainConfig = ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0)} + expectedChunkNum = 45 } else { - chainConfig = ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0)} + chainConfig = ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64)} + expectedChunkNum = 45 } cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ @@ -882,14 +1100,90 @@ func testBatchProposerMaxChunkNumPerBatchLimit(t *testing.T) { assert.Len(t, batches, 2) dbBatch := batches[1] - var expectedChunkNum uint64 - if compressed { - expectedChunkNum = 45 - } else { - expectedChunkNum = 15 - } assert.Equal(t, expectedChunkNum, dbBatch.EndChunkIndex) database.CloseDB(db) } } + +func testBatchProposerRespectHardforks(t *testing.T) { + db := setupDB(t) + defer database.CloseDB(db) + + chainConfig := ¶ms.ChainConfig{ + BernoulliBlock: big.NewInt(1), + CurieBlock: big.NewInt(2), + DarwinTime: func() *uint64 { t := uint64(4); return &t }(), + } + + // Add genesis batch. + block := &encoding.Block{ + Header: &gethTypes.Header{ + Number: big.NewInt(0), + }, + RowConsumption: &gethTypes.RowConsumption{}, + } + chunk := &encoding.Chunk{ + Blocks: []*encoding.Block{block}, + } + chunkOrm := orm.NewChunk(db) + _, err := chunkOrm.InsertChunk(context.Background(), chunk, encoding.CodecV0, utils.ChunkMetrics{}) + assert.NoError(t, err) + batch := &encoding.Batch{ + Index: 0, + TotalL1MessagePoppedBefore: 0, + ParentBatchHash: common.Hash{}, + Chunks: []*encoding.Chunk{chunk}, + } + batchOrm := orm.NewBatch(db) + _, err = batchOrm.InsertBatch(context.Background(), batch, encoding.CodecV0, utils.BatchMetrics{}) + assert.NoError(t, err) + + cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ + MaxBlockNumPerChunk: math.MaxUint64, + MaxTxNumPerChunk: math.MaxUint64, + MaxL1CommitGasPerChunk: math.MaxUint64, + MaxL1CommitCalldataSizePerChunk: math.MaxUint64, + MaxRowConsumptionPerChunk: math.MaxUint64, + ChunkTimeoutSec: math.MaxUint64, + GasCostIncreaseMultiplier: 1, + MaxUncompressedBatchBytesSize: math.MaxUint64, + }, chainConfig, db, nil) + + block = readBlockFromJSON(t, "../../../testdata/blockTrace_02.json") + for i := int64(1); i <= 60; i++ { + block.Header.Number = big.NewInt(i) + block.Header.Time = uint64(i) + err = orm.NewL2Block(db).InsertL2Blocks(context.Background(), []*encoding.Block{block}) + assert.NoError(t, err) + } + + for i := 0; i < 5; i++ { + cp.TryProposeChunk() + } + + bp := NewBatchProposer(context.Background(), &config.BatchProposerConfig{ + MaxL1CommitGasPerBatch: math.MaxUint64, + MaxL1CommitCalldataSizePerBatch: math.MaxUint64, + BatchTimeoutSec: math.MaxUint64, + GasCostIncreaseMultiplier: 1, + MaxUncompressedBatchBytesSize: math.MaxUint64, + }, chainConfig, db, nil) + + for i := 0; i < 5; i++ { + bp.TryProposeBatch() + } + + batches, err := batchOrm.GetBatches(context.Background(), map[string]interface{}{}, []string{}, 0) + assert.NoError(t, err) + assert.Len(t, batches, 4) + + expectedEndChunkIndices := []uint64{0, 1, 3, 4} + expectedEndBlockNumbers := []uint64{0, 1, 3, 60} + for i, batch := range batches { + assert.Equal(t, expectedEndChunkIndices[i], batch.EndChunkIndex) + chunk, err := chunkOrm.GetChunkByIndex(context.Background(), batch.EndChunkIndex) + assert.NoError(t, err) + assert.Equal(t, expectedEndBlockNumbers[i], chunk.EndBlockNumber) + } +} diff --git a/rollup/internal/controller/watcher/chunk_proposer.go b/rollup/internal/controller/watcher/chunk_proposer.go index 8b8c07ea71..574c24d42e 100644 --- a/rollup/internal/controller/watcher/chunk_proposer.go +++ b/rollup/internal/controller/watcher/chunk_proposer.go @@ -35,7 +35,6 @@ type ChunkProposer struct { chunkTimeoutSec uint64 gasCostIncreaseMultiplier float64 maxUncompressedBatchBytesSize uint64 - forkHeights []uint64 chainCfg *params.ChainConfig @@ -58,7 +57,6 @@ type ChunkProposer struct { // NewChunkProposer creates a new ChunkProposer instance. func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, chainCfg *params.ChainConfig, db *gorm.DB, reg prometheus.Registerer) *ChunkProposer { - forkHeights, _, _ := forks.CollectSortedForkHeights(chainCfg) log.Debug("new chunk proposer", "maxTxNumPerChunk", cfg.MaxTxNumPerChunk, "maxL1CommitGasPerChunk", cfg.MaxL1CommitGasPerChunk, @@ -66,8 +64,7 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, chai "maxRowConsumptionPerChunk", cfg.MaxRowConsumptionPerChunk, "chunkTimeoutSec", cfg.ChunkTimeoutSec, "gasCostIncreaseMultiplier", cfg.GasCostIncreaseMultiplier, - "maxUncompressedBatchBytesSize", cfg.MaxUncompressedBatchBytesSize, - "forkHeights", forkHeights) + "maxUncompressedBatchBytesSize", cfg.MaxUncompressedBatchBytesSize) p := &ChunkProposer{ ctx: ctx, @@ -82,7 +79,6 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, chai chunkTimeoutSec: cfg.ChunkTimeoutSec, gasCostIncreaseMultiplier: cfg.GasCostIncreaseMultiplier, maxUncompressedBatchBytesSize: cfg.MaxUncompressedBatchBytesSize, - forkHeights: forkHeights, chainCfg: chainCfg, chunkProposerCircleTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{ @@ -194,10 +190,6 @@ func (p *ChunkProposer) proposeChunk() error { } maxBlocksThisChunk := p.maxBlockNumPerChunk - blocksUntilFork := forks.BlocksUntilFork(unchunkedBlockHeight, p.forkHeights) - if blocksUntilFork != 0 && blocksUntilFork < maxBlocksThisChunk { - maxBlocksThisChunk = blocksUntilFork - } // select at most maxBlocksThisChunk blocks blocks, err := p.l2BlockOrm.GetL2BlocksGEHeight(p.ctx, unchunkedBlockHeight, int(maxBlocksThisChunk)) @@ -209,15 +201,20 @@ func (p *ChunkProposer) proposeChunk() error { return nil } - var codecVersion encoding.CodecVersion - if !p.chainCfg.IsBernoulli(blocks[0].Header.Number) { - codecVersion = encoding.CodecV0 - } else if !p.chainCfg.IsCurie(blocks[0].Header.Number) { - codecVersion = encoding.CodecV1 - } else { - codecVersion = encoding.CodecV2 + // Ensure all blocks in the same chunk use the same hardfork name + // If a different hardfork name is found, truncate the blocks slice at that point + hardforkName := forks.GetHardforkName(p.chainCfg, blocks[0].Header.Number.Uint64(), blocks[0].Header.Time) + for i := 1; i < len(blocks); i++ { + currentHardfork := forks.GetHardforkName(p.chainCfg, blocks[i].Header.Number.Uint64(), blocks[i].Header.Time) + if currentHardfork != hardforkName { + blocks = blocks[:i] + maxBlocksThisChunk = uint64(i) // update maxBlocksThisChunk to trigger chunking, because these blocks are the last blocks before the hardfork + break + } } + codecVersion := forks.GetCodecVersion(p.chainCfg, blocks[0].Header.Number.Uint64(), blocks[0].Header.Time) + // Including Curie block in a sole chunk. if p.chainCfg.CurieBlock != nil && blocks[0].Header.Number.Cmp(p.chainCfg.CurieBlock) == 0 { chunk := encoding.Chunk{Blocks: blocks[:1]} diff --git a/rollup/internal/controller/watcher/chunk_proposer_test.go b/rollup/internal/controller/watcher/chunk_proposer_test.go index 7c35ac6640..805810f42c 100644 --- a/rollup/internal/controller/watcher/chunk_proposer_test.go +++ b/rollup/internal/controller/watcher/chunk_proposer_test.go @@ -145,18 +145,6 @@ func testChunkProposerCodecv0Limits(t *testing.T) { expectedChunksLen: 1, expectedBlocksInFirstChunk: 1, }, - { - name: "ForkBlockReached", - maxBlockNum: 100, - maxTxNum: 10000, - maxL1CommitGas: 50000000000, - maxL1CommitCalldataSize: 1000000, - maxRowConsumption: 1000000, - chunkTimeoutSec: 1000000000000, - expectedChunksLen: 1, - expectedBlocksInFirstChunk: 1, - forkBlock: big.NewInt(2), - }, } for _, tt := range tests { @@ -176,9 +164,7 @@ func testChunkProposerCodecv0Limits(t *testing.T) { MaxRowConsumptionPerChunk: tt.maxRowConsumption, ChunkTimeoutSec: tt.chunkTimeoutSec, GasCostIncreaseMultiplier: 1.2, - }, ¶ms.ChainConfig{ - HomesteadBlock: tt.forkBlock, - }, db, nil) + }, ¶ms.ChainConfig{}, db, nil) cp.TryProposeChunk() chunkOrm := orm.NewChunk(db) @@ -329,18 +315,6 @@ func testChunkProposerCodecv1Limits(t *testing.T) { expectedChunksLen: 1, expectedBlocksInFirstChunk: 1, }, - { - name: "ForkBlockReached", - maxBlockNum: 100, - maxTxNum: 10000, - maxL1CommitGas: 50000000000, - maxL1CommitCalldataSize: 1000000, - maxRowConsumption: 1000000, - chunkTimeoutSec: 1000000000000, - expectedChunksLen: 1, - expectedBlocksInFirstChunk: 1, - forkBlock: big.NewInt(2), - }, } for _, tt := range tests { @@ -360,9 +334,7 @@ func testChunkProposerCodecv1Limits(t *testing.T) { MaxRowConsumptionPerChunk: tt.maxRowConsumption, ChunkTimeoutSec: tt.chunkTimeoutSec, GasCostIncreaseMultiplier: 1.2, - }, ¶ms.ChainConfig{ - BernoulliBlock: big.NewInt(0), HomesteadBlock: tt.forkBlock, - }, db, nil) + }, ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0)}, db, nil) cp.TryProposeChunk() chunkOrm := orm.NewChunk(db) @@ -513,17 +485,176 @@ func testChunkProposerCodecv2Limits(t *testing.T) { expectedChunksLen: 1, expectedBlocksInFirstChunk: 1, }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + db := setupDB(t) + defer database.CloseDB(db) + + l2BlockOrm := orm.NewL2Block(db) + err := l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block1, block2}) + assert.NoError(t, err) + + cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ + MaxBlockNumPerChunk: tt.maxBlockNum, + MaxTxNumPerChunk: tt.maxTxNum, + MaxL1CommitGasPerChunk: tt.maxL1CommitGas, + MaxL1CommitCalldataSizePerChunk: tt.maxL1CommitCalldataSize, + MaxRowConsumptionPerChunk: tt.maxRowConsumption, + ChunkTimeoutSec: tt.chunkTimeoutSec, + GasCostIncreaseMultiplier: 1.2, + MaxUncompressedBatchBytesSize: math.MaxUint64, + }, ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0)}, db, nil) + cp.TryProposeChunk() + + chunkOrm := orm.NewChunk(db) + chunks, err := chunkOrm.GetChunksGEIndex(context.Background(), 0, 0) + assert.NoError(t, err) + assert.Len(t, chunks, tt.expectedChunksLen) + + if len(chunks) > 0 { + blockOrm := orm.NewL2Block(db) + chunkHashes, err := blockOrm.GetChunkHashes(context.Background(), tt.expectedBlocksInFirstChunk) + assert.NoError(t, err) + assert.Len(t, chunkHashes, tt.expectedBlocksInFirstChunk) + firstChunkHash := chunks[0].Hash + for _, chunkHash := range chunkHashes { + assert.Equal(t, firstChunkHash, chunkHash) + } + } + }) + } +} + +func testChunkProposerCodecv3Limits(t *testing.T) { + tests := []struct { + name string + maxBlockNum uint64 + maxTxNum uint64 + maxL1CommitGas uint64 + maxL1CommitCalldataSize uint64 + maxRowConsumption uint64 + chunkTimeoutSec uint64 + forkBlock *big.Int + expectedChunksLen int + expectedBlocksInFirstChunk int // only be checked when expectedChunksLen > 0 + }{ + { + name: "NoLimitReached", + maxBlockNum: 100, + maxTxNum: 10000, + maxL1CommitGas: 50000000000, + maxL1CommitCalldataSize: 1000000, + maxRowConsumption: 1000000, + chunkTimeoutSec: 1000000000000, + expectedChunksLen: 0, + }, { - name: "ForkBlockReached", + name: "Timeout", maxBlockNum: 100, maxTxNum: 10000, maxL1CommitGas: 50000000000, maxL1CommitCalldataSize: 1000000, maxRowConsumption: 1000000, + chunkTimeoutSec: 0, + expectedChunksLen: 1, + expectedBlocksInFirstChunk: 2, + }, + { + name: "MaxTxNumPerChunkIs0", + maxBlockNum: 10, + maxTxNum: 0, + maxL1CommitGas: 50000000000, + maxL1CommitCalldataSize: 1000000, + maxRowConsumption: 1000000, + chunkTimeoutSec: 1000000000000, + expectedChunksLen: 0, + }, + { + name: "MaxL1CommitGasPerChunkIs0", + maxBlockNum: 10, + maxTxNum: 10000, + maxL1CommitGas: 0, + maxL1CommitCalldataSize: 1000000, + maxRowConsumption: 1000000, + chunkTimeoutSec: 1000000000000, + expectedChunksLen: 0, + }, + { + name: "MaxL1CommitCalldataSizePerChunkIs0", + maxBlockNum: 10, + maxTxNum: 10000, + maxL1CommitGas: 50000000000, + maxL1CommitCalldataSize: 0, + maxRowConsumption: 1000000, + chunkTimeoutSec: 1000000000000, + expectedChunksLen: 0, + }, + { + name: "MaxRowConsumptionPerChunkIs0", + maxBlockNum: 100, + maxTxNum: 10000, + maxL1CommitGas: 50000000000, + maxL1CommitCalldataSize: 1000000, + maxRowConsumption: 0, + chunkTimeoutSec: 1000000000000, + expectedChunksLen: 0, + }, + { + name: "MaxBlockNumPerChunkIs1", + maxBlockNum: 1, + maxTxNum: 10000, + maxL1CommitGas: 50000000000, + maxL1CommitCalldataSize: 1000000, + maxRowConsumption: 1000000, + chunkTimeoutSec: 1000000000000, + expectedChunksLen: 1, + expectedBlocksInFirstChunk: 1, + }, + { + name: "MaxTxNumPerChunkIsFirstBlock", + maxBlockNum: 10, + maxTxNum: 2, + maxL1CommitGas: 50000000000, + maxL1CommitCalldataSize: 1000000, + maxRowConsumption: 1000000, + chunkTimeoutSec: 1000000000000, + expectedChunksLen: 1, + expectedBlocksInFirstChunk: 1, + }, + { + name: "MaxL1CommitGasPerChunkIsFirstBlock", + maxBlockNum: 10, + maxTxNum: 10000, + maxL1CommitGas: 62500, + maxL1CommitCalldataSize: 1000000, + maxRowConsumption: 1000000, + chunkTimeoutSec: 1000000000000, + expectedChunksLen: 1, + expectedBlocksInFirstChunk: 1, + }, + { + name: "MaxL1CommitCalldataSizePerChunkIsFirstBlock", + maxBlockNum: 10, + maxTxNum: 10000, + maxL1CommitGas: 50000000000, + maxL1CommitCalldataSize: 60, + maxRowConsumption: 1000000, + chunkTimeoutSec: 1000000000000, + expectedChunksLen: 1, + expectedBlocksInFirstChunk: 1, + }, + { + name: "MaxRowConsumptionPerChunkIs1", + maxBlockNum: 10, + maxTxNum: 10000, + maxL1CommitGas: 50000000000, + maxL1CommitCalldataSize: 1000000, + maxRowConsumption: 1, chunkTimeoutSec: 1000000000000, expectedChunksLen: 1, expectedBlocksInFirstChunk: 1, - forkBlock: big.NewInt(2), }, } @@ -545,7 +676,7 @@ func testChunkProposerCodecv2Limits(t *testing.T) { ChunkTimeoutSec: tt.chunkTimeoutSec, GasCostIncreaseMultiplier: 1.2, MaxUncompressedBatchBytesSize: math.MaxUint64, - }, ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), HomesteadBlock: tt.forkBlock}, db, nil) + }, ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64)}, db, nil) cp.TryProposeChunk() chunkOrm := orm.NewChunk(db) @@ -568,11 +699,11 @@ func testChunkProposerCodecv2Limits(t *testing.T) { } func testChunkProposerBlobSizeLimit(t *testing.T) { - compressionTests := []bool{false, true} // false for uncompressed, true for compressed - for _, compressed := range compressionTests { + codecVersions := []encoding.CodecVersion{encoding.CodecV0, encoding.CodecV1, encoding.CodecV2, encoding.CodecV3} + for _, codecVersion := range codecVersions { db := setupDB(t) - block := readBlockFromJSON(t, "../../../testdata/blockTrace_02.json") - for i := int64(0); i < 2000; i++ { + block := readBlockFromJSON(t, "../../../testdata/blockTrace_03.json") + for i := int64(0); i < 510; i++ { l2BlockOrm := orm.NewL2Block(db) block.Header.Number = big.NewInt(i + 1) err := l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block}) @@ -580,14 +711,18 @@ func testChunkProposerBlobSizeLimit(t *testing.T) { } var chainConfig *params.ChainConfig - if compressed { + if codecVersion == encoding.CodecV0 { // will never hit blob size limit + chainConfig = ¶ms.ChainConfig{} + } else if codecVersion == encoding.CodecV1 { + chainConfig = ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0)} + } else if codecVersion == encoding.CodecV2 { chainConfig = ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0)} } else { - chainConfig = ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0)} + chainConfig = ¶ms.ChainConfig{BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64)} } cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ - MaxBlockNumPerChunk: math.MaxUint64, + MaxBlockNumPerChunk: 255, MaxTxNumPerChunk: math.MaxUint64, MaxL1CommitGasPerChunk: math.MaxUint64, MaxL1CommitCalldataSizePerChunk: math.MaxUint64, @@ -597,7 +732,7 @@ func testChunkProposerBlobSizeLimit(t *testing.T) { MaxUncompressedBatchBytesSize: math.MaxUint64, }, chainConfig, db, nil) - for i := 0; i < 10; i++ { + for i := 0; i < 2; i++ { cp.TryProposeChunk() } @@ -605,14 +740,16 @@ func testChunkProposerBlobSizeLimit(t *testing.T) { chunks, err := chunkOrm.GetChunksGEIndex(context.Background(), 0, 0) assert.NoError(t, err) - var expectedNumChunks int + var expectedNumChunks int = 2 var numBlocksMultiplier uint64 - if compressed { - expectedNumChunks = 1 - numBlocksMultiplier = 2000 + if codecVersion == encoding.CodecV0 { + numBlocksMultiplier = 255 + } else if codecVersion == encoding.CodecV1 { + numBlocksMultiplier = 22 + } else if codecVersion == encoding.CodecV2 { + numBlocksMultiplier = 255 } else { - expectedNumChunks = 4 - numBlocksMultiplier = 551 + numBlocksMultiplier = 255 } assert.Len(t, chunks, expectedNumChunks) @@ -627,12 +764,15 @@ func testChunkProposerBlobSizeLimit(t *testing.T) { } } -func testChunkProposerIncludeCurieBlockInOneChunk(t *testing.T) { +func testChunkProposerRespectHardforks(t *testing.T) { db := setupDB(t) + defer database.CloseDB(db) + block := readBlockFromJSON(t, "../../../testdata/blockTrace_02.json") - for i := int64(0); i < 10; i++ { + for i := int64(1); i <= 20; i++ { l2BlockOrm := orm.NewL2Block(db) block.Header.Number = big.NewInt(i) + block.Header.Time = uint64(i) err := l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block}) assert.NoError(t, err) } @@ -646,9 +786,13 @@ func testChunkProposerIncludeCurieBlockInOneChunk(t *testing.T) { ChunkTimeoutSec: math.MaxUint64, GasCostIncreaseMultiplier: 1, MaxUncompressedBatchBytesSize: math.MaxUint64, - }, ¶ms.ChainConfig{BernoulliBlock: big.NewInt(1), CurieBlock: big.NewInt(2)}, db, nil) + }, ¶ms.ChainConfig{ + BernoulliBlock: big.NewInt(1), + CurieBlock: big.NewInt(2), + DarwinTime: func() *uint64 { t := uint64(4); return &t }(), + }, db, nil) - for i := 0; i < 2; i++ { + for i := 0; i < 5; i++ { cp.TryProposeChunk() } @@ -656,9 +800,9 @@ func testChunkProposerIncludeCurieBlockInOneChunk(t *testing.T) { chunks, err := chunkOrm.GetChunksGEIndex(context.Background(), 0, 0) assert.NoError(t, err) - assert.Len(t, chunks, 2) + assert.Len(t, chunks, 4) + expectedEndBlockNumbers := []uint64{1, 2, 3, 20} for i, chunk := range chunks { - assert.Equal(t, uint64(i+1), chunk.EndBlockNumber) + assert.Equal(t, expectedEndBlockNumbers[i], chunk.EndBlockNumber) } - database.CloseDB(db) } diff --git a/rollup/internal/controller/watcher/watcher_test.go b/rollup/internal/controller/watcher/watcher_test.go index 0047a8ca45..806e55a504 100644 --- a/rollup/internal/controller/watcher/watcher_test.go +++ b/rollup/internal/controller/watcher/watcher_test.go @@ -108,18 +108,22 @@ func TestFunction(t *testing.T) { t.Run("TestChunkProposerCodecv0Limits", testChunkProposerCodecv0Limits) t.Run("TestChunkProposerCodecv1Limits", testChunkProposerCodecv1Limits) t.Run("TestChunkProposerCodecv2Limits", testChunkProposerCodecv2Limits) + t.Run("TestChunkProposerCodecv3Limits", testChunkProposerCodecv3Limits) t.Run("TestChunkProposerBlobSizeLimit", testChunkProposerBlobSizeLimit) - t.Run("TestChunkProposerIncludeCurieBlockInOneChunk", testChunkProposerIncludeCurieBlockInOneChunk) + t.Run("TestChunkProposerRespectHardforks", testChunkProposerRespectHardforks) // Run batch proposer test cases. t.Run("TestBatchProposerCodecv0Limits", testBatchProposerCodecv0Limits) t.Run("TestBatchProposerCodecv1Limits", testBatchProposerCodecv1Limits) t.Run("TestBatchProposerCodecv2Limits", testBatchProposerCodecv2Limits) + t.Run("TestBatchProposerCodecv3Limits", testBatchProposerCodecv3Limits) t.Run("TestBatchCommitGasAndCalldataSizeCodecv0Estimation", testBatchCommitGasAndCalldataSizeCodecv0Estimation) t.Run("TestBatchCommitGasAndCalldataSizeCodecv1Estimation", testBatchCommitGasAndCalldataSizeCodecv1Estimation) t.Run("TestBatchCommitGasAndCalldataSizeCodecv2Estimation", testBatchCommitGasAndCalldataSizeCodecv2Estimation) + t.Run("TestBatchCommitGasAndCalldataSizeCodecv3Estimation", testBatchCommitGasAndCalldataSizeCodecv3Estimation) t.Run("TestBatchProposerBlobSizeLimit", testBatchProposerBlobSizeLimit) t.Run("TestBatchProposerMaxChunkNumPerBatchLimit", testBatchProposerMaxChunkNumPerBatchLimit) + t.Run("TestBatchProposerRespectHardforks", testBatchProposerRespectHardforks) } func readBlockFromJSON(t *testing.T, filename string) *encoding.Block { diff --git a/rollup/internal/utils/utils.go b/rollup/internal/utils/utils.go index 40d1aacf04..30a90eb6cb 100644 --- a/rollup/internal/utils/utils.go +++ b/rollup/internal/utils/utils.go @@ -9,6 +9,7 @@ import ( "github.com/scroll-tech/da-codec/encoding/codecv0" "github.com/scroll-tech/da-codec/encoding/codecv1" "github.com/scroll-tech/da-codec/encoding/codecv2" + "github.com/scroll-tech/da-codec/encoding/codecv3" "github.com/scroll-tech/go-ethereum/accounts/abi" "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/core/types" @@ -152,6 +153,22 @@ func CalculateChunkMetrics(chunk *encoding.Chunk, codecVersion encoding.CodecVer return nil, fmt.Errorf("failed to estimate codecv2 chunk L1 commit blob size: %w", err) } return metrics, nil + case encoding.CodecV3: + start := time.Now() + metrics.L1CommitGas = codecv3.EstimateChunkL1CommitGas(chunk) + metrics.EstimateGasTime = time.Since(start) + + start = time.Now() + metrics.L1CommitCalldataSize = codecv3.EstimateChunkL1CommitCalldataSize(chunk) + metrics.EstimateCalldataSizeTime = time.Since(start) + + start = time.Now() + metrics.L1CommitUncompressedBatchBytesSize, metrics.L1CommitBlobSize, err = codecv3.EstimateChunkL1CommitBatchSizeAndBlobSize(chunk) + metrics.EstimateBlobSizeTime = time.Since(start) + if err != nil { + return nil, fmt.Errorf("failed to estimate codecv3 chunk L1 commit blob size: %w", err) + } + return metrics, nil default: return nil, fmt.Errorf("unsupported codec version: %v", codecVersion) } @@ -232,6 +249,22 @@ func CalculateBatchMetrics(batch *encoding.Batch, codecVersion encoding.CodecVer return nil, fmt.Errorf("failed to estimate codecv2 batch L1 commit blob size: %w", err) } return metrics, nil + case encoding.CodecV3: + start := time.Now() + metrics.L1CommitGas = codecv3.EstimateBatchL1CommitGas(batch) + metrics.EstimateGasTime = time.Since(start) + + start = time.Now() + metrics.L1CommitCalldataSize = codecv3.EstimateBatchL1CommitCalldataSize(batch) + metrics.EstimateCalldataSizeTime = time.Since(start) + + start = time.Now() + metrics.L1CommitUncompressedBatchBytesSize, metrics.L1CommitBlobSize, err = codecv3.EstimateBatchL1CommitBatchSizeAndBlobSize(batch) + metrics.EstimateBlobSizeTime = time.Since(start) + if err != nil { + return nil, fmt.Errorf("failed to estimate codecv3 batch L1 commit blob size: %w", err) + } + return metrics, nil default: return nil, fmt.Errorf("unsupported codec version: %v", codecVersion) } @@ -270,6 +303,16 @@ func GetChunkHash(chunk *encoding.Chunk, totalL1MessagePoppedBefore uint64, code return common.Hash{}, fmt.Errorf("failed to get codecv2 DA chunk hash: %w", err) } return chunkHash, nil + case encoding.CodecV3: + daChunk, err := codecv3.NewDAChunk(chunk, totalL1MessagePoppedBefore) + if err != nil { + return common.Hash{}, fmt.Errorf("failed to create codecv3 DA chunk: %w", err) + } + chunkHash, err := daChunk.Hash() + if err != nil { + return common.Hash{}, fmt.Errorf("failed to get codecv3 DA chunk hash: %w", err) + } + return chunkHash, nil default: return common.Hash{}, fmt.Errorf("unsupported codec version: %v", codecVersion) } @@ -403,6 +446,44 @@ func GetBatchMetadata(batch *encoding.Batch, codecVersion encoding.CodecVersion) return nil, fmt.Errorf("failed to get codecv2 end DA chunk hash: %w", err) } return batchMeta, nil + case encoding.CodecV3: + daBatch, err := codecv3.NewDABatch(batch) + if err != nil { + return nil, fmt.Errorf("failed to create codecv3 DA batch: %w", err) + } + + blobDataProof, err := daBatch.BlobDataProofForPointEvaluation() + if err != nil { + return nil, fmt.Errorf("failed to get codecv3 blob data proof for point evaluation: %w", err) + } + + batchMeta := &BatchMetadata{ + BatchHash: daBatch.Hash(), + BatchDataHash: daBatch.DataHash, + BatchBlobDataProof: blobDataProof, + BatchBytes: daBatch.Encode(), + } + + startDAChunk, err := codecv3.NewDAChunk(batch.Chunks[0], batch.TotalL1MessagePoppedBefore) + if err != nil { + return nil, fmt.Errorf("failed to create codecv3 start DA chunk: %w", err) + } + + batchMeta.StartChunkHash, err = startDAChunk.Hash() + if err != nil { + return nil, fmt.Errorf("failed to get codecv3 start DA chunk hash: %w", err) + } + + endDAChunk, err := codecv3.NewDAChunk(batch.Chunks[numChunks-1], totalL1MessagePoppedBeforeEndDAChunk) + if err != nil { + return nil, fmt.Errorf("failed to create codecv3 end DA chunk: %w", err) + } + + batchMeta.EndChunkHash, err = endDAChunk.Hash() + if err != nil { + return nil, fmt.Errorf("failed to get codecv3 end DA chunk hash: %w", err) + } + return batchMeta, nil default: return nil, fmt.Errorf("unsupported codec version: %v", codecVersion) }