Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit dbaebee
Author: 0o-de-lally <[email protected]>
Date:   Sun Jan 14 17:47:54 2024 +0000

    rename txs cli subcommand "upgrade" -> "governance", and include the epoch boundary tx.

commit a042461
Author: 0o-de-lally <[email protected]>
Date:   Sun Jan 14 17:30:22 2024 +0000

    make governance::trigger_epoch an entry function

commit 2dab0e3
Merge: 918cfb3 a4c2f61
Author: 0o-de-lally <[email protected]>
Date:   Sat Jan 13 22:09:11 2024 +0000

    Merge branch 'main' into epoch_scheduler

commit 918cfb3
Author: 0o-de-lally <[email protected]>
Date:   Sat Jan 13 22:04:20 2024 +0000

    Squashed commit of the following:

    commit a4c2f61
    Author: sirouk <[email protected]>
    Date:   Sat Jan 13 17:01:15 2024 -0500

        [move] set slow wallet entry function (#141)

        Co-authored-by: 0o-de-lally <>
        Co-authored-by: 0o-de-lally <[email protected]>

    commit 6b57485
    Author: sirouk <[email protected]>
    Date:   Sat Jan 13 17:01:01 2024 -0500

        [move] patch arithmetic issue on net_val_reward 6.9.2 (#142)

        Co-authored-by: 0o-de-lally <[email protected]>
        Co-authored-by: Nonast <[email protected]>
        Co-authored-by: sh1hsh1nk <[email protected]>

    commit d982a70
    Author: zoz <[email protected]>
    Date:   Sat Jan 13 13:53:23 2024 -0800

        [tools] refactor rescue cli 6.9.1 (#137)

        Co-authored-by: 0o-de-lally <[email protected]>

commit db2813c
Author: 0o-de-lally <[email protected]>
Date:   Wed Dec 20 15:52:16 2023 +0000

    clean

commit d8cb2a6
Author: 0o-de-lally <[email protected]>
Date:   Mon Dec 18 18:25:30 2023 +0000

    notest

commit 5e4d26d
Author: 0o-de-lally <[email protected]>
Date:   Mon Dec 18 18:22:09 2023 +0000

    finish tests

commit d57ba94
Author: 0o-de-lally <[email protected]>
Date:   Mon Dec 18 16:02:34 2023 +0000

    and user can trigger epoch on boundary. functional test written.

commit b6b43ea
Author: 0o-de-lally <[email protected]>
Date:   Sun Dec 17 02:46:03 2023 +0000

    wip epoch count issue passing

commit c6ebe43
Author: 0o-de-lally <[email protected]>
Date:   Sun Dec 17 02:44:53 2023 +0000

    wip epoch count issue

commit ce3c1e8
Author: 0o-de-lally <[email protected]>
Date:   Sun Dec 17 01:48:21 2023 +0000

    patch

commit 43cacc6
Author: 0o-de-lally <[email protected]>
Date:   Sun Dec 17 01:47:15 2023 +0000

    enable epoch trigger
  • Loading branch information
0o-de-lally committed Jan 14, 2024
1 parent 464535a commit b1699e2
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 42 deletions.
48 changes: 48 additions & 0 deletions framework/cached-packages/src/libra_framework_sdk_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ pub enum EntryFunctionCall {
should_pass: bool,
},

/// Any end user can triger epoch/boundary and reconfiguration
/// as long as the VM set the BoundaryBit to true.
/// We do this because we don't want the VM calling complex
/// logic itself. Any abort would cause a halt.
/// On the other hand, a user can call the function once the VM
/// decides the epoch can change. Any error will just cause the
/// user's transaction to abort, but the chain will continue.
/// Whatever fix is needed can be done online with on-chain governance.
DiemGovernanceTriggerEpoch {},

/// Vote on proposal with `proposal_id` and voting power from `stake_pool`.
DiemGovernanceVote {
proposal_id: u64,
Expand Down Expand Up @@ -681,6 +691,7 @@ impl EntryFunctionCall {
proposal_id,
should_pass,
} => diem_governance_ol_vote(proposal_id, should_pass),
DiemGovernanceTriggerEpoch {} => diem_governance_trigger_epoch(),
DiemGovernanceVote {
proposal_id,
should_pass,
Expand Down Expand Up @@ -1367,6 +1378,29 @@ pub fn diem_governance_ol_vote(proposal_id: u64, should_pass: bool) -> Transacti
))
}

/// Any end user can triger epoch/boundary and reconfiguration
/// as long as the VM set the BoundaryBit to true.
/// We do this because we don't want the VM calling complex
/// logic itself. Any abort would cause a halt.
/// On the other hand, a user can call the function once the VM
/// decides the epoch can change. Any error will just cause the
/// user's transaction to abort, but the chain will continue.
/// Whatever fix is needed can be done online with on-chain governance.
pub fn diem_governance_trigger_epoch() -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("diem_governance").to_owned(),
),
ident_str!("trigger_epoch").to_owned(),
vec![],
vec![],
))
}

/// Vote on proposal with `proposal_id` and voting power from `stake_pool`.
pub fn diem_governance_vote(proposal_id: u64, should_pass: bool) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
Expand Down Expand Up @@ -2652,6 +2686,16 @@ mod decoder {
}
}

pub fn diem_governance_trigger_epoch(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(_script) = payload {
Some(EntryFunctionCall::DiemGovernanceTriggerEpoch {})
} else {
None
}
}

pub fn diem_governance_vote(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::DiemGovernanceVote {
Expand Down Expand Up @@ -3334,6 +3378,10 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
"diem_governance_ol_vote".to_string(),
Box::new(decoder::diem_governance_ol_vote),
);
map.insert(
"diem_governance_trigger_epoch".to_string(),
Box::new(decoder::diem_governance_trigger_epoch),
);
map.insert(
"diem_governance_vote".to_string(),
Box::new(decoder::diem_governance_vote),
Expand Down
Binary file modified framework/releases/head.mrb
Binary file not shown.
2 changes: 1 addition & 1 deletion tools/txs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ pub mod submit_transaction;
pub mod tower;
pub mod transfer;
pub mod txs_cli;
pub mod txs_cli_upgrade;
pub mod txs_cli_governance;
pub mod txs_cli_user;
pub mod txs_cli_vals;
6 changes: 3 additions & 3 deletions tools/txs/src/txs_cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::txs_cli_upgrade::UpgradeTxs;
use crate::txs_cli_governance::GovernanceTxs;
use crate::txs_cli_user::UserTxs;
use crate::txs_cli_vals::ValidatorTxs;
use crate::{publish::encode_publish_payload, submit_transaction::Sender};
Expand Down Expand Up @@ -77,7 +77,7 @@ pub enum TxsSub {
Validator(ValidatorTxs),
#[clap(subcommand)]
/// Network upgrade transactions
Upgrade(UpgradeTxs),
Governance(GovernanceTxs),
/// Transfer coins between accounts. Transferring can also be used to create accounts.
Transfer {
/// Address of the recipient
Expand Down Expand Up @@ -190,7 +190,7 @@ impl TxsCli {
args,
}) => send.generic(function_id, ty_args, args).await,
Some(TxsSub::Validator(val_txs)) => val_txs.run(&mut send).await,
Some(TxsSub::Upgrade(upgrade_txs)) => upgrade_txs.run(&mut send).await,
Some(TxsSub::Governance(upgrade_txs)) => upgrade_txs.run(&mut send).await,
Some(TxsSub::User(user_txs)) => user_txs.run(&mut send).await,
_ => {
println!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ use diem_types::transaction::Script;
use diem_types::transaction::TransactionPayload;

use diem_sdk::types::transaction::TransactionArgument;
use libra_cached_packages::libra_stdlib;
use libra_cached_packages::libra_stdlib::{
diem_governance_ol_create_proposal_v2, diem_governance_ol_vote,
};

#[derive(clap::Subcommand)]
pub enum UpgradeTxs {
pub enum GovernanceTxs {
/// after compiling a proposal script with `libra-framework upgrade` any authorized voter can create a proposal.
Propose {
#[clap(short = 'd', long)]
Expand Down Expand Up @@ -44,12 +45,13 @@ pub enum UpgradeTxs {
/// Path to the directory of the compiled proposal script
proposal_script_dir: PathBuf,
},
EpochBoundary
}

impl UpgradeTxs {
impl GovernanceTxs {
pub async fn run(&self, sender: &mut Sender) -> anyhow::Result<()> {
let payload = match self {
UpgradeTxs::Propose {
GovernanceTxs::Propose {
proposal_script_dir,
metadata_url,
} => {
Expand All @@ -65,18 +67,6 @@ impl UpgradeTxs {
let num =
libra_query::chain_queries::get_next_governance_proposal_id(sender.client())
.await?;
// let query_res = libra_query::query_view::run(
// "0x1::diem_governance::get_next_governance_proposal_id",
// None,
// None,
// )
// .await?;
// // let id: Vec<String> = serde_json::from_value(query_res)?;
// let num: u64 = serde_json::from_value::<Vec<String>>(query_res)?
// .iter()
// .next()
// .context("could not get a response from view function get_next_governance_proposal_id")?
// .parse()?;

println!(
"next proposal id is: {}. Save this and use it for voting.",
Expand All @@ -90,11 +80,11 @@ impl UpgradeTxs {
true,
)
}
UpgradeTxs::Vote {
GovernanceTxs::Vote {
proposal_id,
should_fail,
} => diem_governance_ol_vote(*proposal_id, !*should_fail), // NOTE: we are inverting the BOOL here.
UpgradeTxs::Resolve {
GovernanceTxs::Resolve {
proposal_id,
proposal_script_dir,
} => {
Expand All @@ -108,15 +98,11 @@ impl UpgradeTxs {
bail!("proposal {} has already been resolved", proposal_id);
}

// if !libra_query::chain_queries::can_gov_proposal_resolve(sender.client(), *proposal_id).await.context("error calling view")?{
// bail!("proposal {} is not resolvable", proposal_id);
// }
assert!(
&proposal_script_dir.exists(),
"proposal script cannot be found at {proposal_script_dir:?}"
);

// TODO: get the compiled script
let proposal_bytes = std::fs::read(proposal_script_dir.join("script.mv")).unwrap();

let proposal_script = Script::new(
Expand All @@ -129,6 +115,9 @@ impl UpgradeTxs {

TransactionPayload::Script(proposal_script)
}
GovernanceTxs::EpochBoundary => {
libra_stdlib::diem_governance_trigger_epoch()
},
};

sender.sign_submit_wait(payload).await?;
Expand Down
10 changes: 5 additions & 5 deletions tools/txs/tests/gov_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::str::FromStr;
use libra_query::query_view;
use libra_smoke_tests::{configure_validator, libra_smoke::LibraSmoke};
use libra_txs::{
txs_cli::{TxsCli, TxsSub::Upgrade},
txs_cli_upgrade::UpgradeTxs::{Propose, Resolve, Vote},
txs_cli::{TxsCli, TxsSub::Governance},
txs_cli_governance::GovernanceTxs::{Propose, Resolve, Vote},
};
use libra_types::legacy_types::app_cfg::TxCost;

Expand Down Expand Up @@ -34,7 +34,7 @@ async fn smoke_gov_script() {
assert!(script_dir.exists(), "can't find upgrade fixtures");

let mut cli = TxsCli {
subcommand: Some(Upgrade(Propose {
subcommand: Some(Governance(Propose {
proposal_script_dir: script_dir.clone(),
metadata_url: "http://allyourbase.com".to_string(),
})),
Expand All @@ -53,7 +53,7 @@ async fn smoke_gov_script() {
.expect("cli could not send upgrade proposal");

// ALICE VOTES
cli.subcommand = Some(Upgrade(Vote {
cli.subcommand = Some(Governance(Vote {
proposal_id: 0,
should_fail: false,
}));
Expand Down Expand Up @@ -96,7 +96,7 @@ async fn smoke_gov_script() {
.unwrap();

// Now try to resolve upgrade
cli.subcommand = Some(Upgrade(Resolve {
cli.subcommand = Some(Governance(Resolve {
proposal_id: 0,
proposal_script_dir: script_dir,
}));
Expand Down
14 changes: 7 additions & 7 deletions tools/txs/tests/upgrade_multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use libra_framework::upgrade_fixtures;
use libra_query::query_view;
use libra_smoke_tests::{configure_validator, libra_smoke::LibraSmoke};
use libra_txs::{
txs_cli::{TxsCli, TxsSub::Upgrade},
txs_cli_upgrade::UpgradeTxs::{Propose, Resolve, Vote},
txs_cli::{TxsCli, TxsSub::Governance},
txs_cli_governance::GovernanceTxs::{Propose, Resolve, Vote},
};
use libra_types::legacy_types::app_cfg::TxCost;

Expand Down Expand Up @@ -44,7 +44,7 @@ async fn smoke_upgrade_multiple_steps() {
assert!(script_dir.exists(), "can't find upgrade fixtures");

let mut cli = TxsCli {
subcommand: Some(Upgrade(Propose {
subcommand: Some(Governance(Propose {
proposal_script_dir: script_dir.clone(),
metadata_url: "http://allyourbase.com".to_string(),
})),
Expand All @@ -63,7 +63,7 @@ async fn smoke_upgrade_multiple_steps() {
.expect("cli could not send upgrade proposal");

// ALICE VOTES
cli.subcommand = Some(Upgrade(Vote {
cli.subcommand = Some(Governance(Vote {
proposal_id: 0,
should_fail: false,
}));
Expand Down Expand Up @@ -128,7 +128,7 @@ async fn smoke_upgrade_multiple_steps() {

///////// SHOW TIME, RESOLVE FIRST STEP 1/3////////
// Now try to resolve upgrade
cli.subcommand = Some(Upgrade(Resolve {
cli.subcommand = Some(Governance(Resolve {
proposal_id: 0,
proposal_script_dir: script_dir,
}));
Expand All @@ -140,7 +140,7 @@ async fn smoke_upgrade_multiple_steps() {
let script_dir = upgrade_fixtures::fixtures_path()
.join("upgrade-multi-lib")
.join("2-vendor-stdlib");
cli.subcommand = Some(Upgrade(Resolve {
cli.subcommand = Some(Governance(Resolve {
proposal_id: 0,
proposal_script_dir: script_dir,
}));
Expand All @@ -153,7 +153,7 @@ async fn smoke_upgrade_multiple_steps() {
let script_dir = upgrade_fixtures::fixtures_path()
.join("upgrade-multi-lib")
.join("3-libra-framework");
cli.subcommand = Some(Upgrade(Resolve {
cli.subcommand = Some(Governance(Resolve {
proposal_id: 0,
proposal_script_dir: script_dir,
}));
Expand Down
10 changes: 5 additions & 5 deletions tools/txs/tests/upgrade_single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use libra_framework::upgrade_fixtures;
use libra_query::query_view;
use libra_smoke_tests::{configure_validator, libra_smoke::LibraSmoke};
use libra_txs::{
txs_cli::{TxsCli, TxsSub::Upgrade},
txs_cli_upgrade::UpgradeTxs::{Propose, Resolve, Vote},
txs_cli::{TxsCli, TxsSub::Governance},
txs_cli_governance::GovernanceTxs::{Propose, Resolve, Vote},
};
use libra_types::legacy_types::app_cfg::TxCost;

Expand Down Expand Up @@ -43,7 +43,7 @@ async fn smoke_upgrade_single_step() {
assert!(query_res.is_err(), "expected all_your_base to fail");

let mut cli = TxsCli {
subcommand: Some(Upgrade(Propose {
subcommand: Some(Governance(Propose {
proposal_script_dir: script_dir.clone(),
metadata_url: "http://allyourbase.com".to_string(),
})),
Expand All @@ -62,7 +62,7 @@ async fn smoke_upgrade_single_step() {
.expect("cli could not send upgrade proposal");

// ALICE VOTES
cli.subcommand = Some(Upgrade(Vote {
cli.subcommand = Some(Governance(Vote {
proposal_id: 0,
should_fail: false,
}));
Expand Down Expand Up @@ -127,7 +127,7 @@ async fn smoke_upgrade_single_step() {

///////// SHOWTIME ////////
// Now try to resolve upgrade
cli.subcommand = Some(Upgrade(Resolve {
cli.subcommand = Some(Governance(Resolve {
proposal_id: 0,
proposal_script_dir: script_dir,
}));
Expand Down

0 comments on commit b1699e2

Please sign in to comment.