Skip to content

Commit 057daac

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 243f1c0 + 01b2565 commit 057daac

File tree

19 files changed

+622
-494
lines changed

19 files changed

+622
-494
lines changed

.cargo/config .cargo/config.toml

File renamed without changes.

Cargo.lock

+576-417
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ blake2-rfc = "0.2"
2424
chrono = "0.4.11"
2525
clap = { version = "2.33", features = ["yaml"] }
2626
ctrlc = { version = "3.1", features = ["termination"] }
27-
cursive_table_view = "0.14.0"
27+
cursive_table_view = "0.15.0"
2828
humansize = "1.1.0"
2929
serde = "1"
3030
futures = "0.3.19"
@@ -42,12 +42,12 @@ grin_servers = { path = "./servers", version = "5.4.0-alpha.0" }
4242
grin_util = { path = "./util", version = "5.4.0-alpha.0" }
4343

4444
[dependencies.cursive]
45-
version = "0.20"
45+
version = "0.21"
4646
default-features = false
4747
features = ["pancurses-backend"]
4848

4949
[build-dependencies]
50-
built = { version = "0.4", features = ["git2"]}
50+
built = { version = "0.7", features = ["git2"]}
5151

5252
[dev-dependencies]
5353
grin_chain = { path = "./chain", version = "5.4.0-alpha.0" }

api/src/owner_rpc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub trait OwnerRpc: Sync + Send {
4949
"jsonrpc": "2.0",
5050
"result": {
5151
"Ok": {
52+
"chain": "main",
5253
"protocol_version": "2",
5354
"user_agent": "MW/Grin 2.x.x",
5455
"connections": "8",

api/src/types.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::chain;
1616
use crate::core::core::hash::Hashed;
1717
use crate::core::core::merkle_proof::MerkleProof;
1818
use crate::core::core::{FeeFields, KernelFeatures, TxKernel};
19-
use crate::core::{core, ser};
19+
use crate::core::{core, global, ser};
2020
use crate::p2p;
2121
use crate::util::secp::pedersen;
2222
use crate::util::{self, ToHex};
@@ -68,6 +68,8 @@ impl Tip {
6868
/// Status page containing different server information
6969
#[derive(Serialize, Deserialize, Debug, Clone)]
7070
pub struct Status {
71+
// The chain type
72+
pub chain: String,
7173
// The protocol version
7274
pub protocol_version: u32,
7375
// The user user agent
@@ -91,6 +93,7 @@ impl Status {
9193
sync_info: Option<serde_json::Value>,
9294
) -> Status {
9395
Status {
96+
chain: global::get_chain_type().shortname(),
9497
protocol_version: ser::ProtocolVersion::local().into(),
9598
user_agent: p2p::msg::USER_AGENT.to_string(),
9699
connections: connections,

chain/tests/chain_test_helper.rs

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ use grin_keychain as keychain;
2929
use std::fs;
3030
use std::sync::Arc;
3131

32+
#[allow(dead_code)]
33+
#[cfg(test)]
3234
pub fn clean_output_dir(dir_name: &str) {
3335
let _ = fs::remove_dir_all(dir_name);
3436
}

core/src/core/block.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::pow::{verify_size, Difficulty, Proof, ProofOfWork};
2727
use crate::ser::{
2828
self, deserialize_default, serialize_default, PMMRable, Readable, Reader, Writeable, Writer,
2929
};
30-
use chrono::prelude::{DateTime, NaiveDateTime, Utc};
30+
use chrono::prelude::{DateTime, Utc};
3131
use chrono::Duration;
3232
use keychain::{self, BlindingFactor};
3333
use std::convert::TryInto;
@@ -232,7 +232,7 @@ impl Default for BlockHeader {
232232
version: HeaderVersion(1),
233233
height: 0,
234234
timestamp: DateTime::from_naive_utc_and_offset(
235-
NaiveDateTime::from_timestamp_opt(0, 0).unwrap(),
235+
DateTime::<Utc>::from_timestamp(0, 0).unwrap().naive_utc(),
236236
Utc,
237237
),
238238
prev_hash: ZERO_HASH,
@@ -295,25 +295,27 @@ fn read_block_header<R: Reader>(reader: &mut R) -> Result<BlockHeader, ser::Erro
295295
> chrono::NaiveDate::MAX
296296
.and_hms_opt(0, 0, 0)
297297
.unwrap()
298+
.and_utc()
298299
.timestamp()
299300
|| timestamp
300301
< chrono::NaiveDate::MIN
301302
.and_hms_opt(0, 0, 0)
302303
.unwrap()
304+
.and_utc()
303305
.timestamp()
304306
{
305307
return Err(ser::Error::CorruptedData);
306308
}
307309

308-
let ts = NaiveDateTime::from_timestamp_opt(timestamp, 0);
310+
let ts = DateTime::<Utc>::from_timestamp(timestamp, 0);
309311
if ts.is_none() {
310312
return Err(ser::Error::CorruptedData);
311313
}
312314

313315
Ok(BlockHeader {
314316
version,
315317
height,
316-
timestamp: DateTime::from_naive_utc_and_offset(ts.unwrap(), Utc),
318+
timestamp: DateTime::from_naive_utc_and_offset(ts.unwrap().naive_utc(), Utc),
317319
prev_hash,
318320
prev_root,
319321
output_root,
@@ -662,12 +664,12 @@ impl Block {
662664

663665
let now = Utc::now().timestamp();
664666

665-
let ts = NaiveDateTime::from_timestamp_opt(now, 0);
667+
let ts = DateTime::<Utc>::from_timestamp(now, 0);
666668
if ts.is_none() {
667669
return Err(Error::Other("Converting Utc::now() into timestamp".into()));
668670
}
669671

670-
let timestamp = DateTime::from_naive_utc_and_offset(ts.unwrap(), Utc);
672+
let timestamp = DateTime::from_naive_utc_and_offset(ts.unwrap().naive_utc(), Utc);
671673
// Now build the block with all the above information.
672674
// Note: We have not validated the block here.
673675
// Caller must validate the block as necessary.

core/src/genesis.rs

-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
// required for genesis replacement
1818
//! #![allow(unused_imports)]
1919
20-
#![cfg_attr(feature = "cargo-clippy", allow(clippy::unreadable_literal))]
21-
2220
use crate::core;
2321
use crate::core::hash::Hash;
2422
use crate::pow::{Difficulty, Proof, ProofOfWork};
@@ -44,7 +42,6 @@ pub fn genesis_dev() -> core::Block {
4442
}
4543

4644
/// Testnet genesis block
47-
#[allow(clippy::inconsistent_digit_grouping)]
4845
pub fn genesis_test() -> core::Block {
4946
let gen = core::Block::with_header(core::BlockHeader {
5047
height: 0,
@@ -157,7 +154,6 @@ pub fn genesis_test() -> core::Block {
157154
}
158155

159156
/// Mainnet genesis block
160-
#[allow(clippy::inconsistent_digit_grouping)]
161157
pub fn genesis_main() -> core::Block {
162158
let gen = core::Block::with_header(core::BlockHeader {
163159
height: 0,

core/src/pow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub use crate::pow::cuckaroom::{new_cuckaroom_ctx, CuckaroomContext};
5353
pub use crate::pow::cuckarooz::{new_cuckarooz_ctx, CuckaroozContext};
5454
pub use crate::pow::cuckatoo::{new_cuckatoo_ctx, CuckatooContext};
5555
pub use crate::pow::error::Error;
56-
use chrono::prelude::{DateTime, NaiveDateTime, Utc};
56+
use chrono::prelude::{DateTime, Utc};
5757

5858
const MAX_SOLS: u32 = 10;
5959

@@ -116,7 +116,7 @@ pub fn pow_size(
116116
// well)
117117
if bh.pow.nonce == start_nonce {
118118
bh.timestamp = DateTime::from_naive_utc_and_offset(
119-
NaiveDateTime::from_timestamp_opt(0, 0).unwrap(),
119+
DateTime::<Utc>::from_timestamp(0, 0).unwrap().naive_utc(),
120120
Utc,
121121
);
122122
}

core/src/pow/common.rs

-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ pub fn create_siphash_keys(header: &[u8]) -> Result<[u64; 4], Error> {
8282
/// Utility struct to calculate commonly used Cuckoo parameters calculated
8383
/// from header, nonce, edge_bits, etc.
8484
pub struct CuckooParams {
85-
pub edge_bits: u8,
8685
pub proof_size: usize,
8786
pub num_edges: u64,
8887
pub siphash_keys: [u64; 4],
@@ -98,7 +97,6 @@ impl CuckooParams {
9897
let num_nodes = 1u64 << node_bits;
9998
let node_mask = num_nodes - 1;
10099
Ok(CuckooParams {
101-
edge_bits,
102100
proof_size,
103101
num_edges,
104102
siphash_keys: [0; 4],

core/tests/pmmr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ fn bench_peak_map() {
4343
let increments = vec![1_000_000u64, 10_000_000u64, 100_000_000u64];
4444

4545
for v in increments {
46-
let start = Utc::now().timestamp_nanos();
46+
let start = Utc::now().timestamp_nanos_opt().unwrap();
4747
for i in 0..v {
4848
let _ = pmmr::peak_map_height(i);
4949
}
50-
let fin = Utc::now().timestamp_nanos();
50+
let fin = Utc::now().timestamp_nanos_opt().unwrap();
5151
let dur_ms = (fin - start) as f64 * nano_to_millis;
5252
println!("{:9?} peak_map_height() in {:9.3?}ms", v, dur_ms);
5353
}

keychain/src/extkey_bip32.rs

-33
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
//! Modified from above to integrate into grin and allow for different
3131
//! hashing algorithms if desired
3232
33-
#[cfg(feature = "serde")]
34-
use serde;
3533
use std::default::Default;
3634
use std::io::Cursor;
3735
use std::str::FromStr;
@@ -276,26 +274,6 @@ impl fmt::Display for ChildNumber {
276274
}
277275
}
278276

279-
#[cfg(feature = "serde")]
280-
impl<'de> serde::Deserialize<'de> for ChildNumber {
281-
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
282-
where
283-
D: serde::Deserializer<'de>,
284-
{
285-
u32::deserialize(deserializer).map(ChildNumber::from)
286-
}
287-
}
288-
289-
#[cfg(feature = "serde")]
290-
impl serde::Serialize for ChildNumber {
291-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
292-
where
293-
S: serde::Serializer,
294-
{
295-
u32::from(*self).serialize(serializer)
296-
}
297-
}
298-
299277
/// A BIP32 error
300278
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
301279
pub enum Error {
@@ -875,15 +853,4 @@ mod tests {
875853
"xprv9uPDJpEQgRQfDcW7BkF7eTya6RPxXeJCqCJGHuCJ4GiRVLzkTXBAJMu2qaMWPrS7AANYqdq6vcBcBUdJCVVFceUvJFjaPdGZ2y9WACViL4L",
876854
"xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y");
877855
}
878-
879-
#[test]
880-
#[cfg(all(feature = "serde", feature = "strason"))]
881-
pub fn encode_decode_childnumber() {
882-
serde_round_trip!(ChildNumber::from_normal_idx(0));
883-
serde_round_trip!(ChildNumber::from_normal_idx(1));
884-
serde_round_trip!(ChildNumber::from_normal_idx((1 << 31) - 1));
885-
serde_round_trip!(ChildNumber::from_hardened_idx(0));
886-
serde_round_trip!(ChildNumber::from_hardened_idx(1));
887-
serde_round_trip!(ChildNumber::from_hardened_idx((1 << 31) - 1));
888-
}
889856
}

servers/src/mining/mine_block.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//! Build a block to mine: gathers transactions from the pool, assembles
1616
//! them into a block and returns it.
1717
18-
use chrono::prelude::{DateTime, NaiveDateTime, Utc};
18+
use chrono::prelude::{DateTime, Utc};
1919
use rand::{thread_rng, Rng};
2020
use serde_json::{json, Value};
2121
use std::sync::Arc;
@@ -168,11 +168,11 @@ fn build_block(
168168

169169
b.header.pow.nonce = thread_rng().gen();
170170
b.header.pow.secondary_scaling = difficulty.secondary_scaling;
171-
let ts = NaiveDateTime::from_timestamp_opt(now_sec, 0);
171+
let ts = DateTime::<Utc>::from_timestamp(now_sec, 0);
172172
if ts.is_none() {
173173
return Err(Error::General("Utc::now into timestamp".into()));
174174
}
175-
b.header.timestamp = DateTime::from_naive_utc_and_offset(ts.unwrap(), Utc);
175+
b.header.timestamp = DateTime::from_naive_utc_and_offset(ts.unwrap().naive_utc(), Utc);
176176

177177
debug!(
178178
"Built new block with {} inputs and {} outputs, block difficulty: {}, cumulative difficulty {}",

src/bin/cmd/client.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ impl HTTPNodeClient {
6363
Err(e) => {
6464
let report = format!("Error calling {}: {}", method, e);
6565
error!("{}", report);
66-
Err(Error::RPCError(report))
66+
Err(Error::RPCError)
6767
}
6868
Ok(inner) => match inner.clone().into_result() {
6969
Ok(r) => Ok(r),
7070
Err(e) => {
7171
error!("{:?}", inner);
7272
let report = format!("Unable to parse response for {}: {}", method, e);
7373
error!("{}", report);
74-
Err(Error::RPCError(report))
74+
Err(Error::RPCError)
7575
}
7676
},
7777
}
@@ -92,6 +92,7 @@ impl HTTPNodeClient {
9292
t.reset().unwrap();
9393
match self.send_json_request::<Status>("get_status", &serde_json::Value::Null) {
9494
Ok(status) => {
95+
writeln!(e, "Chain type: {}", status.chain).unwrap();
9596
writeln!(e, "Protocol version: {:?}", status.protocol_version).unwrap();
9697
writeln!(e, "User agent: {}", status.user_agent).unwrap();
9798
writeln!(e, "Connections: {}", status.connections).unwrap();
@@ -251,5 +252,5 @@ pub fn client_command(client_args: &ArgMatches<'_>, global_config: GlobalConfig)
251252
#[derive(Debug)]
252253
enum Error {
253254
/// RPC Error
254-
RPCError(String),
255+
RPCError,
255256
}

src/bin/tui/mining.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
1717
use std::cmp::Ordering;
1818

19-
use chrono::prelude::{DateTime, NaiveDateTime, Utc};
19+
use chrono::prelude::{DateTime, Utc};
2020
use cursive::direction::Orientation;
2121
use cursive::event::Key;
2222
use cursive::traits::{Nameable, Resizable};
@@ -64,14 +64,15 @@ impl StratumWorkerColumn {
6464

6565
impl TableViewItem<StratumWorkerColumn> for WorkerStats {
6666
fn to_column(&self, column: StratumWorkerColumn) -> String {
67-
let naive_datetime = NaiveDateTime::from_timestamp_opt(
67+
let naive_datetime = DateTime::<Utc>::from_timestamp(
6868
self.last_seen
6969
.duration_since(time::UNIX_EPOCH)
7070
.unwrap()
7171
.as_secs() as i64,
7272
0,
7373
)
74-
.unwrap_or_default();
74+
.unwrap_or_default()
75+
.naive_utc();
7576
let datetime: DateTime<Utc> = DateTime::from_naive_utc_and_offset(naive_datetime, Utc);
7677

7778
match column {
@@ -127,8 +128,9 @@ impl DiffColumn {
127128

128129
impl TableViewItem<DiffColumn> for DiffBlock {
129130
fn to_column(&self, column: DiffColumn) -> String {
130-
let naive_datetime =
131-
NaiveDateTime::from_timestamp_opt(self.time as i64, 0).unwrap_or_default();
131+
let naive_datetime = DateTime::<Utc>::from_timestamp(self.time as i64, 0)
132+
.unwrap_or_default()
133+
.naive_utc();
132134
let datetime: DateTime<Utc> = DateTime::from_naive_utc_and_offset(naive_datetime, Utc);
133135

134136
match column {

src/build/build.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,10 @@ fn main() {
3838
}
3939

4040
// build and versioning information
41-
let mut opts = built::Options::default();
42-
opts.set_dependencies(true);
4341
let out_dir_path = format!("{}{}", env::var("OUT_DIR").unwrap(), "/built.rs");
4442
// don't fail the build if something's missing, may just be cargo release
4543
let _ = built::write_built_file_with_opts(
46-
&opts,
47-
Path::new(env!("CARGO_MANIFEST_DIR")),
44+
Some(Path::new(env!("CARGO_MANIFEST_DIR"))),
4845
Path::new(&out_dir_path),
4946
);
5047
}

0 commit comments

Comments
 (0)