Skip to content
This repository has been archived by the owner on Jan 27, 2025. It is now read-only.

Commit

Permalink
Val Universe Transactions (#470)
Browse files Browse the repository at this point in the history
* check autopay instruction add to < 100%

* autopay safety feature, abort on user deny autopay instruction

* patch autopay checking balance, patch IS_CI global

* rename validator universe tx scripts

* add error codes to validator universe join
  • Loading branch information
0o-de-lally authored May 2, 2021
1 parent 1732c79 commit b854b44
Show file tree
Hide file tree
Showing 25 changed files with 211 additions and 138 deletions.
76 changes: 38 additions & 38 deletions client/transaction-builder/src/stdlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,8 @@ pub enum ScriptCall {

Join {},

Leave {},

MinerstateCommit {
challenge: Bytes,
solution: Bytes,
Expand Down Expand Up @@ -912,8 +914,6 @@ pub enum ScriptCall {
fullnode_network_addresses: Bytes,
},

RemoveSelf {},

/// # Summary
/// This script removes a validator account from the validator set, and triggers a reconfiguration
/// of the system to remove the validator from the system. This transaction can only be
Expand Down Expand Up @@ -1667,6 +1667,7 @@ impl ScriptCall {
to_freeze_account,
} => encode_freeze_account_script(sliding_nonce, to_freeze_account),
Join {} => encode_join_script(),
Leave {} => encode_leave_script(),
MinerstateCommit {
challenge,
solution,
Expand Down Expand Up @@ -1734,7 +1735,6 @@ impl ScriptCall {
validator_network_addresses,
fullnode_network_addresses,
),
RemoveSelf {} => encode_remove_self_script(),
RemoveValidatorAndReconfigure {
sliding_nonce,
validator_name,
Expand Down Expand Up @@ -2639,6 +2639,10 @@ pub fn encode_join_script() -> Script {
Script::new(JOIN_CODE.to_vec(), vec![], vec![])
}

pub fn encode_leave_script() -> Script {
Script::new(LEAVE_CODE.to_vec(), vec![], vec![])
}

pub fn encode_minerstate_commit_script(challenge: Vec<u8>, solution: Vec<u8>) -> Script {
Script::new(
MINERSTATE_COMMIT_CODE.to_vec(),
Expand Down Expand Up @@ -2936,10 +2940,6 @@ pub fn encode_register_validator_config_script(
)
}

pub fn encode_remove_self_script() -> Script {
Script::new(REMOVE_SELF_CODE.to_vec(), vec![], vec![])
}

/// # Summary
/// This script removes a validator account from the validator set, and triggers a reconfiguration
/// of the system to remove the validator from the system. This transaction can only be
Expand Down Expand Up @@ -3850,6 +3850,10 @@ fn decode_join_script(_script: &Script) -> Option<ScriptCall> {
Some(ScriptCall::Join {})
}

fn decode_leave_script(_script: &Script) -> Option<ScriptCall> {
Some(ScriptCall::Leave {})
}

fn decode_minerstate_commit_script(script: &Script) -> Option<ScriptCall> {
Some(ScriptCall::MinerstateCommit {
challenge: decode_u8vector_argument(script.args().get(0)?.clone())?,
Expand Down Expand Up @@ -3932,10 +3936,6 @@ fn decode_register_validator_config_script(script: &Script) -> Option<ScriptCall
})
}

fn decode_remove_self_script(_script: &Script) -> Option<ScriptCall> {
Some(ScriptCall::RemoveSelf {})
}

fn decode_remove_validator_and_reconfigure_script(script: &Script) -> Option<ScriptCall> {
Some(ScriptCall::RemoveValidatorAndReconfigure {
sliding_nonce: decode_u64_argument(script.args().get(0)?.clone())?,
Expand Down Expand Up @@ -4138,6 +4138,7 @@ static SCRIPT_DECODER_MAP: once_cell::sync::Lazy<DecoderMap> = once_cell::sync::
Box::new(decode_freeze_account_script),
);
map.insert(JOIN_CODE.to_vec(), Box::new(decode_join_script));
map.insert(LEAVE_CODE.to_vec(), Box::new(decode_leave_script));
map.insert(
MINERSTATE_COMMIT_CODE.to_vec(),
Box::new(decode_minerstate_commit_script),
Expand Down Expand Up @@ -4175,10 +4176,6 @@ static SCRIPT_DECODER_MAP: once_cell::sync::Lazy<DecoderMap> = once_cell::sync::
REGISTER_VALIDATOR_CONFIG_CODE.to_vec(),
Box::new(decode_register_validator_config_script),
);
map.insert(
REMOVE_SELF_CODE.to_vec(),
Box::new(decode_remove_self_script),
);
map.insert(
REMOVE_VALIDATOR_AND_RECONFIGURE_CODE.to_vec(),
Box::new(decode_remove_validator_and_reconfigure_script),
Expand Down Expand Up @@ -4466,19 +4463,32 @@ const FREEZE_ACCOUNT_CODE: &[u8] = &[
];

const JOIN_CODE: &[u8] = &[
161, 28, 235, 11, 1, 0, 0, 0, 5, 1, 0, 6, 3, 6, 35, 5, 41, 16, 7, 57, 128, 1, 8, 185, 1, 16, 0,
0, 0, 1, 0, 2, 0, 3, 0, 1, 0, 1, 4, 2, 3, 0, 2, 5, 2, 4, 0, 2, 6, 3, 1, 0, 2, 7, 3, 1, 0, 2, 8,
3, 1, 0, 2, 9, 2, 4, 0, 2, 6, 12, 5, 1, 1, 1, 6, 12, 1, 5, 0, 3, 5, 1, 3, 10, 77, 105, 110,
101, 114, 83, 116, 97, 116, 101, 6, 83, 105, 103, 110, 101, 114, 17, 86, 97, 108, 105, 100, 97,
116, 111, 114, 85, 110, 105, 118, 101, 114, 115, 101, 17, 110, 111, 100, 101, 95, 97, 98, 111,
118, 101, 95, 116, 104, 114, 101, 115, 104, 10, 97, 100, 100, 114, 101, 115, 115, 95, 111, 102,
8, 97, 100, 100, 95, 115, 101, 108, 102, 16, 101, 120, 105, 115, 116, 115, 95, 106, 97, 105,
108, 101, 100, 98, 105, 116, 14, 105, 115, 95, 105, 110, 95, 117, 110, 105, 118, 101, 114, 115,
101, 9, 105, 115, 95, 106, 97, 105, 108, 101, 100, 11, 117, 110, 106, 97, 105, 108, 95, 115,
101, 108, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 5, 37, 10, 0, 17, 1, 12,
1, 10, 0, 10, 1, 17, 0, 12, 2, 11, 2, 3, 13, 11, 0, 1, 6, 1, 0, 0, 0, 0, 0, 0, 0, 39, 10, 1,
17, 4, 32, 3, 18, 5, 20, 10, 0, 17, 2, 10, 1, 17, 3, 32, 3, 25, 5, 27, 10, 0, 17, 6, 10, 1, 17,
5, 3, 31, 5, 34, 11, 0, 17, 6, 5, 36, 11, 0, 1, 2,
161, 28, 235, 11, 1, 0, 0, 0, 6, 1, 0, 8, 3, 8, 45, 5, 53, 18, 7, 71, 160, 1, 8, 231, 1, 16, 6,
247, 1, 10, 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 0, 0, 1, 5, 1, 2, 0, 2, 6, 3, 4, 0, 3, 7, 3, 5, 0,
3, 8, 4, 2, 0, 3, 9, 3, 5, 0, 3, 10, 4, 2, 0, 3, 11, 4, 2, 0, 3, 12, 3, 5, 0, 1, 3, 2, 6, 12,
5, 1, 1, 1, 6, 12, 1, 5, 0, 3, 5, 1, 3, 6, 69, 114, 114, 111, 114, 115, 10, 77, 105, 110, 101,
114, 83, 116, 97, 116, 101, 6, 83, 105, 103, 110, 101, 114, 17, 86, 97, 108, 105, 100, 97, 116,
111, 114, 85, 110, 105, 118, 101, 114, 115, 101, 13, 105, 110, 118, 97, 108, 105, 100, 95, 115,
116, 97, 116, 101, 17, 110, 111, 100, 101, 95, 97, 98, 111, 118, 101, 95, 116, 104, 114, 101,
115, 104, 10, 97, 100, 100, 114, 101, 115, 115, 95, 111, 102, 8, 97, 100, 100, 95, 115, 101,
108, 102, 16, 101, 120, 105, 115, 116, 115, 95, 106, 97, 105, 108, 101, 100, 98, 105, 116, 10,
105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 14, 105, 115, 95, 105, 110, 95, 117, 110, 105,
118, 101, 114, 115, 101, 9, 105, 115, 95, 106, 97, 105, 108, 101, 100, 11, 117, 110, 106, 97,
105, 108, 95, 115, 101, 108, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 8, 1, 0,
0, 0, 0, 0, 0, 0, 0, 3, 6, 40, 10, 0, 17, 2, 12, 1, 10, 0, 10, 1, 17, 1, 7, 0, 17, 0, 12, 3,
12, 2, 11, 2, 3, 16, 11, 0, 1, 11, 3, 39, 10, 1, 17, 6, 32, 3, 21, 5, 23, 10, 0, 17, 3, 10, 1,
17, 4, 32, 3, 28, 5, 30, 10, 0, 17, 5, 10, 1, 17, 7, 3, 34, 5, 37, 11, 0, 17, 8, 5, 39, 11, 0,
1, 2,
];

const LEAVE_CODE: &[u8] = &[
161, 28, 235, 11, 1, 0, 0, 0, 5, 1, 0, 4, 3, 4, 15, 5, 19, 8, 7, 27, 63, 8, 90, 16, 0, 0, 0, 1,
0, 2, 0, 1, 0, 1, 3, 1, 2, 0, 1, 4, 0, 3, 0, 1, 6, 12, 1, 5, 1, 1, 0, 6, 83, 105, 103, 110,
101, 114, 17, 86, 97, 108, 105, 100, 97, 116, 111, 114, 85, 110, 105, 118, 101, 114, 115, 101,
10, 97, 100, 100, 114, 101, 115, 115, 95, 111, 102, 14, 105, 115, 95, 105, 110, 95, 117, 110,
105, 118, 101, 114, 115, 101, 11, 114, 101, 109, 111, 118, 101, 95, 115, 101, 108, 102, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 13, 10, 0, 17, 0, 12, 1, 10, 1, 17, 1, 3, 7,
5, 10, 11, 0, 17, 2, 5, 12, 11, 0, 1, 2,
];

const MINERSTATE_COMMIT_CODE: &[u8] = &[
Expand Down Expand Up @@ -4596,16 +4606,6 @@ const REGISTER_VALIDATOR_CONFIG_CODE: &[u8] = &[
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 7, 11, 0, 10, 1, 11, 2, 11, 3, 11, 4, 17, 0, 2,
];

const REMOVE_SELF_CODE: &[u8] = &[
161, 28, 235, 11, 1, 0, 0, 0, 5, 1, 0, 4, 3, 4, 15, 5, 19, 8, 7, 27, 63, 8, 90, 16, 0, 0, 0, 1,
0, 2, 0, 1, 0, 1, 3, 1, 2, 0, 1, 4, 0, 3, 0, 1, 6, 12, 1, 5, 1, 1, 0, 6, 83, 105, 103, 110,
101, 114, 17, 86, 97, 108, 105, 100, 97, 116, 111, 114, 85, 110, 105, 118, 101, 114, 115, 101,
10, 97, 100, 100, 114, 101, 115, 115, 95, 111, 102, 14, 105, 115, 95, 105, 110, 95, 117, 110,
105, 118, 101, 114, 115, 101, 11, 114, 101, 109, 111, 118, 101, 95, 115, 101, 108, 102, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 13, 10, 0, 17, 0, 12, 1, 10, 1, 17, 1, 3, 7,
5, 10, 11, 0, 17, 2, 5, 12, 11, 0, 1, 2,
];

const REMOVE_VALIDATOR_AND_RECONFIGURE_CODE: &[u8] = &[
161, 28, 235, 11, 1, 0, 0, 0, 5, 1, 0, 6, 3, 6, 15, 5, 21, 24, 7, 45, 95, 8, 140, 1, 16, 0, 0,
0, 1, 0, 2, 1, 3, 0, 1, 0, 2, 4, 2, 3, 0, 0, 5, 4, 1, 0, 2, 6, 12, 3, 0, 1, 5, 1, 10, 2, 2, 6,
Expand Down
46 changes: 46 additions & 0 deletions config/management/genesis/src/keyscheme.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//! Key derivation for 0L.
use libra_types::{transaction::authenticator::AuthenticationKey, account_address::AccountAddress};
use libra_wallet::{Mnemonic, WalletLibrary, key_factory::{ChildNumber, ExtendedPrivKey}};

/// The key derivation used throughout 0L for configuration of validators and miners. Depended on by config/management for genesis.
// #[derive(Debug)]
pub struct KeyScheme {
/// Owner key, the main key where funds are kept
pub child_0_owner: ExtendedPrivKey,
/// Operator of node
pub child_1_operator: ExtendedPrivKey,
/// Validator network identity
pub child_2_val_network: ExtendedPrivKey,
/// Fullnode network identity
pub child_3_fullnode_network: ExtendedPrivKey,
/// Consensus key
pub child_4_consensus: ExtendedPrivKey,
/// Execution key
pub child_5_executor: ExtendedPrivKey,
}

impl KeyScheme {
/// Generates the necessary private keys for validator and full node set up.
pub fn new(wallet: &WalletLibrary) -> Self {
let kf = wallet.get_key_factory();
Self {
child_0_owner: kf.private_child(ChildNumber::new(0)).unwrap(),
child_1_operator: kf.private_child(ChildNumber::new(1)).unwrap(),
child_2_val_network: kf.private_child(ChildNumber::new(2)).unwrap(),
child_3_fullnode_network: kf.private_child(ChildNumber::new(3)).unwrap(),
child_4_consensus: kf.private_child(ChildNumber::new(4)).unwrap(),
child_5_executor: kf.private_child(ChildNumber::new(5)).unwrap(),
}
}
/// Get KeyScheme from a mnemonic string.
pub fn new_from_mnemonic(mnemonic: String) -> KeyScheme {
let wallet = WalletLibrary::new_from_mnemonic(Mnemonic::from(&mnemonic).unwrap());
KeyScheme::new(&wallet)
}
/// Returns the default owner address given the key derivation.
pub fn derived_address(&self) -> AccountAddress {
let staged_owner_auth_key = AuthenticationKey::ed25519(&self.child_0_owner.get_public());
staged_owner_auth_key.derived_address()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ fun main(sender: &signer) {

//! new-transaction
//! sender: eve
stdlib_script::ol_join_validator_set
stdlib_script::ol_validator_universe_join
// check: "Keep(EXECUTED)"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Carol removes herself as a validator
//! new-transaction
//! sender: carol
stdlib_script::ol_remove_self_validator_universe
stdlib_script::ol_validator_universe_leave
// check: "Keep(EXECUTED)"


Expand Down Expand Up @@ -149,7 +149,7 @@ fun main(sender: &signer) {

//! new-transaction
//! sender: carol
stdlib_script::ol_join_validator_set
stdlib_script::ol_validator_universe_join
// check: "Keep(EXECUTED)"


Expand Down
8 changes: 4 additions & 4 deletions language/stdlib/compiled/src/transaction_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub enum StdlibScript {
CreateUserAccount,
Join,
Demo,
Remove,
Leave,
// ...add new scripts here
}

Expand Down Expand Up @@ -117,7 +117,7 @@ impl StdlibScript {
CreateUserAccount,
Join,
Demo,
Remove,
Leave,
// ...add new scripts here
]
}
Expand Down Expand Up @@ -255,9 +255,9 @@ impl fmt::Display for StdlibScript {
MinerStateCommit => "ol_miner_state_commit",
MinerStateOnboarding => "ol_miner_state_onboarding",
CreateUserAccount => "ol_create_user_account",
Join => "ol_join_validator_set",
Demo => "ol_demo_e2e",
Remove => "ol_remove_self_validator_universe",
Join => "ol_validator_universe_join",
Leave => "ol_validator_universe_leave",

}
)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
18 changes: 2 additions & 16 deletions language/stdlib/modules/0L/Subsidy.move
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ address 0x1 {
use 0x1::Testnet::is_testnet;
use 0x1::FullnodeState;
use 0x1::ValidatorConfig;
use 0x1::Debug::print;
use 0x1::MinerState;

// estimated gas unit cost for proof verification divided coin scaling factor
Expand Down Expand Up @@ -70,7 +69,6 @@ address 0x1 {
b"validator subsidy",
b""
);
print(&01);
// refund operator tx fees for mining
refund_operator_tx_fees(vm_sig, node_address);
i = i + 1;
Expand Down Expand Up @@ -361,7 +359,6 @@ address 0x1 {
// FixedPoint32::create_from_raw_value(baseline_auction_units)
// );
let baseline_proof_price = ceiling/baseline_auction_units;
// print(&baseline_proof_price);

// print(&FixedPoint32::get_raw_value(copy baseline_proof_price));
// Calculate the appropriate multiplier.
Expand Down Expand Up @@ -412,35 +409,24 @@ address 0x1 {

// Operators may run out of balance to submit txs for the Validator. This is true for mining, where the operator receives no network subsidy.
fun refund_operator_tx_fees(vm: &signer, miner_addr: address) {
print(&011);
// get operator for validator
let oper_addr = ValidatorConfig::get_operator(miner_addr);
// count OWNER's proofs submitted
print(&012);
let proofs_in_epoch = MinerState::get_count_in_epoch(miner_addr);
print(&proofs_in_epoch);

let cost = 0;
// find cost from baseline
print(&013);
if (proofs_in_epoch > 0) {
cost = BASELINE_TX_COST * proofs_in_epoch;
};
// deduct from subsidy to miner
// send payment to operator
print(&014);
print(&cost);
if (cost > 0) {
print(&0141);

let owner_balance = LibraAccount::balance<GAS>(miner_addr);
print(&01412);

if (!(owner_balance > cost)) {
print(&014121);

cost = owner_balance;
};
print(&015);

LibraAccount::vm_make_payment<GAS>(
miner_addr,
oper_addr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,33 @@



- [Constants](#@Constants_0)


<pre><code><b>use</b> <a href="../../modules/doc/MinerState.md#0x1_MinerState">0x1::MinerState</a>;
<pre><code><b>use</b> <a href="../../modules/doc/Errors.md#0x1_Errors">0x1::Errors</a>;
<b>use</b> <a href="../../modules/doc/MinerState.md#0x1_MinerState">0x1::MinerState</a>;
<b>use</b> <a href="../../modules/doc/Signer.md#0x1_Signer">0x1::Signer</a>;
<b>use</b> <a href="../../modules/doc/ValidatorUniverse.md#0x1_ValidatorUniverse">0x1::ValidatorUniverse</a>;
</code></pre>



<a name="@Constants_0"></a>

<pre><code><b>public</b> <b>fun</b> <a href="ol_join_validator_set.md#join">join</a>(validator: &signer)
## Constants


<a name="join_NOT_ABOVE_THRESH"></a>



<pre><code><b>const</b> <a href="ol_validator_universe_join.md#join_NOT_ABOVE_THRESH">NOT_ABOVE_THRESH</a>: u64 = 1;
</code></pre>




<pre><code><b>public</b> <b>fun</b> <a href="ol_validator_universe_join.md#join">join</a>(validator: &signer)
</code></pre>


Expand All @@ -24,17 +40,17 @@
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="ol_join_validator_set.md#join">join</a>(validator: &signer) {
<pre><code><b>fun</b> <a href="ol_validator_universe_join.md#join">join</a>(validator: &signer) {
<b>let</b> addr = <a href="../../modules/doc/Signer.md#0x1_Signer_address_of">Signer::address_of</a>(validator);
// <b>if</b> is above threshold <b>continue</b>, or raise error.
<b>assert</b>(<a href="../../modules/doc/MinerState.md#0x1_MinerState_node_above_thresh">MinerState::node_above_thresh</a>(validator, addr), 01);
<b>assert</b>(<a href="../../modules/doc/MinerState.md#0x1_MinerState_node_above_thresh">MinerState::node_above_thresh</a>(validator, addr), <a href="../../modules/doc/Errors.md#0x1_Errors_invalid_state">Errors::invalid_state</a>(<a href="ol_validator_universe_join.md#join_NOT_ABOVE_THRESH">NOT_ABOVE_THRESH</a>));
// <b>if</b> is not in universe, add back
<b>if</b> (!<a href="../../modules/doc/ValidatorUniverse.md#0x1_ValidatorUniverse_is_in_universe">ValidatorUniverse::is_in_universe</a>(addr)) {
<a href="../../modules/doc/ValidatorUniverse.md#0x1_ValidatorUniverse_add_self">ValidatorUniverse::add_self</a>(validator);
};
// Initiate jailbit <b>if</b> not present
// Initialize jailbit <b>if</b> not present
<b>if</b> (!<a href="../../modules/doc/ValidatorUniverse.md#0x1_ValidatorUniverse_exists_jailedbit">ValidatorUniverse::exists_jailedbit</a>(addr)) {
<a href="../../modules/doc/ValidatorUniverse.md#0x1_ValidatorUniverse_unjail_self">ValidatorUniverse::unjail_self</a>(validator);
<a href="../../modules/doc/ValidatorUniverse.md#0x1_ValidatorUniverse_initialize">ValidatorUniverse::initialize</a>(validator);
};

// <b>if</b> is jailed, try <b>to</b> unjail
Expand Down
Loading

0 comments on commit b854b44

Please sign in to comment.