99#include " vm/actor/builtin/v5/miner/miner_actor.hpp"
1010
1111namespace fc ::mining {
12- using vm::actor::builtin::types::miner::kChainFinality ;
13- using PairStorage = CommitBatcherImpl::UnionStorage::PairStorage;
1412 using fc::primitives::ActorId;
1513 using primitives::BigInt;
1614 using primitives::sector::AggregateSealVerifyInfo;
15+ using vm::actor::builtin::types::miner::kChainFinality ;
1716 using vm::actor::builtin::types::miner::SectorPreCommitOnChainInfo;
1817 using vm::actor::builtin::v5::miner::ProveCommitAggregate;
19- namespace vm ::actor::builtin::types::miner::SectorPreCommitOnChainInfo;
2018
2119 CommitBatcherImpl::CommitBatcherImpl (
2220 const std::chrono::milliseconds &max_time,
@@ -32,10 +30,12 @@ namespace fc::mining {
3230 const SectorInfo §or_info,
3331 const AggregateInput &aggregate_input,
3432 const CommitCallback &callback) {
33+ std::unique_lock<std::mutex> locker (mutex_storage_);
34+
3535 const SectorNumber §or_number = sector_info.sector_number ;
3636 OUTCOME_TRY (head, api_->ChainHead ());
3737
38- union_storage_. push ( sector_number, PairStorage ( aggregate_input, callback)) ;
38+ union_storage_[ sector_number] = PairStorage{ aggregate_input, callback} ;
3939
4040 if (union_storage_.size () >= max_size_callback_) {
4141 sendCallbacks ();
@@ -49,7 +49,12 @@ namespace fc::mining {
4949 void CommitBatcherImpl::forceSend () {}
5050
5151 void CommitBatcherImpl::sendCallbacks () {
52- UnionStorage union_storage_for_send_ (std::move (union_storage_));
52+ std::unique_lock<std::mutex> locker (mutex_storage_);
53+ MapPairStorage union_storage_for_send_ (
54+ std::make_move_iterator (union_storage_.begin ()),
55+ std::make_move_iterator (union_storage_.end ()));
56+ locker.unlock ();
57+
5358 const auto maybe_result = sendBatch (union_storage_for_send_);
5459 for (const auto &[key, pair_storage] : union_storage_for_send_) {
5560 pair_storage.commit_callback (maybe_result);
@@ -62,8 +67,8 @@ namespace fc::mining {
6267 }
6368
6469 outcome::result<CID> CommitBatcherImpl::sendBatch (
65- UnionStorage &union_storage_for_send) {
66- if (not union_storage_for_send.size ()) {
70+ MapPairStorage &union_storage_for_send) {
71+ if (union_storage_for_send.empty ()) {
6772 cutoff_start_ = std::chrono::system_clock::now ();
6873 return ERROR_TEXT (" Empty Batcher" );
6974 }
@@ -80,26 +85,24 @@ namespace fc::mining {
8085 BigInt collateral = 0 ;
8186
8287 for (const auto &[sector_number, pair_storage] : union_storage_for_send) {
83-
84-
85- TokenAmount sc = getSectorCollateral (head, sector_number, *head.get ());
88+ OUTCOME_TRY (sc, getSectorCollateral (sector_number, head->key ));
8689 collateral = collateral + sc;
8790
8891 params.sectors .insert (sector_number);
8992 }
9093
91-
92-
9394 for (const auto &[sector_number, pair_storage] : union_storage_for_send) {
94- proofs.push_back (
95- pair_storage.aggregate_input .proof );
95+ proofs.push_back (pair_storage.aggregate_input .proof );
9696 }
9797
9898 const ActorId mid = miner_address_.getId ();
9999 // TODO maybe long (AggregateSealProofs)
100- params.proof = proof_->AggregateSealProofs (); // OUTCOME_TRY
101100
102- // TODO CBOR::ENCODE params
101+ // TODO params.proof = proof_->AggregateSealProofs(); // OUTCOME_TRY
102+ OUTCOME_TRY (a, proof_->AggregateSealProofs ());
103+
104+ auto enc = codec::cbor::encode (params);
105+ OUTCOME_TRY (mi, api_->StateMinerInfo (miner_address_, head->key ));
103106
104107 // BigDiv usage вместо /(обычное деление)
105108
@@ -115,16 +118,16 @@ namespace fc::mining {
115118 */
116119 // OTCOME_TRY(mi, api_->StateMinerInfo());
117120
118- OUTCOME_TRY (bf, api_->ChainBaseFee (head));
119- OUTCOME_TRY (nv, api_->StateNetworkVersion (/* NetworkVersion */ , head));
121+ // TODO OUTCOME_TRY(bf, api_->ChainBaseFee(head));
122+ OUTCOME_TRY (nv, api_->StateNetworkVersion (head-> key ));
120123 }
121124
122125 void CommitBatcherImpl::setCommitCutoff (const ChainEpoch ¤t_epoch,
123126 const SectorInfo §or_info) {
124127 ChainEpoch cutoff_epoch =
125128 sector_info.ticket_epoch
126129 + static_cast <int64_t >(kEpochsInDay + kChainFinality );
127- ChainEpoch start_epoch{} ;
130+ ChainEpoch start_epoch;
128131 for (const auto &piece : sector_info.pieces ) {
129132 if (!piece.deal_info ) {
130133 continue ;
@@ -150,58 +153,20 @@ namespace fc::mining {
150153 }
151154 }
152155
153- TokenAmount CommitBatcherImpl::getSectorCollateral (
154- std::shared_ptr<const Tipset> &head,
155- const SectorNumber §or_number,
156- const TipsetKey &tip_set_key) {
156+ outcome::result<TokenAmount> CommitBatcherImpl::getSectorCollateral (
157+ const SectorNumber §or_number, const TipsetKey &tip_set_key) {
157158 OUTCOME_TRY (pci,
158159 api_->StateSectorPreCommitInfo (
159160 miner_address_, sector_number, tip_set_key));
161+
160162 OUTCOME_TRY (collateral,
161163 api_->StateMinerInitialPledgeCollateral (
162- miner_address_, head-> key , pci.info , tip_set_key));
164+ miner_address_, pci.info , tip_set_key));
163165
164- collateral = collateral + pci.PreCommitDeposit ;
165- collateral = max (0 , collateral);
166+ collateral = collateral + pci.precommit_deposit ;
167+ collateral = std:: max (BigInt ( 0 ) , collateral);
166168
167169 return collateral;
168170 }
169171
170- void CommitBatcherImpl::UnionStorage::push (const SectorNumber §or_number,
171- const PairStorage &pair_storage) {
172- std::unique_lock<std::mutex> locker (mutex_);
173- storage_[sector_number] = pair_storage;
174- }
175-
176- CommitBatcherImpl::UnionStorage::UnionStorage (
177- CommitBatcherImpl::UnionStorage &&union_storage1) {
178- std::unique_lock<std::mutex> locker (union_storage1.mutex_ );
179- storage_.insert (std::make_move_iterator (union_storage1.storage_ .begin ()),
180- std::make_move_iterator (union_storage1.storage_ .end ()));
181- }
182-
183- size_t CommitBatcherImpl::UnionStorage::size () {
184- std::unique_lock<std::mutex> locker (mutex_);
185- return storage_.size ();
186- }
187-
188- CommitBatcherImpl::UnionStorage::PairStorage::PairStorage (
189- const AggregateInput &aggregate_input,
190- const CommitCallback &commit_callback)
191- : aggregate_input(aggregate_input), commit_callback(commit_callback) {}
192-
193- std::map<SectorNumber, CommitBatcherImpl::UnionStorage::PairStorage>::iterator
194- CommitBatcherImpl::UnionStorage::begin () {
195- return storage_.begin ();
196- }
197-
198- std::map<SectorNumber, CommitBatcherImpl::UnionStorage::PairStorage>::iterator
199- CommitBatcherImpl::UnionStorage::end () {
200- return storage_.end ();
201- }
202-
203- PairStorage CommitBatcherImpl::UnionStorage::get (const int index) {
204- std::unique_lock<std::mutex> locker (mutex_);
205- return storage_[index];
206- }
207172} // namespace fc::mining
0 commit comments