Skip to content

Commit

Permalink
return error when UnmarshalBinary fails
Browse files Browse the repository at this point in the history
  • Loading branch information
jinmel committed Aug 13, 2024
1 parent e1c790a commit fd07061
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 5 additions & 1 deletion op-node/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,11 @@ func (n *OpNode) PublishL2Payload(ctx context.Context, envelope *eth.ExecutionPa
}

func (n *OpNode) PublishL2Attributes(ctx context.Context, attrs *derive.AttributesWithParent) error {
builderAttrs := attrs.ToBuilderPayloadAttributes()
builderAttrs, err := attrs.ToBuilderPayloadAttributes()
if err != nil {
n.log.Warn("failed to convert attributes to builder attributes", "err", err)
return err
}
jsonBytes, err := json.Marshal(builderAttrs)
if err != nil {
n.log.Warn("failed to marshal payload attributes", "err", err)
Expand Down
9 changes: 6 additions & 3 deletions op-node/rollup/derive/attributes_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ type AttributesWithParent struct {
IsLastInSpan bool
}

func (a *AttributesWithParent) ToBuilderPayloadAttributes() *BuilderPayloadAttributes {
func (a *AttributesWithParent) ToBuilderPayloadAttributes() (*BuilderPayloadAttributes, error) {
transactions := make([]*types.Transaction, len(a.Attributes.Transactions))
for i, txBytes := range a.Attributes.Transactions {
var ttx types.Transaction
ttx.UnmarshalBinary(txBytes)
err := ttx.UnmarshalBinary(txBytes)
if err != nil {
return nil, err
}
transactions[i] = &ttx
}

Expand All @@ -54,7 +57,7 @@ func (a *AttributesWithParent) ToBuilderPayloadAttributes() *BuilderPayloadAttri
ParentBeaconBlockRoot: a.Attributes.ParentBeaconBlockRoot,
Transactions: transactions,
GasLimit: uint64(*a.Attributes.GasLimit),
}
}, nil
}

type BuilderPayloadAttributes struct {
Expand Down
5 changes: 4 additions & 1 deletion op-service/events/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ func (s *Server) StreamEvents(w http.ResponseWriter, r *http.Request) {
}

func (s *Server) sendPayloadAttributes(ctx context.Context, w http.ResponseWriter, flusher http.Flusher, attrs *derive.AttributesWithParent) error {
builderAttrs := attrs.ToBuilderPayloadAttributes()
builderAttrs, err := attrs.ToBuilderPayloadAttributes()
if err != nil {
return err
}
jsonBytes, err := json.Marshal(builderAttrs)
if err != nil {
return err
Expand Down

0 comments on commit fd07061

Please sign in to comment.