Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Dunitrust
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nodes
rust
Dunitrust
Commits
0d80c5b9
Commit
0d80c5b9
authored
6 years ago
by
Pascal Engélibert
Browse files
Options
Downloads
Patches
Plain Diff
[ref] separate checks for block 0
parent
bb3ecf87
No related branches found
No related tags found
1 merge request
!117
WIP: Resolve "Add block checking (checking all rules of the unit protocol)"
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/modules/blockchain/blockchain/src/dubp/check/mod.rs
+77
-80
77 additions, 80 deletions
lib/modules/blockchain/blockchain/src/dubp/check/mod.rs
lib/modules/blockchain/blockchain/src/dubp/mod.rs
+12
-8
12 additions, 8 deletions
lib/modules/blockchain/blockchain/src/dubp/mod.rs
with
89 additions
and
88 deletions
lib/modules/blockchain/blockchain/src/dubp/check/mod.rs
+
77
−
80
View file @
0d80c5b9
...
@@ -55,16 +55,33 @@ fn invalid_rule_error(error: InvalidRuleError) -> BlockError {
...
@@ -55,16 +55,33 @@ fn invalid_rule_error(error: InvalidRuleError) -> BlockError {
BlockError
::
InvalidBlock
(
InvalidBlockError
::
InvalidRule
(
error
))
BlockError
::
InvalidBlock
(
InvalidBlockError
::
InvalidRule
(
error
))
}
}
pub
fn
verify_genesis_block_validity
(
block
:
&
BlockDocument
)
->
Result
<
(),
BlockError
>
{
// BR_G03 - previous issuer
if
block
.previous_issuer
!=
None
{
return
Err
(
invalid_rule_error
(
InvalidRuleError
::
WrongPreviousIssuer
));
}
// BR_G04 - issuers count
if
block
.issuers_count
!=
0
{
return
Err
(
invalid_rule_error
(
InvalidRuleError
::
WrongIssuersCount
));
}
// BR_G05 - issuers count
if
block
.issuers_frame
!=
1
{
return
Err
(
invalid_rule_error
(
InvalidRuleError
::
WrongIssuersFrame
));
}
Ok
(())
}
pub
fn
verify_block_validity
<
W
:
WebOfTrust
>
(
pub
fn
verify_block_validity
<
W
:
WebOfTrust
>
(
block
:
&
BlockDocument
,
block
:
&
BlockDocument
,
blockchain_db
:
&
BinDB
<
LocalBlockchainV10Datas
>
,
blockchain_db
:
&
BinDB
<
LocalBlockchainV10Datas
>
,
identities_db
:
&
BinDB
<
IdentitiesV10Datas
>
,
_certs_db
:
&
BinDB
<
CertsExpirV10Datas
>
,
_certs_db
:
&
BinDB
<
CertsExpirV10Datas
>
,
_wot_index
:
&
HashMap
<
PubKey
,
NodeId
>
,
_wot_index
:
&
HashMap
<
PubKey
,
NodeId
>
,
_wot_db
:
&
BinDB
<
W
>
,
_wot_db
:
&
BinDB
<
W
>
,
identities_db
:
&
BinDB
<
IdentitiesV10Datas
>
,
)
->
Result
<
(),
BlockError
>
{
)
->
Result
<
(),
BlockError
>
{
// Rules that do not concern genesis block
if
block
.number
.0
>
0
{
// Get previous block
// Get previous block
let
previous_block_opt
=
readers
::
block
::
get_block_in_local_blockchain
(
let
previous_block_opt
=
readers
::
block
::
get_block_in_local_blockchain
(
blockchain_db
,
blockchain_db
,
...
@@ -102,16 +119,14 @@ pub fn verify_block_validity<W: WebOfTrust>(
...
@@ -102,16 +119,14 @@ pub fn verify_block_validity<W: WebOfTrust>(
}
}
// BR_G04 - issuers count
// BR_G04 - issuers count
let
mut
issuers
:
Vec
<
PubKey
>
=
vec!
[];
let
issuers_frame
=
readers
::
block
::
get_current_frame
(
for
i
in
(
previous_block
.issuers_frame
as
u32
)
..=
previous_block
.number
.0
{
&
entities
::
block
::
DALBlock
{
let
issuer
=
readers
::
block
::
get_block_in_local_blockchain
(
blockchain_db
,
BlockId
(
i
))
?
block
:
block
.clone
(),
.expect
(
"safe unwrap"
)
expire_certs
:
None
,
.issuers
[
0
];
},
if
!
issuers
.contains
(
&
issuer
)
{
blockchain_db
,
issuers
.push
(
issuer
);
)
?
;
}
if
issuers_frame
.len
()
!=
block
.issuers_count
{
}
if
issuers
.len
()
!=
block
.issuers_count
{
return
Err
(
invalid_rule_error
(
InvalidRuleError
::
WrongIssuersCount
));
return
Err
(
invalid_rule_error
(
InvalidRuleError
::
WrongIssuersCount
));
}
}
...
@@ -126,24 +141,6 @@ pub fn verify_block_validity<W: WebOfTrust>(
...
@@ -126,24 +141,6 @@ pub fn verify_block_validity<W: WebOfTrust>(
{
{
return
Err
(
invalid_rule_error
(
InvalidRuleError
::
WrongIssuersFrame
));
return
Err
(
invalid_rule_error
(
InvalidRuleError
::
WrongIssuersFrame
));
}
}
}
// Only rules that do concern genesis block
else
{
// BR_G03 - previous issuer
if
block
.previous_issuer
!=
None
{
return
Err
(
invalid_rule_error
(
InvalidRuleError
::
WrongPreviousIssuer
));
}
// BR_G04 - issuers count
if
block
.issuers_count
!=
0
{
return
Err
(
invalid_rule_error
(
InvalidRuleError
::
WrongIssuersCount
));
}
// BR_G05 - issuers count
if
block
.issuers_frame
!=
1
{
return
Err
(
invalid_rule_error
(
InvalidRuleError
::
WrongIssuersFrame
));
}
}
Ok
(())
Ok
(())
}
}
This diff is collapsed.
Click to expand it.
lib/modules/blockchain/blockchain/src/dubp/mod.rs
+
12
−
8
View file @
0d80c5b9
...
@@ -92,14 +92,18 @@ pub fn check_and_apply_block(
...
@@ -92,14 +92,18 @@ pub fn check_and_apply_block(
)
?
;
)
?
;
// Verify block validity (check all protocol rule, very long !)
// Verify block validity (check all protocol rule, very long !)
if
block_doc
.number
.0
==
0
{
verify_genesis_block_validity
(
&
block_doc
)
?
;
}
else
{
verify_block_validity
(
verify_block_validity
(
&
block_doc
,
&
block_doc
,
&
bc
.blocks_databases.blockchain_db
,
&
bc
.blocks_databases.blockchain_db
,
&
bc
.wot_databases.identities_db
,
&
bc
.wot_databases.certs_db
,
&
bc
.wot_databases.certs_db
,
&
bc
.wot_index
,
&
bc
.wot_index
,
&
bc
.wot_databases.wot_db
,
&
bc
.wot_databases.wot_db
,
&
bc
.wot_databases.identities_db
,
)
?
;
)
?
;
}
Ok
(
CheckAndApplyBlockReturn
::
ValidBlock
(
apply_valid_block
(
Ok
(
CheckAndApplyBlockReturn
::
ValidBlock
(
apply_valid_block
(
block_doc
,
block_doc
,
...
...
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