Skip to content

ChainGetPath #529

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

Merged
merged 2 commits into from
Nov 22, 2021
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
23 changes: 23 additions & 0 deletions core/api/full_node/make.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace fc::api {
using primitives::kChainEpochUndefined;
using primitives::block::MsgMeta;
using primitives::sector::getPreferredSealProofTypeFromWindowPoStType;
using primitives::tipset::HeadChangeType;
using primitives::tipset::Tipset;
using storage::ipld::kAllSelector;
using vm::isVMExitCode;
Expand All @@ -84,6 +85,7 @@ namespace fc::api {
using vm::actor::builtin::states::RewardActorStatePtr;
using vm::actor::builtin::states::VerifiedRegistryActorStatePtr;
using vm::actor::builtin::types::market::DealState;
using vm::actor::builtin::types::miner::kChainFinality;
using vm::actor::builtin::types::storage_power::kConsensusMinerMinPower;
using vm::interpreter::InterpreterCache;
using vm::runtime::Env;
Expand Down Expand Up @@ -293,6 +295,27 @@ namespace fc::api {
OUTCOME_TRY(cbor, ipld->get(cid));
return UnsignedMessage::decode(cbor);
};
api->ChainGetPath = [=](const TipsetKey &from_key, const TipsetKey &to_key)
-> outcome::result<std::vector<HeadChange>> {
std::vector<HeadChange> revert;
std::vector<HeadChange> apply;
OUTCOME_TRY(from, ts_load->load(from_key));
OUTCOME_TRY(to, ts_load->load(to_key));
while (from->key != to->key) {
if (revert.size() > kChainFinality || apply.size() > kChainFinality) {
return ERROR_TEXT("ChainGetPath finality limit");
}
if (from->height() > to->height()) {
revert.emplace_back(HeadChange{HeadChangeType::REVERT, from});
OUTCOME_TRYA(from, ts_load->load(from->getParents()));
} else {
apply.emplace_back(HeadChange{HeadChangeType::APPLY, to});
OUTCOME_TRYA(to, ts_load->load(to->getParents()));
}
}
revert.insert(revert.end(), apply.rbegin(), apply.rend());
return std::move(revert);
};
api->ChainGetParentMessages =
[=](auto &block_cid) -> outcome::result<std::vector<CidMessage>> {
std::vector<CidMessage> messages;
Expand Down
6 changes: 6 additions & 0 deletions core/api/full_node/node_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ namespace fc::api {
jwt::kReadPermission,
UnsignedMessage,
const CID &)
API_METHOD(ChainGetPath,
jwt::kReadPermission,
std::vector<HeadChange>,
const TipsetKey &,
const TipsetKey &)
API_METHOD(ChainGetParentMessages,
jwt::kReadPermission,
std::vector<CidMessage>,
Expand Down Expand Up @@ -813,6 +818,7 @@ namespace fc::api {
f(a.ChainGetGenesis);
f(a.ChainGetMessage);
f(a.ChainGetNode);
f(a.ChainGetPath);
f(a.ChainGetParentMessages);
f(a.ChainGetParentReceipts);
f(a.ChainGetRandomnessFromBeacon);
Expand Down
11 changes: 11 additions & 0 deletions core/vm/actor/cgo/actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ namespace fc::vm::actor::cgo {
cgoCall<cgoActorsConfigParams>(arg);
}

void logLevel(LogLevel level) {
CborEncodeStream arg;
arg << level;
cgoCall<cgoActorsSetLogLevel>(arg);
}

constexpr auto kFatal{VMExitCode::kFatal};
constexpr auto kOk{VMExitCode::kOk};

Expand Down Expand Up @@ -394,4 +400,9 @@ namespace fc::vm::actor::cgo {
ret << VMExitCode::kErrIllegalState;
}
}

RUNTIME_METHOD(gocRtLog) {
spdlog::info("cgoActorsInvoke log: {}", arg.get<std::string>());
ret << kOk;
}
} // namespace fc::vm::actor::cgo
8 changes: 8 additions & 0 deletions core/vm/actor/cgo/actors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ namespace fc::vm::actor::cgo {
*/
void configParams();

enum class LogLevel {
kDebug = -1,
kInfo,
kWarn,
kError,
};
void logLevel(LogLevel level);

outcome::result<Bytes> invoke(const CID &code,
const std::shared_ptr<Runtime> &runtime);
} // namespace fc::vm::actor::cgo
1 change: 1 addition & 0 deletions core/vm/actor/cgo/c_actors.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Raw gocRtStateGet(Raw);
Raw gocRtStateCommit(Raw);
Raw gocRtDeleteActor(Raw);
Raw gocRtCirc(Raw);
Raw gocRtLog(Raw);

#ifdef __cplusplus
}
Expand Down
8 changes: 8 additions & 0 deletions core/vm/actor/cgo/cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ func (out *cborOut) bytes(b []byte) *cborOut {
return out
}

func (out *cborOut) str(s string) *cborOut {
e := typegen.CborWriteHeader(out.w, typegen.MajTextString, uint64(len(s)))
cgoAsserte(e)
_, e = out.w.Write([]byte(s))
cgoAsserte(e)
return out
}

func (out *cborOut) int(i int64) *cborOut {
t := typegen.MajUnsignedInt
if i < 0 {
Expand Down
23 changes: 22 additions & 1 deletion core/vm/actor/cgo/go_actors.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,21 @@ func (rt *rt) ChargeGas(_ string, gas int64, _ int64) {
rt.gocRet(C.gocRtCharge(rt.gocArg().int(gas).arg()))
}

func (rt *rt) Log(rtt.LogLevel, string, ...interface{}) {
var log_level rtt.LogLevel = rtt.WARN
var log_levels = []string{"DEBUG", "INFO", "WARN", "ERROR"}

func (rt *rt) Log(level rtt.LogLevel, format string, args ...interface{}) {
if level < rtt.DEBUG {
return
}
if level > rtt.ERROR {
level = rtt.ERROR
}
if level < log_level {
return
}
msg := fmt.Sprintf("%s %s", log_levels[level+1], fmt.Sprintf(format, args...))
rt.gocRet(C.gocRtLog(rt.gocArg().str(msg).arg()))
}

var _ rt1.StateHandle = &rt{}
Expand Down Expand Up @@ -844,6 +858,13 @@ func cgoActorsConfigParams(raw C.Raw) C.Raw {
return cgoRet(nil)
}

//export cgoActorsSetLogLevel
func cgoActorsSetLogLevel(raw C.Raw) C.Raw {
arg := cgoArgCbor(raw)
log_level = rtt.LogLevel(arg.int())
return cgoRet(nil)
}

func init() {
for k, v := range _actors {
actors[k] = export(v)
Expand Down
2 changes: 1 addition & 1 deletion test/core/sector_storage/zerocomm/zerocomm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace fc::sector_storage::zerocomm {
params.expected)
}

INSTANTIATE_TEST_CASE_P(
INSTANTIATE_TEST_SUITE_P(
ZerocommTestCases,
ZerocommTest,
::testing::Values(Params{1016,
Expand Down
6 changes: 3 additions & 3 deletions test/core/storage/mpool/message_pool_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ namespace fc::storage::mpool {
EXPECT_FALSE(testMpoolSelectRevert(fix, ticket_quality).empty());
}

INSTANTIATE_TEST_CASE_P(MpoolSelectQualityTest,
MpoolSelectQualityTest,
::testing::Values(0.8, 0.9));
INSTANTIATE_TEST_SUITE_P(MpoolSelectQualityTest,
MpoolSelectQualityTest,
::testing::Values(0.8, 0.9));
} // namespace fc::storage::mpool
2 changes: 1 addition & 1 deletion test/core/storage/unixfs/unixfs_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TEST_P(UnixfsTest, MatchGo) {
EXPECT_EQ(unwrapped.str(), data);
}

INSTANTIATE_TEST_CASE_P(
INSTANTIATE_TEST_SUITE_P(
UnixfsTestCases,
UnixfsTest,
::testing::Values(
Expand Down
13 changes: 5 additions & 8 deletions test/core/test_vectors/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,7 @@ struct TestVectors : testing::TestWithParam<MessageVector> {
OUTCOME_EXCEPT(params,
ProofParamProvider::readJson(
"/var/tmp/filecoin-proof-parameters/parameters.json"));
RegisteredSealProof seal_proof_type =
RegisteredSealProof::kStackedDrg2KiBV1;
OUTCOME_EXCEPT(sector_size, getSectorSize(seal_proof_type));
OUTCOME_EXCEPT(ProofParamProvider::getParams(params, sector_size));
OUTCOME_EXCEPT(ProofParamProvider::getParams(params, 0));
}
};

Expand Down Expand Up @@ -404,7 +401,7 @@ TEST_P(TestVectors, Vector) {
}
}

INSTANTIATE_TEST_CASE_P(Vectors,
TestVectors,
testing::ValuesIn(search()),
[](auto &&p) { return testName(p.param.path); });
INSTANTIATE_TEST_SUITE_P(Vectors,
TestVectors,
testing::ValuesIn(search()),
[](auto &&p) { return testName(p.param.path); });
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ namespace fc::vm::actor::builtin::types::miner {
}
}

INSTANTIATE_TEST_CASE_P(
INSTANTIATE_TEST_SUITE_P(
P,
DeadlineAssignmentTestP,
::testing::ValuesIn(DeadlineAssignmentTestP::initTestCases()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,23 @@ namespace fc::vm::actor::builtin::types::reward {
ASSERT_LT(err, err_bound);
}

INSTANTIATE_TEST_CASE_P(RewardActorCalculusV0Cases,
RewardActorCalculusV0,
::testing::Values(
// 1 byte
Params{StoragePower{1}, BigFloat{1}},
// GiB
Params{StoragePower{1} << 30, BigFloat{1e-3}},
// TiB
Params{StoragePower{1} << 40, BigFloat{1e-6}},
// PiB
Params{StoragePower{1} << 50, BigFloat{1e-8}},
// EiB
Params{kBaselineInitialValueV0, BigFloat{1e-8}},
// ZiB
Params{StoragePower{1} << 70, BigFloat{1e-8}},
// non power of 2 ~ 1 EiB
Params{StoragePower{"513633559722596517"},
BigFloat{1e-8}}));
INSTANTIATE_TEST_SUITE_P(RewardActorCalculusV0Cases,
RewardActorCalculusV0,
::testing::Values(
// 1 byte
Params{StoragePower{1}, BigFloat{1}},
// GiB
Params{StoragePower{1} << 30, BigFloat{1e-3}},
// TiB
Params{StoragePower{1} << 40, BigFloat{1e-6}},
// PiB
Params{StoragePower{1} << 50, BigFloat{1e-8}},
// EiB
Params{kBaselineInitialValueV0, BigFloat{1e-8}},
// ZiB
Params{StoragePower{1} << 70, BigFloat{1e-8}},
// non power of 2 ~ 1 EiB
Params{StoragePower{"513633559722596517"},
BigFloat{1e-8}}));

} // namespace fc::vm::actor::builtin::types::reward
4 changes: 2 additions & 2 deletions test/core/vm/actor/builtin/v2/miner/miner_actor_v2_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ namespace fc::vm::actor::builtin::v2::miner {
EXPECT_OUTCOME_TRUE_1(Construct::call(runtime, params));
}

INSTANTIATE_TEST_CASE_P(
INSTANTIATE_TEST_SUITE_P(
ConstructSuccesssMinerActorTestCases,
ConstructSuccesssMinerActorTest,
::testing::Values(
Expand All @@ -333,7 +333,7 @@ namespace fc::vm::actor::builtin::v2::miner {
: public MinerActorTest,
public ::testing::WithParamInterface<ConstructParams> {};

INSTANTIATE_TEST_CASE_P(
INSTANTIATE_TEST_SUITE_P(
ConstructFailureMinerActorTestCases,
ConstructFailureMinerActorTest,
::testing::Values(
Expand Down