77#include " commit_batcher_impl.hpp"
88#include < iterator>
99#include " vm/actor/builtin/v5/miner/miner_actor.hpp"
10+ #include " vm/actor/builtin/v6/monies.hpp"
1011
1112namespace fc ::mining {
12- using fc::primitives::ActorId;
13- using primitives::BigInt;
13+ using api::kPushNoSpec ;
14+ using fc::BytesIn;
15+ using fc::proofs::ProofEngine;
16+ using primitives::ActorId;
17+ using primitives::go::bigdiv;
1418 using primitives::sector::AggregateSealVerifyInfo;
19+ using primitives::sector::AggregateSealVerifyProofAndInfos;
20+ using primitives::tipset::TipsetCPtr;
21+ using vm::actor::MethodParams;
1522 using vm::actor::builtin::types::miner::kChainFinality ;
1623 using vm::actor::builtin::types::miner::SectorPreCommitOnChainInfo;
1724 using vm::actor::builtin::v5::miner::ProveCommitAggregate;
25+ using vm::actor::builtin::v6::miner::AggregateProveCommitNetworkFee;
1826
1927 CommitBatcherImpl::CommitBatcherImpl (
2028 const std::chrono::milliseconds &max_time,
@@ -74,21 +82,24 @@ namespace fc::mining {
7482 }
7583 OUTCOME_TRY (head, api_->ChainHead ());
7684
77- // TODO ?
7885 const size_t total = union_storage_for_send.size ();
7986
8087 ProveCommitAggregate::Params params;
8188
82- std::vector<std::vector< uint8_t > > proofs;
89+ std::vector<BytesIn > proofs;
8390 proofs.reserve (total);
8491
92+ std::vector<AggregateSealVerifyInfo> infos;
93+ infos.reserve (total);
94+
8595 BigInt collateral = 0 ;
8696
8797 for (const auto &[sector_number, pair_storage] : union_storage_for_send) {
8898 OUTCOME_TRY (sc, getSectorCollateral (sector_number, head->key ));
8999 collateral = collateral + sc;
90100
91101 params.sectors .insert (sector_number);
102+ infos.push_back (pair_storage.aggregate_input .info );
92103 }
93104
94105 for (const auto &[sector_number, pair_storage] : union_storage_for_send) {
@@ -98,28 +109,56 @@ namespace fc::mining {
98109 const ActorId mid = miner_address_.getId ();
99110 // TODO maybe long (AggregateSealProofs)
100111
101- // TODO params.proof = proof_->AggregateSealProofs(); // OUTCOME_TRY
102- OUTCOME_TRY (a, proof_->AggregateSealProofs ());
103-
104- auto enc = codec::cbor::encode (params);
112+ AggregateSealVerifyProofAndInfos aggregate_seal =
113+ AggregateSealVerifyProofAndInfos{
114+ .miner = mid,
115+ .seal_proof =
116+ union_storage_for_send[infos[0 ].number ].aggregate_input .spt ,
117+ .aggregate_proof = arp_,
118+ .proof = proofs[infos[0 ].number ], // TODO is it correct?
119+ .infos = infos};
120+
121+ OUTCOME_TRY (proof_->aggregateSealProofs (aggregate_seal, proofs));
122+ // need: std::vector<gsl::span<const uint8_t>>
123+ // proofs: std::vector<std::vector<uint8_t>>
124+ // proof: std::vector<uint8_t>
125+ // BytesIn: gsl::span<const uint8_t>;
126+
127+ // proofs: std::vector<std::vector<uint8_t>>
128+ auto b = gsl::make_span (proofs);
129+ params.proof = aggregate_seal.proof ;
130+ OUTCOME_TRY (enc, codec::cbor::encode (params));
105131 OUTCOME_TRY (mi, api_->StateMinerInfo (miner_address_, head->key ));
106132
107- // BigDiv usage вместо /(обычное деление)
108-
109133 const TokenAmount max_fee =
110134 fee_config_->max_commit_batch_gas_fee .FeeForSector (proofs.size ());
111135
112- /*
113- * API_METHOD(StateMinerInfo,
114- * jwt::kReadPermission,
115- * MinerInfo,
116- * const Address &,
117- * const TipsetKey &)
118- */
119- // OTCOME_TRY(mi, api_->StateMinerInfo());
136+ OUTCOME_TRY (ts, api_->ChainGetTipSet (head->key ));
137+ const BigInt bf = ts->blks [0 ].parent_base_fee ;
120138
121- // TODO OUTCOME_TRY(bf, api_->ChainBaseFee(head));
122139 OUTCOME_TRY (nv, api_->StateNetworkVersion (head->key ));
140+
141+ TokenAmount agg_fee_raw = AggregateProveCommitNetworkFee (infos.size (), bf);
142+
143+ TokenAmount agg_fee = bigdiv (agg_fee_raw * agg_fee_num_, agg_fee_den_);
144+ TokenAmount need_funds = collateral + agg_fee;
145+ TokenAmount good_funds = max_fee + need_funds;
146+
147+ OUTCOME_TRY (address, address_selector_ (mi, good_funds, need_funds, api_));
148+ OUTCOME_TRY (mcid,
149+ api_->MpoolPushMessage (
150+ vm::message::UnsignedMessage (miner_address_,
151+ address,
152+ 0 ,
153+ need_funds,
154+ max_fee,
155+ {},
156+ ProveCommitAggregate::Number,
157+ MethodParams{enc}),
158+ kPushNoSpec ));
159+
160+ cutoff_start_ = std::chrono::system_clock::now ();
161+ return mcid.getCid ();
123162 }
124163
125164 void CommitBatcherImpl::setCommitCutoff (const ChainEpoch ¤t_epoch,
0 commit comments