Skip to content

Commit

Permalink
support querying optimistic block using the optimistic string
Browse files Browse the repository at this point in the history
  • Loading branch information
bharath-123 committed Nov 21, 2024
1 parent 32ac201 commit 57dfe08
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions grpc/execution/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (s *ExecutionServiceServerV1) ExecuteBlock(ctx context.Context, req *astria
// Build a payload to add to the chain
payloadAttributes := &miner.BuildPayloadArgs{
Parent: prevHeadHash,
Timestamp: uint64(req.GetTimestamp().AsTime().UnixNano()),
Timestamp: uint64(req.GetTimestamp().GetSeconds()),
Random: common.Hash{},
FeeRecipient: s.NextFeeRecipient(),
OverrideTransactions: types.Transactions{},
Expand All @@ -190,7 +190,7 @@ func (s *ExecutionServiceServerV1) ExecuteBlock(ctx context.Context, req *astria
payload, err := s.Eth().Miner().BuildPayload(payloadAttributes)
if err != nil {
log.Error("failed to build payload", "err", err)
return nil, status.Error(codes.InvalidArgument, "Could not build block with provided txs")
return nil, status.Errorf(codes.InvalidArgument, "Could not build block with provided txs: %v", err)
}

// call blockchain.InsertChain to actually execute and write the blocks to
Expand Down
4 changes: 2 additions & 2 deletions grpc/optimistic/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (o *OptimisticServiceV1Alpha1) ExecuteOptimisticBlockStream(stream optimist
// execute the optimistic block and wait for the mempool clearing event
optimisticBlock, err := o.ExecuteOptimisticBlock(stream.Context(), baseBlock)
if err != nil {
return status.Error(codes.Internal, "failed to execute optimistic block")
return status.Errorf(codes.Internal, "failed to execute optimistic block: %v", err)
}
optimisticBlockHash := common.BytesToHash(optimisticBlock.Hash)

Expand Down Expand Up @@ -203,7 +203,7 @@ func (o *OptimisticServiceV1Alpha1) ExecuteOptimisticBlock(ctx context.Context,
payload, err := o.Eth().Miner().BuildPayload(payloadAttributes)
if err != nil {
log.Error("failed to build payload", "err", err)
return nil, status.Error(codes.InvalidArgument, "Could not build block with provided txs")
return nil, status.Errorf(codes.InvalidArgument, "Could not build block with provided txs: %v", err)
}

block, err := engine.ExecutableDataToBlock(*payload.Resolve().ExecutionPayload, nil, nil)
Expand Down
9 changes: 9 additions & 0 deletions rpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
case "safe":
*bn = SafeBlockNumber
return nil
case "optimistic":
*bn = OptimisticBlockNumber
return nil
}

blckNum, err := hexutil.DecodeUint64(input)
Expand Down Expand Up @@ -136,6 +139,8 @@ func (bn BlockNumber) String() string {
return "finalized"
case SafeBlockNumber:
return "safe"
case OptimisticBlockNumber:
return "optimistic"
default:
if bn < 0 {
return fmt.Sprintf("<invalid %d>", bn)
Expand Down Expand Up @@ -189,6 +194,10 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error {
bn := SafeBlockNumber
bnh.BlockNumber = &bn
return nil
case "optimistic":
bn := OptimisticBlockNumber
bnh.BlockNumber = &bn
return nil
default:
if len(input) == 66 {
hash := common.Hash{}
Expand Down

0 comments on commit 57dfe08

Please sign in to comment.