good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
8f7174fb
Commit
8f7174fb
authored
Jan 21, 2022
by
Shivam Sharma
Browse files
Options
Downloads
Patches
Plain Diff
Refactor Code
parent
949822c0
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/blockchain_bor_test.go
+47
-72
47 additions, 72 deletions
core/blockchain_bor_test.go
with
47 additions
and
72 deletions
core/blockchain_bor_test.go
+
47
−
72
View file @
8f7174fb
...
@@ -53,96 +53,71 @@ func TestChain2HeadEvent(t *testing.T) {
...
@@ -53,96 +53,71 @@ func TestChain2HeadEvent(t *testing.T) {
t
.
Fatalf
(
"failed to insert chain: %v"
,
err
)
t
.
Fatalf
(
"failed to insert chain: %v"
,
err
)
}
}
// first two block of the secondary chain are for a brief moment considered
// side chains because up to that point the first one is considered the
// heavier chain.
expectedReorgHashes
:=
map
[
common
.
Hash
]
bool
{
replacementBlocks
[
0
]
.
Hash
()
:
true
,
replacementBlocks
[
1
]
.
Hash
()
:
true
,
replacementBlocks
[
2
]
.
Hash
()
:
true
,
}
expectedReplacedHashes
:=
map
[
common
.
Hash
]
bool
{
chain
[
0
]
.
Hash
()
:
true
,
chain
[
1
]
.
Hash
()
:
true
,
chain
[
2
]
.
Hash
()
:
true
,
}
expectedForkHashes
:=
map
[
common
.
Hash
]
bool
{
replacementBlocks
[
0
]
.
Hash
()
:
true
,
replacementBlocks
[
1
]
.
Hash
()
:
true
,
}
expectedHeadHashes
:=
map
[
common
.
Hash
]
bool
{
chain
[
2
]
.
Hash
()
:
true
,
replacementBlocks
[
3
]
.
Hash
()
:
true
,
}
i
:=
0
i
:=
0
tot
:=
0
readEvent
:=
func
()
*
Chain2HeadEvent
{
readEvent
:=
func
()
*
Chain2HeadEvent
{
select
{
select
{
case
ev
:=
<-
chain2HeadCh
:
case
ev
:=
<-
chain2HeadCh
:
i
++
i
++
if
ev
.
Type
==
Chain2HeadReorgEvent
{
return
&
ev
//Reorg Event Sends Chain of Added Blocks in NewChain. So need to check all of them in reorgHashes
case
<-
time
.
After
(
2
*
time
.
Second
)
:
for
j
:=
0
;
j
<
len
(
ev
.
OldChain
);
j
++
{
t
.
Fatal
(
"timeout"
)
tot
++
}
block
:=
ev
.
OldChain
[
j
]
return
nil
if
_
,
ok
:=
expectedReplacedHashes
[
block
.
Hash
()];
!
ok
{
t
.
Errorf
(
"%d: didn't expect %x to be in side chain"
,
i
,
block
.
Hash
())
}
}
// head event
event1
:=
readEvent
()
if
event1
.
Type
!=
Chain2HeadCanonicalEvent
{
t
.
Fatal
(
"it should be type head"
)
}
}
//Reorg Event also Sends Chain of Removed Blocks in NewChain. So need to check all of them in replacedHashes
if
event1
.
NewChain
[
0
]
.
Hash
()
!=
chain
[
2
]
.
Hash
()
{
for
j
:=
0
;
j
<
len
(
ev
.
OldChain
);
j
++
{
t
.
Fatalf
(
"%d : Hash Does Not Match"
,
i
)
tot
++
block
:=
ev
.
NewChain
[
j
]
if
_
,
ok
:=
expectedReorgHashes
[
block
.
Hash
()];
!
ok
{
t
.
Errorf
(
"%d: didn't expect %x to be in side chain"
,
i
,
block
.
Hash
())
}
}
// fork event
event2
:=
readEvent
()
if
event2
.
Type
!=
Chain2HeadForkEvent
{
t
.
Fatal
(
"it should be type fork"
)
}
}
if
event2
.
NewChain
[
0
]
.
Hash
()
!=
replacementBlocks
[
0
]
.
Hash
()
{
t
.
Fatalf
(
"%d : Hash Does Not Match"
,
i
)
}
}
if
ev
.
Type
==
Chain2HeadForkEvent
{
// fork event
tot
++
event3
:=
readEvent
()
block
:=
ev
.
NewChain
[
0
]
if
event3
.
Type
!=
Chain2HeadForkEvent
{
if
_
,
ok
:=
expectedForkHashes
[
block
.
Hash
()];
!
ok
{
t
.
Fatal
(
"it should be type fork"
)
t
.
Errorf
(
"%d: didn't expect %x to be in fork chain"
,
i
,
block
.
Hash
())
}
}
if
event3
.
NewChain
[
0
]
.
Hash
()
!=
replacementBlocks
[
1
]
.
Hash
()
{
t
.
Fatalf
(
"%d : Hash Does Not Match"
,
i
)
}
}
if
ev
.
Type
==
Chain2HeadCanonicalEvent
{
// reorg event
tot
++
//In this event the channel recieves an array of Blocks in NewChain and OldChain
block
:=
ev
.
NewChain
[
0
]
expectedOldChainHashes
:=
[
3
]
common
.
Hash
{
0
:
chain
[
2
]
.
Hash
(),
1
:
chain
[
1
]
.
Hash
(),
2
:
chain
[
0
]
.
Hash
()}
if
_
,
ok
:=
expectedHeadHashes
[
block
.
Hash
()];
!
ok
{
expectedNewChainHashes
:=
[
3
]
common
.
Hash
{
0
:
replacementBlocks
[
2
]
.
Hash
(),
1
:
replacementBlocks
[
1
]
.
Hash
(),
2
:
replacementBlocks
[
0
]
.
Hash
()}
t
.
Errorf
(
"%d: didn't expect %x to be in head chain"
,
i
,
block
.
Hash
())
event4
:=
readEvent
()
if
event4
.
Type
!=
Chain2HeadReorgEvent
{
t
.
Fatal
(
"it should be type reorg"
)
}
}
for
j
:=
0
;
j
<
len
(
event4
.
OldChain
);
j
++
{
if
event4
.
OldChain
[
j
]
.
Hash
()
!=
expectedOldChainHashes
[
j
]
{
t
.
Fatalf
(
"%d : Oldchain hashes Does Not Match"
,
i
)
}
}
return
nil
case
<-
time
.
After
(
2
*
time
.
Second
)
:
t
.
Fatal
(
"timeout"
)
}
}
return
nil
for
j
:=
0
;
j
<
len
(
event4
.
NewChain
);
j
++
{
if
event4
.
NewChain
[
j
]
.
Hash
()
!=
expectedNewChainHashes
[
j
]
{
t
.
Fatalf
(
"%d : Newchain hashes Does Not Match"
,
i
)
}
}
}
// head event
// head event
readEvent
()
event5
:=
readEvent
()
if
event5
.
Type
!=
Chain2HeadCanonicalEvent
{
// fork event
t
.
Fatal
(
"it should be type head"
)
readEvent
()
}
if
event5
.
NewChain
[
0
]
.
Hash
()
!=
replacementBlocks
[
3
]
.
Hash
()
{
// fork event
t
.
Fatalf
(
"%d : Hash Does Not Match"
,
i
)
readEvent
()
}
// reorg event
readEvent
()
// head event
readEvent
()
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment