Skip to content
Snippets Groups Projects
Commit e0bec026 authored by Éloïs's avatar Éloïs
Browse files

wip: #76

parent 03b6bc9e
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,27 @@ dependencies = [
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "backtrace"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace-sys 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "backtrace-sys"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "base58"
version = "0.1.0"
......@@ -72,6 +93,15 @@ dependencies = [
"serde 1.0.57 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bincode"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.57 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "0.9.1"
......@@ -229,6 +259,7 @@ dependencies = [
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"pbr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rustbreak 2.0.0-rc2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.57 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.57 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -278,6 +309,7 @@ dependencies = [
"base64 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.57 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.57 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -294,10 +326,10 @@ dependencies = [
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
"rustbreak 2.0.0-rc2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.57 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.57 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
"sqlite 0.23.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -312,6 +344,7 @@ dependencies = [
"regex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.57 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.57 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -419,6 +452,25 @@ name = "either"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "failure"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "failure_derive"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
"synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "foreign-types"
version = "0.3.2"
......@@ -716,6 +768,11 @@ dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quote"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "quote"
version = "0.5.2"
......@@ -838,6 +895,22 @@ dependencies = [
"time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustbreak"
version = "2.0.0-rc2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"base64 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bincode 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.57 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc-demangle"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustc-serialize"
version = "0.3.24"
......@@ -964,6 +1037,16 @@ name = "strsim"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "syn"
version = "0.11.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syn"
version = "0.13.10"
......@@ -974,6 +1057,23 @@ dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "synom"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "synstructure"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tempdir"
version = "0.3.7"
......@@ -1213,6 +1313,11 @@ name = "unicode-width"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-xid"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-xid"
version = "0.1.0"
......@@ -1330,11 +1435,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
"checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef"
"checksum atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2fc4a1aa4c24c0718a250f0681885c1af91419d242f29eb8f2ab28502d80dbd1"
"checksum backtrace 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dbdd17cd962b570302f5297aea8648d5923e22e555c2ed2d8b2e34eca646bf6d"
"checksum backtrace-sys 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)" = "bff67d0c06556c0b8e6b5f090f0eac52d950d9dfd1d35ba04e4ca3543eaf6a7e"
"checksum base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5024ee8015f02155eee35c711107ddd9a9bf3cb689cf2a9089c97e79b6e1ae83"
"checksum base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30e93c03064e7590d0466209155251b90c22e37fab1daf2771582598b5827557"
"checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9"
"checksum base64 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9263aa6a38da271eec5c91a83ce1e800f093c8535788d403d626d8d5c3f8f007"
"checksum bincode 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9a6301db0b49fb63551bc15b5ae348147101cdf323242b93ec7546d5002ff1af"
"checksum bincode 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bda13183df33055cbb84b847becce220d392df502ebe7a4a78d7021771ed94d0"
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789"
"checksum byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "74c0b906e9446b0a2e4f760cdb3fa4b2c48cdc6db8766a845c54b6ff063fd2e9"
......@@ -1353,6 +1461,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum crossbeam-utils 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d636a8b3bcc1b409d7ffd3facef8f21dcb4009626adbd0c5e6c4305c07253c7b"
"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
"checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0"
"checksum failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "934799b6c1de475a012a02dab0ace1ace43789ee4b99bcfbf1a2e3e8ced5de82"
"checksum failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cdda555bb90c9bb67a3b670a0f42de8e73f5981524123ad8578aafec8ddb8b"
"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
......@@ -1391,6 +1501,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831"
"checksum pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "110d5ee3593dbb73f56294327fe5668bcc997897097cbc76b51e7aed3f52452f"
"checksum proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1b06e2f335f48d24442b35a19df506a835fb3547bc3c06ef27340da9acf5cae7"
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9949cfe66888ffe1d53e6ec9d9f3b70714083854be20fd5e271b232a017401e8"
"checksum rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "15a732abf9d20f0ad8eeb6f909bf6868722d9a06e1e50802b6a70351f40b4eb1"
"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5"
......@@ -1404,6 +1515,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum regex-syntax 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8f1ac0f60d675cc6cf13a20ec076568254472551051ad5dd050364d70671bf6b"
"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
"checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a"
"checksum rustbreak 2.0.0-rc2 (registry+https://github.com/rust-lang/crates.io-index)" = "676cb04876f4391d5d2f2c9029d10cfe5fe28ad625ad8460531bed1191477083"
"checksum rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649"
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
"checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f"
"checksum schannel 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "85fd9df495640643ad2d00443b3d78aae69802ad488debab4f1dd52fc1806ade"
......@@ -1421,7 +1534,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum sqlite3-src 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "46e0bc115b563b1ee6c665ef895b56bf488522f57d1c6571887547c57c8f5a88"
"checksum sqlite3-sys 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71fec807a1534bd13eeaaec396175d67c79bdc68df55e18a452726ec62a8fb08"
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
"checksum syn 0.13.10 (registry+https://github.com/rust-lang/crates.io-index)" = "77961dcdac942fa8bc033c16f3a790b311c8a27d00811b878ebd8cf9b7ba39d5"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
"checksum synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a761d12e6d8dcb4dcf952a7a89b475e3a9d69e4a69307e01a470977642914bd"
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
"checksum term 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5e6b677dd1e8214ea1ef4297f85dbcbed8e8cdddb561040cc998ca2551c37561"
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
......@@ -1447,6 +1563,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
"checksum unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6a0180bc61fc5a987082bfa111f4cc95c4caff7f9799f3e46df09163a937aa25"
"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f"
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
"checksum url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f808aadd8cfec6ef90e4a14eb46f24511824d1ac596b9682703c87056c8678b7"
......
......@@ -20,6 +20,7 @@ duniter-wotb = { path = "../wotb" }
log = "0.4.1"
pbr = "1.0.1"
rand = "0.4.2"
rustbreak = {version = "2.0.0-rc2", features = ["bin_enc"]}
serde = "1.0.57"
serde_derive = "1.0.57"
serde_json = "1.0.17"
......
This diff is collapsed.
......@@ -20,23 +20,47 @@ extern crate duniter_wotb;
use duniter_crypto::keys::*;
use duniter_dal::block::{DALBlock, WotEvent};
use duniter_dal::writers::requests::DBWriteRequest;
use duniter_dal::sources::SourceAmount;
use duniter_dal::writers::requests::*;
use duniter_dal::ForkId;
use duniter_documents::blockchain::v10::documents::transaction::{TxAmount, TxBase};
use duniter_documents::blockchain::v10::documents::BlockDocument;
use duniter_documents::blockchain::Document;
use duniter_documents::BlockId;
use duniter_wotb::{NodeId, WebOfTrust};
use std::collections::HashMap;
use CompletedBlockError;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
/// Error returned by function try_stack_up_block()
pub enum TryStackBlockError {
/// Completed block error
CompletedBlockError(CompletedBlockError),
/// Unknow error
UnknowError(),
}
#[derive(Debug)]
/// Stores all queries to apply in database to "apply" the block
pub struct ValidBlockApplyReqs(
pub BlocksDBsWriteQuery,
pub Vec<WotsDBsWriteQuery>,
pub Vec<WotEvent>,
pub Vec<CurrencyDBsWriteQuery>,
);
pub fn try_stack_up_completed_block<W: WebOfTrust + Sync>(
block: &BlockDocument,
wotb_index: &HashMap<PubKey, NodeId>,
wot: &W,
) -> (bool, Vec<DBWriteRequest>, Vec<WotEvent>) {
expire_certs: &HashMap<(NodeId, NodeId), BlockId>,
) -> Result<ValidBlockApplyReqs, TryStackBlockError> {
debug!(
"BlockchainModule : try stack up complete block {}",
block.blockstamp()
);
let mut db_requests = Vec::new();
let mut wot_dbs_requests = Vec::new();
let mut currency_dbs_requests = Vec::new();
let mut wot_events = Vec::new();
let mut wot_copy: W = wot.clone();
let mut wotb_index_copy: HashMap<PubKey, NodeId> = wotb_index.clone();
......@@ -53,21 +77,23 @@ pub fn try_stack_up_completed_block<W: WebOfTrust + Sync>(
wot_events.push(WotEvent::AddNode(pubkey, wotb_id));
wot_copy.add_node();
wotb_index_copy.insert(pubkey, wotb_id);
db_requests.push(DBWriteRequest::CreateIdentity(
wot_dbs_requests.push(WotsDBsWriteQuery::CreateIdentity(
wotb_id,
current_blockstamp,
block.median_time,
Box::new(idty_doc.clone()),
joiner.blockstamp().id,
));
} else {
// Renewer
let wotb_id = wotb_index_copy[&joiner.issuers()[0]];
wot_events.push(WotEvent::EnableNode(wotb_id));
wot_copy.set_enabled(wotb_id, true);
db_requests.push(DBWriteRequest::RenewalIdentity(
wot_dbs_requests.push(WotsDBsWriteQuery::RenewalIdentity(
joiner.issuers()[0],
block.blockstamp(),
wotb_id,
block.median_time,
joiner.blockstamp().id,
));
}
}
......@@ -77,32 +103,35 @@ pub fn try_stack_up_completed_block<W: WebOfTrust + Sync>(
let wotb_id = wotb_index_copy[&pubkey];
wot_events.push(WotEvent::EnableNode(wotb_id));
wot_copy.set_enabled(wotb_id, true);
db_requests.push(DBWriteRequest::RenewalIdentity(
wot_dbs_requests.push(WotsDBsWriteQuery::RenewalIdentity(
pubkey,
block.blockstamp(),
wotb_id,
block.median_time,
active.blockstamp().id,
));
}
}
for exclusion in block.excluded.clone() {
let wotb_id = wotb_index_copy[&exclusion];
wot_events.push(WotEvent::DisableNode(wotb_id));
wot_copy.set_enabled(wotb_id, false);
db_requests.push(DBWriteRequest::ExcludeIdentity(
wotb_id,
let wotb_id = wotb_index
.get(&exclusion)
.expect("Fatal error : try to exclude unknow wotb_id !");
wot_events.push(WotEvent::DisableNode(*wotb_id));
wot_copy.set_enabled(*wotb_id, false);
wot_dbs_requests.push(WotsDBsWriteQuery::ExcludeIdentity(
exclusion,
block.blockstamp(),
block.median_time,
));
}
for revocation in block.revoked.clone() {
let compact_revoc = revocation.to_compact_document();
let wotb_id = wotb_index_copy[&compact_revoc.issuer];
wot_events.push(WotEvent::DisableNode(wotb_id));
wot_copy.set_enabled(wotb_id, false);
db_requests.push(DBWriteRequest::RevokeIdentity(
wotb_id,
let wotb_id = wotb_index
.get(&compact_revoc.issuer)
.expect("Fatal error : try to revoke unknow wotb_id !");
wot_events.push(WotEvent::DisableNode(*wotb_id));
wot_copy.set_enabled(*wotb_id, false);
wot_dbs_requests.push(WotsDBsWriteQuery::RevokeIdentity(
compact_revoc.issuer,
block.blockstamp(),
block.median_time,
));
}
for certification in block.certifications.clone() {
......@@ -112,13 +141,41 @@ pub fn try_stack_up_completed_block<W: WebOfTrust + Sync>(
let wotb_node_to = wotb_index_copy[&compact_cert.target];
wot_events.push(WotEvent::AddLink(wotb_node_from, wotb_node_to));
wot_copy.add_link(wotb_node_from, wotb_node_to);
db_requests.push(DBWriteRequest::CreateCert(
block.blockstamp(),
wot_dbs_requests.push(WotsDBsWriteQuery::CreateCert(
compact_cert.issuer,
wotb_node_from,
wotb_node_to,
compact_cert.block_number,
block.median_time,
compact_cert,
));
trace!("try_stack_up_completed_block: apply cert...success.");
}
for ((source, target), created_block_id) in expire_certs {
wot_dbs_requests.push(WotsDBsWriteQuery::ExpireCert(
*source,
*target,
*created_block_id,
));
}
if let Some(du_amount) = block.dividend {
if du_amount > 0 {
let members_wot_ids = wot_copy.get_enabled();
let mut members_pubkeys = Vec::new();
for (pubkey, wotb_id) in &wotb_index_copy {
if members_wot_ids.contains(wotb_id) {
members_pubkeys.push(*pubkey);
}
}
currency_dbs_requests.push(CurrencyDBsWriteQuery::CreateDU(
SourceAmount(TxAmount(du_amount as isize), TxBase(block.unit_base)),
block.number,
members_pubkeys,
));
}
}
for tx in block.transactions.clone() {
currency_dbs_requests.push(CurrencyDBsWriteQuery::WriteTx(Box::new(tx.unwrap_doc())));
}
/*// Calculate the state of the wot
if !wot_events.is_empty() && verif_level != SyncVerificationLevel::FastSync() {
......@@ -142,6 +199,7 @@ pub fn try_stack_up_completed_block<W: WebOfTrust + Sync>(
let average_centrality =
(centralities.iter().sum::<u64>() as f64 / centralities.len() as f64) as usize;
// Register the state of the wot
let max_connectivity = currency_params.max_connectivity();
duniter_dal::register_wot_state(
db,
&WotState {
......@@ -155,8 +213,8 @@ pub fn try_stack_up_completed_block<W: WebOfTrust + Sync>(
connectivities: connectivities
.iter()
.map(|c| {
if *c > *G1_CONNECTIVITY_MAX {
*G1_CONNECTIVITY_MAX
if *c > max_connectivity {
max_connectivity
} else {
*c
}
......@@ -167,12 +225,20 @@ pub fn try_stack_up_completed_block<W: WebOfTrust + Sync>(
},
);
}*/
// Write block in bdd
db_requests.push(DBWriteRequest::WriteBlock(Box::new(DALBlock {
block: block.clone(),
fork: 0,
// Create DALBlock
let mut block = block.clone();
block.reduce();
let dal_block = DALBlock {
block,
fork_id: ForkId(0),
isolate: false,
})));
(true, db_requests, wot_events)
expire_certs: Some(expire_certs.clone()),
};
// Return DBs requests
Ok(ValidBlockApplyReqs(
BlocksDBsWriteQuery::WriteBlock(Box::new(dal_block)),
wot_dbs_requests,
wot_events,
currency_dbs_requests,
))
}
This diff is collapsed.
// Copyright (C) 2018 The Duniter Project Developers.
//
// 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/>.
extern crate serde_json;
extern crate sqlite;
use duniter_crypto::keys::*;
use duniter_documents::blockchain::v10::documents::block::{
BlockV10Parameters, CurrencyName, TxDocOrTxHash,
};
use duniter_documents::blockchain::v10::documents::identity::IdentityDocumentBuilder;
use duniter_documents::blockchain::v10::documents::membership::*;
use duniter_documents::blockchain::v10::documents::transaction::*;
use duniter_documents::blockchain::v10::documents::*;
use duniter_documents::blockchain::DocumentBuilder;
use duniter_documents::{BlockHash, BlockId, Blockstamp, Hash};
use duniter_network::{NetworkBlock, NetworkBlockV10};
use std::str::FromStr;
use sync::BlockHeader;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
/// MembershipParseError
pub enum MembershipParseError {
WrongFormat(),
}
/// Parse a block from duniter-ts database
pub fn parse_ts_block(row: &[sqlite::Value]) -> NetworkBlock {
let current_header = BlockHeader {
number: BlockId(row[16].as_integer().expect("Fail to parse block number") as u32),
hash: BlockHash(
Hash::from_hex(row[0].as_string().expect("Fail to parse block hash"))
.expect("Fail to parse block hash (2)"),
),
issuer: PubKey::Ed25519(
ed25519::PublicKey::from_base58(
row[4].as_string().expect("Fail to parse block issuer"),
).expect("Failt to parse block issuer (2)"),
),
};
let previous_header = if current_header.number.0 > 0 {
Some(BlockHeader {
number: BlockId(current_header.number.0 - 1),
hash: BlockHash(
Hash::from_hex(
row[6]
.as_string()
.expect("Fail to parse block previous hash"),
).expect("Fail to parse block previous hash (2)"),
),
issuer: PubKey::Ed25519(
ed25519::PublicKey::from_base58(
row[7]
.as_string()
.expect("Fail to parse previous block issuer"),
).expect("Fail to parse previous block issuer (2)"),
),
})
} else {
None
};
let currency = row[3].as_string().expect("Fail to parse currency");
let parameters = if let Some(params_str) = row[5].as_string() {
if let Ok(params) = BlockV10Parameters::from_str(params_str) {
Some(params)
} else {
None
}
} else {
None
};
let dividend = match row[12].as_integer() {
Some(dividend) => Some(dividend as usize),
None => None,
};
let json_identities: serde_json::Value = serde_json::from_str(
row[20].as_string().expect("Fail to parse block identities"),
).expect("Fail to parse block identities (2)");
let mut identities = Vec::new();
for raw_idty in json_identities
.as_array()
.expect("Fail to parse block identities (3)")
{
identities
.push(parse_compact_identity(&currency, &raw_idty).expect("Fail to parse block idty"));
}
let json_txs: serde_json::Value = serde_json::from_str(
row[18].as_string().expect("Fail to parse block txs"),
).expect("Fail to parse block txs (2)");
let mut transactions = Vec::new();
for json_tx in json_txs.as_array().expect("Fail to parse block txs (3)") {
transactions.push(TxDocOrTxHash::TxDoc(Box::new(
parse_transaction(currency, &json_tx).expect("Fail to parse block tx"),
)));
}
let previous_hash = match previous_header.clone() {
Some(previous_header_) => previous_header_.hash.0,
None => Hash::default(),
};
let previous_issuer = match previous_header {
Some(previous_header_) => Some(previous_header_.issuer),
None => None,
};
let excluded: serde_json::Value = serde_json::from_str(
row[25].as_string().expect("Fail to parse excluded"),
).expect("Fail to parse excluded (2)");
let uncompleted_block_doc = BlockDocument {
nonce: row[17].as_integer().expect("Fail to parse nonce") as u64,
number: current_header.number,
pow_min: row[15].as_integer().expect("Fail to parse pow_min") as usize,
time: row[14].as_integer().expect("Fail to parse time") as u64,
median_time: row[11].as_integer().expect("Fail to parse median_time") as u64,
members_count: row[9].as_integer().expect("Fail to parse members_count") as usize,
monetary_mass: row[10]
.as_string()
.expect("Fail to parse monetary_mass")
.parse()
.expect("Fail to parse monetary_mass (2)"),
unit_base: row[13].as_integer().expect("Fail to parse unit_base") as usize,
issuers_count: row[28].as_integer().expect("Fail to parse issuers_count") as usize,
issuers_frame: row[26].as_integer().expect("Fail to parse issuers_frame") as isize,
issuers_frame_var: row[27]
.as_integer()
.expect("Fail to parse issuers_frame_var") as isize,
currency: CurrencyName(String::from(currency)),
issuers: vec![PubKey::Ed25519(
ed25519::PublicKey::from_base58(row[4].as_string().expect("Fail to parse issuer"))
.expect("Fail to parse issuer '2)"),
)],
signatures: vec![Sig::Ed25519(
ed25519::Signature::from_base64(row[2].as_string().expect("Fail to parse signature"))
.expect("Fail to parse signature (2)"),
)],
hash: Some(current_header.hash),
parameters,
previous_hash,
previous_issuer,
inner_hash: Some(
Hash::from_hex(row[1].as_string().expect("Fail to parse block inner_hash"))
.expect("Fail to parse block inner_hash (2)"),
),
dividend,
identities,
joiners: parse_memberships(
currency,
MembershipType::In(),
row[21].as_string().expect("Fail to parse joiners"),
).expect("Fail to parse joiners (2)"),
actives: parse_memberships(
currency,
MembershipType::In(),
row[22].as_string().expect("Fail to parse actives"),
).expect("Fail to parse actives (2)"),
leavers: parse_memberships(
currency,
MembershipType::In(),
row[23].as_string().expect("Fail to parse leavers"),
).expect("Fail to parse leavers (2)"),
revoked: Vec::new(),
excluded: excluded
.as_array()
.expect("Fail to parse excluded (3)")
.to_vec()
.into_iter()
.map(|e| {
PubKey::Ed25519(
ed25519::PublicKey::from_base58(
e.as_str().expect("Fail to parse excluded (4)"),
).expect("Fail to parse excluded (5)"),
)
})
.collect(),
certifications: Vec::new(),
transactions,
inner_hash_and_nonce_str: String::new(),
};
let revoked: serde_json::Value = serde_json::from_str(
row[24].as_string().expect("Fail to parse revoked"),
).expect("Fail to parse revoked (2)");
let certifications: serde_json::Value = serde_json::from_str(
row[19].as_string().expect("Fail to parse certifications"),
).expect("Fail to parse certifications (2)");
// return NetworkBlock
NetworkBlock::V10(Box::new(NetworkBlockV10 {
uncompleted_block_doc,
revoked: revoked
.as_array()
.expect("Fail to parse revoked (3)")
.to_vec(),
certifications: certifications
.as_array()
.expect("Fail to parse certifications (3)")
.to_vec(),
}))
}
/// Parse a compact identity
pub fn parse_compact_identity(
currency: &str,
source: &serde_json::Value,
) -> Option<IdentityDocument> {
if source.is_string() {
let idty_elements: Vec<&str> = source.as_str().unwrap().split(':').collect();
let issuer = match ed25519::PublicKey::from_base58(idty_elements[0]) {
Ok(pubkey) => PubKey::Ed25519(pubkey),
Err(_) => return None,
};
let signature = match ed25519::Signature::from_base64(idty_elements[1]) {
Ok(sig) => Sig::Ed25519(sig),
Err(_) => return None,
};
let blockstamp = match Blockstamp::from_string(idty_elements[2]) {
Ok(blockstamp) => blockstamp,
Err(_) => return None,
};
let username = idty_elements[3];
let idty_doc_builder = IdentityDocumentBuilder {
currency,
username,
blockstamp: &blockstamp,
issuer: &issuer,
};
Some(idty_doc_builder.build_with_signature(vec![signature]))
} else {
None
}
}
/// Parse memberships documents from json string
pub fn parse_memberships(
currency: &str,
membership_type: MembershipType,
json_datas: &str,
) -> Option<Vec<MembershipDocument>> {
let raw_memberships: serde_json::Value = serde_json::from_str(json_datas).unwrap();
if raw_memberships.is_array() {
return Some(
parse_memberships_from_json_value(
currency,
membership_type,
raw_memberships.as_array().unwrap(),
).iter()
.map(|m| {
m.clone()
.expect("Fatal error : Fail to parse membership from local DB !")
})
.collect(),
);
}
None
}
/// Parse memberships documents from array of json values
pub fn parse_memberships_from_json_value(
currency: &str,
membership_type: MembershipType,
array_memberships: &[serde_json::Value],
) -> Vec<Result<MembershipDocument, MembershipParseError>> {
//let memberships: Vec<MembershipDocument> = Vec::new();
array_memberships
.iter()
.map(|membership| {
let membership_datas: Vec<&str> = membership.as_str().unwrap().split(':').collect();
if membership_datas.len() == 5 {
let membership_doc_builder = MembershipDocumentBuilder {
currency,
issuer: &PubKey::Ed25519(
ed25519::PublicKey::from_base58(membership_datas[0]).unwrap(),
),
blockstamp: &Blockstamp::from_string(membership_datas[2]).unwrap(),
membership: membership_type,
identity_username: membership_datas[4],
identity_blockstamp: &Blockstamp::from_string(membership_datas[3]).unwrap(),
};
let membership_sig =
Sig::Ed25519(ed25519::Signature::from_base64(membership_datas[1]).unwrap());
Ok(membership_doc_builder.build_with_signature(vec![membership_sig]))
} else {
Err(MembershipParseError::WrongFormat())
}
})
.collect()
}
/// Parse transaction from json value
pub fn parse_transaction(
currency: &str,
source: &serde_json::Value,
) -> Option<TransactionDocument> {
//debug!("transaction={:#?}", source);
let blockstamp = match Blockstamp::from_string(source.get("blockstamp")?.as_str()?) {
Ok(blockstamp) => blockstamp,
Err(_) => {
return None;
}
};
let locktime = source.get("locktime")?.as_i64()? as u64;
let issuers_array = source.get("issuers")?.as_array()?;
let mut issuers = Vec::with_capacity(issuers_array.len());
for issuer in issuers_array {
match ed25519::PublicKey::from_base58(issuer.as_str()?) {
Ok(pubkey) => issuers.push(PubKey::Ed25519(pubkey)),
Err(_) => {
return None;
}
}
}
let inputs_array = source.get("inputs")?.as_array()?;
let mut inputs = Vec::with_capacity(inputs_array.len());
for input in inputs_array {
let input_str = input.as_str()?;
match TransactionInput::parse_from_str(input_str) {
Ok(input) => inputs.push(input),
Err(_) => {
return None;
}
}
}
let unlocks_array = source.get("unlocks")?.as_array()?;
let mut unlocks = Vec::with_capacity(unlocks_array.len());
for unlock in unlocks_array {
match TransactionInputUnlocks::parse_from_str(unlock.as_str()?) {
Ok(unlock) => unlocks.push(unlock),
Err(_) => {
return None;
}
}
}
let outputs_array = source.get("outputs")?.as_array()?;
let mut outputs = Vec::with_capacity(outputs_array.len());
for output in outputs_array {
match TransactionOutput::parse_from_str(output.as_str()?) {
Ok(output) => outputs.push(output),
Err(_) => {
return None;
}
}
}
let signatures_array = source.get("signatures")?.as_array()?;
let mut signatures = Vec::with_capacity(signatures_array.len());
for signature in signatures_array {
match ed25519::Signature::from_base64(signature.as_str()?) {
Ok(signature) => signatures.push(Sig::Ed25519(signature)),
Err(_) => {
return None;
}
}
}
let comment = source.get("comment")?.as_str()?;
let tx_doc_builder = TransactionDocumentBuilder {
currency,
blockstamp: &blockstamp,
locktime: &locktime,
issuers: &issuers,
inputs: &inputs,
unlocks: &unlocks,
outputs: &outputs,
comment,
};
Some(tx_doc_builder.build_with_signature(signatures))
}
......@@ -327,19 +327,13 @@ pub fn write_conf_file(file_path: &PathBuf, conf: &DuniterConf) -> Result<(), st
}
/// Returns the path to the database containing the blockchain
pub fn get_db_path(profile: &str, currency: &Currency, sync: bool) -> PathBuf {
if sync {
let mut db_path = PathBuf::new();
let mut db_name = String::from(profile);
db_name.push_str("_durs.db");
db_path.push("/dev/shm");
db_path.push(db_name);
db_path
} else {
pub fn get_blockchain_db_path(profile: &str, currency: &Currency) -> PathBuf {
let mut db_path = datas_path(profile, &currency);
db_path.push("blockchain.db");
db_path
db_path.push("blockchain/");
if !db_path.as_path().exists() {
fs::create_dir(db_path.as_path()).expect("Impossible to create blockchain dir !");
}
db_path
}
/// Returns the path to the binary file containing the state of the web of trust
......
......@@ -38,7 +38,6 @@ extern crate simplelog;
extern crate sqlite;
extern crate threadpool;
use self::threadpool::ThreadPool;
use clap::{App, ArgMatches};
use duniter_blockchain::BlockchainModule;
use duniter_conf::DuniterKeyPairs;
......@@ -52,6 +51,7 @@ use std::fs::{File, OpenOptions};
use std::sync::mpsc;
use std::thread;
use std::time::Duration;
use threadpool::ThreadPool;
#[derive(Debug)]
/// Duniter Core Datas
......@@ -189,7 +189,6 @@ impl DuniterCore {
let mut blockchain_module = BlockchainModule::load_blockchain_conf(
&self.conf,
RequiredKeysContent::MemberKeyPair(None),
false,
);
info!("Success to load Blockchain module.");
......
......@@ -16,6 +16,7 @@ base58 = "0.1.0"
base64 = "0.9.1"
rust-crypto = "0.2.36"
serde = "1.0.57"
serde_derive = "1.0.57"
[features]
# Treat warnings as a build error.
......
......@@ -21,20 +21,17 @@
extern crate serde;
use std::collections::hash_map::DefaultHasher;
use std::fmt::Debug;
use std::fmt::Display;
use std::fmt::Error;
use std::fmt::Formatter;
use std::hash::{Hash, Hasher};
use self::serde::ser::{Serialize, Serializer};
use self::serde::de::{Deserialize, Deserializer, SeqAccess, Visitor};
use self::serde::ser::{Serialize, SerializeSeq, Serializer};
use super::{BaseConvertionError, PrivateKey as PrivateKeyMethods, PublicKey as PublicKeyMethods};
use base58::{FromBase58, FromBase58Error, ToBase58};
use base64;
use base64::DecodeError;
use crypto;
use super::{BaseConvertionError, PrivateKey as PrivateKeyMethods, PublicKey as PublicKeyMethods};
use std::collections::hash_map::DefaultHasher;
use std::fmt::{self, Debug, Display, Error, Formatter};
use std::hash::{Hash, Hasher};
use std::marker::PhantomData;
/// Store a ed25519 signature.
#[derive(Clone, Copy)]
......@@ -47,6 +44,73 @@ impl Hash for Signature {
}
}
impl Serialize for Signature {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut seq = serializer.serialize_seq(Some(64))?;
for e in self.0.iter() {
seq.serialize_element(e)?;
}
seq.end()
}
}
struct SignatureVisitor {
marker: PhantomData<fn() -> Signature>,
}
impl SignatureVisitor {
fn new() -> Self {
SignatureVisitor {
marker: PhantomData,
}
}
}
impl<'de> Visitor<'de> for SignatureVisitor {
// The type that our Visitor is going to produce.
type Value = Signature;
// Format a message stating what data this Visitor expects to receive.
fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
formatter.write_str("Signature datas")
}
// Deserialize Signature from an abstract "map" provided by the
// Deserializer. The MapAccess input is a callback provided by
// the Deserializer to let us see each entry in the map.
fn visit_seq<M>(self, mut access: M) -> Result<Self::Value, M::Error>
where
M: SeqAccess<'de>,
{
let mut map = Vec::with_capacity(access.size_hint().unwrap_or(0));
// While there are entries remaining in the input, add them
// into our map.
while let Some(value) = access.next_element()? {
map.push(value);
}
let mut sig_datas: [u8; 64] = [0; 64];
sig_datas.copy_from_slice(&map[0..64]);
Ok(Signature(sig_datas))
}
}
// This is the trait that informs Serde how to deserialize Signature.
impl<'de> Deserialize<'de> for Signature {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
// Instantiate our Visitor and ask the Deserializer to drive
// it over the input data, resulting in an instance of Signature.
deserializer.deserialize_seq(SignatureVisitor::new())
}
}
impl super::Signature for Signature {
fn from_base64(base64_data: &str) -> Result<Signature, BaseConvertionError> {
match base64::decode(base64_data) {
......@@ -104,7 +168,7 @@ impl Eq for Signature {}
/// Can be generated with [`KeyPairGenerator`].
///
/// [`KeyPairGenerator`]: struct.KeyPairGenerator.html
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Copy, Clone, Deserialize, PartialEq, Eq, Hash, Serialize)]
pub struct PublicKey(pub [u8; 32]);
impl ToBase58 for PublicKey {
......@@ -126,15 +190,6 @@ impl Debug for PublicKey {
}
}
impl Serialize for PublicKey {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&format!("{}", self))
}
}
impl super::PublicKey for PublicKey {
type Signature = Signature;
......
......@@ -48,7 +48,6 @@
extern crate serde;
use self::serde::ser::{Serialize, Serializer};
use base58::ToBase58;
use std::fmt::Debug;
use std::fmt::Display;
......@@ -109,7 +108,7 @@ pub trait Signature: Clone + Display + Debug + PartialEq + Eq + Hash {
}
/// Store a cryptographic signature.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub enum Sig {
/// Store a ed25519 Signature
Ed25519(ed25519::Signature),
......@@ -171,7 +170,7 @@ pub trait PublicKey: Clone + Display + Debug + PartialEq + Eq + Hash + ToBase58
}
/// Store a cryptographic public key.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub enum PubKey {
/// Store a ed25519 public key.
Ed25519(ed25519::PublicKey),
......@@ -203,15 +202,6 @@ impl Display for PubKey {
}
}
impl Serialize for PubKey {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&format!("{}", self))
}
}
impl PublicKey for PubKey {
type Signature = Sig;
......
......@@ -22,6 +22,9 @@
unused_qualifications
)]
#[macro_use]
extern crate serde_derive;
extern crate base58;
extern crate base64;
extern crate crypto;
......
......@@ -17,9 +17,9 @@ duniter-wotb = { path = "../wotb" }
lazy_static = "1.0.0"
log = "0.4.1"
rand = "0.4.2"
rustbreak = {version = "2.0.0-rc2", features = ["bin_enc"]}
rust-crypto = "0.2.36"
regex = "1.0.0"
sqlite = "0.23.9"
serde = "1.0.57"
serde_derive = "1.0.57"
serde_json = "1.0.17"
......
This diff is collapsed.
// Copyright (C) 2018 The Duniter Project Developers.
//
// 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/>.
extern crate duniter_documents;
extern crate duniter_wotb;
use duniter_documents::BlockId;
use duniter_wotb::NodeId;
use rustbreak::backend::Backend;
use std::collections::HashMap;
use std::fmt::Debug;
use {BinDB, CertsExpirV10Datas, DALError};
/// Find certifications that emitted in indicated blocks expiring
pub fn find_expire_certs<B: Backend + Debug>(
certs_db: &BinDB<CertsExpirV10Datas, B>,
blocks_expiring: Vec<BlockId>,
) -> Result<HashMap<(NodeId, NodeId), BlockId>, DALError> {
Ok(certs_db.read(|db| {
let mut all_expire_certs = HashMap::new();
for expire_block_id in blocks_expiring {
if let Some(expire_certs) = db.get(&expire_block_id) {
for (source, target) in expire_certs {
all_expire_certs.insert((*source, *target), expire_block_id);
}
}
}
all_expire_certs
})?)
}
cyclomatic-complexity-threshold = 35
too-many-arguments-threshold = 10
\ No newline at end of file
#[derive(Debug, Copy, Clone)]
pub struct CurrencyParametersV10 {
pub c: f64,
pub dt: i64,
pub ud0: i64,
pub sig_period: u64,
pub sig_stock: i64,
pub sig_window: i64,
pub sig_validity: i64,
pub sig_qty: i64,
pub idty_window: i64,
pub ms_window: i64,
pub x_percent: f64,
pub ms_validity: u64,
pub step_max: u32,
pub median_time_blocks: i64,
pub avg_gen_time: i64,
pub dt_diff_eval: i64,
pub percent_rot: f64,
pub ud_time0: i64,
pub ud_reeval_time0: i64,
pub dt_reeval: i64,
}
pub static G1_PARAMS: &'static CurrencyParametersV10 = &CurrencyParametersV10 {
c: 0.0488,
dt: 86_400,
ud0: 1_000,
sig_period: 432_000,
sig_stock: 100,
sig_window: 5_259_600,
sig_validity: 63_115_200,
sig_qty: 5,
idty_window: 5_259_600,
ms_window: 5_259_600,
x_percent: 0.8,
ms_validity: 31_557_600,
step_max: 5,
median_time_blocks: 24,
avg_gen_time: 300,
dt_diff_eval: 12,
percent_rot: 0.67,
ud_time0: 1_488_970_800,
ud_reeval_time0: 1_490_094_000,
dt_reeval: 15_778_800,
};
pub static G1_CONNECTIVITY_MAX: &'static usize = &125;
pub static MAX_FORKS: &'static usize = &50;
pub static DEFAULT_MS_PERIOD: &'static u64 = &5_259_600;
pub static DEFAULT_TX_WINDOW: &'static u64 = &604_800;
pub static MAX_FORKS: &'static usize = &100;
use constants::*;
use duniter_documents::blockchain::v10::documents::block::{BlockV10Parameters, CurrencyName};
#[derive(Debug, Copy, Clone)]
pub struct CurrencyParameters {
pub protocol_version: usize,
pub c: f64,
pub dt: u64,
pub ud0: usize,
pub sig_period: u64,
pub sig_stock: usize,
pub sig_window: u64,
pub sig_validity: u64,
pub sig_qty: usize,
pub idty_window: u64,
pub ms_window: u64,
pub tx_window: u64,
pub x_percent: f64,
pub ms_validity: u64,
pub ms_period: u64,
pub step_max: usize,
pub median_time_blocks: usize,
pub avg_gen_time: u64,
pub dt_diff_eval: usize,
pub percent_rot: f64,
pub ud_time0: u64,
pub ud_reeval_time0: u64,
pub dt_reeval: u64,
}
impl From<(CurrencyName, BlockV10Parameters)> for CurrencyParameters {
fn from(source: (CurrencyName, BlockV10Parameters)) -> CurrencyParameters {
let (currency_name, block_params) = source;
let ms_period = match currency_name.0.as_str() {
"default_currency" => *DEFAULT_MS_PERIOD,
"g1" => 5_259_600,
"g1-test" => 5_259_600 / 5,
_ => *DEFAULT_MS_PERIOD,
};
let tx_window = match currency_name.0.as_str() {
"default_currency" => *DEFAULT_TX_WINDOW,
"g1" => 604_800,
"g1-test" => 604_800,
_ => *DEFAULT_TX_WINDOW,
};
CurrencyParameters {
protocol_version: 10,
c: block_params.c,
dt: block_params.dt,
ud0: block_params.ud0,
sig_period: block_params.sig_period,
sig_stock: block_params.sig_stock,
sig_window: block_params.sig_window,
sig_validity: block_params.sig_validity,
sig_qty: block_params.sig_qty,
idty_window: block_params.idty_window,
ms_window: block_params.ms_window,
tx_window,
x_percent: block_params.x_percent,
ms_validity: block_params.ms_validity,
ms_period,
step_max: block_params.step_max,
median_time_blocks: block_params.median_time_blocks,
avg_gen_time: block_params.avg_gen_time,
dt_diff_eval: block_params.dt_diff_eval,
percent_rot: block_params.percent_rot,
ud_time0: block_params.ud_time0,
ud_reeval_time0: block_params.ud_reeval_time0,
dt_reeval: block_params.dt_reeval,
}
}
}
impl Default for CurrencyParameters {
fn default() -> CurrencyParameters {
CurrencyParameters::from((
CurrencyName(String::from("default_currency")),
BlockV10Parameters::default(),
))
}
}
impl CurrencyParameters {
/// Get max value of connectivity (=1/x_percent)
pub fn max_connectivity(&self) -> f64 {
1.0 / self.x_percent
}
}
extern crate duniter_documents;
extern crate serde;
use self::duniter_documents::blockchain::v10::documents::BlockDocument;
use self::duniter_documents::blockchain::BlockchainProtocol;
use duniter_documents::blockchain::v10::documents::BlockDocument;
use duniter_documents::blockchain::BlockchainProtocol;
#[derive(Debug, Clone)]
pub enum DALEvent {
......
extern crate duniter_crypto;
extern crate duniter_documents;
extern crate duniter_module;
extern crate serde;
use self::duniter_crypto::keys::*;
use self::duniter_documents::blockchain::v10::documents::{
use self::duniter_module::ModuleReqFullId;
use duniter_crypto::keys::*;
use duniter_documents::blockchain::v10::documents::{
BlockDocument, CertificationDocument, IdentityDocument, MembershipDocument, RevocationDocument,
};
use self::duniter_documents::Hash;
use self::duniter_module::ModuleReqFullId;
use duniter_documents::Hash;
use std::collections::HashMap;
#[derive(Debug, Copy, Clone)]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment