Skip to content

Commit 69b75a0

Browse files
authored
paych vouchers (#502)
Signed-off-by: turuslan <[email protected]>
1 parent 08423c8 commit 69b75a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+815
-593
lines changed

core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ add_subdirectory(fslock)
1717
add_subdirectory(markets)
1818
add_subdirectory(miner)
1919
add_subdirectory(node)
20-
add_subdirectory(payment_channel_manager)
20+
add_subdirectory(paych)
2121
add_subdirectory(power)
2222
add_subdirectory(primitives)
2323
add_subdirectory(proofs)

core/api/full_node/make.cpp

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "vm/runtime/env.hpp"
4444
#include "vm/runtime/impl/tipset_randomness.hpp"
4545
#include "vm/state/impl/state_tree_impl.hpp"
46+
#include "vm/state/resolve_key.hpp"
4647
#include "vm/toolchain/toolchain.hpp"
4748

4849
#define MOVE(x) \
@@ -85,8 +86,6 @@ namespace fc::api {
8586
using vm::actor::builtin::types::market::DealState;
8687
using vm::actor::builtin::types::storage_power::kConsensusMinerMinPower;
8788
using vm::interpreter::InterpreterCache;
88-
using vm::message::kDefaultGasLimit;
89-
using vm::message::kDefaultGasPrice;
9089
using vm::runtime::Env;
9190
using vm::state::StateTreeImpl;
9291
using vm::toolchain::Toolchain;
@@ -155,11 +154,7 @@ namespace fc::api {
155154
}
156155

157156
outcome::result<Address> accountKey(const Address &id) {
158-
OUTCOME_TRY(actor, state_tree.get(id));
159-
OUTCOME_TRY(
160-
state,
161-
getCbor<AccountActorStatePtr>(state_tree.getStore(), actor.head));
162-
return state->address;
157+
return resolveKey(state_tree, id);
163158
}
164159

165160
// TODO (a.chernyshov) make explicit
@@ -439,7 +434,7 @@ namespace fc::api {
439434
for (const auto &[peer, maybe_response] : all_calls) {
440435
if (maybe_response.has_error()) {
441436
kNodeApiLogger->error("Error when query peer {}",
442-
maybe_response.error().message());
437+
maybe_response.error().message());
443438
} else {
444439
result.emplace_back(maybe_response.value());
445440
}
@@ -489,7 +484,7 @@ namespace fc::api {
489484
[=](outcome::result<void> res) {
490485
if (res.has_error()) {
491486
kNodeApiLogger->error("Error in ClientRetrieve {}",
492-
res.error().message());
487+
res.error().message());
493488
return cb(res.error());
494489
}
495490
kNodeApiLogger->info("retrieval deal done");
@@ -519,9 +514,7 @@ namespace fc::api {
519514
-> outcome::result<UnsignedMessage> {
520515
if (msg.from.isId()) {
521516
OUTCOME_TRY(context, tipsetContext(tsk));
522-
OUTCOME_TRYA(msg.from,
523-
vm::runtime::resolveKey(
524-
context.state_tree, context, msg.from, false));
517+
OUTCOME_TRYA(msg.from, context.accountKey(msg.from));
525518
}
526519
OUTCOME_TRY(mpool->estimate(
527520
msg, spec ? spec->max_fee : storage::mpool::kDefaultMaxFee));
@@ -657,9 +650,7 @@ namespace fc::api {
657650
auto &spec) -> outcome::result<SignedMessage> {
658651
OUTCOME_TRY(context, tipsetContext({}));
659652
if (message.from.isId()) {
660-
OUTCOME_TRYA(message.from,
661-
vm::runtime::resolveKey(
662-
context.state_tree, ipld, message.from, false));
653+
OUTCOME_TRYA(message.from, context.accountKey(message.from));
663654
}
664655
OUTCOME_TRY(mpool->estimate(
665656
message, spec ? spec->max_fee : storage::mpool::kDefaultMaxFee));
@@ -1272,10 +1263,6 @@ namespace fc::api {
12721263
}
12731264
return key_store->verify(address, data, signature);
12741265
};
1275-
/**
1276-
* Payment channel methods are initialized with
1277-
* PaymentChannelManager::makeApi(Api &api)
1278-
*/
12791266
return api;
1280-
} // namespace fc::api
1267+
}
12811268
} // namespace fc::api

core/api/full_node/make.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "storage/chain/chain_store.hpp"
1515
#include "storage/chain/msg_waiter.hpp"
1616
#include "storage/keystore/keystore.hpp"
17-
#include "storage/leveldb/prefix.hpp"
17+
#include "storage/map_prefix/prefix.hpp"
1818
#include "storage/mpool/mpool.hpp"
1919
#include "vm/runtime/env_context.hpp"
2020

@@ -33,7 +33,8 @@ namespace fc::api {
3333
using sync::PubSubGate;
3434
using vm::runtime::EnvironmentContext;
3535

36-
const static common::Logger kNodeApiLogger = common::createLogger("Full Node API");
36+
const static common::Logger kNodeApiLogger =
37+
common::createLogger("Full Node API");
3738

3839
outcome::result<IpldObject> getNode(const std::shared_ptr<Ipld> &ipld,
3940
const CID &root,

core/api/impl/paych_get.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
#pragma once
77

88
#include "api/full_node/node_api.hpp"
9-
#include "payment_channel_manager/impl/maker.hpp"
9+
#include "paych/maker.hpp"
1010

1111
namespace fc::api {
12-
inline void implPaychGet(
12+
inline void fillPaychGet(
1313
const std::shared_ptr<FullNodeApi> &api,
1414
const std::shared_ptr<paych_maker::PaychMaker> &maker) {
1515
api->PaychGet = [=](auto &&cb,

core/api/impl/paych_voucher.hpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#pragma once
7+
8+
#include "api/full_node/node_api.hpp"
9+
#include "paych/vouchers.hpp"
10+
11+
namespace fc::api {
12+
inline void fillPaychVoucher(
13+
const std::shared_ptr<FullNodeApi> &api,
14+
const std::shared_ptr<paych_vouchers::PaychVouchers> &vouchers) {
15+
using paych_vouchers::actorHash;
16+
api->PaychAllocateLane =
17+
[=](const Address &address) -> outcome::result<LaneId> {
18+
OUTCOME_TRY(paych, actorHash(address));
19+
return vouchers->nextLane(paych);
20+
};
21+
api->PaychVoucherAdd =
22+
[=](const Address &address,
23+
const SignedVoucher &voucher,
24+
const Bytes &proof,
25+
const TokenAmount &min_delta) -> outcome::result<TokenAmount> {
26+
if (!proof.empty()) {
27+
return ERROR_TEXT("PaychVoucherAdd proof not supported");
28+
}
29+
OUTCOME_TRY(paych, actorHash(address));
30+
OUTCOME_TRY(voucher_paych, actorHash(voucher.channel));
31+
if (paych != voucher_paych) {
32+
return ERROR_TEXT("PaychVoucherAdd wrong address");
33+
}
34+
return vouchers->add(voucher, min_delta);
35+
};
36+
api->PaychVoucherCheckValid =
37+
[=](const Address &address,
38+
const SignedVoucher &voucher) -> outcome::result<void> {
39+
OUTCOME_TRY(paych, actorHash(address));
40+
OUTCOME_TRY(voucher_paych, actorHash(voucher.channel));
41+
if (paych != voucher_paych) {
42+
return ERROR_TEXT("PaychVoucherCheckValid wrong address");
43+
}
44+
return vouchers->check(voucher);
45+
};
46+
api->PaychVoucherCreate =
47+
[=](const Address &address,
48+
const TokenAmount &amount,
49+
LaneId lane) -> outcome::result<SignedVoucher> {
50+
OUTCOME_TRY(paych, actorHash(address));
51+
return vouchers->make(paych, lane, amount);
52+
};
53+
}
54+
} // namespace fc::api

core/api/rpc/json.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "common/enum.hpp"
1717
#include "common/libp2p/peer/cbor_peer_info.hpp"
1818
#include "miner/main/type.hpp"
19-
#include "payment_channel_manager/payment_channel_manager.hpp"
2019
#include "primitives/address/address_codec.hpp"
2120
#include "primitives/cid/cid_of_cbor.hpp"
2221
#include "sector_storage/stores/storage.hpp"

core/cbor_blake/ipld_version.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ namespace fc {
2626
};
2727

2828
// TODO(turuslan): refactor Ipld to CbIpld
29-
inline IpldPtr withVersion(IpldPtr ipld, ChainEpoch height) {
30-
const auto version{actorVersion(height)};
29+
inline IpldPtr withVersion(IpldPtr ipld, ActorVersion version) {
3130
if (ipld->actor_version != version) {
3231
ipld = std::make_shared<IpldProxy>(ipld);
3332
ipld->actor_version = version;
3433
}
3534
return ipld;
3635
}
36+
37+
inline IpldPtr withVersion(const IpldPtr &ipld, ChainEpoch height) {
38+
return withVersion(ipld, actorVersion(height));
39+
}
3740
} // namespace fc

core/data_transfer/dt.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "common/libp2p/cbor_stream.hpp"
1111
#include "common/ptr.hpp"
12+
#include "storage/ipfs/graphsync/extension_dedup.hpp"
1213

1314
#define MOVE(x) \
1415
x { \
@@ -226,17 +227,21 @@ namespace fc::data_transfer {
226227
peer,
227228
root,
228229
selector.b,
229-
{makeExt(DataTransferMessage{DataTransferRequest{
230-
root,
231-
MessageType::kNewMessage,
232-
false,
233-
false,
234-
true,
235-
selector,
236-
CborRaw{std::move(voucher)},
237-
std::move(type),
238-
dtid,
239-
}})},
230+
{
231+
makeExt(DataTransferMessage{DataTransferRequest{
232+
root,
233+
MessageType::kNewMessage,
234+
false,
235+
false,
236+
true,
237+
selector,
238+
CborRaw{std::move(voucher)},
239+
std::move(type),
240+
dtid,
241+
}}),
242+
storage::ipfs::graphsync::extension::dedup::make(
243+
std::to_string(dtid)),
244+
},
240245
[this, peer, MOVE(on_cid), sub](auto, auto ext) {
241246
if (auto _ext{gsns::Extension::find(gsns::kResponseMetadataProtocol,
242247
ext)}) {

core/markets/retrieval/provider/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ target_link_libraries(retrieval_market_provider
1313
cbor_stream
1414
tipset
1515
ipld_traverser
16+
map_prefix
1617
memory_indexed_car
1718
piece
1819
piece_data

core/markets/retrieval/provider/impl/retrieval_provider_impl.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "miner/miner.hpp"
1717
#include "storage/ipld/memory_indexed_car.hpp"
1818
#include "storage/ipld/traverser.hpp"
19-
#include "storage/leveldb/prefix.hpp"
19+
#include "storage/map_prefix/prefix.hpp"
2020
#include "storage/piece/piece_storage.hpp"
2121

2222
namespace fc::markets::retrieval::provider {
@@ -71,11 +71,12 @@ namespace fc::markets::retrieval::provider {
7171
void onProposal(const PeerDtId &pdtid,
7272
const PeerGsId &pgsid,
7373
const DealProposal &proposal);
74-
void onPayment(const std::shared_ptr<DealState>& deal, const DealPayment &payment);
75-
void doUnseal(const std::shared_ptr<DealState>& deal);
76-
void doBlocks(const std::shared_ptr<DealState>& deal);
77-
void doComplete(const std::shared_ptr<DealState>& deal);
78-
bool hasOwed(const std::shared_ptr<DealState>& deal);
74+
void onPayment(const std::shared_ptr<DealState> &deal,
75+
const DealPayment &payment);
76+
void doUnseal(const std::shared_ptr<DealState> &deal);
77+
void doBlocks(const std::shared_ptr<DealState> &deal);
78+
void doComplete(const std::shared_ptr<DealState> &deal);
79+
bool hasOwed(const std::shared_ptr<DealState> &deal);
7980
void doFail(const std::shared_ptr<DealState> &deal, std::string error);
8081

8182
void start() override;

0 commit comments

Comments
 (0)