diff --git a/for_devs/local-net b/for_devs/local-net index 8add8bec84..77dcc1a2f3 100755 --- a/for_devs/local-net +++ b/for_devs/local-net @@ -226,7 +226,7 @@ def generate_faucet_wallet(binary): global faucet_public_address wallet_path = f'./{data_dir}/faucet-wallet.json' - + if os.path.isfile(wallet_path): wallet = json.loads('{}') with open(wallet_path) as json_file: diff --git a/for_devs/requirements.txt b/for_devs/requirements.txt index 19d943a12c..43069dfeea 100644 --- a/for_devs/requirements.txt +++ b/for_devs/requirements.txt @@ -1,198 +1,39 @@ -aiohttp==3.9.2 -aiosignal==1.3.1 -anyio==4.0.0 -apt-xapian-index==0.49 -argcomplete==2.0.0 -arrow==1.3.0 -asn1crypto==1.5.1 +aiohttp==3.8.5 +async-timeout==4.0.3 attrs==23.1.0 -Babel==2.10.3 -bcrypt==4.0.1 -binaryornot==0.4.4 -bitarray==2.9.0 -blinker==1.6.2 -boto3==1.28.68 -botocore==1.31.68 -bottle==0.12.25 -Brotli==1.0.9 -build==0.10.0 -CacheControl==0.13.1 -certifi==2022.9.24 -cffi==1.16.0 -chardet==5.1.0 -cleo==2.0.1 +base58==2.1.1 +bitarray==2.8.1 +certifi==2024.2.2 +chardet==5.2.0 click==8.1.6 -click-configfile==0.2.3 -colorama==0.4.6 -command-not-found==0.3 -conan==1.59.0 -configparser==6.0.0 -cookiecutter==2.4.0 -crashtest==0.4.1 -cryptography==42.0.4 -cupshelpers==1.0 cytoolz==0.12.2 -dbus-python==1.3.2 -defer==1.0.6 -distlib==0.3.7 -distro==1.8.0 -distro-info==1.5 -docker==5.0.3 -docker-compose==1.29.2 -dockerpty==0.4.1 -docopt==0.6.2 -dulwich==0.21.6 -eth-abi==5.0.1 -eth-account==0.10.0 +eth-abi==4.1.0 +eth-account==0.9.0 eth-hash==0.5.2 -eth-keyfile==0.7.0 +eth-keyfile==0.6.1 eth-keys==0.4.0 -eth-rlp==1.0.0 -eth-typing==3.5.2 -eth-utils==2.3.1 -fabric==2.7.1 -fasteners==0.19 -fastimport==0.9.14 -filelock==3.12.2 -frozenlist==1.4.1 -fuse-python==1.0.5 -ghp-import==2.1.0 -gpg==1.18.0 -gyp==0.1 -h11==0.14.0 -hamlet==10.0.1 +eth-rlp==0.3.0 +eth-typing==3.4.0 +eth-utils==2.2.0 hexbytes==0.3.1 -html5lib==1.1 -httpcore==0.18.0 -httplib2==0.20.4 -httpx==0.25.0 -idna==3.3 -importlib-metadata==4.12.0 -importlib-resources==5.13.0 -iniconfig==1.1.1 -installer==0.7.0 -invoke==1.7.3 -jaraco.classes==3.2.1 -jeepney==0.8.0 -Jinja2==3.1.3 -jmespath==0.10.0 -joblib==1.2.0 -jsonpointer==2.0 -jsonschema==4.10.3 -keyring==24.2.0 -language-selector==0.1 -launchpadlib==1.11.0 -lazr.restfulclient==0.14.5 -lazr.uri==1.0.6 -livereload==2.6.3 -lockfile==0.12.2 +idna==3.4 +ipfshttpclient==0.7.0 +jsonschema==4.19.1 lru-dict==1.2.0 -lunr==0.6.2 -Markdown==3.4.4 -markdown-it-py==3.0.0 -MarkupSafe==2.1.3 -marshmallow==3.20.1 -mat==0.13.4 -mdurl==0.1.2 -mechanize==0.4.8 -mergedeep==1.3.4 -mkdocs==1.4.2 -more-itertools==10.1.0 -msgpack==1.0.3 +multiaddr==0.0.9 multidict==6.0.4 -mutagen==1.46.0 -netifaces==0.11.0 -nltk==3.8.1 -node-semver==0.6.1 -numpy==1.24.2 -oauthlib==3.2.2 -olefile==0.46 -packaging==23.1 -paramiko==3.4.0 +netaddr==1.2.1 parsimonious==0.9.0 -patch-ng==1.17.4 -pathlib2==2.3.7.post1 -pexpect==4.8.0 -Pillow==10.2.0 -pipx==1.2.0 -pkginfo==1.8.2 -platformdirs==3.10.0 -pluggy==1.2.0 -pluginbase==1.0.1 -poetry==1.6.1 -poetry-core==1.6.1 -protobuf==4.25.1 -psutil==5.9.4 -ptyprocess==0.7.0 -pycairo==1.24.0 -pycparser==2.21 -pycryptodome==3.19.0 -pycryptodomex==3.19.1 -pycups==2.0.1 -Pygments==2.15.1 -PyGObject==3.46.0 -pyinotify==0.9.6 -PyJWT==2.7.0 -pylev==1.4.0 -pylibacl==0.7.0 -PyNaCl==1.5.0 -pyparsing==3.1.0 -pyproject_hooks==1.0.0 -PyQt5==5.15.9 -PyQt5-sip==12.12.2 -pyrsistent==0.18.1 -pytest==6.2.5 -python-apt==2.6.0+ubuntu1 -python-dateutil==2.8.2 -python-debian==0.1.49+ubuntu2 -python-dotenv==1.0.0 -python-slugify==8.0.1 -pytz==2023.3 -pyunormalize==15.1.0 -pyxattr==0.8.1 -PyYAML==6.0 -pyyaml_env_tag==0.1 -regex==2022.10.31 +protobuf==4.24.3 +pycryptodome==3.18.0 +pyrsistent==0.20.0 requests==2.31.0 -requests-toolbelt==1.0.0 -rich==13.3.1 -rlp==4.0.0 -s3transfer==0.7.0 -SecretStorage==3.3.3 -semver==2.13.0 -shellingham==1.5.1 -simple-term-menu==1.6.1 -simplejson==3.19.1 +rlp==3.0.0 six==1.16.0 -sniffio==1.3.0 -systemd-python==235 -tabulate==0.9.0 -text-unidecode==1.3 -texttable==1.6.7 -toml==0.10.2 -tomlkit==0.12.1 toolz==0.12.0 -tornado==6.3.2 -tqdm==4.64.1 -trove-classifiers==2023.7.6 -types-python-dateutil==2.8.19.14 -typing_extensions==4.9.0 -ubuntu-advantage-tools==8001 -ubuntu-drivers-common==0.0.0 -ufw==0.36.2 -unattended-upgrades==0.1 -urllib3==1.26.16 -usb-creator==0.3.16 -userpath==1.9.0 -virtualenv==20.24.1+ds -wadllib==1.3.6 -watchdog==3.0.0 -web3==6.12.0 -webencodings==0.5.1 -websocket-client==1.2.3 -websockets==10.4 -www-authenticate==0.9.2 -xkit==0.0.0 -yarl==1.9.4 -yt-dlp==2023.11.14 -zipp==1.0.0 +typing-extensions==4.8.0 +urllib3==2.0.5 +varint==1.0.2 +web3==6.10.0 +websockets==11.0.3 +yarl==1.9.2 \ No newline at end of file diff --git a/libraries/cli/include/cli/config_jsons/default/default_genesis.json b/libraries/cli/include/cli/config_jsons/default/default_genesis.json index 22929381c0..729f22ebfc 100644 --- a/libraries/cli/include/cli/config_jsons/default/default_genesis.json +++ b/libraries/cli/include/cli/config_jsons/default/default_genesis.json @@ -58,12 +58,13 @@ }, "initial_balances": { "2cd4da7d3b345e022ca7e997c2bb3276a4d3d2e9": "0x1027e72f1f12813088000000", - "7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0x1027e72f1f12813088000000" + "7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0x27e72f1f12813088000000", + "fF310642f352E0b6b5266CE492e91D6af1241F41": "0x27e72f1f12813088000000с" }, "gas_price": { "blocks": 200, "percentile": 60, - "minimum_price" : 1 + "minimum_price": 1 }, "pbft": { "committee_size": "0x3e8", @@ -100,25 +101,26 @@ "hardforks": { "fix_redelegate_block_num": 0, "rewards_distribution_frequency": { - "0" : 100 + "0": 100 }, - "magnolia_hf" : { - "block_num" : 0, + "magnolia_hf": { + "block_num": 0, "jail_time": 163459 }, "phalaenopsis_hf_block_num": 0, "fix_claim_all_block_num": -1, - "aspen_hf" : { - "block_num_part_one" : 0, - "block_num_part_two" : 0, + "aspen_hf": { + "block_num_part_one": 0, + "block_num_part_two": 0, "max_supply": "0x26C62AD77DC602DAE0000000", "generated_rewards": "0x0" }, - "ficus_hf" : { - "block_num" : 0, - "pillar_block_periods" : 100, - "pillar_chain_sync_periods" : 25, - "pbft_inclusion_delay": 6 + "ficus_hf": { + "block_num": 1000, + "pillar_block_periods": 100, + "pillar_chain_sync_periods": 25, + "pbft_inclusion_delay": 6, + "bridge_contract_address": "0xd3c087C17C0E8EA2084FB12ac8B1494AA1E7B749" } } } \ No newline at end of file diff --git a/libraries/config/include/config/hardfork.hpp b/libraries/config/include/config/hardfork.hpp index af757fd39c..872d569684 100644 --- a/libraries/config/include/config/hardfork.hpp +++ b/libraries/config/include/config/hardfork.hpp @@ -46,6 +46,7 @@ struct FicusHardforkConfig { // previous pillar blocks and 2t+1 signatures for latest pillar block) uint64_t pbft_inclusion_delay{ 6}; // [periods] how many periods after the pillar block is created it is included in pbft block + taraxa::addr_t bridge_contract_address; // [address] of the bridge contract bool isFicusHardfork(taraxa::PbftPeriod period) const; bool isPillarBlockPeriod(taraxa::PbftPeriod period, uint64_t from_n_th_block = 1) const; diff --git a/libraries/config/src/hardfork.cpp b/libraries/config/src/hardfork.cpp index 2febb85582..15e646d4d2 100644 --- a/libraries/config/src/hardfork.cpp +++ b/libraries/config/src/hardfork.cpp @@ -87,6 +87,10 @@ void FicusHardforkConfig::validate(uint32_t delegation_delay) const { if (pbft_inclusion_delay < 1 || pbft_inclusion_delay <= delegation_delay) { throw taraxa::ConfigException("ficus_hf.pbft_inclusion_delay must be >= 1 && > dpos.delegation_delay"); } + + if (bridge_contract_address == taraxa::addr_t()) { + throw taraxa::ConfigException("ficus_hf.bridge_contract_address must be set"); + } } Json::Value enc_json(const FicusHardforkConfig& obj) { @@ -95,6 +99,7 @@ Json::Value enc_json(const FicusHardforkConfig& obj) { json["pillar_block_periods"] = dev::toJS(obj.pillar_block_periods); json["pillar_chain_sync_periods"] = dev::toJS(obj.pillar_chain_sync_periods); json["pbft_inclusion_delay"] = dev::toJS(obj.pbft_inclusion_delay); + json["bridge_contract_address"] = dev::toJS(obj.bridge_contract_address); return json; } @@ -103,8 +108,10 @@ void dec_json(const Json::Value& json, FicusHardforkConfig& obj) { obj.pillar_block_periods = dev::getUInt(json["pillar_block_periods"]); obj.pillar_chain_sync_periods = dev::getUInt(json["pillar_chain_sync_periods"]); obj.pbft_inclusion_delay = dev::getUInt(json["pbft_inclusion_delay"]); + obj.bridge_contract_address = taraxa::addr_t(json["bridge_contract_address"].asString()); } -RLP_FIELDS_DEFINE(FicusHardforkConfig, block_num, pillar_block_periods, pillar_chain_sync_periods, pbft_inclusion_delay) +RLP_FIELDS_DEFINE(FicusHardforkConfig, block_num, pillar_block_periods, pillar_chain_sync_periods, pbft_inclusion_delay, + bridge_contract_address) Json::Value enc_json(const HardforksConfig& obj) { Json::Value json(Json::objectValue); @@ -158,4 +165,4 @@ void dec_json(const Json::Value& json, HardforksConfig& obj) { } RLP_FIELDS_DEFINE(HardforksConfig, fix_redelegate_block_num, redelegations, rewards_distribution_frequency, magnolia_hf, - phalaenopsis_hf_block_num, fix_claim_all_block_num, aspen_hf) + phalaenopsis_hf_block_num, fix_claim_all_block_num, aspen_hf, ficus_hf) diff --git a/libraries/core_libs/consensus/include/final_chain/final_chain.hpp b/libraries/core_libs/consensus/include/final_chain/final_chain.hpp index 15215c47eb..979d3cbc6a 100644 --- a/libraries/core_libs/consensus/include/final_chain/final_chain.hpp +++ b/libraries/core_libs/consensus/include/final_chain/final_chain.hpp @@ -248,6 +248,12 @@ class FinalChain { */ virtual u256 dpos_total_supply(EthBlockNumber blk_num) const = 0; + /** + * @param blk_num + * @return bridge root + */ + virtual h256 get_bridge_root(EthBlockNumber blk_num) const = 0; + // TODO move out of here: std::pair getBalance(addr_t const& addr) const { diff --git a/libraries/core_libs/consensus/include/final_chain/state_api.hpp b/libraries/core_libs/consensus/include/final_chain/state_api.hpp index 2e39be8843..12b058254c 100644 --- a/libraries/core_libs/consensus/include/final_chain/state_api.hpp +++ b/libraries/core_libs/consensus/include/final_chain/state_api.hpp @@ -62,6 +62,7 @@ class StateAPI { std::vector dpos_validators_vote_counts(EthBlockNumber blk_num) const; uint64_t dpos_yield(EthBlockNumber blk_num) const; u256 dpos_total_supply(EthBlockNumber blk_num) const; + h256 get_bridge_root(const addr_t& bridge_contract_address, EthBlockNumber blk_num) const; }; /** @} */ diff --git a/libraries/core_libs/consensus/src/final_chain/final_chain.cpp b/libraries/core_libs/consensus/src/final_chain/final_chain.cpp index d94076a558..f9a6b090ad 100644 --- a/libraries/core_libs/consensus/src/final_chain/final_chain.cpp +++ b/libraries/core_libs/consensus/src/final_chain/final_chain.cpp @@ -44,6 +44,7 @@ class FinalChainImpl final : public FinalChain { std::atomic last_block_number_; + const HardforksConfig& hardforks_config_; LOG_OBJECTS_DEFINE public: @@ -72,9 +73,10 @@ class FinalChainImpl final : public FinalChain { dpos_vote_count_cache_( config.final_chain_cache_in_blocks, [this](uint64_t blk, const addr_t& addr) { return state_api_.dpos_eligible_vote_count(blk, addr); }), - dpos_is_eligible_cache_(config.final_chain_cache_in_blocks, [this](uint64_t blk, const addr_t& addr) { - return state_api_.dpos_is_eligible(blk, addr); - }) { + dpos_is_eligible_cache_( + config.final_chain_cache_in_blocks, + [this](uint64_t blk, const addr_t& addr) { return state_api_.dpos_is_eligible(blk, addr); }), + hardforks_config_(config.genesis.state.hardforks) { LOG_OBJECTS_CREATE("EXECUTOR"); num_executed_dag_blk_ = db_->getStatusField(taraxa::StatusDbField::ExecutedBlkCount); num_executed_trx_ = db_->getStatusField(taraxa::StatusDbField::ExecutedTrxCount); @@ -468,6 +470,10 @@ class FinalChainImpl final : public FinalChain { u256 dpos_total_supply(EthBlockNumber blk_num) const override { return state_api_.dpos_total_supply(blk_num); } + h256 get_bridge_root(EthBlockNumber blk_num) const override { + return state_api_.get_bridge_root(hardforks_config_.ficus_hf.bridge_contract_address, blk_num); + } + private: std::shared_ptr get_transaction_hashes(std::optional n = {}) const { const auto& trxs = db_->getPeriodTransactions(last_if_absent(n)); diff --git a/libraries/core_libs/consensus/src/final_chain/state_api.cpp b/libraries/core_libs/consensus/src/final_chain/state_api.cpp index 1a195342e4..85be8e6bba 100644 --- a/libraries/core_libs/consensus/src/final_chain/state_api.cpp +++ b/libraries/core_libs/consensus/src/final_chain/state_api.cpp @@ -284,4 +284,12 @@ u256 StateAPI::dpos_total_supply(EthBlockNumber blk_num) const { return ret; } +h256 StateAPI::get_bridge_root(const addr_t& bridge_contract_address, EthBlockNumber blk_num) const { + h256 ret; + ErrorHandler err_h; + const auto bridge_root_position = h256("0x6"); + return c_method_args_rlp( + this_c_, blk_num, bridge_contract_address, bridge_root_position); +} + } // namespace taraxa::state_api diff --git a/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp b/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp index f466a48dd1..325336dd5a 100644 --- a/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp +++ b/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp @@ -50,6 +50,7 @@ std::shared_ptr PillarChainManager::createPillarBlock( blk_hash_t previous_pillar_block_hash{}; // null block hash auto new_vote_counts = final_chain_->dpos_validators_vote_counts(block_num); std::vector votes_count_changes; + h256 bridge_root = final_chain_->get_bridge_root(block_num); // First ever pillar block if (block_num == kFicusHfConfig.firstPillarBlockPeriod()) { @@ -105,9 +106,9 @@ std::shared_ptr PillarChainManager::createPillarBlock( votes_count_changes = getOrderedValidatorsVoteCountsChanges(new_vote_counts, current_pillar_block_vote_counts_); } - // TODO: provide bridge root ??? - const auto pillar_block = std::make_shared(block_num, block_data->final_chain_blk->state_root, h256{}, - std::move(votes_count_changes), previous_pillar_block_hash); + const auto pillar_block = + std::make_shared(block_num, block_data->final_chain_blk->state_root, bridge_root, + std::move(votes_count_changes), previous_pillar_block_hash); // Check if some pillar block was not skipped if (!isValidPillarBlock(pillar_block)) {