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
d44c9f96
Commit
d44c9f96
authored
Apr 10, 2023
by
Nickqiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node: L1BlockInfo MarshalBinary&UnmarshalBinary migrated to writer&reader based API
parent
cbb0bb5d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
51 deletions
+95
-51
l1_block_info.go
op-node/rollup/derive/l1_block_info.go
+95
-51
No files found.
op-node/rollup/derive/l1_block_info.go
View file @
d44c9f96
...
@@ -45,68 +45,112 @@ type L1BlockInfo struct {
...
@@ -45,68 +45,112 @@ type L1BlockInfo struct {
L1FeeScalar
eth
.
Bytes32
L1FeeScalar
eth
.
Bytes32
}
}
//+---------+--------------------------+
//| Bytes | Field |
//+---------+--------------------------+
//| 4 | Function signature |
//| 24 | Padding for Number |
//| 8 | Number |
//| 24 | Padding for Time |
//| 8 | Time |
//| 32 | BaseFee |
//| 32 | BlockHash |
//| 24 | Padding for SequenceNumber|
//| 8 | SequenceNumber |
//| 12 | Padding for BatcherAddr |
//| 20 | BatcherAddr |
//| 32 | L1FeeOverhead |
//| 32 | L1FeeScalar |
//+---------+--------------------------+
func
(
info
*
L1BlockInfo
)
MarshalBinary
()
([]
byte
,
error
)
{
func
(
info
*
L1BlockInfo
)
MarshalBinary
()
([]
byte
,
error
)
{
data
:=
make
([]
byte
,
L1InfoLen
)
writer
:=
bytes
.
NewBuffer
(
make
([]
byte
,
0
,
L1InfoLen
)
)
offset
:=
0
writer
.
Write
(
L1InfoFuncBytes4
)
copy
(
data
[
offset
:
4
],
L1InfoFuncBytes4
)
offset
+=
4
var
padding
[
24
]
byte
binary
.
BigEndian
.
PutUint64
(
data
[
offset
+
24
:
offset
+
32
],
info
.
Number
)
writer
.
Write
(
padding
[
:
]
)
offset
+=
32
binary
.
Write
(
writer
,
binary
.
BigEndian
,
info
.
Number
)
binary
.
BigEndian
.
PutUint64
(
data
[
offset
+
24
:
offset
+
32
],
info
.
Time
)
writer
.
Write
(
padding
[
:
]
)
offset
+=
32
binary
.
Write
(
writer
,
binary
.
BigEndian
,
info
.
Time
)
// Ensure that the baseFee is not too large.
// Ensure that the baseFee is not too large.
if
info
.
BaseFee
.
BitLen
()
>
256
{
if
info
.
BaseFee
.
BitLen
()
>
256
{
return
nil
,
fmt
.
Errorf
(
"base fee exceeds 256 bits: %d"
,
info
.
BaseFee
)
return
nil
,
fmt
.
Errorf
(
"base fee exceeds 256 bits: %d"
,
info
.
BaseFee
)
}
}
info
.
BaseFee
.
FillBytes
(
data
[
offset
:
offset
+
32
])
var
baseFeeBuf
[
32
]
byte
offset
+=
32
info
.
BaseFee
.
FillBytes
(
baseFeeBuf
[
:
])
copy
(
data
[
offset
:
offset
+
32
],
info
.
BlockHash
.
Bytes
())
writer
.
Write
(
baseFeeBuf
[
:
])
offset
+=
32
writer
.
Write
(
info
.
BlockHash
.
Bytes
())
binary
.
BigEndian
.
PutUint64
(
data
[
offset
+
24
:
offset
+
32
],
info
.
SequenceNumber
)
writer
.
Write
(
padding
[
:
])
offset
+=
32
binary
.
Write
(
writer
,
binary
.
BigEndian
,
info
.
SequenceNumber
)
copy
(
data
[
offset
+
12
:
offset
+
32
],
info
.
BatcherAddr
[
:
])
offset
+=
32
var
addrPadding
[
12
]
byte
copy
(
data
[
offset
:
offset
+
32
],
info
.
L1FeeOverhead
[
:
])
writer
.
Write
(
addrPadding
[
:
])
offset
+=
32
writer
.
Write
(
info
.
BatcherAddr
.
Bytes
())
copy
(
data
[
offset
:
offset
+
32
],
info
.
L1FeeScalar
[
:
])
writer
.
Write
(
info
.
L1FeeOverhead
[
:
])
return
data
,
nil
writer
.
Write
(
info
.
L1FeeScalar
[
:
])
return
writer
.
Bytes
(),
nil
}
}
func
(
info
*
L1BlockInfo
)
UnmarshalBinary
(
data
[]
byte
)
error
{
func
(
info
*
L1BlockInfo
)
UnmarshalBinary
(
data
[]
byte
)
error
{
if
len
(
data
)
!=
L1InfoLen
{
if
len
(
data
)
!=
L1InfoLen
{
return
fmt
.
Errorf
(
"data is unexpected length: %d"
,
len
(
data
))
return
fmt
.
Errorf
(
"data is unexpected length: %d"
,
len
(
data
))
}
}
var
padding
[
24
]
byte
reader
:=
bytes
.
NewReader
(
data
)
offset
:=
4
funcSignature
:=
make
([]
byte
,
4
)
if
!
bytes
.
Equal
(
data
[
0
:
offset
],
L1InfoFuncBytes4
)
{
if
_
,
err
:=
reader
.
Read
(
funcSignature
);
err
!=
nil
||
!
bytes
.
Equal
(
funcSignature
,
L1InfoFuncBytes4
)
{
return
fmt
.
Errorf
(
"data does not match L1 info function signature: 0x%x"
,
data
[
offset
:
4
])
return
fmt
.
Errorf
(
"data does not match L1 info function signature: 0x%x"
,
funcSignature
)
}
}
info
.
Number
=
binary
.
BigEndian
.
Uint64
(
data
[
offset
+
24
:
offset
+
32
])
var
padding
,
readPadding
[
24
]
byte
if
!
bytes
.
Equal
(
data
[
offset
:
offset
+
24
],
padding
[
:
])
{
return
fmt
.
Errorf
(
"l1 info number exceeds uint64 bounds: %x"
,
data
[
offset
:
offset
+
32
])
if
_
,
err
:=
reader
.
Read
(
readPadding
[
:
]);
err
!=
nil
||
!
bytes
.
Equal
(
readPadding
[
:
],
padding
[
:
])
{
}
return
fmt
.
Errorf
(
"l1 info number exceeds uint64 bounds: %x"
,
readPadding
[
:
])
offset
+=
32
}
info
.
Time
=
binary
.
BigEndian
.
Uint64
(
data
[
offset
+
24
:
offset
+
32
])
if
err
:=
binary
.
Read
(
reader
,
binary
.
BigEndian
,
&
info
.
Number
);
err
!=
nil
{
if
!
bytes
.
Equal
(
data
[
offset
:
offset
+
24
],
padding
[
:
])
{
return
err
return
fmt
.
Errorf
(
"l1 info time exceeds uint64 bounds: %x"
,
data
[
offset
:
offset
+
32
])
}
}
offset
+=
32
if
_
,
err
:=
reader
.
Read
(
readPadding
[
:
]);
err
!=
nil
||
!
bytes
.
Equal
(
readPadding
[
:
],
padding
[
:
])
{
info
.
BaseFee
=
new
(
big
.
Int
)
.
SetBytes
(
data
[
offset
:
offset
+
32
])
return
fmt
.
Errorf
(
"l1 info time exceeds uint64 bounds: %x"
,
readPadding
[
:
])
offset
+=
32
}
info
.
BlockHash
.
SetBytes
(
data
[
offset
:
offset
+
32
])
if
err
:=
binary
.
Read
(
reader
,
binary
.
BigEndian
,
&
info
.
Time
);
err
!=
nil
{
offset
+=
32
return
err
info
.
SequenceNumber
=
binary
.
BigEndian
.
Uint64
(
data
[
offset
+
24
:
offset
+
32
])
}
if
!
bytes
.
Equal
(
data
[
offset
:
offset
+
24
],
padding
[
:
])
{
return
fmt
.
Errorf
(
"l1 info sequence number exceeds uint64 bounds: %x"
,
data
[
offset
:
offset
+
32
])
var
baseFeeBytes
[
32
]
byte
}
if
_
,
err
:=
reader
.
Read
(
baseFeeBytes
[
:
]);
err
!=
nil
{
offset
+=
32
return
err
info
.
BatcherAddr
.
SetBytes
(
data
[
offset
+
12
:
offset
+
32
])
}
offset
+=
32
info
.
BaseFee
=
new
(
big
.
Int
)
.
SetBytes
(
baseFeeBytes
[
:
])
copy
(
info
.
L1FeeOverhead
[
:
],
data
[
offset
:
offset
+
32
])
offset
+=
32
var
blockHashBytes
[
32
]
byte
copy
(
info
.
L1FeeScalar
[
:
],
data
[
offset
:
offset
+
32
])
if
_
,
err
:=
reader
.
Read
(
blockHashBytes
[
:
]);
err
!=
nil
{
return
err
}
info
.
BlockHash
.
SetBytes
(
blockHashBytes
[
:
])
if
_
,
err
:=
reader
.
Read
(
readPadding
[
:
]);
err
!=
nil
||
!
bytes
.
Equal
(
readPadding
[
:
],
padding
[
:
])
{
return
fmt
.
Errorf
(
"l1 info sequence number exceeds uint64 bounds: %x"
,
readPadding
[
:
])
}
if
err
:=
binary
.
Read
(
reader
,
binary
.
BigEndian
,
&
info
.
SequenceNumber
);
err
!=
nil
{
return
err
}
var
addrPadding
[
12
]
byte
if
_
,
err
:=
reader
.
Read
(
addrPadding
[
:
]);
err
!=
nil
{
return
err
}
if
_
,
err
:=
reader
.
Read
(
info
.
BatcherAddr
[
:
]);
err
!=
nil
{
return
err
}
if
_
,
err
:=
reader
.
Read
(
info
.
L1FeeOverhead
[
:
]);
err
!=
nil
{
return
err
}
if
_
,
err
:=
reader
.
Read
(
info
.
L1FeeScalar
[
:
]);
err
!=
nil
{
return
err
}
return
nil
return
nil
}
}
...
...
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