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

Add timestamp and parent_timestamp to finality leaf nodes. #392

Merged
merged 21 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3c5adc9
Add `timestamp` and `parent_timestamp` to finality leaf nodes.
greg7mdp Jul 23, 2024
39d0d9e
Undo change adding `std::move`.
greg7mdp Jul 23, 2024
337203f
Update `deep-mind.log`
greg7mdp Jul 23, 2024
4cfbfca
Merge branch 'main' of github.com:AntelopeIO/spring into gh_387
greg7mdp Jul 23, 2024
099ff5c
WIP
systemzax Jul 23, 2024
d913d4f
WIP
systemzax Jul 23, 2024
efb00c7
Changed timestamp + parent_timestamp serialization form to fc::time_p…
systemzax Jul 24, 2024
3f9fdf1
Clean up
systemzax Jul 24, 2024
96fb137
Clean up
systemzax Jul 24, 2024
e75750d
Merge branch 'gh_387' of https://github.com/antelopeIO/spring into gh…
systemzax Jul 24, 2024
10c2c96
Merge branch 'gh_387' of https://github.com/antelopeIO/spring into gh…
systemzax Jul 24, 2024
bdd3b4e
Removed leftover comments in savanna smart contract, recompiled
systemzax Jul 24, 2024
d4a233a
Merge branch 'gh_387' of https://github.com/antelopeIO/spring into gh…
systemzax Jul 24, 2024
0fbb424
Update `deep-mind` log.
greg7mdp Jul 24, 2024
51964f7
Merge branch 'main' of github.com:AntelopeIO/spring into gh_387
greg7mdp Jul 24, 2024
5db00c5
Switch back to using `block_timestamp_type` instead of `fc::time_point`
greg7mdp Jul 24, 2024
91542ed
Update `deep-mind.log`
greg7mdp Jul 24, 2024
0c6995d
Disable `svnn_ibc` tests.
greg7mdp Jul 24, 2024
af6b56f
Fix disabling of `svnn_ibc` tests
greg7mdp Jul 25, 2024
55755c5
Merge branch 'main' of github.com:AntelopeIO/spring into gh_387
greg7mdp Jul 25, 2024
3088f77
Updated `deep-mind.log`
greg7mdp Jul 25, 2024
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
18 changes: 12 additions & 6 deletions libraries/chain/block_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,13 @@ block_state_ptr block_state::create_if_genesis_block(const block_state_legacy& b

// build leaf_node and validation_tree
valid_t::finality_leaf_node_t leaf_node {
.block_num = bsp.block_num(),
.finality_digest = result.strong_digest,
.action_mroot = *bsp.action_mroot_savanna
.block_num = bsp.block_num(),
.timestamp = bsp.timestamp().to_time_point(),
.parent_timestamp = block_timestamp_type().to_time_point(), // for the genesis block, the parent_timestamp is the the earliest representable timestamp.
heifner marked this conversation as resolved.
Show resolved Hide resolved
.finality_digest = result.strong_digest,
.action_mroot = *bsp.action_mroot_savanna
};

// construct valid structure
incremental_merkle_tree validation_tree;
validation_tree.append(fc::sha256::hash(leaf_node));
Expand Down Expand Up @@ -322,10 +325,13 @@ valid_t block_state::new_valid(const block_header_state& next_bhs, const digest_

// construct block's finality leaf node.
valid_t::finality_leaf_node_t leaf_node{
.block_num = next_bhs.block_num(),
.finality_digest = strong_digest,
.action_mroot = action_mroot
.block_num = next_bhs.block_num(),
.timestamp = next_bhs.timestamp().to_time_point(),
.parent_timestamp = timestamp().to_time_point(),
.finality_digest = strong_digest,
.action_mroot = action_mroot
};

auto leaf_node_digest = fc::sha256::hash(leaf_node);

// append new finality leaf node digest to validation_tree
Expand Down
14 changes: 8 additions & 6 deletions libraries/chain/include/eosio/chain/block_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ struct block_state_accessor;
* */
struct valid_t {
struct finality_leaf_node_t {
uint32_t major_version{light_header_protocol_version_major};
uint32_t minor_version{light_header_protocol_version_minor};
block_num_type block_num{0}; // the block number
digest_type finality_digest; // finality digest for the block
digest_type action_mroot; // digest of the root of the action Merkle tree of the block
uint32_t major_version{light_header_protocol_version_major};
uint32_t minor_version{light_header_protocol_version_minor};
block_num_type block_num{0}; // the block number
fc::time_point timestamp;
fc::time_point parent_timestamp;
digest_type finality_digest; // finality digest for the block
digest_type action_mroot; // digest of the root of the action Merkle tree of the block
};

// The Finality Merkle Tree, containing leaf nodes from IF genesis block to current block
Expand Down Expand Up @@ -198,7 +200,7 @@ using block_state_pair = std::pair<std::shared_ptr<block_state_legacy>, blo
} // namespace eosio::chain

// not exporting pending_qc or valid_qc
FC_REFLECT( eosio::chain::valid_t::finality_leaf_node_t, (major_version)(minor_version)(block_num)(finality_digest)(action_mroot) )
FC_REFLECT( eosio::chain::valid_t::finality_leaf_node_t, (major_version)(minor_version)(block_num)(timestamp)(parent_timestamp)(finality_digest)(action_mroot) )
FC_REFLECT( eosio::chain::valid_t, (validation_tree)(validation_mroots))
FC_REFLECT( eosio::chain::finality_data_t, (major_version)(minor_version)(active_finalizer_policy_generation)(final_on_strong_qc_block_num)(action_mroot)(reversible_blocks_mroot)(base_digest)(pending_finalizer_policy) )
FC_REFLECT_DERIVED( eosio::chain::block_state, (eosio::chain::block_header_state), (block)(strong_digest)(weak_digest)(pending_qc)(valid)(validated) )
190 changes: 95 additions & 95 deletions unittests/deep-mind/deep-mind.log

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion unittests/finality_proof.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace finality_proof {
digest_type level_2_commitments_digest;
digest_type finality_leaf;
digest_type finality_root;
block_timestamp_type parent_timestamp;
};

static digest_type hash_pair(const digest_type& a, const digest_type& b) {
Expand Down Expand Up @@ -139,6 +140,9 @@ namespace finality_proof {
finalizer_policy active_finalizer_policy;
digest_type active_finalizer_policy_digest;

block_timestamp_type parent_timestamp = block_timestamp_type();
block_timestamp_type timestamp;

// counter to (optimistically) track internal policy changes
std::unordered_map<digest_type, policy_count> blocks_since_proposed_policy;

Expand All @@ -165,6 +169,7 @@ namespace finality_proof {

//skip this part on genesis
if (!is_genesis){
parent_timestamp = timestamp;
for (const auto& p : blocks_since_proposed_policy){
//under the happy path with strong QCs in every block, a policy becomes active 6 blocks after being proposed
if (p.second.blocks_since_proposed == 6){
Expand All @@ -179,6 +184,8 @@ namespace finality_proof {
}
}

timestamp = block->timestamp;

// if we have policy diffs, process them
if (has_finalizer_policy_diffs(block)){
if (is_genesis) {
Expand Down Expand Up @@ -234,6 +241,8 @@ namespace finality_proof {
// compute finality leaf
digest_type finality_leaf = fc::sha256::hash(valid_t::finality_leaf_node_t{
.block_num = block->block_num(),
.timestamp = timestamp,
.parent_timestamp = parent_timestamp,
.finality_digest = finality_digest,
.action_mroot = action_mroot
});
Expand All @@ -247,7 +256,7 @@ namespace finality_proof {
qc_data_t qc_data = extract_qc_data(block);

// return relevant IBC information
return {block, qc_data, onblock_trace, finality_data, active_finalizer_policy.generation, last_pending_finalizer_policy.generation, last_proposed_finalizer_policy.generation, action_mroot, base_digest, active_finalizer_policy_digest, last_pending_finalizer_policy_digest, last_proposed_finalizer_policy_digest, finality_digest, level_3_commitments_digest, level_2_commitments_digest, finality_leaf, finality_root };
return {block, qc_data, onblock_trace, finality_data, active_finalizer_policy.generation, last_pending_finalizer_policy.generation, last_proposed_finalizer_policy.generation, action_mroot, base_digest, active_finalizer_policy_digest, last_pending_finalizer_policy_digest, last_proposed_finalizer_policy_digest, finality_digest, level_3_commitments_digest, level_2_commitments_digest, finality_leaf, finality_root, parent_timestamp };

}

Expand Down
19 changes: 17 additions & 2 deletions unittests/svnn_ibc_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ using namespace eosio::testing;

using mvo = mutable_variant_object;


std::string bitset_to_input_string(const boost::dynamic_bitset<unsigned char>& bitset) {
static const char* hexchar = "0123456789abcdef";

Expand Down Expand Up @@ -132,6 +131,8 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("witness_hash", block_2_result.level_2_commitments_digest)
("finality_mroot", block_2_result.finality_root)
)
("timestamp", block_2_result.block->timestamp.to_time_point())
("parent_timestamp", block_2_result.parent_timestamp.to_time_point())
("dynamic_data", mvo()
("block_num", block_2_result.block->block_num())
("action_proofs", fc::variants())
Expand Down Expand Up @@ -166,6 +167,8 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("major_version", 1)
("minor_version", 0)
("finality_digest", block_2_result.finality_digest)
("timestamp", block_2_result.block->timestamp.to_time_point())
("parent_timestamp", block_2_result.parent_timestamp.to_time_point())
("dynamic_data", mvo()
("block_num", block_2_result.block->block_num())
("action_proofs", fc::variants())
Expand Down Expand Up @@ -205,6 +208,8 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("witness_hash", block_2_result.level_2_commitments_digest)
("finality_mroot", block_2_result.finality_root)
)
("timestamp", block_2_result.block->timestamp.to_time_point())
("parent_timestamp", block_2_result.parent_timestamp.to_time_point())
("dynamic_data", mvo()
("block_num", block_2_result.block->block_num())
("action_proofs", fc::variants())
Expand All @@ -230,6 +235,8 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("witness_hash", block_2_result.level_2_commitments_digest)
("finality_mroot", block_2_result.finality_root)
)
("timestamp", block_2_result.block->timestamp.to_time_point())
("parent_timestamp", block_2_result.parent_timestamp.to_time_point())
("dynamic_data", mvo()
("block_num", block_2_result.block->block_num())
("action_proofs", fc::variants())
Expand Down Expand Up @@ -387,6 +394,8 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("witness_hash", block_7_result.level_2_commitments_digest)
("finality_mroot", block_7_result.finality_root)
)
("timestamp", block_7_result.block->timestamp.to_time_point())
("parent_timestamp", block_7_result.parent_timestamp.to_time_point())
("dynamic_data", mvo()
("block_num", block_7_result.block->block_num())
("action_proofs", fc::variants({onblock_action_proof}))
Expand All @@ -411,6 +420,8 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("witness_hash", block_7_result.level_2_commitments_digest)
("finality_mroot", block_7_result.finality_root)
)
("timestamp", block_7_result.block->timestamp.to_time_point())
("parent_timestamp", block_7_result.parent_timestamp.to_time_point())
("dynamic_data", mvo()
("block_num", block_7_result.block->block_num())
("action_proofs", fc::variants({action_proof_1, action_proof_2}))
Expand Down Expand Up @@ -505,6 +516,8 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("reversible_blocks_mroot", block_11_result.finality_data.reversible_blocks_mroot)
("finality_mroot", block_11_result.finality_root)
)
("timestamp", block_11_result.block->timestamp.to_time_point())
("parent_timestamp", block_11_result.parent_timestamp.to_time_point())
("dynamic_data", mvo()
("block_num", block_11_result.block->block_num())
("action_proofs", fc::variants())
Expand Down Expand Up @@ -551,6 +564,8 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
("witness_hash", block_12_result.level_2_commitments_digest)
("finality_mroot", block_12_result.finality_root)
)
("timestamp", block_12_result.block->timestamp.to_time_point())
("parent_timestamp", block_12_result.parent_timestamp.to_time_point())
("dynamic_data", mvo()
("block_num", block_12_result.block->block_num())
("action_proofs", fc::variants())
Expand All @@ -573,7 +588,7 @@ BOOST_AUTO_TEST_SUITE(svnn_ibc)
// we must first prove that block #11 became final, which makes the policy proposed in block #8 pending.
// The QC provided to prove this also proves a commitment from finalizers to this policy, so the smart contract can accept it.
action_trace check_heavy_proof_3_trace = cluster.node0.push_action("ibc"_n, "checkproof"_n, "ibc"_n, heavy_proof_3)->action_traces[0];

// now that we have successfully proven finalizer policy generation #2, the contract has it, and we can prove heavy_proof_4
action_trace check_heavy_proof_4_trace = cluster.node0.push_action("ibc"_n, "checkproof"_n, "ibc"_n, heavy_proof_4)->action_traces[0];

Expand Down
23 changes: 20 additions & 3 deletions unittests/test-contracts/savanna/common/savanna.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ namespace savanna {
//finality data
block_finality_data finality_data;

time_point timestamp;
time_point parent_timestamp;

//dynamic_data to be verified
dynamic_data_v0 dynamic_data;
Expand All @@ -365,11 +367,17 @@ namespace savanna {
checksum256 resolved_finality_digest;
checksum256 resolved_action_mroot;

time_point resolved_timestamp;
time_point resolved_parent_timestamp;

extended_block_data_internal(const extended_block_data& base) : extended_block_data(base){

resolved_finality_digest = block_finality_data_internal(base.finality_data).finality_digest();

resolved_action_mroot = base.dynamic_data.get_action_mroot();

resolved_timestamp = base.timestamp;
resolved_parent_timestamp = base.parent_timestamp;

}

checksum256 finality_leaf() const {
Expand All @@ -378,13 +386,16 @@ namespace savanna {
return hash;
}

EOSLIB_SERIALIZE(extended_block_data_internal, (finality_data.major_version)(finality_data.minor_version)(dynamic_data.block_num)(resolved_finality_digest)(resolved_action_mroot))
EOSLIB_SERIALIZE(extended_block_data_internal, (finality_data.major_version)(finality_data.minor_version)(dynamic_data.block_num)(resolved_timestamp)(resolved_parent_timestamp)(resolved_finality_digest)(resolved_action_mroot))
};

struct simple_block_data {
uint32_t major_version = 0 ;
uint32_t minor_version = 0 ;

time_point timestamp;
time_point parent_timestamp;

checksum256 finality_digest;

//dynamic_data to be verified
Expand All @@ -394,9 +405,15 @@ namespace savanna {
struct simple_block_data_internal : simple_block_data {
checksum256 resolved_action_mroot;

time_point resolved_timestamp;
time_point resolved_parent_timestamp;

simple_block_data_internal(const simple_block_data& base) : simple_block_data(base){

resolved_action_mroot = base.dynamic_data.get_action_mroot();

resolved_timestamp = base.timestamp;
resolved_parent_timestamp = base.parent_timestamp;
}

checksum256 finality_leaf() const {
Expand All @@ -405,7 +422,7 @@ namespace savanna {
return hash;
}

EOSLIB_SERIALIZE(simple_block_data_internal, (major_version)(minor_version)(dynamic_data.block_num)(finality_digest)(resolved_action_mroot))
EOSLIB_SERIALIZE(simple_block_data_internal, (major_version)(minor_version)(dynamic_data.block_num)(resolved_timestamp)(resolved_parent_timestamp)(finality_digest)(resolved_action_mroot))
};

using block_data_type = std::variant<simple_block_data, extended_block_data>;
Expand Down
16 changes: 16 additions & 0 deletions unittests/test-contracts/savanna/ibc/ibc.abi
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@
"name": "finality_data",
"type": "block_finality_data"
},
{
"name": "timestamp",
"type": "time_point"
},
{
"name": "parent_timestamp",
"type": "time_point"
},
{
"name": "dynamic_data",
"type": "dynamic_data_v0"
Expand Down Expand Up @@ -322,6 +330,14 @@
"name": "minor_version",
"type": "uint32"
},
{
"name": "timestamp",
"type": "time_point"
},
{
"name": "parent_timestamp",
"type": "time_point"
},
{
"name": "finality_digest",
"type": "checksum256"
Expand Down
Binary file modified unittests/test-contracts/savanna/ibc/ibc.wasm
Binary file not shown.