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
1136269a
Unverified
Commit
1136269a
authored
Aug 23, 2018
by
Péter Szilágyi
Browse files
Options
Downloads
Patches
Plain Diff
miner: differentiate between uncle and lost block
parent
67d6d0bb
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
miner/unconfirmed.go
+27
-8
27 additions, 8 deletions
miner/unconfirmed.go
miner/unconfirmed_test.go
+8
-5
8 additions, 5 deletions
miner/unconfirmed_test.go
miner/worker.go
+1
-1
1 addition, 1 deletion
miner/worker.go
with
36 additions
and
14 deletions
miner/unconfirmed.go
+
27
−
8
View file @
1136269a
...
@@ -25,11 +25,14 @@ import (
...
@@ -25,11 +25,14 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/log"
)
)
//
header
Retriever is used by the unconfirmed block set to verify whether a previously
//
chain
Retriever is used by the unconfirmed block set to verify whether a previously
// mined block is part of the canonical chain or not.
// mined block is part of the canonical chain or not.
type
header
Retriever
interface
{
type
chain
Retriever
interface
{
// GetHeaderByNumber retrieves the canonical header associated with a block number.
// GetHeaderByNumber retrieves the canonical header associated with a block number.
GetHeaderByNumber
(
number
uint64
)
*
types
.
Header
GetHeaderByNumber
(
number
uint64
)
*
types
.
Header
// GetBlockByNumber retrieves the canonical block associated with a block number.
GetBlockByNumber
(
number
uint64
)
*
types
.
Block
}
}
// unconfirmedBlock is a small collection of metadata about a locally mined block
// unconfirmedBlock is a small collection of metadata about a locally mined block
...
@@ -44,14 +47,14 @@ type unconfirmedBlock struct {
...
@@ -44,14 +47,14 @@ type unconfirmedBlock struct {
// used by the miner to provide logs to the user when a previously mined block
// used by the miner to provide logs to the user when a previously mined block
// has a high enough guarantee to not be reorged out of the canonical chain.
// has a high enough guarantee to not be reorged out of the canonical chain.
type
unconfirmedBlocks
struct
{
type
unconfirmedBlocks
struct
{
chain
header
Retriever
// Blockchain to verify canonical status through
chain
chain
Retriever
// Blockchain to verify canonical status through
depth
uint
// Depth after which to discard previous blocks
depth
uint
// Depth after which to discard previous blocks
blocks
*
ring
.
Ring
// Block infos to allow canonical chain cross checks
blocks
*
ring
.
Ring
// Block infos to allow canonical chain cross checks
lock
sync
.
RWMutex
// Protects the fields from concurrent access
lock
sync
.
RWMutex
// Protects the fields from concurrent access
}
}
// newUnconfirmedBlocks returns new data structure to track currently unconfirmed blocks.
// newUnconfirmedBlocks returns new data structure to track currently unconfirmed blocks.
func
newUnconfirmedBlocks
(
chain
header
Retriever
,
depth
uint
)
*
unconfirmedBlocks
{
func
newUnconfirmedBlocks
(
chain
chain
Retriever
,
depth
uint
)
*
unconfirmedBlocks
{
return
&
unconfirmedBlocks
{
return
&
unconfirmedBlocks
{
chain
:
chain
,
chain
:
chain
,
depth
:
depth
,
depth
:
depth
,
...
@@ -103,7 +106,23 @@ func (set *unconfirmedBlocks) Shift(height uint64) {
...
@@ -103,7 +106,23 @@ func (set *unconfirmedBlocks) Shift(height uint64) {
case
header
.
Hash
()
==
next
.
hash
:
case
header
.
Hash
()
==
next
.
hash
:
log
.
Info
(
"🔗 block reached canonical chain"
,
"number"
,
next
.
index
,
"hash"
,
next
.
hash
)
log
.
Info
(
"🔗 block reached canonical chain"
,
"number"
,
next
.
index
,
"hash"
,
next
.
hash
)
default
:
default
:
log
.
Info
(
"⑂ block became a side fork"
,
"number"
,
next
.
index
,
"hash"
,
next
.
hash
)
// Block is not canonical, check whether we have an uncle or a lost block
included
:=
false
for
number
:=
next
.
index
;
!
included
&&
number
<
next
.
index
+
uint64
(
set
.
depth
)
&&
number
<=
height
;
number
++
{
if
block
:=
set
.
chain
.
GetBlockByNumber
(
number
);
block
!=
nil
{
for
_
,
uncle
:=
range
block
.
Uncles
()
{
if
uncle
.
Hash
()
==
next
.
hash
{
included
=
true
break
}
}
}
}
if
included
{
log
.
Info
(
"⑂ block became an uncle"
,
"number"
,
next
.
index
,
"hash"
,
next
.
hash
)
}
else
{
log
.
Info
(
"😱 block lost"
,
"number"
,
next
.
index
,
"hash"
,
next
.
hash
)
}
}
}
// Drop the block out of the ring
// Drop the block out of the ring
if
set
.
blocks
.
Value
==
set
.
blocks
.
Next
()
.
Value
{
if
set
.
blocks
.
Value
==
set
.
blocks
.
Next
()
.
Value
{
...
...
This diff is collapsed.
Click to expand it.
miner/unconfirmed_test.go
+
8
−
5
View file @
1136269a
...
@@ -23,11 +23,14 @@ import (
...
@@ -23,11 +23,14 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
)
)
// noop
Header
Retriever is an implementation of headerRetriever that always
// noop
Chain
Retriever is an implementation of headerRetriever that always
// returns nil for any requested headers.
// returns nil for any requested headers.
type
noop
Header
Retriever
struct
{}
type
noop
Chain
Retriever
struct
{}
func
(
r
*
noopHeaderRetriever
)
GetHeaderByNumber
(
number
uint64
)
*
types
.
Header
{
func
(
r
*
noopChainRetriever
)
GetHeaderByNumber
(
number
uint64
)
*
types
.
Header
{
return
nil
}
func
(
r
*
noopChainRetriever
)
GetBlockByNumber
(
number
uint64
)
*
types
.
Block
{
return
nil
return
nil
}
}
...
@@ -36,7 +39,7 @@ func (r *noopHeaderRetriever) GetHeaderByNumber(number uint64) *types.Header {
...
@@ -36,7 +39,7 @@ func (r *noopHeaderRetriever) GetHeaderByNumber(number uint64) *types.Header {
func
TestUnconfirmedInsertBounds
(
t
*
testing
.
T
)
{
func
TestUnconfirmedInsertBounds
(
t
*
testing
.
T
)
{
limit
:=
uint
(
10
)
limit
:=
uint
(
10
)
pool
:=
newUnconfirmedBlocks
(
new
(
noop
Header
Retriever
),
limit
)
pool
:=
newUnconfirmedBlocks
(
new
(
noop
Chain
Retriever
),
limit
)
for
depth
:=
uint64
(
0
);
depth
<
2
*
uint64
(
limit
);
depth
++
{
for
depth
:=
uint64
(
0
);
depth
<
2
*
uint64
(
limit
);
depth
++
{
// Insert multiple blocks for the same level just to stress it
// Insert multiple blocks for the same level just to stress it
for
i
:=
0
;
i
<
int
(
depth
);
i
++
{
for
i
:=
0
;
i
<
int
(
depth
);
i
++
{
...
@@ -58,7 +61,7 @@ func TestUnconfirmedShifts(t *testing.T) {
...
@@ -58,7 +61,7 @@ func TestUnconfirmedShifts(t *testing.T) {
// Create a pool with a few blocks on various depths
// Create a pool with a few blocks on various depths
limit
,
start
:=
uint
(
10
),
uint64
(
25
)
limit
,
start
:=
uint
(
10
),
uint64
(
25
)
pool
:=
newUnconfirmedBlocks
(
new
(
noop
Header
Retriever
),
limit
)
pool
:=
newUnconfirmedBlocks
(
new
(
noop
Chain
Retriever
),
limit
)
for
depth
:=
start
;
depth
<
start
+
uint64
(
limit
);
depth
++
{
for
depth
:=
start
;
depth
<
start
+
uint64
(
limit
);
depth
++
{
pool
.
Insert
(
depth
,
common
.
Hash
([
32
]
byte
{
byte
(
depth
)}))
pool
.
Insert
(
depth
,
common
.
Hash
([
32
]
byte
{
byte
(
depth
)}))
}
}
...
...
This diff is collapsed.
Click to expand it.
miner/worker.go
+
1
−
1
View file @
1136269a
...
@@ -55,7 +55,7 @@ const (
...
@@ -55,7 +55,7 @@ const (
resubmitAdjustChanSize
=
10
resubmitAdjustChanSize
=
10
// miningLogAtDepth is the number of confirmations before logging successful mining.
// miningLogAtDepth is the number of confirmations before logging successful mining.
miningLogAtDepth
=
5
miningLogAtDepth
=
7
// minRecommitInterval is the minimal time interval to recreate the mining block with
// minRecommitInterval is the minimal time interval to recreate the mining block with
// any newly arrived transactions.
// any newly arrived transactions.
...
...
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