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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
github
maticnetwork
bor
Commits
a5ba992b
Commit
a5ba992b
authored
4 years ago
by
ptsayli@gmail.com
Browse files
Options
Downloads
Patches
Plain Diff
fix: handle multiple state sync events
parent
dfe6a86d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
consensus/bor/bor.go
+6
-5
6 additions, 5 deletions
consensus/bor/bor.go
core/blockchain.go
+2
-2
2 additions, 2 deletions
core/blockchain.go
core/types/block.go
+8
-8
8 additions, 8 deletions
core/types/block.go
with
16 additions
and
15 deletions
consensus/bor/bor.go
+
6
−
5
View file @
a5ba992b
...
@@ -682,7 +682,7 @@ func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state
...
@@ -682,7 +682,7 @@ func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state
// FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set,
// FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set,
// nor block rewards given, and returns the final block.
// nor block rewards given, and returns the final block.
func
(
c
*
Bor
)
FinalizeAndAssemble
(
chain
consensus
.
ChainReader
,
header
*
types
.
Header
,
state
*
state
.
StateDB
,
txs
[]
*
types
.
Transaction
,
uncles
[]
*
types
.
Header
,
receipts
[]
*
types
.
Receipt
)
(
*
types
.
Block
,
error
)
{
func
(
c
*
Bor
)
FinalizeAndAssemble
(
chain
consensus
.
ChainReader
,
header
*
types
.
Header
,
state
*
state
.
StateDB
,
txs
[]
*
types
.
Transaction
,
uncles
[]
*
types
.
Header
,
receipts
[]
*
types
.
Receipt
)
(
*
types
.
Block
,
error
)
{
stateSyncData
:=
&
types
.
StateData
{}
stateSyncData
:=
[]
*
types
.
StateData
{}
headerNumber
:=
header
.
Number
.
Uint64
()
headerNumber
:=
header
.
Number
.
Uint64
()
if
headerNumber
%
c
.
config
.
Sprint
==
0
{
if
headerNumber
%
c
.
config
.
Sprint
==
0
{
cx
:=
chainContext
{
Chain
:
chain
,
Bor
:
c
}
cx
:=
chainContext
{
Chain
:
chain
,
Bor
:
c
}
...
@@ -1093,8 +1093,8 @@ func (c *Bor) CommitStates(
...
@@ -1093,8 +1093,8 @@ func (c *Bor) CommitStates(
state
*
state
.
StateDB
,
state
*
state
.
StateDB
,
header
*
types
.
Header
,
header
*
types
.
Header
,
chain
chainContext
,
chain
chainContext
,
)
(
*
types
.
StateData
,
error
)
{
)
(
[]
*
types
.
StateData
,
error
)
{
var
state
Data
types
.
StateData
state
Syncs
:=
make
([]
*
types
.
StateData
,
0
)
number
:=
header
.
Number
.
Uint64
()
number
:=
header
.
Number
.
Uint64
()
_lastStateID
,
err
:=
c
.
GenesisContractsClient
.
LastStateId
(
number
-
1
)
_lastStateID
,
err
:=
c
.
GenesisContractsClient
.
LastStateId
(
number
-
1
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -1119,19 +1119,20 @@ func (c *Bor) CommitStates(
...
@@ -1119,19 +1119,20 @@ func (c *Bor) CommitStates(
break
break
}
}
stateData
=
types
.
StateData
{
stateData
:
=
types
.
StateData
{
Did
:
eventRecord
.
ID
,
Did
:
eventRecord
.
ID
,
Contract
:
eventRecord
.
Contract
,
Contract
:
eventRecord
.
Contract
,
Data
:
hex
.
EncodeToString
(
eventRecord
.
Data
),
Data
:
hex
.
EncodeToString
(
eventRecord
.
Data
),
TxHash
:
eventRecord
.
TxHash
,
TxHash
:
eventRecord
.
TxHash
,
}
}
stateSyncs
=
append
(
stateSyncs
,
&
stateData
)
if
err
:=
c
.
GenesisContractsClient
.
CommitState
(
eventRecord
,
state
,
header
,
chain
);
err
!=
nil
{
if
err
:=
c
.
GenesisContractsClient
.
CommitState
(
eventRecord
,
state
,
header
,
chain
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
lastStateID
++
lastStateID
++
}
}
return
&
state
Data
,
nil
return
state
Syncs
,
nil
}
}
func
validateEventRecord
(
eventRecord
*
EventRecordWithTime
,
number
uint64
,
to
time
.
Time
,
lastStateID
uint64
,
chainID
string
)
error
{
func
validateEventRecord
(
eventRecord
*
EventRecordWithTime
,
number
uint64
,
to
time
.
Time
,
lastStateID
uint64
,
chainID
string
)
error
{
...
...
This diff is collapsed.
Click to expand it.
core/blockchain.go
+
2
−
2
View file @
a5ba992b
...
@@ -1544,8 +1544,8 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
...
@@ -1544,8 +1544,8 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
}
}
syncData
:=
block
.
StateSyncData
()
syncData
:=
block
.
StateSyncData
()
// TODO: add emitStateSyncEvent flag check
// TODO: add emitStateSyncEvent flag check
if
syncData
.
Did
!=
0
{
for
_
,
data
:=
range
syncData
{
bc
.
stateSyncFeed
.
Send
(
StateSyncEvent
{
StateData
:
syncD
ata
})
bc
.
stateSyncFeed
.
Send
(
StateSyncEvent
{
StateData
:
d
ata
})
}
}
}
else
{
}
else
{
bc
.
chainSideFeed
.
Send
(
ChainSideEvent
{
Block
:
block
})
bc
.
chainSideFeed
.
Send
(
ChainSideEvent
{
Block
:
block
})
...
...
This diff is collapsed.
Click to expand it.
core/types/block.go
+
8
−
8
View file @
a5ba992b
...
@@ -159,7 +159,7 @@ type Block struct {
...
@@ -159,7 +159,7 @@ type Block struct {
header
*
Header
header
*
Header
uncles
[]
*
Header
uncles
[]
*
Header
transactions
Transactions
transactions
Transactions
stateSyncData
*
StateData
stateSyncData
[]
*
StateData
// caches
// caches
hash
atomic
.
Value
hash
atomic
.
Value
size
atomic
.
Value
size
atomic
.
Value
...
@@ -267,7 +267,7 @@ func CopyHeader(h *Header) *Header {
...
@@ -267,7 +267,7 @@ func CopyHeader(h *Header) *Header {
}
}
// SetStateSync set sync data in block
// SetStateSync set sync data in block
func
(
b
*
Block
)
SetStateSync
(
stateData
*
StateData
)
{
func
(
b
*
Block
)
SetStateSync
(
stateData
[]
*
StateData
)
{
b
.
stateSyncData
=
stateData
b
.
stateSyncData
=
stateData
}
}
...
@@ -316,12 +316,12 @@ func (b *Block) Transaction(hash common.Hash) *Transaction {
...
@@ -316,12 +316,12 @@ func (b *Block) Transaction(hash common.Hash) *Transaction {
return
nil
return
nil
}
}
func
(
b
*
Block
)
Number
()
*
big
.
Int
{
return
new
(
big
.
Int
)
.
Set
(
b
.
header
.
Number
)
}
func
(
b
*
Block
)
Number
()
*
big
.
Int
{
return
new
(
big
.
Int
)
.
Set
(
b
.
header
.
Number
)
}
func
(
b
*
Block
)
GasLimit
()
uint64
{
return
b
.
header
.
GasLimit
}
func
(
b
*
Block
)
GasLimit
()
uint64
{
return
b
.
header
.
GasLimit
}
func
(
b
*
Block
)
GasUsed
()
uint64
{
return
b
.
header
.
GasUsed
}
func
(
b
*
Block
)
GasUsed
()
uint64
{
return
b
.
header
.
GasUsed
}
func
(
b
*
Block
)
Difficulty
()
*
big
.
Int
{
return
new
(
big
.
Int
)
.
Set
(
b
.
header
.
Difficulty
)
}
func
(
b
*
Block
)
Difficulty
()
*
big
.
Int
{
return
new
(
big
.
Int
)
.
Set
(
b
.
header
.
Difficulty
)
}
func
(
b
*
Block
)
Time
()
uint64
{
return
b
.
header
.
Time
}
func
(
b
*
Block
)
Time
()
uint64
{
return
b
.
header
.
Time
}
func
(
b
*
Block
)
StateSyncData
()
*
StateData
{
return
b
.
stateSyncData
}
func
(
b
*
Block
)
StateSyncData
()
[]
*
StateData
{
return
b
.
stateSyncData
}
func
(
b
*
Block
)
NumberU64
()
uint64
{
return
b
.
header
.
Number
.
Uint64
()
}
func
(
b
*
Block
)
NumberU64
()
uint64
{
return
b
.
header
.
Number
.
Uint64
()
}
func
(
b
*
Block
)
MixDigest
()
common
.
Hash
{
return
b
.
header
.
MixDigest
}
func
(
b
*
Block
)
MixDigest
()
common
.
Hash
{
return
b
.
header
.
MixDigest
}
...
...
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