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
f37d07db
Unverified
Commit
f37d07db
authored
May 17, 2019
by
Jaynti Kanani
Browse files
Options
Downloads
Patches
Plain Diff
update bor consensus
parent
84828e7c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
cmd/puppeth/wizard_genesis.go
+1
-1
1 addition, 1 deletion
cmd/puppeth/wizard_genesis.go
consensus/bor/bor.go
+15
-10
15 additions, 10 deletions
consensus/bor/bor.go
consensus/bor/snapshot.go
+3
-3
3 additions, 3 deletions
consensus/bor/snapshot.go
params/config.go
+1
-1
1 addition, 1 deletion
params/config.go
with
20 additions
and
15 deletions
cmd/puppeth/wizard_genesis.go
+
1
−
1
View file @
f37d07db
...
...
@@ -107,7 +107,7 @@ func (w *wizard) makeGenesis() {
genesis
.
Difficulty
=
big
.
NewInt
(
1
)
genesis
.
GasLimit
=
10000000
genesis
.
Config
.
Bor
=
&
params
.
BorConfig
{
BlockInterval
:
1
,
Period
:
1
,
ProducerInterval
:
60
,
Epoch
:
30000
,
}
...
...
This diff is collapsed.
Click to expand it.
consensus/bor/bor.go
+
15
−
10
View file @
f37d07db
...
...
@@ -183,8 +183,8 @@ func encodeSigHeader(w io.Writer, header *types.Header) {
// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty
// that a new block should have based on the previous blocks in the chain and the
// current signer.
func
CalcDifficulty
(
snap
*
Snapshot
,
signer
common
.
Address
)
*
big
.
Int
{
if
snap
.
inturn
(
snap
.
Number
+
1
,
signer
)
{
func
CalcDifficulty
(
snap
*
Snapshot
,
signer
common
.
Address
,
producerPeriod
uint64
)
*
big
.
Int
{
if
snap
.
inturn
(
snap
.
Number
+
1
,
signer
,
producerPeriod
)
{
return
new
(
big
.
Int
)
.
Set
(
diffInTurn
)
}
return
new
(
big
.
Int
)
.
Set
(
diffNoTurn
)
...
...
@@ -356,7 +356,7 @@ func (c *Bor) verifyCascadingFields(chain consensus.ChainReader, header *types.H
if
parent
==
nil
||
parent
.
Number
.
Uint64
()
!=
number
-
1
||
parent
.
Hash
()
!=
header
.
ParentHash
{
return
consensus
.
ErrUnknownAncestor
}
if
parent
.
Time
+
c
.
config
.
BlockInterval
>
header
.
Time
{
if
parent
.
Time
+
c
.
config
.
Period
>
header
.
Time
{
return
ErrInvalidTimestamp
}
// Retrieve the snapshot needed to verify this header and cache it
...
...
@@ -500,13 +500,13 @@ func (c *Bor) verifySeal(chain consensus.ChainReader, header *types.Header, pare
if
recent
==
signer
{
// Signer is among recents, only fail if the current block doesn't shift it out
if
limit
:=
uint64
(
len
(
snap
.
Signers
)
/
2
+
1
);
seen
>
number
-
limit
{
return
errRecentlySigned
//
return errRecentlySigned
}
}
}
// Ensure that the difficulty corresponds to the turn-ness of the signer
if
!
c
.
fakeDiff
{
inturn
:=
snap
.
inturn
(
header
.
Number
.
Uint64
(),
signer
)
inturn
:=
snap
.
inturn
(
header
.
Number
.
Uint64
(),
signer
,
c
.
config
.
ProducerInterval
)
if
inturn
&&
header
.
Difficulty
.
Cmp
(
diffInTurn
)
!=
0
{
return
errWrongDifficulty
}
...
...
@@ -514,6 +514,7 @@ func (c *Bor) verifySeal(chain consensus.ChainReader, header *types.Header, pare
return
errWrongDifficulty
}
}
return
nil
}
...
...
@@ -552,7 +553,7 @@ func (c *Bor) Prepare(chain consensus.ChainReader, header *types.Header) error {
c
.
lock
.
RUnlock
()
}
// Set the correct difficulty
header
.
Difficulty
=
CalcDifficulty
(
snap
,
c
.
signer
)
header
.
Difficulty
=
CalcDifficulty
(
snap
,
c
.
signer
,
c
.
config
.
ProducerInterval
)
// Ensure the extra data has all it's components
if
len
(
header
.
Extra
)
<
extraVanity
{
...
...
@@ -575,7 +576,7 @@ func (c *Bor) Prepare(chain consensus.ChainReader, header *types.Header) error {
if
parent
==
nil
{
return
consensus
.
ErrUnknownAncestor
}
header
.
Time
=
parent
.
Time
+
c
.
config
.
BlockInterval
header
.
Time
=
parent
.
Time
+
c
.
config
.
Period
if
header
.
Time
<
uint64
(
time
.
Now
()
.
Unix
())
{
header
.
Time
=
uint64
(
time
.
Now
()
.
Unix
())
}
...
...
@@ -622,7 +623,7 @@ func (c *Bor) Seal(chain consensus.ChainReader, block *types.Block, results chan
return
errUnknownBlock
}
// For 0-period chains, refuse to seal empty blocks (no reward but would spin sealing)
if
c
.
config
.
BlockInterval
==
0
&&
len
(
block
.
Transactions
())
==
0
{
if
c
.
config
.
Period
==
0
&&
len
(
block
.
Transactions
())
==
0
{
log
.
Info
(
"Sealing paused, waiting for transactions"
)
return
nil
}
...
...
@@ -645,7 +646,7 @@ func (c *Bor) Seal(chain consensus.ChainReader, block *types.Block, results chan
// Signer is among recents, only wait if the current block doesn't shift it out
if
limit
:=
uint64
(
len
(
snap
.
Signers
)
/
2
+
1
);
number
<
limit
||
seen
>
number
-
limit
{
log
.
Info
(
"Signed recently, must wait for others"
)
return
nil
//
return nil
}
}
}
...
...
@@ -687,7 +688,11 @@ func (c *Bor) Seal(chain consensus.ChainReader, block *types.Block, results chan
// that a new block should have based on the previous blocks in the chain and the
// current signer.
func
(
c
*
Bor
)
CalcDifficulty
(
chain
consensus
.
ChainReader
,
time
uint64
,
parent
*
types
.
Header
)
*
big
.
Int
{
return
big
.
NewInt
(
0
)
snap
,
err
:=
c
.
snapshot
(
chain
,
parent
.
Number
.
Uint64
(),
parent
.
Hash
(),
nil
)
if
err
!=
nil
{
return
nil
}
return
CalcDifficulty
(
snap
,
c
.
signer
,
c
.
config
.
ProducerInterval
)
}
// SealHash returns the hash of a block prior to it being sealed.
...
...
This diff is collapsed.
Click to expand it.
consensus/bor/snapshot.go
+
3
−
3
View file @
f37d07db
...
...
@@ -218,7 +218,7 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
}
for
_
,
recent
:=
range
snap
.
Recents
{
if
recent
==
signer
{
return
nil
,
errRecentlySigned
//
return nil, errRecentlySigned
}
}
snap
.
Recents
[
number
]
=
signer
...
...
@@ -303,10 +303,10 @@ func (s *Snapshot) signers() []common.Address {
}
// inturn returns if a signer at a given block height is in-turn or not.
func
(
s
*
Snapshot
)
inturn
(
number
uint64
,
signer
common
.
Address
)
bool
{
func
(
s
*
Snapshot
)
inturn
(
number
uint64
,
signer
common
.
Address
,
producerPeriod
uint64
)
bool
{
signers
,
offset
:=
s
.
signers
(),
0
for
offset
<
len
(
signers
)
&&
signers
[
offset
]
!=
signer
{
offset
++
}
return
(
number
%
uint64
(
len
(
signers
)))
==
uint64
(
offset
)
return
(
(
number
/
producerPeriod
)
%
uint64
(
len
(
signers
)))
==
uint64
(
offset
)
}
This diff is collapsed.
Click to expand it.
params/config.go
+
1
−
1
View file @
f37d07db
...
...
@@ -228,7 +228,7 @@ func (c *CliqueConfig) String() string {
// BorConfig is the consensus engine configs for Matic bor based sealing.
type
BorConfig
struct
{
BlockInterval
uint64
`json:"
blockInterval"`
// Number of seconds between blocks to enforce
Period
uint64
`json:"
period"`
// Number of seconds between blocks to enforce
ProducerInterval
uint64
`json:"producerInterval"`
// Number of seconds between change in block producer interval to enforce
Epoch
uint64
`json:"epoch"`
// Epoch length to reset votes and checkpoint
}
...
...
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