From e042010ac22caba6cc9fc70c745b17f1bf7d666a Mon Sep 17 00:00:00 2001 From: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Date: Tue, 21 Sep 2021 17:02:13 -0400 Subject: [PATCH] V5 Decimal numeric type in Move Vm (#654) * add decimal native * ol_decimal.rs tests * decimal irrational number test * change move decimal type to u128 to use throughout. * patch negative number casting --- Cargo.lock | 5 +- .../diem-framework/modules/0L/Decimal.move | 169 +++++ .../modules/0L/Demo_Bonding.move | 179 +++++ language/diem-framework/modules/doc/Cases.md | 2 +- .../diem-framework/modules/doc/Decimal.md | 648 ++++++++++++++++++ .../modules/doc/Demo_Bonding.md | 249 +++++++ .../diem-framework/modules/doc/DiemAccount.md | 7 +- .../diem-framework/modules/doc/DiemSystem.md | 1 + .../modules/doc/FullnodeSubsidy.md | 396 +---------- .../diem-framework/modules/doc/Genesis.md | 3 +- .../diem-framework/modules/doc/MinerState.md | 84 ++- .../diem-framework/modules/doc/Reconfigure.md | 81 ++- .../diem-framework/modules/doc/Subsidy.md | 51 +- .../modules/doc/ValidatorUniverse.md | 4 +- .../diem-framework/modules/doc/ol_Decimal.md | 553 +++++++++++++++ .../modules/doc/ol_validator.md | 4 +- .../diem-framework/modules/doc/overview.md | 3 +- .../artifacts/current/docs/modules/Cases.md | 2 +- .../artifacts/current/docs/modules/Decimal.md | 648 ++++++++++++++++++ .../current/docs/modules/Demo_Bonding.md | 249 +++++++ .../current/docs/modules/DiemAccount.md | 7 +- .../current/docs/modules/DiemSystem.md | 1 + .../current/docs/modules/FullnodeState.md | 399 ----------- .../current/docs/modules/FullnodeSubsidy.md | 396 +---------- .../artifacts/current/docs/modules/Genesis.md | 3 +- .../current/docs/modules/MinerState.md | 84 ++- .../current/docs/modules/Reconfigure.md | 81 ++- .../artifacts/current/docs/modules/Subsidy.md | 51 +- .../current/docs/modules/ValidatorUniverse.md | 4 +- .../current/docs/modules/ol_validator.md | 4 +- .../current/docs/modules/overview.md | 3 +- .../current/modules/026_MinerState.mv | Bin 0 -> 4881 bytes .../current/modules/027_MinerState.mv | Bin 4827 -> 0 bytes ...orUniverse.mv => 027_ValidatorUniverse.mv} | Bin 1381 -> 1377 bytes .../{029_NodeWeight.mv => 028_NodeWeight.mv} | Bin .../artifacts/current/modules/029_Cases.mv | Bin 0 -> 315 bytes .../artifacts/current/modules/030_Cases.mv | Bin 319 -> 0 bytes .../{031_DiemSystem.mv => 030_DiemSystem.mv} | Bin .../modules/{032_Wallet.mv => 031_Wallet.mv} | Bin .../modules/{033_VASP.mv => 032_VASP.mv} | Bin .../modules/{034_XDX.mv => 033_XDX.mv} | Bin ...ransactionFee.mv => 034_TransactionFee.mv} | Bin .../modules/{036_FIFO.mv => 035_FIFO.mv} | Bin ...lAttestation.mv => 036_DualAttestation.mv} | Bin ...=> 037_DiemTransactionPublishingOption.mv} | Bin .../modules/{039_DiemId.mv => 038_DiemId.mv} | Bin ...natedDealer.mv => 039_DesignatedDealer.mv} | Bin .../{041_ChainId.mv => 040_ChainId.mv} | Bin ...ountFreezing.mv => 041_AccountFreezing.mv} | Bin ...{043_DiemAccount.mv => 042_DiemAccount.mv} | Bin 12853 -> 12867 bytes ..._Authenticator.mv => 043_Authenticator.mv} | Bin ...icKey.mv => 044_SharedEd25519PublicKey.mv} | Bin ...overyAddress.mv => 045_RecoveryAddress.mv} | Bin ...mv => 046_AccountAdministrationScripts.mv} | Bin ...ripts.mv => 047_AccountCreationScripts.mv} | Bin .../modules/{026_Debug.mv => 048_Debug.mv} | Bin .../artifacts/current/modules/053_Decimal.mv | Bin 0 -> 1025 bytes .../artifacts/current/modules/054_Bonding.mv | Bin 0 -> 801 bytes .../modules/{053_Burn.mv => 055_Burn.mv} | Bin .../artifacts/current/modules/055_Subsidy.mv | Bin 2013 -> 0 bytes ...{054_DemoScripts.mv => 056_DemoScripts.mv} | Bin .../current/modules/056_FullnodeSubsidy.mv | Bin 1620 -> 0 bytes .../artifacts/current/modules/057_Subsidy.mv | Bin 0 -> 2257 bytes .../current/modules/058_FullnodeSubsidy.mv | Bin 0 -> 488 bytes .../current/modules/058_Reconfigure.mv | Bin 1726 -> 0 bytes .../modules/{057_Epoch.mv => 059_Epoch.mv} | Bin .../current/modules/060_Reconfigure.mv | Bin 0 -> 1950 bytes .../{059_Migrations.mv => 061_Migrations.mv} | Bin .../{060_DiemBlock.mv => 062_DiemBlock.mv} | Bin ...usConfig.mv => 063_DiemConsensusConfig.mv} | Bin ...62_DiemVMConfig.mv => 064_DiemVMConfig.mv} | Bin .../current/modules/064_FullnodeState.mv | Bin 1208 -> 0 bytes ...{063_DiemVersion.mv => 065_DiemVersion.mv} | Bin .../{065_Upgrade.mv => 066_Upgrade.mv} | Bin .../modules/{066_Oracle.mv => 067_Oracle.mv} | Bin .../{067_Genesis.mv => 068_Genesis.mv} | Bin 1074 -> 1029 bytes ...igrateWallets.mv => 069_MigrateWallets.mv} | Bin ...69_TestFixtures.mv => 070_TestFixtures.mv} | Bin ...ateScripts.mv => 071_MinerStateScripts.mv} | Bin ..._OracleScripts.mv => 072_OracleScripts.mv} | Bin ...aymentScripts.mv => 073_PaymentScripts.mv} | Bin ...sistenceDemo.mv => 074_PersistenceDemo.mv} | Bin ....mv => 075_SystemAdministrationScripts.mv} | Bin ...ts.mv => 076_TreasuryComplianceScripts.mv} | Bin ...stedAccounts.mv => 077_TrustedAccounts.mv} | Bin ... => 078_ValidatorAdministrationScripts.mv} | Bin ...atorScripts.mv => 079_ValidatorScripts.mv} | Bin 908 -> 900 bytes ..._WalletScripts.mv => 080_WalletScripts.mv} | Bin language/diem-framework/staged/stdlib.mv | Bin 109077 -> 109040 bytes .../move-binary-format/src/file_format.rs | 2 +- .../tests/0L/decimal/bonding_calc.move | 25 + .../tests/0L/decimal/bonding_init.move | 20 + .../tests/0L/decimal/bonding_mint.move | 29 + .../tests/0L/decimal/decimal_pair.move | 15 + .../tests/0L/decimal/decimal_pair_math.move | 47 ++ .../0L/decimal/decimal_pair_negatives.move | 25 + .../tests/0L/decimal/decimal_pair_power.move | 24 + .../0L/decimal/decimal_pair_rescale.move | 16 + .../tests/0L/decimal/decimal_round_trip.move | 13 + .../0L/decimal/decimal_single_irrational.move | 19 + .../tests/0L/decimal/decimal_single_sqrt.move | 26 + language/move-vm/natives/Cargo.toml | 3 + language/move-vm/natives/src/lib.rs | 3 +- language/move-vm/natives/src/ol_decimal.rs | 272 ++++++++ .../move-vm/runtime/src/native_functions.rs | 18 +- language/move-vm/types/src/gas_schedule.rs | 3 +- .../vm-genesis/src/genesis_gas_schedule.rs | 3 +- 107 files changed, 3569 insertions(+), 1365 deletions(-) create mode 100644 language/diem-framework/modules/0L/Decimal.move create mode 100644 language/diem-framework/modules/0L/Demo_Bonding.move create mode 100644 language/diem-framework/modules/doc/Decimal.md create mode 100644 language/diem-framework/modules/doc/Demo_Bonding.md create mode 100644 language/diem-framework/modules/doc/ol_Decimal.md create mode 100644 language/diem-framework/releases/artifacts/current/docs/modules/Decimal.md create mode 100644 language/diem-framework/releases/artifacts/current/docs/modules/Demo_Bonding.md delete mode 100644 language/diem-framework/releases/artifacts/current/docs/modules/FullnodeState.md create mode 100644 language/diem-framework/releases/artifacts/current/modules/026_MinerState.mv delete mode 100644 language/diem-framework/releases/artifacts/current/modules/027_MinerState.mv rename language/diem-framework/releases/artifacts/current/modules/{028_ValidatorUniverse.mv => 027_ValidatorUniverse.mv} (86%) rename language/diem-framework/releases/artifacts/current/modules/{029_NodeWeight.mv => 028_NodeWeight.mv} (100%) create mode 100644 language/diem-framework/releases/artifacts/current/modules/029_Cases.mv delete mode 100644 language/diem-framework/releases/artifacts/current/modules/030_Cases.mv rename language/diem-framework/releases/artifacts/current/modules/{031_DiemSystem.mv => 030_DiemSystem.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{032_Wallet.mv => 031_Wallet.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{033_VASP.mv => 032_VASP.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{034_XDX.mv => 033_XDX.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{035_TransactionFee.mv => 034_TransactionFee.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{036_FIFO.mv => 035_FIFO.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{037_DualAttestation.mv => 036_DualAttestation.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{038_DiemTransactionPublishingOption.mv => 037_DiemTransactionPublishingOption.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{039_DiemId.mv => 038_DiemId.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{040_DesignatedDealer.mv => 039_DesignatedDealer.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{041_ChainId.mv => 040_ChainId.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{042_AccountFreezing.mv => 041_AccountFreezing.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{043_DiemAccount.mv => 042_DiemAccount.mv} (99%) rename language/diem-framework/releases/artifacts/current/modules/{044_Authenticator.mv => 043_Authenticator.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{045_SharedEd25519PublicKey.mv => 044_SharedEd25519PublicKey.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{046_RecoveryAddress.mv => 045_RecoveryAddress.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{047_AccountAdministrationScripts.mv => 046_AccountAdministrationScripts.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{048_AccountCreationScripts.mv => 047_AccountCreationScripts.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{026_Debug.mv => 048_Debug.mv} (100%) create mode 100644 language/diem-framework/releases/artifacts/current/modules/053_Decimal.mv create mode 100644 language/diem-framework/releases/artifacts/current/modules/054_Bonding.mv rename language/diem-framework/releases/artifacts/current/modules/{053_Burn.mv => 055_Burn.mv} (100%) delete mode 100644 language/diem-framework/releases/artifacts/current/modules/055_Subsidy.mv rename language/diem-framework/releases/artifacts/current/modules/{054_DemoScripts.mv => 056_DemoScripts.mv} (100%) delete mode 100644 language/diem-framework/releases/artifacts/current/modules/056_FullnodeSubsidy.mv create mode 100644 language/diem-framework/releases/artifacts/current/modules/057_Subsidy.mv create mode 100644 language/diem-framework/releases/artifacts/current/modules/058_FullnodeSubsidy.mv delete mode 100644 language/diem-framework/releases/artifacts/current/modules/058_Reconfigure.mv rename language/diem-framework/releases/artifacts/current/modules/{057_Epoch.mv => 059_Epoch.mv} (100%) create mode 100644 language/diem-framework/releases/artifacts/current/modules/060_Reconfigure.mv rename language/diem-framework/releases/artifacts/current/modules/{059_Migrations.mv => 061_Migrations.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{060_DiemBlock.mv => 062_DiemBlock.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{061_DiemConsensusConfig.mv => 063_DiemConsensusConfig.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{062_DiemVMConfig.mv => 064_DiemVMConfig.mv} (100%) delete mode 100644 language/diem-framework/releases/artifacts/current/modules/064_FullnodeState.mv rename language/diem-framework/releases/artifacts/current/modules/{063_DiemVersion.mv => 065_DiemVersion.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{065_Upgrade.mv => 066_Upgrade.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{066_Oracle.mv => 067_Oracle.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{067_Genesis.mv => 068_Genesis.mv} (53%) rename language/diem-framework/releases/artifacts/current/modules/{068_MigrateWallets.mv => 069_MigrateWallets.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{069_TestFixtures.mv => 070_TestFixtures.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{070_MinerStateScripts.mv => 071_MinerStateScripts.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{071_OracleScripts.mv => 072_OracleScripts.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{072_PaymentScripts.mv => 073_PaymentScripts.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{073_PersistenceDemo.mv => 074_PersistenceDemo.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{074_SystemAdministrationScripts.mv => 075_SystemAdministrationScripts.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{075_TreasuryComplianceScripts.mv => 076_TreasuryComplianceScripts.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{076_TrustedAccounts.mv => 077_TrustedAccounts.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{077_ValidatorAdministrationScripts.mv => 078_ValidatorAdministrationScripts.mv} (100%) rename language/diem-framework/releases/artifacts/current/modules/{078_ValidatorScripts.mv => 079_ValidatorScripts.mv} (55%) rename language/diem-framework/releases/artifacts/current/modules/{079_WalletScripts.mv => 080_WalletScripts.mv} (100%) create mode 100644 language/move-lang/functional-tests/tests/0L/decimal/bonding_calc.move create mode 100644 language/move-lang/functional-tests/tests/0L/decimal/bonding_init.move create mode 100644 language/move-lang/functional-tests/tests/0L/decimal/bonding_mint.move create mode 100644 language/move-lang/functional-tests/tests/0L/decimal/decimal_pair.move create mode 100644 language/move-lang/functional-tests/tests/0L/decimal/decimal_pair_math.move create mode 100644 language/move-lang/functional-tests/tests/0L/decimal/decimal_pair_negatives.move create mode 100644 language/move-lang/functional-tests/tests/0L/decimal/decimal_pair_power.move create mode 100644 language/move-lang/functional-tests/tests/0L/decimal/decimal_pair_rescale.move create mode 100644 language/move-lang/functional-tests/tests/0L/decimal/decimal_round_trip.move create mode 100644 language/move-lang/functional-tests/tests/0L/decimal/decimal_single_irrational.move create mode 100644 language/move-lang/functional-tests/tests/0L/decimal/decimal_single_sqrt.move create mode 100644 language/move-vm/natives/src/ol_decimal.rs diff --git a/Cargo.lock b/Cargo.lock index b4f2105514..f35c9d84ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5337,6 +5337,7 @@ dependencies = [ "move-core-types", "move-vm-types", "once_cell", + "rust_decimal", "sha2 0.9.3", "smallvec 1.6.1", "vdf", @@ -7181,9 +7182,9 @@ dependencies = [ [[package]] name = "rust_decimal" -version = "1.10.3" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc7f5b8840fb1f83869a3e1dfd06d93db79ea05311ac5b42b8337d3371caa4f1" +checksum = "c5446d1cf2dfe2d6367c8b27f2082bdf011e60e76fa1fcd140047f535156d6e7" dependencies = [ "arrayvec 0.5.2", "num-traits", diff --git a/language/diem-framework/modules/0L/Decimal.move b/language/diem-framework/modules/0L/Decimal.move new file mode 100644 index 0000000000..13f69168d4 --- /dev/null +++ b/language/diem-framework/modules/0L/Decimal.move @@ -0,0 +1,169 @@ +address 0x1 { +module Decimal { + // The Move Decimal data structure is optimized for readability and compatibility. + // In particular it is indended for compatibility with the underlying rust_decimal crate https://github.com/paupino/rust-decimal. In that library a new decimal type is initialized with Decimal::from_i128_with_scale(mantissa: i128, scale: u32) + // Note: While the underlying Rust crate type has optimal storage characteristics, this Move decimal representation is NOT optimized for storage. + + struct Decimal has key, store, drop { + sign: bool, + int: u128, + scale: u8, // max intger is number 28 + } + + // while stored in u128, the largest integer possible in the rust_decimal vm dependency is 2^96 + const MAX_RUST_DECIMAL_U128: u128 = 79228162514264337593543950335; + + // pair decimal ops + const ADD: u8 = 1; + const SUB: u8 = 2; + const MUL: u8 = 3; + const DIV: u8 = 4; + const POW: u8 = 5; + const ROUND: u8 = 6; + + // single ops + const SQRT: u8 = 100; + const TRUNC: u8 = 101; + + const ROUND_MID_TO_EVEN: u8 = 0; // This is the default in the rust_decimal lib. + const ROUND_MID_FROM_ZERO: u8 = 1; + + + + native public fun decimal_demo(sign: bool, int: u128, scale: u8): (bool, u128, u8); + + native public fun single_op(op_id: u8, sign: bool, int: u128, scale: u8): (bool, u128, u8); + + native public fun pair_op( + op_id: u8, + rounding_strategy_id: u8, + // left number + sign_1: bool, + int_1: u128, + scale_1: u8, + // right number + sign_2: bool, + int_2: u128, + scale_3: u8 + ): (bool, u128, u8); + + public fun new(sign: bool, int: u128, scale: u8): Decimal { + + assert(int < MAX_RUST_DECIMAL_U128, 01); + + // check scale < 28 + assert(scale < 28, 02); + + return Decimal { + sign: sign, + int: int, + scale: scale + } + } + + /////// SUGAR ///////// + public fun trunc(d: &Decimal): Decimal { + let (sign, int, scale) = single_op(TRUNC, *&d.sign, *&d.int, *&d.scale); + return Decimal { + sign: sign, + int: int, + scale: scale, + } + } + + public fun sqrt(d: &Decimal): Decimal { + let (sign, int, scale) = single_op(SQRT, *&d.sign, *&d.int, *&d.scale); + return Decimal { + sign: sign, + int: int, + scale: scale, + } + } + + public fun add(l: &Decimal, r: &Decimal): Decimal { + let (sign, int, scale) = pair_op(ADD, ROUND_MID_TO_EVEN, *&l.sign, *&l.int, *&l.scale, *&r.sign, *&r.int, *&r.scale); + return Decimal { + sign: sign, + int: int, + scale: scale, + } + } + + public fun sub(l: &Decimal, r: &Decimal): Decimal { + let (sign, int, scale) = pair_op(SUB, ROUND_MID_TO_EVEN, *&l.sign, *&l.int, *&l.scale, *&r.sign, *&r.int, *&r.scale); + return Decimal { + sign: sign, + int: int, + scale: scale, + } + } + public fun mul(l: &Decimal, r: &Decimal): Decimal { + let (sign, int, scale) = pair_op(MUL, ROUND_MID_TO_EVEN, *&l.sign, *&l.int, *&l.scale, *&r.sign, *&r.int, *&r.scale); + return Decimal { + sign: sign, + int: int, + scale: scale, + } + } + + public fun div(l: &Decimal, r: &Decimal): Decimal { + let (sign, int, scale) = pair_op(DIV, ROUND_MID_TO_EVEN, *&l.sign, *&l.int, *&l.scale, *&r.sign, *&r.int, *&r.scale); + return Decimal { + sign: sign, + int: int, + scale: scale, + } + } + + + public fun rescale(l: &Decimal, r: &Decimal): Decimal { + let (sign, int, scale) = pair_op(0, ROUND_MID_TO_EVEN, *&l.sign, *&l.int, *&l.scale, *&r.sign, *&r.int, *&r.scale); + return Decimal { + sign: sign, + int: int, + scale: scale, + } + } + + public fun round(l: &Decimal, r: &Decimal, strategy: u8): Decimal { + let (sign, int, scale) = pair_op(ROUND, strategy, *&l.sign, *&l.int, *&l.scale, *&r.sign, *&r.int, *&r.scale); + return Decimal { + sign: sign, + int: int, + scale: scale, + } + } + + + public fun power(l: &Decimal, r: &Decimal): Decimal { + let (sign, int, scale) = pair_op(POW, ROUND_MID_TO_EVEN, *&l.sign, *&l.int, *&l.scale, *&r.sign, *&r.int, *&r.scale); + return Decimal { + sign: sign, + int: int, + scale: scale, + } + } + + ///// GETTERS ///// + + // unwrap creates a new decimal instance + public fun unwrap(d: &Decimal): (bool, u128, u8) { + return (*&d.sign, *&d.int, *&d.scale) + } + + // borrow sign + public fun borrow_sign(d: &Decimal): &bool { + return &d.sign + } + + // borrows the value of the integer + public fun borrow_int(d: &Decimal): &u128 { + return &d.int + } + + // borrow sign + public fun borrow_scale(d: &Decimal): &u8 { + return &d.scale + } +} +} diff --git a/language/diem-framework/modules/0L/Demo_Bonding.move b/language/diem-framework/modules/0L/Demo_Bonding.move new file mode 100644 index 0000000000..072116d5f5 --- /dev/null +++ b/language/diem-framework/modules/0L/Demo_Bonding.move @@ -0,0 +1,179 @@ +address 0x1 { +module Bonding { + // use 0x1::Signer; + use 0x1::Decimal; + use 0x1::Debug::print; + + struct CurveState has key { + is_deprecated: bool, + reserve: u128, //todo: change to Diem, + supply_issued: u128, + } + + struct Token has key, store { + value: u128 + } + + // fun sunset() { + // // if true state.is_deprecated == true + // // allow holders to redeem at the spot price at sunset. + // // cannot receive new deposits + // //TBD + // } + + ///////// Initialization ///////// + public fun initialize_curve( + service: &signer, + deposit: u128, // Diem, + supply_init: u128, + ) { + // let deposit_value = Diem::value(&deposit); + assert(deposit > 0, 7357001); + + let init_state = CurveState { + is_deprecated: false, // deprecate mode + reserve: deposit, + supply_issued: supply_init, + }; + + // This initializes the contract, and stores the contract state at the address of sender. TDB where the state gets stored. + move_to(service, init_state); + + let first_token = Token { + value: supply_init + }; + + // minting the first coin, sponsor is recipent of initial coin. + move_to(service, first_token); + } + + /////////// Calculations ///////// + public fun deposit_calc(add_to_reserve: u128, reserve: u128, supply: u128): u128 { + + let one = Decimal::new(true, 1, 0); + print(&one); + + let add_dec = Decimal::new(true, add_to_reserve, 0); + print(&add_dec); + + let reserve_dec = Decimal::new(true, reserve, 0); + print(&reserve_dec); + + let supply_dec = Decimal::new(true, supply, 0); + print(&supply_dec); + + // formula: + // supply * sqrt(one+(add_to_reserve/reserve)) + + let a = Decimal::div(&add_dec, &reserve_dec); + print(&a); + let b = Decimal::add(&one, &a); + print(&b); + let c = Decimal::sqrt(&b); + print(&c); + let d = Decimal::mul(&supply_dec, &c); + print(&d); + let int = Decimal::borrow_int(&Decimal::trunc(&d)); + print(int); + + return *int + } + +// fun withdraw_curve(remove_from_supply: u128, supply: u128, reserve: u128):u128 { +// // TODO: +// // formula: reserve * (one - remove_from_supply/supply )^2 +// // let one = Decimal::new(true, 1, 0); +// +// +// } + + + ///////// API ///////// + // this simulates the depositing and getting a minted token out, but just using integers, not coin types for now. + public fun test_bond_to_mint(_sender: &signer, service_addr: address, deposit: u128): u128 acquires CurveState { + assert(exists(service_addr), 73570002); + let state = borrow_global_mut(service_addr); + + let post_supply = deposit_calc(deposit, state.reserve, state.supply_issued); + print(&post_supply); + assert(post_supply > state.supply_issued, 73570003); + let mint = post_supply - state.supply_issued; + print(&mint); + // update the new curve state + state.reserve = state.reserve + deposit; + state.supply_issued = state.supply_issued + mint; + // print(&state); + mint + } + +// public fun burn_to_withdraw(sender: &signer, service_addr: address, burn_value: u128):Decimal acquires CurveState, Token { + +// assert(exists(service_addr), 73570002); +// let sender_addr = Signer::address_of(sender); +// assert(exists(sender_addr), 73570003); +// assert(Coin::balance(sender_addr) >= burn_value, 73570004); + +// let state = borrow_global_mut(service_addr); + +// // Calculate the reserve change. +// let remove_from_supply = Decimal::new(burn_value); +// let withdraw_value = withdraw_curve(remove_from_supply, service_addr, state.reserve); + +// withdraw_token_from(sender, burn_value); +// // new curve state +// state.reserve = state.reserve - withdraw_value; +// state.supply = state.supply - burn_value; +// withdraw_value +// } + + +// // Merges a GAS coin. +// fun deposit_gas_and_merge(sender: &signer, coin: GAS) acquires Token { +// //TODO: merges gas coin to bonding curve reserve +// } + +// // Splits a coin to be used. +// fun withdraw_token_and_split_gas(sender: &signer, sub_value: Decimal) acquires Token { +// //TODO: +// } + + +// ///////// GETTERS ///////// + + public fun get_curve_state(sponsor_address: address): (u128, u128) acquires CurveState { + let state = borrow_global(sponsor_address); + (state.reserve, state.supply_issued) + } + +// public fun get_user_balance(addr: address): Decimal acquires Token { +// let state = borrow_global(addr); +// state.value +// } + +// // This is a steady state getter +// public fun calc_spot_price_from_state(sponsor_addr: address): Decimal acquires CurveState { +// let state = borrow_global_mut(sponsor_addr); +// state.kappa * (state.reserve/state.supply) +// } + + +// ///////// TEST ///////// + +// // // NOTE: This "invariant" may not be invariant with rounding issues. +// // public fun test_get_curve_invariant(sponsor_addr: address):Decimal acquires CurveState { +// // let state = borrow_global_mut(sponsor_addr); +// // let two = FixedPoint32::create_from_raw_value(2); +// // let zero = FixedPoint32::create_from_raw_value(0); + +// // // TOOD: when we have native math lib the formula will be: +// // // (state.supply, to power of state.kappa) / state.reserve +// // if (state.kappa == two ) { +// // return (state.supply * state.supply) / state.reserve +// // }; +// // zero +// // } + + + +} +} \ No newline at end of file diff --git a/language/diem-framework/modules/doc/Cases.md b/language/diem-framework/modules/doc/Cases.md index 4e8358b92f..057b0b0e8a 100644 --- a/language/diem-framework/modules/doc/Cases.md +++ b/language/diem-framework/modules/doc/Cases.md @@ -85,7 +85,7 @@ set and/or jailed. To be compliant, validators must be BOTH validating and minin Roles::assert_diem_root(vm); // did the validator sign blocks above threshold? let signs = Stats::node_above_thresh(vm, node_addr, height_start, height_end); - let mines = MinerState::node_above_thresh(vm, node_addr); + let mines = MinerState::node_above_thresh(node_addr); if (signs && mines) { VALIDATOR_COMPLIANT // compliant: in next set, gets paid, weight increments diff --git a/language/diem-framework/modules/doc/Decimal.md b/language/diem-framework/modules/doc/Decimal.md new file mode 100644 index 0000000000..6948bfed0b --- /dev/null +++ b/language/diem-framework/modules/doc/Decimal.md @@ -0,0 +1,648 @@ + + + +# Module `0x1::Decimal` + + + +- [Resource `Decimal`](#0x1_Decimal_Decimal) +- [Constants](#@Constants_0) +- [Function `decimal_demo`](#0x1_Decimal_decimal_demo) +- [Function `single_op`](#0x1_Decimal_single_op) +- [Function `pair_op`](#0x1_Decimal_pair_op) +- [Function `new`](#0x1_Decimal_new) +- [Function `trunc`](#0x1_Decimal_trunc) +- [Function `sqrt`](#0x1_Decimal_sqrt) +- [Function `add`](#0x1_Decimal_add) +- [Function `sub`](#0x1_Decimal_sub) +- [Function `mul`](#0x1_Decimal_mul) +- [Function `div`](#0x1_Decimal_div) +- [Function `rescale`](#0x1_Decimal_rescale) +- [Function `round`](#0x1_Decimal_round) +- [Function `power`](#0x1_Decimal_power) +- [Function `unwrap`](#0x1_Decimal_unwrap) +- [Function `borrow_sign`](#0x1_Decimal_borrow_sign) +- [Function `borrow_int`](#0x1_Decimal_borrow_int) +- [Function `borrow_scale`](#0x1_Decimal_borrow_scale) + + +
+ + + + + +## Resource `Decimal` + + + +
struct Decimal has drop, store, key
+
+ + + +
+Fields + + +
+
+sign: bool +
+
+ +
+
+int: u128 +
+
+ +
+
+scale: u8 +
+
+ +
+
+ + +
+ + + +## Constants + + + + + + +
const ADD: u8 = 1;
+
+ + + + + + + +
const DIV: u8 = 4;
+
+ + + + + + + +
const MAX_RUST_DECIMAL_U128: u128 = 79228162514264337593543950335;
+
+ + + + + + + +
const MUL: u8 = 3;
+
+ + + + + + + +
const POW: u8 = 5;
+
+ + + + + + + +
const ROUND: u8 = 6;
+
+ + + + + + + +
const ROUND_MID_FROM_ZERO: u8 = 1;
+
+ + + + + + + +
const ROUND_MID_TO_EVEN: u8 = 0;
+
+ + + + + + + +
const SQRT: u8 = 100;
+
+ + + + + + + +
const SUB: u8 = 2;
+
+ + + + + + + +
const TRUNC: u8 = 101;
+
+ + + + + +## Function `decimal_demo` + + + +
public fun decimal_demo(sign: bool, int: u128, scale: u8): (bool, u128, u8)
+
+ + + +
+Implementation + + +
native public fun decimal_demo(sign: bool, int: u128, scale: u8): (bool, u128, u8);
+
+ + + +
+ + + +## Function `single_op` + + + +
public fun single_op(op_id: u8, sign: bool, int: u128, scale: u8): (bool, u128, u8)
+
+ + + +
+Implementation + + +
native public fun single_op(op_id: u8, sign: bool, int: u128, scale: u8): (bool, u128, u8);
+
+ + + +
+ + + +## Function `pair_op` + + + +
public fun pair_op(op_id: u8, rounding_strategy_id: u8, sign_1: bool, int_1: u128, scale_1: u8, sign_2: bool, int_2: u128, scale_3: u8): (bool, u128, u8)
+
+ + + +
+Implementation + + +
native public fun pair_op(
+  op_id: u8,
+  rounding_strategy_id: u8,
+  // left number
+  sign_1: bool,
+  int_1: u128,
+  scale_1: u8,
+  // right number
+  sign_2: bool,
+  int_2: u128,
+  scale_3: u8
+): (bool, u128, u8);
+
+ + + +
+ + + +## Function `new` + + + +
public fun new(sign: bool, int: u128, scale: u8): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun new(sign: bool, int: u128, scale: u8): Decimal {
+
+  assert(int < MAX_RUST_DECIMAL_U128, 01);
+
+  // check scale < 28
+  assert(scale < 28, 02);
+
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale
+  }
+}
+
+ + + +
+ + + +## Function `trunc` + + + +
public fun trunc(d: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun trunc(d: &Decimal): Decimal {
+  let (sign, int, scale) = single_op(TRUNC, *&d.sign, *&d.int, *&d.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `sqrt` + + + +
public fun sqrt(d: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun sqrt(d: &Decimal): Decimal {
+  let (sign, int, scale) = single_op(SQRT, *&d.sign, *&d.int, *&d.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `add` + + + +
public fun add(l: &Decimal::Decimal, r: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun add(l: &Decimal, r: &Decimal): Decimal {
+  let (sign, int, scale) = pair_op(ADD, ROUND_MID_TO_EVEN, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `sub` + + + +
public fun sub(l: &Decimal::Decimal, r: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun sub(l: &Decimal, r: &Decimal): Decimal {
+  let (sign, int, scale) = pair_op(SUB, ROUND_MID_TO_EVEN, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `mul` + + + +
public fun mul(l: &Decimal::Decimal, r: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun mul(l: &Decimal, r: &Decimal): Decimal {
+  let (sign, int, scale) = pair_op(MUL, ROUND_MID_TO_EVEN, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `div` + + + +
public fun div(l: &Decimal::Decimal, r: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun div(l: &Decimal, r: &Decimal): Decimal {
+ let (sign, int, scale) = pair_op(DIV, ROUND_MID_TO_EVEN, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+ return Decimal {
+   sign: sign,
+   int: int,
+   scale: scale,
+ }
+}
+
+ + + +
+ + + +## Function `rescale` + + + +
public fun rescale(l: &Decimal::Decimal, r: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun rescale(l: &Decimal, r: &Decimal): Decimal {
+  let (sign, int, scale) = pair_op(0, ROUND_MID_TO_EVEN, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `round` + + + +
public fun round(l: &Decimal::Decimal, r: &Decimal::Decimal, strategy: u8): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun round(l: &Decimal, r: &Decimal, strategy: u8): Decimal {
+  let (sign, int, scale) = pair_op(ROUND, strategy, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `power` + + + +
public fun power(l: &Decimal::Decimal, r: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun power(l: &Decimal, r: &Decimal): Decimal {
+  let (sign, int, scale) = pair_op(POW, ROUND_MID_TO_EVEN, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `unwrap` + + + +
public fun unwrap(d: &Decimal::Decimal): (bool, u128, u8)
+
+ + + +
+Implementation + + +
public fun unwrap(d: &Decimal): (bool, u128, u8) {
+  return (*&d.sign, *&d.int, *&d.scale)
+}
+
+ + + +
+ + + +## Function `borrow_sign` + + + +
public fun borrow_sign(d: &Decimal::Decimal): &bool
+
+ + + +
+Implementation + + +
public fun borrow_sign(d: &Decimal): &bool {
+  return &d.sign
+}
+
+ + + +
+ + + +## Function `borrow_int` + + + +
public fun borrow_int(d: &Decimal::Decimal): &u128
+
+ + + +
+Implementation + + +
public fun borrow_int(d: &Decimal): &u128 {
+  return &d.int
+}
+
+ + + +
+ + + +## Function `borrow_scale` + + + +
public fun borrow_scale(d: &Decimal::Decimal): &u8
+
+ + + +
+Implementation + + +
public fun borrow_scale(d: &Decimal): &u8 {
+  return &d.scale
+}
+
+ + + +
+ + +[//]: # ("File containing references which can be used from documentation") +[ACCESS_CONTROL]: https://github.com/diem/dip/blob/main/dips/dip-2.md +[ROLE]: https://github.com/diem/dip/blob/main/dips/dip-2.md#roles +[PERMISSION]: https://github.com/diem/dip/blob/main/dips/dip-2.md#permissions diff --git a/language/diem-framework/modules/doc/Demo_Bonding.md b/language/diem-framework/modules/doc/Demo_Bonding.md new file mode 100644 index 0000000000..dd0dc0144e --- /dev/null +++ b/language/diem-framework/modules/doc/Demo_Bonding.md @@ -0,0 +1,249 @@ + + + +# Module `0x1::Bonding` + + + +- [Resource `CurveState`](#0x1_Bonding_CurveState) +- [Resource `Token`](#0x1_Bonding_Token) +- [Function `initialize_curve`](#0x1_Bonding_initialize_curve) +- [Function `deposit_calc`](#0x1_Bonding_deposit_calc) +- [Function `test_bond_to_mint`](#0x1_Bonding_test_bond_to_mint) +- [Function `get_curve_state`](#0x1_Bonding_get_curve_state) + + +
use 0x1::Debug;
+use 0x1::Decimal;
+
+ + + + + +## Resource `CurveState` + + + +
struct CurveState has key
+
+ + + +
+Fields + + +
+
+is_deprecated: bool +
+
+ +
+
+reserve: u128 +
+
+ +
+
+supply_issued: u128 +
+
+ +
+
+ + +
+ + + +## Resource `Token` + + + +
struct Token has store, key
+
+ + + +
+Fields + + +
+
+value: u128 +
+
+ +
+
+ + +
+ + + +## Function `initialize_curve` + + + +
public fun initialize_curve(service: &signer, deposit: u128, supply_init: u128)
+
+ + + +
+Implementation + + +
public fun initialize_curve(
+  service: &signer,
+  deposit: u128, // Diem<XUS>,
+  supply_init: u128,
+) {
+  // let deposit_value = Diem::value<XUS>(&deposit);
+  assert(deposit > 0, 7357001);
+
+  let init_state = CurveState {
+    is_deprecated: false, // deprecate mode
+    reserve: deposit,
+    supply_issued: supply_init,
+  };
+
+  // This initializes the contract, and stores the contract state at the address of sender. TDB where the state gets stored.
+  move_to<CurveState>(service, init_state);
+
+  let first_token = Token {
+    value: supply_init
+  };
+
+  // minting the first coin, sponsor is recipent of initial coin.
+  move_to<Token>(service, first_token);
+}
+
+ + + +
+ + + +## Function `deposit_calc` + + + +
public fun deposit_calc(add_to_reserve: u128, reserve: u128, supply: u128): u128
+
+ + + +
+Implementation + + +
public fun deposit_calc(add_to_reserve: u128, reserve: u128, supply: u128): u128 {
+
+  let one = Decimal::new(true, 1, 0);
+  print(&one);
+
+  let add_dec = Decimal::new(true, add_to_reserve, 0);
+  print(&add_dec);
+
+  let reserve_dec = Decimal::new(true, reserve, 0);
+  print(&reserve_dec);
+
+  let supply_dec = Decimal::new(true, supply, 0);
+  print(&supply_dec);
+
+  // formula:
+  // supply * sqrt(one+(add_to_reserve/reserve))
+
+  let a = Decimal::div(&add_dec, &reserve_dec);
+  print(&a);
+  let b = Decimal::add(&one, &a);
+  print(&b);
+  let c = Decimal::sqrt(&b);
+  print(&c);
+  let d = Decimal::mul(&supply_dec, &c);
+  print(&d);
+  let int = Decimal::borrow_int(&Decimal::trunc(&d));
+  print(int);
+
+  return *int
+}
+
+ + + +
+ + + +## Function `test_bond_to_mint` + + + +
public fun test_bond_to_mint(_sender: &signer, service_addr: address, deposit: u128): u128
+
+ + + +
+Implementation + + +
public fun test_bond_to_mint(_sender: &signer, service_addr: address, deposit: u128): u128 acquires CurveState {
+  assert(exists<CurveState>(service_addr), 73570002);
+  let state = borrow_global_mut<CurveState>(service_addr);
+
+  let post_supply = deposit_calc(deposit, state.reserve, state.supply_issued);
+  print(&post_supply);
+  assert(post_supply > state.supply_issued, 73570003);
+  let mint = post_supply - state.supply_issued;
+  print(&mint);
+  // update the new curve state
+  state.reserve = state.reserve + deposit;
+  state.supply_issued = state.supply_issued + mint;
+  // print(&state);
+  mint
+}
+
+ + + +
+ + + +## Function `get_curve_state` + + + +
public fun get_curve_state(sponsor_address: address): (u128, u128)
+
+ + + +
+Implementation + + +
public fun get_curve_state(sponsor_address: address): (u128, u128) acquires CurveState {
+  let state = borrow_global<CurveState>(sponsor_address);
+  (state.reserve, state.supply_issued)
+}
+
+ + + +
+ + +[//]: # ("File containing references which can be used from documentation") +[ACCESS_CONTROL]: https://github.com/diem/dip/blob/main/dips/dip-2.md +[ROLE]: https://github.com/diem/dip/blob/main/dips/dip-2.md#roles +[PERMISSION]: https://github.com/diem/dip/blob/main/dips/dip-2.md#permissions diff --git a/language/diem-framework/modules/doc/DiemAccount.md b/language/diem-framework/modules/doc/DiemAccount.md index 1df966b604..54b2812803 100644 --- a/language/diem-framework/modules/doc/DiemAccount.md +++ b/language/diem-framework/modules/doc/DiemAccount.md @@ -1471,7 +1471,7 @@ Initialize this module. This is only callable from genesis. // NOTE: VDF verification is being called twice! MinerState::init_miner_state(&new_signer, challenge, solution); // TODO: Should fullnode init happen here, or under MinerState::init? - // FullnodeState::init(&new_signer); + // FullnodeState::init(&new_signer); // Create OP Account let new_op_account = create_signer(op_address); Roles::new_validator_operator_role_with_proof(&new_op_account); @@ -2663,7 +2663,10 @@ Return the withdraw capability to the account it originally came from // TODO: Is this the best way to access a struct property from // outside a module? let (payer, payee, value, description) = Wallet::get_tx_args(t); - if (Wallet::is_frozen(payer)) continue; + if (Wallet::is_frozen(payer)) { + i = i + 1; + continue + }; vm_make_payment_no_limit<GAS>(payer, payee, value, description, b"", vm); Wallet::maybe_reset_rejection_counter(vm, payer); i = i + 1; diff --git a/language/diem-framework/modules/doc/DiemSystem.md b/language/diem-framework/modules/doc/DiemSystem.md index c1b66654dc..47de5cb3fb 100644 --- a/language/diem-framework/modules/doc/DiemSystem.md +++ b/language/diem-framework/modules/doc/DiemSystem.md @@ -1377,6 +1377,7 @@ Private function checks for membership of addr in validator set. }; i = i + 1; }; + // calculate the ratio of votes per node. let fee_ratios = Vector::empty<FixedPoint32::FixedPoint32>(); let k = 0; while (k < Vector::length(&compliant_nodes)) { diff --git a/language/diem-framework/modules/doc/FullnodeSubsidy.md b/language/diem-framework/modules/doc/FullnodeSubsidy.md index 27ca11a74c..79c00f193d 100644 --- a/language/diem-framework/modules/doc/FullnodeSubsidy.md +++ b/language/diem-framework/modules/doc/FullnodeSubsidy.md @@ -5,148 +5,27 @@ -- [Resource `FullnodeSubsidy`](#0x1_FullnodeSubsidy_FullnodeSubsidy) -- [Constants](#@Constants_0) -- [Function `init_fullnode_sub`](#0x1_FullnodeSubsidy_init_fullnode_sub) - [Function `get_proof_price`](#0x1_FullnodeSubsidy_get_proof_price) - [Function `distribute_fullnode_subsidy`](#0x1_FullnodeSubsidy_distribute_fullnode_subsidy) -- [Function `fullnode_reconfig`](#0x1_FullnodeSubsidy_fullnode_reconfig) -- [Function `set_global_count`](#0x1_FullnodeSubsidy_set_global_count) -- [Function `baseline_auction_units`](#0x1_FullnodeSubsidy_baseline_auction_units) -- [Function `auctioneer`](#0x1_FullnodeSubsidy_auctioneer) -- [Function `calc_auction`](#0x1_FullnodeSubsidy_calc_auction) -- [Function `fullnode_subsidy_ceiling`](#0x1_FullnodeSubsidy_fullnode_subsidy_ceiling) -- [Function `test_set_fullnode_fixtures`](#0x1_FullnodeSubsidy_test_set_fullnode_fixtures)
use 0x1::CoreAddresses;
 use 0x1::Diem;
 use 0x1::DiemAccount;
 use 0x1::DiemSystem;
-use 0x1::Errors;
 use 0x1::GAS;
 use 0x1::MinerState;
-use 0x1::Roles;
-use 0x1::Signer;
-use 0x1::Testnet;
-use 0x1::TransactionFee;
-use 0x1::Vector;
 
- - -## Resource `FullnodeSubsidy` - - - -
struct FullnodeSubsidy has key
-
- - - -
-Fields - - -
-
-previous_epoch_proofs: u64 -
-
- -
-
-current_proof_price: u64 -
-
- -
-
-current_cap: u64 -
-
- -
-
-current_subsidy_distributed: u64 -
-
- -
-
-current_proofs_verified: u64 -
-
- -
-
- - -
- - - -## Constants - - - - - - -
const BASELINE_TX_COST: u64 = 4336;
-
- - - - - -## Function `init_fullnode_sub` - - - -
public fun init_fullnode_sub(vm: &signer)
-
- - - -
-Implementation - - -
public fun init_fullnode_sub(vm: &signer) {
-  let genesis_validators = DiemSystem::get_val_set_addr();
-  let validator_count = Vector::length(&genesis_validators);
-  if (validator_count < 10) validator_count = 10;
-
-  // baseline_cap: baseline units per epoch times the mininmum as used in tx, times minimum gas per unit.
-
-  let ceiling = baseline_auction_units() * BASELINE_TX_COST * validator_count;
-
-  Roles::assert_diem_root(vm);
-  assert(!exists<FullnodeSubsidy>(Signer::address_of(vm)), Errors::not_published(190106));
-  move_to<FullnodeSubsidy>(vm, FullnodeSubsidy{
-    previous_epoch_proofs: 0u64,
-    current_proof_price: BASELINE_TX_COST * 24 * 8 * 3, // number of proof submisisons in 3 initial epochs.
-    current_cap: ceiling,
-    current_subsidy_distributed: 0u64,
-    current_proofs_verified: 0u64,
-  });
-}
-
- - - -
- ## Function `get_proof_price` -
public fun get_proof_price(subsidy: u64): u64
+
public fun get_proof_price(one_val_subsidy: u64): u64
 
@@ -155,11 +34,15 @@ Implementation -
public fun get_proof_price(subsidy: u64): u64 {
-  // TODO: Check this exclude proofs submitted by validator nodes, or the total reward paid will not equal the pool for fullnodes.
-
+
public fun get_proof_price(one_val_subsidy: u64): u64 {
   let global_proofs = MinerState::get_fullnode_proofs();
-  subsidy/global_proofs
+
+  // proof price is simple, miners divide the equivalent of one compliant validator's subsidy.
+  // miners get a subsidy per proof in their tower.
+
+  // Note to rascals: I know what you're thinking, but for the same effort you'll put into that idea, it would be more profitable to just run a validator node.
+
+  one_val_subsidy/global_proofs
 }
 
@@ -184,7 +67,7 @@
public fun distribute_fullnode_subsidy(vm: &signer, miner: address, subsidy: u64):u64 {
   CoreAddresses::assert_diem_root(vm);
-  // Payment is only for fullnodes, ie. not in current validator set.
+  // Payment is only for fullnodes, ie. not validator candidates
   if (DiemSystem::is_validator(miner)) return 0; // TODO: this check is duplicated in reconfigure
   if (subsidy == 0) return 0;
 
@@ -203,265 +86,6 @@
 
 
 
-
-
-
-
-## Function `fullnode_reconfig`
-
-
-
-
public fun fullnode_reconfig(vm: &signer)
-
- - - -
-Implementation - - -
public fun fullnode_reconfig(vm: &signer) acquires FullnodeSubsidy {
-  Roles::assert_diem_root(vm);
-
-  // update values for the proof auction.
-  auctioneer(vm);
-  let state = borrow_global_mut<FullnodeSubsidy>(Signer::address_of(vm));
-   // save
-  state.previous_epoch_proofs = state.current_proofs_verified;
-  // reset counters
-  state.current_subsidy_distributed = 0u64;
-  state.current_proofs_verified = 0u64;
-}
-
- - - -
- - - -## Function `set_global_count` - - - -
public fun set_global_count(vm: &signer, count: u64)
-
- - - -
-Implementation - - -
public fun set_global_count(vm: &signer, count: u64) acquires FullnodeSubsidy{
-  let state = borrow_global_mut<FullnodeSubsidy>(Signer::address_of(vm));
-  state.current_proofs_verified = count;
-}
-
- - - -
- - - -## Function `baseline_auction_units` - - - -
fun baseline_auction_units(): u64
-
- - - -
-Implementation - - -
fun baseline_auction_units():u64 {
-  let epoch_length_mins = 24 * 60;
-  let steady_state_nodes = 1000;
-  let target_delay_mins = 10;
-  steady_state_nodes * (epoch_length_mins/target_delay_mins)
-}
-
- - - -
- - - -## Function `auctioneer` - - - -
fun auctioneer(vm: &signer)
-
- - - -
-Implementation - - -
fun auctioneer(vm: &signer) acquires FullnodeSubsidy {
-
-  Roles::assert_diem_root(vm);
-
-  let state = borrow_global_mut<FullnodeSubsidy>(Signer::address_of(vm));
-
-  // The targeted amount of proofs to be submitted network-wide per epoch.
-  let baseline_auction_units = baseline_auction_units();
-  // The max subsidy that can be paid out in the next epoch.
-  let ceiling = fullnode_subsidy_ceiling(vm);
-
-
-  // Failure case
-  if (ceiling < 1) ceiling = 1;
-
-  state.current_proof_price = calc_auction(
-    ceiling,
-    baseline_auction_units,
-    state.current_proofs_verified
-  );
-  // Set new ceiling
-  state.current_cap = ceiling;
-}
-
- - - -
- - - -## Function `calc_auction` - - - -
public fun calc_auction(ceiling: u64, baseline_auction_units: u64, current_proofs_verified: u64): u64
-
- - - -
-Implementation - - -
public fun calc_auction(
-  ceiling: u64,
-  baseline_auction_units: u64,
-  current_proofs_verified: u64,
-): u64 {
-  // Calculate price per proof
-  // Find the baseline price of a proof, which will be altered based on performance.
-  // let baseline_proof_price = FixedPoint32::divide_u64(
-  //   ceiling,
-  //   FixedPoint32::create_from_raw_value(baseline_auction_units)
-  // );
-  let baseline_proof_price = ceiling/baseline_auction_units;
-
-  // print(&FixedPoint32::get_raw_value(copy baseline_proof_price));
-  // Calculate the appropriate multiplier.
-  let proofs = current_proofs_verified;
-  if (proofs < 1) proofs = 1;
-
-  let multiplier = baseline_auction_units/proofs;
-
-  // let multiplier = FixedPoint32::create_from_rational(
-  //   baseline_auction_units,
-  //   proofs
-  // );
-  // print(&multiplier);
-
-  // Set the proof price using multiplier.
-  // New unit price cannot be more than the ceiling
-  // let proposed_price = FixedPoint32::multiply_u64(
-  //   baseline_proof_price,
-  //   multiplier
-  // );
-
-  let proposed_price = baseline_proof_price * multiplier;
-
-  // print(&proposed_price);
-
-  if (proposed_price < ceiling) {
-    return proposed_price
-  };
-  //Note: in failure case, the next miner gets the full ceiling
-  return ceiling
-}
-
- - - -
- - - -## Function `fullnode_subsidy_ceiling` - - - -
fun fullnode_subsidy_ceiling(vm: &signer): u64
-
- - - -
-Implementation - - -
fun fullnode_subsidy_ceiling(vm: &signer):u64 {
-  //get TX fees from previous epoch.
-  let fees = TransactionFee::get_amount_to_distribute(vm);
-  // Recover from failure case where there are no fees
-  if (fees < baseline_auction_units()) return baseline_auction_units();
-  fees
-}
-
- - - -
- - - -## Function `test_set_fullnode_fixtures` - - - -
public fun test_set_fullnode_fixtures(vm: &signer, previous_epoch_proofs: u64, current_proof_price: u64, current_cap: u64, current_subsidy_distributed: u64, current_proofs_verified: u64)
-
- - - -
-Implementation - - -
public fun test_set_fullnode_fixtures(
-  vm: &signer,
-  previous_epoch_proofs: u64,
-  current_proof_price: u64,
-  current_cap: u64,
-  current_subsidy_distributed: u64,
-  current_proofs_verified: u64,
-) acquires FullnodeSubsidy {
-  Roles::assert_diem_root(vm);
-  assert(is_testnet(), Errors::invalid_state(190108));
-  let state = borrow_global_mut<FullnodeSubsidy>(@0x0);
-  state.previous_epoch_proofs = previous_epoch_proofs;
-  state.current_proof_price = current_proof_price;
-  state.current_cap = current_cap;
-  state.current_subsidy_distributed = current_subsidy_distributed;
-  state.current_proofs_verified = current_proofs_verified;
-}
-
- - -
diff --git a/language/diem-framework/modules/doc/Genesis.md b/language/diem-framework/modules/doc/Genesis.md index e363c81241..21e6a42529 100644 --- a/language/diem-framework/modules/doc/Genesis.md +++ b/language/diem-framework/modules/doc/Genesis.md @@ -27,7 +27,6 @@ when executing from a fresh state. use 0x1::DiemVersion; use 0x1::DualAttestation; use 0x1::Epoch; -use 0x1::FullnodeSubsidy; use 0x1::GAS; use 0x1::Hash; use 0x1::Migrations; @@ -136,7 +135,7 @@ Initializes the Diem framework. Stats::initialize(dm_account); ValidatorUniverse::initialize(dm_account); AutoPay2::initialize(dm_account); - FullnodeSubsidy::init_fullnode_sub(dm_account); + // FullnodeSubsidy::init_fullnode_sub(dm_account); Oracle::initialize(dm_account); MinerState::init_list(dm_account); Wallet::init(dm_account); diff --git a/language/diem-framework/modules/doc/MinerState.md b/language/diem-framework/modules/doc/MinerState.md index ef1df2b7f4..1467e0e79c 100644 --- a/language/diem-framework/modules/doc/MinerState.md +++ b/language/diem-framework/modules/doc/MinerState.md @@ -57,7 +57,6 @@ TODO
use 0x1::CoreAddresses;
-use 0x1::Debug;
 use 0x1::DiemConfig;
 use 0x1::Errors;
 use 0x1::Globals;
@@ -274,7 +273,7 @@ Struct to encapsulate information about the state of a miner
 
 
 
-
fun increment_stats(global: u64, validator: u64, fullnode: u64)
+
fun increment_stats(miner_addr: address)
 
@@ -283,13 +282,20 @@ Struct to encapsulate information about the state of a miner Implementation -
fun increment_stats(global: u64, validator: u64, fullnode: u64) acquires MinerStats {
+
fun increment_stats(miner_addr: address) acquires MinerStats {
   assert(exists<MinerStats>(CoreAddresses::VM_RESERVED_ADDRESS()), 1301001);
   let state = borrow_global_mut<MinerStats>(CoreAddresses::VM_RESERVED_ADDRESS());
 
-  state.proofs_in_epoch = global;
-  state.validator_proofs = validator;
-  state.fullnode_proofs = fullnode;
+  if (ValidatorConfig::is_valid(miner_addr)) {
+    state.validator_proofs = state.validator_proofs + 1;
+  } else {
+    state.fullnode_proofs = state.fullnode_proofs + 1;
+  };
+
+  state.proofs_in_epoch = state.proofs_in_epoch + 1;
+  // print(&miner_addr);
+  // print(state);
+
 }
 
@@ -524,13 +530,13 @@ adds miner to list of miners //TODO: Previously in OLv3 is_genesis() returned true. How to check that this is part of genesis? is_genesis returns false here. // assert(DiemTimestamp::is_genesis(), 130101024010); - print(&10001); + // print(&10001); init_miner_state(miner_sig, &challenge, &solution); - print(&10002); + // print(&10002); // TODO: Move this elsewhere? // Initialize stats for first validator set from rust genesis. let node_addr = Signer::address_of(miner_sig); - print(&10003); + // print(&10003); Stats::init_address(vm_sig, node_addr); }
@@ -690,15 +696,7 @@ Permissions: PUBLIC, ANYONE miner_history.latest_epoch_mining = DiemConfig::get_current_epoch(); - if (ValidatorConfig::is_valid(miner_addr)) { - // TODO: ValidatorConfig::is_valid is being used here instead of DiemSystem::is_validator() because of dependency cycling. is_validator is used in reconfigure and FullnodeSubsidy - - // increment validator count - increment_stats(1, 1, 0); - } else { - // increment fullnode count - increment_stats(1, 0, 1); - } + increment_stats(miner_addr); }
@@ -732,7 +730,7 @@ Permissions: PUBLIC, ANYONE // Check that there was mining and validating in period. // Account may not have any proofs submitted in epoch, since the resource was last emptied. - let passed = node_above_thresh(account, miner_addr); + let passed = node_above_thresh(miner_addr); let miner_history = borrow_global_mut<MinerProofHistory>(miner_addr); // Update statistics. @@ -766,7 +764,7 @@ Permissions: PUBLIC, ANYONE Checks to see if miner submitted enough proofs to be considered compliant -
public fun node_above_thresh(_account: &signer, miner_addr: address): bool
+
public fun node_above_thresh(miner_addr: address): bool
 
@@ -775,7 +773,7 @@ Checks to see if miner submitted enough proofs to be considered compliant Implementation -
public fun node_above_thresh(_account: &signer, miner_addr: address): bool acquires MinerProofHistory {
+
public fun node_above_thresh(miner_addr: address): bool acquires MinerProofHistory {
   let miner_history = borrow_global<MinerProofHistory>(miner_addr);
   miner_history.count_proofs_in_epoch > Globals::get_epoch_mining_thres_lower()
 }
@@ -927,7 +925,7 @@ Checks to see if miner submitted enough proofs to be considered compliant
   };
 
   // TODO: should fullnode state happen here?
-  // FullnodeState::init(miner_sig);
+  // FullnodeState::init(miner_sig);
 
   //submit the proof
   verify_and_update_state(Signer::address_of(miner_sig), proof, false);
@@ -1071,7 +1069,11 @@ Public Getters ///
 
 
 
public fun get_epochs_mining(node_addr: address): u64 acquires MinerProofHistory {
-  borrow_global<MinerProofHistory>(node_addr).epochs_validating_and_mining
+  if (exists<MinerProofHistory>(node_addr)) {
+    return borrow_global<MinerProofHistory>(node_addr).epochs_validating_and_mining
+
+  };
+  0
 }
 
@@ -1095,7 +1097,10 @@ Public Getters ///
public fun get_count_in_epoch(miner_addr: address): u64 acquires MinerProofHistory {
-  borrow_global<MinerProofHistory>(miner_addr).count_proofs_in_epoch
+  if (exists<MinerProofHistory>(miner_addr)) {
+    return borrow_global<MinerProofHistory>(miner_addr).count_proofs_in_epoch
+  };
+  0
 }
 
@@ -1121,7 +1126,10 @@ Public Getters ///
public fun can_create_val_account(node_addr: address): bool acquires MinerProofHistory {
   if(Testnet::is_testnet() || StagingNet::is_staging_net()) return true;
   // check if rate limited, needs 7 epochs of validating.
-  borrow_global<MinerProofHistory>(node_addr).epochs_since_last_account_creation > EPOCHS_UNTIL_ACCOUNT_CREATION
+  if (exists<MinerProofHistory>(node_addr)) {
+    return borrow_global<MinerProofHistory>(node_addr).epochs_since_last_account_creation > EPOCHS_UNTIL_ACCOUNT_CREATION
+  };
+  false
 }
 
@@ -1170,7 +1178,7 @@ Public Getters /// }; verify_and_update_state(Signer::address_of(miner_sig), proof, false); - // FullnodeState::init(miner_sig); + // FullnodeState::init(miner_sig); }
@@ -1242,11 +1250,18 @@ Public Getters /// Implementation -
public fun test_helper_mock_mining(sender: &signer,  count: u64) acquires MinerProofHistory {
+
public fun test_helper_mock_mining(sender: &signer,  count: u64) acquires MinerProofHistory, MinerStats {
   assert(Testnet::is_testnet(), Errors::invalid_state(130118));
-  let state = borrow_global_mut<MinerProofHistory>(Signer::address_of(sender));
+  let addr = Signer::address_of(sender);
+  let state = borrow_global_mut<MinerProofHistory>(addr);
   state.count_proofs_in_epoch = count;
-  // FullnodeState::mock_proof(sender, count);
+  let i = 0;
+  while (i < count) {
+    increment_stats(addr);
+    i = i + 1;
+  }
+
+  // FullnodeState::mock_proof(sender, count);
 }
 
@@ -1269,12 +1284,17 @@ Public Getters /// Implementation -
public fun test_helper_mock_mining_vm(vm: &signer, addr: address, count: u64) acquires MinerProofHistory {
-  CoreAddresses::assert_diem_root(vm);
-
+
public fun test_helper_mock_mining_vm(vm: &signer, addr: address, count: u64) acquires MinerProofHistory, MinerStats {
   assert(Testnet::is_testnet(), Errors::invalid_state(130120));
+  CoreAddresses::assert_diem_root(vm);
   let state = borrow_global_mut<MinerProofHistory>(addr);
   state.count_proofs_in_epoch = count;
+
+  let i = 0;
+  while (i < count) {
+    increment_stats(addr);
+    i = i + 1;
+  }
 }
 
diff --git a/language/diem-framework/modules/doc/Reconfigure.md b/language/diem-framework/modules/doc/Reconfigure.md index fea3b83314..41b2630441 100644 --- a/language/diem-framework/modules/doc/Reconfigure.md +++ b/language/diem-framework/modules/doc/Reconfigure.md @@ -16,6 +16,7 @@ use 0x1::AutoPay2; use 0x1::Burn; use 0x1::CoreAddresses; +use 0x1::Debug; use 0x1::DiemAccount; use 0x1::DiemConfig; use 0x1::DiemSystem; @@ -49,24 +50,33 @@
public fun reconfigure(vm: &signer, height_now: u64) {
+    print(&1800100);
     CoreAddresses::assert_vm(vm);
 
     let height_start = Epoch::get_timer_height_start(vm);
 
-    let (subsidy_units, subsidy_per) = Subsidy::calculate_subsidy(vm, height_start, height_now);
+    print(&1800101);
+    let (outgoing_compliant_set, _) = DiemSystem::get_fee_ratio(vm, height_start, height_now);
+    // NOTE: This is "nominal" because it doesn't check
+    let compliant_nodes_count = Vector::length(&outgoing_compliant_set);
+    let (subsidy_units, nominal_subsidy_per) = Subsidy::calculate_subsidy(vm, compliant_nodes_count);
 
-    process_fullnodes(vm, subsidy_per);
+    print(&1800102);
+    process_fullnodes(vm, nominal_subsidy_per);
 
-    process_validators(vm, height_start, height_now, subsidy_units);
+    print(&1800103);
+    process_validators(vm, subsidy_units, outgoing_compliant_set);
 
+    print(&1800104);
     let proposed_set = propose_new_set(vm, height_start, height_now);
 
+    print(&1800105);
     // Update all slow wallet limits
     if (DiemConfig::check_transfer_enabled()) {
         DiemAccount::slow_wallet_epoch_drip(vm, Globals::get_unlock());
         // update_validator_withdrawal_limit(vm);
     };
-
+    print(&1800106);
     reset_counters(vm, proposed_set, height_now)
 }
 
@@ -81,7 +91,7 @@ -
fun process_fullnodes(vm: &signer, subsidy_per_node: u64)
+
fun process_fullnodes(vm: &signer, nominal_subsidy_per_node: u64)
 
@@ -90,44 +100,44 @@ Implementation -
fun process_fullnodes(vm: &signer, subsidy_per_node: u64) {
+
fun process_fullnodes(vm: &signer, nominal_subsidy_per_node: u64) {
     // Fullnode subsidy
     // loop through validators and pay full node subsidies.
     // Should happen before transactionfees get distributed.
     // Note: need to check, there may be new validators which have not mined yet.
-    // print(&03100);
 
+    print(&1800200);
     let miners = MinerState::get_miner_list();
-
+    print(&1800201);
     // fullnode subsidy is a fraction of the total subsidy available to validators.
-    let proof_price = FullnodeSubsidy::get_proof_price(subsidy_per_node);
+    let proof_price = FullnodeSubsidy::get_proof_price(nominal_subsidy_per_node);
+    // print(&nominal_subsidy_per_node);
+    // print(&proof_price);
 
     let k = 0;
-    // print(&03200);
     // Distribute mining subsidy to fullnodes
+    print(&1800202);
     while (k < Vector::length(&miners)) {
         let addr = *Vector::borrow(&miners, k);
-        // print(&03210);
-
-        // if (!FullnodeState::is_init(addr)) continue; // fail-safe
-        if (DiemSystem::is_validator(addr)) continue; // skip validators
-
-        let count = MinerState::get_count_in_epoch(addr);
-
-        let miner_subsidy = count * proof_price;
+        print(&1800203);
+        if (DiemSystem::is_validator(addr)) { // skip validators
+          k = k + 1;
+          continue
+        };
+        print(&1800204);
 
-        FullnodeSubsidy::distribute_fullnode_subsidy(vm, addr, miner_subsidy);
+        if (MinerState::node_above_thresh(addr)){ // TODO: this call is repeated in propose_new_set. Not sure if the performance hit at epoch boundary is worth the refactor.
+          let count = MinerState::get_count_in_epoch(addr);
+          // print(&count);
 
-        // print(&03230);
-        // FullnodeState::inc_payment_count(vm, addr, count);
-        // FullnodeState::inc_payment_value(vm, addr, value);
-        // FullnodeState::reconfig(vm, addr, count);
+          let miner_subsidy = count * proof_price;
+          print(&1800205);
+          // print(&miner_subsidy);
+          FullnodeSubsidy::distribute_fullnode_subsidy(vm, addr, miner_subsidy);
+        };
 
         k = k + 1;
     };
-
-     // needs to be set before the auctioneer runs in Subsidy::fullnode_reconfig
-    // FullnodeSubsidy::set_global_count(vm, global_proofs_count);
 }
 
@@ -141,7 +151,7 @@ -
fun process_validators(vm: &signer, height_start: u64, height_now: u64, subsidy_units: u64)
+
fun process_validators(vm: &signer, subsidy_units: u64, outgoing_compliant_set: vector<address>)
 
@@ -150,22 +160,21 @@ Implementation -
fun process_validators(vm: &signer, height_start: u64, height_now: u64, subsidy_units: u64) {
+
fun process_validators(vm: &signer, subsidy_units: u64, outgoing_compliant_set: vector<address>) {
     // Process outgoing validators:
     // Distribute Transaction fees and subsidy payments to all outgoing validators
     // print(&03240);
-    let (outgoing_set, _) = DiemSystem::get_fee_ratio(vm, height_start, height_now);
 
-    if (Vector::length<address>(&outgoing_set) > 0) {
-        // let (subsidy_units, _) = Subsidy::calculate_subsidy(vm, height_start, height_now);
+
+    if (Vector::length<address>(&outgoing_compliant_set) > 0) {
         // print(&03241);
 
         if (subsidy_units > 0) {
-            Subsidy::process_subsidy(vm, subsidy_units, &outgoing_set);
+            Subsidy::process_subsidy(vm, subsidy_units, &outgoing_compliant_set);
         };
         // print(&03241);
 
-        Subsidy::process_fees(vm, &outgoing_set);
+        Subsidy::process_fees(vm, &outgoing_compliant_set);
     };
 
 }
@@ -205,6 +214,7 @@
     let jailed_set = DiemSystem::get_jailed_set(vm, height_start, height_now);
 
     Burn::reset_ratios(vm);
+    // LEAVE THIS CODE COMMENTED for future use
     // TODO: Make the burn value dynamic.
     // let incoming_count = Vector::length<address>(&top_accounts) - Vector::length<address>(&jailed_set);
     // let burn_value = Subsidy::subsidy_curve(
@@ -212,6 +222,7 @@
     //   incoming_count,
     //   Globals::get_max_node_density()
     // )/4;
+
     let burn_value = 1000000; // TODO: switch to a variable cost, as above.
 
     // print(&03250);
@@ -221,7 +232,7 @@
         // print(&03251);
 
         let addr = *Vector::borrow(&top_accounts, i);
-        let mined_last_epoch = MinerState::node_above_thresh(vm, addr);
+        let mined_last_epoch = MinerState::node_above_thresh(addr);
         // print(&mined_last_epoch);
         // TODO: temporary until jail-refactor merge.
         if (
@@ -283,7 +294,7 @@
     // print(&032110);
 
     // reset clocks
-    FullnodeSubsidy::fullnode_reconfig(vm);
+    // FullnodeSubsidy::fullnode_reconfig(vm);
     // print(&032120);
 
     // process community wallets
diff --git a/language/diem-framework/modules/doc/Subsidy.md b/language/diem-framework/modules/doc/Subsidy.md
index 0a6d0e6532..4200be4859 100644
--- a/language/diem-framework/modules/doc/Subsidy.md
+++ b/language/diem-framework/modules/doc/Subsidy.md
@@ -15,6 +15,7 @@
 
 
 
use 0x1::CoreAddresses;
+use 0x1::Debug;
 use 0x1::Diem;
 use 0x1::DiemAccount;
 use 0x1::DiemTimestamp;
@@ -24,7 +25,6 @@
 use 0x1::Globals;
 use 0x1::MinerState;
 use 0x1::Signer;
-use 0x1::Stats;
 use 0x1::TransactionFee;
 use 0x1::ValidatorConfig;
 use 0x1::ValidatorUniverse;
@@ -68,23 +68,25 @@
   outgoing_set: &vector<address>,
 ) {
   CoreAddresses::assert_vm(vm);
-
+  print(&1901001);
   // Get the split of payments from Stats.
   let len = Vector::length<address>(outgoing_set);
-
+  print(&1901002);
   // equal subsidy for all active validators
   let subsidy_granted;
+  // TODO: This calculation is duplicated with get_subsidy
   if (subsidy_units > len && subsidy_units > 0 ) { // arithmetic safety check
     subsidy_granted = subsidy_units/len;
+    print(&subsidy_granted);
   } else { return };
 
   let i = 0;
   while (i < len) {
-
+    print(&1901003);
     let node_address = *(Vector::borrow<address>(outgoing_set, i));
     // Transfer gas from vm address to validator
     let minted_coins = Diem::mint<GAS>(vm, subsidy_granted);
-
+    print(&1901004);
     DiemAccount::vm_deposit_with_metadata<GAS>(
       vm,
       node_address,
@@ -92,6 +94,8 @@
       b"validator subsidy",
       b""
     );
+    print(&1901005);
+
     // refund operator tx fees for mining
     refund_operator_tx_fees(vm, node_address);
     i = i + 1;
@@ -109,7 +113,7 @@
 
 
 
-
public fun calculate_subsidy(vm: &signer, height_start: u64, height_end: u64): (u64, u64)
+
public fun calculate_subsidy(vm: &signer, network_density: u64): (u64, u64)
 
@@ -118,32 +122,49 @@ Implementation -
public fun calculate_subsidy(vm: &signer, height_start: u64, height_end: u64): (u64, u64) {
+
public fun calculate_subsidy(vm: &signer, network_density: u64): (u64, u64) {
   CoreAddresses::assert_vm(vm);
+  print(&1901006);
   // skip genesis
   assert(!DiemTimestamp::is_genesis(), Errors::invalid_state(190102));
 
   // Gets the transaction fees in the epoch
   let txn_fee_amount = TransactionFee::get_amount_to_distribute(vm);
-
+  print(&1901007);
   // Calculate the split for subsidy and burn
   let subsidy_ceiling_gas = Globals::get_subsidy_ceiling_gas();
-  let network_density = Stats::network_density(vm, height_start, height_end);
-  let max_node_count = Globals::get_max_validators_per_set();
+  // TODO: This metric network density is different than DiemSystem::get_fee_ratio which actually checks the cases.
 
+  // let network_density = Stats::network_density(vm, height_start, height_end);
+  let max_node_count = Globals::get_max_validators_per_set();
+  print(&1901008);
   let guaranteed_minimum = subsidy_curve(
     subsidy_ceiling_gas,
     network_density,
     max_node_count,
   );
-
+  print(&1901009);
+  let subsidy = 0;
+  let subsidy_per_node = 0;
   // deduct transaction fees from guaranteed minimum.
   if (guaranteed_minimum > txn_fee_amount ){
-    let subsidy = guaranteed_minimum - txn_fee_amount;
+    print(&190100901);
+    subsidy = guaranteed_minimum - txn_fee_amount;
     // return global subsidy and subsidy per node.
-    return (subsidy, subsidy/network_density)
+    print(&190100902);
+    // TODO: we are doing this computation twice at reconfigure time.
+    if ((subsidy > network_density) && (network_density > 0)) {
+      print(&190100903);
+      print(&subsidy);
+      print(&network_density);
+
+      subsidy_per_node = subsidy/network_density;
+      print(&subsidy_per_node);
+
+    };
   };
-  (0u64, 0u64)
+  print(&1901010);
+  (subsidy, subsidy_per_node)
 }
 
@@ -170,7 +191,7 @@ subsidy_ceiling_gas: u64, network_density: u64, max_node_count: u64 - ): u64 { +): u64 { let min_node_count = 4u64; diff --git a/language/diem-framework/modules/doc/ValidatorUniverse.md b/language/diem-framework/modules/doc/ValidatorUniverse.md index a1f5c1cfc2..8cce6d57de 100644 --- a/language/diem-framework/modules/doc/ValidatorUniverse.md +++ b/language/diem-framework/modules/doc/ValidatorUniverse.md @@ -138,7 +138,7 @@ if (MinerState::is_onboarding(addr)) { add(sender); } else { - assert(MinerState::node_above_thresh(sender, addr), 220102014010); + assert(MinerState::node_above_thresh(addr), 220102014010); add(sender); } } @@ -333,7 +333,7 @@ // only a validator can un-jail themselves. let validator = Signer::address_of(sender); // check the node has been mining before unjailing. - assert(MinerState::node_above_thresh(sender, validator), 220102014010); + assert(MinerState::node_above_thresh(validator), 220102014010); unjail(sender); }
diff --git a/language/diem-framework/modules/doc/ol_Decimal.md b/language/diem-framework/modules/doc/ol_Decimal.md new file mode 100644 index 0000000000..da7ccc7369 --- /dev/null +++ b/language/diem-framework/modules/doc/ol_Decimal.md @@ -0,0 +1,553 @@ + + + +# Module `0x1::Decimal` + + + +- [Resource `Decimal`](#0x1_Decimal_Decimal) +- [Constants](#@Constants_0) +- [Function `decimal_demo`](#0x1_Decimal_decimal_demo) +- [Function `single_op`](#0x1_Decimal_single_op) +- [Function `pair_op`](#0x1_Decimal_pair_op) +- [Function `new`](#0x1_Decimal_new) +- [Function `sqrt`](#0x1_Decimal_sqrt) +- [Function `add`](#0x1_Decimal_add) +- [Function `sub`](#0x1_Decimal_sub) +- [Function `mul`](#0x1_Decimal_mul) +- [Function `div`](#0x1_Decimal_div) +- [Function `rescale`](#0x1_Decimal_rescale) +- [Function `power`](#0x1_Decimal_power) +- [Function `unwrap`](#0x1_Decimal_unwrap) +- [Function `borrow_sign`](#0x1_Decimal_borrow_sign) +- [Function `borrow_int`](#0x1_Decimal_borrow_int) +- [Function `borrow_scale`](#0x1_Decimal_borrow_scale) + + +
+ + + + + +## Resource `Decimal` + + + +
struct Decimal has drop, store, key
+
+ + + +
+Fields + + +
+
+sign: bool +
+
+ +
+
+int: u128 +
+
+ +
+
+scale: u8 +
+
+ +
+
+ + +
+ + + +## Constants + + + + + + +
const ADD: u8 = 1;
+
+ + + + + + + +
const DIV: u8 = 4;
+
+ + + + + + + +
const MAX_RUST_U64: u128 = 18446744073709551615;
+
+ + + + + + + +
const MULT: u8 = 3;
+
+ + + + + + + +
const ROUNDING_UP: u8 = 1;
+
+ + + + + + + +
const SQRT: u8 = 5;
+
+ + + + + + + +
const SUB: u8 = 2;
+
+ + + + + +## Function `decimal_demo` + + + +
public fun decimal_demo(sign: bool, int: u128, scale: u8): (bool, u128, u8)
+
+ + + +
+Implementation + + +
native public fun decimal_demo(sign: bool, int: u128, scale: u8): (bool, u128, u8);
+
+ + + +
+ + + +## Function `single_op` + + + +
public fun single_op(op_id: u8, sign: bool, int: u128, scale: u8): (bool, u128, u8)
+
+ + + +
+Implementation + + +
native public fun single_op(op_id: u8, sign: bool, int: u128, scale: u8): (bool, u128, u8);
+
+ + + +
+ + + +## Function `pair_op` + + + +
public fun pair_op(op_id: u8, rounding_strategy_id: u8, sign_1: bool, int_1: u128, scale_1: u8, sign_2: bool, int_2: u128, scale_3: u8): (bool, u128, u8)
+
+ + + +
+Implementation + + +
native public fun pair_op(
+  op_id: u8,
+  rounding_strategy_id: u8,
+  // left number
+  sign_1: bool,
+  int_1: u128,
+  scale_1: u8,
+  // right number
+  sign_2: bool,
+  int_2: u128,
+  scale_3: u8
+): (bool, u128, u8);
+
+ + + +
+ + + +## Function `new` + + + +
public fun new(sign: bool, int: u128, scale: u8): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun new(sign: bool, int: u128, scale: u8): Decimal {
+  // in Rust, the integer is downcast to u64
+  // so we limit new Decimal types to that scale.
+  assert(int < MAX_RUST_U64, 01);
+
+  // check scale < 28
+  assert(scale < 28, 02);
+
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale
+  }
+}
+
+ + + +
+ + + +## Function `sqrt` + + + +
public fun sqrt(d: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun sqrt(d: &Decimal): Decimal {
+  let (sign, int, scale) = single_op(5, *&d.sign, *&d.int, *&d.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `add` + + + +
public fun add(l: &Decimal::Decimal, r: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun add(l: &Decimal, r: &Decimal): Decimal {
+  let (sign, int, scale) = pair_op(1, 0, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `sub` + + + +
public fun sub(l: &Decimal::Decimal, r: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun sub(l: &Decimal, r: &Decimal): Decimal {
+  let (sign, int, scale) = pair_op(2, 0, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `mul` + + + +
public fun mul(l: &Decimal::Decimal, r: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun mul(l: &Decimal, r: &Decimal): Decimal {
+  let (sign, int, scale) = pair_op(3, 0, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `div` + + + +
public fun div(l: &Decimal::Decimal, r: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun div(l: &Decimal, r: &Decimal): Decimal {
+ let (sign, int, scale) = pair_op(4, 0, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+ return Decimal {
+   sign: sign,
+   int: int,
+   scale: scale,
+ }
+}
+
+ + + +
+ + + +## Function `rescale` + + + +
public fun rescale(l: &Decimal::Decimal, r: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun rescale(l: &Decimal, r: &Decimal): Decimal {
+  let (sign, int, scale) = pair_op(0, 0, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `power` + + + +
public fun power(l: &Decimal::Decimal, r: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun power(l: &Decimal, r: &Decimal): Decimal {
+  let (sign, int, scale) = pair_op(5, 0, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `unwrap` + + + +
public fun unwrap(d: &Decimal::Decimal): (bool, u128, u8)
+
+ + + +
+Implementation + + +
public fun unwrap(d: &Decimal): (bool, u128, u8) {
+  return (*&d.sign, *&d.int, *&d.scale)
+}
+
+ + + +
+ + + +## Function `borrow_sign` + + + +
public fun borrow_sign(d: &Decimal::Decimal): &bool
+
+ + + +
+Implementation + + +
public fun borrow_sign(d: &Decimal): &bool {
+  return &d.sign
+}
+
+ + + +
+ + + +## Function `borrow_int` + + + +
public fun borrow_int(d: &Decimal::Decimal): &u128
+
+ + + +
+Implementation + + +
public fun borrow_int(d: &Decimal): &u128 {
+  return &d.int
+}
+
+ + + +
+ + + +## Function `borrow_scale` + + + +
public fun borrow_scale(d: &Decimal::Decimal): &u8
+
+ + + +
+Implementation + + +
public fun borrow_scale(d: &Decimal): &u8 {
+  return &d.scale
+}
+
+ + + +
+ + +[//]: # ("File containing references which can be used from documentation") +[ACCESS_CONTROL]: https://github.com/diem/dip/blob/main/dips/dip-2.md +[ROLE]: https://github.com/diem/dip/blob/main/dips/dip-2.md#roles +[PERMISSION]: https://github.com/diem/dip/blob/main/dips/dip-2.md#permissions diff --git a/language/diem-framework/modules/doc/ol_validator.md b/language/diem-framework/modules/doc/ol_validator.md index c25f093d2d..c2a3411bcf 100644 --- a/language/diem-framework/modules/doc/ol_validator.md +++ b/language/diem-framework/modules/doc/ol_validator.md @@ -109,7 +109,7 @@ let addr = Signer::address_of(&validator); // if is above threshold continue, or raise error. assert( - MinerState::node_above_thresh(&validator, addr), + MinerState::node_above_thresh(addr), Errors::invalid_state(NOT_ABOVE_THRESH_JOIN) ); // if is not in universe, add back @@ -179,7 +179,7 @@ let addr = Signer::address_of(validator); // if is above threshold continue, or raise error. assert( - MinerState::node_above_thresh(validator, addr), + MinerState::node_above_thresh(addr), Errors::invalid_state(NOT_ABOVE_THRESH_ADD) ); // if is not in universe, add back diff --git a/language/diem-framework/modules/doc/overview.md b/language/diem-framework/modules/doc/overview.md index 3c3734544c..1d0551e4cb 100644 --- a/language/diem-framework/modules/doc/overview.md +++ b/language/diem-framework/modules/doc/overview.md @@ -99,11 +99,13 @@ The Move modules in the Diem Framework can be bucketed in to a couple categories - [`0x1::AutoPay2`](AutoPay.md#0x1_AutoPay2) - [`0x1::AutoPayScripts`](ol_autopay.md#0x1_AutoPayScripts) - [`0x1::BCS`](../../../../../../move-stdlib/docs/BCS.md#0x1_BCS) +- [`0x1::Bonding`](Demo_Bonding.md#0x1_Bonding) - [`0x1::Burn`](Burn.md#0x1_Burn) - [`0x1::Cases`](Cases.md#0x1_Cases) - [`0x1::ChainId`](ChainId.md#0x1_ChainId) - [`0x1::CoreAddresses`](CoreAddresses.md#0x1_CoreAddresses) - [`0x1::Debug`](Debug.md#0x1_Debug) +- [`0x1::Decimal`](Decimal.md#0x1_Decimal) - [`0x1::DemoScripts`](ol_demo_e2e.md#0x1_DemoScripts) - [`0x1::DesignatedDealer`](DesignatedDealer.md#0x1_DesignatedDealer) - [`0x1::Diem`](Diem.md#0x1_Diem) @@ -123,7 +125,6 @@ The Move modules in the Diem Framework can be bucketed in to a couple categories - [`0x1::Event`](../../../../../../move-stdlib/docs/Event.md#0x1_Event) - [`0x1::FIFO`](FIFO.md#0x1_FIFO) - [`0x1::FixedPoint32`](../../../../../../move-stdlib/docs/FixedPoint32.md#0x1_FixedPoint32) -- [`0x1::FullnodeState`](FullnodeState.md#0x1_FullnodeState) - [`0x1::FullnodeSubsidy`](FullnodeSubsidy.md#0x1_FullnodeSubsidy) - [`0x1::GAS`](GAS.md#0x1_GAS) - [`0x1::Genesis`](Genesis.md#0x1_Genesis) diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/Cases.md b/language/diem-framework/releases/artifacts/current/docs/modules/Cases.md index 4e8358b92f..057b0b0e8a 100644 --- a/language/diem-framework/releases/artifacts/current/docs/modules/Cases.md +++ b/language/diem-framework/releases/artifacts/current/docs/modules/Cases.md @@ -85,7 +85,7 @@ set and/or jailed. To be compliant, validators must be BOTH validating and minin Roles::assert_diem_root(vm); // did the validator sign blocks above threshold? let signs = Stats::node_above_thresh(vm, node_addr, height_start, height_end); - let mines = MinerState::node_above_thresh(vm, node_addr); + let mines = MinerState::node_above_thresh(node_addr); if (signs && mines) { VALIDATOR_COMPLIANT // compliant: in next set, gets paid, weight increments diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/Decimal.md b/language/diem-framework/releases/artifacts/current/docs/modules/Decimal.md new file mode 100644 index 0000000000..6948bfed0b --- /dev/null +++ b/language/diem-framework/releases/artifacts/current/docs/modules/Decimal.md @@ -0,0 +1,648 @@ + + + +# Module `0x1::Decimal` + + + +- [Resource `Decimal`](#0x1_Decimal_Decimal) +- [Constants](#@Constants_0) +- [Function `decimal_demo`](#0x1_Decimal_decimal_demo) +- [Function `single_op`](#0x1_Decimal_single_op) +- [Function `pair_op`](#0x1_Decimal_pair_op) +- [Function `new`](#0x1_Decimal_new) +- [Function `trunc`](#0x1_Decimal_trunc) +- [Function `sqrt`](#0x1_Decimal_sqrt) +- [Function `add`](#0x1_Decimal_add) +- [Function `sub`](#0x1_Decimal_sub) +- [Function `mul`](#0x1_Decimal_mul) +- [Function `div`](#0x1_Decimal_div) +- [Function `rescale`](#0x1_Decimal_rescale) +- [Function `round`](#0x1_Decimal_round) +- [Function `power`](#0x1_Decimal_power) +- [Function `unwrap`](#0x1_Decimal_unwrap) +- [Function `borrow_sign`](#0x1_Decimal_borrow_sign) +- [Function `borrow_int`](#0x1_Decimal_borrow_int) +- [Function `borrow_scale`](#0x1_Decimal_borrow_scale) + + +
+ + + + + +## Resource `Decimal` + + + +
struct Decimal has drop, store, key
+
+ + + +
+Fields + + +
+
+sign: bool +
+
+ +
+
+int: u128 +
+
+ +
+
+scale: u8 +
+
+ +
+
+ + +
+ + + +## Constants + + + + + + +
const ADD: u8 = 1;
+
+ + + + + + + +
const DIV: u8 = 4;
+
+ + + + + + + +
const MAX_RUST_DECIMAL_U128: u128 = 79228162514264337593543950335;
+
+ + + + + + + +
const MUL: u8 = 3;
+
+ + + + + + + +
const POW: u8 = 5;
+
+ + + + + + + +
const ROUND: u8 = 6;
+
+ + + + + + + +
const ROUND_MID_FROM_ZERO: u8 = 1;
+
+ + + + + + + +
const ROUND_MID_TO_EVEN: u8 = 0;
+
+ + + + + + + +
const SQRT: u8 = 100;
+
+ + + + + + + +
const SUB: u8 = 2;
+
+ + + + + + + +
const TRUNC: u8 = 101;
+
+ + + + + +## Function `decimal_demo` + + + +
public fun decimal_demo(sign: bool, int: u128, scale: u8): (bool, u128, u8)
+
+ + + +
+Implementation + + +
native public fun decimal_demo(sign: bool, int: u128, scale: u8): (bool, u128, u8);
+
+ + + +
+ + + +## Function `single_op` + + + +
public fun single_op(op_id: u8, sign: bool, int: u128, scale: u8): (bool, u128, u8)
+
+ + + +
+Implementation + + +
native public fun single_op(op_id: u8, sign: bool, int: u128, scale: u8): (bool, u128, u8);
+
+ + + +
+ + + +## Function `pair_op` + + + +
public fun pair_op(op_id: u8, rounding_strategy_id: u8, sign_1: bool, int_1: u128, scale_1: u8, sign_2: bool, int_2: u128, scale_3: u8): (bool, u128, u8)
+
+ + + +
+Implementation + + +
native public fun pair_op(
+  op_id: u8,
+  rounding_strategy_id: u8,
+  // left number
+  sign_1: bool,
+  int_1: u128,
+  scale_1: u8,
+  // right number
+  sign_2: bool,
+  int_2: u128,
+  scale_3: u8
+): (bool, u128, u8);
+
+ + + +
+ + + +## Function `new` + + + +
public fun new(sign: bool, int: u128, scale: u8): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun new(sign: bool, int: u128, scale: u8): Decimal {
+
+  assert(int < MAX_RUST_DECIMAL_U128, 01);
+
+  // check scale < 28
+  assert(scale < 28, 02);
+
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale
+  }
+}
+
+ + + +
+ + + +## Function `trunc` + + + +
public fun trunc(d: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun trunc(d: &Decimal): Decimal {
+  let (sign, int, scale) = single_op(TRUNC, *&d.sign, *&d.int, *&d.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `sqrt` + + + +
public fun sqrt(d: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun sqrt(d: &Decimal): Decimal {
+  let (sign, int, scale) = single_op(SQRT, *&d.sign, *&d.int, *&d.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `add` + + + +
public fun add(l: &Decimal::Decimal, r: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun add(l: &Decimal, r: &Decimal): Decimal {
+  let (sign, int, scale) = pair_op(ADD, ROUND_MID_TO_EVEN, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `sub` + + + +
public fun sub(l: &Decimal::Decimal, r: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun sub(l: &Decimal, r: &Decimal): Decimal {
+  let (sign, int, scale) = pair_op(SUB, ROUND_MID_TO_EVEN, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `mul` + + + +
public fun mul(l: &Decimal::Decimal, r: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun mul(l: &Decimal, r: &Decimal): Decimal {
+  let (sign, int, scale) = pair_op(MUL, ROUND_MID_TO_EVEN, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `div` + + + +
public fun div(l: &Decimal::Decimal, r: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun div(l: &Decimal, r: &Decimal): Decimal {
+ let (sign, int, scale) = pair_op(DIV, ROUND_MID_TO_EVEN, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+ return Decimal {
+   sign: sign,
+   int: int,
+   scale: scale,
+ }
+}
+
+ + + +
+ + + +## Function `rescale` + + + +
public fun rescale(l: &Decimal::Decimal, r: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun rescale(l: &Decimal, r: &Decimal): Decimal {
+  let (sign, int, scale) = pair_op(0, ROUND_MID_TO_EVEN, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `round` + + + +
public fun round(l: &Decimal::Decimal, r: &Decimal::Decimal, strategy: u8): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun round(l: &Decimal, r: &Decimal, strategy: u8): Decimal {
+  let (sign, int, scale) = pair_op(ROUND, strategy, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `power` + + + +
public fun power(l: &Decimal::Decimal, r: &Decimal::Decimal): Decimal::Decimal
+
+ + + +
+Implementation + + +
public fun power(l: &Decimal, r: &Decimal): Decimal {
+  let (sign, int, scale) = pair_op(POW, ROUND_MID_TO_EVEN, *&l.sign, *&l.int, *&l.scale,  *&r.sign, *&r.int, *&r.scale);
+  return Decimal {
+    sign: sign,
+    int: int,
+    scale: scale,
+  }
+}
+
+ + + +
+ + + +## Function `unwrap` + + + +
public fun unwrap(d: &Decimal::Decimal): (bool, u128, u8)
+
+ + + +
+Implementation + + +
public fun unwrap(d: &Decimal): (bool, u128, u8) {
+  return (*&d.sign, *&d.int, *&d.scale)
+}
+
+ + + +
+ + + +## Function `borrow_sign` + + + +
public fun borrow_sign(d: &Decimal::Decimal): &bool
+
+ + + +
+Implementation + + +
public fun borrow_sign(d: &Decimal): &bool {
+  return &d.sign
+}
+
+ + + +
+ + + +## Function `borrow_int` + + + +
public fun borrow_int(d: &Decimal::Decimal): &u128
+
+ + + +
+Implementation + + +
public fun borrow_int(d: &Decimal): &u128 {
+  return &d.int
+}
+
+ + + +
+ + + +## Function `borrow_scale` + + + +
public fun borrow_scale(d: &Decimal::Decimal): &u8
+
+ + + +
+Implementation + + +
public fun borrow_scale(d: &Decimal): &u8 {
+  return &d.scale
+}
+
+ + + +
+ + +[//]: # ("File containing references which can be used from documentation") +[ACCESS_CONTROL]: https://github.com/diem/dip/blob/main/dips/dip-2.md +[ROLE]: https://github.com/diem/dip/blob/main/dips/dip-2.md#roles +[PERMISSION]: https://github.com/diem/dip/blob/main/dips/dip-2.md#permissions diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/Demo_Bonding.md b/language/diem-framework/releases/artifacts/current/docs/modules/Demo_Bonding.md new file mode 100644 index 0000000000..dd0dc0144e --- /dev/null +++ b/language/diem-framework/releases/artifacts/current/docs/modules/Demo_Bonding.md @@ -0,0 +1,249 @@ + + + +# Module `0x1::Bonding` + + + +- [Resource `CurveState`](#0x1_Bonding_CurveState) +- [Resource `Token`](#0x1_Bonding_Token) +- [Function `initialize_curve`](#0x1_Bonding_initialize_curve) +- [Function `deposit_calc`](#0x1_Bonding_deposit_calc) +- [Function `test_bond_to_mint`](#0x1_Bonding_test_bond_to_mint) +- [Function `get_curve_state`](#0x1_Bonding_get_curve_state) + + +
use 0x1::Debug;
+use 0x1::Decimal;
+
+ + + + + +## Resource `CurveState` + + + +
struct CurveState has key
+
+ + + +
+Fields + + +
+
+is_deprecated: bool +
+
+ +
+
+reserve: u128 +
+
+ +
+
+supply_issued: u128 +
+
+ +
+
+ + +
+ + + +## Resource `Token` + + + +
struct Token has store, key
+
+ + + +
+Fields + + +
+
+value: u128 +
+
+ +
+
+ + +
+ + + +## Function `initialize_curve` + + + +
public fun initialize_curve(service: &signer, deposit: u128, supply_init: u128)
+
+ + + +
+Implementation + + +
public fun initialize_curve(
+  service: &signer,
+  deposit: u128, // Diem<XUS>,
+  supply_init: u128,
+) {
+  // let deposit_value = Diem::value<XUS>(&deposit);
+  assert(deposit > 0, 7357001);
+
+  let init_state = CurveState {
+    is_deprecated: false, // deprecate mode
+    reserve: deposit,
+    supply_issued: supply_init,
+  };
+
+  // This initializes the contract, and stores the contract state at the address of sender. TDB where the state gets stored.
+  move_to<CurveState>(service, init_state);
+
+  let first_token = Token {
+    value: supply_init
+  };
+
+  // minting the first coin, sponsor is recipent of initial coin.
+  move_to<Token>(service, first_token);
+}
+
+ + + +
+ + + +## Function `deposit_calc` + + + +
public fun deposit_calc(add_to_reserve: u128, reserve: u128, supply: u128): u128
+
+ + + +
+Implementation + + +
public fun deposit_calc(add_to_reserve: u128, reserve: u128, supply: u128): u128 {
+
+  let one = Decimal::new(true, 1, 0);
+  print(&one);
+
+  let add_dec = Decimal::new(true, add_to_reserve, 0);
+  print(&add_dec);
+
+  let reserve_dec = Decimal::new(true, reserve, 0);
+  print(&reserve_dec);
+
+  let supply_dec = Decimal::new(true, supply, 0);
+  print(&supply_dec);
+
+  // formula:
+  // supply * sqrt(one+(add_to_reserve/reserve))
+
+  let a = Decimal::div(&add_dec, &reserve_dec);
+  print(&a);
+  let b = Decimal::add(&one, &a);
+  print(&b);
+  let c = Decimal::sqrt(&b);
+  print(&c);
+  let d = Decimal::mul(&supply_dec, &c);
+  print(&d);
+  let int = Decimal::borrow_int(&Decimal::trunc(&d));
+  print(int);
+
+  return *int
+}
+
+ + + +
+ + + +## Function `test_bond_to_mint` + + + +
public fun test_bond_to_mint(_sender: &signer, service_addr: address, deposit: u128): u128
+
+ + + +
+Implementation + + +
public fun test_bond_to_mint(_sender: &signer, service_addr: address, deposit: u128): u128 acquires CurveState {
+  assert(exists<CurveState>(service_addr), 73570002);
+  let state = borrow_global_mut<CurveState>(service_addr);
+
+  let post_supply = deposit_calc(deposit, state.reserve, state.supply_issued);
+  print(&post_supply);
+  assert(post_supply > state.supply_issued, 73570003);
+  let mint = post_supply - state.supply_issued;
+  print(&mint);
+  // update the new curve state
+  state.reserve = state.reserve + deposit;
+  state.supply_issued = state.supply_issued + mint;
+  // print(&state);
+  mint
+}
+
+ + + +
+ + + +## Function `get_curve_state` + + + +
public fun get_curve_state(sponsor_address: address): (u128, u128)
+
+ + + +
+Implementation + + +
public fun get_curve_state(sponsor_address: address): (u128, u128) acquires CurveState {
+  let state = borrow_global<CurveState>(sponsor_address);
+  (state.reserve, state.supply_issued)
+}
+
+ + + +
+ + +[//]: # ("File containing references which can be used from documentation") +[ACCESS_CONTROL]: https://github.com/diem/dip/blob/main/dips/dip-2.md +[ROLE]: https://github.com/diem/dip/blob/main/dips/dip-2.md#roles +[PERMISSION]: https://github.com/diem/dip/blob/main/dips/dip-2.md#permissions diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/DiemAccount.md b/language/diem-framework/releases/artifacts/current/docs/modules/DiemAccount.md index 1df966b604..54b2812803 100644 --- a/language/diem-framework/releases/artifacts/current/docs/modules/DiemAccount.md +++ b/language/diem-framework/releases/artifacts/current/docs/modules/DiemAccount.md @@ -1471,7 +1471,7 @@ Initialize this module. This is only callable from genesis. // NOTE: VDF verification is being called twice! MinerState::init_miner_state(&new_signer, challenge, solution); // TODO: Should fullnode init happen here, or under MinerState::init? - // FullnodeState::init(&new_signer); + // FullnodeState::init(&new_signer); // Create OP Account let new_op_account = create_signer(op_address); Roles::new_validator_operator_role_with_proof(&new_op_account); @@ -2663,7 +2663,10 @@ Return the withdraw capability to the account it originally came from // TODO: Is this the best way to access a struct property from // outside a module? let (payer, payee, value, description) = Wallet::get_tx_args(t); - if (Wallet::is_frozen(payer)) continue; + if (Wallet::is_frozen(payer)) { + i = i + 1; + continue + }; vm_make_payment_no_limit<GAS>(payer, payee, value, description, b"", vm); Wallet::maybe_reset_rejection_counter(vm, payer); i = i + 1; diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/DiemSystem.md b/language/diem-framework/releases/artifacts/current/docs/modules/DiemSystem.md index c1b66654dc..47de5cb3fb 100644 --- a/language/diem-framework/releases/artifacts/current/docs/modules/DiemSystem.md +++ b/language/diem-framework/releases/artifacts/current/docs/modules/DiemSystem.md @@ -1377,6 +1377,7 @@ Private function checks for membership of addr in validator set. }; i = i + 1; }; + // calculate the ratio of votes per node. let fee_ratios = Vector::empty<FixedPoint32::FixedPoint32>(); let k = 0; while (k < Vector::length(&compliant_nodes)) { diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/FullnodeState.md b/language/diem-framework/releases/artifacts/current/docs/modules/FullnodeState.md deleted file mode 100644 index 5b0156ee6b..0000000000 --- a/language/diem-framework/releases/artifacts/current/docs/modules/FullnodeState.md +++ /dev/null @@ -1,399 +0,0 @@ - - - -# Module `0x1::FullnodeState` - - - - -## Summary - -This module tracks the activity of the network's fullnodes - - -- [Summary](#@Summary_0) -- [Resource `FullnodeCounter`](#0x1_FullnodeState_FullnodeCounter) -- [Function `init`](#0x1_FullnodeState_init) -- [Function `reconfig`](#0x1_FullnodeState_reconfig) -- [Function `inc_payment_count`](#0x1_FullnodeState_inc_payment_count) -- [Function `inc_payment_value`](#0x1_FullnodeState_inc_payment_value) -- [Function `is_init`](#0x1_FullnodeState_is_init) -- [Function `is_onboarding`](#0x1_FullnodeState_is_onboarding) -- [Function `get_address_proof_count`](#0x1_FullnodeState_get_address_proof_count) -- [Function `get_cumulative_subsidy`](#0x1_FullnodeState_get_cumulative_subsidy) -- [Function `test_set_fullnode_fixtures`](#0x1_FullnodeState_test_set_fullnode_fixtures) -- [Function `mock_proof`](#0x1_FullnodeState_mock_proof) - - -
use 0x1::CoreAddresses;
-use 0x1::Errors;
-use 0x1::Roles;
-use 0x1::Signer;
-use 0x1::Testnet;
-
- - - - - -## Resource `FullnodeCounter` - - - -
struct FullnodeCounter has key
-
- - - -
-Fields - - -
-
-proofs_submitted_in_epoch: u64 -
-
- -
-
-proofs_paid_in_epoch: u64 -
-
- -
-
-subsidy_in_epoch: u64 -
-
- -
-
-cumulative_proofs_submitted: u64 -
-
- -
-
-cumulative_proofs_paid: u64 -
-
- -
-
-cumulative_subsidy: u64 -
-
- -
-
- - -
- - - -## Function `init` - - - -
public fun init(sender: &signer)
-
- - - -
-Implementation - - -
public fun init(sender: &signer) {
-    assert(!exists<FullnodeCounter>(Signer::address_of(sender)), Errors::not_published(060001));
-    move_to<FullnodeCounter>(
-    sender,
-    FullnodeCounter {
-        proofs_submitted_in_epoch: 0,
-        proofs_paid_in_epoch: 0, // count
-        subsidy_in_epoch: 0, // value
-        cumulative_proofs_submitted: 0,
-        cumulative_proofs_paid: 0,
-        cumulative_subsidy: 0,
-      }
-    );
-}
-
- - - -
- - - -## Function `reconfig` - -Called by root at the epoch boundary for each fullnode, updates the cumulative stats and resets the others - - -
public fun reconfig(vm: &signer, addr: address, proofs_in_epoch: u64)
-
- - - -
-Implementation - - -
public fun reconfig(vm: &signer, addr: address, proofs_in_epoch: u64) acquires FullnodeCounter {
-    Roles::assert_diem_root(vm);
-    let state = borrow_global_mut<FullnodeCounter>(addr);
-    // update cumulative values
-    state.cumulative_proofs_submitted = state.cumulative_proofs_submitted + proofs_in_epoch;
-    state.cumulative_proofs_paid = state.cumulative_proofs_paid + state.proofs_paid_in_epoch;
-    state.cumulative_subsidy = state.cumulative_subsidy + state.subsidy_in_epoch;
-    // reset
-    state.proofs_submitted_in_epoch = proofs_in_epoch;
-    state.proofs_paid_in_epoch = 0;
-    state.subsidy_in_epoch = 0;
-}
-
- - - -
- - - -## Function `inc_payment_count` - -VM Increments payments in epoch for addr. Increases by count - - -
public fun inc_payment_count(vm: &signer, addr: address, count: u64)
-
- - - -
-Implementation - - -
public fun inc_payment_count(vm: &signer, addr: address, count: u64) acquires FullnodeCounter {
-  Roles::assert_diem_root(vm);
-  let state = borrow_global_mut<FullnodeCounter>(addr);
-  state.proofs_paid_in_epoch = state.proofs_paid_in_epoch + count;
-}
-
- - - -
- - - -## Function `inc_payment_value` - -VM Increments subsidy in epoch for addr. Increases by value - - -
public fun inc_payment_value(vm: &signer, addr: address, value: u64)
-
- - - -
-Implementation - - -
public fun inc_payment_value(vm: &signer, addr: address, value: u64) acquires FullnodeCounter {
-  Roles::assert_diem_root(vm);
-  let state = borrow_global_mut<FullnodeCounter>(addr);
-  state.subsidy_in_epoch = state.subsidy_in_epoch + value;
-}
-
- - - -
- - - -## Function `is_init` - -Function to check whether or not the module has been initialized - - -
public fun is_init(addr: address): bool
-
- - - -
-Implementation - - -
public fun is_init(addr: address): bool {
-  exists<FullnodeCounter>(addr)
-}
-
- - - -
- - - -## Function `is_onboarding` - -Function checks to see if the node is in the process of onboarding -The first proof is submitted by the node doing the onboarding, so if -proof submitted < 2, the node hasn't yet produced a proof - - -
public fun is_onboarding(addr: address): bool
-
- - - -
-Implementation - - -
public fun is_onboarding(addr: address): bool acquires FullnodeCounter{
-  let state = borrow_global<FullnodeCounter>(addr);
-
-  state.cumulative_proofs_submitted < 2 &&
-  state.cumulative_proofs_paid < 2 &&
-  state.cumulative_subsidy < 1000000
-}
-
- - - -
- - - -## Function `get_address_proof_count` - -Get the number of proofs submitted in the current epoch for addr - - -
public fun get_address_proof_count(addr: address): u64
-
- - - -
-Implementation - - -
public fun get_address_proof_count(addr:address): u64 acquires FullnodeCounter {
-  borrow_global<FullnodeCounter>(addr).proofs_submitted_in_epoch
-}
-
- - - -
- - - -## Function `get_cumulative_subsidy` - -Get the cumulative subsity for addr - - -
public fun get_cumulative_subsidy(addr: address): u64
-
- - - -
-Implementation - - -
public fun get_cumulative_subsidy(addr: address): u64 acquires FullnodeCounter{
-  let state = borrow_global<FullnodeCounter>(addr);
-  state.cumulative_subsidy
-}
-
- - - -
- - - -## Function `test_set_fullnode_fixtures` - -initialize fullnode state for a node and set stats to given values - - -
public fun test_set_fullnode_fixtures(vm: &signer, addr: address, proofs_submitted_in_epoch: u64, proofs_paid_in_epoch: u64, subsidy_in_epoch: u64, cumulative_proofs_submitted: u64, cumulative_proofs_paid: u64, cumulative_subsidy: u64)
-
- - - -
-Implementation - - -
public fun test_set_fullnode_fixtures(
-  vm: &signer,
-  addr: address,
-  proofs_submitted_in_epoch: u64,
-  proofs_paid_in_epoch: u64,
-  subsidy_in_epoch: u64,
-  cumulative_proofs_submitted: u64,
-  cumulative_proofs_paid: u64,
-  cumulative_subsidy: u64,
-) acquires FullnodeCounter {
-  CoreAddresses::assert_diem_root(vm);
-  assert(is_testnet(), Errors::invalid_state(060006));
-
-  let state = borrow_global_mut<FullnodeCounter>(addr);
-  state.proofs_submitted_in_epoch = proofs_submitted_in_epoch;
-  state.proofs_paid_in_epoch = proofs_paid_in_epoch;
-  state.subsidy_in_epoch = subsidy_in_epoch;
-  state.cumulative_proofs_submitted = cumulative_proofs_submitted;
-  state.cumulative_proofs_paid = cumulative_proofs_paid;
-  state.cumulative_subsidy = cumulative_subsidy;
-}
-
- - - -
- - - -## Function `mock_proof` - -Add count proofs to the number submitted by sender - - -
public fun mock_proof(sender: &signer, count: u64)
-
- - - -
-Implementation - - -
public fun mock_proof(sender: &signer, count: u64) acquires FullnodeCounter {
-  assert(is_testnet(), Errors::invalid_state(060006));
-  let addr = Signer::address_of(sender);
-  let state = borrow_global_mut<FullnodeCounter>(addr);
-  state.proofs_submitted_in_epoch = state.proofs_submitted_in_epoch + count;
-}
-
- - - -
- - -[//]: # ("File containing references which can be used from documentation") -[ACCESS_CONTROL]: https://github.com/diem/dip/blob/main/dips/dip-2.md -[ROLE]: https://github.com/diem/dip/blob/main/dips/dip-2.md#roles -[PERMISSION]: https://github.com/diem/dip/blob/main/dips/dip-2.md#permissions diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/FullnodeSubsidy.md b/language/diem-framework/releases/artifacts/current/docs/modules/FullnodeSubsidy.md index 27ca11a74c..79c00f193d 100644 --- a/language/diem-framework/releases/artifacts/current/docs/modules/FullnodeSubsidy.md +++ b/language/diem-framework/releases/artifacts/current/docs/modules/FullnodeSubsidy.md @@ -5,148 +5,27 @@ -- [Resource `FullnodeSubsidy`](#0x1_FullnodeSubsidy_FullnodeSubsidy) -- [Constants](#@Constants_0) -- [Function `init_fullnode_sub`](#0x1_FullnodeSubsidy_init_fullnode_sub) - [Function `get_proof_price`](#0x1_FullnodeSubsidy_get_proof_price) - [Function `distribute_fullnode_subsidy`](#0x1_FullnodeSubsidy_distribute_fullnode_subsidy) -- [Function `fullnode_reconfig`](#0x1_FullnodeSubsidy_fullnode_reconfig) -- [Function `set_global_count`](#0x1_FullnodeSubsidy_set_global_count) -- [Function `baseline_auction_units`](#0x1_FullnodeSubsidy_baseline_auction_units) -- [Function `auctioneer`](#0x1_FullnodeSubsidy_auctioneer) -- [Function `calc_auction`](#0x1_FullnodeSubsidy_calc_auction) -- [Function `fullnode_subsidy_ceiling`](#0x1_FullnodeSubsidy_fullnode_subsidy_ceiling) -- [Function `test_set_fullnode_fixtures`](#0x1_FullnodeSubsidy_test_set_fullnode_fixtures)
use 0x1::CoreAddresses;
 use 0x1::Diem;
 use 0x1::DiemAccount;
 use 0x1::DiemSystem;
-use 0x1::Errors;
 use 0x1::GAS;
 use 0x1::MinerState;
-use 0x1::Roles;
-use 0x1::Signer;
-use 0x1::Testnet;
-use 0x1::TransactionFee;
-use 0x1::Vector;
 
- - -## Resource `FullnodeSubsidy` - - - -
struct FullnodeSubsidy has key
-
- - - -
-Fields - - -
-
-previous_epoch_proofs: u64 -
-
- -
-
-current_proof_price: u64 -
-
- -
-
-current_cap: u64 -
-
- -
-
-current_subsidy_distributed: u64 -
-
- -
-
-current_proofs_verified: u64 -
-
- -
-
- - -
- - - -## Constants - - - - - - -
const BASELINE_TX_COST: u64 = 4336;
-
- - - - - -## Function `init_fullnode_sub` - - - -
public fun init_fullnode_sub(vm: &signer)
-
- - - -
-Implementation - - -
public fun init_fullnode_sub(vm: &signer) {
-  let genesis_validators = DiemSystem::get_val_set_addr();
-  let validator_count = Vector::length(&genesis_validators);
-  if (validator_count < 10) validator_count = 10;
-
-  // baseline_cap: baseline units per epoch times the mininmum as used in tx, times minimum gas per unit.
-
-  let ceiling = baseline_auction_units() * BASELINE_TX_COST * validator_count;
-
-  Roles::assert_diem_root(vm);
-  assert(!exists<FullnodeSubsidy>(Signer::address_of(vm)), Errors::not_published(190106));
-  move_to<FullnodeSubsidy>(vm, FullnodeSubsidy{
-    previous_epoch_proofs: 0u64,
-    current_proof_price: BASELINE_TX_COST * 24 * 8 * 3, // number of proof submisisons in 3 initial epochs.
-    current_cap: ceiling,
-    current_subsidy_distributed: 0u64,
-    current_proofs_verified: 0u64,
-  });
-}
-
- - - -
- ## Function `get_proof_price` -
public fun get_proof_price(subsidy: u64): u64
+
public fun get_proof_price(one_val_subsidy: u64): u64
 
@@ -155,11 +34,15 @@ Implementation -
public fun get_proof_price(subsidy: u64): u64 {
-  // TODO: Check this exclude proofs submitted by validator nodes, or the total reward paid will not equal the pool for fullnodes.
-
+
public fun get_proof_price(one_val_subsidy: u64): u64 {
   let global_proofs = MinerState::get_fullnode_proofs();
-  subsidy/global_proofs
+
+  // proof price is simple, miners divide the equivalent of one compliant validator's subsidy.
+  // miners get a subsidy per proof in their tower.
+
+  // Note to rascals: I know what you're thinking, but for the same effort you'll put into that idea, it would be more profitable to just run a validator node.
+
+  one_val_subsidy/global_proofs
 }
 
@@ -184,7 +67,7 @@
public fun distribute_fullnode_subsidy(vm: &signer, miner: address, subsidy: u64):u64 {
   CoreAddresses::assert_diem_root(vm);
-  // Payment is only for fullnodes, ie. not in current validator set.
+  // Payment is only for fullnodes, ie. not validator candidates
   if (DiemSystem::is_validator(miner)) return 0; // TODO: this check is duplicated in reconfigure
   if (subsidy == 0) return 0;
 
@@ -203,265 +86,6 @@
 
 
 
-
-
-
-
-## Function `fullnode_reconfig`
-
-
-
-
public fun fullnode_reconfig(vm: &signer)
-
- - - -
-Implementation - - -
public fun fullnode_reconfig(vm: &signer) acquires FullnodeSubsidy {
-  Roles::assert_diem_root(vm);
-
-  // update values for the proof auction.
-  auctioneer(vm);
-  let state = borrow_global_mut<FullnodeSubsidy>(Signer::address_of(vm));
-   // save
-  state.previous_epoch_proofs = state.current_proofs_verified;
-  // reset counters
-  state.current_subsidy_distributed = 0u64;
-  state.current_proofs_verified = 0u64;
-}
-
- - - -
- - - -## Function `set_global_count` - - - -
public fun set_global_count(vm: &signer, count: u64)
-
- - - -
-Implementation - - -
public fun set_global_count(vm: &signer, count: u64) acquires FullnodeSubsidy{
-  let state = borrow_global_mut<FullnodeSubsidy>(Signer::address_of(vm));
-  state.current_proofs_verified = count;
-}
-
- - - -
- - - -## Function `baseline_auction_units` - - - -
fun baseline_auction_units(): u64
-
- - - -
-Implementation - - -
fun baseline_auction_units():u64 {
-  let epoch_length_mins = 24 * 60;
-  let steady_state_nodes = 1000;
-  let target_delay_mins = 10;
-  steady_state_nodes * (epoch_length_mins/target_delay_mins)
-}
-
- - - -
- - - -## Function `auctioneer` - - - -
fun auctioneer(vm: &signer)
-
- - - -
-Implementation - - -
fun auctioneer(vm: &signer) acquires FullnodeSubsidy {
-
-  Roles::assert_diem_root(vm);
-
-  let state = borrow_global_mut<FullnodeSubsidy>(Signer::address_of(vm));
-
-  // The targeted amount of proofs to be submitted network-wide per epoch.
-  let baseline_auction_units = baseline_auction_units();
-  // The max subsidy that can be paid out in the next epoch.
-  let ceiling = fullnode_subsidy_ceiling(vm);
-
-
-  // Failure case
-  if (ceiling < 1) ceiling = 1;
-
-  state.current_proof_price = calc_auction(
-    ceiling,
-    baseline_auction_units,
-    state.current_proofs_verified
-  );
-  // Set new ceiling
-  state.current_cap = ceiling;
-}
-
- - - -
- - - -## Function `calc_auction` - - - -
public fun calc_auction(ceiling: u64, baseline_auction_units: u64, current_proofs_verified: u64): u64
-
- - - -
-Implementation - - -
public fun calc_auction(
-  ceiling: u64,
-  baseline_auction_units: u64,
-  current_proofs_verified: u64,
-): u64 {
-  // Calculate price per proof
-  // Find the baseline price of a proof, which will be altered based on performance.
-  // let baseline_proof_price = FixedPoint32::divide_u64(
-  //   ceiling,
-  //   FixedPoint32::create_from_raw_value(baseline_auction_units)
-  // );
-  let baseline_proof_price = ceiling/baseline_auction_units;
-
-  // print(&FixedPoint32::get_raw_value(copy baseline_proof_price));
-  // Calculate the appropriate multiplier.
-  let proofs = current_proofs_verified;
-  if (proofs < 1) proofs = 1;
-
-  let multiplier = baseline_auction_units/proofs;
-
-  // let multiplier = FixedPoint32::create_from_rational(
-  //   baseline_auction_units,
-  //   proofs
-  // );
-  // print(&multiplier);
-
-  // Set the proof price using multiplier.
-  // New unit price cannot be more than the ceiling
-  // let proposed_price = FixedPoint32::multiply_u64(
-  //   baseline_proof_price,
-  //   multiplier
-  // );
-
-  let proposed_price = baseline_proof_price * multiplier;
-
-  // print(&proposed_price);
-
-  if (proposed_price < ceiling) {
-    return proposed_price
-  };
-  //Note: in failure case, the next miner gets the full ceiling
-  return ceiling
-}
-
- - - -
- - - -## Function `fullnode_subsidy_ceiling` - - - -
fun fullnode_subsidy_ceiling(vm: &signer): u64
-
- - - -
-Implementation - - -
fun fullnode_subsidy_ceiling(vm: &signer):u64 {
-  //get TX fees from previous epoch.
-  let fees = TransactionFee::get_amount_to_distribute(vm);
-  // Recover from failure case where there are no fees
-  if (fees < baseline_auction_units()) return baseline_auction_units();
-  fees
-}
-
- - - -
- - - -## Function `test_set_fullnode_fixtures` - - - -
public fun test_set_fullnode_fixtures(vm: &signer, previous_epoch_proofs: u64, current_proof_price: u64, current_cap: u64, current_subsidy_distributed: u64, current_proofs_verified: u64)
-
- - - -
-Implementation - - -
public fun test_set_fullnode_fixtures(
-  vm: &signer,
-  previous_epoch_proofs: u64,
-  current_proof_price: u64,
-  current_cap: u64,
-  current_subsidy_distributed: u64,
-  current_proofs_verified: u64,
-) acquires FullnodeSubsidy {
-  Roles::assert_diem_root(vm);
-  assert(is_testnet(), Errors::invalid_state(190108));
-  let state = borrow_global_mut<FullnodeSubsidy>(@0x0);
-  state.previous_epoch_proofs = previous_epoch_proofs;
-  state.current_proof_price = current_proof_price;
-  state.current_cap = current_cap;
-  state.current_subsidy_distributed = current_subsidy_distributed;
-  state.current_proofs_verified = current_proofs_verified;
-}
-
- - -
diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/Genesis.md b/language/diem-framework/releases/artifacts/current/docs/modules/Genesis.md index e363c81241..21e6a42529 100644 --- a/language/diem-framework/releases/artifacts/current/docs/modules/Genesis.md +++ b/language/diem-framework/releases/artifacts/current/docs/modules/Genesis.md @@ -27,7 +27,6 @@ when executing from a fresh state. use 0x1::DiemVersion; use 0x1::DualAttestation; use 0x1::Epoch; -use 0x1::FullnodeSubsidy; use 0x1::GAS; use 0x1::Hash; use 0x1::Migrations; @@ -136,7 +135,7 @@ Initializes the Diem framework. Stats::initialize(dm_account); ValidatorUniverse::initialize(dm_account); AutoPay2::initialize(dm_account); - FullnodeSubsidy::init_fullnode_sub(dm_account); + // FullnodeSubsidy::init_fullnode_sub(dm_account); Oracle::initialize(dm_account); MinerState::init_list(dm_account); Wallet::init(dm_account); diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/MinerState.md b/language/diem-framework/releases/artifacts/current/docs/modules/MinerState.md index ef1df2b7f4..1467e0e79c 100644 --- a/language/diem-framework/releases/artifacts/current/docs/modules/MinerState.md +++ b/language/diem-framework/releases/artifacts/current/docs/modules/MinerState.md @@ -57,7 +57,6 @@ TODO
use 0x1::CoreAddresses;
-use 0x1::Debug;
 use 0x1::DiemConfig;
 use 0x1::Errors;
 use 0x1::Globals;
@@ -274,7 +273,7 @@ Struct to encapsulate information about the state of a miner
 
 
 
-
fun increment_stats(global: u64, validator: u64, fullnode: u64)
+
fun increment_stats(miner_addr: address)
 
@@ -283,13 +282,20 @@ Struct to encapsulate information about the state of a miner Implementation -
fun increment_stats(global: u64, validator: u64, fullnode: u64) acquires MinerStats {
+
fun increment_stats(miner_addr: address) acquires MinerStats {
   assert(exists<MinerStats>(CoreAddresses::VM_RESERVED_ADDRESS()), 1301001);
   let state = borrow_global_mut<MinerStats>(CoreAddresses::VM_RESERVED_ADDRESS());
 
-  state.proofs_in_epoch = global;
-  state.validator_proofs = validator;
-  state.fullnode_proofs = fullnode;
+  if (ValidatorConfig::is_valid(miner_addr)) {
+    state.validator_proofs = state.validator_proofs + 1;
+  } else {
+    state.fullnode_proofs = state.fullnode_proofs + 1;
+  };
+
+  state.proofs_in_epoch = state.proofs_in_epoch + 1;
+  // print(&miner_addr);
+  // print(state);
+
 }
 
@@ -524,13 +530,13 @@ adds miner to list of miners //TODO: Previously in OLv3 is_genesis() returned true. How to check that this is part of genesis? is_genesis returns false here. // assert(DiemTimestamp::is_genesis(), 130101024010); - print(&10001); + // print(&10001); init_miner_state(miner_sig, &challenge, &solution); - print(&10002); + // print(&10002); // TODO: Move this elsewhere? // Initialize stats for first validator set from rust genesis. let node_addr = Signer::address_of(miner_sig); - print(&10003); + // print(&10003); Stats::init_address(vm_sig, node_addr); }
@@ -690,15 +696,7 @@ Permissions: PUBLIC, ANYONE miner_history.latest_epoch_mining = DiemConfig::get_current_epoch(); - if (ValidatorConfig::is_valid(miner_addr)) { - // TODO: ValidatorConfig::is_valid is being used here instead of DiemSystem::is_validator() because of dependency cycling. is_validator is used in reconfigure and FullnodeSubsidy - - // increment validator count - increment_stats(1, 1, 0); - } else { - // increment fullnode count - increment_stats(1, 0, 1); - } + increment_stats(miner_addr); }
@@ -732,7 +730,7 @@ Permissions: PUBLIC, ANYONE // Check that there was mining and validating in period. // Account may not have any proofs submitted in epoch, since the resource was last emptied. - let passed = node_above_thresh(account, miner_addr); + let passed = node_above_thresh(miner_addr); let miner_history = borrow_global_mut<MinerProofHistory>(miner_addr); // Update statistics. @@ -766,7 +764,7 @@ Permissions: PUBLIC, ANYONE Checks to see if miner submitted enough proofs to be considered compliant -
public fun node_above_thresh(_account: &signer, miner_addr: address): bool
+
public fun node_above_thresh(miner_addr: address): bool
 
@@ -775,7 +773,7 @@ Checks to see if miner submitted enough proofs to be considered compliant Implementation -
public fun node_above_thresh(_account: &signer, miner_addr: address): bool acquires MinerProofHistory {
+
public fun node_above_thresh(miner_addr: address): bool acquires MinerProofHistory {
   let miner_history = borrow_global<MinerProofHistory>(miner_addr);
   miner_history.count_proofs_in_epoch > Globals::get_epoch_mining_thres_lower()
 }
@@ -927,7 +925,7 @@ Checks to see if miner submitted enough proofs to be considered compliant
   };
 
   // TODO: should fullnode state happen here?
-  // FullnodeState::init(miner_sig);
+  // FullnodeState::init(miner_sig);
 
   //submit the proof
   verify_and_update_state(Signer::address_of(miner_sig), proof, false);
@@ -1071,7 +1069,11 @@ Public Getters ///
 
 
 
public fun get_epochs_mining(node_addr: address): u64 acquires MinerProofHistory {
-  borrow_global<MinerProofHistory>(node_addr).epochs_validating_and_mining
+  if (exists<MinerProofHistory>(node_addr)) {
+    return borrow_global<MinerProofHistory>(node_addr).epochs_validating_and_mining
+
+  };
+  0
 }
 
@@ -1095,7 +1097,10 @@ Public Getters ///
public fun get_count_in_epoch(miner_addr: address): u64 acquires MinerProofHistory {
-  borrow_global<MinerProofHistory>(miner_addr).count_proofs_in_epoch
+  if (exists<MinerProofHistory>(miner_addr)) {
+    return borrow_global<MinerProofHistory>(miner_addr).count_proofs_in_epoch
+  };
+  0
 }
 
@@ -1121,7 +1126,10 @@ Public Getters ///
public fun can_create_val_account(node_addr: address): bool acquires MinerProofHistory {
   if(Testnet::is_testnet() || StagingNet::is_staging_net()) return true;
   // check if rate limited, needs 7 epochs of validating.
-  borrow_global<MinerProofHistory>(node_addr).epochs_since_last_account_creation > EPOCHS_UNTIL_ACCOUNT_CREATION
+  if (exists<MinerProofHistory>(node_addr)) {
+    return borrow_global<MinerProofHistory>(node_addr).epochs_since_last_account_creation > EPOCHS_UNTIL_ACCOUNT_CREATION
+  };
+  false
 }
 
@@ -1170,7 +1178,7 @@ Public Getters /// }; verify_and_update_state(Signer::address_of(miner_sig), proof, false); - // FullnodeState::init(miner_sig); + // FullnodeState::init(miner_sig); }
@@ -1242,11 +1250,18 @@ Public Getters /// Implementation -
public fun test_helper_mock_mining(sender: &signer,  count: u64) acquires MinerProofHistory {
+
public fun test_helper_mock_mining(sender: &signer,  count: u64) acquires MinerProofHistory, MinerStats {
   assert(Testnet::is_testnet(), Errors::invalid_state(130118));
-  let state = borrow_global_mut<MinerProofHistory>(Signer::address_of(sender));
+  let addr = Signer::address_of(sender);
+  let state = borrow_global_mut<MinerProofHistory>(addr);
   state.count_proofs_in_epoch = count;
-  // FullnodeState::mock_proof(sender, count);
+  let i = 0;
+  while (i < count) {
+    increment_stats(addr);
+    i = i + 1;
+  }
+
+  // FullnodeState::mock_proof(sender, count);
 }
 
@@ -1269,12 +1284,17 @@ Public Getters /// Implementation -
public fun test_helper_mock_mining_vm(vm: &signer, addr: address, count: u64) acquires MinerProofHistory {
-  CoreAddresses::assert_diem_root(vm);
-
+
public fun test_helper_mock_mining_vm(vm: &signer, addr: address, count: u64) acquires MinerProofHistory, MinerStats {
   assert(Testnet::is_testnet(), Errors::invalid_state(130120));
+  CoreAddresses::assert_diem_root(vm);
   let state = borrow_global_mut<MinerProofHistory>(addr);
   state.count_proofs_in_epoch = count;
+
+  let i = 0;
+  while (i < count) {
+    increment_stats(addr);
+    i = i + 1;
+  }
 }
 
diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/Reconfigure.md b/language/diem-framework/releases/artifacts/current/docs/modules/Reconfigure.md index fea3b83314..41b2630441 100644 --- a/language/diem-framework/releases/artifacts/current/docs/modules/Reconfigure.md +++ b/language/diem-framework/releases/artifacts/current/docs/modules/Reconfigure.md @@ -16,6 +16,7 @@ use 0x1::AutoPay2; use 0x1::Burn; use 0x1::CoreAddresses; +use 0x1::Debug; use 0x1::DiemAccount; use 0x1::DiemConfig; use 0x1::DiemSystem; @@ -49,24 +50,33 @@
public fun reconfigure(vm: &signer, height_now: u64) {
+    print(&1800100);
     CoreAddresses::assert_vm(vm);
 
     let height_start = Epoch::get_timer_height_start(vm);
 
-    let (subsidy_units, subsidy_per) = Subsidy::calculate_subsidy(vm, height_start, height_now);
+    print(&1800101);
+    let (outgoing_compliant_set, _) = DiemSystem::get_fee_ratio(vm, height_start, height_now);
+    // NOTE: This is "nominal" because it doesn't check
+    let compliant_nodes_count = Vector::length(&outgoing_compliant_set);
+    let (subsidy_units, nominal_subsidy_per) = Subsidy::calculate_subsidy(vm, compliant_nodes_count);
 
-    process_fullnodes(vm, subsidy_per);
+    print(&1800102);
+    process_fullnodes(vm, nominal_subsidy_per);
 
-    process_validators(vm, height_start, height_now, subsidy_units);
+    print(&1800103);
+    process_validators(vm, subsidy_units, outgoing_compliant_set);
 
+    print(&1800104);
     let proposed_set = propose_new_set(vm, height_start, height_now);
 
+    print(&1800105);
     // Update all slow wallet limits
     if (DiemConfig::check_transfer_enabled()) {
         DiemAccount::slow_wallet_epoch_drip(vm, Globals::get_unlock());
         // update_validator_withdrawal_limit(vm);
     };
-
+    print(&1800106);
     reset_counters(vm, proposed_set, height_now)
 }
 
@@ -81,7 +91,7 @@ -
fun process_fullnodes(vm: &signer, subsidy_per_node: u64)
+
fun process_fullnodes(vm: &signer, nominal_subsidy_per_node: u64)
 
@@ -90,44 +100,44 @@ Implementation -
fun process_fullnodes(vm: &signer, subsidy_per_node: u64) {
+
fun process_fullnodes(vm: &signer, nominal_subsidy_per_node: u64) {
     // Fullnode subsidy
     // loop through validators and pay full node subsidies.
     // Should happen before transactionfees get distributed.
     // Note: need to check, there may be new validators which have not mined yet.
-    // print(&03100);
 
+    print(&1800200);
     let miners = MinerState::get_miner_list();
-
+    print(&1800201);
     // fullnode subsidy is a fraction of the total subsidy available to validators.
-    let proof_price = FullnodeSubsidy::get_proof_price(subsidy_per_node);
+    let proof_price = FullnodeSubsidy::get_proof_price(nominal_subsidy_per_node);
+    // print(&nominal_subsidy_per_node);
+    // print(&proof_price);
 
     let k = 0;
-    // print(&03200);
     // Distribute mining subsidy to fullnodes
+    print(&1800202);
     while (k < Vector::length(&miners)) {
         let addr = *Vector::borrow(&miners, k);
-        // print(&03210);
-
-        // if (!FullnodeState::is_init(addr)) continue; // fail-safe
-        if (DiemSystem::is_validator(addr)) continue; // skip validators
-
-        let count = MinerState::get_count_in_epoch(addr);
-
-        let miner_subsidy = count * proof_price;
+        print(&1800203);
+        if (DiemSystem::is_validator(addr)) { // skip validators
+          k = k + 1;
+          continue
+        };
+        print(&1800204);
 
-        FullnodeSubsidy::distribute_fullnode_subsidy(vm, addr, miner_subsidy);
+        if (MinerState::node_above_thresh(addr)){ // TODO: this call is repeated in propose_new_set. Not sure if the performance hit at epoch boundary is worth the refactor.
+          let count = MinerState::get_count_in_epoch(addr);
+          // print(&count);
 
-        // print(&03230);
-        // FullnodeState::inc_payment_count(vm, addr, count);
-        // FullnodeState::inc_payment_value(vm, addr, value);
-        // FullnodeState::reconfig(vm, addr, count);
+          let miner_subsidy = count * proof_price;
+          print(&1800205);
+          // print(&miner_subsidy);
+          FullnodeSubsidy::distribute_fullnode_subsidy(vm, addr, miner_subsidy);
+        };
 
         k = k + 1;
     };
-
-     // needs to be set before the auctioneer runs in Subsidy::fullnode_reconfig
-    // FullnodeSubsidy::set_global_count(vm, global_proofs_count);
 }
 
@@ -141,7 +151,7 @@ -
fun process_validators(vm: &signer, height_start: u64, height_now: u64, subsidy_units: u64)
+
fun process_validators(vm: &signer, subsidy_units: u64, outgoing_compliant_set: vector<address>)
 
@@ -150,22 +160,21 @@ Implementation -
fun process_validators(vm: &signer, height_start: u64, height_now: u64, subsidy_units: u64) {
+
fun process_validators(vm: &signer, subsidy_units: u64, outgoing_compliant_set: vector<address>) {
     // Process outgoing validators:
     // Distribute Transaction fees and subsidy payments to all outgoing validators
     // print(&03240);
-    let (outgoing_set, _) = DiemSystem::get_fee_ratio(vm, height_start, height_now);
 
-    if (Vector::length<address>(&outgoing_set) > 0) {
-        // let (subsidy_units, _) = Subsidy::calculate_subsidy(vm, height_start, height_now);
+
+    if (Vector::length<address>(&outgoing_compliant_set) > 0) {
         // print(&03241);
 
         if (subsidy_units > 0) {
-            Subsidy::process_subsidy(vm, subsidy_units, &outgoing_set);
+            Subsidy::process_subsidy(vm, subsidy_units, &outgoing_compliant_set);
         };
         // print(&03241);
 
-        Subsidy::process_fees(vm, &outgoing_set);
+        Subsidy::process_fees(vm, &outgoing_compliant_set);
     };
 
 }
@@ -205,6 +214,7 @@
     let jailed_set = DiemSystem::get_jailed_set(vm, height_start, height_now);
 
     Burn::reset_ratios(vm);
+    // LEAVE THIS CODE COMMENTED for future use
     // TODO: Make the burn value dynamic.
     // let incoming_count = Vector::length<address>(&top_accounts) - Vector::length<address>(&jailed_set);
     // let burn_value = Subsidy::subsidy_curve(
@@ -212,6 +222,7 @@
     //   incoming_count,
     //   Globals::get_max_node_density()
     // )/4;
+
     let burn_value = 1000000; // TODO: switch to a variable cost, as above.
 
     // print(&03250);
@@ -221,7 +232,7 @@
         // print(&03251);
 
         let addr = *Vector::borrow(&top_accounts, i);
-        let mined_last_epoch = MinerState::node_above_thresh(vm, addr);
+        let mined_last_epoch = MinerState::node_above_thresh(addr);
         // print(&mined_last_epoch);
         // TODO: temporary until jail-refactor merge.
         if (
@@ -283,7 +294,7 @@
     // print(&032110);
 
     // reset clocks
-    FullnodeSubsidy::fullnode_reconfig(vm);
+    // FullnodeSubsidy::fullnode_reconfig(vm);
     // print(&032120);
 
     // process community wallets
diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/Subsidy.md b/language/diem-framework/releases/artifacts/current/docs/modules/Subsidy.md
index 0a6d0e6532..4200be4859 100644
--- a/language/diem-framework/releases/artifacts/current/docs/modules/Subsidy.md
+++ b/language/diem-framework/releases/artifacts/current/docs/modules/Subsidy.md
@@ -15,6 +15,7 @@
 
 
 
use 0x1::CoreAddresses;
+use 0x1::Debug;
 use 0x1::Diem;
 use 0x1::DiemAccount;
 use 0x1::DiemTimestamp;
@@ -24,7 +25,6 @@
 use 0x1::Globals;
 use 0x1::MinerState;
 use 0x1::Signer;
-use 0x1::Stats;
 use 0x1::TransactionFee;
 use 0x1::ValidatorConfig;
 use 0x1::ValidatorUniverse;
@@ -68,23 +68,25 @@
   outgoing_set: &vector<address>,
 ) {
   CoreAddresses::assert_vm(vm);
-
+  print(&1901001);
   // Get the split of payments from Stats.
   let len = Vector::length<address>(outgoing_set);
-
+  print(&1901002);
   // equal subsidy for all active validators
   let subsidy_granted;
+  // TODO: This calculation is duplicated with get_subsidy
   if (subsidy_units > len && subsidy_units > 0 ) { // arithmetic safety check
     subsidy_granted = subsidy_units/len;
+    print(&subsidy_granted);
   } else { return };
 
   let i = 0;
   while (i < len) {
-
+    print(&1901003);
     let node_address = *(Vector::borrow<address>(outgoing_set, i));
     // Transfer gas from vm address to validator
     let minted_coins = Diem::mint<GAS>(vm, subsidy_granted);
-
+    print(&1901004);
     DiemAccount::vm_deposit_with_metadata<GAS>(
       vm,
       node_address,
@@ -92,6 +94,8 @@
       b"validator subsidy",
       b""
     );
+    print(&1901005);
+
     // refund operator tx fees for mining
     refund_operator_tx_fees(vm, node_address);
     i = i + 1;
@@ -109,7 +113,7 @@
 
 
 
-
public fun calculate_subsidy(vm: &signer, height_start: u64, height_end: u64): (u64, u64)
+
public fun calculate_subsidy(vm: &signer, network_density: u64): (u64, u64)
 
@@ -118,32 +122,49 @@ Implementation -
public fun calculate_subsidy(vm: &signer, height_start: u64, height_end: u64): (u64, u64) {
+
public fun calculate_subsidy(vm: &signer, network_density: u64): (u64, u64) {
   CoreAddresses::assert_vm(vm);
+  print(&1901006);
   // skip genesis
   assert(!DiemTimestamp::is_genesis(), Errors::invalid_state(190102));
 
   // Gets the transaction fees in the epoch
   let txn_fee_amount = TransactionFee::get_amount_to_distribute(vm);
-
+  print(&1901007);
   // Calculate the split for subsidy and burn
   let subsidy_ceiling_gas = Globals::get_subsidy_ceiling_gas();
-  let network_density = Stats::network_density(vm, height_start, height_end);
-  let max_node_count = Globals::get_max_validators_per_set();
+  // TODO: This metric network density is different than DiemSystem::get_fee_ratio which actually checks the cases.
 
+  // let network_density = Stats::network_density(vm, height_start, height_end);
+  let max_node_count = Globals::get_max_validators_per_set();
+  print(&1901008);
   let guaranteed_minimum = subsidy_curve(
     subsidy_ceiling_gas,
     network_density,
     max_node_count,
   );
-
+  print(&1901009);
+  let subsidy = 0;
+  let subsidy_per_node = 0;
   // deduct transaction fees from guaranteed minimum.
   if (guaranteed_minimum > txn_fee_amount ){
-    let subsidy = guaranteed_minimum - txn_fee_amount;
+    print(&190100901);
+    subsidy = guaranteed_minimum - txn_fee_amount;
     // return global subsidy and subsidy per node.
-    return (subsidy, subsidy/network_density)
+    print(&190100902);
+    // TODO: we are doing this computation twice at reconfigure time.
+    if ((subsidy > network_density) && (network_density > 0)) {
+      print(&190100903);
+      print(&subsidy);
+      print(&network_density);
+
+      subsidy_per_node = subsidy/network_density;
+      print(&subsidy_per_node);
+
+    };
   };
-  (0u64, 0u64)
+  print(&1901010);
+  (subsidy, subsidy_per_node)
 }
 
@@ -170,7 +191,7 @@ subsidy_ceiling_gas: u64, network_density: u64, max_node_count: u64 - ): u64 { +): u64 { let min_node_count = 4u64; diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/ValidatorUniverse.md b/language/diem-framework/releases/artifacts/current/docs/modules/ValidatorUniverse.md index a1f5c1cfc2..8cce6d57de 100644 --- a/language/diem-framework/releases/artifacts/current/docs/modules/ValidatorUniverse.md +++ b/language/diem-framework/releases/artifacts/current/docs/modules/ValidatorUniverse.md @@ -138,7 +138,7 @@ if (MinerState::is_onboarding(addr)) { add(sender); } else { - assert(MinerState::node_above_thresh(sender, addr), 220102014010); + assert(MinerState::node_above_thresh(addr), 220102014010); add(sender); } } @@ -333,7 +333,7 @@ // only a validator can un-jail themselves. let validator = Signer::address_of(sender); // check the node has been mining before unjailing. - assert(MinerState::node_above_thresh(sender, validator), 220102014010); + assert(MinerState::node_above_thresh(validator), 220102014010); unjail(sender); }
diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/ol_validator.md b/language/diem-framework/releases/artifacts/current/docs/modules/ol_validator.md index c25f093d2d..c2a3411bcf 100644 --- a/language/diem-framework/releases/artifacts/current/docs/modules/ol_validator.md +++ b/language/diem-framework/releases/artifacts/current/docs/modules/ol_validator.md @@ -109,7 +109,7 @@ let addr = Signer::address_of(&validator); // if is above threshold continue, or raise error. assert( - MinerState::node_above_thresh(&validator, addr), + MinerState::node_above_thresh(addr), Errors::invalid_state(NOT_ABOVE_THRESH_JOIN) ); // if is not in universe, add back @@ -179,7 +179,7 @@ let addr = Signer::address_of(validator); // if is above threshold continue, or raise error. assert( - MinerState::node_above_thresh(validator, addr), + MinerState::node_above_thresh(addr), Errors::invalid_state(NOT_ABOVE_THRESH_ADD) ); // if is not in universe, add back diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/overview.md b/language/diem-framework/releases/artifacts/current/docs/modules/overview.md index 3c3734544c..1d0551e4cb 100644 --- a/language/diem-framework/releases/artifacts/current/docs/modules/overview.md +++ b/language/diem-framework/releases/artifacts/current/docs/modules/overview.md @@ -99,11 +99,13 @@ The Move modules in the Diem Framework can be bucketed in to a couple categories - [`0x1::AutoPay2`](AutoPay.md#0x1_AutoPay2) - [`0x1::AutoPayScripts`](ol_autopay.md#0x1_AutoPayScripts) - [`0x1::BCS`](../../../../../../move-stdlib/docs/BCS.md#0x1_BCS) +- [`0x1::Bonding`](Demo_Bonding.md#0x1_Bonding) - [`0x1::Burn`](Burn.md#0x1_Burn) - [`0x1::Cases`](Cases.md#0x1_Cases) - [`0x1::ChainId`](ChainId.md#0x1_ChainId) - [`0x1::CoreAddresses`](CoreAddresses.md#0x1_CoreAddresses) - [`0x1::Debug`](Debug.md#0x1_Debug) +- [`0x1::Decimal`](Decimal.md#0x1_Decimal) - [`0x1::DemoScripts`](ol_demo_e2e.md#0x1_DemoScripts) - [`0x1::DesignatedDealer`](DesignatedDealer.md#0x1_DesignatedDealer) - [`0x1::Diem`](Diem.md#0x1_Diem) @@ -123,7 +125,6 @@ The Move modules in the Diem Framework can be bucketed in to a couple categories - [`0x1::Event`](../../../../../../move-stdlib/docs/Event.md#0x1_Event) - [`0x1::FIFO`](FIFO.md#0x1_FIFO) - [`0x1::FixedPoint32`](../../../../../../move-stdlib/docs/FixedPoint32.md#0x1_FixedPoint32) -- [`0x1::FullnodeState`](FullnodeState.md#0x1_FullnodeState) - [`0x1::FullnodeSubsidy`](FullnodeSubsidy.md#0x1_FullnodeSubsidy) - [`0x1::GAS`](GAS.md#0x1_GAS) - [`0x1::Genesis`](Genesis.md#0x1_Genesis) diff --git a/language/diem-framework/releases/artifacts/current/modules/026_MinerState.mv b/language/diem-framework/releases/artifacts/current/modules/026_MinerState.mv new file mode 100644 index 0000000000000000000000000000000000000000..b0f339c7898f2a924d6727ff59a4985f17f6bf6f GIT binary patch literal 4881 zcmb7I*>W4l742numY%^fSV);7MN%XUk(8)iqGZXkBGQ&E$xf{C#a62RIWl2wFctZHGXDVwpngV~IWVb;TN21nTkG|Wj1XMGIwGGJ_h zX6GP=Ez+<=$Ce8i&J)uW8dhmoD`M?K+HI6DTp(8KG;GkY$;ymf46$*kf?>M$lh)0$b2p`ZL5Gye-fAfI5ypF%EwhEu_p zXEkT~`TPQtFROO5Q(3GMeursa~Ax372N$_zyj-+wEC;{4bJ4R zNzm7L*1x&Infh(H%r4K}V7J*eyD@i}eZ;upT-X8NlXjq7DYd{qcO|z2p=>QIJFo*S zuqHvLxK<#kyKoA>ELbt9G4E8H7>ZVJ%&LD1s1kT zZ_cr%9G5E`kdDh7t!#xu9rly(5CFw+MiHePQ$j8ngGo-or6M8_Deq4Bzr18W3{WQ+9IMX|w_~=p6JLnwRyJ?!F zne$mU*=u$)>v1z{+b=tZIH+;*u+uyIGVUv4k~y#9tlx|K^7YQArPs}FXTRA`(jlMM zaSIQg5&5)}^+PjzktWH(V>~A5+le}vGV3#~W-n@`G4zYxG`mr=)k+4ve$YyejynA) zBgM~5KSX*xHqWfm2Y-YJE zgN+0AX{~_Iq_>we(|u?e8ts~U$(uOpw}D36P2-kvcG+MP0lyd=fw6Bi&LNnann$EB z&h$HngJh7^-`xUIGpASE#;o%6avR|^JH2p}w7wa_c|zdSdi3V#gLjUMOqieE8O1`B z4fbG7wlKYkC^+f9#nZdF2geRSp%0y&;B-PC+R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^Rrn=N0q^q~GDy@alENcw_?Cyz4oP)H*g6*#@={}#f`s5LtC~&Uq3E@Ob~f}W zw9b&Cj4rKr!hYY65Ibs2o@TDYRF`ZhZLF%mP-3z5dRxi3p@UDQdl zO^VhAf@_kh@Eog)ncNE(7s53Yg)UCocdz{Ii*vC0hd?)wU>M6BYi#3-nRyZDJ~G9Z zC*htYZ7!9=HFw#5HgfpA02xBH)E5wm66)2&8ADhgLbK=EfB56z$xthhAd5dBlC62e z>&b+d$q4Y0;DrMCbhI-nxpfql+{f^fu8FxRm0pa9-%-i0iL>w~7nfJVHT%;EU7o!@ z1*+XJ84j-jX$!_%B{ivkbOmU>BInhL7GY7#F?=(DRI_54%xA=cF|ta5Xz==CA|c1CL1eh*N!L+1 zuFw@lSI*9e_l4nAGLNfdbmg2^TcayycSLtD@B{5@x#j!gD`$}uzE(BLemNnukjE0v zwctXkl>k|k?7CR`5#*{amVX2}vgEuW58;{dC3J6i(Rvh3D_ohX@|vprBpOip?K;-HlWQKWp#V*)v_J-{8{_1|Id2kf zzy*e`qPpP@xZW~wQJq0$y1!!Ioj{u3xD{X0jf)>0>S`5jNB~lQ+5Tukmp3A-MCUY! z!Za(qTnIl7wAS{$5$ULdxJ{&JB3M`eX`vQA(6Z#i3i(LA0((7ei!AB7(Qe8<2@BNM n6Z?o}ybWHe9^L}xP8}kO_`O1MK^cl)Be;dB`ALNWSqk=l1v(T^ literal 0 HcmV?d00001 diff --git a/language/diem-framework/releases/artifacts/current/modules/027_MinerState.mv b/language/diem-framework/releases/artifacts/current/modules/027_MinerState.mv deleted file mode 100644 index 00f3136c57adfeae4eee445f5060dbcb078f64b4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4827 zcmb7INpl;=74BuaXV5cP1`DZ$lt_^@L{g%5iI%03cqRB_{qObiZ`Kwdz?oo@IZQFl zT;{P7Gt6fJE3=BnSQURY{Dsh62QO;~$yn3D&{CSQITy2e55t)fhO-c6=V&-DF)a8P z7G=QL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Y*7aH3q#Y)jiTWA=0j*(E)6z67K`n+I%!zI5d&J*Jebaegxl+8h5 zNmxUjI_)vY6t}3VmRPV74Ulg`>d90p?_NH6LOU2=!;mZpELvY0R4+EHkESAdSXDA4 zVF*2aMO?_Uck>pqN2i3INgaB=VawB9RdmBToe>o`5d$a7Evr;+oe@-IsLg;Y)u@t>P*W zfYo2t?@amf%fKq}xozUG7Y1G{hu;Z|G5SHlTAbqdh!qDp3(H_FH^X<);C)0PAFJn3 zZ)RhWRnxNG&BRCLtG=AZM?8~d=u)i^HgH10#CvjI^(KqcNzqrriaLIiI-!IW{EISV-qjQJs~MR#u5MAF en1wg{GrwUJ?l-t`mps~Oogu5M;h6z5_P7X91^}Db4D0{^ diff --git a/language/diem-framework/releases/artifacts/current/modules/029_NodeWeight.mv b/language/diem-framework/releases/artifacts/current/modules/028_NodeWeight.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/029_NodeWeight.mv rename to language/diem-framework/releases/artifacts/current/modules/028_NodeWeight.mv diff --git a/language/diem-framework/releases/artifacts/current/modules/029_Cases.mv b/language/diem-framework/releases/artifacts/current/modules/029_Cases.mv new file mode 100644 index 0000000000000000000000000000000000000000..c1e88e96b43bb674237eb1e43b62260baf19ec9f GIT binary patch literal 315 zcmYk0K}rNM5Jjs}sU)4$q8mj)8fI`cAR;nHaOJ{{9w4+%bOv-9I>D7k@Dkp^TX_jP zDB|DLtEvzGfAn8L0f0qt!=aji}c2B9qhuP2$Ij5<_%`UyfX&g(pA2%ru_v34d zWjm$3owNT7$>Hx#PXAGDUqz07pf(1z_RwJfk6wA|l(5H+M0@snK`kFxkcKZk(-EI| ly%fWJBPJMH@Tpbe_`>tDdRKgANi3gR6dSC#;G_wSf^QG{C58Y1 literal 0 HcmV?d00001 diff --git a/language/diem-framework/releases/artifacts/current/modules/030_Cases.mv b/language/diem-framework/releases/artifacts/current/modules/030_Cases.mv deleted file mode 100644 index 26718605c790b74a5de11ab58acf11f9385bca93..0000000000000000000000000000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&`3%brj*HC zbe$c=`(HhLqMto|`dshr?>~EZa8S$54>OB3(RntRqnU{v+rx=j2_+^b9hWb~VTNTn z^|1m;IyBxC>(V)yB8TG)N$68szSL7wCMbE*yht#~$Fr$P%eC*&Jj#>P2gz}Ah?$h< zo93*{v0BwhXVSw<8O-A7@w1-N@Quz@`f@qQAu~MG&C6`{z6_ZTLKI`*)ZqddD;eNbJ#hf=_S6n=l zAY}A4hO8+iRb1Z@KVQH$7O>4FY*Uds836X0*FSDo5tP3SrLb2>w#%;b$8}^iAnS@t zKA;E>b$@-pkReDOc|P&!z;h;K<+oN4TPjjAlI%-|7~R6&gY2rOr6}*>TZ;O^)z6(o z_-|vXj*nZ16~5SIP2P6L35i(TxlGxSk!arL_fa(N==n%kbSqjuQu7AfXLD*RxSVgS zgkuQb{-T1X2<%}fug@fJNU{{7uL6#AT*W%>C?(Xnbyu}=CGvLJF8|Dl=Ez_U(npav z&LZNzS24kL>`Au5hw<%2P!E;q+?6EmIvL_k#g`ONi_1-))p+cq^c^SB(x=Z_{5Hx* zF$+)9eh(|RBR%vXNRIm4rx6SUzk_g;W8U4qaFFgnmZ;$k=JQa3J3w!;I&UsxQ%nLW Yw3oc&Yw>n<4{4`@6OwdX^%#Z!0a6lWJpcdz diff --git a/language/diem-framework/releases/artifacts/current/modules/054_DemoScripts.mv b/language/diem-framework/releases/artifacts/current/modules/056_DemoScripts.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/054_DemoScripts.mv rename to language/diem-framework/releases/artifacts/current/modules/056_DemoScripts.mv diff --git a/language/diem-framework/releases/artifacts/current/modules/056_FullnodeSubsidy.mv b/language/diem-framework/releases/artifacts/current/modules/056_FullnodeSubsidy.mv deleted file mode 100644 index cd3300d018d5425cf5ed11e758e115d69de54628..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1620 zcmY*aPjBNy6n``089Q$#wcRvrNXu?_16zT_0mPx#3Rq5D=!&c5I+Jvy#I9_o%ia** zfeV5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YKVig@*s&Mg1Qh8tX<+AJ1G4# z3a$j_w6s&qM#L`QbE&g4-OJTQh z@xyLxMT`@zkf9X~T4Ok=2o&eHMByBWu$cyDY@xDsQNjEcu% zFNHEZae(nC85lN!6xxRqJv0Yt9vAvaTs+njQ$#>?)Tk1Qve9&6lA`$zsE1kf6$qzGN@5`)2j5~SO=gW4fB7x4Vx|8tO{IGtq0H-`J6RnEvjNP?MvBJI!-iz z9Xz(MC(-*xA4E?rIGv<=98cn6X^yu43v`#Q}>_7 zOdv_4J}+i>ULi>^k|b=LfZDa)BS|w{6zbSG@QWj>@6MXZ4x-vXqELum@R>4*assE1 zLboeEd2WXwOsblyDc5sp6TVKbcELlTR88?~bwLIaE_jNE3WmaOmDmfsK9XEwNkguP zcvdM?p!zT<=S#8Uqku2E*`wF^d*X|4c0FsM{J;k{Aa8-?mz6XK0+2F^dvu%Mk$B;w zr|SHznyPzs`Zl=vs=Ck!8hsQn_~F^bjuL?Y9KTnv!XPX)f?!}py$P)NN=X$48{*T7 ziu#<2#*7NEX($XXF=YPXN9$!y%2}XMFv%p{q-Xi<087#*ONvY0r!YcM;4Jl-ViGv= zn1dbCFI7@VXXQl173C@EN&1G3=v{!x2X|sLw+OD%rM-FKl{rg{W8s@XP5_~`z#X0m*MR`|hT3H~A#vL_110ERh17X$ literal 0 HcmV?d00001 diff --git a/language/diem-framework/releases/artifacts/current/modules/058_FullnodeSubsidy.mv b/language/diem-framework/releases/artifacts/current/modules/058_FullnodeSubsidy.mv new file mode 100644 index 0000000000000000000000000000000000000000..ec5adb8bb4bb69c23ff77b9cf3b15ac79de0ded3 GIT binary patch literal 488 zcmY+B&rSj{5XNVwf0peo0^uN06XU_NR}LN|8a;X90h)y^+Jt4vwqST1-@!-Fx9|;o z2?s=?P18)~`}&*a>+9K9MgWi^9MMrKjxXi4R5w>i{ei7F>gsnIBg%`@a3j`TQ_c0mW>O+1$pOPm2HpFbXu<#(QNDSCPY_>htb$P`h{!8 zv54-p^dUBWvWm{m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cu7hz$vix@F ziHL(-ky7vl9CYL<{Rvblyl~oQwJ&6MVJOD9nw2I+^5IvA&w11%pS)g zPGb6mJ?}-F4t*CKeEFi^agF`^Yi(CLI(hR0z1x*OK-g)?!QE` zADkbF_Y?h#`+o-m`6hVH(20Np6kK4y!2=%x5Dn?EZxSfi7BcDexe?-1A^?MG+WW?W4~%q6x_B z!~?aB4E!AgrZFpi?_gypv?+uaV9Xf)+`>+n)2SkGW5Fz+o zWYoWhxcZ}^3q8B??{5(BKDO3RY@uTd@F}jC=LbPB2-br2z~PbtMIo4#l(gR{B%{0k|N(r_nXqN-DaBB{%%tj&*S5}?!%_cdyk6J>`tepsVY;k$7a&(hmTV;-%XOD z$!lTPk6MIw`Qo^$&73`16v<3JO<$Sm^CHdbdw2U!n=H$Vsd>>%s&snnJt;skO>wtz}%NMdjnv z>p0CTjpU=)4nA7MRh8!Z!J?^V(Iid|1})#Hs^hYbCU_bG^f0(SoR2JvI-O(USv#?% zSI?@EYt&}ZNt`83hNJE38znQ797J^)=hYs@nmnE$Jz>L|JS&oeQI!=((NUabs9NTq zmg&OphPG~9O_uJb7{^->^Ldk}_3=rzYNg8& zEjv}G$pIb~dqCPs@%B3V!3zn1f64t-4-ry(<0VLx@?8Z&P^)Wx`p%}dxY*1 zFBmGk4as<~^XaJ``XHEKx<~$x6#}u>Es&9N#^jXlb;{X_IJ*y7A3=z6vt1jD+q;x+a_3Bhc|$X18aQ(V!pds%pw=r+5F zx{(an?LY=$K<}{oJzvluOqQt87L*JoT z;@VUG%hB1PA-zrfKZh6V>&~zo9cIGuZQ*OC*qBJic2A#|F3$7U&T~0L9HR#QTc=!( z4TKjmP5AGfdO4;gs)HxxkIvA}Mqi*0*k{P(qQ1oc>`Y3jF}{%@M<%X=k0H2g0u<4g d(eny+4iwc_@fjuh8fvcVZInBqWqQMb{{WvacZ&c3 literal 0 HcmV?d00001 diff --git a/language/diem-framework/releases/artifacts/current/modules/059_Migrations.mv b/language/diem-framework/releases/artifacts/current/modules/061_Migrations.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/059_Migrations.mv rename to language/diem-framework/releases/artifacts/current/modules/061_Migrations.mv diff --git a/language/diem-framework/releases/artifacts/current/modules/060_DiemBlock.mv b/language/diem-framework/releases/artifacts/current/modules/062_DiemBlock.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/060_DiemBlock.mv rename to language/diem-framework/releases/artifacts/current/modules/062_DiemBlock.mv diff --git a/language/diem-framework/releases/artifacts/current/modules/061_DiemConsensusConfig.mv b/language/diem-framework/releases/artifacts/current/modules/063_DiemConsensusConfig.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/061_DiemConsensusConfig.mv rename to language/diem-framework/releases/artifacts/current/modules/063_DiemConsensusConfig.mv diff --git a/language/diem-framework/releases/artifacts/current/modules/062_DiemVMConfig.mv b/language/diem-framework/releases/artifacts/current/modules/064_DiemVMConfig.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/062_DiemVMConfig.mv rename to language/diem-framework/releases/artifacts/current/modules/064_DiemVMConfig.mv diff --git a/language/diem-framework/releases/artifacts/current/modules/064_FullnodeState.mv b/language/diem-framework/releases/artifacts/current/modules/064_FullnodeState.mv deleted file mode 100644 index fb2a6c8d63ff651013da22784c21ff0b48e2819b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1208 zcmb7E+iuh_5FLB$Tx_SCw8{1c5~vSVLGS~-02MqV%6mw6y(MBdS>;mEH$DT2Cw_qc z;1l=*1V6!eFYOk1!I3;ZGtSJJV<%tk{L&l%LI#E#f$=N(_KE+QeZ}CLh}Cy7Fh9g6 z5q%5|?P9<)sv{IyL{fCPs{e59V=?qbwfHw zWkq5Txz?QzU8K!Hm&!|U8+S0p42N|5^q^Gm5MoHVyB-ku4jQIe%u>#sE8NnMD8(Lt zL4`3-6(4FG@QmX>!ng`!#sytiwWlD_CveXzelEErhVDP*M@q{yKi1%_N&eSj8y*3d zR02`K3AN_P=%Xcl#bS|q?t63N2$f98B{y7#%bn10&2cF2F1q!eJ|8T%8H{$Vg0?E);cG zI?No#)M1t>P6o1TRS5ALL={M5`kgR{9EHJchRTFGB!=pEadH7A3n-aFGCWg)3}#A_ VAtD|bs_*N7$~x5~WnKP(egn6W$e#cJ diff --git a/language/diem-framework/releases/artifacts/current/modules/063_DiemVersion.mv b/language/diem-framework/releases/artifacts/current/modules/065_DiemVersion.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/063_DiemVersion.mv rename to language/diem-framework/releases/artifacts/current/modules/065_DiemVersion.mv diff --git a/language/diem-framework/releases/artifacts/current/modules/065_Upgrade.mv b/language/diem-framework/releases/artifacts/current/modules/066_Upgrade.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/065_Upgrade.mv rename to language/diem-framework/releases/artifacts/current/modules/066_Upgrade.mv diff --git a/language/diem-framework/releases/artifacts/current/modules/066_Oracle.mv b/language/diem-framework/releases/artifacts/current/modules/067_Oracle.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/066_Oracle.mv rename to language/diem-framework/releases/artifacts/current/modules/067_Oracle.mv diff --git a/language/diem-framework/releases/artifacts/current/modules/067_Genesis.mv b/language/diem-framework/releases/artifacts/current/modules/068_Genesis.mv similarity index 53% rename from language/diem-framework/releases/artifacts/current/modules/067_Genesis.mv rename to language/diem-framework/releases/artifacts/current/modules/068_Genesis.mv index 53afaa4e8770ce5f235293f45fb7e87feaf68056..2c80c0b31a6e33284704c4d21a08501b48875b6f 100644 GIT binary patch delta 216 zcmWm7yAA zgsNbho~%?(&@E5W)*9Sl1Md1i?ioVHMTFR82o>4Ygg__@rM{;=@bHlHgra0L^5os_ W@wvPxrhP#zX|dm`gN{wH72pql(-{W< delta 263 zcmZqW*uN8w872k*g&-!2 diff --git a/language/diem-framework/releases/artifacts/current/modules/068_MigrateWallets.mv b/language/diem-framework/releases/artifacts/current/modules/069_MigrateWallets.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/068_MigrateWallets.mv rename to language/diem-framework/releases/artifacts/current/modules/069_MigrateWallets.mv diff --git a/language/diem-framework/releases/artifacts/current/modules/069_TestFixtures.mv b/language/diem-framework/releases/artifacts/current/modules/070_TestFixtures.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/069_TestFixtures.mv rename to language/diem-framework/releases/artifacts/current/modules/070_TestFixtures.mv diff --git a/language/diem-framework/releases/artifacts/current/modules/070_MinerStateScripts.mv b/language/diem-framework/releases/artifacts/current/modules/071_MinerStateScripts.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/070_MinerStateScripts.mv rename to language/diem-framework/releases/artifacts/current/modules/071_MinerStateScripts.mv diff --git a/language/diem-framework/releases/artifacts/current/modules/071_OracleScripts.mv b/language/diem-framework/releases/artifacts/current/modules/072_OracleScripts.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/071_OracleScripts.mv rename to language/diem-framework/releases/artifacts/current/modules/072_OracleScripts.mv diff --git a/language/diem-framework/releases/artifacts/current/modules/072_PaymentScripts.mv b/language/diem-framework/releases/artifacts/current/modules/073_PaymentScripts.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/072_PaymentScripts.mv rename to language/diem-framework/releases/artifacts/current/modules/073_PaymentScripts.mv diff --git a/language/diem-framework/releases/artifacts/current/modules/073_PersistenceDemo.mv b/language/diem-framework/releases/artifacts/current/modules/074_PersistenceDemo.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/073_PersistenceDemo.mv rename to language/diem-framework/releases/artifacts/current/modules/074_PersistenceDemo.mv diff --git a/language/diem-framework/releases/artifacts/current/modules/074_SystemAdministrationScripts.mv b/language/diem-framework/releases/artifacts/current/modules/075_SystemAdministrationScripts.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/074_SystemAdministrationScripts.mv rename to language/diem-framework/releases/artifacts/current/modules/075_SystemAdministrationScripts.mv diff --git a/language/diem-framework/releases/artifacts/current/modules/075_TreasuryComplianceScripts.mv b/language/diem-framework/releases/artifacts/current/modules/076_TreasuryComplianceScripts.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/075_TreasuryComplianceScripts.mv rename to language/diem-framework/releases/artifacts/current/modules/076_TreasuryComplianceScripts.mv diff --git a/language/diem-framework/releases/artifacts/current/modules/076_TrustedAccounts.mv b/language/diem-framework/releases/artifacts/current/modules/077_TrustedAccounts.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/076_TrustedAccounts.mv rename to language/diem-framework/releases/artifacts/current/modules/077_TrustedAccounts.mv diff --git a/language/diem-framework/releases/artifacts/current/modules/077_ValidatorAdministrationScripts.mv b/language/diem-framework/releases/artifacts/current/modules/078_ValidatorAdministrationScripts.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/077_ValidatorAdministrationScripts.mv rename to language/diem-framework/releases/artifacts/current/modules/078_ValidatorAdministrationScripts.mv diff --git a/language/diem-framework/releases/artifacts/current/modules/078_ValidatorScripts.mv b/language/diem-framework/releases/artifacts/current/modules/079_ValidatorScripts.mv similarity index 55% rename from language/diem-framework/releases/artifacts/current/modules/078_ValidatorScripts.mv rename to language/diem-framework/releases/artifacts/current/modules/079_ValidatorScripts.mv index a60e3f54b0f31a4a2b426d1a56c32c5eeb8e151b..8ffd04f15a87cf8ada24c2b7b8866e540a18a29e 100644 GIT binary patch delta 237 zcmX|(F>b;@5JhKpXLgKt?Xbp}*p3v3B9S-%RdNEZMF$1QbQW#8C`y-fxdRts+_-sq z|Lf}?WiO|)_>f<`ndCroH&7YA>FfNu*|7tYi2&zn{6GjiA1#hnjJ6o9RJbM1lvRq# zl@|nj42l{Buwi!|nxDT^9=v>f z|1f-S_T8T9YH$DWrreQ6=9}txp>y}TIT#CS=p1lj3;aX~JSvupRmH}|YJr)c7d{6R zPNPG>*-$V?2iUOfz8bAeJYRosw@Q#HVgiquEoKvSR6*$!^jc1~)nlH>kCQQIb;Ao8 rUPjO@FZ)lm#6kb7KDOy4K_pM5=IOr%k6IN7AHgX%fwJR;92MLFSces? diff --git a/language/diem-framework/releases/artifacts/current/modules/079_WalletScripts.mv b/language/diem-framework/releases/artifacts/current/modules/080_WalletScripts.mv similarity index 100% rename from language/diem-framework/releases/artifacts/current/modules/079_WalletScripts.mv rename to language/diem-framework/releases/artifacts/current/modules/080_WalletScripts.mv diff --git a/language/diem-framework/staged/stdlib.mv b/language/diem-framework/staged/stdlib.mv index 16e9091d1c9cd5db1dc12462ab8bd7e4bd79c6eb..43ac79c2d2e880c883e7b3af370f0a1b740b23cc 100644 GIT binary patch delta 6583 zcmb7Idyr&Rc|YHI-FweHeYu)AQUH%|2jRV3&uYz@ic~!|Y7649w1K z=E3g5N@IyZN-9;!HS`};nGnN@C`PlIHHopTD5*+Jz!g$SjIkhnKje(DkXQ%r$cd5X zxcmW+)PL}&xc6J?N$Y<#&gmE9F7tzU)IO2_cp>xUOU=#t)XYkh_O5uj1?qE zQEA3nJd|2}khTD%#0+EYj&ul+&Jd(aSjM_tX$u2Ok0ZUV+tv(7pA*{e$bch*5$c9q z>u?rin-jGiq{c>EvCMLejmBsh%Y%%EAQJ_U$s)*xWkR~Uc8(4?INarF_&W#9lO|NtipD6 zB(E=2lBpB7C&`JMgbrBp@`+-%Qo{3zglzl;g4RFoJ>iQJ$#?4E`9q6)m9q1T^Q+0( zf%fD#R}KXJ{L1uwGYj)`Np`iAyuNZIxpsA8ZjVvKy~_-*h|9%Zu}|z52L$Kh3UQ@4 zC=*<5K8-&lphaS3Q2@2<8#BdlZaKxurlRX(PINV;8-^HgtsQo zufB)clHs)nsg#^s+e_`qD{HsZSZFBXk%)64#lu#H%*c2L_uN1N<^YLO1*t?;U6*+7jle8XfXT3rxuY%1W z7?EG()^*w1i7vxd7!mJIzJK4A);(4lX?WIa33(2qW*7wYB|WElYP?qzR4JsaZ&*dB zj*y5)Xy$|4;_>a=jVU}Ge5;VIV>lik!5D_cmy1ZX8On*GhJmL~tD&rDQ9Y=Ym)6P_ z)bUMq7>~E`EU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pN8L%c`O zzxIotrC*_2h9Y6CkRn7jqa6;(e2FJvW(rz@+X&pe7BI#|#j7%AMg?|l0$e{0w%`9b w+!=W7i=U%k-5d2roUU8U4+xL>;c8%mUpBCi-fyrh;R@F>uI_2y{CT?izur ::std::fmt::Result { diff --git a/language/move-lang/functional-tests/tests/0L/decimal/bonding_calc.move b/language/move-lang/functional-tests/tests/0L/decimal/bonding_calc.move new file mode 100644 index 0000000000..79c2bef022 --- /dev/null +++ b/language/move-lang/functional-tests/tests/0L/decimal/bonding_calc.move @@ -0,0 +1,25 @@ +//! account: alice + +//! new-transaction +//! sender: diemroot +script { + use 0x1::Bonding; + // use 0x1::Debug::print; + + fun main(_diemroot: signer) { + let add_to_reserve = 300; + let reserve = 100; + let supply = 1; + let res = Bonding::deposit_calc(add_to_reserve, reserve, supply); + assert(res == 2, 73501); + + + + let add_to_reserve = 10; + let reserve = 100; + let supply = 10000; + let res = Bonding::deposit_calc(add_to_reserve, reserve, supply); + // print(&res); + assert(res == 10488, 73502); + } +} \ No newline at end of file diff --git a/language/move-lang/functional-tests/tests/0L/decimal/bonding_init.move b/language/move-lang/functional-tests/tests/0L/decimal/bonding_init.move new file mode 100644 index 0000000000..ca9456f7af --- /dev/null +++ b/language/move-lang/functional-tests/tests/0L/decimal/bonding_init.move @@ -0,0 +1,20 @@ +//! account: alices_app + +//! new-transaction +//! sender: alices_app +script { + use 0x1::Bonding; + use 0x1::Signer; + // use 0x1::Debug::print; + + fun main(sender: signer) { + let coin = 10; + let supply = 100; + Bonding::initialize_curve(&sender, coin, supply); + + let addr = Signer::address_of(&sender); + let (reserve, supply) = Bonding::get_curve_state(addr); + assert(reserve == 10, 735701); + assert(supply == 100, 735701); + } +} \ No newline at end of file diff --git a/language/move-lang/functional-tests/tests/0L/decimal/bonding_mint.move b/language/move-lang/functional-tests/tests/0L/decimal/bonding_mint.move new file mode 100644 index 0000000000..4365dcb3fc --- /dev/null +++ b/language/move-lang/functional-tests/tests/0L/decimal/bonding_mint.move @@ -0,0 +1,29 @@ +//! account: alices_app + +//! new-transaction +//! sender: alices_app +script { + use 0x1::Bonding; + use 0x1::Signer; + use 0x1::Debug::print; + + fun main(sender: signer) { + let coin = 10; + let supply = 100; + Bonding::initialize_curve(&sender, coin, supply); + + let addr = Signer::address_of(&sender); + let (reserve, supply) = Bonding::get_curve_state(addr); + assert(reserve == 10, 735701); + assert(supply == 100, 735701); + + Bonding::test_bond_to_mint(&sender, addr, 100); + + let (reserve, supply) = Bonding::get_curve_state(addr); + print(&reserve); + print(&supply); + + assert(reserve == 110, 735701); + assert(supply == 331, 735701); + } +} \ No newline at end of file diff --git a/language/move-lang/functional-tests/tests/0L/decimal/decimal_pair.move b/language/move-lang/functional-tests/tests/0L/decimal/decimal_pair.move new file mode 100644 index 0000000000..0168740254 --- /dev/null +++ b/language/move-lang/functional-tests/tests/0L/decimal/decimal_pair.move @@ -0,0 +1,15 @@ +//! account: alice + +//! new-transaction +//! sender: alice +script { +use 0x1::Decimal; + +fun main(_s: signer) { + // test pair_op function. + let (sign, int, scale) = Decimal::pair_op(1, 0, true, 123, 2, true, 456, 2); + assert(sign, 7357001); + assert(int == 579, 7357002); + assert(scale == 2, 7357003); +} +} diff --git a/language/move-lang/functional-tests/tests/0L/decimal/decimal_pair_math.move b/language/move-lang/functional-tests/tests/0L/decimal/decimal_pair_math.move new file mode 100644 index 0000000000..b0935d9dba --- /dev/null +++ b/language/move-lang/functional-tests/tests/0L/decimal/decimal_pair_math.move @@ -0,0 +1,47 @@ +//! account: alice + +//! new-transaction +//! sender: alice +script { +use 0x1::Decimal; + +fun main(_s: signer) { + let (sign, int, scale) = Decimal::pair_op(1, 0, true, 123, 2, true, 456, 2); + assert(sign, 7357001); + assert(int == 579, 7357002); + assert(scale == 2, 7357003); + + //////// ADD //////// + + let left = Decimal::new(true, 123, 2); + let right = Decimal::new(true, 456, 2); + + let sum = Decimal::add(&left, &right); + assert(Decimal::borrow_int(&sum) == &579, 7357004); + + //////// SUB //////// + + let left = Decimal::new(true, 500, 2); + let right = Decimal::new(true, 200, 2); + + let res = Decimal::sub(&left, &right); + assert(Decimal::borrow_int(&res) == &3, 7357005); + + //////// MULT //////// + + let two = Decimal::new(true, 2, 0); + let mul = Decimal::mul(&two, &two); + assert(Decimal::borrow_int(&mul) == &4, 7357006); + + let neg_one = Decimal::new(false, 1, 0); + let res = Decimal::mul(&two, &neg_one); + assert(Decimal::borrow_int(&res) == &2, 7357007); + assert(Decimal::borrow_sign(&res) == &false, 7357008); + + //////// DIV //////// + + let hundred = Decimal::new(true, 100, 0); + let res = Decimal::div(&hundred, &two); + assert(Decimal::borrow_int(&res) == &50, 7357009); +} +} diff --git a/language/move-lang/functional-tests/tests/0L/decimal/decimal_pair_negatives.move b/language/move-lang/functional-tests/tests/0L/decimal/decimal_pair_negatives.move new file mode 100644 index 0000000000..db5a91f59b --- /dev/null +++ b/language/move-lang/functional-tests/tests/0L/decimal/decimal_pair_negatives.move @@ -0,0 +1,25 @@ +//! account: alice + +//! new-transaction +//! sender: alice +script { +use 0x1::Decimal; + +fun main(_s: signer) { + // MUL + let two = Decimal::new(true, 2, 0); + let neg_one = Decimal::new(false, 1, 0); + let res = Decimal::mul(&two, &neg_one); + assert(Decimal::borrow_sign(&res) == &false, 7357007); + assert(Decimal::borrow_int(&res) == &2, 7357008); + assert(Decimal::borrow_scale(&res) == &0, 7357009); + + let neg_two = Decimal::new(false, 2, 0); + let neg_one = Decimal::new(false, 1, 0); + let res = Decimal::mul(&neg_two, &neg_one); + assert(Decimal::borrow_sign(&res) == &true, 7357007); + assert(Decimal::borrow_int(&res) == &2, 7357008); + assert(Decimal::borrow_scale(&res) == &0, 7357009); + +} +} diff --git a/language/move-lang/functional-tests/tests/0L/decimal/decimal_pair_power.move b/language/move-lang/functional-tests/tests/0L/decimal/decimal_pair_power.move new file mode 100644 index 0000000000..d1b7ce7d30 --- /dev/null +++ b/language/move-lang/functional-tests/tests/0L/decimal/decimal_pair_power.move @@ -0,0 +1,24 @@ +//! account: alice + +//! new-transaction +//! sender: alice +script { +use 0x1::Decimal; + +fun main(_s: signer) { + //////// POWER //////// + let left = Decimal::new(true, 200, 2); + let right = Decimal::new(true, 2, 0); + + let res = Decimal::power(&left, &right); + assert(Decimal::borrow_int(&res) == &4, 7357005); + + + // test negative powers with decimals + let left = Decimal::new(true, 2, 0); + let right = Decimal::new(false, 123, 2); + + let res = Decimal::power(&left, &right); + assert(Decimal::borrow_int(&res) == &4263174467315223084025448727, 7357006); +} +} diff --git a/language/move-lang/functional-tests/tests/0L/decimal/decimal_pair_rescale.move b/language/move-lang/functional-tests/tests/0L/decimal/decimal_pair_rescale.move new file mode 100644 index 0000000000..929678f98f --- /dev/null +++ b/language/move-lang/functional-tests/tests/0L/decimal/decimal_pair_rescale.move @@ -0,0 +1,16 @@ +//! account: alice + +//! new-transaction +//! sender: alice +script { +use 0x1::Decimal; + +fun main(_s: signer) { + //////// RESCALE //////// + let left = Decimal::new(true, 123, 2); + let right = Decimal::new(true, 6, 0); + + let res = Decimal::rescale(&left, &right); + assert(Decimal::borrow_int(&res) == &1230000, 7357007); +} +} diff --git a/language/move-lang/functional-tests/tests/0L/decimal/decimal_round_trip.move b/language/move-lang/functional-tests/tests/0L/decimal/decimal_round_trip.move new file mode 100644 index 0000000000..36f89d96b2 --- /dev/null +++ b/language/move-lang/functional-tests/tests/0L/decimal/decimal_round_trip.move @@ -0,0 +1,13 @@ +//! account: alice + +//! new-transaction +//! sender: alice +script { +use 0x1::Decimal; +fun main(_s: signer) { + let (sign, num, scale) = Decimal::decimal_demo(true, 100, 2); + assert(sign, 7357001); + assert(num == 100, 7357002); + assert(scale == 2, 7357003); +} +} \ No newline at end of file diff --git a/language/move-lang/functional-tests/tests/0L/decimal/decimal_single_irrational.move b/language/move-lang/functional-tests/tests/0L/decimal/decimal_single_irrational.move new file mode 100644 index 0000000000..d5303fc7eb --- /dev/null +++ b/language/move-lang/functional-tests/tests/0L/decimal/decimal_single_irrational.move @@ -0,0 +1,19 @@ +//! account: alice + +//! new-transaction +//! sender: alice +script { +use 0x1::Decimal; + +fun main(_s: signer) { + // Irrational numbers 28 decimal point precision + let three = Decimal::new(true, 3, 0); + let root = Decimal::sqrt(&three); + // assert(Decimal::borrow_int(&root) == &17320508075688772935274463415, 7357008); + + let (sign, int, scale) = Decimal::unwrap(&root); + assert(sign, 7357009); + assert(int == 17320508075688772935274463415, 7357010); + assert(scale == 28, 7357011); +} +} diff --git a/language/move-lang/functional-tests/tests/0L/decimal/decimal_single_sqrt.move b/language/move-lang/functional-tests/tests/0L/decimal/decimal_single_sqrt.move new file mode 100644 index 0000000000..d2f11950b6 --- /dev/null +++ b/language/move-lang/functional-tests/tests/0L/decimal/decimal_single_sqrt.move @@ -0,0 +1,26 @@ +//! account: alice + +//! new-transaction +//! sender: alice +script { +use 0x1::Decimal; + +fun main(_s: signer) { + // do a square root directly with single_op + let (sign, int, scale) = Decimal::single_op(100, true, 100, 0); + + assert(sign, 7357001); + assert(int == 10, 7357002); + assert(scale == 0, 7357003); + + // use sqrt helper + let hundred = Decimal::new(true, 100, 0); + let ten = Decimal::sqrt(&hundred); + assert(Decimal::borrow_int(&ten) == &10, 7357004); + + let (sign, int, scale) = Decimal::unwrap(&ten); + assert(sign, 7357005); + assert(int == 10, 7357006); + assert(scale == 0, 7357007); +} +} diff --git a/language/move-vm/natives/Cargo.toml b/language/move-vm/natives/Cargo.toml index e900c4be08..3a650b3e6f 100644 --- a/language/move-vm/natives/Cargo.toml +++ b/language/move-vm/natives/Cargo.toml @@ -22,11 +22,14 @@ diem-workspace-hack = { path = "../../../common/workspace-hack" } move-core-types = { path = "../../move-core/types" } move-vm-types = { path = "../types" } move-binary-format = { path = "../../move-binary-format" } + ######### 0L ######## diem-global-constants = { path = "../../../config/global-constants"} hex = "0.4.2" diem-types = { path = "../../../types"} vdf = { path="../../../ol/verifiable_delay/vdf"} +rust_decimal= { version = "1.14.2", default-features = true, features = ["maths"] } + [features] default = [] diff --git a/language/move-vm/natives/src/lib.rs b/language/move-vm/natives/src/lib.rs index b88644a7af..9126f98550 100644 --- a/language/move-vm/natives/src/lib.rs +++ b/language/move-vm/natives/src/lib.rs @@ -14,4 +14,5 @@ pub mod signer; pub mod vector; //////// 0L //////// -pub mod vdf; \ No newline at end of file +pub mod vdf; +pub mod ol_decimal; \ No newline at end of file diff --git a/language/move-vm/natives/src/ol_decimal.rs b/language/move-vm/natives/src/ol_decimal.rs new file mode 100644 index 0000000000..ad40856c2b --- /dev/null +++ b/language/move-vm/natives/src/ol_decimal.rs @@ -0,0 +1,272 @@ +//////// 0L //////// +// SPDX-License-Identifier: Apache-2.0 +use move_binary_format::errors::{PartialVMError, PartialVMResult}; +use move_core_types::vm_status::StatusCode; +use move_vm_types::{ + gas_schedule::NativeCostIndex, + loaded_data::runtime_types::Type, + natives::function::{native_gas, NativeContext, NativeResult}, + values::Value, +}; +use rust_decimal::{self, Decimal, MathematicalOps, RoundingStrategy, prelude::ToPrimitive}; +use smallvec::smallvec; +use std::collections::VecDeque; + + +#[derive(Debug)] +struct MoveDecimalType { + sign: bool, + int: u128, + scale: u8, +} + +impl MoveDecimalType { + fn new(scale: u8, int: u128, sign: bool) -> Self { + MoveDecimalType { sign, int, scale } + } + fn into_decimal(&self) -> Decimal { + let scale_right = self.scale as u32; + let mut signed_int_right = self.int as i128; + if !self.sign { + signed_int_right = signed_int_right * -1 + } + + Decimal::from_i128_with_scale(signed_int_right, scale_right) + } + + fn from_decimal(dec: Decimal) -> MoveDecimalType { + MoveDecimalType { + sign: dec.is_sign_positive(), + int: dec.mantissa().abs() as u128, + scale: dec.scale() as u8, + } + } +} + +pub fn native_decimal_demo( + context: &impl NativeContext, + _ty_args: Vec, + mut arguments: VecDeque, +) -> PartialVMResult { + debug_assert!(_ty_args.is_empty()); + debug_assert!(arguments.len() == 3); + + // pop arguments in reverse order + let scale = pop_arg!(arguments, u8); + let int = pop_arg!(arguments, u128); + let sign = pop_arg!(arguments, bool); + + let m = MoveDecimalType::new(scale, int, sign); + let dec = m.into_decimal(); + + let cost = native_gas( + context.cost_table(), + NativeCostIndex::DECIMAL, + m.int.to_be_bytes().len(), + ); + + let new_m = MoveDecimalType::from_decimal(dec); + + Ok(NativeResult::ok( + cost, + smallvec![ + Value::bool(new_m.sign), + Value::u128(new_m.int), + Value::u8(new_m.scale) + ], + )) +} + +pub fn native_decimal_single( + context: &impl NativeContext, + _ty_args: Vec, + mut arguments: VecDeque, +) -> PartialVMResult { + debug_assert!(_ty_args.is_empty()); + debug_assert!(arguments.len() == 4); + + // pop arguments in reverse order + let scale = pop_arg!(arguments, u8); + let int = pop_arg!(arguments, u128); + let sign = pop_arg!(arguments, bool); + let op_id = pop_arg!(arguments, u8); + + + let m = MoveDecimalType::new(scale, int, sign); + let dec = m.into_decimal(); + + let result = match op_id { + 100 => dec.sqrt().unwrap().normalize(), + 101 => dec.trunc(), + _ => return Err(PartialVMError::new(StatusCode::INDEX_OUT_OF_BOUNDS)), + }; + + let cost = native_gas( + context.cost_table(), + NativeCostIndex::DECIMAL, + m.int.to_be_bytes().len(), + ); + + let out = MoveDecimalType::from_decimal(result); + + Ok(NativeResult::ok( + cost, + smallvec![ + Value::bool(out.sign), + Value::u128(out.int), + Value::u8(out.scale) + ], + )) +} + +pub fn native_decimal_pair( + context: &impl NativeContext, + _ty_args: Vec, + mut arguments: VecDeque, +) -> PartialVMResult { + debug_assert!(_ty_args.is_empty()); + debug_assert!(arguments.len() == 8); + + // pop arguments in reverse order + let scale_right = pop_arg!(arguments, u8); + let int_right = pop_arg!(arguments, u128); + let sign_right = pop_arg!(arguments, bool); + + + let m_right = MoveDecimalType::new(scale_right, int_right, sign_right); + let dec_right = m_right.into_decimal(); + + // pop arguments in reverse order + let scale_left = pop_arg!(arguments, u8); + let int_left = pop_arg!(arguments, u128); + let sign_left = pop_arg!(arguments, bool); + + let m_left = MoveDecimalType::new(scale_left, int_left, sign_left); + let mut dec_left = m_left.into_decimal(); + + let strategy = match pop_arg!(arguments, u8) { + 0=> RoundingStrategy::MidpointNearestEven, + 1 => RoundingStrategy::MidpointAwayFromZero, + _ => RoundingStrategy::MidpointNearestEven + + }; + + let op_id = pop_arg!(arguments, u8); + + dbg!(&op_id); + dbg!(&dec_left); + dbg!(&dec_right); + + let result = match op_id { + 0 => { + dec_left.rescale(dec_right.trunc().to_u32().unwrap()); + dec_left + } + 1 => dec_left.checked_add(dec_right).unwrap().normalize(), + 2 => dec_left.checked_sub(dec_right).unwrap().normalize(), + 3 => dec_left.checked_mul(dec_right).unwrap().normalize(), + 4 => dec_left.checked_div(dec_right).unwrap().normalize(), + 5 => { + let pow = dec_right.to_f64().unwrap(); + dec_left.powf(pow).normalize() + }, + 6 => { + // let pow = dec_right.to_f64().unwrap(); + dec_left.round_dp_with_strategy(dec_right.trunc().to_u32().unwrap(), strategy) + }, + _ => return Err(PartialVMError::new(StatusCode::INDEX_OUT_OF_BOUNDS)), + }; + + let out = MoveDecimalType::from_decimal(result); + dbg!(&out); + + let cost = native_gas( + context.cost_table(), + NativeCostIndex::DECIMAL, + m_left.int.to_be_bytes().len(), + ); + + Ok(NativeResult::ok( + cost, + smallvec![ + Value::bool(out.sign), + Value::u128(out.int), + Value::u8(out.scale) + ], + )) +} + +#[test] +fn test_into_dec() { + let m = MoveDecimalType { + sign: true, + int: Decimal::MAX.to_u128().unwrap(), //79228162514264337593543950335 + scale: 0, + }; + + let dec = m.into_decimal(); + + // dbg!(&dec.to_string()); + assert_eq!(dec.to_u128(), Some(m.int)); + + let new_m = MoveDecimalType::from_decimal(dec); + // dbg!(&new_m); + assert_eq!(m.int, new_m.int); + + + let new_dec = new_m.into_decimal(); + // dbg!(&new_dec.to_string()); + assert_eq!(new_dec.to_u128(), Some(m.int)); +} + +#[test] +fn sanity() { + + // let d = Decimal::new(1, 1); + // let d = Decimal::MAX; + let two = Decimal::from_i128_with_scale(2, 0); + + let neg_one = Decimal::from_i128_with_scale(-1, 0); + let res = two.checked_mul(neg_one).unwrap(); + // dbg!(&res); + // dbg!(&res.mantissa()); + + +} + +#[test] +fn test_irrational() { + let m = MoveDecimalType { + sign: true, + int: 3, + scale: 0, + }; + + let dec = m.into_decimal(); + // dbg!(&dec.to_string()); + + let i = dec.sqrt().unwrap().normalize(); + // dbg!(&i.to_string()); + // assert_eq!(dec.to_u128(), Some(m.int)); + + let new_m = MoveDecimalType::from_decimal(i); + // dbg!(&new_m); + // assert_eq!(m.int, new_m.int); + + + // let new_dec = new_m.into_decimal(); + // dbg!(&new_dec.to_string()); + // assert_eq!(new_dec.to_u128(), Some(m.int)); +} + +#[test] +fn test_decimal_power() { + let left = MoveDecimalType::new(2, 200, true).into_decimal(); + let right = MoveDecimalType::new(2, 200, true).into_decimal(); + + let pow = right.to_f64().unwrap(); + let res = left.powf(pow).normalize(); + + let out = MoveDecimalType::from_decimal(res); + assert_eq!(out.int, 4); +} diff --git a/language/move-vm/runtime/src/native_functions.rs b/language/move-vm/runtime/src/native_functions.rs index f70cef918d..7cbfaff63b 100644 --- a/language/move-vm/runtime/src/native_functions.rs +++ b/language/move-vm/runtime/src/native_functions.rs @@ -7,7 +7,7 @@ use move_core_types::{ account_address::AccountAddress, gas_schedule::CostTable, language_storage::CORE_CODE_ADDRESS, value::MoveTypeLayout, vm_status::StatusType, }; -use move_vm_natives::{account, bcs, debug, event, hash, signature, signer, vector, vdf}; +use move_vm_natives::{account, bcs, debug, event, hash, signature, signer, vector, vdf, ol_decimal}; //////// 0L //////// use move_vm_types::{ data_store::DataStore, gas_schedule::GasStatus, @@ -47,7 +47,10 @@ pub(crate) enum NativeFunction { DestroySigner, //////// 0L //////// VDFVerify, - RedeemAuthKeyParse, + RedeemAuthKeyParse, + DecimalDemo, + DecimalSingle, + DecimalPair, } impl NativeFunction { @@ -82,7 +85,11 @@ impl NativeFunction { (&CORE_CODE_ADDRESS, "DiemAccount", "destroy_signer") => DestroySigner, //////// 0L //////// (&CORE_CODE_ADDRESS, "VDF", "verify") => VDFVerify, - (&CORE_CODE_ADDRESS, "VDF", "extract_address_from_challenge") => RedeemAuthKeyParse, + (&CORE_CODE_ADDRESS, "VDF", "extract_address_from_challenge") => RedeemAuthKeyParse, + (&CORE_CODE_ADDRESS, "Decimal", "decimal_demo") => DecimalDemo, + (&CORE_CODE_ADDRESS, "Decimal", "single_op") => DecimalSingle, + (&CORE_CODE_ADDRESS, "Decimal", "pair_op") => DecimalPair, + _ => return None, }) } @@ -118,7 +125,10 @@ impl NativeFunction { Self::DestroySigner => account::native_destroy_signer(ctx, t, v), //////// 0L //////// Self::VDFVerify => vdf::verify(ctx, t, v), - Self::RedeemAuthKeyParse => vdf::extract_address_from_challenge(ctx, t, v), + Self::RedeemAuthKeyParse => vdf::extract_address_from_challenge(ctx, t, v), + Self::DecimalDemo => ol_decimal::native_decimal_demo(ctx, t, v), + Self::DecimalSingle => ol_decimal::native_decimal_single(ctx, t, v), + Self::DecimalPair => ol_decimal::native_decimal_pair(ctx, t, v), }; debug_assert!(match &result { Err(e) => e.major_status().status_type() == StatusType::InvariantViolation, diff --git a/language/move-vm/types/src/gas_schedule.rs b/language/move-vm/types/src/gas_schedule.rs index 01baf4bcbc..a18a10032f 100644 --- a/language/move-vm/types/src/gas_schedule.rs +++ b/language/move-vm/types/src/gas_schedule.rs @@ -317,5 +317,6 @@ pub enum NativeCostIndex { EMIT_EVENT = 17, //////// 0L //////// VDF_VERIFY = 18, - VDF_PARSE = 19, + VDF_PARSE = 19, + DECIMAL = 20, } diff --git a/language/tools/vm-genesis/src/genesis_gas_schedule.rs b/language/tools/vm-genesis/src/genesis_gas_schedule.rs index c3c3f460bf..368c98838d 100644 --- a/language/tools/vm-genesis/src/genesis_gas_schedule.rs +++ b/language/tools/vm-genesis/src/genesis_gas_schedule.rs @@ -145,7 +145,8 @@ pub static INITIAL_GAS_SCHEDULE: Lazy = Lazy::new(|| { (N::EMIT_EVENT, GasCost::new(52, 1)), //////// 0L //////// (N::VDF_VERIFY, GasCost::new(1000000, 1)), // one second of cost. - (N::VDF_PARSE, GasCost::new(100, 1)), + (N::VDF_PARSE, GasCost::new(100, 1)), + (N::DECIMAL, GasCost::new(52, 1)), ]; native_table.sort_by_key(|cost| cost.0 as u64); let raw_native_table = native_table