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
345172f7
Commit
345172f7
authored
Apr 17, 2023
by
inphi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-program: Hint reader recovery
Attempt to recover the hint read stream when the NextHint callback fails
parent
e6f1f61c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
0 deletions
+20
-0
hints.go
op-program/preimage/hints.go
+2
-0
hints_test.go
op-program/preimage/hints_test.go
+18
-0
No files found.
op-program/preimage/hints.go
View file @
345172f7
...
...
@@ -55,6 +55,8 @@ func (hr *HintReader) NextHint(router func(hint string) error) error {
}
}
if
err
:=
router
(
string
(
payload
));
err
!=
nil
{
// stream recovery
_
,
_
=
hr
.
r
.
Read
([]
byte
{
0
})
return
fmt
.
Errorf
(
"failed to handle hint: %w"
,
err
)
}
if
_
,
err
:=
hr
.
r
.
Read
([]
byte
{
0
});
err
!=
nil
{
...
...
op-program/preimage/hints_test.go
View file @
345172f7
...
...
@@ -3,6 +3,7 @@ package preimage
import
(
"bytes"
"crypto/rand"
"errors"
"io"
"testing"
...
...
@@ -71,4 +72,21 @@ func TestHints(t *testing.T) {
err
:=
hr
.
NextHint
(
func
(
hint
string
)
error
{
return
nil
})
require
.
ErrorIs
(
t
,
err
,
io
.
ErrUnexpectedEOF
)
})
t
.
Run
(
"cb error"
,
func
(
t
*
testing
.
T
)
{
var
buf
bytes
.
Buffer
hw
:=
NewHintWriter
(
&
buf
)
hw
.
Hint
(
rawHint
(
"one"
))
hw
.
Hint
(
rawHint
(
"two"
))
hr
:=
NewHintReader
(
&
buf
)
cbErr
:=
errors
.
New
(
"fail"
)
err
:=
hr
.
NextHint
(
func
(
hint
string
)
error
{
return
cbErr
})
require
.
ErrorIs
(
t
,
err
,
cbErr
)
var
readHint
string
err
=
hr
.
NextHint
(
func
(
hint
string
)
error
{
readHint
=
hint
return
nil
})
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
readHint
,
"two"
)
})
}
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