Skip to content

Commit 4887629

Browse files
authored
fix circulating (#617)
Signed-off-by: turuslan <[email protected]>
1 parent be79e14 commit 4887629

File tree

14 files changed

+44
-71
lines changed

14 files changed

+44
-71
lines changed

core/api/full_node/make.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ namespace fc::api {
588588
if (!message.gas_limit) {
589589
message.gas_limit = kBlockGasLimit;
590590
}
591-
auto env = std::make_shared<Env>(env_context, ts_branch, context.tipset);
591+
OUTCOME_TRY(env, Env::make(env_context, ts_branch, context.tipset));
592592
InvocResult result;
593593
result.message = message;
594594
OUTCOME_TRYA(result.receipt, env->applyImplicitMessage(message));

core/api/wallet/local_wallet.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace fc::api {
7171
std::sort(addresses.begin(), addresses.end());
7272
auto last = std::unique(addresses.begin(), addresses.end());
7373
addresses.erase(last, addresses.end());
74-
return addresses;
74+
return std::move(addresses);
7575
};
7676
api->WalletSetDefault = [=](auto &address) -> outcome::result<void> {
7777
wallet_default_address->setCbor(address);

core/const.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ namespace fc {
5151
DEFINE(kUpgradeHyperdriveHeight){892800};
5252
// 2021-10-26T13:30:00Z
5353
DEFINE(kUpgradeChocolateHeight){1231620};
54-
// 2021-03-01T14:00:00Z
55-
DEFINE(kUpgradeOhSnapHeight){1594560};
54+
// 2022-03-01T15:00:00Z
55+
DEFINE(kUpgradeOhSnapHeight){1594680};
5656

5757
DEFINE(kBreezeGasTampingDuration){120};
5858

core/node/blocksync_request.cpp

+2-36
Original file line numberDiff line numberDiff line change
@@ -347,33 +347,10 @@ namespace fc::sync::blocksync {
347347
done();
348348

349349
if (result_->error) {
350-
int64_t dr = 0;
351-
const auto &category =
352-
std::error_code(BlocksyncRequest::Error::kTimeout).category();
353-
if (result_->error.category() == category) {
354-
switch (result_->error.value()) {
355-
case int(BlocksyncRequest::Error::kStoreCidsMismatch):
356-
dr = -700;
357-
break;
358-
case int(BlocksyncRequest::Error::kInconsistentResponse):
359-
dr = -500;
360-
break;
361-
case int(BlocksyncRequest::Error::kTimeout):
362-
dr = -200;
363-
break;
364-
default:
365-
break;
366-
}
367-
} else {
368-
// stream and other errors
369-
dr -= 200;
370-
}
371-
log()->debug("peer {}, error {}, dr={}",
350+
log()->debug("peer {}, error {}",
372351
(result_->from.has_value() ? result_->from->toBase58()
373352
: "unknown"),
374-
result_->error.message(),
375-
dr);
376-
result_->delta_rating += dr;
353+
result_->error.message());
377354
}
378355

379356
if (call_now) {
@@ -447,15 +424,9 @@ namespace fc::sync::blocksync {
447424
statusToString(response.status),
448425
response.message,
449426
response.chain.size());
450-
451-
if (response.status == ResponseStatus::kResponseComplete) {
452-
result_->delta_rating += 100;
453-
}
454427
if (response.chain.size() > 0) {
455-
result_->delta_rating += 50;
456428
storeChain(std::move(response.chain));
457429
} else {
458-
result_->delta_rating -= 50;
459430
result_->error = BlocksyncRequest::Error::kIncompleteResponse;
460431
}
461432
}
@@ -554,11 +525,6 @@ namespace fc::sync::blocksync {
554525
break;
555526
}
556527
}
557-
558-
if (!result_->blocks_available.empty()) {
559-
result_->delta_rating +=
560-
(result_->blocks_available.size() + result_->parents.size()) * 5;
561-
}
562528
}
563529

564530
libp2p::Host &host_;

core/node/blocksync_request.hpp

-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ namespace fc::sync::blocksync {
3434
/// Not 0 if error occured
3535
std::error_code error;
3636

37-
/// Change rating for this peer
38-
int64_t delta_rating = 0;
39-
4037
/// Blocks which were requested
4138
std::vector<CbCid> blocks_requested;
4239

core/node/main/builder.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ namespace fc::node {
364364
storage::LevelDB::create(config.join("ipld_leveldb")).value();
365365
o.ipld_leveldb =
366366
std::make_shared<storage::ipfs::LeveldbDatastore>(o.ipld_leveldb_kv);
367-
o.ipld = o.ipld_leveldb;
368367
o.ipld = *storage::cids_index::loadOrCreateWithProgress(
369368
config.genesisCar(), false, boost::none, o.ipld, log());
370369
auto snapshot_cids{loadSnapshot(config, o)};

core/node/sync_job.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,6 @@ namespace fc::sync {
454454
ts = _ts.value();
455455
} else {
456456
peers_->onError(*r.from);
457-
r.delta_rating -= 500;
458457
}
459458

460459
if (ts) {

core/storage/mpool/mpool.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ namespace fc::storage::mpool {
628628
std::shared_lock head_lock(head_mutex_);
629629
const auto height = head_->height();
630630
OUTCOME_TRY(interpeted, env_context.interpreter_cache->get(head_->key));
631-
auto env{std::make_shared<vm::runtime::Env>(env_context, ts_main, head_)};
631+
OUTCOME_TRY(env, vm::runtime::Env::make(env_context, ts_main, head_));
632632
head_lock.unlock();
633633
env->state_tree = std::make_shared<vm::state::StateTreeImpl>(
634634
env->ipld, interpeted.state_root);

core/vm/interpreter/impl/interpreter_impl.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ namespace fc::vm::interpreter {
146146
return InterpreterError::kDuplicateMiner;
147147
}
148148

149-
auto env = std::make_shared<Env>(env_context_, ts_branch, tipset);
149+
OUTCOME_TRY(env, Env::make(env_context_, ts_branch, tipset));
150150

151151
auto cron{[&]() -> outcome::result<void> {
152152
OUTCOME_TRY(receipt,
@@ -171,10 +171,10 @@ namespace fc::vm::interpreter {
171171
OUTCOME_TRY(parent, env_context_.ts_load->load(tipset->getParents()));
172172
for (auto epoch{parent->height() + 1}; epoch < tipset->height();
173173
++epoch) {
174-
env->setHeight(epoch);
174+
OUTCOME_TRY(env->setHeight(epoch));
175175
OUTCOME_TRY(cron());
176176
}
177-
env->setHeight(tipset->height());
177+
OUTCOME_TRY(env->setHeight(tipset->height()));
178178
}
179179

180180
nextStep(&metricMessages);

core/vm/runtime/env.hpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ namespace fc::vm::runtime {
3737

3838
/// Environment contains objects that are shared by runtime contexts
3939
struct Env : std::enable_shared_from_this<Env> {
40-
Env(const EnvironmentContext &env_context,
40+
static outcome::result<std::shared_ptr<Env>> make(
41+
const EnvironmentContext &env_context,
4142
TsBranchPtr ts_branch,
4243
TipsetCPtr tipset);
4344

@@ -47,7 +48,7 @@ namespace fc::vm::runtime {
4748
TokenAmount reward;
4849
};
4950

50-
void setHeight(ChainEpoch height);
51+
outcome::result<void> setHeight(ChainEpoch height);
5152

5253
outcome::result<Apply> applyMessage(const UnsignedMessage &message,
5354
size_t size);
@@ -61,7 +62,8 @@ namespace fc::vm::runtime {
6162
ChainEpoch epoch; // mutable epoch for cron()
6263
TsBranchPtr ts_branch;
6364
TipsetCPtr tipset;
64-
Pricelist pricelist;
65+
Pricelist pricelist{0};
66+
TokenAmount base_circulating;
6567
};
6668

6769
struct Execution : std::enable_shared_from_this<Execution> {

core/vm/runtime/impl/env.cpp

+21-13
Original file line numberDiff line numberDiff line change
@@ -110,23 +110,31 @@ namespace fc::vm::runtime {
110110
return storage::ipfs::IpfsDatastoreError::kNotFound;
111111
}
112112

113-
Env::Env(const EnvironmentContext &env_context,
114-
TsBranchPtr ts_branch,
115-
TipsetCPtr tipset)
116-
: ipld{std::make_shared<IpldBuffered>(env_context.ipld)},
117-
state_tree{std::make_shared<StateTreeImpl>(
118-
this->ipld, tipset->getParentStateRoot())},
119-
env_context{env_context},
120-
epoch{tipset->height()},
121-
ts_branch{std::move(ts_branch)},
122-
tipset{std::move(tipset)},
123-
pricelist{epoch} {
124-
setHeight(epoch);
113+
outcome::result<std::shared_ptr<Env>> Env::make(
114+
const EnvironmentContext &env_context,
115+
TsBranchPtr ts_branch,
116+
TipsetCPtr tipset) {
117+
auto env{std::make_shared<Env>()};
118+
env->ipld = std::make_shared<IpldBuffered>(env_context.ipld);
119+
env->state_tree = std::make_shared<StateTreeImpl>(
120+
env->ipld, tipset->getParentStateRoot());
121+
env->env_context = env_context;
122+
env->epoch = tipset->height();
123+
env->ts_branch = std::move(ts_branch);
124+
env->tipset = std::move(tipset);
125+
env->pricelist = Pricelist{env->epoch};
126+
OUTCOME_TRY(env->setHeight(env->epoch));
127+
return env;
125128
}
126129

127-
void Env::setHeight(ChainEpoch height) {
130+
outcome::result<void> Env::setHeight(ChainEpoch height) {
128131
epoch = height;
129132
ipld->actor_version = actorVersion(height);
133+
if (env_context.circulating) {
134+
OUTCOME_TRYA(base_circulating,
135+
env_context.circulating->circulating(state_tree, height));
136+
}
137+
return outcome::success();
130138
}
131139

132140
// NOLINTNEXTLINE(readability-function-cognitive-complexity)

core/vm/runtime/impl/runtime_impl.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,13 @@ namespace fc::vm::runtime {
181181

182182
outcome::result<TokenAmount> RuntimeImpl::getTotalFilCirculationSupply()
183183
const {
184-
if (auto circulating{execution_->env->env_context.circulating}) {
185-
return circulating->circulating(execution_->state_tree,
186-
getCurrentEpoch());
184+
if (getNetworkVersion() <= NetworkVersion::kVersion14) {
185+
if (const auto &circulating{execution_->env->env_context.circulating}) {
186+
return circulating->circulating(execution_->state_tree,
187+
getCurrentEpoch());
188+
}
187189
}
188-
return 0;
190+
return execution_->env->base_circulating;
189191
}
190192

191193
std::shared_ptr<IpfsDatastore> RuntimeImpl::getIpfsDatastore() const {

test/core/test_vectors/test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ void testMessages(const MessageVector &mv, IpldPtr ipld) {
363363
std::shared_ptr<RuntimeRandomness> randomness =
364364
std::make_shared<ReplayingRandomness>(mv.randomness);
365365
fc::vm::runtime::EnvironmentContext env_context{ipld, invoker, randomness};
366-
auto env{std::make_shared<fc::vm::runtime::Env>(env_context, nullptr, ts)};
366+
auto env{fc::vm::runtime::Env::make(env_context, nullptr, ts).value()};
367367
auto i{0};
368368
for (const auto &[epoch_offset, message] : mv.messages) {
369369
const auto &receipt{mv.receipts[i]};

test/core/vm/actor/invoker_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace fc::vm::actor {
2929
ts->blks.emplace_back();
3030
auto execution{std::make_shared<Execution>()};
3131
execution->env =
32-
std::make_shared<Env>(runtime::EnvironmentContext{}, nullptr, ts);
32+
Env::make(runtime::EnvironmentContext{}, nullptr, ts).value();
3333

3434
InvokerImpl invoker;
3535

0 commit comments

Comments
 (0)