Skip to content

Commit

Permalink
Merge remote-tracking branch 'spring/main' into GH-5-diff-policies
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed May 6, 2024
2 parents ac63786 + d411eea commit c528f0c
Show file tree
Hide file tree
Showing 41 changed files with 1,481 additions and 623 deletions.
4 changes: 2 additions & 2 deletions .cicd/defaults.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"cdt":{
"target":"hotstuff_integration",
"prerelease":false
"target":"main",
"prerelease":true
},
"referencecontracts":{
"ref":"main"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ jobs:
run: |
zstdcat build.tar.zst | tar x
- if: ${{ matrix.test == 'build-tree' }}
name: Set leap_DIR env var
name: Set spring_DIR env var
run: |
echo "leap_DIR=$PWD/build/lib/cmake/leap" >> "$GITHUB_ENV"
echo "spring_DIR=$PWD/build/lib/cmake/spring" >> "$GITHUB_ENV"
- if: ${{ matrix.test == 'make-dev-install' }}
name: spring dev-install
run: |
Expand Down Expand Up @@ -336,7 +336,7 @@ jobs:
apt-get -y install cmake build-essential
- name: Build & Test reference-contracts
run: |
cmake -S reference-contracts -B reference-contracts/build -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=On -DSYSTEM_ENABLE_LEAP_VERSION_CHECK=Off -DSYSTEM_ENABLE_CDT_VERSION_CHECK=Off
cmake -S reference-contracts -B reference-contracts/build -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=On -DSYSTEM_ENABLE_SPRING_VERSION_CHECK=Off -DSYSTEM_ENABLE_CDT_VERSION_CHECK=Off
cmake --build reference-contracts/build -- -j $(nproc)
cd reference-contracts/build/tests
ctest --output-on-failure -j $(nproc)
Expand Down
14 changes: 0 additions & 14 deletions libraries/chain/block_header_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ namespace eosio::chain {
// gets updated if a protocol feature causes a breaking change to light block
// header validation

// data for finality_digest
struct finality_digest_data_v1 {
uint32_t major_version{light_header_protocol_version_major};
uint32_t minor_version{light_header_protocol_version_minor};
uint32_t active_finalizer_policy_generation {0};
digest_type finality_tree_digest;
digest_type active_finalizer_policy_and_base_digest;
};

// compute base_digest explicitly because of pointers involved.
digest_type block_header_state::compute_base_digest() const {
digest_type::encoder enc;
Expand Down Expand Up @@ -76,8 +67,6 @@ const vector<digest_type>& block_header_state::get_new_protocol_feature_activati
return detail::get_new_protocol_feature_activations(header_exts);
}

#warning Add last_proposed_finalizer_policy_generation to snapshot_block_header_state_v3, see header file TODO

// -------------------------------------------------------------------------------------------------
// `finish_next` updates the next `block_header_state` according to the contents of the
// header extensions (either new protocol_features or instant_finality_extension) applicable to this
Expand Down Expand Up @@ -298,6 +287,3 @@ block_header_state block_header_state::next(const signed_block_header& h, valida

} // namespace eosio::chain

FC_REFLECT( eosio::chain::finality_digest_data_v1,
(major_version)(minor_version)(active_finalizer_policy_generation)
(finality_tree_digest)(active_finalizer_policy_and_base_digest) )
271 changes: 172 additions & 99 deletions libraries/chain/controller.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion libraries/chain/finality/finalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void my_finalizers_t::set_keys(const std::map<std::string, std::string>& finaliz
// --------------------------------------------------------------------------------------------
// Can be called either:
// - when transitioning to IF (before any votes are to be sent)
// - at leap startup, if we start at a block which is either within or past the IF transition.
// - at spring startup, if we start at a block which is either within or past the IF transition.
// In either case, we are never updating existing finalizer safety information. This is only
// to ensure that the safety information will have defaults that ensure safety as much as
// possible, and allow for liveness which will allow the finalizers to eventually vote.
Expand Down
17 changes: 17 additions & 0 deletions libraries/chain/include/eosio/chain/block_header_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ namespace detail { struct schedule_info; };
constexpr uint32_t light_header_protocol_version_major = 1;
constexpr uint32_t light_header_protocol_version_minor = 0;

// data for finality_digest
struct finality_digest_data_v1 {
uint32_t major_version{light_header_protocol_version_major};
uint32_t minor_version{light_header_protocol_version_minor};
uint32_t active_finalizer_policy_generation {0};
digest_type finality_tree_digest;
digest_type active_finalizer_policy_and_base_digest;

};

// ------------------------------------------------------------------------------------------
// this is used for tracking in-flight `finalizer_policy` changes, which have been requested,
// but are not activated yet. This struct is associated to a block_number in the
Expand Down Expand Up @@ -69,6 +79,11 @@ struct block_header_state {
proposer_policy_ptr active_proposer_policy; // producer authority schedule, supports `digest()`

// block time when proposer_policy will become active
// current algorithm only two entries possible, for the next,next round and one for block round after that
// The active time is the next,next producer round. For example,
// round A [1,2,..12], next_round B [1,2,..12], next_next_round C [1,2,..12], D [1,2,..12]
// If proposed in A1, A2, .. A12 becomes active in C1
// If proposed in B1, B2, .. B12 becomes active in D1
flat_map<block_timestamp_type, proposer_policy_ptr> proposer_policies;

// track in-flight finalizer policies. This is a `multimap` because the same block number
Expand Down Expand Up @@ -128,3 +143,5 @@ FC_REFLECT( eosio::chain::block_header_state, (block_id)(header)
(activated_protocol_features)(core)(active_finalizer_policy)
(active_proposer_policy)(proposer_policies)(finalizer_policies)
(finalizer_policy_generation)(header_exts))

FC_REFLECT( eosio::chain::finality_digest_data_v1, (major_version)(minor_version)(active_finalizer_policy_generation)(finality_tree_digest)(active_finalizer_policy_and_base_digest) )
2 changes: 2 additions & 0 deletions libraries/chain/include/eosio/chain/chain_id_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace chain {
namespace legacy {
struct snapshot_global_property_object_v3;
struct snapshot_global_property_object_v4;
struct snapshot_global_property_object_v5;
}

struct chain_id_type : public fc::sha256 {
Expand Down Expand Up @@ -60,6 +61,7 @@ namespace chain {
friend struct snapshot_global_property_object;
friend struct legacy::snapshot_global_property_object_v3;
friend struct legacy::snapshot_global_property_object_v4;
friend struct legacy::snapshot_global_property_object_v5;
};

} } // namespace eosio::chain
Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ namespace eosio::chain {

// returns nullptr pre-savanna
finalizer_policy_ptr head_active_finalizer_policy()const;
// returns nullptr pre-savanna, thread-safe, block_num according to branch curresponding to id
finalizer_policy_ptr active_finalizer_policy(const block_id_type& id, block_num_type block_num)const;

void set_if_irreversible_block_id(const block_id_type& id);
uint32_t if_irreversible_block_num() const;
Expand Down
10 changes: 7 additions & 3 deletions libraries/chain/include/eosio/chain/database_header_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ namespace eosio { namespace chain {
* - 1 : initial version, prior to this no `database_header_object` existed in the shared memory file but
* no changes to its format were made so it can be safely added to existing databases
* - 2 : shared_authority now holds shared_key_weights & shared_public_keys
* change from producer_key to producer_authority for many in-memory structures
* change from producer_key to producer_authority for many in-memory structures.
* NOTE: The version has not been updated since EOSIO 2.0. Version 2.0 implies
* all changes up to and including Leap 5.0.
* - 3 : global_property_object now holds proposed_fin_pol_block_num and proposed_fin_pol,
* and removes kv_configuration in Spring 1.0
*/

static constexpr uint32_t current_version = 2;
static constexpr uint32_t minimum_version = 2;
static constexpr uint32_t current_version = 3;
static constexpr uint32_t minimum_version = 3;

id_type id;
uint32_t version = current_version;
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/include/eosio/chain/finality/finalizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// are an essential part of the Savanna consensus algorithm.
// - every time a finalizer votes, it may update its own safety info in memory
// - finalizer safety info is appropriately initialized (iff not already present
// in the persistent file) at Leap startup.
// in the persistent file) at Spring startup.
//
// my_finalizers_t:
// ---------------
Expand Down Expand Up @@ -77,7 +77,7 @@ namespace eosio::chain {
mutable fc::datastream<fc::cfile> persist_file; // we want to keep the file open for speed
std::map<bls_public_key, finalizer> finalizers; // the active finalizers for this node, loaded at startup, not mutated afterwards
fsi_map inactive_safety_info; // loaded at startup, not mutated afterwards
fsi_t default_fsi = fsi_t::unset_fsi(); // default provided at leap startup
fsi_t default_fsi = fsi_t::unset_fsi(); // default provided at spring startup
mutable bool inactive_safety_info_written{false};

public:
Expand Down
86 changes: 57 additions & 29 deletions libraries/chain/include/eosio/chain/global_property_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include <eosio/chain/kv_config.hpp>
#include <eosio/chain/wasm_config.hpp>
#include <eosio/chain/producer_schedule.hpp>
#include <eosio/chain/finality/finalizer_policy.hpp>
#include <eosio/chain/snapshot.hpp>
#include <eosio/chain/genesis_state.hpp>
#include <chainbase/chainbase.hpp>
#include "multi_index_includes.hpp"

Expand Down Expand Up @@ -54,6 +56,21 @@ namespace eosio::chain {
kv_database_config kv_configuration;
wasm_config wasm_configuration;
};
struct snapshot_global_property_object_v5 {
// minimum_version and maximum_version refer to chain_snapshot_header
// version. snapshot_global_property_object_v5 applies to version 5 & 6
static constexpr uint32_t minimum_version = 5;
static constexpr uint32_t maximum_version = 6;
static_assert(chain_snapshot_header::minimum_compatible_version <= maximum_version,
"snapshot_global_property_object_v5 is no longer needed");

std::optional<block_num_type> proposed_schedule_block_num;
producer_authority_schedule proposed_schedule;
chain_config configuration;
chain_id_type chain_id;
kv_database_config kv_configuration;
wasm_config wasm_configuration;
};
}

/**
Expand All @@ -72,40 +89,45 @@ namespace eosio::chain {
shared_producer_authority_schedule proposed_schedule;
chain_config configuration;
chain_id_type chain_id;
kv_database_config kv_configuration;
wasm_config wasm_configuration;

void initalize_from( const legacy::snapshot_global_property_object_v2& legacy, const chain_id_type& chain_id_val,
const kv_database_config& kv_config_val, const wasm_config& wasm_config_val ) {
// Note: proposed_fin_pol_block_num and proposed_fin_pol are used per block
// and reset after uses. They do not need to be stored in snapshots.
std::optional<block_num_type> proposed_fin_pol_block_num;
finalizer_policy proposed_fin_pol;

// For snapshot_global_property_object_v2 and initialize_from( const T& legacy )
template<typename T>
void initialize_from( const T& legacy, const chain_id_type& chain_id_val) {
proposed_schedule_block_num = legacy.proposed_schedule_block_num;
proposed_schedule = producer_authority_schedule(legacy.proposed_schedule);

if constexpr (std::is_same_v<T, legacy::snapshot_global_property_object_v2>) {
proposed_schedule = producer_authority_schedule(legacy.proposed_schedule);
} else {
proposed_schedule = legacy.proposed_schedule;
}

configuration = legacy.configuration;
chain_id = chain_id_val;
kv_configuration = kv_config_val;
wasm_configuration = wasm_config_val;
}

void initalize_from( const legacy::snapshot_global_property_object_v3& legacy,
const kv_database_config& kv_config_val, const wasm_config& wasm_config_val ) {
proposed_schedule_block_num = legacy.proposed_schedule_block_num;
proposed_schedule = legacy.proposed_schedule;
configuration = legacy.configuration;
chain_id = legacy.chain_id;
kv_configuration = kv_config_val;
wasm_configuration = wasm_config_val;
if constexpr (std::is_same_v<T, legacy::snapshot_global_property_object_v2> ||
std::is_same_v<T, legacy::snapshot_global_property_object_v3>) {
wasm_configuration = genesis_state::default_initial_wasm_configuration;
} else {
wasm_configuration = legacy.wasm_configuration;
}

// proposed_fin_pol_block_num and proposed_fin_pol are set to default values.
proposed_fin_pol_block_num = std::nullopt;
proposed_fin_pol = finalizer_policy{};
}

void initalize_from( const legacy::snapshot_global_property_object_v4& legacy ) {
proposed_schedule_block_num = legacy.proposed_schedule_block_num;
proposed_schedule = legacy.proposed_schedule;
configuration = legacy.configuration;
chain_id = legacy.chain_id;
kv_configuration = legacy.kv_configuration;
wasm_configuration = legacy.wasm_configuration;
// For snapshot_global_property_object v3, v4, and v5
template<typename T>
void initialize_from( const T& legacy ) {
initialize_from(legacy, legacy.chain_id);
}
};


using global_property_multi_index = chainbase::shared_multi_index_container<
global_property_object,
indexed_by<
Expand All @@ -120,7 +142,6 @@ namespace eosio::chain {
producer_authority_schedule proposed_schedule;
chain_config configuration;
chain_id_type chain_id;
kv_database_config kv_configuration;
wasm_config wasm_configuration;
};

Expand All @@ -132,16 +153,19 @@ namespace eosio::chain {

static snapshot_global_property_object to_snapshot_row( const global_property_object& value, const chainbase::database& ) {
return {value.proposed_schedule_block_num, producer_authority_schedule::from_shared(value.proposed_schedule),
value.configuration, value.chain_id, value.kv_configuration, value.wasm_configuration};
value.configuration, value.chain_id, value.wasm_configuration};
}

static void from_snapshot_row( snapshot_global_property_object&& row, global_property_object& value, chainbase::database& ) {
value.proposed_schedule_block_num = row.proposed_schedule_block_num;
value.proposed_schedule = row.proposed_schedule;
value.configuration = row.configuration;
value.chain_id = row.chain_id;
value.kv_configuration = row.kv_configuration;
value.wasm_configuration = row.wasm_configuration;
// Snapshot does not contain proposed_fin_pol_block_num and proposed_fin_pol.
// Return their default values
value.proposed_fin_pol_block_num = std::nullopt;
value.proposed_fin_pol = finalizer_policy{};
}
};
}
Expand Down Expand Up @@ -176,7 +200,7 @@ CHAINBASE_SET_INDEX_TYPE(eosio::chain::dynamic_global_property_object,
eosio::chain::dynamic_global_property_multi_index)

FC_REFLECT(eosio::chain::global_property_object,
(proposed_schedule_block_num)(proposed_schedule)(configuration)(chain_id)(kv_configuration)(wasm_configuration)
(proposed_schedule_block_num)(proposed_schedule)(configuration)(chain_id)(wasm_configuration)
)

FC_REFLECT(eosio::chain::legacy::snapshot_global_property_object_v2,
Expand All @@ -191,10 +215,14 @@ FC_REFLECT(eosio::chain::legacy::snapshot_global_property_object_v4,
(proposed_schedule_block_num)(proposed_schedule)(configuration)(chain_id)(kv_configuration)(wasm_configuration)
)

FC_REFLECT(eosio::chain::snapshot_global_property_object,
FC_REFLECT(eosio::chain::legacy::snapshot_global_property_object_v5,
(proposed_schedule_block_num)(proposed_schedule)(configuration)(chain_id)(kv_configuration)(wasm_configuration)
)

FC_REFLECT(eosio::chain::snapshot_global_property_object,
(proposed_schedule_block_num)(proposed_schedule)(configuration)(chain_id)(wasm_configuration)
)

FC_REFLECT(eosio::chain::dynamic_global_property_object,
(global_action_sequence)
)
8 changes: 6 additions & 2 deletions libraries/chain/include/eosio/chain/kv_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ namespace eosio { namespace chain {
* The key and value limits apply when adding or modifying elements. They may be reduced
* below existing database entries.
*
* This has been marked for removal at a later date, when v7 snapshots are deemed necessary.
* kv_database_config will be removed as part of that effort.
* Current uses of kv_database_config were removed in Spring 1.0.
* Do not use it in the future.
*
* The file is kept for backward compatibilities as kv_database_config was used
* in snapshots containing legacy::snapshot_global_property_object_v4 and
* legacy::snapshot_global_property_object_v5.
*/
struct kv_database_config {
std::uint32_t max_key_size = 0; ///< the maximum size in bytes of a key
Expand Down
Loading

0 comments on commit c528f0c

Please sign in to comment.