Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fpelliccioni committed May 21, 2024
1 parent ae60d52 commit 769bc7d
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 74 deletions.
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class KnuthDomainConan(KnuthConanFileV2):

def build_requirements(self):
if self.options.tests:
self.test_requires("catch2/3.5.2")
self.test_requires("catch2/3.6.0")

def requirements(self):
self.requires("infrastructure/0.32.0", transitive_headers=True, transitive_libs=True)
Expand Down
10 changes: 8 additions & 2 deletions include/kth/domain/chain/chain_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ class KD_API chain_state {
size_t bip9_bit1_height(size_t height, uint32_t forks);
#endif

public:
// static
// bool is_rule_enabled(size_t height, uint32_t forks, size_t mainnet_height, size_t testnet_height);
static
Expand Down Expand Up @@ -413,14 +414,19 @@ class KD_API chain_state {
static
bool is_descartes_enabled(size_t height, config::network network);

// static
// bool is_lobachevski_enabled(size_t height, config::network network);
static
bool is_lobachevski_enabled(size_t height, config::network network);

// static
// bool is_galois_enabled(size_t height, config::network network);

// static
// bool is_leibniz_enabled(size_t height, config::network network);

#endif // KTH_CURRENCY_BCH
// ------------------------------------------------------------------------

private:
static
data to_block(chain_state const& pool, block const& block);

Expand Down
79 changes: 39 additions & 40 deletions include/kth/domain/chain/token_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <utility>
#include <variant>
#include <vector>
#include <version> // for __cpp_lib_three_way_comparison

#include <kth/domain/chain/script.hpp>
#include <kth/domain/define.hpp>
Expand All @@ -37,7 +38,7 @@ template<class> inline constexpr bool always_false_v = false;

namespace encoding {
static constexpr uint8_t PREFIX_BYTE = uint8_t(::kth::domain::machine::opcode::special_token_prefix);
}
} // namespace encoding

using token_id_t = hash_digest;
enum class amount_t : int64_t {};
Expand All @@ -54,44 +55,43 @@ using commitment_t = std::vector<uint8_t>;
// #endif

//TODO(fernando): move to a helper library
#if __cpp_lib_three_way_comparison < 201907L
template <typename I1, typename I2> //, typename Cmp>
constexpr
// auto lexicographical_compare_three_way(I1 f1, I1 l1, I2 f2, I2 l2, Cmp comp) { //-> decltype(comp(*f1, *f2)) {
auto lexicographical_compare_three_way(I1 f1, I1 l1, I2 f2, I2 l2) { //-> decltype(comp(*f1, *f2)) {
// using ret_t = decltype(comp(*f1, *f2));
using ret_t = decltype(*f1 <=> *f2);
static_assert(std::disjunction_v<
std::is_same<ret_t, std::strong_ordering>,
std::is_same<ret_t, std::weak_ordering>,
std::is_same<ret_t, std::partial_ordering>>,
"The return type must be a comparison category type.");

bool exhaust1 = (f1 == l1);
bool exhaust2 = (f2 == l2);
for (; !exhaust1 && !exhaust2; exhaust1 = (++f1 == l1), exhaust2 = (++f2 == l2)) {
// if (auto c = comp(*f1, *f2); c != 0) {
if (auto c = *f1 <=> *f2; c != 0) {
return c;
}
}

return !exhaust1 ? std::strong_ordering::greater:
!exhaust2 ? std::strong_ordering::less:
std::strong_ordering::equal;
}

constexpr
auto operator<=>(commitment_t const& x, commitment_t const& y) {
return lexicographical_compare_three_way(x.begin(), x.end(), y.begin(), y.end());
}

constexpr
auto operator<=>(token_id_t const& x, token_id_t const& y) {
return lexicographical_compare_three_way(x.begin(), x.end(), y.begin(), y.end());
}
#endif

// #if __cpp_lib_three_way_comparison < 201907L
// template <typename I1, typename I2> //, typename Cmp>
// constexpr
// // auto lexicographical_compare_three_way(I1 f1, I1 l1, I2 f2, I2 l2, Cmp comp) { //-> decltype(comp(*f1, *f2)) {
// auto lexicographical_compare_three_way(I1 f1, I1 l1, I2 f2, I2 l2) { //-> decltype(comp(*f1, *f2)) {
// // using ret_t = decltype(comp(*f1, *f2));
// using ret_t = decltype(*f1 <=> *f2);
// static_assert(std::disjunction_v<
// std::is_same<ret_t, std::strong_ordering>,
// std::is_same<ret_t, std::weak_ordering>,
// std::is_same<ret_t, std::partial_ordering>>,
// "The return type must be a comparison category type.");

// bool exhaust1 = (f1 == l1);
// bool exhaust2 = (f2 == l2);
// for (; !exhaust1 && !exhaust2; exhaust1 = (++f1 == l1), exhaust2 = (++f2 == l2)) {
// // if (auto c = comp(*f1, *f2); c != 0) {
// if (auto c = *f1 <=> *f2; c != 0) {
// return c;
// }
// }

// return !exhaust1 ? std::strong_ordering::greater:
// !exhaust2 ? std::strong_ordering::less:
// std::strong_ordering::equal;
// }

// constexpr
// auto operator<=>(commitment_t const& x, commitment_t const& y) {
// return lexicographical_compare_three_way(x.begin(), x.end(), y.begin(), y.end());
// }

// constexpr
// auto operator<=>(token_id_t const& x, token_id_t const& y) {
// return lexicographical_compare_three_way(x.begin(), x.end(), y.begin(), y.end());
// }
// #endif // __cpp_lib_three_way_comparison

// The values assigned to the low-order nibble of the bitfield byte represent the "permissions" of an NFT.
// For pure-fungible tokens, the value must be none (0x0).
Expand All @@ -102,7 +102,6 @@ enum class capability_t : uint8_t {
minting = 0x02, // If the minting capability is present, it indicates that the encoded token is a non-fungible token used for minting.
};


struct fungible {
amount_t amount;

Expand Down
63 changes: 32 additions & 31 deletions src/chain/chain_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,17 +563,22 @@ chain_state::activations chain_state::activation(data const& values, uint32_t fo
result.forks |= (rule_fork::bch_descartes & forks);
}

auto const mtp = median_time_past(values);
if (is_mtp_activated(mtp, to_underlying(lobachevski_activation_time))) {
//Note(Fernando): Move this to the next fork rules
if (is_lobachevski_enabled(values.height, network)) {
result.forks |= (rule_fork::bch_lobachevski & forks);
}

auto const mtp = median_time_past(values);
if (is_mtp_activated(mtp, to_underlying(galois_activation_time))) {
//Note(Fernando): Move this to the next fork rules
result.forks |= (rule_fork::bch_galois & forks);
}

if (is_mtp_activated(mtp, to_underlying(leibniz_activation_time))) {
//Note(Fernando): Move this to the next fork rules
result.forks |= (rule_fork::bch_leibniz & forks);
}


// Old rules with Replay Protection
// auto const mtp = median_time_past(values);
// if (is_mtp_activated(mtp, to_underlying(gauss_activation_time))) {
Expand Down Expand Up @@ -670,7 +675,6 @@ size_t chain_state::bip9_bit1_height(size_t height, uint32_t forks) {
// median_time_past
//-----------------------------------------------------------------------------

inline
bool chain_state::is_rule_enabled(size_t height, config::network network, size_t mainnet_height, size_t testnet_height
#if defined(KTH_CURRENCY_BCH)
, size_t testnet4_height
Expand All @@ -695,7 +699,6 @@ bool chain_state::is_rule_enabled(size_t height, config::network network, size_t

#if defined(KTH_CURRENCY_BCH)
// Block height at which CSV (BIP68, BIP112 and BIP113) becomes active
inline
bool chain_state::is_csv_enabled(size_t height, config::network network) {
auto res = is_rule_enabled(height, network
, mainnet_csv_activation_height
Expand All @@ -709,7 +712,6 @@ bool chain_state::is_csv_enabled(size_t height, config::network network) {
}

//2017-August-01 hard fork
inline
bool chain_state::is_uahf_enabled(size_t height, config::network network) {
auto res = is_rule_enabled(height, network
, mainnet_uahf_activation_height
Expand All @@ -723,7 +725,6 @@ bool chain_state::is_uahf_enabled(size_t height, config::network network) {
}

//2017-November-13 hard fork
inline
bool chain_state::is_daa_cw144_enabled(size_t height, config::network network) {
return is_rule_enabled(height, network
, mainnet_daa_cw144_activation_height
Expand All @@ -735,7 +736,6 @@ bool chain_state::is_daa_cw144_enabled(size_t height, config::network network) {
}

//2018-May hard fork
inline
bool chain_state::is_pythagoras_enabled(size_t height, config::network network) {
return is_rule_enabled(height, network
, mainnet_pythagoras_activation_height
Expand All @@ -747,7 +747,6 @@ bool chain_state::is_pythagoras_enabled(size_t height, config::network network)
}

//2018-Nov hard fork
inline
bool chain_state::is_euclid_enabled(size_t height, config::network network) {
return is_rule_enabled(height, network
, mainnet_euclid_activation_height
Expand All @@ -759,7 +758,6 @@ bool chain_state::is_euclid_enabled(size_t height, config::network network) {
}

//2019-May hard fork
inline
bool chain_state::is_pisano_enabled(size_t height, config::network network) {
return is_rule_enabled(height, network
, mainnet_pisano_activation_height
Expand All @@ -771,7 +769,6 @@ bool chain_state::is_pisano_enabled(size_t height, config::network network) {
}

//2019-Nov hard fork
inline
bool chain_state::is_mersenne_enabled(size_t height, config::network network) {
return is_rule_enabled(height, network
, mainnet_mersenne_activation_height
Expand All @@ -783,7 +780,6 @@ bool chain_state::is_mersenne_enabled(size_t height, config::network network) {
}

//2020-May hard fork
inline
bool chain_state::is_fermat_enabled(size_t height, config::network network) {
return is_rule_enabled(height, network
, mainnet_fermat_activation_height
Expand All @@ -795,7 +791,6 @@ bool chain_state::is_fermat_enabled(size_t height, config::network network) {
}

//2020-Nov hard fork
inline
bool chain_state::is_euler_enabled(size_t height, config::network network) {
return is_rule_enabled(height, network
, mainnet_euler_activation_height
Expand All @@ -807,7 +802,6 @@ bool chain_state::is_euler_enabled(size_t height, config::network network) {
}

//2022-May hard fork
inline
bool chain_state::is_gauss_enabled(size_t height, config::network network) {
return is_rule_enabled(height, network
, mainnet_gauss_activation_height
Expand All @@ -819,7 +813,6 @@ bool chain_state::is_gauss_enabled(size_t height, config::network network) {
}

//2023-May hard fork
inline
bool chain_state::is_descartes_enabled(size_t height, config::network network) {
return is_rule_enabled(height, network
, mainnet_descartes_activation_height
Expand All @@ -830,22 +823,19 @@ bool chain_state::is_descartes_enabled(size_t height, config::network network) {
);
}

//2024-May hard fork
// Complete after the hard fork
// inline
// bool chain_state::is_lobachevski_enabled(size_t height, config::network network) {
// return is_rule_enabled(height, network
// , mainnet_lobachevski_activation_height
// , testnet_lobachevski_activation_height
// , testnet4_lobachevski_activation_height
// , scalenet_lobachevski_activation_height
// , chipnet_lobachevski_activation_height
// );
// }
// 2024-May hard fork
bool chain_state::is_lobachevski_enabled(size_t height, config::network network) {
return is_rule_enabled(height, network
, mainnet_lobachevski_activation_height
, testnet_lobachevski_activation_height
, testnet4_lobachevski_activation_height
, scalenet_lobachevski_activation_height
, chipnet_lobachevski_activation_height
);
}

//2025-May hard fork
// Complete after the hard fork
// inline
// bool chain_state::is_galois_enabled(size_t height, config::network network) {
// return is_rule_enabled(height, network
// , mainnet_galois_activation_height
Expand All @@ -856,10 +846,20 @@ bool chain_state::is_descartes_enabled(size_t height, config::network network) {
// );
// }

//2026-May hard fork
// Complete after the hard fork
// bool chain_state::is_leibniz_enabled(size_t height, config::network network) {
// return is_rule_enabled(height, network
// , mainnet_leibniz_activation_height
// , testnet_leibniz_activation_height
// , testnet4_leibniz_activation_height
// , scalenet_leibniz_activation_height
// , chipnet_leibniz_activation_height
// );
// }

//2025-May hard fork
//2027-May hard fork
// Complete after the hard fork
// inline
// bool chain_state::is_unnamed_enabled(size_t height, config::network network) {
// return is_rule_enabled(height, network
// , mainnet_unnamed_activation_height
Expand Down Expand Up @@ -1460,8 +1460,9 @@ uint32_t chain_state::get_next_work_required(uint32_t time_now) {
// , euler_activation_time()
// , gauss_activation_time()
// , descartes_activation_time()
, lobachevski_activation_time()
// , lobachevski_activation_time()
, galois_activation_time()
, leibniz_activation_time()
, assert_anchor_block_info_
, asert_half_life()
#endif
Expand Down

0 comments on commit 769bc7d

Please sign in to comment.