From 736aca33330de1eb7c09e0cfd6e005366c0e5d29 Mon Sep 17 00:00:00 2001 From: Andrew Westberg Date: Wed, 4 Sep 2024 14:06:41 +0000 Subject: [PATCH] Project scaffolding --- .gitignore | 5 + Cargo.lock | 904 ++++++++++++++++++++++++++++++ Cargo.toml | 8 + amaru-common/Cargo.toml | 17 + amaru-common/README.md | 1 + amaru-common/src/ledger/mod.rs | 21 + amaru-common/src/lib.rs | 7 + amaru-common/src/nonce/mod.rs | 11 + amaru-common/src/pool/mod.rs | 10 + amaru-common/src/tests.rs | 11 + amaru-common/src/validator/mod.rs | 7 + amaru-consensus/Cargo.toml | 19 + amaru-consensus/README.md | 1 + amaru-consensus/src/block/mod.rs | 59 ++ amaru-consensus/src/lib.rs | 8 + amaru-consensus/src/tests.rs | 7 + amaru-crypto/Cargo.toml | 13 + amaru-crypto/src/lib.rs | 14 + amaru-node/Cargo.toml | 25 + amaru-node/README.md | 1 + amaru-node/src/main.rs | 34 ++ version.toml | 2 + 22 files changed, 1185 insertions(+) create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 amaru-common/Cargo.toml create mode 100644 amaru-common/README.md create mode 100644 amaru-common/src/ledger/mod.rs create mode 100644 amaru-common/src/lib.rs create mode 100644 amaru-common/src/nonce/mod.rs create mode 100644 amaru-common/src/pool/mod.rs create mode 100644 amaru-common/src/tests.rs create mode 100644 amaru-common/src/validator/mod.rs create mode 100644 amaru-consensus/Cargo.toml create mode 100644 amaru-consensus/README.md create mode 100644 amaru-consensus/src/block/mod.rs create mode 100644 amaru-consensus/src/lib.rs create mode 100644 amaru-consensus/src/tests.rs create mode 100644 amaru-crypto/Cargo.toml create mode 100644 amaru-crypto/src/lib.rs create mode 100644 amaru-node/Cargo.toml create mode 100644 amaru-node/README.md create mode 100644 amaru-node/src/main.rs create mode 100644 version.toml diff --git a/.gitignore b/.gitignore index d317873..e31f888 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,8 @@ target/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. .idea/ + + +# Added by cargo + +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..aa6afc0 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,904 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "amaru-common" +version = "0.0.1" +dependencies = [ + "pallas-crypto", + "pallas-traverse", + "thiserror", +] + +[[package]] +name = "amaru-consensus" +version = "0.0.1" +dependencies = [ + "amaru-common", + "log", + "pallas-codec", + "pallas-primitives", + "pallas-traverse", +] + +[[package]] +name = "amaru-crypto" +version = "0.0.1" + +[[package]] +name = "amaru-node" +version = "0.0.1" +dependencies = [ + "amaru-common", + "amaru-consensus", + "env_logger 0.11.5", + "log", + "pretty_env_logger", + "thiserror", + "tokio", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "anstream" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + +[[package]] +name = "anstyle-parse" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "base58" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6107fe1be6682a68940da878d9e9f5e90ca5745b3dec9fd1bb393c8777d4f581" + +[[package]] +name = "bech32" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" + +[[package]] +name = "bytes" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" + +[[package]] +name = "cc" +version = "1.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "colorchoice" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" + +[[package]] +name = "crc" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + +[[package]] +name = "cryptoxide" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "382ce8820a5bb815055d3553a610e8cb542b2d767bbacea99038afda96cd760d" + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[package]] +name = "env_filter" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "env_logger" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "half" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b43ede17f21864e81be2fa654110bf1e793774238d86ef8555c37e6519c0403" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "hermit-abi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "is-terminal" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" +dependencies = [ + "hermit-abi 0.4.0", + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "minicbor" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d15f4203d71fdf90903c2696e55426ac97a363c67b218488a73b534ce7aca10" +dependencies = [ + "half", + "minicbor-derive", +] + +[[package]] +name = "minicbor-derive" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1154809406efdb7982841adb6311b3d095b46f78342dd646736122fe6b19e267" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +dependencies = [ + "hermit-abi 0.3.9", + "libc", + "wasi", + "windows-sys 0.52.0", +] + +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + +[[package]] +name = "object" +version = "0.36.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] +name = "pallas-addresses" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c38fac39e0da3b0fc4c859635c72e97584f01f3a0f4f1508b0851c02d6d52f15" +dependencies = [ + "base58", + "bech32", + "crc", + "cryptoxide", + "hex", + "pallas-codec", + "pallas-crypto", + "thiserror", +] + +[[package]] +name = "pallas-codec" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea8a4b87dbc8bcb8aeb865f7cca5e1eb29744330e23b307169fc30537648b264" +dependencies = [ + "hex", + "minicbor", + "serde", + "thiserror", +] + +[[package]] +name = "pallas-crypto" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b98c3f204299d47d9b581ab425043789caff1f491c078ee3d3f109d6556f725" +dependencies = [ + "cryptoxide", + "hex", + "pallas-codec", + "rand_core", + "serde", + "thiserror", +] + +[[package]] +name = "pallas-primitives" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f64835dd9cbdd75a38961a190b983f02746c872340daf1a921eada8c525a4b6" +dependencies = [ + "base58", + "bech32", + "hex", + "log", + "pallas-codec", + "pallas-crypto", + "serde", + "serde_json", +] + +[[package]] +name = "pallas-traverse" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad516b05ba7d838ee84f9998d7b2b4ff7acc178cb052bcfd5fea9edc2ef6023f" +dependencies = [ + "hex", + "itertools", + "pallas-addresses", + "pallas-codec", + "pallas-crypto", + "pallas-primitives", + "paste", + "serde", + "thiserror", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pretty_env_logger" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "865724d4dbe39d9f3dd3b52b88d859d66bcb2d6a0acfd5ea68a65fb66d4bdc1c" +dependencies = [ + "env_logger 0.10.2", + "log", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "regex" +version = "1.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "serde" +version = "1.0.209" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.209" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", +] + +[[package]] +name = "serde_json" +version = "1.0.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", +] + +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "tokio" +version = "1.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "tokio-macros", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-macros" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", +] + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "nu-ansi-term", + "sharded-slab", + "smallvec", + "thread_local", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..7ec09f9 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] +resolver = "2" +members = [ + "amaru-common", + "amaru-consensus", + "amaru-crypto", + "amaru-node", +] diff --git a/amaru-common/Cargo.toml b/amaru-common/Cargo.toml new file mode 100644 index 0000000..24acc1a --- /dev/null +++ b/amaru-common/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "amaru-common" +description = "Amaru crate providing common functionality for various bounded contexts." +version = "0.0.1" +edition = "2021" +repository = "https://github.com/pragma-org/amaru" +homepage = "https://github.com/pragma-org/amaru" +license = "Apache-2.0" +readme = "README.md" +authors = [ + "Andrew Westberg ", +] + +[dependencies] +pallas-crypto = "0.30.1" +pallas-traverse = "0.30.1" +thiserror = "1" \ No newline at end of file diff --git a/amaru-common/README.md b/amaru-common/README.md new file mode 100644 index 0000000..099d877 --- /dev/null +++ b/amaru-common/README.md @@ -0,0 +1 @@ +# amaru-common \ No newline at end of file diff --git a/amaru-common/src/ledger/mod.rs b/amaru-common/src/ledger/mod.rs new file mode 100644 index 0000000..6c2d745 --- /dev/null +++ b/amaru-common/src/ledger/mod.rs @@ -0,0 +1,21 @@ +use crate::pool::PoolId; +use pallas_traverse::update::RationalNumber; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum Error { + #[error("PoolId not found")] + PoolIdNotFound, +} + +/// The sigma value of a pool. This is a rational number that represents the total value of the +/// delegated stake in the pool over the total value of the active stake in the network. This value +/// is tracked in the ledger state and recorded as a snapshot value at each epoch. +pub type Sigma = RationalNumber; + +/// Performs a lookup of a pool_id to its sigma value. This usually represents a different set of +/// sigma snapshot data depending on whether we need to look up the pool_id in the current epoch +/// or in the future. +pub trait PoolIdToSigma { + fn sigma(&self, pool_id: &PoolId) -> Result; +} \ No newline at end of file diff --git a/amaru-common/src/lib.rs b/amaru-common/src/lib.rs new file mode 100644 index 0000000..23271cd --- /dev/null +++ b/amaru-common/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests; + +pub mod ledger; +pub mod nonce; +pub mod pool; +pub mod validator; diff --git a/amaru-common/src/nonce/mod.rs b/amaru-common/src/nonce/mod.rs new file mode 100644 index 0000000..8cbcbc0 --- /dev/null +++ b/amaru-common/src/nonce/mod.rs @@ -0,0 +1,11 @@ +use pallas_crypto::hash::Hash; + +// +// The universal constant nonce. The blake2b hash of the 8 byte long value of 1 +// 12dd0a6a7d0e222a97926da03adb5a7768d31cc7c5c2bd6828e14a7d25fa3a60 +// Sometimes called seedL in the haskell code +// +pub const UC_NONCE: Hash<32> = Hash::new([ + 0x12, 0xdd, 0x0a, 0x6a, 0x7d, 0x0e, 0x22, 0x2a, 0x97, 0x92, 0x6d, 0xa0, 0x3a, 0xdb, 0x5a, 0x77, 0x68, 0xd3, 0x1c, + 0xc7, 0xc5, 0xc2, 0xbd, 0x68, 0x28, 0xe1, 0x4a, 0x7d, 0x25, 0xfa, 0x3a, 0x60, +]); \ No newline at end of file diff --git a/amaru-common/src/pool/mod.rs b/amaru-common/src/pool/mod.rs new file mode 100644 index 0000000..bf670d6 --- /dev/null +++ b/amaru-common/src/pool/mod.rs @@ -0,0 +1,10 @@ +use pallas_crypto::hash::{Hash, Hasher}; +use pallas_traverse::update::RationalNumber; + +pub type PoolId = Hash<28>; + +/// The node's vkey is hashed with blake2b224 to create the pool id +pub fn issuer_vkey_to_pool_id(issuer_vkey: &[u8]) -> PoolId { + Hasher::<224>::hash(issuer_vkey) +} + diff --git a/amaru-common/src/tests.rs b/amaru-common/src/tests.rs new file mode 100644 index 0000000..b725c47 --- /dev/null +++ b/amaru-common/src/tests.rs @@ -0,0 +1,11 @@ +use crate::pool::{issuer_vkey_to_pool_id, PoolId}; + +#[test] +fn test_issuer_vkey_to_pool_id() { + // cad3c900ca6baee9e65bf61073d900bfbca458eeca6d0b9f9931f5b1017a8cd6 + let issuer_vkey = [0xca, 0xd3, 0xc9, 0x00, 0xca, 0x6b, 0xae, 0xe9, 0xe6, 0x5b, 0xf6, 0x10, 0x73, 0xd9, 0x00, 0xbf, 0xbc, 0xa4, 0x58, 0xee, 0xca, 0x6d, 0x0b, 0x9f, 0x99, 0x31, 0xf5, 0xb1, 0x01, 0x7a, 0x8c, 0xd6]; + let pool_id = issuer_vkey_to_pool_id(&issuer_vkey); + // 00beef0a9be2f6d897ed24a613cf547bb20cd282a04edfc53d477114 + let expected_pool_id = PoolId::new([0x00, 0xbe, 0xef, 0x0a, 0x9b, 0xe2, 0xf6, 0xd8, 0x97, 0xed, 0x24, 0xa6, 0x13, 0xcf, 0x54, 0x7b, 0xb2, 0x0c, 0xd2, 0x82, 0xa0, 0x4e, 0xdf, 0xc5, 0x3d, 0x47, 0x71, 0x14]); + assert_eq!(pool_id, expected_pool_id); +} diff --git a/amaru-common/src/validator/mod.rs b/amaru-common/src/validator/mod.rs new file mode 100644 index 0000000..896d6d9 --- /dev/null +++ b/amaru-common/src/validator/mod.rs @@ -0,0 +1,7 @@ +/// Generic trait for validating any type of data. Designed to be used across threads so validations +/// can be done in parallel. Validators are expected to never result in an error, but instead panic +/// if the validation is unable to be completed and return a true or false. This indicates a serious +/// bug in the code. +pub trait Validator: Send + Sync { + fn validate(&self) -> bool; +} \ No newline at end of file diff --git a/amaru-consensus/Cargo.toml b/amaru-consensus/Cargo.toml new file mode 100644 index 0000000..d17078a --- /dev/null +++ b/amaru-consensus/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "amaru-consensus" +description = "Amaru crate providing Cardano consensus logic." +version = "0.0.1" +edition = "2021" +repository = "https://github.com/pragma-org/amaru" +homepage = "https://github.com/pragma-org/amaru" +license = "Apache-2.0" +readme = "README.md" +authors = [ + "Andrew Westberg ", +] + +[dependencies] +amaru-common = { path = "../amaru-common" } +pallas-codec = "0.30.1" +pallas-primitives = "0.30.1" +pallas-traverse = "0.30.1" +log = "0.4.22" \ No newline at end of file diff --git a/amaru-consensus/README.md b/amaru-consensus/README.md new file mode 100644 index 0000000..5a7e953 --- /dev/null +++ b/amaru-consensus/README.md @@ -0,0 +1 @@ +# amaru-consensus \ No newline at end of file diff --git a/amaru-consensus/src/block/mod.rs b/amaru-consensus/src/block/mod.rs new file mode 100644 index 0000000..454c4c7 --- /dev/null +++ b/amaru-consensus/src/block/mod.rs @@ -0,0 +1,59 @@ +use amaru_common::ledger::{PoolIdToSigma, Sigma}; +use amaru_common::pool::issuer_vkey_to_pool_id; +use amaru_common::validator::Validator; +use log::warn; +use pallas_traverse::MultiEraHeader; + +struct BlockValidator<'b> { + multi_era_header: MultiEraHeader<'b>, + pool_id_to_sigma: &'b dyn PoolIdToSigma, +} + +impl<'b> BlockValidator<'b> { + fn new(multi_era_header: MultiEraHeader<'b>, pool_id_to_sigma: &'b dyn PoolIdToSigma) -> Self { + Self { multi_era_header, pool_id_to_sigma } + } + + fn validate_epoch_boundary(&self) -> bool { + // we ignore epoch boundaries and assume they are valid + true + } + + fn validate_byron(&self) -> bool { + // we ignore byron headers and assume they are valid + true + } + + fn validate_shelley_compatible(&self) -> bool { + let Some(issuer_vkey) = self.multi_era_header.issuer_vkey(); + let pool_id = issuer_vkey_to_pool_id(issuer_vkey); + let sigma = match self.pool_id_to_sigma.sigma(&pool_id) { + Ok(sigma) => sigma, + Err(error) => { + warn!("{:?} - {:?}", error, pool_id); + return false; + } + }; + let slot = self.multi_era_header.slot(); + let Ok(leader_vrf_output) = self.multi_era_header.leader_vrf_output(); + let Ok(vrf_vkey) = self.multi_era_header.vrf_vkey(); + + true + } + + fn validate_babbage_compatible(&self) -> bool { + let cbor = self.multi_era_header.cbor(); + true + } +} + +impl Validator for BlockValidator<'_> { + fn validate(&self) -> bool { + match self.multi_era_header { + MultiEraHeader::EpochBoundary(_) => self.validate_epoch_boundary(), + MultiEraHeader::Byron(_) => self.validate_byron(), + MultiEraHeader::ShelleyCompatible(_) => self.validate_shelley_compatible(), + MultiEraHeader::BabbageCompatible(_) => self.validate_babbage_compatible(), + } + } +} \ No newline at end of file diff --git a/amaru-consensus/src/lib.rs b/amaru-consensus/src/lib.rs new file mode 100644 index 0000000..11ec6da --- /dev/null +++ b/amaru-consensus/src/lib.rs @@ -0,0 +1,8 @@ +mod block; + +pub fn add(left: u64, right: u64) -> u64 { + left + right +} + +#[cfg(test)] +mod tests; diff --git a/amaru-consensus/src/tests.rs b/amaru-consensus/src/tests.rs new file mode 100644 index 0000000..53ed08a --- /dev/null +++ b/amaru-consensus/src/tests.rs @@ -0,0 +1,7 @@ +use super::*; + +#[test] +fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); +} diff --git a/amaru-crypto/Cargo.toml b/amaru-crypto/Cargo.toml new file mode 100644 index 0000000..b82e222 --- /dev/null +++ b/amaru-crypto/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "amaru-crypto" +description = "Amaru crate providing higher-level Cardano-specific crypto algorithms." +version = "0.0.1" +edition = "2021" +repository = "https://github.com/pragma-org/amaru" +homepage = "https://github.com/pragma-org/amaru" +license = "Apache-2.0" +readme = "README.md" +authors = [ + "Andrew Westberg ", +] +[dependencies] diff --git a/amaru-crypto/src/lib.rs b/amaru-crypto/src/lib.rs new file mode 100644 index 0000000..b93cf3f --- /dev/null +++ b/amaru-crypto/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: u64, right: u64) -> u64 { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} diff --git a/amaru-node/Cargo.toml b/amaru-node/Cargo.toml new file mode 100644 index 0000000..1d9d4e2 --- /dev/null +++ b/amaru-node/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "amaru-node" +description = "Cardano Rust node implementation." +version = "0.0.1" +edition = "2021" +repository = "https://github.com/pragma-org/amaru" +homepage = "https://github.com/pragma-org/amaru" +license = "Apache-2.0" +readme = "README.md" +authors = [ + "Andrew Westberg ", +] + +[dependencies] +amaru-common = { path = "../amaru-common" } +amaru-consensus = { path = "../amaru-consensus" } +tokio = { version = "1", features = ["rt", "rt-multi-thread", "net", "io-util", "time", "sync", "macros"] } +thiserror = "1.0" +tracing = "0.1" +tracing-subscriber = "0.3" + +# logging +log = "0.4" +env_logger = "0.11" +pretty_env_logger = "0.5" diff --git a/amaru-node/README.md b/amaru-node/README.md new file mode 100644 index 0000000..bc1adda --- /dev/null +++ b/amaru-node/README.md @@ -0,0 +1 @@ +# amaru-node \ No newline at end of file diff --git a/amaru-node/src/main.rs b/amaru-node/src/main.rs new file mode 100644 index 0000000..9c2c22f --- /dev/null +++ b/amaru-node/src/main.rs @@ -0,0 +1,34 @@ +use std::env::{set_var, var}; +use tracing::info; + +#[tokio::main] +async fn main() { + match var("RUST_LOG") { + Ok(_) => {} + Err(_) => { + // set a default logging level of info if unset. + set_var("RUST_LOG", "info"); + } + } + pretty_env_logger::init_timed(); + + let tracing_filter = match var("RUST_LOG") { + Ok(level) => match level.to_lowercase().as_str() { + "error" => tracing::Level::ERROR, + "warn" => tracing::Level::WARN, + "info" => tracing::Level::INFO, + "debug" => tracing::Level::DEBUG, + "trace" => tracing::Level::TRACE, + _ => tracing::Level::INFO, + }, + Err(_) => tracing::Level::INFO, + }; + + tracing::subscriber::set_global_default( + tracing_subscriber::FmtSubscriber::builder() + .with_max_level(tracing_filter) + .finish(), + ).unwrap(); + + info!("Hello, amaru-node!"); +} diff --git a/version.toml b/version.toml new file mode 100644 index 0000000..1ead7a7 --- /dev/null +++ b/version.toml @@ -0,0 +1,2 @@ +[package] +version = "0.0.1" \ No newline at end of file