Skip to content

Commit

Permalink
Merge branch 'main' into pending_pol_gen
Browse files Browse the repository at this point in the history
  • Loading branch information
systemzax committed Jul 26, 2024
2 parents e4cd854 + 8796c13 commit 9b18111
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
1 change: 1 addition & 0 deletions unittests/finality_proof.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ namespace finality_proof {
// compute digest for verification purposes
digest_type finality_digest = fc::sha256::hash(finality_digest_data_v1{
.active_finalizer_policy_generation = is_genesis ? 1 : active_finalizer_policy.generation,
.pending_finalizer_policy_generation = is_genesis ? 1 : last_pending_finalizer_policy.generation,
.finality_tree_digest = finality_root,
.l2_commitments_digest = level_2_commitments_digest
});
Expand Down
29 changes: 16 additions & 13 deletions unittests/svnn_ibc_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("qc_block", mvo()
("major_version", 1)
("minor_version", 0)
("finalizer_policy_generation", 1)
("active_finalizer_policy_generation", 1)
("witness_hash", block_3_result.level_2_commitments_digest)
("finality_mroot", block_3_result.finality_root)
)
Expand All @@ -129,7 +129,7 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("finality_data", mvo()
("major_version", 1)
("minor_version", 0)
("finalizer_policy_generation", 1)
("active_finalizer_policy_generation", 1)
("witness_hash", block_2_result.level_2_commitments_digest)
("finality_mroot", block_2_result.finality_root)
)
Expand All @@ -152,7 +152,7 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("qc_block", mvo()
("major_version", 1)
("minor_version", 0)
("finalizer_policy_generation", 1)
("active_finalizer_policy_generation", 1)
("witness_hash", block_3_result.level_2_commitments_digest)
("finality_mroot", block_3_result.finality_root)
)
Expand Down Expand Up @@ -187,7 +187,7 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("qc_block", mvo()
("major_version", 1)
("minor_version", 0)
("finalizer_policy_generation", 1)
("active_finalizer_policy_generation", 1)
("witness_hash", block_4_result.level_2_commitments_digest)
("finality_mroot", block_4_result.finality_root)
)
Expand All @@ -203,7 +203,7 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("finality_data", mvo()
("major_version", 1)
("minor_version", 0)
("finalizer_policy_generation", 1)
("active_finalizer_policy_generation", 1)
("witness_hash", block_2_result.level_2_commitments_digest)
("finality_mroot", block_2_result.finality_root)
)
Expand All @@ -229,7 +229,7 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("finality_data", mvo()
("major_version", 1)
("minor_version", 0)
("finalizer_policy_generation", 1)
("active_finalizer_policy_generation", 1)
("witness_hash", block_2_result.level_2_commitments_digest)
("finality_mroot", block_2_result.finality_root)
)
Expand Down Expand Up @@ -388,7 +388,7 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("qc_block", mvo()
("major_version", 1)
("minor_version", 0)
("finalizer_policy_generation", 1)
("active_finalizer_policy_generation", 1)
("witness_hash", block_8_result.level_2_commitments_digest)
("finality_mroot", block_8_result.finality_root)
)
Expand All @@ -404,7 +404,7 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("finality_data", mvo()
("major_version", 1)
("minor_version", 0)
("finalizer_policy_generation", 1)
("active_finalizer_policy_generation", 1)
("witness_hash", block_7_result.level_2_commitments_digest)
("finality_mroot", block_7_result.finality_root)
)
Expand All @@ -429,7 +429,7 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("finality_data", mvo()
("major_version", 1)
("minor_version", 0)
("finalizer_policy_generation", 1)
("active_finalizer_policy_generation", 1)
("witness_hash", block_7_result.level_2_commitments_digest)
("finality_mroot", block_7_result.finality_root)
)
Expand Down Expand Up @@ -493,7 +493,8 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("qc_block", mvo()
("major_version", 1)
("minor_version", 0)
("finalizer_policy_generation", 1)
("active_finalizer_policy_generation", 1)
("pending_finalizer_policy_generation", 2)
("witness_hash", block_11_result.level_2_commitments_digest)
("finality_mroot", block_11_result.finality_root)
)
Expand All @@ -509,7 +510,8 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("finality_data", mvo()
("major_version", 1)
("minor_version", 0)
("finalizer_policy_generation", 1)
("active_finalizer_policy_generation", 1)
("pending_finalizer_policy_generation", 2)
("new_finalizer_policy", cluster.last_pending_finalizer_policy)
("witness_hash", block_10_result.level_3_commitments_digest)
("last_pending_finalizer_policy_start_num", block_10_result.last_pending_finalizer_policy_start_num )
Expand Down Expand Up @@ -541,7 +543,7 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("qc_block", mvo()
("major_version", 1)
("minor_version", 0)
("finalizer_policy_generation", 2)
("active_finalizer_policy_generation", 2)
("witness_hash", block_12_result.level_2_commitments_digest)
("finality_mroot", block_12_result.finality_root)
)
Expand All @@ -557,7 +559,8 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("finality_data", mvo()
("major_version", 1)
("minor_version", 0)
("finalizer_policy_generation", 1)
("active_finalizer_policy_generation", 1)
("pending_finalizer_policy_generation", 2)
("witness_hash", block_11_result.level_2_commitments_digest)
("finality_mroot", block_11_result.finality_root)
)
Expand Down
7 changes: 5 additions & 2 deletions unittests/test-contracts/savanna/common/savanna.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ namespace savanna {
uint32_t minor_version;

//finalizer_policy_generation for this block
uint32_t finalizer_policy_generation;
uint32_t active_finalizer_policy_generation;
std::optional<uint32_t> pending_finalizer_policy_generation;

//Allows the contract to obtain knowledge about them and to record them in its internal state.
std::optional<finalizer_policy_input> new_finalizer_policy;
Expand Down Expand Up @@ -343,9 +344,11 @@ namespace savanna {
//internal representation of finality data
struct block_finality_data_internal : block_finality_data {
checksum256 resolved_witness_hash;
uint32_t pending_finalizer_policy_generation = 0;

block_finality_data_internal(const block_finality_data& base) : block_finality_data(base){
resolved_witness_hash = base.resolve_witness();
pending_finalizer_policy_generation = base.pending_finalizer_policy_generation.has_value() ? base.pending_finalizer_policy_generation.value() : active_finalizer_policy_generation;
}

checksum256 finality_digest() const {
Expand All @@ -354,7 +357,7 @@ namespace savanna {
return hash;
}

EOSLIB_SERIALIZE(block_finality_data_internal, (major_version)(minor_version)(finalizer_policy_generation)(finality_mroot)(resolved_witness_hash))
EOSLIB_SERIALIZE(block_finality_data_internal, (major_version)(minor_version)(active_finalizer_policy_generation)(pending_finalizer_policy_generation)(finality_mroot)(resolved_witness_hash))
};

//used in "heavy" proofs, where verification of finality digest is performed
Expand Down
6 changes: 5 additions & 1 deletion unittests/test-contracts/savanna/ibc/ibc.abi
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@
"type": "uint32"
},
{
"name": "finalizer_policy_generation",
"name": "active_finalizer_policy_generation",
"type": "uint32"
},
{
"name": "pending_finalizer_policy_generation",
"type": "uint32?"
},
{
"name": "new_finalizer_policy",
"type": "finalizer_policy_input?"
Expand Down
2 changes: 1 addition & 1 deletion unittests/test-contracts/savanna/ibc/ibc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ finalizer_policy_input ibc::_get_stored_finalizer_policy(const uint64_t finalize
void ibc::_check_finality_proof(const finality_proof& finality_proof, const block_proof_of_inclusion& target_block_proof_of_inclusion){

//attempt to retrieve the stored policy with the correct generation number
finalizer_policy_input finalizer_policy = _get_stored_finalizer_policy(finality_proof.qc_block.finalizer_policy_generation);
finalizer_policy_input finalizer_policy = _get_stored_finalizer_policy(finality_proof.qc_block.active_finalizer_policy_generation);

//verify QC. If QC is valid, it means that we have reached finality on the block referenced by the finality_mroot
_check_qc(finality_proof.qc, block_finality_data_internal(finality_proof.qc_block).finality_digest(), finalizer_policy);
Expand Down
Binary file modified unittests/test-contracts/savanna/ibc/ibc.wasm
Binary file not shown.

0 comments on commit 9b18111

Please sign in to comment.