Skip to content
This repository was archived by the owner on Oct 4, 2019. It is now read-only.

Commit c81cee0

Browse files
authored
Merge pull request #1353 from GolosChain/1348-transit-to-cyberway
Transit to cyberway. #1348
2 parents 1f7cd4b + efdc585 commit c81cee0

24 files changed

Lines changed: 536 additions & 42 deletions

File tree

libraries/api/include/golos/api/witness_api_object.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace golos { namespace api {
3232
version running_version;
3333
hardfork_version hardfork_version_vote;
3434
time_point_sec hardfork_time_vote;
35+
time_point_sec transit_to_cyberway_vote = STEEMIT_GENESIS_TIME;
3536
};
3637

3738
} } // golos::api
@@ -42,4 +43,4 @@ FC_REFLECT(
4243
(id)(owner)(created)(url)(votes)(virtual_last_update)(virtual_position)(virtual_scheduled_time)
4344
(total_missed)(last_aslot)(last_confirmed_block_num)(pow_worker)(signing_key)(props)
4445
(sbd_exchange_rate)(last_sbd_exchange_update)(last_work)(running_version)(hardfork_version_vote)
45-
(hardfork_time_vote))
46+
(hardfork_time_vote)(transit_to_cyberway_vote))

libraries/api/witness_api_object.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ namespace golos { namespace api {
1010
virtual_last_update(w.virtual_last_update), virtual_position(w.virtual_position),
1111
virtual_scheduled_time(w.virtual_scheduled_time), last_work(w.last_work),
1212
running_version(w.running_version), hardfork_version_vote(w.hardfork_version_vote),
13-
hardfork_time_vote(w.hardfork_time_vote) {
13+
hardfork_time_vote(w.hardfork_time_vote), transit_to_cyberway_vote(w.transit_to_cyberway_vote) {
1414
}
1515
} } // golos::api

libraries/chain/chain_properties_evaluators.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,24 @@ namespace golos { namespace chain {
7979
}
8080
}
8181

82+
void transit_to_cyberway_evaluator::do_apply(const transit_to_cyberway_operation& o) {
83+
ASSERT_REQ_HF(STEEMIT_HARDFORK_0_21__1348, "transit_to_cyberway");
84+
85+
_db.get_account(o.owner); // verify owner exists
86+
auto& witness = _db.get_witness(o.owner);
87+
88+
GOLOS_CHECK_OP_PARAM(o, vote_to_transit, {
89+
GOLOS_CHECK_VALUE(o.vote_to_transit != (witness.transit_to_cyberway_vote != STEEMIT_GENESIS_TIME),
90+
"You should change your vote.");
91+
});
92+
93+
_db.modify(witness, [&](witness_object& w) {
94+
if (o.vote_to_transit) {
95+
w.transit_to_cyberway_vote = _db.head_block_time();
96+
} else {
97+
w.transit_to_cyberway_vote = STEEMIT_GENESIS_TIME;
98+
}
99+
});
100+
}
101+
82102
} } // golos::chain

libraries/chain/database.cpp

Lines changed: 102 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,8 @@ namespace golos { namespace chain {
10731073
GOLOS_ASSERT(fc::raw::pack_size(trx) <= (get_dynamic_global_properties().maximum_block_size - 256),
10741074
golos::protocol::tx_too_long, "Transaction data is too long. Maximum transaction size ${max} bytes",
10751075
("max",get_dynamic_global_properties().maximum_block_size - 256));
1076+
GOLOS_ASSERT(!is_transit_enabled(), golos::transit_enabled_exception,
1077+
"Migrating to CyberWay disabled transaction accepting to prevent user actions lost.");
10761078
with_weak_write_lock([&]() {
10771079
detail::with_producing(*this, [&]() {
10781080
_push_transaction(trx, skip);
@@ -1162,7 +1164,9 @@ namespace golos { namespace chain {
11621164

11631165
uint64_t postponed_tx_count = 0;
11641166
// pop pending state (reset to head block state)
1165-
for (const signed_transaction &tx : _pending_tx) {
1167+
if (is_transit_enabled()) {
1168+
wlog("Migrating to CyberWay disables generating blocks with transactions.");
1169+
} else for (const signed_transaction &tx : _pending_tx) {
11661170
// Only include transactions that have not expired yet for currently generating block,
11671171
// this should clear problem transactions and allow block production to continue
11681172

@@ -1475,6 +1479,58 @@ namespace golos { namespace chain {
14751479
}
14761480
}
14771481

1482+
bool database::is_transit_enabled() const {
1483+
return
1484+
has_hardfork(STEEMIT_HARDFORK_0_21__1348) &&
1485+
get_dynamic_global_properties().transit_block_num != std::numeric_limits<uint32_t>::max();
1486+
}
1487+
1488+
void database::process_transit_to_cyberway(const signed_block& b, uint32_t skip) {
1489+
if (!has_hardfork(STEEMIT_HARDFORK_0_21__1348)) {
1490+
return;
1491+
}
1492+
1493+
const auto& gpo = get_dynamic_global_properties();
1494+
1495+
if (!is_transit_enabled()) {
1496+
vector<account_name_type> transit_witnesses;
1497+
transit_witnesses.reserve(STEEMIT_MAX_WITNESSES);
1498+
1499+
uint32_t i;
1500+
const auto& wso = get_witness_schedule_object();
1501+
for (i = 0; i < wso.num_scheduled_witnesses; ++i) {
1502+
auto& witness = get_witness(wso.current_shuffled_witnesses[i]);
1503+
if (witness.schedule != witness_object::top19) {
1504+
//skip
1505+
} else if (witness.transit_to_cyberway_vote != STEEMIT_GENESIS_TIME) {
1506+
transit_witnesses.push_back(witness.owner);
1507+
}
1508+
}
1509+
1510+
if (transit_witnesses.size() >= STEEMIT_TRANSIT_REQUIRED_WITNESSES) {
1511+
modify(gpo, [&](auto& o) {
1512+
i = 0;
1513+
o.transit_block_num = b.block_num();
1514+
for (auto owner: transit_witnesses) {
1515+
o.transit_witnesses[i++] = owner;
1516+
}
1517+
});
1518+
} else {
1519+
return;
1520+
}
1521+
}
1522+
1523+
if (is_transit_enabled()) {
1524+
if (skip & skip_block_log) {
1525+
set_revision(gpo.head_block_number);
1526+
}
1527+
1528+
if (gpo.transit_block_num == gpo.last_irreversible_block_num) {
1529+
STEEMIT_TRY_NOTIFY(transit_to_cyberway, b.block_num(), skip);
1530+
}
1531+
}
1532+
}
1533+
14781534
void database::update_witness_schedule4() {
14791535
vector<account_name_type> active_witnesses;
14801536
active_witnesses.reserve(STEEMIT_MAX_WITNESSES);
@@ -3057,6 +3113,7 @@ namespace golos { namespace chain {
30573113
_my->_evaluator_registry.register_evaluator<delegate_vesting_shares_evaluator>();
30583114
_my->_evaluator_registry.register_evaluator<delegate_vesting_shares_with_interest_evaluator>();
30593115
_my->_evaluator_registry.register_evaluator<reject_vesting_shares_delegation_evaluator>();
3116+
_my->_evaluator_registry.register_evaluator<transit_to_cyberway_evaluator>();
30603117
_my->_evaluator_registry.register_evaluator<proposal_create_evaluator>();
30613118
_my->_evaluator_registry.register_evaluator<proposal_update_evaluator>();
30623119
_my->_evaluator_registry.register_evaluator<proposal_delete_evaluator>();
@@ -3589,6 +3646,11 @@ namespace golos { namespace chain {
35893646
);
35903647
}
35913648

3649+
if (is_transit_enabled()) {
3650+
FC_ASSERT(next_block.transactions.empty(),
3651+
"Migrating to CyberWay disabled accepting blocks with transactions.");
3652+
}
3653+
35923654
for (const auto &trx : next_block.transactions) {
35933655
/* We do not need to push the undo state for each transaction
35943656
* because they either all apply and are valid or the
@@ -3610,33 +3672,43 @@ namespace golos { namespace chain {
36103672
update_last_irreversible_block(skip);
36113673

36123674
create_block_summary(next_block);
3613-
clear_expired_proposals();
3614-
clear_expired_transactions();
3615-
clear_expired_orders();
3616-
clear_expired_delegations();
3675+
3676+
if (is_transit_enabled()) {
3677+
wlog("Migrating to Cyberway disables the processes to prevent lost of account balances");
3678+
} else {
3679+
clear_expired_proposals();
3680+
clear_expired_transactions();
3681+
clear_expired_orders();
3682+
clear_expired_delegations();
3683+
}
3684+
36173685
update_witness_schedule();
36183686

3619-
update_median_feed();
3620-
update_virtual_supply();
3687+
if (!is_transit_enabled()) {
3688+
update_median_feed();
3689+
update_virtual_supply();
36213690

3622-
clear_null_account_balance();
3623-
process_funds();
3624-
process_conversions();
3625-
process_comment_cashout();
3626-
process_vesting_withdrawals();
3627-
process_savings_withdraws();
3628-
pay_liquidity_reward();
3629-
update_virtual_supply();
3691+
clear_null_account_balance();
3692+
process_funds();
3693+
process_conversions();
3694+
process_comment_cashout();
3695+
process_vesting_withdrawals();
3696+
process_savings_withdraws();
3697+
pay_liquidity_reward();
3698+
update_virtual_supply();
36303699

3631-
account_recovery_processing();
3632-
expire_escrow_ratification();
3633-
process_decline_voting_rights();
3700+
account_recovery_processing();
3701+
expire_escrow_ratification();
3702+
process_decline_voting_rights();
3703+
}
36343704

36353705
process_hardforks();
36363706

36373707
// notify observers that the block has been applied
36383708
notify_applied_block(next_block);
36393709

3710+
process_transit_to_cyberway(next_block, skip);
3711+
36403712
notify_changed_objects();
36413713

36423714
} FC_CAPTURE_LOG_AND_RETHROW((next_block.block_num()))
@@ -3903,9 +3975,7 @@ namespace golos { namespace chain {
39033975
modify(witness_missed, [&](witness_object &w) {
39043976
w.total_missed++;
39053977
if (has_hardfork(STEEMIT_HARDFORK_0_14__278)) {
3906-
if (head_block_num() -
3907-
w.last_confirmed_block_num >
3908-
STEEMIT_BLOCKS_PER_DAY) {
3978+
if (head_block_num() - w.last_confirmed_block_num > STEEMIT_BLOCKS_PER_DAY) {
39093979
w.signing_key = public_key_type();
39103980
push_virtual_operation(shutdown_witness_operation(w.owner));
39113981
}
@@ -4076,10 +4146,18 @@ namespace golos { namespace chain {
40764146
b->last_confirmed_block_num;
40774147
});
40784148

4079-
uint32_t new_last_irreversible_block_num = wit_objs[offset]->last_confirmed_block_num;
4149+
uint32_t new_last_irreversible_block_num = std::min(
4150+
uint32_t(wit_objs[offset]->last_confirmed_block_num),
4151+
_fixed_irreversible_block_num);
4152+
4153+
if (new_last_irreversible_block_num > dpo.last_irreversible_block_num) {
4154+
if (is_transit_enabled() &&
4155+
dpo.transit_block_num > dpo.last_irreversible_block_num &&
4156+
dpo.transit_block_num <= new_last_irreversible_block_num
4157+
) {
4158+
new_last_irreversible_block_num = dpo.transit_block_num;
4159+
}
40804160

4081-
if (new_last_irreversible_block_num >
4082-
dpo.last_irreversible_block_num) {
40834161
modify(dpo, [&](dynamic_global_property_object &_dpo) {
40844162
_dpo.last_irreversible_block_num = new_last_irreversible_block_num;
40854163
});

libraries/chain/hardfork.d/0_21.hf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#ifndef STEEMIT_HARDFORK_0_21
22
#define STEEMIT_HARDFORK_0_21 21
33

4+
#define STEEMIT_HARDFORK_0_21__1348 (STEEMIT_HARDFORK_0_21) // Transit to CyberWay
5+
6+
47
#ifdef STEEMIT_BUILD_TESTNET
58
#define STEEMIT_HARDFORK_0_21_TIME 1563613200 // 20 jul 2019 12:00:00 MSK
69
#else

libraries/chain/include/golos/chain/database.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ namespace golos { namespace chain {
5858
_is_generating = p;
5959
}
6060

61+
bool is_transit_enabled() const;
62+
6163
bool _is_producing = false;
6264
bool _is_generating = false;
6365
bool _is_testing = false; ///< set for tests to avoid low free memory spam
6466
bool _log_hardforks = true;
67+
uint32_t _fixed_irreversible_block_num = UINT32_MAX;
6568

6669
enum validation_steps {
6770
skip_nothing = 0,
@@ -328,6 +331,11 @@ namespace golos { namespace chain {
328331
*/
329332
fc::signal<void(const signed_transaction &)> on_applied_transaction;
330333

334+
/**
335+
* This signal is emitted when required number of votes is reached to transit to CyberWay
336+
*/
337+
fc::signal<void(const uint32_t, const uint32_t)> transit_to_cyberway;
338+
331339
/**
332340
* Emitted After a block has been applied and committed. The callback
333341
* should not yield and should execute quickly.
@@ -581,6 +589,8 @@ namespace golos { namespace chain {
581589

582590
void update_witness_schedule4();
583591

592+
void process_transit_to_cyberway(const signed_block& b, uint32_t skip);
593+
584594
void update_median_witness_props();
585595

586596
void clear_null_account_balance();

libraries/chain/include/golos/chain/global_property_object.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ namespace golos {
144144
uint32_t vote_regeneration_per_day = 40;
145145

146146
uint16_t custom_ops_bandwidth_multiplier = STEEMIT_CUSTOM_OPS_BANDWIDTH_MULTIPLIER;
147+
148+
uint32_t transit_block_num = UINT32_MAX;
149+
fc::array<account_name_type, STEEMIT_MAX_WITNESSES> transit_witnesses;
147150
};
148151

149152
typedef multi_index_container <
@@ -189,5 +192,7 @@ FC_REFLECT((golos::chain::dynamic_global_property_object),
189192
(vote_regeneration_per_day)
190193
(custom_ops_bandwidth_multiplier)
191194
(is_forced_min_price)
195+
(transit_block_num)
196+
(transit_witnesses)
192197
)
193198
CHAINBASE_SET_INDEX_TYPE(golos::chain::dynamic_global_property_object, golos::chain::dynamic_global_property_index)

libraries/chain/include/golos/chain/steem_evaluator.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ namespace golos { namespace chain {
5555
DEFINE_EVALUATOR(break_free_referral)
5656
DEFINE_EVALUATOR(delegate_vesting_shares_with_interest)
5757
DEFINE_EVALUATOR(reject_vesting_shares_delegation)
58+
DEFINE_EVALUATOR(transit_to_cyberway)
5859

5960
class proposal_create_evaluator: public evaluator_impl<proposal_create_evaluator> {
6061
public:

libraries/chain/include/golos/chain/witness_objects.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ namespace golos { namespace chain {
115115

116116
hardfork_version hardfork_version_vote;
117117
time_point_sec hardfork_time_vote = STEEMIT_GENESIS_TIME;
118+
119+
time_point_sec transit_to_cyberway_vote = STEEMIT_GENESIS_TIME;
118120
};
119121

120122

@@ -247,7 +249,7 @@ FC_REFLECT(
247249
(golos::chain::witness_object),
248250
(id)(owner)(created)(url)(votes)(schedule)(virtual_last_update)(virtual_position)(virtual_scheduled_time)(total_missed)
249251
(last_aslot)(last_confirmed_block_num)(pow_worker)(signing_key)(props)(sbd_exchange_rate)(last_sbd_exchange_update)
250-
(last_work)(running_version)(hardfork_version_vote)(hardfork_time_vote))
252+
(last_work)(running_version)(hardfork_version_vote)(hardfork_time_vote)(transit_to_cyberway_vote))
251253

252254
CHAINBASE_SET_INDEX_TYPE(golos::chain::witness_object, golos::chain::witness_index)
253255

libraries/protocol/include/golos/protocol/config.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
#define STEEMIT_BLOCKS_PER_YEAR (365*24*60*60/STEEMIT_BLOCK_INTERVAL)
5050
#define STEEMIT_BLOCKS_PER_DAY (24*60*60/STEEMIT_BLOCK_INTERVAL)
5151
#define STEEMIT_START_VESTING_BLOCK (STEEMIT_BLOCKS_PER_DAY / 512)
52-
#define STEEMIT_START_MINER_VOTING_BLOCK (60*10/STEEMIT_BLOCK_INTERVAL)
52+
#define STEEMIT_START_MINER_VOTING_BLOCK (60/STEEMIT_BLOCK_INTERVAL)
5353
#define STEEMIT_FIRST_CASHOUT_TIME (fc::time_point_sec(1476788400 + STEEMIT_BLOCK_INTERVAL))
5454

5555
#define STEEMIT_INIT_MINER_NAME "cyberfounder"
@@ -61,6 +61,7 @@
6161
#define STEEMIT_MAX_MINER_WITNESSES 1
6262
#define STEEMIT_MAX_RUNNER_WITNESSES 1
6363
#define STEEMIT_MAX_WITNESSES (STEEMIT_MAX_VOTED_WITNESSES+STEEMIT_MAX_MINER_WITNESSES+STEEMIT_MAX_RUNNER_WITNESSES) /// 21 is more than enough
64+
#define STEEMIT_TRANSIT_REQUIRED_WITNESSES 1 // 16 from top19 -> This guarantees 75% participation on all subsequent rounds.
6465
#define STEEMIT_HARDFORK_REQUIRED_WITNESSES 1 // 17 of the 20 dpos witnesses (19 elected and 1 virtual time) required for hardfork. This guarantees 75% participation on all subsequent rounds.
6566
#define STEEMIT_MAX_TIME_UNTIL_EXPIRATION (60*60) // seconds, aka: 1 hour
6667
#define STEEMIT_MAX_MEMO_SIZE 2048
@@ -293,6 +294,7 @@
293294
#define STEEMIT_MAX_MINER_WITNESSES 1
294295
#define STEEMIT_MAX_RUNNER_WITNESSES 1
295296
#define STEEMIT_MAX_WITNESSES (STEEMIT_MAX_VOTED_WITNESSES+STEEMIT_MAX_MINER_WITNESSES+STEEMIT_MAX_RUNNER_WITNESSES) /// 21 is more than enough
297+
#define STEEMIT_TRANSIT_REQUIRED_WITNESSES 16 // 16 from top19 -> This guarantees 75% participation on all subsequent rounds.
296298
#define STEEMIT_HARDFORK_REQUIRED_WITNESSES 17 // 17 of the 20 dpos witnesses (19 elected and 1 virtual time) required for hardfork. This guarantees 75% participation on all subsequent rounds.
297299
#define STEEMIT_MAX_TIME_UNTIL_EXPIRATION (60*60) // seconds, aka: 1 hour
298300
#define STEEMIT_MAX_MEMO_SIZE 2048

0 commit comments

Comments
 (0)