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
0dcb1b2c
Unverified
Commit
0dcb1b2c
authored
May 30, 2024
by
Sebastian Stammler
Committed by
GitHub
May 30, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node/p2p: add descriptive error code string (#10662)
parent
272d4471
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
3 deletions
+57
-3
sync.go
op-node/p2p/sync.go
+14
-1
sync_test.go
op-node/p2p/sync_test.go
+43
-2
No files found.
op-node/p2p/sync.go
View file @
0dcb1b2c
...
@@ -68,6 +68,13 @@ const (
...
@@ -68,6 +68,13 @@ const (
ResultCodeUnknownErr
byte
=
3
ResultCodeUnknownErr
byte
=
3
)
)
var
resultCodeString
=
[]
string
{
"success"
,
"not found"
,
"invalid request"
,
"unknown error"
,
}
func
PayloadByNumberProtocolID
(
l2ChainID
*
big
.
Int
)
protocol
.
ID
{
func
PayloadByNumberProtocolID
(
l2ChainID
*
big
.
Int
)
protocol
.
ID
{
return
protocol
.
ID
(
fmt
.
Sprintf
(
"/opstack/req/payload_by_number/%d/0"
,
l2ChainID
))
return
protocol
.
ID
(
fmt
.
Sprintf
(
"/opstack/req/payload_by_number/%d/0"
,
l2ChainID
))
}
}
...
@@ -614,7 +621,13 @@ func (s *SyncClient) peerLoop(ctx context.Context, id peer.ID) {
...
@@ -614,7 +621,13 @@ func (s *SyncClient) peerLoop(ctx context.Context, id peer.ID) {
type
requestResultErr
byte
type
requestResultErr
byte
func
(
r
requestResultErr
)
Error
()
string
{
func
(
r
requestResultErr
)
Error
()
string
{
return
fmt
.
Sprintf
(
"peer failed to serve request with code %d"
,
uint8
(
r
))
var
errStr
string
if
ri
:=
int
(
r
);
ri
<
len
(
resultCodeString
)
{
errStr
=
resultCodeString
[
ri
]
}
else
{
errStr
=
"invalid code"
}
return
fmt
.
Sprintf
(
"peer failed to serve request with code %d: %s"
,
uint8
(
r
),
errStr
)
}
}
func
(
r
requestResultErr
)
ResultCode
()
byte
{
func
(
r
requestResultErr
)
ResultCode
()
byte
{
...
...
op-node/p2p/sync_test.go
View file @
0dcb1b2c
...
@@ -2,7 +2,9 @@ package p2p
...
@@ -2,7 +2,9 @@ package p2p
import
(
import
(
"context"
"context"
"fmt"
"math/big"
"math/big"
"strings"
"sync"
"sync"
"testing"
"testing"
"time"
"time"
...
@@ -378,7 +380,7 @@ func TestNetworkNotifyAddPeerAndRemovePeer(t *testing.T) {
...
@@ -378,7 +380,7 @@ func TestNetworkNotifyAddPeerAndRemovePeer(t *testing.T) {
require
.
NoError
(
t
,
err
,
"failed to connect to peer B from peer A"
)
require
.
NoError
(
t
,
err
,
"failed to connect to peer B from peer A"
)
require
.
Equal
(
t
,
hostA
.
Network
()
.
Connectedness
(
hostB
.
ID
()),
network
.
Connected
)
require
.
Equal
(
t
,
hostA
.
Network
()
.
Connectedness
(
hostB
.
ID
()),
network
.
Connected
)
//wait for async add process done
//
wait for async add process done
<-
waitChan
<-
waitChan
_
,
ok
:=
syncCl
.
peers
[
hostB
.
ID
()]
_
,
ok
:=
syncCl
.
peers
[
hostB
.
ID
()]
require
.
True
(
t
,
ok
,
"peerB should exist in syncClient"
)
require
.
True
(
t
,
ok
,
"peerB should exist in syncClient"
)
...
@@ -386,7 +388,7 @@ func TestNetworkNotifyAddPeerAndRemovePeer(t *testing.T) {
...
@@ -386,7 +388,7 @@ func TestNetworkNotifyAddPeerAndRemovePeer(t *testing.T) {
err
=
hostA
.
Network
()
.
ClosePeer
(
hostB
.
ID
())
err
=
hostA
.
Network
()
.
ClosePeer
(
hostB
.
ID
())
require
.
NoError
(
t
,
err
,
"close peer fail"
)
require
.
NoError
(
t
,
err
,
"close peer fail"
)
//wait for async removing process done
//
wait for async removing process done
<-
waitChan
<-
waitChan
_
,
peerBExist3
:=
syncCl
.
peers
[
hostB
.
ID
()]
_
,
peerBExist3
:=
syncCl
.
peers
[
hostB
.
ID
()]
require
.
True
(
t
,
!
peerBExist3
,
"peerB should not exist in syncClient"
)
require
.
True
(
t
,
!
peerBExist3
,
"peerB should not exist in syncClient"
)
...
@@ -400,5 +402,44 @@ func TestPanicGuard(t *testing.T) {
...
@@ -400,5 +402,44 @@ func TestPanicGuard(t *testing.T) {
err
:=
panicGuard
(
mockPanickingFn
)(
context
.
Background
(),
peer
.
ID
(
""
),
37
)
err
:=
panicGuard
(
mockPanickingFn
)(
context
.
Background
(),
peer
.
ID
(
""
),
37
)
require
.
EqualError
(
t
,
err
,
"recovered from a panic: gotcha"
)
require
.
EqualError
(
t
,
err
,
"recovered from a panic: gotcha"
)
})
})
}
func
TestRequestResultErr_Error
(
t
*
testing
.
T
)
{
for
_
,
test
:=
range
[]
struct
{
code
byte
expStr
string
}{
{
code
:
0
,
expStr
:
"success"
,
},
{
code
:
1
,
expStr
:
"not found"
,
},
{
code
:
2
,
expStr
:
"invalid request"
,
},
{
code
:
3
,
expStr
:
"unknown error"
,
},
{
code
:
4
,
expStr
:
"invalid code"
,
},
{
code
:
0xff
,
expStr
:
"invalid code"
,
},
}
{
t
.
Run
(
fmt
.
Sprintf
(
"code %d"
,
test
.
code
),
func
(
t
*
testing
.
T
)
{
err
:=
requestResultErr
(
test
.
code
)
errStr
:=
err
.
Error
()
if
!
strings
.
HasSuffix
(
errStr
,
test
.
expStr
)
{
t
.
Fatalf
(
"unexpected error string %q, expted suffix %q"
,
errStr
,
test
.
expStr
)
}
})
}
}
}
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