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
22f02a3f
Commit
22f02a3f
authored
May 26, 2023
by
Felipe Andrade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moar tests for safe and finalized bans
parent
f4333150
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
162 additions
and
55 deletions
+162
-55
consensus_poller.go
proxyd/consensus_poller.go
+64
-55
consensus_test.go
proxyd/integration_tests/consensus_test.go
+76
-0
consensus_responses.yml
proxyd/integration_tests/testdata/consensus_responses.yml
+22
-0
No files found.
proxyd/consensus_poller.go
View file @
22f02a3f
...
@@ -406,11 +406,6 @@ func (cp *ConsensusPoller) UpdateBackendGroupConsensus(ctx context.Context) {
...
@@ -406,11 +406,6 @@ func (cp *ConsensusPoller) UpdateBackendGroupConsensus(ctx context.Context) {
}
}
}
}
// no block to propose (i.e. initializing consensus)
if
lowestLatestBlock
==
0
{
return
}
proposedBlock
:=
lowestLatestBlock
proposedBlock
:=
lowestLatestBlock
proposedBlockHash
:=
lowestLatestBlockHash
proposedBlockHash
:=
lowestLatestBlockHash
hasConsensus
:=
false
hasConsensus
:=
false
...
@@ -424,7 +419,10 @@ func (cp *ConsensusPoller) UpdateBackendGroupConsensus(ctx context.Context) {
...
@@ -424,7 +419,10 @@ func (cp *ConsensusPoller) UpdateBackendGroupConsensus(ctx context.Context) {
log
.
Debug
(
"validating consensus on block"
,
"lowestLatestBlock"
,
lowestLatestBlock
)
log
.
Debug
(
"validating consensus on block"
,
"lowestLatestBlock"
,
lowestLatestBlock
)
}
}
broken
:=
false
// if there is no block to propose, the consensus is automatically broken
broken
:=
proposedBlock
==
0
&&
currentConsensusBlockNumber
>
0
if
proposedBlock
>
0
{
for
!
hasConsensus
{
for
!
hasConsensus
{
allAgreed
:=
true
allAgreed
:=
true
consensusBackends
=
consensusBackends
[
:
0
]
consensusBackends
=
consensusBackends
[
:
0
]
...
@@ -479,6 +477,7 @@ func (cp *ConsensusPoller) UpdateBackendGroupConsensus(ctx context.Context) {
...
@@ -479,6 +477,7 @@ func (cp *ConsensusPoller) UpdateBackendGroupConsensus(ctx context.Context) {
log
.
Debug
(
"no consensus, now trying"
,
"block:"
,
proposedBlock
)
log
.
Debug
(
"no consensus, now trying"
,
"block:"
,
proposedBlock
)
}
}
}
}
}
if
broken
{
if
broken
{
// propagate event to other interested parts, such as cache invalidator
// propagate event to other interested parts, such as cache invalidator
...
@@ -521,6 +520,16 @@ func (cp *ConsensusPoller) Ban(be *Backend) {
...
@@ -521,6 +520,16 @@ func (cp *ConsensusPoller) Ban(be *Backend) {
defer
bs
.
backendStateMux
.
Unlock
()
defer
bs
.
backendStateMux
.
Unlock
()
bs
.
backendStateMux
.
Lock
()
bs
.
backendStateMux
.
Lock
()
bs
.
bannedUntil
=
time
.
Now
()
.
Add
(
cp
.
banPeriod
)
bs
.
bannedUntil
=
time
.
Now
()
.
Add
(
cp
.
banPeriod
)
bs
.
safeBlockNumber
=
0
bs
.
finalizedBlockNumber
=
0
}
// Unban remove any bans from the backends
func
(
cp
*
ConsensusPoller
)
Unban
(
be
*
Backend
)
{
bs
:=
cp
.
backendState
[
be
]
defer
bs
.
backendStateMux
.
Unlock
()
bs
.
backendStateMux
.
Lock
()
bs
.
bannedUntil
=
time
.
Now
()
.
Add
(
-
10
*
time
.
Hour
)
}
}
// Reset remove any bans from the backends and reset their states
// Reset remove any bans from the backends and reset their states
...
...
proxyd/integration_tests/consensus_test.go
View file @
22f02a3f
...
@@ -330,6 +330,82 @@ func TestConsensus(t *testing.T) {
...
@@ -330,6 +330,82 @@ func TestConsensus(t *testing.T) {
require
.
Equal
(
t
,
1
,
len
(
consensusGroup
))
require
.
Equal
(
t
,
1
,
len
(
consensusGroup
))
})
})
t
.
Run
(
"recover after safe and finalized dropped"
,
func
(
t
*
testing
.
T
)
{
reset
()
useOnlyNode1
()
overrideBlock
(
"node1"
,
"latest"
,
"0xd1"
)
overrideBlock
(
"node1"
,
"safe"
,
"0xb1"
)
overrideBlock
(
"node1"
,
"finalized"
,
"0x91"
)
update
()
consensusGroup
:=
bg
.
Consensus
.
GetConsensusGroup
()
require
.
NotContains
(
t
,
consensusGroup
,
nodes
[
"node1"
]
.
backend
)
require
.
True
(
t
,
bg
.
Consensus
.
IsBanned
(
nodes
[
"node1"
]
.
backend
))
require
.
Equal
(
t
,
0
,
len
(
consensusGroup
))
// unban and see if it recovers
bg
.
Consensus
.
Unban
(
nodes
[
"node1"
]
.
backend
)
update
()
consensusGroup
=
bg
.
Consensus
.
GetConsensusGroup
()
require
.
Contains
(
t
,
consensusGroup
,
nodes
[
"node1"
]
.
backend
)
require
.
False
(
t
,
bg
.
Consensus
.
IsBanned
(
nodes
[
"node1"
]
.
backend
))
require
.
Equal
(
t
,
1
,
len
(
consensusGroup
))
require
.
Equal
(
t
,
"0xd1"
,
bg
.
Consensus
.
GetLatestBlockNumber
()
.
String
())
require
.
Equal
(
t
,
"0x91"
,
bg
.
Consensus
.
GetFinalizedBlockNumber
()
.
String
())
require
.
Equal
(
t
,
"0xb1"
,
bg
.
Consensus
.
GetSafeBlockNumber
()
.
String
())
})
t
.
Run
(
"latest dropped below safe, then recovered"
,
func
(
t
*
testing
.
T
)
{
reset
()
useOnlyNode1
()
overrideBlock
(
"node1"
,
"latest"
,
"0xd1"
)
update
()
consensusGroup
:=
bg
.
Consensus
.
GetConsensusGroup
()
require
.
NotContains
(
t
,
consensusGroup
,
nodes
[
"node1"
]
.
backend
)
require
.
True
(
t
,
bg
.
Consensus
.
IsBanned
(
nodes
[
"node1"
]
.
backend
))
require
.
Equal
(
t
,
0
,
len
(
consensusGroup
))
// unban and see if it recovers
bg
.
Consensus
.
Unban
(
nodes
[
"node1"
]
.
backend
)
overrideBlock
(
"node1"
,
"safe"
,
"0xb1"
)
overrideBlock
(
"node1"
,
"finalized"
,
"0x91"
)
update
()
consensusGroup
=
bg
.
Consensus
.
GetConsensusGroup
()
require
.
Contains
(
t
,
consensusGroup
,
nodes
[
"node1"
]
.
backend
)
require
.
False
(
t
,
bg
.
Consensus
.
IsBanned
(
nodes
[
"node1"
]
.
backend
))
require
.
Equal
(
t
,
1
,
len
(
consensusGroup
))
require
.
Equal
(
t
,
"0xd1"
,
bg
.
Consensus
.
GetLatestBlockNumber
()
.
String
())
require
.
Equal
(
t
,
"0x91"
,
bg
.
Consensus
.
GetFinalizedBlockNumber
()
.
String
())
require
.
Equal
(
t
,
"0xb1"
,
bg
.
Consensus
.
GetSafeBlockNumber
()
.
String
())
})
t
.
Run
(
"latest dropped below safe, and stayed inconsistent after ban"
,
func
(
t
*
testing
.
T
)
{
reset
()
useOnlyNode1
()
overrideBlock
(
"node1"
,
"latest"
,
"0xd1"
)
update
()
consensusGroup
:=
bg
.
Consensus
.
GetConsensusGroup
()
require
.
NotContains
(
t
,
consensusGroup
,
nodes
[
"node1"
]
.
backend
)
require
.
True
(
t
,
bg
.
Consensus
.
IsBanned
(
nodes
[
"node1"
]
.
backend
))
require
.
Equal
(
t
,
0
,
len
(
consensusGroup
))
// unban and see if it recovers - it should not since the blocks stays the same
bg
.
Consensus
.
Unban
(
nodes
[
"node1"
]
.
backend
)
update
()
// should be banned again
consensusGroup
=
bg
.
Consensus
.
GetConsensusGroup
()
require
.
NotContains
(
t
,
consensusGroup
,
nodes
[
"node1"
]
.
backend
)
require
.
True
(
t
,
bg
.
Consensus
.
IsBanned
(
nodes
[
"node1"
]
.
backend
))
require
.
Equal
(
t
,
0
,
len
(
consensusGroup
))
})
t
.
Run
(
"broken consensus"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"broken consensus"
,
func
(
t
*
testing
.
T
)
{
reset
()
reset
()
listenerCalled
:=
false
listenerCalled
:=
false
...
...
proxyd/integration_tests/testdata/consensus_responses.yml
View file @
22f02a3f
...
@@ -107,6 +107,17 @@
...
@@ -107,6 +107,17 @@
"number": "0x200"
"number": "0x200"
}
}
}
}
-
method
:
eth_getBlockByNumber
block
:
0x91
response
:
>
{
"jsonrpc": "2.0",
"id": 67,
"result": {
"hash": "hash_0x91",
"number": "0x91"
}
}
-
method
:
eth_getBlockByNumber
-
method
:
eth_getBlockByNumber
block
:
safe
block
:
safe
response
:
>
response
:
>
...
@@ -151,3 +162,14 @@
...
@@ -151,3 +162,14 @@
"number": "0xc1"
"number": "0xc1"
}
}
}
}
-
method
:
eth_getBlockByNumber
block
:
0xd1
response
:
>
{
"jsonrpc": "2.0",
"id": 67,
"result": {
"hash": "hash_0xd1",
"number": "0xd1"
}
}
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