From d6b3725e0fd8beb376bb64e20bbbc8549732f2b1 Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Wed, 19 Aug 2020 10:01:15 -0700 Subject: [PATCH] [breaking][libra framework] Remove LibraTransactionTimeout module The only purpose of LibraTransactionTimeout was to an enforce upper and lower bounds on transaction expiration time. The lower bound check is very simple to do and the upper bound check is no longer a requirement, so we can kill this module. The PR deletes LibraTransactionTimeout and moves the lower bound check into the transaction prologue. To keep the check simple, it adds a LibraTimestamp::now_seconds function that can be directly compared against the transaction expiration time (which is specified in seconds). This is a breaking change in the sense that it removes the LibraTransactionTimeout module and orphans the TTL resource, but it is not observable to clients and should be deployable via a WriteSet. --- .../libra_transaction_timeout/basic.move | 38 --- .../error_descriptions.errmap | Bin 13403 -> 13299 bytes ...=> 31_LibraTransactionPublishingOption.mv} | Bin .../stdlib/31_LibraTransactionTimeout.mv | Bin 597 -> 0 bytes ...{33_LibraAccount.mv => 32_LibraAccount.mv} | Bin 6947 -> 6902 bytes ...tManager.mv => 33_LibraWriteSetManager.mv} | Bin ...{35_LibraVersion.mv => 34_LibraVersion.mv} | Bin ...6_LibraVMConfig.mv => 35_LibraVMConfig.mv} | Bin .../{37_LibraSystem.mv => 36_LibraSystem.mv} | Bin .../{38_LibraBlock.mv => 37_LibraBlock.mv} | Bin .../stdlib/{39_Genesis.mv => 38_Genesis.mv} | Bin 1135 -> 1100 bytes .../stdlib/{40_Offer.mv => 39_Offer.mv} | Bin ...coveryAddress.mv => 40_RecoveryAddress.mv} | Bin ...licKey.mv => 41_SharedEd25519PublicKey.mv} | Bin .../compiled/stdlib/4_LibraTimestamp.mv | Bin 1027 -> 1066 bytes language/stdlib/modules/Genesis.move | 2 - language/stdlib/modules/LibraAccount.move | 5 +- language/stdlib/modules/LibraTimestamp.move | 19 +- .../modules/LibraTransactionTimeout.move | 67 ------ language/stdlib/modules/doc/Genesis.md | 1 - language/stdlib/modules/doc/LibraAccount.md | 6 +- language/stdlib/modules/doc/LibraTimestamp.md | 75 +++++- .../modules/doc/LibraTransactionTimeout.md | 222 ------------------ 23 files changed, 93 insertions(+), 342 deletions(-) delete mode 100644 language/move-lang/functional-tests/tests/libra_transaction_timeout/basic.move rename language/stdlib/compiled/stdlib/{32_LibraTransactionPublishingOption.mv => 31_LibraTransactionPublishingOption.mv} (100%) delete mode 100644 language/stdlib/compiled/stdlib/31_LibraTransactionTimeout.mv rename language/stdlib/compiled/stdlib/{33_LibraAccount.mv => 32_LibraAccount.mv} (60%) rename language/stdlib/compiled/stdlib/{34_LibraWriteSetManager.mv => 33_LibraWriteSetManager.mv} (100%) rename language/stdlib/compiled/stdlib/{35_LibraVersion.mv => 34_LibraVersion.mv} (100%) rename language/stdlib/compiled/stdlib/{36_LibraVMConfig.mv => 35_LibraVMConfig.mv} (100%) rename language/stdlib/compiled/stdlib/{37_LibraSystem.mv => 36_LibraSystem.mv} (100%) rename language/stdlib/compiled/stdlib/{38_LibraBlock.mv => 37_LibraBlock.mv} (100%) rename language/stdlib/compiled/stdlib/{39_Genesis.mv => 38_Genesis.mv} (58%) rename language/stdlib/compiled/stdlib/{40_Offer.mv => 39_Offer.mv} (100%) rename language/stdlib/compiled/stdlib/{41_RecoveryAddress.mv => 40_RecoveryAddress.mv} (100%) rename language/stdlib/compiled/stdlib/{42_SharedEd25519PublicKey.mv => 41_SharedEd25519PublicKey.mv} (100%) delete mode 100644 language/stdlib/modules/LibraTransactionTimeout.move delete mode 100644 language/stdlib/modules/doc/LibraTransactionTimeout.md diff --git a/language/move-lang/functional-tests/tests/libra_transaction_timeout/basic.move b/language/move-lang/functional-tests/tests/libra_transaction_timeout/basic.move deleted file mode 100644 index 3ca170de8890..000000000000 --- a/language/move-lang/functional-tests/tests/libra_transaction_timeout/basic.move +++ /dev/null @@ -1,38 +0,0 @@ -//! new-transaction -script { - use 0x1::LibraTransactionTimeout; - fun main(account: &signer) { - LibraTransactionTimeout::initialize(account); - } -} -// check: ABORTED -// check: 1 - -//! new-transaction -script { - use 0x1::LibraTransactionTimeout; - fun main(account: &signer) { - LibraTransactionTimeout::set_timeout(account, 0); - } -} -// check: ABORTED -// check: 3 - -//! new-transaction -script { - use 0x1::LibraTransactionTimeout; - fun main(account: &signer) { - LibraTransactionTimeout::set_timeout(account, 0); - } -} -// check: ABORTED -// check: 3 - -//! new-transaction -//! sender: libraroot -script { - use 0x1::LibraTransactionTimeout; - fun main(account: &signer) { - LibraTransactionTimeout::set_timeout(account, 86400000000); - } -} diff --git a/language/stdlib/compiled/error_descriptions/error_descriptions.errmap b/language/stdlib/compiled/error_descriptions/error_descriptions.errmap index eca6e2a168e543b3e284cc9108d59fb1b25c88d7..fc2aad964f534275ee613057fda9a5418e7ec150 100644 GIT binary patch delta 19 acmcbe@i~11J1e8yW)9Ycx|;=!y%+&ZR0c@^ delta 68 zcmeyIemi3WJ1e97W)9Ycx&}U(NkxevMTvREiOD6I`FSCkxvBZ3C5#MEz~UMb;$x@~ Rl98&A0AwX>E;MRl1ON_z6zl*1 diff --git a/language/stdlib/compiled/stdlib/32_LibraTransactionPublishingOption.mv b/language/stdlib/compiled/stdlib/31_LibraTransactionPublishingOption.mv similarity index 100% rename from language/stdlib/compiled/stdlib/32_LibraTransactionPublishingOption.mv rename to language/stdlib/compiled/stdlib/31_LibraTransactionPublishingOption.mv diff --git a/language/stdlib/compiled/stdlib/31_LibraTransactionTimeout.mv b/language/stdlib/compiled/stdlib/31_LibraTransactionTimeout.mv deleted file mode 100644 index a6bd05930bcdbff14d6d23f976ef1a203c01f66c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 597 zcmY*XOKub~5Uq0cFYcb6b~NE5K0+cA5X71-6EX{=ks?icP1BjSf~B7J$o3GyiY=!A zq+Ee3a0QOQ0XpmouXlgt2ml;`Gaga-Jf7W7Uw>lRPgW)8>@ojL zadAc;adZ|jpNPPKAcEK*l7LfWfEgjs7JA2n3zAXbpa^b+5kTpSVC>6~0AoxFM3xl9 zkb+^F!OgikHf?R%!M01M^iZpn)EhT?sg0a=osrf`o6L;S#+HAReTH@IY8@|hFD=#e zT(rHBZTG%eZ;pFq-^y-#{%U_QZ5D@zbu&FUSj>)&MC+xDYx>Z!F zr`rU1J^Ux_pY>lu%B~<~zrTGs|6T!5_F{j0LHp>NANMBV%&?*qA(;r`AehJ=q#&SR z1?EWO9582(a!6?#o&ocsNCKY#3yVwdh=@aqyOhM)787xS0-r(!lY(*N><0QMyH)rF ab9(40ge(_P4k8h_=X-E3K8Bs}NB#f{7I|?1 diff --git a/language/stdlib/compiled/stdlib/33_LibraAccount.mv b/language/stdlib/compiled/stdlib/32_LibraAccount.mv similarity index 60% rename from language/stdlib/compiled/stdlib/33_LibraAccount.mv rename to language/stdlib/compiled/stdlib/32_LibraAccount.mv index 0a269ade5ecff9ba4fd6fdecd44a7cb73b047279..6e3dbe659b659dee4311788a716a2ddd863bc9ff 100644 GIT binary patch delta 1297 zcmZ9L%Wqpn6vofFbLZOk&e-wTu@gU%jN?3=hnNEfI=6rXTcr`u|;fY+R!Jy3`ZnXFiaEK2(bSfE?4Mq$`3F)zrjhG$}GsH;6^$@*DVf#IJEt@)u z95HpQl|$+&Bpjz{Qzyuj^1s8vPV$r@YwI)ZHmGMiG@@F~lb}v_l1)9Q3y3Wy*t|xT z*z+_+>`WI2IBUwndN<|5IWXKn58yn~2=GFW;fpjkEXGXi0=*F7B0Uk|rGAnx1;@*{ zQv}!?AYp5eP&c?jQ^LyzOG74qyGY_I!{+#^QD1`+z*Q&%ygp*YYr!OMm}b{U>C?YC zMyI#NP3Y~4;m(BN4Gg4rutec^u}pjqCwFLjAFC$eCL#m4g$IbYamqaJ1DvM#E(U#; zXH3?IfpiCFsnbVzP?7X8&e6807i)|2iwgx^)KBO>-KAIbAw8gHOS9!keNlJl9^I{5 zmagandb%`Sep(Odc3nzgb5pYEVEJIFb*c5px~}V9y`*PKGv!rXuhr*Q76x^FVWqY* z-*QCj{>EL#S>tPGAEnsby1KT#vA(r=Zo6?P+{GHVMF&6q35LUH;awCix?ov&4>_}( z4bR#`5y7zYX|P#7iV%kF`@zO~0kXrM^%?Td(X;r!_x*qF4wdqm+Q6uPLH#V6 z1Vn8$LM!br$Frfd2T`tK{#HEsWL0ossWodEp%_t~2kMx#qLy-_hBaXcr07wKraYt= z549 z*UPDsQVPl9p@_L;w2X=<%Y=Y#MJ8S9o%ijQ>q1G77i30c*rmp9OBT+N6U;XOV(nwyswhH$Z~8sUJ7FlCLs`42yrm7V}s)*imikt zfLTIV90Fztao|8v{0TmDO~C;u4p4BUid(8UQBa)VwI~V>{d@hs_rC7eQ#HRAKOdR+ zEOlQX00a<5w2?B~`BT^L^ELjRaZmT%5x+&u{Y=>SB=Z$ozsO~AFKgQ0WdDi;zAiQd ze?FKPO+u3FDMW;{I)_%X29Tj84{oLQTvtPE$dcaB0vh;R83TWtLc2nTLMOrK(h-bq zg&xo$)TUrlIEUCHNH|5)#vUbS%=-dc_ZrVSu~Tt_9*eNqP4ZTk zzDN6Q>;bscOG34ea9Lr8MulC4xqj7O>ml(4U=LeMdLVc2J>arIH z>HEJlM7x)VRcWuN_zI4w@G91|*Dz1@*Rili;X0OxZ{VnExPiz3-o#_Xw{T3o?`<5X z`a4*^=;5;J+OJDDae}UT7mqt6-NH!xF6(QIRx=JnmB ztCh|53rn^C+Lmh6w_B@hRgcb!3_t%KnkH)aJ_47gWDi=}9pr~-Y5d>(?mxLfM|t0eS25s?J3on_fS~RaXvMvZoAkvk z2y!RnO}kMnd1u^o@1)QKI!oFKgq}tVos%}N_k@EKoq-@1Aed7kSKRy5O%&~V52JIL zGf68hn9#_7iu~bvO((zZxa!WJUUwh&esyC}=YPsEq1RoHdF4pjD@BGd;cY}#Fn{!I zWFIl-or{(+OgZe#QZ#EF*4=7j}wc312N^hBLDyZ diff --git a/language/stdlib/compiled/stdlib/34_LibraWriteSetManager.mv b/language/stdlib/compiled/stdlib/33_LibraWriteSetManager.mv similarity index 100% rename from language/stdlib/compiled/stdlib/34_LibraWriteSetManager.mv rename to language/stdlib/compiled/stdlib/33_LibraWriteSetManager.mv diff --git a/language/stdlib/compiled/stdlib/35_LibraVersion.mv b/language/stdlib/compiled/stdlib/34_LibraVersion.mv similarity index 100% rename from language/stdlib/compiled/stdlib/35_LibraVersion.mv rename to language/stdlib/compiled/stdlib/34_LibraVersion.mv diff --git a/language/stdlib/compiled/stdlib/36_LibraVMConfig.mv b/language/stdlib/compiled/stdlib/35_LibraVMConfig.mv similarity index 100% rename from language/stdlib/compiled/stdlib/36_LibraVMConfig.mv rename to language/stdlib/compiled/stdlib/35_LibraVMConfig.mv diff --git a/language/stdlib/compiled/stdlib/37_LibraSystem.mv b/language/stdlib/compiled/stdlib/36_LibraSystem.mv similarity index 100% rename from language/stdlib/compiled/stdlib/37_LibraSystem.mv rename to language/stdlib/compiled/stdlib/36_LibraSystem.mv diff --git a/language/stdlib/compiled/stdlib/38_LibraBlock.mv b/language/stdlib/compiled/stdlib/37_LibraBlock.mv similarity index 100% rename from language/stdlib/compiled/stdlib/38_LibraBlock.mv rename to language/stdlib/compiled/stdlib/37_LibraBlock.mv diff --git a/language/stdlib/compiled/stdlib/39_Genesis.mv b/language/stdlib/compiled/stdlib/38_Genesis.mv similarity index 58% rename from language/stdlib/compiled/stdlib/39_Genesis.mv rename to language/stdlib/compiled/stdlib/38_Genesis.mv index 8db6ca79c507dec44ee934c81428b7f75bad658b..f5de67a8fa15ecd65d01d031f8a41a1612919012 100644 GIT binary patch delta 316 zcmW-WJx;?w5QX22?e*@g<9K5`n;-L+G%13_1?Xux1m~cpv^W6`7vKa`2nmUnBOoC` zNdpqI6yG=R&HJ)1c6T>?cmiMvd*0{S*+|7BU6eQcn%g(in0M1vKjwbionE_v(9S`a zL@*``)ohux${1#?iPFF^XZVzCQWka1lloN4l!}zPln%;g1mjl)ywzeD7>6f=_V~JzidWpG}*)+xf%t{abv9U<4#r zFB|W?>1kN#*mg9uux+xWt4qHbF(CRxN(>1{2qI5(svRzZ)hT089}>A M&Hrv}VPK`iA3Ms_<<^bfQeCpnURT6a`Hr` v{R#|>EP{OOEK*DYj6lFC$fC)}%)-hc$fCn2%*eGI9#CXfiUhuyP2p=r9U1 SGBOEF?q+sk6r6mHIR*g#ZWS~D diff --git a/language/stdlib/modules/Genesis.move b/language/stdlib/modules/Genesis.move index 4efcaca1e9fd..308b0a3ca0a3 100644 --- a/language/stdlib/modules/Genesis.move +++ b/language/stdlib/modules/Genesis.move @@ -19,7 +19,6 @@ module Genesis { use 0x1::LibraSystem; use 0x1::LibraTimestamp; use 0x1::LibraTransactionPublishingOption; - use 0x1::LibraTransactionTimeout; use 0x1::LibraVersion; use 0x1::LibraWriteSetManager; use 0x1::Signer; @@ -82,7 +81,6 @@ module Genesis { copy dummy_auth_key_prefix, ); - LibraTransactionTimeout::initialize(lr_account); LibraSystem::initialize_validator_set( lr_account, ); diff --git a/language/stdlib/modules/LibraAccount.move b/language/stdlib/modules/LibraAccount.move index 6dd2f63e0123..05f67ca04571 100644 --- a/language/stdlib/modules/LibraAccount.move +++ b/language/stdlib/modules/LibraAccount.move @@ -16,7 +16,6 @@ module LibraAccount { use 0x1::LCS; use 0x1::LibraTimestamp; use 0x1::LibraTransactionPublishingOption; - use 0x1::LibraTransactionTimeout; use 0x1::Signer; use 0x1::SlidingNonce; use 0x1::TransactionFee; @@ -924,7 +923,7 @@ module LibraAccount { txn_public_key: vector, txn_gas_price: u64, txn_max_gas_units: u64, - txn_expiration_time: u64, + txn_expiration_time_seconds: u64, chain_id: u8, ) acquires LibraAccount, Balance { let transaction_sender = Signer::address_of(sender); @@ -973,7 +972,7 @@ module LibraAccount { PROLOGUE_ESEQUENCE_NUMBER_TOO_NEW ); assert( - LibraTransactionTimeout::is_valid_transaction_timestamp(txn_expiration_time), + LibraTimestamp::now_seconds() < txn_expiration_time_seconds, PROLOGUE_ETRANSACTION_EXPIRED ); } diff --git a/language/stdlib/modules/LibraTimestamp.move b/language/stdlib/modules/LibraTimestamp.move index 0df8d7cb38b9..59d7904f9662 100644 --- a/language/stdlib/modules/LibraTimestamp.move +++ b/language/stdlib/modules/LibraTimestamp.move @@ -8,7 +8,6 @@ address 0x1 { /// * LibraSystem, LibraAccount, LibraConfig: to check if the current state is in the genesis state /// * LibraBlock: to reach consensus on the global wall clock time /// * AccountLimits: to limit the time of account limits -/// * LibraTransactionTimeout: to determine whether a transaction is still valid /// module LibraTimestamp { use 0x1::CoreAddresses; @@ -23,6 +22,9 @@ module LibraTimestamp { /// is called at the end of genesis. resource struct TimeHasStarted {} + /// Conversion factor between seconds and microseconds + const MICRO_CONVERSION_FACTOR: u64 = 1000000; + /// The blockchain is not in the genesis state anymore const ENOT_GENESIS: u64 = 0; /// The blockchain is not in an operating state yet @@ -151,7 +153,7 @@ module LibraTimestamp { } - /// Gets the timestamp representing `now` in microseconds. + /// Gets the current time in microseconds. public fun now_microseconds(): u64 acquires CurrentTimeMicroseconds { assert( exists(CoreAddresses::LIBRA_ROOT_ADDRESS()), @@ -168,6 +170,19 @@ module LibraTimestamp { global(CoreAddresses::LIBRA_ROOT_ADDRESS()).microseconds } + /// Gets the current time in seconds. + public fun now_seconds(): u64 acquires CurrentTimeMicroseconds { + now_microseconds() / MICRO_CONVERSION_FACTOR + } + spec fun now_seconds { + pragma opaque; + include AbortsIfNoTime; + ensures result == spec_now_microseconds() * MICRO_CONVERSION_FACTOR; + } + spec define spec_now_seconds(): u64 { + global(CoreAddresses::LIBRA_ROOT_ADDRESS()).microseconds * MICRO_CONVERSION_FACTOR + } + /// Schema specifying that a function aborts if the timer is not published. spec schema AbortsIfNoTime { aborts_if !spec_timer_initialized() with Errors::NOT_PUBLISHED; diff --git a/language/stdlib/modules/LibraTransactionTimeout.move b/language/stdlib/modules/LibraTransactionTimeout.move deleted file mode 100644 index a9da29a860f4..000000000000 --- a/language/stdlib/modules/LibraTransactionTimeout.move +++ /dev/null @@ -1,67 +0,0 @@ -address 0x1 { - -module LibraTransactionTimeout { - use 0x1::CoreAddresses; - use 0x1::Errors; - use 0x1::LibraTimestamp; - use 0x1::Roles; - - resource struct TTL { - // Only transactions with timestamp in between block time and block time + duration would be accepted. - duration_microseconds: u64, - } - - spec module { - invariant [global] LibraTimestamp::is_operating() ==> is_initialized(); - } - - // U64_MAX / 1_000_000 - const MAX_TIMESTAMP: u64 = 18446744073709551615 / 1000000; - const MICROS_MULTIPLIER: u64 = 1000000; - const ONE_DAY_MICROS: u64 = 86400000000; - - /// The `TTL` resource was not in the required state - const ETTL: u64 = 0; - - public fun initialize(lr_account: &signer) { - LibraTimestamp::assert_genesis(); - // Operational constraint, only callable by the libra root account - CoreAddresses::assert_libra_root(lr_account); - assert(!is_initialized(), Errors::already_published(ETTL)); - // Currently set to 1day. - move_to(lr_account, TTL {duration_microseconds: ONE_DAY_MICROS}); - } - - fun is_initialized(): bool { - exists(CoreAddresses::LIBRA_ROOT_ADDRESS()) - } - - // TODO (dd): is this called anywhere? - public fun set_timeout(lr_account: &signer, new_duration: u64) acquires TTL { - LibraTimestamp::assert_operating(); - Roles::assert_libra_root(lr_account); - let timeout = borrow_global_mut(CoreAddresses::LIBRA_ROOT_ADDRESS()); - timeout.duration_microseconds = new_duration; - } - - public fun is_valid_transaction_timestamp(timestamp: u64): bool acquires TTL { - LibraTimestamp::assert_operating(); - // Reject timestamp greater than u64::MAX / 1_000_000. - // This allows converting the timestamp from seconds to microseconds. - if (timestamp > MAX_TIMESTAMP) { - return false - }; - - let current_block_time = LibraTimestamp::now_microseconds(); - let timeout = borrow_global(CoreAddresses::LIBRA_ROOT_ADDRESS()).duration_microseconds; - let _max_txn_time = current_block_time + timeout; - - let txn_time_microseconds = timestamp * MICROS_MULTIPLIER; - // TODO: Add LibraTimestamp::is_before_exclusive(&txn_time_microseconds, &max_txn_time) - // This is causing flaky test right now. The reason is that we will use this logic for AC, where its wall - // clock time might be out of sync with the real block time stored in StateStore. - // See details in issue #2346. - current_block_time < txn_time_microseconds - } -} -} diff --git a/language/stdlib/modules/doc/Genesis.md b/language/stdlib/modules/doc/Genesis.md index 16404422615d..3ec7d8045a88 100644 --- a/language/stdlib/modules/doc/Genesis.md +++ b/language/stdlib/modules/doc/Genesis.md @@ -79,7 +79,6 @@ copy dummy_auth_key_prefix, ); - LibraTransactionTimeout::initialize(lr_account); LibraSystem::initialize_validator_set( lr_account, ); diff --git a/language/stdlib/modules/doc/LibraAccount.md b/language/stdlib/modules/doc/LibraAccount.md index 143b0bd73b0e..819a33f5c826 100644 --- a/language/stdlib/modules/doc/LibraAccount.md +++ b/language/stdlib/modules/doc/LibraAccount.md @@ -2247,7 +2247,7 @@ It verifies: - That the sequence number matches the transaction's sequence key -
fun prologue_common<Token>(sender: &signer, txn_sequence_number: u64, txn_public_key: vector<u8>, txn_gas_price: u64, txn_max_gas_units: u64, txn_expiration_time: u64, chain_id: u8)
+
fun prologue_common<Token>(sender: &signer, txn_sequence_number: u64, txn_public_key: vector<u8>, txn_gas_price: u64, txn_max_gas_units: u64, txn_expiration_time_seconds: u64, chain_id: u8)
 
@@ -2262,7 +2262,7 @@ It verifies: txn_public_key: vector<u8>, txn_gas_price: u64, txn_max_gas_units: u64, - txn_expiration_time: u64, + txn_expiration_time_seconds: u64, chain_id: u8, ) acquires LibraAccount, Balance { let transaction_sender = Signer::address_of(sender); @@ -2311,7 +2311,7 @@ It verifies: PROLOGUE_ESEQUENCE_NUMBER_TOO_NEW ); assert( - LibraTransactionTimeout::is_valid_transaction_timestamp(txn_expiration_time), + LibraTimestamp::now_seconds() < txn_expiration_time_seconds, PROLOGUE_ETRANSACTION_EXPIRED ); } diff --git a/language/stdlib/modules/doc/LibraTimestamp.md b/language/stdlib/modules/doc/LibraTimestamp.md index 695f36007e52..fb954082ee28 100644 --- a/language/stdlib/modules/doc/LibraTimestamp.md +++ b/language/stdlib/modules/doc/LibraTimestamp.md @@ -7,6 +7,7 @@ - [Resource `CurrentTimeMicroseconds`](#0x1_LibraTimestamp_CurrentTimeMicroseconds) - [Resource `TimeHasStarted`](#0x1_LibraTimestamp_TimeHasStarted) +- [Const `MICRO_CONVERSION_FACTOR`](#0x1_LibraTimestamp_MICRO_CONVERSION_FACTOR) - [Const `ENOT_GENESIS`](#0x1_LibraTimestamp_ENOT_GENESIS) - [Const `ENOT_OPERATING`](#0x1_LibraTimestamp_ENOT_OPERATING) - [Const `ETIMER_RESOURCE`](#0x1_LibraTimestamp_ETIMER_RESOURCE) @@ -16,6 +17,7 @@ - [Function `reset_time_has_started_for_test`](#0x1_LibraTimestamp_reset_time_has_started_for_test) - [Function `update_global_time`](#0x1_LibraTimestamp_update_global_time) - [Function `now_microseconds`](#0x1_LibraTimestamp_now_microseconds) +- [Function `now_seconds`](#0x1_LibraTimestamp_now_seconds) - [Function `is_genesis`](#0x1_LibraTimestamp_is_genesis) - [Function `assert_genesis`](#0x1_LibraTimestamp_assert_genesis) - [Function `is_operating`](#0x1_LibraTimestamp_is_operating) @@ -26,6 +28,7 @@ - [Function `set_time_has_started`](#0x1_LibraTimestamp_Specification_set_time_has_started) - [Function `update_global_time`](#0x1_LibraTimestamp_Specification_update_global_time) - [Function `now_microseconds`](#0x1_LibraTimestamp_Specification_now_microseconds) + - [Function `now_seconds`](#0x1_LibraTimestamp_Specification_now_seconds) - [Function `assert_genesis`](#0x1_LibraTimestamp_Specification_assert_genesis) - [Function `assert_operating`](#0x1_LibraTimestamp_Specification_assert_operating) @@ -37,7 +40,6 @@ It interacts with the other modules in the following ways: * LibraSystem, LibraAccount, LibraConfig: to check if the current state is in the genesis state * LibraBlock: to reach consensus on the global wall clock time * AccountLimits: to limit the time of account limits -* LibraTransactionTimeout: to determine whether a transaction is still valid @@ -99,6 +101,18 @@ is called at the end of genesis. + + +## Const `MICRO_CONVERSION_FACTOR` + +Conversion factor between seconds and microseconds + + +
const MICRO_CONVERSION_FACTOR: u64 = 1000000;
+
+ + + ## Const `ENOT_GENESIS` @@ -293,8 +307,7 @@ Updates the wall clock time by consensus. Requires VM privilege and will be invo ## Function `now_microseconds` -Gets the timestamp representing -now in microseconds. +Gets the current time in microseconds.
public fun now_microseconds(): u64
@@ -317,6 +330,31 @@ Gets the timestamp representing
 
 
 
+
+
+
+
+## Function `now_seconds`
+
+Gets the current time in seconds.
+
+
+
public fun now_seconds(): u64
+
+ + + +
+Implementation + + +
public fun now_seconds(): u64 acquires CurrentTimeMicroseconds {
+    now_microseconds() / MICRO_CONVERSION_FACTOR
+}
+
+ + +
@@ -558,7 +596,7 @@ these assertions verify.
include AbortsIfNotOperating;
 include CoreAddresses::AbortsIfNotVM;
-
+
 let now = old(spec_now_microseconds());
 aborts_if [assume]
     (if (proposer == CoreAddresses::VM_RESERVED_ADDRESS()) {
@@ -601,6 +639,35 @@ these assertions verify.
 
+ + + +### Function `now_seconds` + + +
public fun now_seconds(): u64
+
+ + + + +
pragma opaque;
+include AbortsIfNoTime;
+ensures result == spec_now_microseconds() *  MICRO_CONVERSION_FACTOR;
+
+ + + + + + + +
define spec_now_seconds(): u64 {
+global<CurrentTimeMicroseconds>(CoreAddresses::LIBRA_ROOT_ADDRESS()).microseconds * MICRO_CONVERSION_FACTOR
+}
+
+ + Schema specifying that a function aborts if the timer is not published. diff --git a/language/stdlib/modules/doc/LibraTransactionTimeout.md b/language/stdlib/modules/doc/LibraTransactionTimeout.md deleted file mode 100644 index 5b387315bc9d..000000000000 --- a/language/stdlib/modules/doc/LibraTransactionTimeout.md +++ /dev/null @@ -1,222 +0,0 @@ - - - -# Module `0x1::LibraTransactionTimeout` - -### Table of Contents - -- [Resource `TTL`](#0x1_LibraTransactionTimeout_TTL) -- [Const `MAX_TIMESTAMP`](#0x1_LibraTransactionTimeout_MAX_TIMESTAMP) -- [Const `MICROS_MULTIPLIER`](#0x1_LibraTransactionTimeout_MICROS_MULTIPLIER) -- [Const `ONE_DAY_MICROS`](#0x1_LibraTransactionTimeout_ONE_DAY_MICROS) -- [Const `ETTL`](#0x1_LibraTransactionTimeout_ETTL) -- [Function `initialize`](#0x1_LibraTransactionTimeout_initialize) -- [Function `is_initialized`](#0x1_LibraTransactionTimeout_is_initialized) -- [Function `set_timeout`](#0x1_LibraTransactionTimeout_set_timeout) -- [Function `is_valid_transaction_timestamp`](#0x1_LibraTransactionTimeout_is_valid_transaction_timestamp) -- [Specification](#0x1_LibraTransactionTimeout_Specification) - - - - - -## Resource `TTL` - - - -
resource struct TTL
-
- - - -
-Fields - - -
-
- -duration_microseconds: u64 -
-
- -
-
- - -
- - - -## Const `MAX_TIMESTAMP` - - - -
const MAX_TIMESTAMP: u64 = 18446744073709;
-
- - - - - -## Const `MICROS_MULTIPLIER` - - - -
const MICROS_MULTIPLIER: u64 = 1000000;
-
- - - - - -## Const `ONE_DAY_MICROS` - - - -
const ONE_DAY_MICROS: u64 = 86400000000;
-
- - - - - -## Const `ETTL` - -The -TTL resource was not in the required state - - -
const ETTL: u64 = 0;
-
- - - - - -## Function `initialize` - - - -
public fun initialize(lr_account: &signer)
-
- - - -
-Implementation - - -
public fun initialize(lr_account: &signer) {
-    LibraTimestamp::assert_genesis();
-    // Operational constraint, only callable by the libra root account
-    CoreAddresses::assert_libra_root(lr_account);
-    assert(!is_initialized(), Errors::already_published(ETTL));
-    // Currently set to 1day.
-    move_to(lr_account, TTL {duration_microseconds: ONE_DAY_MICROS});
-}
-
- - - -
- - - -## Function `is_initialized` - - - -
fun is_initialized(): bool
-
- - - -
-Implementation - - -
fun is_initialized(): bool {
-    exists<TTL>(CoreAddresses::LIBRA_ROOT_ADDRESS())
-}
-
- - - -
- - - -## Function `set_timeout` - - - -
public fun set_timeout(lr_account: &signer, new_duration: u64)
-
- - - -
-Implementation - - -
public fun set_timeout(lr_account: &signer, new_duration: u64) acquires TTL {
-    LibraTimestamp::assert_operating();
-    Roles::assert_libra_root(lr_account);
-    let timeout = borrow_global_mut<TTL>(CoreAddresses::LIBRA_ROOT_ADDRESS());
-    timeout.duration_microseconds = new_duration;
-}
-
- - - -
- - - -## Function `is_valid_transaction_timestamp` - - - -
public fun is_valid_transaction_timestamp(timestamp: u64): bool
-
- - - -
-Implementation - - -
public fun is_valid_transaction_timestamp(timestamp: u64): bool acquires TTL {
-    LibraTimestamp::assert_operating();
-    // Reject timestamp greater than u64::MAX / 1_000_000.
-    // This allows converting the timestamp from seconds to microseconds.
-    if (timestamp > MAX_TIMESTAMP) {
-      return false
-    };
-
-    let current_block_time = LibraTimestamp::now_microseconds();
-    let timeout = borrow_global<TTL>(CoreAddresses::LIBRA_ROOT_ADDRESS()).duration_microseconds;
-    let _max_txn_time = current_block_time + timeout;
-
-    let txn_time_microseconds = timestamp * MICROS_MULTIPLIER;
-    // TODO: Add LibraTimestamp::is_before_exclusive(&txn_time_microseconds, &max_txn_time)
-    //       This is causing flaky test right now. The reason is that we will use this logic for AC, where its wall
-    //       clock time might be out of sync with the real block time stored in StateStore.
-    //       See details in issue #2346.
-    current_block_time < txn_time_microseconds
-}
-
- - - -
- - - -## Specification - - - -
invariant [global] LibraTimestamp::is_operating() ==> is_initialized();
-