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
Merge requests
!210
wip: blockchain: local validation
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Closed
wip: blockchain: local validation
jawaka-146-dubp-local-validation
into
dev
Overview
1
Commits
7
Pipelines
0
Changes
10
Closed
Éloïs
requested to merge
jawaka-146-dubp-local-validation
into
dev
5 years ago
Overview
1
Commits
7
Pipelines
0
Changes
10
Closes
#146 (closed)
0
0
Merge request reports
Compare
dev
version 3
4358d7c3
5 years ago
version 2
afa8ca4d
5 years ago
version 1
d1ccce14
5 years ago
dev (base)
and
latest version
latest version
c32d1ac6
7 commits,
5 years ago
version 3
4358d7c3
6 commits,
5 years ago
version 2
afa8ca4d
4 commits,
5 years ago
version 1
d1ccce14
1 commit,
5 years ago
10 files
+
1423
−
11
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
10
lib/modules/blockchain/blockchain/src/dubp/check/global.rs
0 → 100644
+
73
−
0
View file @ c32d1ac6
// Copyright (C) 2017-2019 The AXIOM TEAM Association.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Sub-module checking if a block complies with all the rules of the (DUBP DUniter Blockchain Protocol).
use
crate
::
dubp
::
BlockError
;
use
dubp_block_doc
::
block
::{
BlockDocument
,
BlockDocumentTrait
};
use
dubp_common_doc
::
traits
::
Document
;
use
dubp_common_doc
::
BlockNumber
;
use
dup_crypto
::
keys
::
PubKey
;
use
durs_bc_db_reader
::
DbReadable
;
use
durs_bc_db_reader
::
DbReader
;
use
durs_bc_db_writer
::
BinFreeStructDb
;
use
durs_wot
::
*
;
use
std
::
collections
::
HashMap
;
#[derive(Debug,
Copy,
Clone)]
pub
enum
GlobalVerifyBlockError
{
NoPreviousBlock
,
VersionDecrease
,
}
pub
fn
verify_global_validity_block
<
DB
,
R
,
W
>
(
block
:
&
BlockDocument
,
db
:
&
DB
,
r
:
&
R
,
_wot_index
:
&
HashMap
<
PubKey
,
WotId
>
,
_wot_db
:
&
BinFreeStructDb
<
W
>
,
)
->
Result
<
(),
BlockError
>
where
DB
:
DbReadable
,
R
:
DbReader
,
W
:
WebOfTrust
,
{
// Rules that do not concern genesis block
if
block
.number
()
.0
>
0
{
// Get previous block
let
previous_block_opt
=
durs_bc_db_reader
::
blocks
::
get_block_in_local_blockchain
(
db
,
r
,
BlockNumber
(
block
.number
()
.0
-
1
),
)
?
;
// Previous block must exist
if
previous_block_opt
.is_none
()
{
return
Err
(
BlockError
::
InvalidBlock
(
super
::
InvalidBlockError
::
Global
(
GlobalVerifyBlockError
::
NoPreviousBlock
,
)));
}
let
previous_block
=
previous_block_opt
.expect
(
"safe unwrap"
);
// Block version must not decrease
if
previous_block
.version
()
>
block
.version
()
{
return
Err
(
BlockError
::
InvalidBlock
(
super
::
InvalidBlockError
::
Global
(
GlobalVerifyBlockError
::
VersionDecrease
,
)));
}
}
Ok
(())
}
Loading