Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont fail finalize #2785

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions libraries/core_libs/consensus/src/final_chain/final_chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>();
}

std::vector<SharedTransaction> makeSystemTransactions(PbftPeriod blk_num) {
std::vector<SharedTransaction> 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<const FinalizationResult> finalize_(PeriodData&& new_blk,
std::vector<h256>&& finalized_dag_blk_hashes,
std::shared_ptr<DagBlock>&& anchor) {
Expand All @@ -186,12 +209,7 @@ class FinalChainImpl final : public FinalChain {
}
} */

std::vector<SharedTransaction> 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());
Expand Down
2 changes: 1 addition & 1 deletion submodules/taraxa-evm
Submodule taraxa-evm updated 0 files
80 changes: 42 additions & 38 deletions tests/pillar_chain_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand Down
Loading