@@ -842,7 +842,7 @@ func (r *Rollup) finalize() error {
842842 if err != nil {
843843 return fmt .Errorf ("pack finalizeBatch error:%v" , err )
844844 }
845- tip , feecap , _ , err := r .GetGasTipAndCap ()
845+ tip , feecap , _ , _ , err := r .GetGasTipAndCap ()
846846 if err != nil {
847847 log .Error ("get gas tip and cap error" , "business" , "finalize" )
848848 return fmt .Errorf ("get gas tip and cap error:%v" , err )
@@ -1068,7 +1068,7 @@ func (r *Rollup) rollup() error {
10681068 }
10691069
10701070 // tip and cap
1071- tip , gasFeeCap , blobFee , err := r .GetGasTipAndCap ()
1071+ tip , gasFeeCap , blobFee , head , err := r .GetGasTipAndCap ()
10721072 if err != nil {
10731073 return fmt .Errorf ("get gas tip and cap error:%v" , err )
10741074 }
@@ -1105,7 +1105,7 @@ func (r *Rollup) rollup() error {
11051105 }
11061106
11071107 // Create and sign transaction
1108- tx , err := r .createRollupTx (batch , nonce , gas , tip , gasFeeCap , blobFee , calldata )
1108+ tx , err := r .createRollupTx (batch , nonce , gas , tip , gasFeeCap , blobFee , calldata , head )
11091109 if err != nil {
11101110 return fmt .Errorf ("failed to create rollup tx: %w" , err )
11111111 }
@@ -1119,14 +1119,14 @@ func (r *Rollup) rollup() error {
11191119 r .logTxInfo (signedTx , batchIndex )
11201120
11211121 // Send transaction
1122- if err : = r .SendTx (signedTx ); err != nil {
1122+ if err = r .SendTx (signedTx ); err != nil {
11231123 return fmt .Errorf ("failed to send tx: %w" , err )
11241124 }
11251125
11261126 // Update pending state
11271127 r .pendingTxs .SetPindex (batchIndex )
11281128 r .pendingTxs .SetNonce (tx .Nonce ())
1129- if err : = r .pendingTxs .Add (signedTx ); err != nil {
1129+ if err = r .pendingTxs .Add (signedTx ); err != nil {
11301130 log .Error ("Failed to track transaction" , "error" , err )
11311131 }
11321132
@@ -1146,17 +1146,36 @@ func (r *Rollup) getNextNonce() uint64 {
11461146 return nonce
11471147}
11481148
1149- func (r * Rollup ) createRollupTx (batch * eth.RPCRollupBatch , nonce , gas uint64 , tip , gasFeeCap , blobFee * big.Int , calldata []byte ) (* ethtypes.Transaction , error ) {
1149+ func (r * Rollup ) createRollupTx (batch * eth.RPCRollupBatch , nonce , gas uint64 , tip , gasFeeCap , blobFee * big.Int , calldata []byte , head * ethtypes. Header ) (* ethtypes.Transaction , error ) {
11501150 if len (batch .Sidecar .Blobs ) > 0 {
1151- return r .createBlobTx (batch , nonce , gas , tip , gasFeeCap , blobFee , calldata )
1151+ return r .createBlobTx (batch , nonce , gas , tip , gasFeeCap , blobFee , calldata , head )
11521152 }
11531153 return r .createDynamicFeeTx (nonce , gas , tip , gasFeeCap , calldata )
11541154}
11551155
1156- func (r * Rollup ) createBlobTx (batch * eth.RPCRollupBatch , nonce , gas uint64 , tip , gasFeeCap , blobFee * big.Int , calldata []byte ) (* ethtypes.Transaction , error ) {
1157- versionedHashes := make ([]common.Hash , 0 , len (batch .Sidecar .Commitments ))
1158- for _ , commit := range batch .Sidecar .Commitments {
1159- versionedHashes = append (versionedHashes , kZGToVersionedHash (commit ))
1156+ func (r * Rollup ) createBlobTx (batch * eth.RPCRollupBatch , nonce , gas uint64 , tip , gasFeeCap , blobFee * big.Int , calldata []byte , head * ethtypes.Header ) (* ethtypes.Transaction , error ) {
1157+ versionedHashes := types .BlobHashes (batch .Sidecar .Blobs , batch .Sidecar .Commitments )
1158+ sidecar := & ethtypes.BlobTxSidecar {
1159+ Blobs : batch .Sidecar .Blobs ,
1160+ Commitments : batch .Sidecar .Commitments ,
1161+ }
1162+ switch types .DetermineBlobVersion (head , r .chainId .Uint64 ()) {
1163+ case ethtypes .BlobSidecarVersion0 :
1164+ sidecar .Version = ethtypes .BlobSidecarVersion0
1165+ proof , err := types .MakeBlobProof (sidecar .Blobs , sidecar .Commitments )
1166+ if err != nil {
1167+ return nil , fmt .Errorf ("gen blob proof failed %v" , err )
1168+ }
1169+ sidecar .Proofs = proof
1170+ case ethtypes .BlobSidecarVersion1 :
1171+ sidecar .Version = ethtypes .BlobSidecarVersion1
1172+ proof , err := types .MakeCellProof (sidecar .Blobs )
1173+ if err != nil {
1174+ return nil , fmt .Errorf ("gen cell proof failed %v" , err )
1175+ }
1176+ sidecar .Proofs = proof
1177+ default :
1178+ return nil , fmt .Errorf ("unsupported blob version" )
11601179 }
11611180
11621181 return ethtypes .NewTx (& ethtypes.BlobTx {
@@ -1169,11 +1188,7 @@ func (r *Rollup) createBlobTx(batch *eth.RPCRollupBatch, nonce, gas uint64, tip,
11691188 Data : calldata ,
11701189 BlobFeeCap : uint256 .MustFromBig (blobFee ),
11711190 BlobHashes : versionedHashes ,
1172- Sidecar : & ethtypes.BlobTxSidecar {
1173- Blobs : batch .Sidecar .Blobs ,
1174- Commitments : batch .Sidecar .Commitments ,
1175- Proofs : batch .Sidecar .Proofs ,
1176- },
1191+ Sidecar : sidecar ,
11771192 }), nil
11781193}
11791194
@@ -1242,21 +1257,21 @@ func (r *Rollup) buildSignatureInput(batch *eth.RPCRollupBatch) (*bindings.IRoll
12421257 return & sigData , nil
12431258}
12441259
1245- func (r * Rollup ) GetGasTipAndCap () (* big.Int , * big.Int , * big.Int , error ) {
1260+ func (r * Rollup ) GetGasTipAndCap () (* big.Int , * big.Int , * big.Int , * ethtypes. Header , error ) {
12461261 head , err := r .L1Client .HeaderByNumber (context .Background (), nil )
12471262 if err != nil {
1248- return nil , nil , nil , err
1263+ return nil , nil , nil , nil , err
12491264 }
12501265 if head .BaseFee != nil {
12511266 log .Info ("market fee info" , "feecap" , head .BaseFee )
12521267 if r .cfg .MaxBaseFee > 0 && head .BaseFee .Cmp (big .NewInt (int64 (r .cfg .MaxBaseFee ))) > 0 {
1253- return nil , nil , nil , fmt .Errorf ("base fee is too high, base fee %v exceeds max %v" , head .BaseFee , r .cfg .MaxBaseFee )
1268+ return nil , nil , nil , nil , fmt .Errorf ("base fee is too high, base fee %v exceeds max %v" , head .BaseFee , r .cfg .MaxBaseFee )
12541269 }
12551270 }
12561271
12571272 tip , err := r .L1Client .SuggestGasTipCap (context .Background ())
12581273 if err != nil {
1259- return nil , nil , nil , err
1274+ return nil , nil , nil , nil , err
12601275 }
12611276 log .Info ("market fee info" , "tip" , tip )
12621277
@@ -1265,7 +1280,7 @@ func (r *Rollup) GetGasTipAndCap() (*big.Int, *big.Int, *big.Int, error) {
12651280 tip = new (big.Int ).Div (tip , big .NewInt (100 ))
12661281 }
12671282 if r .cfg .MaxTip > 0 && tip .Cmp (big .NewInt (int64 (r .cfg .MaxTip ))) > 0 {
1268- return nil , nil , nil , fmt .Errorf ("tip is too high, tip %v exceeds max %v" , tip , r .cfg .MaxTip )
1283+ return nil , nil , nil , nil , fmt .Errorf ("tip is too high, tip %v exceeds max %v" , tip , r .cfg .MaxTip )
12691284 }
12701285
12711286 var gasFeeCap * big.Int
@@ -1282,7 +1297,7 @@ func (r *Rollup) GetGasTipAndCap() (*big.Int, *big.Int, *big.Int, error) {
12821297 var blobFee * big.Int
12831298 if head .ExcessBlobGas != nil {
12841299 log .Info ("market blob fee info" , "excess blob gas" , * head .ExcessBlobGas )
1285- blobConfig , exist := r .ChainConfigMap [r .chainId .Uint64 ()]
1300+ blobConfig , exist := types .ChainConfigMap [r .chainId .Uint64 ()]
12861301 if ! exist {
12871302 blobConfig = types .DefaultBlobConfig
12881303 }
@@ -1298,7 +1313,7 @@ func (r *Rollup) GetGasTipAndCap() (*big.Int, *big.Int, *big.Int, error) {
12981313 "blobfee" , blobFee ,
12991314 )
13001315
1301- return tip , gasFeeCap , blobFee , nil
1316+ return tip , gasFeeCap , blobFee , head , nil
13021317}
13031318
13041319// PreCheck is run before the submitter to check whether the submitter can be started
@@ -1578,7 +1593,7 @@ func (r *Rollup) ReSubmitTx(resend bool, tx *ethtypes.Transaction) (*ethtypes.Tr
15781593 "nonce" , tx .Nonce (),
15791594 )
15801595
1581- tip , gasFeeCap , blobFeeCap , err := r .GetGasTipAndCap ()
1596+ tip , gasFeeCap , blobFeeCap , head , err := r .GetGasTipAndCap ()
15821597 if err != nil {
15831598 return nil , fmt .Errorf ("get gas tip and cap error:%w" , err )
15841599 }
@@ -1606,11 +1621,6 @@ func (r *Rollup) ReSubmitTx(resend bool, tx *ethtypes.Transaction) (*ethtypes.Tr
16061621 if r .cfg .MinTip > 0 && tip .Cmp (big .NewInt (int64 (r .cfg .MinTip ))) < 0 {
16071622 log .Info ("replace tip is too low, update tip to min tip " , "tip" , tip , "min_tip" , r .cfg .MinTip )
16081623 tip = big .NewInt (int64 (r .cfg .MinTip ))
1609- // recalc feecap
1610- head , err := r .L1Client .HeaderByNumber (context .Background (), nil )
1611- if err != nil {
1612- return nil , fmt .Errorf ("get l1 head error:%w" , err )
1613- }
16141624 var recalculatedFeecap * big.Int
16151625 if head .BaseFee != nil {
16161626 recalculatedFeecap = new (big.Int ).Add (
@@ -1640,7 +1650,14 @@ func (r *Rollup) ReSubmitTx(resend bool, tx *ethtypes.Transaction) (*ethtypes.Tr
16401650 Data : tx .Data (),
16411651 })
16421652 case ethtypes .BlobTxType :
1643-
1653+ sidecar := tx .BlobTxSidecar ()
1654+ version := types .DetermineBlobVersion (head , r .chainId .Uint64 ())
1655+ if sidecar .Version == ethtypes .BlobSidecarVersion0 && version == ethtypes .BlobSidecarVersion1 {
1656+ err = types .BlobSidecarVersionToV1 (sidecar )
1657+ if err != nil {
1658+ return nil , err
1659+ }
1660+ }
16441661 newTx = ethtypes .NewTx (& ethtypes.BlobTx {
16451662 ChainID : uint256 .MustFromBig (tx .ChainId ()),
16461663 Nonce : tx .Nonce (),
@@ -1652,7 +1669,7 @@ func (r *Rollup) ReSubmitTx(resend bool, tx *ethtypes.Transaction) (*ethtypes.Tr
16521669 Data : tx .Data (),
16531670 BlobFeeCap : uint256 .MustFromBig (blobFeeCap ),
16541671 BlobHashes : tx .BlobHashes (),
1655- Sidecar : tx . BlobTxSidecar () ,
1672+ Sidecar : sidecar ,
16561673 })
16571674
16581675 default :
@@ -1818,7 +1835,7 @@ func (r *Rollup) CancelTx(tx *ethtypes.Transaction) (*ethtypes.Transaction, erro
18181835 "nonce" , tx .Nonce (),
18191836 )
18201837
1821- tip , gasFeeCap , blobFeeCap , err := r .GetGasTipAndCap ()
1838+ tip , gasFeeCap , blobFeeCap , _ , err := r .GetGasTipAndCap ()
18221839 if err != nil {
18231840 return nil , fmt .Errorf ("get gas tip and cap error:%w" , err )
18241841 }
0 commit comments