Skip to content

Commit

Permalink
TXS Patches (#561)
Browse files Browse the repository at this point in the history
* autopay patches

* patch tests

* migrate autopay patch
  • Loading branch information
0o-de-lally authored Jun 14, 2021
1 parent 3f6252a commit 10c81d5
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 24 deletions.
96 changes: 96 additions & 0 deletions ol/documentation/node_reset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# 0L Configuration Jubilee

## backup your files

```
cd ~
rsync -av --exclude db/ ~/.0L ~/0L_backup_20210607
```

## Create a new user on host

Especially important for those running as root.

Make this a restricted user: do not give the user `sudo`.

For a user with the name `val`:
```
sudo useradd -m val
```

## Switch into new user

```
su val
```

## Add ~/bin to PATH

`~/bin` will be where your binaries will live. You need to add this to the "search path" to execute commands easily.

```
# add to ./bashrc
PATH=~/bin:$PATH
```

Do this: https://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path


TODO: dboreham, tell us what to do.


### Add your ssh pubkey to the new user

Include your public key in .ssh/authorized_key so you can access the user directly from ssh.

```
nano /home/val/.ssh/authorized_keys
```

alternatively copy the file from the /root/.ssh/authorized_keys

```
cp /root/.ssh/authorized_keys /home/val/.ssh/
```


## Fetch latest code

```
git clone https://github.com/OLSF/libra.git --branch main --depth 1 --single-branch
```

## Build binaries
```
cd libra
make bins install
```

## Create Autopay File

For your autopay instructions to be preserved, an `autopay_batch.json` file should exist in your intended config folder (e.g. `~/.0L/autopay_batch.json`).

Here's a blank example: https://github.com/LOL-LLC/donations-record/blob/main/clean.autopay_batch.json

## Recreate config files

Follow these instructions to refresh your node's configurations. This way they will be up to date with the configuration format that other validators have.

Do this first: [Resetting Val Configs](resetting_val_configs.md)


## Restart your services as the new user

Stop your node, miner, monitor and restart

```
# in previous user
ol mgmt --stop all
# in new user
ol start
```
2 changes: 1 addition & 1 deletion ol/documentation/resetting_val_configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Ideally you will start from a fresh new user (not root) on your host.
2. Create all files needed for validator

```
onboard --val --skip-mining --upstream-peer http://ip-address --from-source
onboard --val --skip-mining --upstream-peer http://ip-address --source-path path/to/libra/source
```

This command will prompt for a few configs, including what directory you will be storing configs for that account. It will also prompt for the IP address of the node.
Expand Down
17 changes: 13 additions & 4 deletions ol/onboard/src/commands/fix_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ use ol_keys::wallet;
use ol::config::AppCfg;
use ol_types::pay_instruction::{InstructionType, PayInstruction, write_batch_file};

/// `val-wizard` subcommand
/// `fix` subcommand
#[derive(Command, Debug, Default, Options)]
pub struct FixCmd {
#[options(help = "waypoint to set")]
waypoint: Option<Waypoint>,
#[options(help = "migrate account json")]
account: bool,
#[options(help = "fix operator key")]
operator: bool,
}

impl Runnable for FixCmd {
Expand All @@ -31,11 +35,14 @@ impl Runnable for FixCmd {
// set the waypoint
if let Some(w) = self.waypoint {
key::set_waypoint(home_dir, namespace, w);

}
key::set_operator_key(home_dir, namespace);
if self.operator {
key::set_operator_key(home_dir, namespace);
}

migrate_account_json(&cfg);
if self.account {
migrate_account_json(&cfg);
}
}
}

Expand Down Expand Up @@ -86,10 +93,12 @@ pub fn migrate_autopay_json_4_3_0(cfg: &AppCfg, instructions: Vec<PayInstruction
let vec_instr: Vec<PayInstruction> = instructions.into_iter()
.map(|mut i| {
if i.type_of == InstructionType::PercentOfChange {
i.uid = None;
i.type_of = InstructionType::PercentOfBalance;
i.type_move = None;
i.value_move = None;
i.duration_epochs = Some(1);
i.end_epoch = None;
}
i
})
Expand Down
2 changes: 1 addition & 1 deletion ol/onboard/src/commands/keygen_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use abscissa_core::{Command, Options, Runnable};
use ol_keys::wallet;
/// `version` subcommand
/// `keygen` subcommand
#[derive(Command, Debug, Default, Options)]
pub struct KeygenCmd {}

Expand Down
2 changes: 1 addition & 1 deletion ol/onboard/src/commands/wizard_fn_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use libra_types::waypoint::Waypoint;
use std::{path::PathBuf};
use super::{files_cmd};
use crate::{application::app_config};
/// `val-wizard` subcommand
/// `fullnode wizard` subcommand
#[derive(Command, Debug, Default, Options)]
pub struct FnWizardCmd {
#[options(help = "output path files created, defaults to ~/.0L")]
Expand Down
2 changes: 1 addition & 1 deletion ol/onboard/src/commands/wizard_user_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ol_types::config::AppCfg;
use abscissa_core::{Command, Options, Runnable};
use std::{path::PathBuf};
use ol_types::account;
/// `user-wizard` subcommand
/// `user wizard` subcommand
#[derive(Command, Debug, Default, Options)]
pub struct UserWizardCmd {
#[options(help = "path to write account manifest")]
Expand Down
2 changes: 1 addition & 1 deletion ol/onboard/src/commands/wizard_val_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use reqwest::Url;
use std::process::exit;
use std::{fs::File, io::Write, path::PathBuf};
use txs::{commands::autopay_batch_cmd, submit_tx};
/// `val-wizard` subcommand
/// `validator wizard` subcommand
#[derive(Command, Debug, Default, Options)]
pub struct ValWizardCmd {
#[options(
Expand Down
15 changes: 9 additions & 6 deletions ol/txs/src/commands/autopay_batch_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ pub fn process_instructions(instructions: Vec<PayInstruction>) -> Vec<Script> {
exit(1);
},
}
match i.duration_epochs.unwrap() > 0 {
true => {},
false => {
println!("Instructions must have duration greater than 0. Exiting. Instruction: {:?}", &i);
exit(1);
},

if i.duration_epochs.is_none() || i.duration_epochs.unwrap() < 1 {
println!("Instructions must have epoch_duration greater than 0. Exiting. Instruction: {:?}", &i);
exit(1);
}

if i.end_epoch.is_none() || i.end_epoch.unwrap() < 1 {
println!("Instructions must have end_epoch greater than 0. Exiting. Instruction: {:?}", &i);
exit(1);
}

println!("{}", i.text_instruction());
Expand Down
24 changes: 15 additions & 9 deletions ol/types/src/pay_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,17 @@ impl PayInstruction {
inst.uid = Some(new_uid + i as u64);

if inst.end_epoch.is_none()
&& inst.duration_epochs.is_none()
&& inst.type_of != InstructionType::FixedOnce {
println!(
"Need to set end_epoch, or duration_epoch in instruction: {:?}",
&inst
);
exit(1);
&& inst.duration_epochs.is_none() {

if inst.type_of != InstructionType::FixedOnce {
println!(
"Need to set end_epoch, or duration_epoch in instruction: {:?}",
&inst
);
exit(1);
} else {
inst.duration_epochs = Some(1);
}
}

if let Some(duration) = inst.duration_epochs {
Expand All @@ -103,6 +107,8 @@ impl PayInstruction {
println!("If you are setting a duration_epochs instruction, we need the current epoch. Instruction: {:?}", &inst);
exit(1);
}
} else {

}

match inst.type_of {
Expand Down Expand Up @@ -197,7 +203,7 @@ impl PayInstruction {
},
InstructionType::PercentOfChange => {
format!(
"Instruction {uid}: {note}\nSend {percent_balance:.2?}% new incoming funds every day {times} (until epoch {epoch_ending}) to address: {destination}?",
"Instruction {uid}: {note}\nSend {percent_balance:.2?}% of new incoming funds every day {times} (until epoch {epoch_ending}) to address: {destination}?",
uid = &self.uid.unwrap(),
percent_balance = *&self.value_move.unwrap() as f64 /100f64,
times = times,
Expand Down Expand Up @@ -336,7 +342,7 @@ fn parse_fixed_once_type() {
assert_eq!(fourth.destination, "88E74DFED34420F2AD8032148280A84B".parse::<AccountAddress>().unwrap());
assert_eq!(fourth.type_move, Some(3));
assert_eq!(fourth.duration_epochs, Some(2)); // TODO: This is temporary patch for v4.3.2
assert_eq!(fourth.end_epoch, None);
assert_eq!(fourth.end_epoch, Some(1));
assert_eq!(fourth.type_of, InstructionType::FixedOnce);
assert_eq!(fourth.value_move.unwrap(), 22000000u64);
}
Expand Down

0 comments on commit 10c81d5

Please sign in to comment.