Skip to content

Commit 8b5ef04

Browse files
authored
fixes (#576)
Signed-off-by: turuslan <[email protected]>
1 parent aec1835 commit 8b5ef04

File tree

8 files changed

+95
-3
lines changed

8 files changed

+95
-3
lines changed

core/api/full_node/make.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,32 @@ namespace fc::api {
10321032
};
10331033
// TODO(artyom-yurin): FIL-165 implement method
10341034
api->StateSectorPartition =
1035-
std::function<decltype(api->StateSectorPartition)::FunctionSignature>{};
1035+
[=](const Address &address,
1036+
SectorNumber sector,
1037+
const TipsetKey &tsk) -> outcome::result<SectorLocation> {
1038+
OUTCOME_TRY(context, tipsetContext(tsk, false));
1039+
OUTCOME_TRY(state, context.minerState(address));
1040+
OUTCOME_TRY(deadlines, state->deadlines.get());
1041+
uint64_t i_deadline{0};
1042+
for (const auto &_deadline : deadlines.due) {
1043+
boost::optional<SectorLocation> result;
1044+
OUTCOME_TRY(deadline, _deadline.get());
1045+
const auto visit{
1046+
[&](auto i_partition, auto &partition) -> outcome::result<void> {
1047+
if (partition->sectors.has(sector)) {
1048+
result = SectorLocation{i_deadline, i_partition};
1049+
return outcome::failure(adt::kStopError);
1050+
}
1051+
return outcome::success();
1052+
}};
1053+
CATCH_STOP(deadline->partitions.visit(visit));
1054+
if (result) {
1055+
return *result;
1056+
}
1057+
++i_deadline;
1058+
}
1059+
return ERROR_TEXT("StateSectorPartition: not found");
1060+
};
10361061

10371062
api->StateVerifiedClientStatus = [=](const Address &address,
10381063
const TipsetKey &tipset_key)

core/api/rpc/ws.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,14 @@ namespace fc::api {
163163
return std::nullopt;
164164
}
165165

166-
return static_cast<std::string>(auth_token.substr(perfix.size()));
166+
return std::string{auth_token.substr(perfix.size())};
167+
}
168+
const std::string_view url{request.target().data(),
169+
request.target().size()};
170+
constexpr std::string_view kParam{"?token="};
171+
const auto pos{url.find(kParam)};
172+
if (pos != url.npos) {
173+
return std::string{url.substr(pos + kParam.size())};
167174
}
168175
return std::string();
169176
}

core/vm/actor/builtin/types/miner/sector_info.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ namespace fc::vm::actor::builtin::types::miner {
3131
TokenAmount init_pledge{};
3232
TokenAmount expected_day_reward{};
3333
TokenAmount expected_storage_pledge{};
34+
ChainEpoch replaced_sector_age{};
35+
TokenAmount replaced_day_reward;
3436
boost::optional<CID> sector_key_cid;
3537

3638
inline bool operator==(const SectorOnChainInfo &other) const {
@@ -43,6 +45,8 @@ namespace fc::vm::actor::builtin::types::miner {
4345
&& init_pledge == other.init_pledge
4446
&& expected_day_reward == other.expected_day_reward
4547
&& expected_storage_pledge == other.expected_storage_pledge
48+
&& replaced_sector_age == other.replaced_sector_age
49+
&& replaced_day_reward == other.replaced_day_reward
4650
&& sector_key_cid == other.sector_key_cid;
4751
}
4852

core/vm/actor/builtin/types/miner/v7/sector_info.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ namespace fc::vm::actor::builtin::v7::miner {
2222
init_pledge,
2323
expected_day_reward,
2424
expected_storage_pledge,
25+
replaced_sector_age,
26+
replaced_day_reward,
2527
sector_key_cid)
2628

2729
} // namespace fc::vm::actor::builtin::v7::miner

core/vm/actor/cgo/actors.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ namespace fc::vm::actor::cgo {
3939
using primitives::piece::PieceInfo;
4040
using primitives::sector::AggregateSealVerifyProofAndInfos;
4141
using primitives::sector::RegisteredSealProof;
42+
using primitives::sector::ReplicaUpdateInfo;
4243
using primitives::sector::SealVerifyInfo;
4344
using primitives::sector::WindowPoStVerifyInfo;
4445
using toolchain::Toolchain;
@@ -230,6 +231,15 @@ namespace fc::vm::actor::cgo {
230231
}
231232
}
232233

234+
RUNTIME_METHOD(gocRtVerifyReplicaUpdate) {
235+
const auto info{arg.get<ReplicaUpdateInfo>()};
236+
if (charge(
237+
ret, rt, rt->execution()->env->pricelist.onVerifyReplicaUpdate())) {
238+
const auto r{proofs->verifyUpdateProof(info)};
239+
ret << kOk << (r && r.value());
240+
}
241+
}
242+
233243
RUNTIME_METHOD(gocRtActorId) {
234244
if (auto _id{
235245
rt->execution()->state_tree->tryLookupId(arg.get<Address>())}) {

core/vm/actor/cgo/c_actors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Raw gocRtBlake(Raw);
2020
Raw gocRtVerifyPost(Raw);
2121
Raw gocRtVerifySeals(Raw);
2222
Raw gocRtVerifyAggregateSeals(Raw);
23+
Raw gocRtVerifyReplicaUpdate(Raw);
2324
Raw gocRtActorId(Raw);
2425
Raw gocRtSend(Raw);
2526
Raw gocRtVerifySig(Raw);

core/vm/actor/cgo/go_actors.go

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ import (
112112
reward7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/reward"
113113
system7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/system"
114114
verifreg7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/verifreg"
115-
rt7 "github.com/filecoin-project/specs-actors/v6/actors/runtime"
115+
rt7 "github.com/filecoin-project/specs-actors/v7/actors/runtime"
116+
proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof"
116117
"github.com/ipfs/go-cid"
117118
"github.com/whyrusleeping/cbor-gen"
118119
)
@@ -543,6 +544,33 @@ func MarshalCBOR_WindowPoStVerifyInfo(out *cborOut, t *proof1.WindowPoStVerifyIn
543544
return nil
544545
}
545546

547+
func MarshalCBOR_ReplicaUpdateInfo(out *cborOut, t *proof7.ReplicaUpdateInfo) error {
548+
w := out.w
549+
if _, e := w.Write(cborArray5); e != nil {
550+
return e
551+
}
552+
s := make([]byte, 9)
553+
if e := typegen.WriteMajorTypeHeaderBuf(s, w, typegen.MajUnsignedInt, uint64(t.UpdateProofType)); e != nil {
554+
return e
555+
}
556+
if e := typegen.WriteCid(w, t.OldSealedSectorCID); e != nil {
557+
return e
558+
}
559+
if e := typegen.WriteCid(w, t.NewSealedSectorCID); e != nil {
560+
return e
561+
}
562+
if e := typegen.WriteCid(w, t.NewUnsealedSectorCID); e != nil {
563+
return e
564+
}
565+
if e := typegen.WriteMajorTypeHeaderBuf(s, w, typegen.MajByteString, uint64(len(t.Proof))); e != nil {
566+
return e
567+
}
568+
if _, e := w.Write(t.Proof[:]); e != nil {
569+
return e
570+
}
571+
return nil
572+
}
573+
546574
func (rt *rt) VerifyPoSt(info proof1.WindowPoStVerifyInfo) error {
547575
arg := rt.gocArg()
548576
if e := MarshalCBOR_WindowPoStVerifyInfo(arg, &info); e != nil {
@@ -567,6 +595,18 @@ func (rt *rt) VerifyAggregateSeals(aggregate proof5.AggregateSealVerifyProofAndI
567595
return exitcode.ErrIllegalArgument
568596
}
569597

598+
func (rt *rt) VerifyReplicaUpdate(info proof7.ReplicaUpdateInfo) error {
599+
arg := rt.gocArg()
600+
if e := MarshalCBOR_ReplicaUpdateInfo(arg, &info); e != nil {
601+
panic(cgoErrors("VerifyReplicaUpdate MarshalCBOR"))
602+
}
603+
ret := rt.gocRet(C.gocRtVerifyReplicaUpdate(arg.arg()))
604+
if ret.bool() {
605+
return nil
606+
}
607+
return exitcode.ErrIllegalArgument
608+
}
609+
570610
func (rt *rt) VerifyConsensusFault(block1, block2, extra []byte) (*rt1.ConsensusFault, error) {
571611
ret := rt.gocRet(C.gocRtVerifyConsensusFault(rt.gocArg().bytes(block1).bytes(block2).bytes(extra).arg()))
572612
if ret.bool() {

core/vm/runtime/pricelist.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ namespace fc::vm::runtime {
135135
->second};
136136
return static_cast<GasAmount>(n) * (_64gib ? 359272 : 449900) + step;
137137
}
138+
GasAmount onVerifyReplicaUpdate() {
139+
return make(calico ? 36316136 : 0, 0);
140+
}
138141
static inline GasAmount onVerifyConsensusFault() {
139142
return make(495422, 0);
140143
}

0 commit comments

Comments
 (0)