11package optimistic
22
33import (
4- optimisticGrpc "buf.build/gen/go/astria/execution-apis/grpc/go/astria/bundle /v1alpha1/bundlev1alpha1grpc "
5- optimsticPb "buf.build/gen/go/astria/execution-apis/protocolbuffers/go/astria/bundle /v1alpha1"
4+ optimisticGrpc "buf.build/gen/go/astria/execution-apis/grpc/go/astria/auction /v1alpha1/auctionv1alpha1grpc "
5+ optimsticPb "buf.build/gen/go/astria/execution-apis/protocolbuffers/go/astria/auction /v1alpha1"
66 astriaPb "buf.build/gen/go/astria/execution-apis/protocolbuffers/go/astria/execution/v1"
77 "context"
88 "errors"
@@ -28,7 +28,7 @@ import (
2828
2929type OptimisticServiceV1Alpha1 struct {
3030 optimisticGrpc.UnimplementedOptimisticExecutionServiceServer
31- optimisticGrpc.UnimplementedBundleServiceServer
31+ optimisticGrpc.UnimplementedAuctionServiceServer
3232
3333 sharedServiceContainer * shared.SharedServiceContainer
3434
@@ -38,6 +38,8 @@ type OptimisticServiceV1Alpha1 struct {
3838var (
3939 executeOptimisticBlockRequestCount = metrics .GetOrRegisterCounter ("astria/optimistic/execute_optimistic_block_requests" , nil )
4040 executeOptimisticBlockSuccessCount = metrics .GetOrRegisterCounter ("astria/optimistic/execute_optimistic_block_success" , nil )
41+ optimisticBlockHeight = metrics .GetOrRegisterGauge ("astria/execution/optimistic_block_height" , nil )
42+ txsStreamedCount = metrics .GetOrRegisterCounter ("astria/optimistic/txs_streamed" , nil )
4143
4244 executionOptimisticBlockTimer = metrics .GetOrRegisterTimer ("astria/optimistic/execute_optimistic_block_time" , nil )
4345)
@@ -52,8 +54,8 @@ func NewOptimisticServiceV1Alpha(sharedServiceContainer *shared.SharedServiceCon
5254 return optimisticService
5355}
5456
55- func (o * OptimisticServiceV1Alpha1 ) GetBundleStream (_ * optimsticPb.GetBundleStreamRequest , stream optimisticGrpc.BundleService_GetBundleStreamServer ) error {
56- log .Debug ("GetBundleStream called" )
57+ func (o * OptimisticServiceV1Alpha1 ) GetBidStream (_ * optimsticPb.GetBidStreamRequest , stream optimisticGrpc.AuctionService_GetBidStreamServer ) error {
58+ log .Debug ("GetBidStream called" )
5759
5860 pendingTxEventCh := make (chan core.NewTxsEvent )
5961 pendingTxEvent := o .Eth ().TxPool ().SubscribeTransactions (pendingTxEventCh , false )
@@ -67,7 +69,7 @@ func (o *OptimisticServiceV1Alpha1) GetBundleStream(_ *optimsticPb.GetBundleStre
6769 optimisticBlock := o .Eth ().BlockChain ().CurrentOptimisticBlock ()
6870
6971 for _ , pendingTx := range pendingTxs .Txs {
70- bundle := optimsticPb.Bundle {}
72+ bid := optimsticPb.Bid {}
7173
7274 totalCost := big .NewInt (0 )
7375 effectiveTip := cmath .BigMin (pendingTx .GasTipCap (), new (big.Int ).Sub (pendingTx .GasFeeCap (), optimisticBlock .BaseFee ))
@@ -80,15 +82,16 @@ func (o *OptimisticServiceV1Alpha1) GetBundleStream(_ *optimsticPb.GetBundleStre
8082 }
8183 marshalledTxs = append (marshalledTxs , marshalledTx )
8284
83- bundle .Fee = totalCost .Uint64 ()
84- bundle .Transactions = marshalledTxs
85- bundle . BaseSequencerBlockHash = * o .currentOptimisticSequencerBlock .Load ()
86- bundle . PrevRollupBlockHash = optimisticBlock .Hash ().Bytes ()
85+ bid .Fee = totalCost .Uint64 ()
86+ bid .Transactions = marshalledTxs
87+ bid . SequencerParentBlockHash = * o .currentOptimisticSequencerBlock .Load ()
88+ bid . RollupParentBlockHash = optimisticBlock .Hash ().Bytes ()
8789
88- err = stream .Send (& optimsticPb.GetBundleStreamResponse {Bundle : & bundle })
90+ txsStreamedCount .Inc (1 )
91+ err = stream .Send (& optimsticPb.GetBidStreamResponse {Bid : & bid })
8992 if err != nil {
90- log .Error ("error sending bundle over stream" , "err" , err )
91- return status .Error (codes .Internal , shared .WrapError (err , "error sending bundle over stream" ).Error ())
93+ log .Error ("error sending bid over stream" , "err" , err )
94+ return status .Error (codes .Internal , shared .WrapError (err , "error sending bid over stream" ).Error ())
9295 }
9396 }
9497
@@ -124,6 +127,8 @@ func (o *OptimisticServiceV1Alpha1) ExecuteOptimisticBlockStream(stream optimist
124127 return err
125128 }
126129
130+ executeOptimisticBlockRequestCount .Inc (1 )
131+
127132 baseBlock := msg .GetBaseBlock ()
128133
129134 // execute the optimistic block and wait for the mempool clearing event
@@ -140,6 +145,7 @@ func (o *OptimisticServiceV1Alpha1) ExecuteOptimisticBlockStream(stream optimist
140145 return status .Error (codes .Internal , "failed to clear mempool after optimistic block execution" )
141146 }
142147 o .currentOptimisticSequencerBlock .Store (& baseBlock .SequencerBlockHash )
148+ executeOptimisticBlockSuccessCount .Inc (1 )
143149 err = stream .Send (& optimsticPb.ExecuteOptimisticBlockStreamResponse {
144150 Block : optimisticBlock ,
145151 BaseSequencerBlockHash : baseBlock .SequencerBlockHash ,
@@ -164,7 +170,10 @@ func (o *OptimisticServiceV1Alpha1) ExecuteOptimisticBlockStream(stream optimist
164170func (o * OptimisticServiceV1Alpha1 ) ExecuteOptimisticBlock (ctx context.Context , req * optimsticPb.BaseBlock ) (* astriaPb.Block , error ) {
165171 // we need to execute the optimistic block
166172 log .Debug ("ExecuteOptimisticBlock called" , "timestamp" , req .Timestamp , "sequencer_block_hash" , req .SequencerBlockHash )
167- executeOptimisticBlockRequestCount .Inc (1 )
173+
174+ // Deliberately called after lock, to more directly measure the time spent executing
175+ executionStart := time .Now ()
176+ defer executionOptimisticBlockTimer .UpdateSince (executionStart )
168177
169178 if err := validateStaticExecuteOptimisticBlockRequest (req ); err != nil {
170179 log .Error ("ExecuteOptimisticBlock called with invalid BaseBlock" , "err" , err )
@@ -175,10 +184,6 @@ func (o *OptimisticServiceV1Alpha1) ExecuteOptimisticBlock(ctx context.Context,
175184 return nil , status .Error (codes .PermissionDenied , "Cannot execute block until GetGenesisInfo && GetCommitmentState methods are called" )
176185 }
177186
178- // Deliberately called after lock, to more directly measure the time spent executing
179- executionStart := time .Now ()
180- defer executionOptimisticBlockTimer .UpdateSince (executionStart )
181-
182187 softBlock := o .Bc ().CurrentSafeBlock ()
183188
184189 nextFeeRecipient := o .NextFeeRecipient ()
@@ -234,8 +239,9 @@ func (o *OptimisticServiceV1Alpha1) ExecuteOptimisticBlock(ctx context.Context,
234239 },
235240 }
236241
242+ optimisticBlockHeight .Update (int64 (block .NumberU64 ()))
243+
237244 log .Info ("ExecuteOptimisticBlock completed" , "block_num" , res .Number , "timestamp" , res .Timestamp )
238- executeOptimisticBlockSuccessCount .Inc (1 )
239245
240246 return res , nil
241247}
0 commit comments