Skip to content

Commit 08423c8

Browse files
Check publish proposal deal id in deal publish message in storage market (#500)
Signed-off-by: Alexey-N-Chernyshov <[email protected]>
1 parent 4756e1c commit 08423c8

File tree

23 files changed

+390
-426
lines changed

23 files changed

+390
-426
lines changed

core/api/full_node/make.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,13 +875,13 @@ namespace fc::api {
875875
[=](auto deal_id, auto &tipset_key) -> outcome::result<StorageDeal> {
876876
OUTCOME_TRY(context, tipsetContext(tipset_key));
877877
OUTCOME_TRY(state, context.marketState());
878-
OUTCOME_TRY(deal, state->proposals.get(deal_id));
878+
OUTCOME_TRY(proposal, state->proposals.get(deal_id));
879879
OUTCOME_TRY(deal_state, state->states.tryGet(deal_id));
880880
if (!deal_state) {
881881
deal_state = DealState{
882882
kChainEpochUndefined, kChainEpochUndefined, kChainEpochUndefined};
883883
}
884-
return StorageDeal{deal, *deal_state};
884+
return StorageDeal{proposal, *deal_state};
885885
};
886886
api->StateMinerActiveSectors =
887887
[=](auto &miner,

core/const.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace fc {
3838
constexpr uint64_t kFilReserve{300000000};
3939
constexpr uint64_t kFilecoinPrecision{1000000000000000000};
4040
constexpr auto kGasLimitOverestimation{1.25};
41-
constexpr auto kMessageConfidence{5};
41+
constexpr EpochDuration kMessageConfidence{5};
4242
const TokenAmount kMinimumBaseFee{100};
4343
constexpr auto kPackingEfficiencyDenom{5};
4444
constexpr auto kPackingEfficiencyNum{4};

core/markets/storage/client/impl/storage_market_client_impl.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <libp2p/protocol/common/asio/asio_scheduler.hpp>
1111

1212
#include "codec/cbor/cbor_codec.hpp"
13+
#include "common/enum.hpp"
1314
#include "common/libp2p/peer/peer_info_helper.hpp"
1415
#include "common/outcome_fmt.hpp"
1516
#include "common/ptr.hpp"
@@ -402,19 +403,18 @@ namespace fc::markets::storage::client {
402403
if (msg_state.receipt.exit_code != VMExitCode::kOk) {
403404
deal->message =
404405
"Publish deal exit code "
405-
+ std::to_string(static_cast<uint64_t>(msg_state.receipt.exit_code));
406+
+ std::to_string(common::to_int(msg_state.receipt.exit_code));
406407
return false;
407408
}
408409

409410
// check if published
410411
OUTCOME_TRY(publish_message, api_->ChainGetMessage(deal->publish_message));
411-
OUTCOME_TRY(chain_head, api_->ChainHead());
412412
OUTCOME_TRY(
413413
miner_info,
414414
api_->StateMinerInfo(deal->client_deal_proposal.proposal.provider,
415-
chain_head->key));
415+
msg_state.tipset));
416416
OUTCOME_TRY(from_id_address,
417-
api_->StateLookupID(publish_message.from, chain_head->key));
417+
api_->StateLookupID(publish_message.from, msg_state.tipset));
418418
if (from_id_address != miner_info.worker) {
419419
deal->message = "Publisher is not storage provider";
420420
return false;
@@ -432,8 +432,8 @@ namespace fc::markets::storage::client {
432432
OUTCOME_TRY(params,
433433
codec::cbor::decode<PublishStorageDeals::Params>(
434434
publish_message.params));
435-
auto &proposals{params.deals};
436-
auto it = std::find(
435+
const auto &proposals{params.deals};
436+
const auto it = std::find(
437437
proposals.begin(), proposals.end(), deal->client_deal_proposal);
438438
if (it == proposals.end()) {
439439
OUTCOME_TRY(proposal_cid_str, deal->proposal_cid.toString());
@@ -444,7 +444,7 @@ namespace fc::markets::storage::client {
444444

445445
// get proposal id from publish call return
446446
size_t index = std::distance(proposals.begin(), it);
447-
OUTCOME_TRY(network, api_->StateNetworkVersion(chain_head->key));
447+
OUTCOME_TRY(network, api_->StateNetworkVersion(msg_state.tipset));
448448
OUTCOME_TRY(
449449
deal_id,
450450
vm::actor::builtin::types::market::publishDealsResult(
@@ -527,7 +527,7 @@ namespace fc::markets::storage::client {
527527
SELF_FSM_HALT_ON_ERROR(result, "Wait for funding error", deal);
528528
if (result.value().receipt.exit_code != VMExitCode::kOk) {
529529
deal->message = "Funding exit code "
530-
+ std::to_string(static_cast<uint64_t>(
530+
+ std::to_string(common::to_int(
531531
result.value().receipt.exit_code));
532532
SELF_FSM_SEND(deal, ClientEvent::ClientEventFailed);
533533
return;

core/markets/storage/provider/impl/provider_impl.cpp

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
}
3737

3838
namespace fc::markets::storage::provider {
39-
using api::MsgWait;
4039
using data_transfer::Selector;
4140
using fc::storage::piece::DealInfo;
4241
using fc::storage::piece::PayloadLocation;
@@ -61,7 +60,8 @@ namespace fc::markets::storage::provider {
6160
std::shared_ptr<ChainEvents> chain_events,
6261
Address miner_actor_address,
6362
std::shared_ptr<PieceIO> piece_io,
64-
std::shared_ptr<FileStore> filestore)
63+
std::shared_ptr<FileStore> filestore,
64+
std::shared_ptr<DealInfoManager> deal_info_manager)
6565
: host_{std::move(host)},
6666
context_{std::move(context)},
6767
stored_ask_{std::move(stored_ask)},
@@ -73,7 +73,8 @@ namespace fc::markets::storage::provider {
7373
piece_storage_{std::move(piece_storage)},
7474
filestore_{std::move(filestore)},
7575
ipld_{std::move(ipld)},
76-
datatransfer_{std::move(datatransfer)} {}
76+
datatransfer_{std::move(datatransfer)},
77+
deal_info_manager_{std::move(deal_info_manager)} {}
7778

7879
std::shared_ptr<MinerDeal> StorageProviderImpl::getDealPtr(
7980
const CID &proposal_cid) {
@@ -640,33 +641,23 @@ namespace fc::markets::storage::provider {
640641
ProviderEvent event,
641642
StorageDealStatus from,
642643
StorageDealStatus to) {
644+
assert(deal->publish_cid.has_value());
645+
643646
api_->StateWaitMsg(
644-
[self{shared_from_this()}, deal, to](outcome::result<MsgWait> result) {
647+
[self{shared_from_this()}, deal, to](
648+
outcome::result<MsgWait> msg_state) {
649+
const auto maybe_deal_id =
650+
self->deal_info_manager_->dealIdFromPublishDealsMsg(
651+
msg_state.value(), deal->client_deal_proposal.proposal);
645652
SELF_FSM_HALT_ON_ERROR(
646-
result, "Publish storage deal message error", deal);
647-
if (result.value().receipt.exit_code != VMExitCode::kOk) {
648-
deal->message = "Publish storage deal exit code "
649-
+ std::to_string(static_cast<uint64_t>(
650-
result.value().receipt.exit_code));
651-
SELF_FSM_SEND(deal, ProviderEvent::ProviderEventFailed);
652-
return;
653-
}
654-
// TODO(turuslan): v6
655-
auto maybe_res = codec::cbor::decode<PublishStorageDeals::Result>(
656-
result.value().receipt.return_value);
657-
SELF_FSM_HALT_ON_ERROR(
658-
maybe_res, "Publish storage deal decode result error", deal);
659-
if (maybe_res.value().deals.size() != 1) {
660-
deal->message = "Publish storage deal result size error";
661-
SELF_FSM_SEND(deal, ProviderEvent::ProviderEventFailed);
662-
return;
663-
}
664-
deal->deal_id = maybe_res.value().deals.front();
653+
maybe_deal_id, "Looking for publish deal message", deal);
654+
deal->deal_id = maybe_deal_id.value();
665655
deal->state = to;
666656
SELF_FSM_SEND(deal, ProviderEvent::ProviderEventDealPublished);
667657
},
668658
deal->publish_cid.get(),
669-
kMessageConfidence,
659+
// Wait for deal to be published (plus additional time for confidence)
660+
kMessageConfidence * 2,
670661
api::kLookbackNoLimit,
671662
true);
672663
}
@@ -717,7 +708,7 @@ namespace fc::markets::storage::provider {
717708
}
718709

719710
void StorageProviderImpl::onProviderEventDealCompleted(
720-
const std::shared_ptr<MinerDeal>& deal,
711+
const std::shared_ptr<MinerDeal> &deal,
721712
ProviderEvent event,
722713
StorageDealStatus from,
723714
StorageDealStatus to) {

0 commit comments

Comments
 (0)