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
825948d5
Unverified
Commit
825948d5
authored
Apr 14, 2023
by
protolambda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-program: hints/oracle comms io style changes
Co-authored-by:
Adrian Sutton
<
adrian@oplabs.co
>
parent
19379a14
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
16 deletions
+8
-16
hints.go
op-program/preimage/hints.go
+4
-5
oracle.go
op-program/preimage/oracle.go
+4
-11
No files found.
op-program/preimage/hints.go
View file @
825948d5
...
...
@@ -20,8 +20,8 @@ func NewHintWriter(w io.Writer) *HintWriter {
func
(
hw
*
HintWriter
)
Hint
(
v
Hint
)
{
hint
:=
v
.
Hint
()
hintBytes
:=
make
([]
byte
,
4
,
4
+
len
(
hint
)
+
1
)
binary
.
BigEndian
.
PutUint32
(
hintBytes
[
:
4
]
,
uint32
(
len
(
hint
)))
var
hintBytes
[]
byte
hintBytes
=
binary
.
BigEndian
.
AppendUint32
(
hintBytes
,
uint32
(
len
(
hint
)))
hintBytes
=
append
(
hintBytes
,
[]
byte
(
hint
)
...
)
hintBytes
=
append
(
hintBytes
,
0
)
// to block writing on
_
,
err
:=
hw
.
w
.
Write
(
hintBytes
)
...
...
@@ -41,14 +41,13 @@ func NewHintReader(r io.Reader) *HintReader {
}
func
(
hr
*
HintReader
)
NextHint
(
router
func
(
hint
string
)
error
)
error
{
var
length
Prefix
[
4
]
byte
if
_
,
err
:=
io
.
ReadFull
(
hr
.
r
,
lengthPrefix
[
:
]
);
err
!=
nil
{
var
length
uint32
if
err
:=
binary
.
Read
(
hr
.
r
,
binary
.
BigEndian
,
&
length
);
err
!=
nil
{
if
err
==
io
.
EOF
{
return
io
.
EOF
}
return
fmt
.
Errorf
(
"failed to read hint length prefix: %w"
,
err
)
}
length
:=
binary
.
BigEndian
.
Uint32
(
lengthPrefix
[
:
])
payload
:=
make
([]
byte
,
length
)
if
length
>
0
{
if
_
,
err
:=
io
.
ReadFull
(
hr
.
r
,
payload
);
err
!=
nil
{
...
...
op-program/preimage/oracle.go
View file @
825948d5
...
...
@@ -26,15 +26,10 @@ func (o *OracleClient) Get(key Key) []byte {
panic
(
fmt
.
Errorf
(
"failed to write key %s (%T) to pre-image oracle: %w"
,
key
,
key
,
err
))
}
var
length
Prefix
[
8
]
byte
if
_
,
err
:=
io
.
ReadFull
(
o
.
rw
,
lengthPrefix
[
:
]
);
err
!=
nil
{
var
length
uint64
if
err
:=
binary
.
Read
(
o
.
rw
,
binary
.
BigEndian
,
&
length
);
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"failed to read pre-image length of key %s (%T) from pre-image oracle: %w"
,
key
,
key
,
err
))
}
length
:=
binary
.
BigEndian
.
Uint64
(
lengthPrefix
[
:
])
if
length
==
0
{
// don't read empty payloads
return
nil
}
payload
:=
make
([]
byte
,
length
)
if
_
,
err
:=
io
.
ReadFull
(
o
.
rw
,
payload
);
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"failed to read pre-image payload (length %d) of key %s (%T) from pre-image oracle: %w"
,
length
,
key
,
key
,
err
))
...
...
@@ -65,10 +60,8 @@ func (o *OracleServer) NextPreimageRequest(getPreimage func(key common.Hash) ([]
return
fmt
.
Errorf
(
"failed to serve pre-image %s request: %w"
,
key
,
err
)
}
var
lengthPrefix
[
8
]
byte
binary
.
BigEndian
.
PutUint64
(
lengthPrefix
[
:
],
uint64
(
len
(
value
)))
if
_
,
err
:=
o
.
rw
.
Write
(
lengthPrefix
[
:
]);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to write length-prefix %x: %w"
,
lengthPrefix
,
err
)
if
err
:=
binary
.
Write
(
o
.
rw
,
binary
.
BigEndian
,
uint64
(
len
(
value
)));
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to write length-prefix %d: %w"
,
len
(
value
),
err
)
}
if
len
(
value
)
==
0
{
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