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 974a78ac70..4d593ab0b7 100644 --- a/libraries/core_libs/consensus/src/final_chain/final_chain.cpp +++ b/libraries/core_libs/consensus/src/final_chain/final_chain.cpp @@ -162,6 +162,29 @@ class FinalChainImpl final : public FinalChain { return trx; } + bool isNeedToFinalize(EthBlockNumber blk_num) const { + const static auto get_bridge_root_method = util::EncodingSolidity::packFunctionCall("shouldFinalizeEpoch()"); + return u256(call(state_api::EVMTransaction{dev::ZeroAddress, 1, kHardforksConfig.ficus_hf.bridge_contract_address, + state_api::ZeroAccount.nonce, 0, 10000000, get_bridge_root_method}, + blk_num) + .code_retval) + .convert_to(); + } + + std::vector makeSystemTransactions(PbftPeriod blk_num) { + std::vector system_transactions; + if (kHardforksConfig.ficus_hf.isPillarBlockPeriod(blk_num)) { + if (const auto bridge_contract = get_account(kHardforksConfig.ficus_hf.bridge_contract_address); + bridge_contract) { + if (bridge_contract->code_size && isNeedToFinalize(blk_num - 1)) { + auto finalize_trx = make_bridge_finalization_transaction(); + system_transactions.push_back(finalize_trx); + } + } + } + return system_transactions; + } + std::shared_ptr finalize_(PeriodData&& new_blk, std::vector&& finalized_dag_blk_hashes, std::shared_ptr&& anchor) { @@ -186,12 +209,7 @@ class FinalChainImpl final : public FinalChain { } } */ - std::vector system_transactions; - const auto blk_num = new_blk.pbft_blk->getPeriod(); - if (kHardforksConfig.ficus_hf.isPillarBlockPeriod(blk_num)) { - auto finalize_trx = make_bridge_finalization_transaction(); - system_transactions.push_back(finalize_trx); - } + auto system_transactions = makeSystemTransactions(new_blk.pbft_blk->getPeriod()); auto all_transactions = new_blk.transactions; all_transactions.insert(all_transactions.end(), system_transactions.begin(), system_transactions.end()); diff --git a/submodules/taraxa-evm b/submodules/taraxa-evm index f7b5045063..ff789fab5b 160000 --- a/submodules/taraxa-evm +++ b/submodules/taraxa-evm @@ -1 +1 @@ -Subproject commit f7b504506346cf80dec05bf4e068ba89b1062144 +Subproject commit ff789fab5b5a691be80839db2e9a3f85549c48a8 diff --git a/tests/pillar_chain_test.cpp b/tests/pillar_chain_test.cpp index 79b9ae45d6..fa63f60d44 100644 --- a/tests/pillar_chain_test.cpp +++ b/tests/pillar_chain_test.cpp @@ -173,7 +173,7 @@ TEST_F(PillarChainTest, votes_count_changes) { EXPECT_HAPPENS({20s, 100ms}, [&](auto& ctx) { for (auto& node : nodes) { - if (ctx.fail_if(node->getDB()->getNumTransactionExecuted() <= validators_count)) { + if (ctx.fail_if(node->getDB()->getNumTransactionExecuted() != validators_count)) { return; } } @@ -422,45 +422,49 @@ TEST_F(PillarChainTest, pillar_vote_solidity_rlp_encoding) { } // contract BridgeMock { -// address public lightClient; - -// address[] public tokenAddresses; -// mapping(address => address) public connectors; -// mapping(address => address) public localAddress; -// uint256 finalizedEpoch; -// uint256 appliedEpoch; -// bytes32 bridgeRoot; -// event Finalized(uint256 epoch, bytes32 bridgeRoot); -// function finalizeEpoch() public { bridgeRoot = bytes32(appliedEpoch++); emit Finalized(appliedEpoch-1, -// bridgeRoot);} - -// function getBridgeRoot() public view returns (bytes32) { -// return bridgeRoot; -// } +// address public lightClient; + +// address[] public tokenAddresses; +// mapping(address => address) public connectors; +// mapping(address => address) public localAddress; +// uint256 finalizedEpoch; +// uint256 appliedEpoch; +// bytes32 bridgeRoot; +// event Finalized(uint256 epoch, bytes32 bridgeRoot); +// function finalizeEpoch() public { +// bridgeRoot = bytes32(appliedEpoch++); +// emit Finalized(appliedEpoch - 1, bridgeRoot); +// } + +// function getBridgeRoot() public view returns(bytes32) { return bridgeRoot; } +// function shouldFinalizeEpoch() public view returns(bool) { return true; } // } + auto bridge_mock_bytecode = - "6080604052348015600e575f80fd5b506104bd8061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610060575f3560e0" - "1c80630e53aae914610064578063695a253f1461009457806376081bd5146100b257806382ae9ef7146100e2578063b5700e68146100ec5780" - "63e5df8b841461010a575b5f80fd5b61007e600480360381019061007991906102c8565b61013a565b60405161008b9190610302565b604051" - "80910390f35b61009c61016a565b6040516100a99190610333565b60405180910390f35b6100cc60048036038101906100c791906102c8565b" - "610173565b6040516100d99190610302565b60405180910390f35b6100ea6101a3565b005b6100f461020c565b604051610101919061030256" - "5b60405180910390f35b610124600480360381019061011f919061037f565b61022f565b6040516101319190610302565b60405180910390f3" - "5b6002602052805f5260405f205f915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b5f60065490509056" - "5b6003602052805f5260405f205f915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60055f8154809291" - "906101b5906103d7565b919050555f1b6006819055507fa05a0e9561eff1f01a29e7a680d5957bb7312e5766a8da1f494b6d6ac18031f46001" - "6005546101f1919061041e565b600654604051610202929190610460565b60405180910390a1565b5f8054906101000a900473ffffffffffff" - "ffffffffffffffffffffffffffff1681565b6001818154811061023e575f80fd5b905f5260205f20015f915054906101000a900473ffffffff" - "ffffffffffffffffffffffffffffffff1681565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61" - "02978261026e565b9050919050565b6102a78161028d565b81146102b1575f80fd5b50565b5f813590506102c28161029e565b92915050565b" - "5f602082840312156102dd576102dc61026a565b5b5f6102ea848285016102b4565b91505092915050565b6102fc8161028d565b8252505056" - "5b5f6020820190506103155f8301846102f3565b92915050565b5f819050919050565b61032d8161031b565b82525050565b5f602082019050" - "6103465f830184610324565b92915050565b5f819050919050565b61035e8161034c565b8114610368575f80fd5b50565b5f81359050610379" - "81610355565b92915050565b5f602082840312156103945761039361026a565b5b5f6103a18482850161036b565b91505092915050565b7f4e" - "487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f6103e18261034c565b91507fff" - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610413576104126103aa565b5b600182019050919050565b" - "5f6104288261034c565b91506104338361034c565b925082820390508181111561044b5761044a6103aa565b5b92915050565b61045a816103" - "4c565b82525050565b5f6040820190506104735f830185610451565b6104806020830184610324565b939250505056fea26469706673582212" - "20733fb729feb3b0d4d1cecf12f9f57a37205e95e709a478b835534f1b7a03c8a164736f6c63430008190033"; + "6080604052348015600e575f80fd5b506105318061001c5f395ff3fe608060405234801561000f575f80fd5b506004361061007b575f3560e0" + "1c806376081bd51161005957806376081bd5146100eb57806382ae9ef71461011b578063b5700e6814610125578063e5df8b84146101435761" + "007b565b80630e53aae91461007f578063567041cd146100af578063695a253f146100cd575b5f80fd5b610099600480360381019061009491" + "90610309565b610173565b6040516100a69190610343565b60405180910390f35b6100b76101a3565b6040516100c49190610376565b604051" + "80910390f35b6100d56101ab565b6040516100e291906103a7565b60405180910390f35b61010560048036038101906101009190610309565b" + "6101b4565b6040516101129190610343565b60405180910390f35b6101236101e4565b005b61012d61024d565b60405161013a919061034356" + "5b60405180910390f35b61015d600480360381019061015891906103f3565b610270565b60405161016a9190610343565b60405180910390f3" + "5b6002602052805f5260405f205f915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b5f6001905090565b" + "5f600654905090565b6003602052805f5260405f205f915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b" + "60055f8154809291906101f69061044b565b919050555f1b6006819055507fa05a0e9561eff1f01a29e7a680d5957bb7312e5766a8da1f494b" + "6d6ac18031f460016005546102329190610492565b6006546040516102439291906104d4565b60405180910390a1565b5f8054906101000a90" + "0473ffffffffffffffffffffffffffffffffffffffff1681565b6001818154811061027f575f80fd5b905f5260205f20015f91505490610100" + "0a900473ffffffffffffffffffffffffffffffffffffffff1681565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff821690" + "50919050565b5f6102d8826102af565b9050919050565b6102e8816102ce565b81146102f2575f80fd5b50565b5f81359050610303816102df" + "565b92915050565b5f6020828403121561031e5761031d6102ab565b5b5f61032b848285016102f5565b91505092915050565b61033d816102" + "ce565b82525050565b5f6020820190506103565f830184610334565b92915050565b5f8115159050919050565b6103708161035c565b825250" + "50565b5f6020820190506103895f830184610367565b92915050565b5f819050919050565b6103a18161038f565b82525050565b5f60208201" + "90506103ba5f830184610398565b92915050565b5f819050919050565b6103d2816103c0565b81146103dc575f80fd5b50565b5f8135905061" + "03ed816103c9565b92915050565b5f60208284031215610408576104076102ab565b5b5f610415848285016103df565b91505092915050565b" + "7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f610455826103c0565b9150" + "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036104875761048661041e565b5b600182019050919050" + "565b5f61049c826103c0565b91506104a7836103c0565b92508282039050818111156104bf576104be61041e565b5b92915050565b6104ce81" + "6103c0565b82525050565b5f6040820190506104e75f8301856104c5565b6104f46020830184610398565b939250505056fea2646970667358" + "22122085e3f65e550b0efa67168cceadab882db443d5c0057e7f286914bc35c257196064736f6c634300081a0033"; TEST_F(PillarChainTest, finalize_root_in_pillar_block) { auto node_cfgs = make_node_cfgs(2, 2, 10);