Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
9aa6fd4f
Commit
9aa6fd4f
authored
Feb 14, 2023
by
Sebastian Stammler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node: Improve Frame.UnmarshalBinary implementation
parent
225ec322
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
19 deletions
+22
-19
frame.go
op-node/rollup/derive/frame.go
+22
-19
No files found.
op-node/rollup/derive/frame.go
View file @
9aa6fd4f
...
...
@@ -73,19 +73,16 @@ type ByteReader interface {
// If r unexpectedly stops returning data half-way, returns io.ErrUnexpectedEOF.
func
(
f
*
Frame
)
UnmarshalBinary
(
r
ByteReader
)
error
{
if
_
,
err
:=
io
.
ReadFull
(
r
,
f
.
ID
[
:
]);
err
!=
nil
{
return
fmt
.
Errorf
(
"error reading ID: %w"
,
err
)
// Forward io.EOF here ok, would mean not a single byte from r.
return
fmt
.
Errorf
(
"reading channel_id: %w"
,
err
)
}
if
err
:=
binary
.
Read
(
r
,
binary
.
BigEndian
,
&
f
.
FrameNumber
);
err
==
io
.
EOF
{
return
fmt
.
Errorf
(
"frame_number missing: %w"
,
io
.
ErrUnexpectedEOF
)
}
else
if
err
!=
nil
{
return
fmt
.
Errorf
(
"reading frame_number: %w"
,
err
)
if
err
:=
binary
.
Read
(
r
,
binary
.
BigEndian
,
&
f
.
FrameNumber
);
err
!=
nil
{
return
fmt
.
Errorf
(
"reading frame_number: %w"
,
eofAsUnexpectedMissing
(
err
))
}
var
frameLength
uint32
if
err
:=
binary
.
Read
(
r
,
binary
.
BigEndian
,
&
frameLength
);
err
==
io
.
EOF
{
return
fmt
.
Errorf
(
"frame_data_length missing: %w"
,
io
.
ErrUnexpectedEOF
)
}
else
if
err
!=
nil
{
return
fmt
.
Errorf
(
"reading frame_data_length: %w"
,
err
)
if
err
:=
binary
.
Read
(
r
,
binary
.
BigEndian
,
&
frameLength
);
err
!=
nil
{
return
fmt
.
Errorf
(
"reading frame_data_length: %w"
,
eofAsUnexpectedMissing
(
err
))
}
// Cap frame length to MaxFrameLen (currently 1MB)
...
...
@@ -93,25 +90,31 @@ func (f *Frame) UnmarshalBinary(r ByteReader) error {
return
fmt
.
Errorf
(
"frame_data_length is too large: %d"
,
frameLength
)
}
f
.
Data
=
make
([]
byte
,
int
(
frameLength
))
if
_
,
err
:=
io
.
ReadFull
(
r
,
f
.
Data
);
err
==
io
.
EOF
{
return
fmt
.
Errorf
(
"frame_data missing: %w"
,
io
.
ErrUnexpectedEOF
)
}
else
if
err
!=
nil
{
return
fmt
.
Errorf
(
"reading frame_data: %w"
,
err
)
if
_
,
err
:=
io
.
ReadFull
(
r
,
f
.
Data
);
err
!=
nil
{
return
fmt
.
Errorf
(
"reading frame_data: %w"
,
eofAsUnexpectedMissing
(
err
))
}
if
isLastByte
,
err
:=
r
.
ReadByte
();
err
==
io
.
EOF
{
return
fmt
.
Errorf
(
"final byte (is_last) missing: %w"
,
io
.
ErrUnexpectedEOF
)
}
else
if
err
!=
nil
{
return
fmt
.
Errorf
(
"reading final byte (is_last): %w"
,
err
)
if
isLastByte
,
err
:=
r
.
ReadByte
();
err
!=
nil
{
return
fmt
.
Errorf
(
"reading final byte (is_last): %w"
,
eofAsUnexpectedMissing
(
err
))
}
else
if
isLastByte
==
0
{
f
.
IsLast
=
false
return
err
}
else
if
isLastByte
==
1
{
f
.
IsLast
=
true
return
err
}
else
{
return
errors
.
New
(
"invalid byte as is_last"
)
}
return
nil
}
// eofAsUnexpectedMissing converts an io.EOF in the error chain of err into an
// io.ErrUnexpectedEOF. It should be used to convert intermediate io.EOF errors
// in unmarshaling code to achieve idiomatic error behavior.
// Other errors are passed through unchanged.
func
eofAsUnexpectedMissing
(
err
error
)
error
{
if
errors
.
Is
(
err
,
io
.
EOF
)
{
return
fmt
.
Errorf
(
"fully missing: %w"
,
io
.
ErrUnexpectedEOF
)
}
return
err
}
// Frames on stored in L1 transactions with the following format:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment