Skip to content
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
4 changes: 4 additions & 0 deletions .github/workflows/robustness.yml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ jobs:
- name: contracts-dice-join
env: DB_BACKEND=lmdb CONTRACTS=1 CONTRACT_DICE=1 JOIN_PRUNED_AT=500 JOIN_FULL=1 CONTRACTS_AFTER_AT=700 TARGET_SEQ=1300
contracts: true
# the same with sync_contract_execution=false: no re-execution while syncing, every state fetched
- name: contracts-dice-join-nosync-exec
env: DB_BACKEND=lmdb CONTRACTS=1 CONTRACT_DICE=1 JOIN_PRUNED_AT=500 JOIN_FULL=1 CONTRACTS_AFTER_AT=700 TARGET_SEQ=1300 SYNC_CONTRACT_EXECUTION=0
contracts: true
- name: contracts-crash
env: DB_BACKEND=lmdb CRASH_NODE=6 CONTRACTS=1 TARGET_SEQ=1600
contracts: true
Expand Down
4 changes: 4 additions & 0 deletions ci/testnet/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
# node reached CONTRACTS_AFTER_AT (default 0); the states are compared once every node,
# a joining one too, reached TARGET_SEQ. contracts.py sends everything through n1: a
# contract scenario never kills, partitions or slows n1
# SYNC_CONTRACT_EXECUTION=0: every node runs with sync_contract_execution=false (no contract
# re-execution while reading the blockchain; states fetched from the confidants once live)
# CONTRACT_DICE=1 (with CONTRACTS): also a Dice contract that reads its own balance, played three
# times before the restart test; a node that syncs through the plays re-executes them
# CONTRACT_LOAD_SECONDS (default 0, with CONTRACTS): after the calls, a load phase of that many
Expand Down Expand Up @@ -179,6 +181,7 @@ JOIN_FULL=${JOIN_FULL:-0}
CONTRACTS=${CONTRACTS:-0}
CONTRACTS_AFTER_AT=${CONTRACTS_AFTER_AT:-0}
CONTRACT_DICE=${CONTRACT_DICE:-0}
SYNC_CONTRACT_EXECUTION=${SYNC_CONTRACT_EXECUTION:-1}
[ "$CONTRACTS_AFTER_AT" -eq 0 ] || [ "$CONTRACTS_AFTER_AT" -le $(( ${TARGET_SEQ:-1100} - 100 )) ] \
|| { echo "CONTRACTS_AFTER_AT must be at most TARGET_SEQ - 100"; exit 1; }
PRUNE_NODE=${PRUNE_NODE:-0}
Expand Down Expand Up @@ -369,6 +372,7 @@ ipv6=false
traverse_nat=false
min_neighbours=1
max_neighbours=16
sync_contract_execution=$([ "$SYNC_CONTRACT_EXECUTION" = 0 ] && echo false || echo true)
round_elapse_time=$ROUND_ELAPSE_MS

[host_input]
Expand Down
5 changes: 5 additions & 0 deletions client/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const std::string PARAM_NAME_OBSERVER_WAIT_TIME = "observer_wait_time";
const std::string PARAM_NAME_ROUND_ELAPSE_TIME = "round_elapse_time";
const std::string PARAM_NAME_STORE_BLOCK_ELAPSE_TIME = "store_block_elapse_time";
const std::string PARAM_NAME_ALWAYS_EXECUTE_CONTRACTS = "always_execute_contracts";
const std::string PARAM_NAME_SYNC_CONTRACT_EXECUTION = "sync_contract_execution";
const std::string PARAM_NAME_MIN_COMPATIBLE_VERSION = "min_compatible_version";
const std::string PARAM_NAME_COMPATIBLE_VERSION = "compatible_version";
const std::string PARAM_NAME_TRAVERSE_NAT = "traverse_nat";
Expand Down Expand Up @@ -873,6 +874,9 @@ Config Config::readFromFile(const std::string& fileName) {
csdebug() << "No initial confidants specified.";
}

if (params.count(PARAM_NAME_SYNC_CONTRACT_EXECUTION) > 0) {
result.syncContractExecution_ = params.get<bool>(PARAM_NAME_SYNC_CONTRACT_EXECUTION);
}
if (params.count(PARAM_NAME_ALWAYS_EXECUTE_CONTRACTS) > 0) {
result.alwaysExecuteContracts_ = params.get<bool>(PARAM_NAME_ALWAYS_EXECUTE_CONTRACTS);
}
Expand Down Expand Up @@ -1343,6 +1347,7 @@ bool operator==(const Config& lhs, const Config& rhs) {
lhs.apiData_ == rhs.apiData_ &&
lhs.snapshotData_ == rhs.snapshotData_ &&
lhs.alwaysExecuteContracts_ == rhs.alwaysExecuteContracts_ &&
lhs.syncContractExecution_ == rhs.syncContractExecution_ &&
lhs.compatibleVersion_ == rhs.compatibleVersion_ &&
lhs.recreateIndex_ == rhs.recreateIndex_ &&
lhs.observerWaitTime_ == rhs.observerWaitTime_ &&
Expand Down
7 changes: 7 additions & 0 deletions client/config/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ class Config {

void dumpJSONKeys(const std::string& fName) const;

// re-execute contract calls while reading the blockchain (sync, start-up) to get their states
// provisionally; off: never, the states are fetched from the confidants once the node is live
bool syncContractExecution() const {
return syncContractExecution_;
}

bool alwaysExecuteContracts() const {
return alwaysExecuteContracts_;
}
Expand Down Expand Up @@ -442,6 +448,7 @@ class Config {

bool showBalanceChange_ = false;
bool alwaysExecuteContracts_ = false;
bool syncContractExecution_ = true;
bool recreateIndex_ = false;
bool newBlockchainTop_ = false;
bool autoShutdownEnabled_ = true;
Expand Down
4 changes: 4 additions & 0 deletions packaging/mainnet/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ min_compatible_version=503
; replaying some contracts (games that read their own balance) is not reproducible, so a syncing
; node can disagree with the network on a few balances by a fee and would then reject valid blocks
compatible_version=true
; true: contract calls are re-executed while syncing to get their states provisionally; the
; states that do not match the chain are fetched from the confidants once the node is live.
; false: no re-execution while syncing, every state is fetched (no executor needed to sync)
sync_contract_execution=true

[host_input]
port=9510
Expand Down
2 changes: 2 additions & 0 deletions solver/include/solver/smartcontracts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,8 @@ public slots:
StateFetcher state_fetcher_;
// the previous stored block was read (sync, start-up), not live: the next live one starts a fetch
bool was_reading_db_ = true;
// get_actual_state skipped a re-execution because of sync_contract_execution=off
bool sync_execution_skipped_ = false;
cs::RoundNumber last_state_summary_ = 0;
void on_live_block(cs::RoundNumber round);

Expand Down
14 changes: 13 additions & 1 deletion solver/src/smartcontracts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,13 @@ csdb::Transaction SmartContracts::get_actual_state(const csdb::Transaction& hash
}
}
}
// sync_contract_execution off: no re-execution while reading the blockchain, the state is
// fetched from the confidants once the node is live (an empty value marks it stale)
if (reading_db && tr_state.user_field_ids().count(new_state::Value) == 0 &&
!cs::ConfigHolder::instance().config()->syncContractExecution()) {
tr_state.add_user_field(new_state::Value, std::string{});
sync_execution_skipped_ = true;
}
// execute contract to get last state if state is not found in cache
if (tr_state.user_field_ids().count(new_state::Value) == 0) {
csdb::Transaction tr_start = get_transaction(ref_start, req_abs_addr);
Expand Down Expand Up @@ -1428,7 +1435,12 @@ csdb::Transaction SmartContracts::get_actual_state(const csdb::Transaction& hash
// a contract whose execution is not reproducible (e.g. one that reads its own balance) leaves its
// state unknown here, and the fees of its later emitted transactions can then be charged to an
// earlier initiator: this node's balances may differ from the network's by such fees
if (state_expected && tr_state.user_field(new_state::Value).value<std::string>().empty()) {
if (sync_execution_skipped_) {
// expected with sync_contract_execution off: not a warning
sync_execution_skipped_ = false;
csdebug() << kLogPrefix << "state of " << to_base58(absolute_address(hashed_state.target())) << " not re-executed while reading the blockchain";
}
else if (state_expected && tr_state.user_field(new_state::Value).value<std::string>().empty()) {
cswarning() << kLogPrefix << "state of " << to_base58(absolute_address(hashed_state.target()))
<< " declared by the block is not available" << (reading_db ? " while reading the blockchain" : "")
<< ", the contract state is out of date";
Expand Down
Loading