Skip to content

Commit

Permalink
Merge branches 'grarco/namada-start-time' (#973) and 'grarco/resize-b…
Browse files Browse the repository at this point in the history
…lock' (#974) into main

* grarco/namada-start-time:
  changelog: add #973
  Moves ledger sleep
  Refactors ledger sleep
  Adds start time argument to namada ledger

* grarco/resize-block:
  changelog: add #974
  Reduces block size to 5 MiB
  • Loading branch information
juped committed Jan 10, 2023
3 parents e9668eb + 122ec91 + fc81718 commit 3f40ac9
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/features/973-namada-start-time.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add a --time argument to the node to specify the time the node should start.
([#973](https://github.com/anoma/namada/pull/973))
2 changes: 2 additions & 0 deletions .changelog/unreleased/features/974-resize-block.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Reduce the block size for transactions to 5 MiB.
([#974](https://github.com/anoma/namada/pull/974))
20 changes: 19 additions & 1 deletion apps/src/bin/namada-node/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Namada node CLI.
use eyre::{Context, Result};
use namada::types::time::Utc;
use namada_apps::cli::{self, cmds};
use namada_apps::node::ledger;

Expand All @@ -11,8 +12,25 @@ pub fn main() -> Result<()> {
}
match cmd {
cmds::NamadaNode::Ledger(sub) => match sub {
cmds::Ledger::Run(_) => {
cmds::Ledger::Run(cmds::LedgerRun(args)) => {
let wasm_dir = ctx.wasm_dir();

// Sleep until start time if needed
if let Some(time) = args.0 {
if let Ok(sleep_time) =
time.0.signed_duration_since(Utc::now()).to_std()
{
if !sleep_time.is_zero() {
tracing::info!(
"Waiting ledger start time: {:?}, time left: \
{:?}",
time,
sleep_time
);
std::thread::sleep(sleep_time)
}
}
}
ledger::run(ctx.config.ledger, wasm_dir);
}
cmds::Ledger::Reset(_) => {
Expand Down
32 changes: 28 additions & 4 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ pub mod cmds {
let reset = SubCmd::parse(matches).map(Self::Reset);
run.or(reset)
// The `run` command is the default if no sub-command given
.or(Some(Self::Run(LedgerRun)))
.or(Some(Self::Run(LedgerRun(args::LedgerRun(None)))))
})
}

Expand All @@ -782,17 +782,21 @@ pub mod cmds {
}

#[derive(Clone, Debug)]
pub struct LedgerRun;
pub struct LedgerRun(pub args::LedgerRun);

impl SubCmd for LedgerRun {
const CMD: &'static str = "run";

fn parse(matches: &ArgMatches) -> Option<Self> {
matches.subcommand_matches(Self::CMD).map(|_matches| Self)
matches
.subcommand_matches(Self::CMD)
.map(|matches| Self(args::LedgerRun::parse(matches)))
}

fn def() -> App {
App::new(Self::CMD).about("Run Namada ledger node.")
App::new(Self::CMD)
.about("Run Namada ledger node.")
.add_args::<args::LedgerRun>()
}
}

Expand Down Expand Up @@ -1519,6 +1523,7 @@ pub mod args {
use namada::types::key::*;
use namada::types::masp::MaspValue;
use namada::types::storage::{self, Epoch};
use namada::types::time::DateTimeUtc;
use namada::types::token;
use namada::types::transaction::GasLimit;
use rust_decimal::Decimal;
Expand Down Expand Up @@ -1590,6 +1595,7 @@ pub mod args {
arg("max-commission-rate-change");
const MODE: ArgOpt<String> = arg_opt("mode");
const NET_ADDRESS: Arg<SocketAddr> = arg("net-address");
const NAMADA_START_TIME: ArgOpt<DateTimeUtc> = arg_opt("time");
const NO_CONVERSIONS: ArgFlag = flag("no-conversions");
const OWNER: ArgOpt<WalletAddress> = arg_opt("owner");
const PIN: ArgFlag = flag("pin");
Expand Down Expand Up @@ -1686,6 +1692,24 @@ pub mod args {
}
}

#[derive(Clone, Debug)]
pub struct LedgerRun(pub Option<DateTimeUtc>);

impl Args for LedgerRun {
fn parse(matches: &ArgMatches) -> Self {
let time = NAMADA_START_TIME.parse(matches);
Self(time)
}

fn def(app: App) -> App {
app.arg(
NAMADA_START_TIME
.def()
.about("The start time of the ledger."),
)
}
}

/// Transaction associated results arguments
#[derive(Clone, Debug)]
pub struct QueryResult {
Expand Down
4 changes: 2 additions & 2 deletions apps/src/lib/node/ledger/shell/prepare_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use crate::node::ledger::shell::{process_tx, ShellMode};
use crate::node::ledger::shims::abcipp_shim_types::shim::TxBytes;

// TODO: remove this hard-coded value; Tendermint, and thus
// Namada uses 20 MiB max block sizes by default; 16 MiB leaves
// Namada uses 20 MiB max block sizes by default; 5 MiB leaves
// plenty of room for header data, evidence and protobuf serialization
// overhead
const MAX_PROPOSAL_SIZE: usize = 16 << 20;
const MAX_PROPOSAL_SIZE: usize = 5 << 20;
const HALF_MAX_PROPOSAL_SIZE: usize = MAX_PROPOSAL_SIZE / 2;

impl<D, H> Shell<D, H>
Expand Down
10 changes: 10 additions & 0 deletions core/src/types/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
use std::convert::{TryFrom, TryInto};
use std::fmt::Display;
use std::ops::{Add, Sub};
use std::str::FromStr;

use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use chrono::ParseError;
pub use chrono::{DateTime, Duration, TimeZone, Utc};

/// Check if the given `duration` has passed since the given `start.
Expand Down Expand Up @@ -109,6 +111,14 @@ impl DateTimeUtc {
}
}

impl FromStr for DateTimeUtc {
type Err = ParseError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(s.parse::<DateTime<Utc>>()?))
}
}

impl Add<DurationSecs> for DateTimeUtc {
type Output = DateTimeUtc;

Expand Down

0 comments on commit 3f40ac9

Please sign in to comment.